1 #ifndef COMPAT_INCLUDE_XEN_PLATFORM_COMPAT_H
2 #define COMPAT_INCLUDE_XEN_PLATFORM_COMPAT_H
3 
4 #include <linux/version.h>
5 #include <linux/spinlock.h>
6 #include <asm/maddr.h>
7 
8 #if defined(__LINUX_COMPILER_H) && !defined(__always_inline)
9 #define __always_inline inline
10 #endif
11 
12 #if defined(__LINUX_SPINLOCK_H) && !defined(DEFINE_SPINLOCK)
13 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
14 #endif
15 
16 #ifdef _LINUX_INIT_H
17 
18 #ifndef __init
19 #define __init
20 #endif
21 
22 #ifndef __devinit
23 #define __devinit
24 #define __devinitdata
25 #endif
26 
27 #endif /* _LINUX_INIT_H */
28 
29 #if defined(__LINUX_CACHE_H) && !defined(__read_mostly)
30 #define __read_mostly
31 #endif
32 
33 #if defined(_LINUX_SKBUFF_H) && !defined(NET_IP_ALIGN)
34 #define NET_IP_ALIGN 0
35 #endif
36 
37 #if defined(_LINUX_SKBUFF_H) && !defined(CHECKSUM_HW)
38 #define CHECKSUM_HW CHECKSUM_PARTIAL
39 #endif
40 
41 #if defined(_LINUX_ERR_H) && !defined(IS_ERR_VALUE)
42 #define IS_ERR_VALUE(x) unlikely((x) > (unsigned long)-1000L)
43 #endif
44 
45 #if defined(_ASM_IA64_PGTABLE_H) && !defined(_PGTABLE_NOPUD_H)
46 #include <asm-generic/pgtable-nopud.h>
47 #endif
48 
49 /* Some kernels have this typedef backported so we cannot reliably
50  * detect based on version number, hence we forcibly #define it.
51  */
52 #if defined(__LINUX_TYPES_H) || defined(__LINUX_GFP_H) || defined(_LINUX_KERNEL_H)
53 #define gfp_t unsigned
54 #endif
55 
56 #if defined(_LINUX_NOTIFIER_H) && !defined(ATOMIC_NOTIFIER_HEAD)
57 #define ATOMIC_NOTIFIER_HEAD(name) struct notifier_block *name
58 #define atomic_notifier_chain_register(chain,nb) notifier_chain_register(chain,nb)
59 #define atomic_notifier_chain_unregister(chain,nb) notifier_chain_unregister(chain,nb)
60 #define atomic_notifier_call_chain(chain,val,v) notifier_call_chain(chain,val,v)
61 #endif
62 
63 #if defined(_LINUX_NOTIFIER_H) && !defined(BLOCKING_NOTIFIER_HEAD)
64 #define BLOCKING_NOTIFIER_HEAD(name) struct notifier_block *name
65 #define blocking_notifier_chain_register(chain,nb) notifier_chain_register(chain,nb)
66 #define blocking_notifier_chain_unregister(chain,nb) notifier_chain_unregister(chain,nb)
67 #define blocking_notifier_call_chain(chain,val,v) notifier_call_chain(chain,val,v)
68 #endif
69 
70 #if defined(_LINUX_MM_H) && defined set_page_count
71 #define init_page_count(page) set_page_count(page, 1)
72 #endif
73 
74 #if defined(__LINUX_GFP_H) && !defined __GFP_NOMEMALLOC
75 #define __GFP_NOMEMALLOC 0
76 #endif
77 
78 #if defined(_LINUX_FS_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
79 #define nonseekable_open(inode, filp) /* Nothing to do */
80 #endif
81 
82 #if defined(_LINUX_MM_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
83 unsigned long vmalloc_to_pfn(void *addr);
84 #endif
85 
86 #if defined(__LINUX_COMPLETION_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
87 unsigned long wait_for_completion_timeout(struct completion *x, unsigned long timeout);
88 #endif
89 
90 #if defined(_LINUX_SCHED_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
91 signed long schedule_timeout_interruptible(signed long timeout);
92 #endif
93 
94 #if defined(_LINUX_SLAB_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
95 void *kzalloc(size_t size, int flags);
96 #endif
97 
98 #if defined(_LINUX_BLKDEV_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
99 #define end_that_request_last(req, uptodate) end_that_request_last(req)
100 #endif
101 
102 #if defined(_LINUX_CAPABILITY_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
103 #define capable(cap) (1)
104 #endif
105 
106 #if defined(_LINUX_KERNEL_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
107 extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
108        __attribute__ ((format (printf, 2, 3)));
109 #endif
110 
111 #if defined(_LINUX_SYSRQ_H) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
112 #define handle_sysrq(x,y,z) handle_sysrq(x,y)
113 #endif
114 
115 #if defined(_PAGE_PRESENT) && !defined(_PAGE_NX)
116 #define _PAGE_NX 0
117 /*
118  * This variable at present is referenced by netfront, but only in code that
119  * is dead when running in hvm guests. To detect potential active uses of it
120  * in the future, don't try to supply a 'valid' value here, so that any
121  * mappings created with it will fault when accessed.
122  */
123 #define __supported_pte_mask ((maddr_t)0)
124 #endif
125 
126 /* This code duplication is not ideal, but || does not seem to properly
127  *  short circuit in a #if condition.
128  **/
129 #if defined(_LINUX_NETDEVICE_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
130 #if !defined(SLE_VERSION)
131 #define netif_tx_lock_bh(dev) spin_lock_bh(&(dev)->xmit_lock)
132 #define netif_tx_unlock_bh(dev) spin_unlock_bh(&(dev)->xmit_lock)
133 #elif SLE_VERSION_CODE < SLE_VERSION(10,1,0)
134 #define netif_tx_lock_bh(dev) spin_lock_bh(&(dev)->xmit_lock)
135 #define netif_tx_unlock_bh(dev) spin_unlock_bh(&(dev)->xmit_lock)
136 #endif
137 #endif
138 
139 #if defined(__LINUX_SEQLOCK_H) && !defined(DEFINE_SEQLOCK)
140 #define DEFINE_SEQLOCK(x) seqlock_t x = SEQLOCK_UNLOCKED
141 #endif
142 
143 /* Bug in RHEL4-U3: rw_lock_t is mistakenly defined in DEFINE_RWLOCK() macro */
144 #if defined(__LINUX_SPINLOCK_H) && defined(DEFINE_RWLOCK)
145 #define rw_lock_t rwlock_t
146 #endif
147 
148 #if defined(__LINUX_SPINLOCK_H) && !defined(DEFINE_RWLOCK)
149 #define DEFINE_RWLOCK(x) rwlock_t x = RW_LOCK_UNLOCKED
150 #endif
151 
152 #if defined(_LINUX_INTERRUPT_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
153 /**
154  *   RHEL4-U5 pulled back this feature into the older kernel
155  *   Since it is a typedef, and not a macro - detect this kernel via
156  *   RHEL_VERSION
157  */
158 #if !defined(RHEL_VERSION) || (RHEL_VERSION == 4 && RHEL_UPDATE < 5)
159 #if !defined(RHEL_MAJOR) || (RHEL_MAJOR == 4 && RHEL_MINOR < 5)
160 typedef irqreturn_t (*irq_handler_t)(int, void *, struct pt_regs *);
161 #endif
162 #endif
163 #endif
164 
165 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
166 #define setup_xen_features xen_setup_features
167 #endif
168 
169 #ifndef atomic_cmpxchg
170 #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new)))
171 #endif
172 
173 #ifdef sync_test_bit
174 #define synch_change_bit		sync_change_bit
175 #define synch_clear_bit			sync_clear_bit
176 #define synch_set_bit			sync_set_bit
177 #define synch_test_and_change_bit	sync_test_and_change_bit
178 #define synch_test_and_clear_bit	sync_test_and_clear_bit
179 #define synch_test_and_set_bit		sync_test_and_set_bit
180 #define synch_test_bit			sync_test_bit
181 #endif
182 
183 #endif
184