iwl3945 : Simplify iwl3945_pci_probe
[linux-2.6/mini2440.git] / include / linux / byteorder.h
blob29f002d73d989c577f0e79a8100d6fb7e0abb188
1 #ifndef _LINUX_BYTEORDER_H
2 #define _LINUX_BYTEORDER_H
4 #include <linux/types.h>
5 #include <linux/swab.h>
7 #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
8 # error Fix asm/byteorder.h to define one endianness
9 #endif
11 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
12 # error Fix asm/byteorder.h to define arch endianness
13 #endif
15 #ifdef __LITTLE_ENDIAN
16 # undef __LITTLE_ENDIAN
17 # define __LITTLE_ENDIAN 1234
18 #endif
20 #ifdef __BIG_ENDIAN
21 # undef __BIG_ENDIAN
22 # define __BIG_ENDIAN 4321
23 #endif
25 #if defined(__LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN_BITFIELD)
26 # define __LITTLE_ENDIAN_BITFIELD
27 #endif
29 #if defined(__BIG_ENDIAN) && !defined(__BIG_ENDIAN_BITFIELD)
30 # define __BIG_ENDIAN_BITFIELD
31 #endif
33 #ifdef __LITTLE_ENDIAN
34 # define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
35 # define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
36 # define __le64_to_cpu(x) ((__force __u64)(__le64)(x))
37 # define __cpu_to_le16(x) ((__force __le16)(__u16)(x))
38 # define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
39 # define __cpu_to_le64(x) ((__force __le64)(__u64)(x))
41 # define __be16_to_cpu(x) __swab16((__force __u16)(__be16)(x))
42 # define __be32_to_cpu(x) __swab32((__force __u32)(__be32)(x))
43 # define __be64_to_cpu(x) __swab64((__force __u64)(__be64)(x))
44 # define __cpu_to_be16(x) ((__force __be16)__swab16(x))
45 # define __cpu_to_be32(x) ((__force __be32)__swab32(x))
46 # define __cpu_to_be64(x) ((__force __be64)__swab64(x))
47 #endif
49 #ifdef __BIG_ENDIAN
50 # define __be16_to_cpu(x) ((__force __u16)(__be16)(x))
51 # define __be32_to_cpu(x) ((__force __u32)(__be32)(x))
52 # define __be64_to_cpu(x) ((__force __u64)(__be64)(x))
53 # define __cpu_to_be16(x) ((__force __be16)(__u16)(x))
54 # define __cpu_to_be32(x) ((__force __be32)(__u32)(x))
55 # define __cpu_to_be64(x) ((__force __be64)(__u64)(x))
57 # define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
58 # define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
59 # define __le64_to_cpu(x) __swab64((__force __u64)(__le64)(x))
60 # define __cpu_to_le16(x) ((__force __le16)__swab16(x))
61 # define __cpu_to_le32(x) ((__force __le32)__swab32(x))
62 # define __cpu_to_le64(x) ((__force __le64)__swab64(x))
63 #endif
66 * These helpers could be phased out over time as the base version
67 * handles constant folding.
69 #define __constant_htonl(x) __cpu_to_be32(x)
70 #define __constant_ntohl(x) __be32_to_cpu(x)
71 #define __constant_htons(x) __cpu_to_be16(x)
72 #define __constant_ntohs(x) __be16_to_cpu(x)
74 #define __constant_le16_to_cpu(x) __le16_to_cpu(x)
75 #define __constant_le32_to_cpu(x) __le32_to_cpu(x)
76 #define __constant_le64_to_cpu(x) __le64_to_cpu(x)
77 #define __constant_be16_to_cpu(x) __be16_to_cpu(x)
78 #define __constant_be32_to_cpu(x) __be32_to_cpu(x)
79 #define __constant_be64_to_cpu(x) __be64_to_cpu(x)
81 #define __constant_cpu_to_le16(x) __cpu_to_le16(x)
82 #define __constant_cpu_to_le32(x) __cpu_to_le32(x)
83 #define __constant_cpu_to_le64(x) __cpu_to_le64(x)
84 #define __constant_cpu_to_be16(x) __cpu_to_be16(x)
85 #define __constant_cpu_to_be32(x) __cpu_to_be32(x)
86 #define __constant_cpu_to_be64(x) __cpu_to_be64(x)
88 static inline void __le16_to_cpus(__u16 *p)
90 #ifdef __BIG_ENDIAN
91 __swab16s(p);
92 #endif
95 static inline void __cpu_to_le16s(__u16 *p)
97 #ifdef __BIG_ENDIAN
98 __swab16s(p);
99 #endif
102 static inline void __le32_to_cpus(__u32 *p)
104 #ifdef __BIG_ENDIAN
105 __swab32s(p);
106 #endif
109 static inline void __cpu_to_le32s(__u32 *p)
111 #ifdef __BIG_ENDIAN
112 __swab32s(p);
113 #endif
116 static inline void __le64_to_cpus(__u64 *p)
118 #ifdef __BIG_ENDIAN
119 __swab64s(p);
120 #endif
123 static inline void __cpu_to_le64s(__u64 *p)
125 #ifdef __BIG_ENDIAN
126 __swab64s(p);
127 #endif
130 static inline void __be16_to_cpus(__u16 *p)
132 #ifdef __LITTLE_ENDIAN
133 __swab16s(p);
134 #endif
137 static inline void __cpu_to_be16s(__u16 *p)
139 #ifdef __LITTLE_ENDIAN
140 __swab16s(p);
141 #endif
144 static inline void __be32_to_cpus(__u32 *p)
146 #ifdef __LITTLE_ENDIAN
147 __swab32s(p);
148 #endif
151 static inline void __cpu_to_be32s(__u32 *p)
153 #ifdef __LITTLE_ENDIAN
154 __swab32s(p);
155 #endif
158 static inline void __be64_to_cpus(__u64 *p)
160 #ifdef __LITTLE_ENDIAN
161 __swab64s(p);
162 #endif
165 static inline void __cpu_to_be64s(__u64 *p)
167 #ifdef __LITTLE_ENDIAN
168 __swab64s(p);
169 #endif
172 static inline __u16 __le16_to_cpup(const __le16 *p)
174 #ifdef __LITTLE_ENDIAN
175 return (__force __u16)*p;
176 #else
177 return __swab16p((__force __u16 *)p);
178 #endif
181 static inline __u32 __le32_to_cpup(const __le32 *p)
183 #ifdef __LITTLE_ENDIAN
184 return (__force __u32)*p;
185 #else
186 return __swab32p((__force __u32 *)p);
187 #endif
190 static inline __u64 __le64_to_cpup(const __le64 *p)
192 #ifdef __LITTLE_ENDIAN
193 return (__force __u64)*p;
194 #else
195 return __swab64p((__force __u64 *)p);
196 #endif
199 static inline __le16 __cpu_to_le16p(const __u16 *p)
201 #ifdef __LITTLE_ENDIAN
202 return (__force __le16)*p;
203 #else
204 return (__force __le16)__swab16p(p);
205 #endif
208 static inline __le32 __cpu_to_le32p(const __u32 *p)
210 #ifdef __LITTLE_ENDIAN
211 return (__force __le32)*p;
212 #else
213 return (__force __le32)__swab32p(p);
214 #endif
217 static inline __le64 __cpu_to_le64p(const __u64 *p)
219 #ifdef __LITTLE_ENDIAN
220 return (__force __le64)*p;
221 #else
222 return (__force __le64)__swab64p(p);
223 #endif
226 static inline __u16 __be16_to_cpup(const __be16 *p)
228 #ifdef __BIG_ENDIAN
229 return (__force __u16)*p;
230 #else
231 return __swab16p((__force __u16 *)p);
232 #endif
235 static inline __u32 __be32_to_cpup(const __be32 *p)
237 #ifdef __BIG_ENDIAN
238 return (__force __u32)*p;
239 #else
240 return __swab32p((__force __u32 *)p);
241 #endif
244 static inline __u64 __be64_to_cpup(const __be64 *p)
246 #ifdef __BIG_ENDIAN
247 return (__force __u64)*p;
248 #else
249 return __swab64p((__force __u64 *)p);
250 #endif
253 static inline __be16 __cpu_to_be16p(const __u16 *p)
255 #ifdef __BIG_ENDIAN
256 return (__force __be16)*p;
257 #else
258 return (__force __be16)__swab16p(p);
259 #endif
262 static inline __be32 __cpu_to_be32p(const __u32 *p)
264 #ifdef __BIG_ENDIAN
265 return (__force __be32)*p;
266 #else
267 return (__force __be32)__swab32p(p);
268 #endif
271 static inline __be64 __cpu_to_be64p(const __u64 *p)
273 #ifdef __BIG_ENDIAN
274 return (__force __be64)*p;
275 #else
276 return (__force __be64)__swab64p(p);
277 #endif
280 #ifdef __KERNEL__
282 # define le16_to_cpu __le16_to_cpu
283 # define le32_to_cpu __le32_to_cpu
284 # define le64_to_cpu __le64_to_cpu
285 # define be16_to_cpu __be16_to_cpu
286 # define be32_to_cpu __be32_to_cpu
287 # define be64_to_cpu __be64_to_cpu
288 # define cpu_to_le16 __cpu_to_le16
289 # define cpu_to_le32 __cpu_to_le32
290 # define cpu_to_le64 __cpu_to_le64
291 # define cpu_to_be16 __cpu_to_be16
292 # define cpu_to_be32 __cpu_to_be32
293 # define cpu_to_be64 __cpu_to_be64
295 # define le16_to_cpup __le16_to_cpup
296 # define le32_to_cpup __le32_to_cpup
297 # define le64_to_cpup __le64_to_cpup
298 # define be16_to_cpup __be16_to_cpup
299 # define be32_to_cpup __be32_to_cpup
300 # define be64_to_cpup __be64_to_cpup
301 # define cpu_to_le16p __cpu_to_le16p
302 # define cpu_to_le32p __cpu_to_le32p
303 # define cpu_to_le64p __cpu_to_le64p
304 # define cpu_to_be16p __cpu_to_be16p
305 # define cpu_to_be32p __cpu_to_be32p
306 # define cpu_to_be64p __cpu_to_be64p
308 # define le16_to_cpus __le16_to_cpus
309 # define le32_to_cpus __le32_to_cpus
310 # define le64_to_cpus __le64_to_cpus
311 # define be16_to_cpus __be16_to_cpus
312 # define be32_to_cpus __be32_to_cpus
313 # define be64_to_cpus __be64_to_cpus
314 # define cpu_to_le16s __cpu_to_le16s
315 # define cpu_to_le32s __cpu_to_le32s
316 # define cpu_to_le64s __cpu_to_le64s
317 # define cpu_to_be16s __cpu_to_be16s
318 # define cpu_to_be32s __cpu_to_be32s
319 # define cpu_to_be64s __cpu_to_be64s
322 * They have to be macros in order to do the constant folding
323 * correctly - if the argument passed into a inline function
324 * it is no longer constant according to gcc..
326 # undef ntohl
327 # undef ntohs
328 # undef htonl
329 # undef htons
331 # define ___htonl(x) __cpu_to_be32(x)
332 # define ___htons(x) __cpu_to_be16(x)
333 # define ___ntohl(x) __be32_to_cpu(x)
334 # define ___ntohs(x) __be16_to_cpu(x)
336 # define htonl(x) ___htonl(x)
337 # define ntohl(x) ___ntohl(x)
338 # define htons(x) ___htons(x)
339 # define ntohs(x) ___ntohs(x)
341 static inline void le16_add_cpu(__le16 *var, u16 val)
343 *var = cpu_to_le16(le16_to_cpup(var) + val);
346 static inline void le32_add_cpu(__le32 *var, u32 val)
348 *var = cpu_to_le32(le32_to_cpup(var) + val);
351 static inline void le64_add_cpu(__le64 *var, u64 val)
353 *var = cpu_to_le64(le64_to_cpup(var) + val);
356 static inline void be16_add_cpu(__be16 *var, u16 val)
358 *var = cpu_to_be16(be16_to_cpup(var) + val);
361 static inline void be32_add_cpu(__be32 *var, u32 val)
363 *var = cpu_to_be32(be32_to_cpup(var) + val);
366 static inline void be64_add_cpu(__be64 *var, u64 val)
368 *var = cpu_to_be64(be64_to_cpup(var) + val);
371 #endif /* __KERNEL__ */
372 #endif /* _LINUX_BYTEORDER_H */