1 #ifndef _LINUX_BYTEORDER_GENERIC_H 2 #define _LINUX_BYTEORDER_GENERIC_H 3 4 /* 5 * linux/byteorder_generic.h 6 * Generic Byte-reordering support 7 * 8 * The "... p" macros, like le64_to_cpup, can be used with pointers 9 * to unaligned data, but there will be a performance penalty on 10 * some architectures. Use get_unaligned for unaligned data. 11 * 12 * Francois-Rene Rideau <fare (at) tunes.org> 19970707 13 * gathered all the good ideas from all asm-foo/byteorder.h into one file, 14 * cleaned them up. 15 * I hope it is compliant with non-GCC compilers. 16 * I decided to put __BYTEORDER_HAS_U64__ in byteorder.h, 17 * because I wasn't sure it would be ok to put it in types.h 18 * Upgraded it to 2.1.43 19 * Francois-Rene Rideau <fare (at) tunes.org> 19971012 20 * Upgraded it to 2.1.57 21 * to please Linus T., replaced huge #ifdef's between little/big endian 22 * by nestedly #include'd files. 23 * Francois-Rene Rideau <fare (at) tunes.org> 19971205 24 * Made it to 2.1.71; now a facelift: 25 * Put files under include/linux/byteorder/ 26 * Split swab from generic support. 27 * 28 * TODO: 29 * = Regular kernel maintainers could also replace all these manual 30 * byteswap macros that remain, disseminated among drivers, 31 * after some grep or the sources... 32 * = Linus might want to rename all these macros and files to fit his taste, 33 * to fit his personal naming scheme. 34 * = it seems that a few drivers would also appreciate 35 * nybble swapping support... 36 * = every architecture could add their byteswap macro in asm/byteorder.h 37 * see how some architectures already do (i386, alpha, ppc, etc) 38 * = cpu_to_beXX and beXX_to_cpu might some day need to be well 39 * distinguished throughout the kernel. This is not the case currently, 40 * since little endian, big endian, and pdp endian machines needn't it. 41 * But this might be the case for, say, a port of Linux to 20/21 bit 42 * architectures (and F21 Linux addict around?). 43 */ 44 45 /* 46 * The following macros are to be defined by <asm/byteorder.h>: 47 * 48 * Conversion of long and short int between network and host format 49 * ntohl(__u32 x) 50 * ntohs(__u16 x) 51 * htonl(__u32 x) 52 * htons(__u16 x) 53 * It seems that some programs (which? where? or perhaps a standard? POSIX?) 54 * might like the above to be functions, not macros (why?). 55 * if that's true, then detect them, and take measures. 56 * Anyway, the measure is: define only ___ntohl as a macro instead, 57 * and in a separate file, have 58 * unsigned long __inline__ ntohl(x){return ___ntohl(x);} 59 * 60 * The same for constant arguments 61 * __constant_ntohl(__u32 x) 62 * __constant_ntohs(__u16 x) 63 * __constant_htonl(__u32 x) 64 * __constant_htons(__u16 x) 65 * 66 * Conversion of XX-bit integers (16- 32- or 64-) 67 * between native CPU format and little/big endian format 68 * 64-bit stuff only defined for proper architectures 69 * cpu_to_[bl]eXX(__uXX x) 70 * [bl]eXX_to_cpu(__uXX x) 71 * 72 * The same, but takes a pointer to the value to convert 73 * cpu_to_[bl]eXXp(__uXX x) 74 * [bl]eXX_to_cpup(__uXX x) 75 * 76 * The same, but change in situ 77 * cpu_to_[bl]eXXs(__uXX x) 78 * [bl]eXX_to_cpus(__uXX x) 79 * 80 * See asm-foo/byteorder.h for examples of how to provide 81 * architecture-optimized versions 82 * 83 */ 84 85 86 87 #endif /* _LINUX_BYTEORDER_GENERIC_H */ 88