generic.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef _LINUX_BYTEORDER_GENERIC_H
  2. #define _LINUX_BYTEORDER_GENERIC_H
  3. /*
  4. * linux/byteorder_generic.h
  5. * Generic Byte-reordering support
  6. *
  7. * Francois-Rene Rideau <fare@tunes.org> 19970707
  8. * gathered all the good ideas from all asm-foo/byteorder.h into one file,
  9. * cleaned them up.
  10. * I hope it is compliant with non-GCC compilers.
  11. * I decided to put __BYTEORDER_HAS_U64__ in byteorder.h,
  12. * because I wasn't sure it would be ok to put it in types.h
  13. * Upgraded it to 2.1.43
  14. * Francois-Rene Rideau <fare@tunes.org> 19971012
  15. * Upgraded it to 2.1.57
  16. * to please Linus T., replaced huge #ifdef's between little/big endian
  17. * by nestedly #include'd files.
  18. * Francois-Rene Rideau <fare@tunes.org> 19971205
  19. * Made it to 2.1.71; now a facelift:
  20. * Put files under include/linux/byteorder/
  21. * Split swab from generic support.
  22. *
  23. * TODO:
  24. * = Regular kernel maintainers could also replace all these manual
  25. * byteswap macros that remain, disseminated among drivers,
  26. * after some grep or the sources...
  27. * = Linus might want to rename all these macros and files to fit his taste,
  28. * to fit his personal naming scheme.
  29. * = it seems that a few drivers would also appreciate
  30. * nybble swapping support...
  31. * = every architecture could add their byteswap macro in asm/byteorder.h
  32. * see how some architectures already do (i386, alpha, ppc, etc)
  33. * = cpu_to_beXX and beXX_to_cpu might some day need to be well
  34. * distinguished throughout the kernel. This is not the case currently,
  35. * since little endian, big endian, and pdp endian machines needn't it.
  36. * But this might be the case for, say, a port of Linux to 20/21 bit
  37. * architectures (and F21 Linux addict around?).
  38. */
  39. /*
  40. * The following macros are to be defined by <asm/byteorder.h>:
  41. *
  42. * Conversion of long and short int between network and host format
  43. * ntohl(__u32 x)
  44. * ntohs(__u16 x)
  45. * htonl(__u32 x)
  46. * htons(__u16 x)
  47. * It seems that some programs (which? where? or perhaps a standard? POSIX?)
  48. * might like the above to be functions, not macros (why?).
  49. * if that's true, then detect them, and take measures.
  50. * Anyway, the measure is: define only ___ntohl as a macro instead,
  51. * and in a separate file, have
  52. * unsigned long inline ntohl(x){return ___ntohl(x);}
  53. *
  54. * The same for constant arguments
  55. * __constant_ntohl(__u32 x)
  56. * __constant_ntohs(__u16 x)
  57. * __constant_htonl(__u32 x)
  58. * __constant_htons(__u16 x)
  59. *
  60. * Conversion of XX-bit integers (16- 32- or 64-)
  61. * between native CPU format and little/big endian format
  62. * 64-bit stuff only defined for proper architectures
  63. * cpu_to_[bl]eXX(__uXX x)
  64. * [bl]eXX_to_cpu(__uXX x)
  65. *
  66. * The same, but takes a pointer to the value to convert
  67. * cpu_to_[bl]eXXp(__uXX x)
  68. * [bl]eXX_to_cpup(__uXX x)
  69. *
  70. * The same, but change in situ
  71. * cpu_to_[bl]eXXs(__uXX x)
  72. * [bl]eXX_to_cpus(__uXX x)
  73. *
  74. * See asm-foo/byteorder.h for examples of how to provide
  75. * architecture-optimized versions
  76. *
  77. */
  78. /*
  79. * inside the kernel, we can use nicknames;
  80. * outside of it, we must avoid POSIX namespace pollution...
  81. */
  82. #define cpu_to_le64 __cpu_to_le64
  83. #define le64_to_cpu __le64_to_cpu
  84. #define cpu_to_le32 __cpu_to_le32
  85. #define le32_to_cpu __le32_to_cpu
  86. #define cpu_to_le16 __cpu_to_le16
  87. #define le16_to_cpu __le16_to_cpu
  88. #define cpu_to_be64 __cpu_to_be64
  89. #define be64_to_cpu __be64_to_cpu
  90. #define cpu_to_be32 __cpu_to_be32
  91. #define be32_to_cpu __be32_to_cpu
  92. #define cpu_to_be16 __cpu_to_be16
  93. #define be16_to_cpu __be16_to_cpu
  94. #define cpu_to_le64p __cpu_to_le64p
  95. #define le64_to_cpup __le64_to_cpup
  96. #define cpu_to_le32p __cpu_to_le32p
  97. #define le32_to_cpup __le32_to_cpup
  98. #define cpu_to_le16p __cpu_to_le16p
  99. #define le16_to_cpup __le16_to_cpup
  100. #define cpu_to_be64p __cpu_to_be64p
  101. #define be64_to_cpup __be64_to_cpup
  102. #define cpu_to_be32p __cpu_to_be32p
  103. #define be32_to_cpup __be32_to_cpup
  104. #define cpu_to_be16p __cpu_to_be16p
  105. #define be16_to_cpup __be16_to_cpup
  106. #define cpu_to_le64s __cpu_to_le64s
  107. #define le64_to_cpus __le64_to_cpus
  108. #define cpu_to_le32s __cpu_to_le32s
  109. #define le32_to_cpus __le32_to_cpus
  110. #define cpu_to_le16s __cpu_to_le16s
  111. #define le16_to_cpus __le16_to_cpus
  112. #define cpu_to_be64s __cpu_to_be64s
  113. #define be64_to_cpus __be64_to_cpus
  114. #define cpu_to_be32s __cpu_to_be32s
  115. #define be32_to_cpus __be32_to_cpus
  116. #define cpu_to_be16s __cpu_to_be16s
  117. #define be16_to_cpus __be16_to_cpus
  118. /*
  119. * Handle ntohl and suches. These have various compatibility
  120. * issues - like we want to give the prototype even though we
  121. * also have a macro for them in case some strange program
  122. * wants to take the address of the thing or something..
  123. *
  124. * Note that these used to return a "long" in libc5, even though
  125. * long is often 64-bit these days.. Thus the casts.
  126. *
  127. * They have to be macros in order to do the constant folding
  128. * correctly - if the argument passed into a inline function
  129. * it is no longer constant according to gcc..
  130. */
  131. #undef ntohl
  132. #undef ntohs
  133. #undef htonl
  134. #undef htons
  135. /*
  136. * Do the prototypes. Somebody might want to take the
  137. * address or some such sick thing..
  138. */
  139. extern __u32 ntohl(__u32);
  140. extern __u32 htonl(__u32);
  141. extern unsigned short int ntohs(unsigned short int);
  142. extern unsigned short int htons(unsigned short int);
  143. #endif /* _LINUX_BYTEORDER_GENERIC_H */