ia64/xen-unstable

view unmodified_drivers/linux-2.6/platform-pci/platform-compat.c @ 18824:0b8c6c91c5a4

pv-on-hvm drivers: build fixes for Linux 2.6.27+

Make the drivers build properly in a 2.6.27 environment as well as
against a kernel with pv-ops Xen configured on (in the latter case
more work would be needed to also make the drivers work, as there's a
large number of duplicate exports).

Portions from Charles Arnold <carnold@novell.com>.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Nov 24 11:11:20 2008 +0000 (2008-11-24)
parents 6e7ef794cdbc
children
line source
1 #include <linux/version.h>
3 #include <linux/mm.h>
4 #include <linux/module.h>
5 #include <linux/sched.h>
6 #include <linux/slab.h>
8 #include <xen/platform-compat.h>
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7)
11 static int system_state = 1;
12 EXPORT_SYMBOL(system_state);
13 #endif
15 void ctrl_alt_del(void)
16 {
17 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
18 kill_proc(1, SIGINT, 1); /* interrupt init */
19 #else
20 kill_cad_pid(SIGINT, 1);
21 #endif
22 }
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)
25 size_t strcspn(const char *s, const char *reject)
26 {
27 const char *p;
28 const char *r;
29 size_t count = 0;
31 for (p = s; *p != '\0'; ++p) {
32 for (r = reject; *r != '\0'; ++r) {
33 if (*p == *r)
34 return count;
35 }
36 ++count;
37 }
39 return count;
40 }
41 EXPORT_SYMBOL(strcspn);
42 #endif
44 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
45 /*
46 * Map a vmalloc()-space virtual address to the physical page frame number.
47 */
48 unsigned long vmalloc_to_pfn(void * vmalloc_addr)
49 {
50 return page_to_pfn(vmalloc_to_page(vmalloc_addr));
51 }
52 EXPORT_SYMBOL(vmalloc_to_pfn);
53 #endif
55 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
56 unsigned long wait_for_completion_timeout(struct completion *x, unsigned long timeout)
57 {
58 might_sleep();
60 spin_lock_irq(&x->wait.lock);
61 if (!x->done) {
62 DECLARE_WAITQUEUE(wait, current);
64 wait.flags |= WQ_FLAG_EXCLUSIVE;
65 __add_wait_queue_tail(&x->wait, &wait);
66 do {
67 __set_current_state(TASK_UNINTERRUPTIBLE);
68 spin_unlock_irq(&x->wait.lock);
69 timeout = schedule_timeout(timeout);
70 spin_lock_irq(&x->wait.lock);
71 if (!timeout) {
72 __remove_wait_queue(&x->wait, &wait);
73 goto out;
74 }
75 } while (!x->done);
76 __remove_wait_queue(&x->wait, &wait);
77 }
78 x->done--;
79 out:
80 spin_unlock_irq(&x->wait.lock);
81 return timeout;
82 }
83 EXPORT_SYMBOL(wait_for_completion_timeout);
84 #endif
86 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
87 /*
88 fake do_exit using complete_and_exit
89 */
90 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
91 asmlinkage NORET_TYPE void do_exit(long code)
92 #else
93 fastcall NORET_TYPE void do_exit(long code)
94 #endif
95 {
96 complete_and_exit(NULL, code);
97 }
98 EXPORT_SYMBOL_GPL(do_exit);
99 #endif
101 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
102 signed long schedule_timeout_interruptible(signed long timeout)
103 {
104 __set_current_state(TASK_INTERRUPTIBLE);
105 return schedule_timeout(timeout);
106 }
107 EXPORT_SYMBOL(schedule_timeout_interruptible);
108 #endif
110 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
111 /**
112 * kzalloc - allocate memory. The memory is set to zero.
113 * @size: how many bytes of memory are required.
114 * @flags: the type of memory to allocate.
115 */
116 void *kzalloc(size_t size, int flags)
117 {
118 void *ret = kmalloc(size, flags);
119 if (ret)
120 memset(ret, 0, size);
121 return ret;
122 }
123 EXPORT_SYMBOL(kzalloc);
124 #endif
126 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
127 /* Simplified asprintf. */
128 char *kasprintf(gfp_t gfp, const char *fmt, ...)
129 {
130 va_list ap;
131 unsigned int len;
132 char *p, dummy[1];
134 va_start(ap, fmt);
135 len = vsnprintf(dummy, 0, fmt, ap);
136 va_end(ap);
138 p = kmalloc(len + 1, gfp);
139 if (!p)
140 return NULL;
141 va_start(ap, fmt);
142 vsprintf(p, fmt, ap);
143 va_end(ap);
144 return p;
145 }
146 EXPORT_SYMBOL(kasprintf);
147 #endif