acmacros.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
  2. /******************************************************************************
  3. *
  4. * Name: acmacros.h - C macros for the entire subsystem.
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #ifndef __ACMACROS_H__
  10. #define __ACMACROS_H__
  11. /*
  12. * Extract data using a pointer. Any more than a byte and we
  13. * get into potential alignment issues -- see the STORE macros below.
  14. * Use with care.
  15. */
  16. #define ACPI_CAST8(ptr) ACPI_CAST_PTR (u8, (ptr))
  17. #define ACPI_CAST16(ptr) ACPI_CAST_PTR (u16, (ptr))
  18. #define ACPI_CAST32(ptr) ACPI_CAST_PTR (u32, (ptr))
  19. #define ACPI_CAST64(ptr) ACPI_CAST_PTR (u64, (ptr))
  20. #define ACPI_GET8(ptr) (*ACPI_CAST8 (ptr))
  21. #define ACPI_GET16(ptr) (*ACPI_CAST16 (ptr))
  22. #define ACPI_GET32(ptr) (*ACPI_CAST32 (ptr))
  23. #define ACPI_GET64(ptr) (*ACPI_CAST64 (ptr))
  24. #define ACPI_SET8(ptr, val) (*ACPI_CAST8 (ptr) = (u8) (val))
  25. #define ACPI_SET16(ptr, val) (*ACPI_CAST16 (ptr) = (u16) (val))
  26. #define ACPI_SET32(ptr, val) (*ACPI_CAST32 (ptr) = (u32) (val))
  27. #define ACPI_SET64(ptr, val) (*ACPI_CAST64 (ptr) = (u64) (val))
  28. /*
  29. * printf() format helper. This macro is a workaround for the difficulties
  30. * with emitting 64-bit integers and 64-bit pointers with the same code
  31. * for both 32-bit and 64-bit hosts.
  32. */
  33. #define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i), ACPI_LODWORD(i)
  34. /*
  35. * Macros for moving data around to/from buffers that are possibly unaligned.
  36. * If the hardware supports the transfer of unaligned data, just do the store.
  37. * Otherwise, we have to move one byte at a time.
  38. */
  39. #ifdef ACPI_BIG_ENDIAN
  40. /*
  41. * Macros for big-endian machines
  42. */
  43. /* These macros reverse the bytes during the move, converting little-endian to big endian */
  44. /* Big Endian <== Little Endian */
  45. /* Hi...Lo Lo...Hi */
  46. /* 16-bit source, 16/32/64 destination */
  47. #define ACPI_MOVE_16_TO_16(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[1];\
  48. (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[0];}
  49. #define ACPI_MOVE_16_TO_32(d, s) {(*(u32 *)(void *)(d))=0;\
  50. ((u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\
  51. ((u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];}
  52. #define ACPI_MOVE_16_TO_64(d, s) {(*(u64 *)(void *)(d))=0;\
  53. ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
  54. ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
  55. /* 32-bit source, 16/32/64 destination */
  56. #define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
  57. #define ACPI_MOVE_32_TO_32(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[3];\
  58. (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[2];\
  59. (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\
  60. (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];}
  61. #define ACPI_MOVE_32_TO_64(d, s) {(*(u64 *)(void *)(d))=0;\
  62. ((u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\
  63. ((u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[2];\
  64. ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
  65. ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
  66. /* 64-bit source, 16/32/64 destination */
  67. #define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
  68. #define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */
  69. #define ACPI_MOVE_64_TO_64(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[7];\
  70. (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[6];\
  71. (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[5];\
  72. (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[4];\
  73. (( u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\
  74. (( u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[2];\
  75. (( u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
  76. (( u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
  77. #else
  78. /*
  79. * Macros for little-endian machines
  80. */
  81. #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
  82. /* The hardware supports unaligned transfers, just do the little-endian move */
  83. /* 16-bit source, 16/32/64 destination */
  84. #define ACPI_MOVE_16_TO_16(d, s) *(u16 *)(void *)(d) = *(u16 *)(void *)(s)
  85. #define ACPI_MOVE_16_TO_32(d, s) *(u32 *)(void *)(d) = *(u16 *)(void *)(s)
  86. #define ACPI_MOVE_16_TO_64(d, s) *(u64 *)(void *)(d) = *(u16 *)(void *)(s)
  87. /* 32-bit source, 16/32/64 destination */
  88. #define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
  89. #define ACPI_MOVE_32_TO_32(d, s) *(u32 *)(void *)(d) = *(u32 *)(void *)(s)
  90. #define ACPI_MOVE_32_TO_64(d, s) *(u64 *)(void *)(d) = *(u32 *)(void *)(s)
  91. /* 64-bit source, 16/32/64 destination */
  92. #define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
  93. #define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */
  94. #define ACPI_MOVE_64_TO_64(d, s) *(u64 *)(void *)(d) = *(u64 *)(void *)(s)
  95. #else
  96. /*
  97. * The hardware does not support unaligned transfers. We must move the
  98. * data one byte at a time. These macros work whether the source or
  99. * the destination (or both) is/are unaligned. (Little-endian move)
  100. */
  101. /* 16-bit source, 16/32/64 destination */
  102. #define ACPI_MOVE_16_TO_16(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\
  103. (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];}
  104. #define ACPI_MOVE_16_TO_32(d, s) {(*(u32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
  105. #define ACPI_MOVE_16_TO_64(d, s) {(*(u64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
  106. /* 32-bit source, 16/32/64 destination */
  107. #define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
  108. #define ACPI_MOVE_32_TO_32(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\
  109. (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];\
  110. (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[2];\
  111. (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[3];}
  112. #define ACPI_MOVE_32_TO_64(d, s) {(*(u64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);}
  113. /* 64-bit source, 16/32/64 destination */
  114. #define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
  115. #define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */
  116. #define ACPI_MOVE_64_TO_64(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\
  117. (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];\
  118. (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[2];\
  119. (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[3];\
  120. (( u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[4];\
  121. (( u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[5];\
  122. (( u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[6];\
  123. (( u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[7];}
  124. #endif
  125. #endif
  126. /*
  127. * Fast power-of-two math macros for non-optimized compilers
  128. */
  129. #define _ACPI_DIV(value, power_of2) ((u32) ((value) >> (power_of2)))
  130. #define _ACPI_MUL(value, power_of2) ((u32) ((value) << (power_of2)))
  131. #define _ACPI_MOD(value, divisor) ((u32) ((value) & ((divisor) -1)))
  132. #define ACPI_DIV_2(a) _ACPI_DIV(a, 1)
  133. #define ACPI_MUL_2(a) _ACPI_MUL(a, 1)
  134. #define ACPI_MOD_2(a) _ACPI_MOD(a, 2)
  135. #define ACPI_DIV_4(a) _ACPI_DIV(a, 2)
  136. #define ACPI_MUL_4(a) _ACPI_MUL(a, 2)
  137. #define ACPI_MOD_4(a) _ACPI_MOD(a, 4)
  138. #define ACPI_DIV_8(a) _ACPI_DIV(a, 3)
  139. #define ACPI_MUL_8(a) _ACPI_MUL(a, 3)
  140. #define ACPI_MOD_8(a) _ACPI_MOD(a, 8)
  141. #define ACPI_DIV_16(a) _ACPI_DIV(a, 4)
  142. #define ACPI_MUL_16(a) _ACPI_MUL(a, 4)
  143. #define ACPI_MOD_16(a) _ACPI_MOD(a, 16)
  144. #define ACPI_DIV_32(a) _ACPI_DIV(a, 5)
  145. #define ACPI_MUL_32(a) _ACPI_MUL(a, 5)
  146. #define ACPI_MOD_32(a) _ACPI_MOD(a, 32)
  147. /* Test for ASCII character */
  148. #define ACPI_IS_ASCII(c) ((c) < 0x80)
  149. /* Signed integers */
  150. #define ACPI_SIGN_POSITIVE 0
  151. #define ACPI_SIGN_NEGATIVE 1
  152. /*
  153. * Rounding macros (Power of two boundaries only)
  154. */
  155. #define ACPI_ROUND_DOWN(value, boundary) (((acpi_size)(value)) & \
  156. (~(((acpi_size) boundary)-1)))
  157. #define ACPI_ROUND_UP(value, boundary) ((((acpi_size)(value)) + \
  158. (((acpi_size) boundary)-1)) & \
  159. (~(((acpi_size) boundary)-1)))
  160. /* Note: sizeof(acpi_size) evaluates to either 4 or 8 (32- vs 64-bit mode) */
  161. #define ACPI_ROUND_DOWN_TO_32BIT(a) ACPI_ROUND_DOWN(a, 4)
  162. #define ACPI_ROUND_DOWN_TO_64BIT(a) ACPI_ROUND_DOWN(a, 8)
  163. #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a, sizeof(acpi_size))
  164. #define ACPI_ROUND_UP_TO_32BIT(a) ACPI_ROUND_UP(a, 4)
  165. #define ACPI_ROUND_UP_TO_64BIT(a) ACPI_ROUND_UP(a, 8)
  166. #define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a, sizeof(acpi_size))
  167. #define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7)
  168. #define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a))
  169. #define ACPI_ROUND_UP_TO_1K(a) (((a) + 1023) >> 10)
  170. /* Generic (non-power-of-two) rounding */
  171. #define ACPI_ROUND_UP_TO(value, boundary) (((value) + ((boundary)-1)) / (boundary))
  172. #define ACPI_IS_MISALIGNED(value) (((acpi_size) value) & (sizeof(acpi_size)-1))
  173. /* Generic bit manipulation */
  174. #ifndef ACPI_USE_NATIVE_BIT_FINDER
  175. #define __ACPI_FIND_LAST_BIT_2(a, r) ((((u8) (a)) & 0x02) ? (r)+1 : (r))
  176. #define __ACPI_FIND_LAST_BIT_4(a, r) ((((u8) (a)) & 0x0C) ? \
  177. __ACPI_FIND_LAST_BIT_2 ((a)>>2, (r)+2) : \
  178. __ACPI_FIND_LAST_BIT_2 ((a), (r)))
  179. #define __ACPI_FIND_LAST_BIT_8(a, r) ((((u8) (a)) & 0xF0) ? \
  180. __ACPI_FIND_LAST_BIT_4 ((a)>>4, (r)+4) : \
  181. __ACPI_FIND_LAST_BIT_4 ((a), (r)))
  182. #define __ACPI_FIND_LAST_BIT_16(a, r) ((((u16) (a)) & 0xFF00) ? \
  183. __ACPI_FIND_LAST_BIT_8 ((a)>>8, (r)+8) : \
  184. __ACPI_FIND_LAST_BIT_8 ((a), (r)))
  185. #define __ACPI_FIND_LAST_BIT_32(a, r) ((((u32) (a)) & 0xFFFF0000) ? \
  186. __ACPI_FIND_LAST_BIT_16 ((a)>>16, (r)+16) : \
  187. __ACPI_FIND_LAST_BIT_16 ((a), (r)))
  188. #define __ACPI_FIND_LAST_BIT_64(a, r) ((((u64) (a)) & 0xFFFFFFFF00000000) ? \
  189. __ACPI_FIND_LAST_BIT_32 ((a)>>32, (r)+32) : \
  190. __ACPI_FIND_LAST_BIT_32 ((a), (r)))
  191. #define ACPI_FIND_LAST_BIT_8(a) ((a) ? __ACPI_FIND_LAST_BIT_8 (a, 1) : 0)
  192. #define ACPI_FIND_LAST_BIT_16(a) ((a) ? __ACPI_FIND_LAST_BIT_16 (a, 1) : 0)
  193. #define ACPI_FIND_LAST_BIT_32(a) ((a) ? __ACPI_FIND_LAST_BIT_32 (a, 1) : 0)
  194. #define ACPI_FIND_LAST_BIT_64(a) ((a) ? __ACPI_FIND_LAST_BIT_64 (a, 1) : 0)
  195. #define __ACPI_FIND_FIRST_BIT_2(a, r) ((((u8) (a)) & 0x01) ? (r) : (r)+1)
  196. #define __ACPI_FIND_FIRST_BIT_4(a, r) ((((u8) (a)) & 0x03) ? \
  197. __ACPI_FIND_FIRST_BIT_2 ((a), (r)) : \
  198. __ACPI_FIND_FIRST_BIT_2 ((a)>>2, (r)+2))
  199. #define __ACPI_FIND_FIRST_BIT_8(a, r) ((((u8) (a)) & 0x0F) ? \
  200. __ACPI_FIND_FIRST_BIT_4 ((a), (r)) : \
  201. __ACPI_FIND_FIRST_BIT_4 ((a)>>4, (r)+4))
  202. #define __ACPI_FIND_FIRST_BIT_16(a, r) ((((u16) (a)) & 0x00FF) ? \
  203. __ACPI_FIND_FIRST_BIT_8 ((a), (r)) : \
  204. __ACPI_FIND_FIRST_BIT_8 ((a)>>8, (r)+8))
  205. #define __ACPI_FIND_FIRST_BIT_32(a, r) ((((u32) (a)) & 0x0000FFFF) ? \
  206. __ACPI_FIND_FIRST_BIT_16 ((a), (r)) : \
  207. __ACPI_FIND_FIRST_BIT_16 ((a)>>16, (r)+16))
  208. #define __ACPI_FIND_FIRST_BIT_64(a, r) ((((u64) (a)) & 0x00000000FFFFFFFF) ? \
  209. __ACPI_FIND_FIRST_BIT_32 ((a), (r)) : \
  210. __ACPI_FIND_FIRST_BIT_32 ((a)>>32, (r)+32))
  211. #define ACPI_FIND_FIRST_BIT_8(a) ((a) ? __ACPI_FIND_FIRST_BIT_8 (a, 1) : 0)
  212. #define ACPI_FIND_FIRST_BIT_16(a) ((a) ? __ACPI_FIND_FIRST_BIT_16 (a, 1) : 0)
  213. #define ACPI_FIND_FIRST_BIT_32(a) ((a) ? __ACPI_FIND_FIRST_BIT_32 (a, 1) : 0)
  214. #define ACPI_FIND_FIRST_BIT_64(a) ((a) ? __ACPI_FIND_FIRST_BIT_64 (a, 1) : 0)
  215. #endif /* ACPI_USE_NATIVE_BIT_FINDER */
  216. /* Generic (power-of-two) rounding */
  217. #define ACPI_ROUND_UP_POWER_OF_TWO_8(a) ((u8) \
  218. (((u16) 1) << ACPI_FIND_LAST_BIT_8 ((a) - 1)))
  219. #define ACPI_ROUND_DOWN_POWER_OF_TWO_8(a) ((u8) \
  220. (((u16) 1) << (ACPI_FIND_LAST_BIT_8 ((a)) - 1)))
  221. #define ACPI_ROUND_UP_POWER_OF_TWO_16(a) ((u16) \
  222. (((u32) 1) << ACPI_FIND_LAST_BIT_16 ((a) - 1)))
  223. #define ACPI_ROUND_DOWN_POWER_OF_TWO_16(a) ((u16) \
  224. (((u32) 1) << (ACPI_FIND_LAST_BIT_16 ((a)) - 1)))
  225. #define ACPI_ROUND_UP_POWER_OF_TWO_32(a) ((u32) \
  226. (((u64) 1) << ACPI_FIND_LAST_BIT_32 ((a) - 1)))
  227. #define ACPI_ROUND_DOWN_POWER_OF_TWO_32(a) ((u32) \
  228. (((u64) 1) << (ACPI_FIND_LAST_BIT_32 ((a)) - 1)))
  229. #define ACPI_IS_ALIGNED(a, s) (((a) & ((s) - 1)) == 0)
  230. #define ACPI_IS_POWER_OF_TWO(a) ACPI_IS_ALIGNED(a, a)
  231. /*
  232. * Bitmask creation
  233. * Bit positions start at zero.
  234. * MASK_BITS_ABOVE creates a mask starting AT the position and above
  235. * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
  236. * MASK_BITS_ABOVE/BELOW accepts a bit offset to create a mask
  237. * MASK_BITS_ABOVE/BELOW_32/64 accepts a bit width to create a mask
  238. * Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
  239. * differences with the shift operator
  240. */
  241. #define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_UINT64_MAX) << ((u32) (position))))
  242. #define ACPI_MASK_BITS_BELOW(position) ((ACPI_UINT64_MAX) << ((u32) (position)))
  243. #define ACPI_MASK_BITS_ABOVE_32(width) ((u32) ACPI_MASK_BITS_ABOVE(width))
  244. #define ACPI_MASK_BITS_BELOW_32(width) ((u32) ACPI_MASK_BITS_BELOW(width))
  245. #define ACPI_MASK_BITS_ABOVE_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
  246. ACPI_UINT64_MAX : \
  247. ACPI_MASK_BITS_ABOVE(width))
  248. #define ACPI_MASK_BITS_BELOW_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
  249. (u64) 0 : \
  250. ACPI_MASK_BITS_BELOW(width))
  251. /* Bitfields within ACPI registers */
  252. #define ACPI_REGISTER_PREPARE_BITS(val, pos, mask) \
  253. ((val << pos) & mask)
  254. #define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val) \
  255. reg = (reg & (~(mask))) | ACPI_REGISTER_PREPARE_BITS(val, pos, mask)
  256. #define ACPI_INSERT_BITS(target, mask, source) \
  257. target = ((target & (~(mask))) | (source & mask))
  258. /* Generic bitfield macros and masks */
  259. #define ACPI_GET_BITS(source_ptr, position, mask) \
  260. ((*(source_ptr) >> (position)) & (mask))
  261. #define ACPI_SET_BITS(target_ptr, position, mask, value) \
  262. (*(target_ptr) |= (((value) & (mask)) << (position)))
  263. #define ACPI_1BIT_MASK 0x00000001
  264. #define ACPI_2BIT_MASK 0x00000003
  265. #define ACPI_3BIT_MASK 0x00000007
  266. #define ACPI_4BIT_MASK 0x0000000F
  267. #define ACPI_5BIT_MASK 0x0000001F
  268. #define ACPI_6BIT_MASK 0x0000003F
  269. #define ACPI_7BIT_MASK 0x0000007F
  270. #define ACPI_8BIT_MASK 0x000000FF
  271. #define ACPI_16BIT_MASK 0x0000FFFF
  272. #define ACPI_24BIT_MASK 0x00FFFFFF
  273. /* Macros to extract flag bits from position zero */
  274. #define ACPI_GET_1BIT_FLAG(value) ((value) & ACPI_1BIT_MASK)
  275. #define ACPI_GET_2BIT_FLAG(value) ((value) & ACPI_2BIT_MASK)
  276. #define ACPI_GET_3BIT_FLAG(value) ((value) & ACPI_3BIT_MASK)
  277. #define ACPI_GET_4BIT_FLAG(value) ((value) & ACPI_4BIT_MASK)
  278. /* Macros to extract flag bits from position one and above */
  279. #define ACPI_EXTRACT_1BIT_FLAG(field, position) (ACPI_GET_1BIT_FLAG ((field) >> position))
  280. #define ACPI_EXTRACT_2BIT_FLAG(field, position) (ACPI_GET_2BIT_FLAG ((field) >> position))
  281. #define ACPI_EXTRACT_3BIT_FLAG(field, position) (ACPI_GET_3BIT_FLAG ((field) >> position))
  282. #define ACPI_EXTRACT_4BIT_FLAG(field, position) (ACPI_GET_4BIT_FLAG ((field) >> position))
  283. /* ACPI Pathname helpers */
  284. #define ACPI_IS_ROOT_PREFIX(c) ((c) == (u8) 0x5C) /* Backslash */
  285. #define ACPI_IS_PARENT_PREFIX(c) ((c) == (u8) 0x5E) /* Carat */
  286. #define ACPI_IS_PATH_SEPARATOR(c) ((c) == (u8) 0x2E) /* Period (dot) */
  287. /*
  288. * An object of type struct acpi_namespace_node can appear in some contexts
  289. * where a pointer to an object of type union acpi_operand_object can also
  290. * appear. This macro is used to distinguish them.
  291. *
  292. * The "DescriptorType" field is the second field in both structures.
  293. */
  294. #define ACPI_GET_DESCRIPTOR_PTR(d) (((union acpi_descriptor *)(void *)(d))->common.common_pointer)
  295. #define ACPI_SET_DESCRIPTOR_PTR(d, p) (((union acpi_descriptor *)(void *)(d))->common.common_pointer = (p))
  296. #define ACPI_GET_DESCRIPTOR_TYPE(d) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type)
  297. #define ACPI_SET_DESCRIPTOR_TYPE(d, t) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type = (t))
  298. /*
  299. * Macros for the master AML opcode table
  300. */
  301. #if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
  302. #define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags) \
  303. {name, (u32)(Pargs), (u32)(Iargs), (u32)(flags), obj_type, class, type}
  304. #else
  305. #define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags) \
  306. {(u32)(Pargs), (u32)(Iargs), (u32)(flags), obj_type, class, type}
  307. #endif
  308. #define ARG_TYPE_WIDTH 5
  309. #define ARG_1(x) ((u32)(x))
  310. #define ARG_2(x) ((u32)(x) << (1 * ARG_TYPE_WIDTH))
  311. #define ARG_3(x) ((u32)(x) << (2 * ARG_TYPE_WIDTH))
  312. #define ARG_4(x) ((u32)(x) << (3 * ARG_TYPE_WIDTH))
  313. #define ARG_5(x) ((u32)(x) << (4 * ARG_TYPE_WIDTH))
  314. #define ARG_6(x) ((u32)(x) << (5 * ARG_TYPE_WIDTH))
  315. #define ARGI_LIST1(a) (ARG_1(a))
  316. #define ARGI_LIST2(a, b) (ARG_1(b)|ARG_2(a))
  317. #define ARGI_LIST3(a, b, c) (ARG_1(c)|ARG_2(b)|ARG_3(a))
  318. #define ARGI_LIST4(a, b, c, d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
  319. #define ARGI_LIST5(a, b, c, d, e) (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
  320. #define ARGI_LIST6(a, b, c, d, e, f) (ARG_1(f)|ARG_2(e)|ARG_3(d)|ARG_4(c)|ARG_5(b)|ARG_6(a))
  321. #define ARGP_LIST1(a) (ARG_1(a))
  322. #define ARGP_LIST2(a, b) (ARG_1(a)|ARG_2(b))
  323. #define ARGP_LIST3(a, b, c) (ARG_1(a)|ARG_2(b)|ARG_3(c))
  324. #define ARGP_LIST4(a, b, c, d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
  325. #define ARGP_LIST5(a, b, c, d, e) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
  326. #define ARGP_LIST6(a, b, c, d, e, f) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e)|ARG_6(f))
  327. #define GET_CURRENT_ARG_TYPE(list) (list & ((u32) 0x1F))
  328. #define INCREMENT_ARG_LIST(list) (list >>= ((u32) ARG_TYPE_WIDTH))
  329. /*
  330. * Ascii error messages can be configured out
  331. */
  332. #ifndef ACPI_NO_ERROR_MESSAGES
  333. /*
  334. * Error reporting. The callers module and line number are inserted by AE_INFO,
  335. * the plist contains a set of parens to allow variable-length lists.
  336. * These macros are used for both the debug and non-debug versions of the code.
  337. */
  338. #define ACPI_ERROR_NAMESPACE(s, p, e) acpi_ut_prefixed_namespace_error (AE_INFO, s, p, e);
  339. #define ACPI_ERROR_METHOD(s, n, p, e) acpi_ut_method_error (AE_INFO, s, n, p, e);
  340. #define ACPI_WARN_PREDEFINED(plist) acpi_ut_predefined_warning plist
  341. #define ACPI_INFO_PREDEFINED(plist) acpi_ut_predefined_info plist
  342. #define ACPI_BIOS_ERROR_PREDEFINED(plist) acpi_ut_predefined_bios_error plist
  343. #define ACPI_ERROR_ONLY(s) s
  344. #else
  345. /* No error messages */
  346. #define ACPI_ERROR_NAMESPACE(s, p, e)
  347. #define ACPI_ERROR_METHOD(s, n, p, e)
  348. #define ACPI_WARN_PREDEFINED(plist)
  349. #define ACPI_INFO_PREDEFINED(plist)
  350. #define ACPI_BIOS_ERROR_PREDEFINED(plist)
  351. #define ACPI_ERROR_ONLY(s)
  352. #endif /* ACPI_NO_ERROR_MESSAGES */
  353. #if (!ACPI_REDUCED_HARDWARE)
  354. #define ACPI_HW_OPTIONAL_FUNCTION(addr) addr
  355. #else
  356. #define ACPI_HW_OPTIONAL_FUNCTION(addr) NULL
  357. #endif
  358. /*
  359. * Macros used for ACPICA utilities only
  360. */
  361. /* Generate a UUID */
  362. #define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
  363. (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \
  364. (b) & 0xFF, ((b) >> 8) & 0xFF, \
  365. (c) & 0xFF, ((c) >> 8) & 0xFF, \
  366. (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)
  367. #define ACPI_IS_OCTAL_DIGIT(d) (((char)(d) >= '0') && ((char)(d) <= '7'))
  368. /*
  369. * Macros used for the ASL-/ASL+ converter utility
  370. */
  371. #ifdef ACPI_ASL_COMPILER
  372. #define ASL_CV_LABEL_FILENODE(a) cv_label_file_node(a);
  373. #define ASL_CV_CAPTURE_COMMENTS_ONLY(a) cv_capture_comments_only (a);
  374. #define ASL_CV_CAPTURE_COMMENTS(a) cv_capture_comments (a);
  375. #define ASL_CV_TRANSFER_COMMENTS(a) cv_transfer_comments (a);
  376. #define ASL_CV_CLOSE_PAREN(a,b) cv_close_paren_write_comment(a,b);
  377. #define ASL_CV_CLOSE_BRACE(a,b) cv_close_brace_write_comment(a,b);
  378. #define ASL_CV_SWITCH_FILES(a,b) cv_switch_files(a,b);
  379. #define ASL_CV_CLEAR_OP_COMMENTS(a) cv_clear_op_comments(a);
  380. #define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d) cv_print_one_comment_type (a,b,c,d);
  381. #define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b) cv_print_one_comment_list (a,b);
  382. #define ASL_CV_FILE_HAS_SWITCHED(a) cv_file_has_switched(a)
  383. #define ASL_CV_INIT_FILETREE(a,b) cv_init_file_tree(a,b);
  384. #else
  385. #define ASL_CV_LABEL_FILENODE(a)
  386. #define ASL_CV_CAPTURE_COMMENTS_ONLY(a)
  387. #define ASL_CV_CAPTURE_COMMENTS(a)
  388. #define ASL_CV_TRANSFER_COMMENTS(a)
  389. #define ASL_CV_CLOSE_PAREN(a,b) acpi_os_printf (")");
  390. #define ASL_CV_CLOSE_BRACE(a,b) acpi_os_printf ("}");
  391. #define ASL_CV_SWITCH_FILES(a,b)
  392. #define ASL_CV_CLEAR_OP_COMMENTS(a)
  393. #define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d)
  394. #define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b)
  395. #define ASL_CV_FILE_HAS_SWITCHED(a) 0
  396. #define ASL_CV_INIT_FILETREE(a,b)
  397. #endif
  398. #endif /* ACMACROS_H */