1 #ifndef LINUX_26_26_COMPAT_H
2 #define LINUX_26_26_COMPAT_H
4 #include <linux/version.h>
6 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
8 #include <linux/device.h>
9 #include <linux/list.h>
10 #include <linux/kernel.h>
11 #include <linux/jiffies.h>
14 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
15 #include <net/net_namespace.h>
18 #include <linux/types.h>
20 /* These jiffie helpers added as of 2.6.26 */
23 * These four macros compare jiffies and 'a' for convenience.
26 /* time_is_before_jiffies(a) return true if a is before jiffies */
27 #define time_is_before_jiffies(a) time_after(jiffies, a)
29 /* time_is_after_jiffies(a) return true if a is after jiffies */
30 #define time_is_after_jiffies(a) time_before(jiffies, a)
32 /* time_is_before_eq_jiffies(a) return true if a is before or equal to jiffies*/
33 #define time_is_before_eq_jiffies(a) time_after_eq(jiffies, a)
35 /* time_is_after_eq_jiffies(a) return true if a is after or equal to jiffies*/
36 #define time_is_after_eq_jiffies(a) time_before_eq(jiffies, a)
38 /* This comes from include/linux/input.h */
39 #define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any"
40 set = radio enabled */
43 #define USHORT_MAX ((u16)(~0U))
44 #define SHORT_MAX ((s16)(USHORT_MAX>>1))
45 #define SHORT_MIN (-SHORT_MAX - 1)
47 extern int dev_set_name(struct device *dev, const char *name, ...)
48 __attribute__((format(printf, 2, 3)));
51 * clamp - return a value clamped to a given range with strict typechecking
53 * @min: minimum allowable value
54 * @max: maximum allowable value
56 * This macro does strict typechecking of min/max to make sure they are of the
57 * same type as val. See the unnecessary pointer comparisons.
59 #define clamp(val, min, max) ({ \
60 typeof(val) __val = (val); \
61 typeof(min) __min = (min); \
62 typeof(max) __max = (max); \
63 (void) (&__val == &__min); \
64 (void) (&__val == &__max); \
65 __val = __val < __min ? __min: __val; \
66 __val > __max ? __max: __val; })
69 * clamp_t - return a value clamped to a given range using a given type
70 * @type: the type of variable to use
72 * @min: minimum allowable value
73 * @max: maximum allowable value
75 * This macro does no typechecking and uses temporary variables of type
76 * 'type' to make all the comparisons.
78 #define clamp_t(type, val, min, max) ({ \
82 __val = __val < __min ? __min: __val; \
83 __val > __max ? __max: __val; })
86 /* from include/linux/device.h */
87 /* device_create_drvdata() is new */
88 extern struct device *device_create_drvdata(struct class *cls,
89 struct device *parent,
93 __attribute__((format(printf, 5, 6)));
95 /* This is from include/linux/list.h */
98 * list_is_singular - tests whether a list has just one entry.
99 * @head: the list to test.
101 static inline int list_is_singular(const struct list_head *head)
103 return !list_empty(head) && (head->next == head->prev);
106 /* This is from include/linux/device.h, which was added as of 2.6.26 */
107 static inline const char *dev_name(struct device *dev)
109 /* will be changed into kobject_name(&dev->kobj) in the near future */
113 /* This is from include/linux/kernel.h, which was added as of 2.6.26 */
116 * clamp_val - return a value clamped to a given range using val's type
117 * @val: current value
118 * @min: minimum allowable value
119 * @max: maximum allowable value
121 * This macro does no typechecking and uses temporary variables of whatever
122 * type the input argument 'val' is. This is useful when val is an unsigned
123 * type and min and max are literals that will otherwise be assigned a signed
127 #define clamp_val(val, min, max) ({ \
128 typeof(val) __val = (val); \
129 typeof(val) __min = (min); \
130 typeof(val) __max = (max); \
131 __val = __val < __min ? __min: __val; \
132 __val > __max ? __max: __val; })
134 /* This comes from include/net/net_namespace.h */
138 int net_eq(const struct net *net1, const struct net *net2)
144 int net_eq(const struct net *net1, const struct net *net2)
151 void dev_net_set(struct net_device *dev, struct net *net)
154 release_net(dev->nd_net);
155 dev->nd_net = hold_net(net);
160 struct net *sock_net(const struct sock *sk)
169 /* This comes from include/linux/netdevice.h */
172 * Net namespace inlines
175 struct net *dev_net(const struct net_device *dev)
179 * compat-wirelss backport note:
180 * For older kernels we may just need to always return init_net,
181 * not sure when we added dev->nd_net.
191 * 2.6.26 added its own unaligned API which the
192 * new drivers can use. Lets port it here by including it in older
193 * kernels and also deal with the architecture handling here.
198 #include <linux/unaligned/be_struct.h>
199 #include <linux/unaligned/le_byteshift.h>
200 #include <linux/unaligned/generic.h>
206 #include <linux/unaligned/le_byteshift.h>
207 #include <linux/unaligned/be_byteshift.h>
208 #include <linux/unaligned/generic.h>
214 * AVR32 can handle some unaligned accesses, depending on the
215 * implementation. The AVR32 AP implementation can handle unaligned
216 * words, but halfwords must be halfword-aligned, and doublewords must
219 * However, swapped word loads must be word-aligned so we can't
220 * optimize word loads in general.
223 #include <linux/unaligned/be_struct.h>
224 #include <linux/unaligned/le_byteshift.h>
225 #include <linux/unaligned/generic.h>
228 #ifdef CONFIG_BLACKFIN
230 #include <linux/unaligned/le_struct.h>
231 #include <linux/unaligned/be_byteshift.h>
232 #include <linux/unaligned/generic.h>
234 #endif /* blackfin */
238 * CRIS can do unaligned accesses itself.
240 #include <linux/unaligned/access_ok.h>
241 #include <linux/unaligned/generic.h>
246 #include <linux/unaligned/le_byteshift.h>
247 #include <linux/unaligned/be_byteshift.h>
248 #include <linux/unaligned/generic.h>
253 #include <linux/unaligned/be_memmove.h>
254 #include <linux/unaligned/le_byteshift.h>
255 #include <linux/unaligned/generic.h>
260 #include <linux/unaligned/le_struct.h>
261 #include <linux/unaligned/be_byteshift.h>
262 #include <linux/unaligned/generic.h>
267 #if defined(__LITTLE_ENDIAN__)
268 # include <linux/unaligned/le_memmove.h>
269 # include <linux/unaligned/be_byteshift.h>
270 # include <linux/unaligned/generic.h>
272 # include <linux/unaligned/be_memmove.h>
273 # include <linux/unaligned/le_byteshift.h>
274 # include <linux/unaligned/generic.h>
278 #ifdef CONFIG_M68K /* this handles both m68k and m68knommu */
280 #ifdef CONFIG_COLDFIRE
281 #include <linux/unaligned/be_struct.h>
282 #include <linux/unaligned/le_byteshift.h>
283 #include <linux/unaligned/generic.h>
287 * The m68k can do unaligned accesses itself.
289 #include <linux/unaligned/access_ok.h>
290 #include <linux/unaligned/generic.h>
293 #endif /* m68k and m68knommu */
296 #if defined(__MIPSEB__)
297 # include <linux/unaligned/be_struct.h>
298 # include <linux/unaligned/le_byteshift.h>
299 # include <linux/unaligned/generic.h>
300 # define get_unaligned __get_unaligned_be
301 # define put_unaligned __put_unaligned_be
302 #elif defined(__MIPSEL__)
303 # include <linux/unaligned/le_struct.h>
304 # include <linux/unaligned/be_byteshift.h>
305 # include <linux/unaligned/generic.h>
309 #ifdef CONFIG_MN10300
311 #include <linux/unaligned/access_ok.h>
312 #include <linux/unaligned/generic.h>
317 #include <linux/unaligned/be_struct.h>
318 #include <linux/unaligned/le_byteshift.h>
319 #include <linux/unaligned/generic.h>
324 * The PowerPC can do unaligned accesses itself in big endian mode.
326 #include <linux/unaligned/access_ok.h>
327 #include <linux/unaligned/generic.h>
333 * The S390 can do unaligned accesses itself.
335 #include <linux/unaligned/access_ok.h>
336 #include <linux/unaligned/generic.h>
341 /* SH can't handle unaligned accesses. */
342 #ifdef __LITTLE_ENDIAN__
343 # include <linux/unaligned/le_struct.h>
344 # include <linux/unaligned/be_byteshift.h>
345 # include <linux/unaligned/generic.h>
347 # include <linux/unaligned/be_struct.h>
348 # include <linux/unaligned/le_byteshift.h>
349 # include <linux/unaligned/generic.h>
352 #endif /* sh - SUPERH */
355 /* sparc and sparc64 */
356 #include <linux/unaligned/be_struct.h>
357 #include <linux/unaligned/le_byteshift.h>
358 #include <linux/unaligned/generic.h>
363 #include "asm/arch/unaligned.h"
365 #endif /* um - uml */
368 #include <linux/unaligned/be_byteshift.h>
369 #include <linux/unaligned/le_byteshift.h>
370 #include <linux/unaligned/generic.h>
375 * The x86 can do unaligned accesses itself.
377 #include <linux/unaligned/access_ok.h>
378 #include <linux/unaligned/generic.h>
384 # include <linux/unaligned/le_memmove.h>
385 # include <linux/unaligned/be_byteshift.h>
386 # include <linux/unaligned/generic.h>
387 #elif defined(__XTENSA_EB__)
388 # include <linux/unaligned/be_memmove.h>
389 # include <linux/unaligned/le_byteshift.h>
390 # include <linux/unaligned/generic.h>
392 # error processor byte order undefined!
397 #define PCIE_LINK_STATE_L0S 1
398 #define PCIE_LINK_STATE_L1 2
399 #define PCIE_LINK_STATE_CLKPM 4
401 static inline void pci_disable_link_state(struct pci_dev *pdev, int state)
404 /* source: include/linux/pci-aspm.h */
406 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) */
408 #endif /* LINUX_26_26_COMPAT_H */