Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
0002 /******************************************************************************
0003  *
0004  * Name: acmacros.h - C macros for the entire subsystem.
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #ifndef __ACMACROS_H__
0011 #define __ACMACROS_H__
0012 
0013 /*
0014  * Extract data using a pointer. Any more than a byte and we
0015  * get into potential alignment issues -- see the STORE macros below.
0016  * Use with care.
0017  */
0018 #define ACPI_CAST8(ptr)                 ACPI_CAST_PTR (u8, (ptr))
0019 #define ACPI_CAST16(ptr)                ACPI_CAST_PTR (u16, (ptr))
0020 #define ACPI_CAST32(ptr)                ACPI_CAST_PTR (u32, (ptr))
0021 #define ACPI_CAST64(ptr)                ACPI_CAST_PTR (u64, (ptr))
0022 #define ACPI_GET8(ptr)                  (*ACPI_CAST8 (ptr))
0023 #define ACPI_GET16(ptr)                 (*ACPI_CAST16 (ptr))
0024 #define ACPI_GET32(ptr)                 (*ACPI_CAST32 (ptr))
0025 #define ACPI_GET64(ptr)                 (*ACPI_CAST64 (ptr))
0026 #define ACPI_SET8(ptr, val)             (*ACPI_CAST8 (ptr) = (u8) (val))
0027 #define ACPI_SET16(ptr, val)            (*ACPI_CAST16 (ptr) = (u16) (val))
0028 #define ACPI_SET32(ptr, val)            (*ACPI_CAST32 (ptr) = (u32) (val))
0029 #define ACPI_SET64(ptr, val)            (*ACPI_CAST64 (ptr) = (u64) (val))
0030 
0031 /*
0032  * printf() format helper. This macro is a workaround for the difficulties
0033  * with emitting 64-bit integers and 64-bit pointers with the same code
0034  * for both 32-bit and 64-bit hosts.
0035  */
0036 #define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i), ACPI_LODWORD(i)
0037 
0038 /*
0039  * Macros for moving data around to/from buffers that are possibly unaligned.
0040  * If the hardware supports the transfer of unaligned data, just do the store.
0041  * Otherwise, we have to move one byte at a time.
0042  */
0043 #ifdef ACPI_BIG_ENDIAN
0044 /*
0045  * Macros for big-endian machines
0046  */
0047 
0048 /* These macros reverse the bytes during the move, converting little-endian to big endian */
0049 
0050      /* Big Endian      <==        Little Endian */
0051      /*  Hi...Lo                     Lo...Hi     */
0052 /* 16-bit source, 16/32/64 destination */
0053 
0054 #define ACPI_MOVE_16_TO_16(d, s)        {((  u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[1];\
0055               ((  u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[0];}
0056 
0057 #define ACPI_MOVE_16_TO_32(d, s)        {(*(u32 *)(void *)(d))=0;\
0058                       ((u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\
0059                       ((u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];}
0060 
0061 #define ACPI_MOVE_16_TO_64(d, s)        {(*(u64 *)(void *)(d))=0;\
0062                                ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
0063                                ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
0064 
0065 /* 32-bit source, 16/32/64 destination */
0066 
0067 #define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
0068 
0069 #define ACPI_MOVE_32_TO_32(d, s)        {((  u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[3];\
0070                                       ((  u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[2];\
0071                                       ((  u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\
0072                                       ((  u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];}
0073 
0074 #define ACPI_MOVE_32_TO_64(d, s)        {(*(u64 *)(void *)(d))=0;\
0075                                            ((u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\
0076                                            ((u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[2];\
0077                                            ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
0078                                            ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
0079 
0080 /* 64-bit source, 16/32/64 destination */
0081 
0082 #define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
0083 
0084 #define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
0085 
0086 #define ACPI_MOVE_64_TO_64(d, s)        {((  u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[7];\
0087                                          ((  u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[6];\
0088                                          ((  u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[5];\
0089                                          ((  u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[4];\
0090                                          ((  u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\
0091                                          ((  u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[2];\
0092                                          ((  u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
0093                                          ((  u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
0094 #else
0095 /*
0096  * Macros for little-endian machines
0097  */
0098 
0099 #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
0100 
0101 /* The hardware supports unaligned transfers, just do the little-endian move */
0102 
0103 /* 16-bit source, 16/32/64 destination */
0104 
0105 #define ACPI_MOVE_16_TO_16(d, s)        *(u16 *)(void *)(d) = *(u16 *)(void *)(s)
0106 #define ACPI_MOVE_16_TO_32(d, s)        *(u32 *)(void *)(d) = *(u16 *)(void *)(s)
0107 #define ACPI_MOVE_16_TO_64(d, s)        *(u64 *)(void *)(d) = *(u16 *)(void *)(s)
0108 
0109 /* 32-bit source, 16/32/64 destination */
0110 
0111 #define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
0112 #define ACPI_MOVE_32_TO_32(d, s)        *(u32 *)(void *)(d) = *(u32 *)(void *)(s)
0113 #define ACPI_MOVE_32_TO_64(d, s)        *(u64 *)(void *)(d) = *(u32 *)(void *)(s)
0114 
0115 /* 64-bit source, 16/32/64 destination */
0116 
0117 #define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
0118 #define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
0119 #define ACPI_MOVE_64_TO_64(d, s)        *(u64 *)(void *)(d) = *(u64 *)(void *)(s)
0120 
0121 #else
0122 /*
0123  * The hardware does not support unaligned transfers. We must move the
0124  * data one byte at a time. These macros work whether the source or
0125  * the destination (or both) is/are unaligned. (Little-endian move)
0126  */
0127 
0128 /* 16-bit source, 16/32/64 destination */
0129 
0130 #define ACPI_MOVE_16_TO_16(d, s)        {((  u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\
0131                                          ((  u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];}
0132 
0133 #define ACPI_MOVE_16_TO_32(d, s)        {(*(u32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
0134 #define ACPI_MOVE_16_TO_64(d, s)        {(*(u64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
0135 
0136 /* 32-bit source, 16/32/64 destination */
0137 
0138 #define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
0139 
0140 #define ACPI_MOVE_32_TO_32(d, s)        {((  u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\
0141                                          ((  u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];\
0142                                          ((  u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[2];\
0143                                          ((  u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[3];}
0144 
0145 #define ACPI_MOVE_32_TO_64(d, s)        {(*(u64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);}
0146 
0147 /* 64-bit source, 16/32/64 destination */
0148 
0149 #define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
0150 #define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
0151 #define ACPI_MOVE_64_TO_64(d, s)        {((  u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\
0152                                          ((  u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];\
0153                                          ((  u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[2];\
0154                                          ((  u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[3];\
0155                                          ((  u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[4];\
0156                                          ((  u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[5];\
0157                                          ((  u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[6];\
0158                                          ((  u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[7];}
0159 #endif
0160 #endif
0161 
0162 /*
0163  * Fast power-of-two math macros for non-optimized compilers
0164  */
0165 #define _ACPI_DIV(value, power_of2)     ((u32) ((value) >> (power_of2)))
0166 #define _ACPI_MUL(value, power_of2)     ((u32) ((value) << (power_of2)))
0167 #define _ACPI_MOD(value, divisor)       ((u32) ((value) & ((divisor) -1)))
0168 
0169 #define ACPI_DIV_2(a)                   _ACPI_DIV(a, 1)
0170 #define ACPI_MUL_2(a)                   _ACPI_MUL(a, 1)
0171 #define ACPI_MOD_2(a)                   _ACPI_MOD(a, 2)
0172 
0173 #define ACPI_DIV_4(a)                   _ACPI_DIV(a, 2)
0174 #define ACPI_MUL_4(a)                   _ACPI_MUL(a, 2)
0175 #define ACPI_MOD_4(a)                   _ACPI_MOD(a, 4)
0176 
0177 #define ACPI_DIV_8(a)                   _ACPI_DIV(a, 3)
0178 #define ACPI_MUL_8(a)                   _ACPI_MUL(a, 3)
0179 #define ACPI_MOD_8(a)                   _ACPI_MOD(a, 8)
0180 
0181 #define ACPI_DIV_16(a)                  _ACPI_DIV(a, 4)
0182 #define ACPI_MUL_16(a)                  _ACPI_MUL(a, 4)
0183 #define ACPI_MOD_16(a)                  _ACPI_MOD(a, 16)
0184 
0185 #define ACPI_DIV_32(a)                  _ACPI_DIV(a, 5)
0186 #define ACPI_MUL_32(a)                  _ACPI_MUL(a, 5)
0187 #define ACPI_MOD_32(a)                  _ACPI_MOD(a, 32)
0188 
0189 /* Test for ASCII character */
0190 
0191 #define ACPI_IS_ASCII(c)                ((c) < 0x80)
0192 
0193 /* Signed integers */
0194 
0195 #define ACPI_SIGN_POSITIVE              0
0196 #define ACPI_SIGN_NEGATIVE              1
0197 
0198 /*
0199  * Rounding macros (Power of two boundaries only)
0200  */
0201 #define ACPI_ROUND_DOWN(value, boundary)    (((acpi_size)(value)) & \
0202                                                 (~(((acpi_size) boundary)-1)))
0203 
0204 #define ACPI_ROUND_UP(value, boundary)      ((((acpi_size)(value)) + \
0205                                                 (((acpi_size) boundary)-1)) & \
0206                                                 (~(((acpi_size) boundary)-1)))
0207 
0208 /* Note: sizeof(acpi_size) evaluates to either 4 or 8 (32- vs 64-bit mode) */
0209 
0210 #define ACPI_ROUND_DOWN_TO_32BIT(a)         ACPI_ROUND_DOWN(a, 4)
0211 #define ACPI_ROUND_DOWN_TO_64BIT(a)         ACPI_ROUND_DOWN(a, 8)
0212 #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)   ACPI_ROUND_DOWN(a, sizeof(acpi_size))
0213 
0214 #define ACPI_ROUND_UP_TO_32BIT(a)           ACPI_ROUND_UP(a, 4)
0215 #define ACPI_ROUND_UP_TO_64BIT(a)           ACPI_ROUND_UP(a, 8)
0216 #define ACPI_ROUND_UP_TO_NATIVE_WORD(a)     ACPI_ROUND_UP(a, sizeof(acpi_size))
0217 
0218 #define ACPI_ROUND_BITS_UP_TO_BYTES(a)      ACPI_DIV_8((a) + 7)
0219 #define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)    ACPI_DIV_8((a))
0220 
0221 #define ACPI_ROUND_UP_TO_1K(a)              (((a) + 1023) >> 10)
0222 
0223 /* Generic (non-power-of-two) rounding */
0224 
0225 #define ACPI_ROUND_UP_TO(value, boundary)   (((value) + ((boundary)-1)) / (boundary))
0226 
0227 #define ACPI_IS_MISALIGNED(value)           (((acpi_size) value) & (sizeof(acpi_size)-1))
0228 
0229 /* Generic bit manipulation */
0230 
0231 #ifndef ACPI_USE_NATIVE_BIT_FINDER
0232 
0233 #define __ACPI_FIND_LAST_BIT_2(a, r)        ((((u8)  (a)) & 0x02) ? (r)+1 : (r))
0234 #define __ACPI_FIND_LAST_BIT_4(a, r)        ((((u8)  (a)) & 0x0C) ? \
0235                                              __ACPI_FIND_LAST_BIT_2  ((a)>>2,  (r)+2) : \
0236                                              __ACPI_FIND_LAST_BIT_2  ((a), (r)))
0237 #define __ACPI_FIND_LAST_BIT_8(a, r)        ((((u8)  (a)) & 0xF0) ? \
0238                                              __ACPI_FIND_LAST_BIT_4  ((a)>>4,  (r)+4) : \
0239                                              __ACPI_FIND_LAST_BIT_4  ((a), (r)))
0240 #define __ACPI_FIND_LAST_BIT_16(a, r)       ((((u16) (a)) & 0xFF00) ? \
0241                                              __ACPI_FIND_LAST_BIT_8  ((a)>>8,  (r)+8) : \
0242                                              __ACPI_FIND_LAST_BIT_8  ((a), (r)))
0243 #define __ACPI_FIND_LAST_BIT_32(a, r)       ((((u32) (a)) & 0xFFFF0000) ? \
0244                                              __ACPI_FIND_LAST_BIT_16 ((a)>>16, (r)+16) : \
0245                                              __ACPI_FIND_LAST_BIT_16 ((a), (r)))
0246 #define __ACPI_FIND_LAST_BIT_64(a, r)       ((((u64) (a)) & 0xFFFFFFFF00000000) ? \
0247                                              __ACPI_FIND_LAST_BIT_32 ((a)>>32, (r)+32) : \
0248                                              __ACPI_FIND_LAST_BIT_32 ((a), (r)))
0249 
0250 #define ACPI_FIND_LAST_BIT_8(a)             ((a) ? __ACPI_FIND_LAST_BIT_8 (a, 1) : 0)
0251 #define ACPI_FIND_LAST_BIT_16(a)            ((a) ? __ACPI_FIND_LAST_BIT_16 (a, 1) : 0)
0252 #define ACPI_FIND_LAST_BIT_32(a)            ((a) ? __ACPI_FIND_LAST_BIT_32 (a, 1) : 0)
0253 #define ACPI_FIND_LAST_BIT_64(a)            ((a) ? __ACPI_FIND_LAST_BIT_64 (a, 1) : 0)
0254 
0255 #define __ACPI_FIND_FIRST_BIT_2(a, r)       ((((u8) (a)) & 0x01) ? (r) : (r)+1)
0256 #define __ACPI_FIND_FIRST_BIT_4(a, r)       ((((u8) (a)) & 0x03) ? \
0257                                              __ACPI_FIND_FIRST_BIT_2  ((a), (r)) : \
0258                                              __ACPI_FIND_FIRST_BIT_2  ((a)>>2, (r)+2))
0259 #define __ACPI_FIND_FIRST_BIT_8(a, r)       ((((u8) (a)) & 0x0F) ? \
0260                                              __ACPI_FIND_FIRST_BIT_4  ((a), (r)) : \
0261                                              __ACPI_FIND_FIRST_BIT_4  ((a)>>4, (r)+4))
0262 #define __ACPI_FIND_FIRST_BIT_16(a, r)      ((((u16) (a)) & 0x00FF) ? \
0263                                              __ACPI_FIND_FIRST_BIT_8  ((a), (r)) : \
0264                                              __ACPI_FIND_FIRST_BIT_8  ((a)>>8, (r)+8))
0265 #define __ACPI_FIND_FIRST_BIT_32(a, r)      ((((u32) (a)) & 0x0000FFFF) ? \
0266                                              __ACPI_FIND_FIRST_BIT_16 ((a), (r)) : \
0267                                              __ACPI_FIND_FIRST_BIT_16 ((a)>>16, (r)+16))
0268 #define __ACPI_FIND_FIRST_BIT_64(a, r)      ((((u64) (a)) & 0x00000000FFFFFFFF) ? \
0269                                              __ACPI_FIND_FIRST_BIT_32 ((a), (r)) : \
0270                                              __ACPI_FIND_FIRST_BIT_32 ((a)>>32, (r)+32))
0271 
0272 #define ACPI_FIND_FIRST_BIT_8(a)            ((a) ? __ACPI_FIND_FIRST_BIT_8 (a, 1) : 0)
0273 #define ACPI_FIND_FIRST_BIT_16(a)           ((a) ? __ACPI_FIND_FIRST_BIT_16 (a, 1) : 0)
0274 #define ACPI_FIND_FIRST_BIT_32(a)           ((a) ? __ACPI_FIND_FIRST_BIT_32 (a, 1) : 0)
0275 #define ACPI_FIND_FIRST_BIT_64(a)           ((a) ? __ACPI_FIND_FIRST_BIT_64 (a, 1) : 0)
0276 
0277 #endif              /* ACPI_USE_NATIVE_BIT_FINDER */
0278 
0279 /* Generic (power-of-two) rounding */
0280 
0281 #define ACPI_ROUND_UP_POWER_OF_TWO_8(a)     ((u8) \
0282                                             (((u16) 1) <<  ACPI_FIND_LAST_BIT_8  ((a)  - 1)))
0283 #define ACPI_ROUND_DOWN_POWER_OF_TWO_8(a)   ((u8) \
0284                                             (((u16) 1) << (ACPI_FIND_LAST_BIT_8  ((a)) - 1)))
0285 #define ACPI_ROUND_UP_POWER_OF_TWO_16(a)    ((u16) \
0286                                             (((u32) 1) <<  ACPI_FIND_LAST_BIT_16 ((a)  - 1)))
0287 #define ACPI_ROUND_DOWN_POWER_OF_TWO_16(a)  ((u16) \
0288                                             (((u32) 1) << (ACPI_FIND_LAST_BIT_16 ((a)) - 1)))
0289 #define ACPI_ROUND_UP_POWER_OF_TWO_32(a)    ((u32) \
0290                                             (((u64) 1) <<  ACPI_FIND_LAST_BIT_32 ((a)  - 1)))
0291 #define ACPI_ROUND_DOWN_POWER_OF_TWO_32(a)  ((u32) \
0292                                             (((u64) 1) << (ACPI_FIND_LAST_BIT_32 ((a)) - 1)))
0293 #define ACPI_IS_ALIGNED(a, s)               (((a) & ((s) - 1)) == 0)
0294 #define ACPI_IS_POWER_OF_TWO(a)             ACPI_IS_ALIGNED(a, a)
0295 
0296 /*
0297  * Bitmask creation
0298  * Bit positions start at zero.
0299  * MASK_BITS_ABOVE creates a mask starting AT the position and above
0300  * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
0301  * MASK_BITS_ABOVE/BELOW accepts a bit offset to create a mask
0302  * MASK_BITS_ABOVE/BELOW_32/64 accepts a bit width to create a mask
0303  * Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
0304  * differences with the shift operator
0305  */
0306 #define ACPI_MASK_BITS_ABOVE(position)      (~((ACPI_UINT64_MAX) << ((u32) (position))))
0307 #define ACPI_MASK_BITS_BELOW(position)      ((ACPI_UINT64_MAX) << ((u32) (position)))
0308 #define ACPI_MASK_BITS_ABOVE_32(width)      ((u32) ACPI_MASK_BITS_ABOVE(width))
0309 #define ACPI_MASK_BITS_BELOW_32(width)      ((u32) ACPI_MASK_BITS_BELOW(width))
0310 #define ACPI_MASK_BITS_ABOVE_64(width)      ((width) == ACPI_INTEGER_BIT_SIZE ? \
0311                                                 ACPI_UINT64_MAX : \
0312                                                 ACPI_MASK_BITS_ABOVE(width))
0313 #define ACPI_MASK_BITS_BELOW_64(width)      ((width) == ACPI_INTEGER_BIT_SIZE ? \
0314                                                 (u64) 0 : \
0315                                                 ACPI_MASK_BITS_BELOW(width))
0316 
0317 /* Bitfields within ACPI registers */
0318 
0319 #define ACPI_REGISTER_PREPARE_BITS(val, pos, mask) \
0320     ((val << pos) & mask)
0321 
0322 #define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val) \
0323     reg = (reg & (~(mask))) | ACPI_REGISTER_PREPARE_BITS(val, pos, mask)
0324 
0325 #define ACPI_INSERT_BITS(target, mask, source) \
0326     target = ((target & (~(mask))) | (source & mask))
0327 
0328 /* Generic bitfield macros and masks */
0329 
0330 #define ACPI_GET_BITS(source_ptr, position, mask) \
0331     ((*(source_ptr) >> (position)) & (mask))
0332 
0333 #define ACPI_SET_BITS(target_ptr, position, mask, value) \
0334     (*(target_ptr) |= (((value) & (mask)) << (position)))
0335 
0336 #define ACPI_1BIT_MASK      0x00000001
0337 #define ACPI_2BIT_MASK      0x00000003
0338 #define ACPI_3BIT_MASK      0x00000007
0339 #define ACPI_4BIT_MASK      0x0000000F
0340 #define ACPI_5BIT_MASK      0x0000001F
0341 #define ACPI_6BIT_MASK      0x0000003F
0342 #define ACPI_7BIT_MASK      0x0000007F
0343 #define ACPI_8BIT_MASK      0x000000FF
0344 #define ACPI_16BIT_MASK     0x0000FFFF
0345 #define ACPI_24BIT_MASK     0x00FFFFFF
0346 
0347 /* Macros to extract flag bits from position zero */
0348 
0349 #define ACPI_GET_1BIT_FLAG(value)                   ((value) & ACPI_1BIT_MASK)
0350 #define ACPI_GET_2BIT_FLAG(value)                   ((value) & ACPI_2BIT_MASK)
0351 #define ACPI_GET_3BIT_FLAG(value)                   ((value) & ACPI_3BIT_MASK)
0352 #define ACPI_GET_4BIT_FLAG(value)                   ((value) & ACPI_4BIT_MASK)
0353 
0354 /* Macros to extract flag bits from position one and above */
0355 
0356 #define ACPI_EXTRACT_1BIT_FLAG(field, position)     (ACPI_GET_1BIT_FLAG ((field) >> position))
0357 #define ACPI_EXTRACT_2BIT_FLAG(field, position)     (ACPI_GET_2BIT_FLAG ((field) >> position))
0358 #define ACPI_EXTRACT_3BIT_FLAG(field, position)     (ACPI_GET_3BIT_FLAG ((field) >> position))
0359 #define ACPI_EXTRACT_4BIT_FLAG(field, position)     (ACPI_GET_4BIT_FLAG ((field) >> position))
0360 
0361 /* ACPI Pathname helpers */
0362 
0363 #define ACPI_IS_ROOT_PREFIX(c)      ((c) == (u8) 0x5C)  /* Backslash */
0364 #define ACPI_IS_PARENT_PREFIX(c)    ((c) == (u8) 0x5E)  /* Carat */
0365 #define ACPI_IS_PATH_SEPARATOR(c)   ((c) == (u8) 0x2E)  /* Period (dot) */
0366 
0367 /*
0368  * An object of type struct acpi_namespace_node can appear in some contexts
0369  * where a pointer to an object of type union acpi_operand_object can also
0370  * appear. This macro is used to distinguish them.
0371  *
0372  * The "DescriptorType" field is the second field in both structures.
0373  */
0374 #define ACPI_GET_DESCRIPTOR_PTR(d)      (((union acpi_descriptor *)(void *)(d))->common.common_pointer)
0375 #define ACPI_SET_DESCRIPTOR_PTR(d, p)   (((union acpi_descriptor *)(void *)(d))->common.common_pointer = (p))
0376 #define ACPI_GET_DESCRIPTOR_TYPE(d)     (((union acpi_descriptor *)(void *)(d))->common.descriptor_type)
0377 #define ACPI_SET_DESCRIPTOR_TYPE(d, t)  (((union acpi_descriptor *)(void *)(d))->common.descriptor_type = (t))
0378 
0379 /*
0380  * Macros for the master AML opcode table
0381  */
0382 #if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
0383 #define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags) \
0384     {name, (u32)(Pargs), (u32)(Iargs), (u32)(flags), obj_type, class, type}
0385 #else
0386 #define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags) \
0387     {(u32)(Pargs), (u32)(Iargs), (u32)(flags), obj_type, class, type}
0388 #endif
0389 
0390 #define ARG_TYPE_WIDTH                  5
0391 #define ARG_1(x)                        ((u32)(x))
0392 #define ARG_2(x)                        ((u32)(x) << (1 * ARG_TYPE_WIDTH))
0393 #define ARG_3(x)                        ((u32)(x) << (2 * ARG_TYPE_WIDTH))
0394 #define ARG_4(x)                        ((u32)(x) << (3 * ARG_TYPE_WIDTH))
0395 #define ARG_5(x)                        ((u32)(x) << (4 * ARG_TYPE_WIDTH))
0396 #define ARG_6(x)                        ((u32)(x) << (5 * ARG_TYPE_WIDTH))
0397 
0398 #define ARGI_LIST1(a)                   (ARG_1(a))
0399 #define ARGI_LIST2(a, b)                (ARG_1(b)|ARG_2(a))
0400 #define ARGI_LIST3(a, b, c)             (ARG_1(c)|ARG_2(b)|ARG_3(a))
0401 #define ARGI_LIST4(a, b, c, d)          (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
0402 #define ARGI_LIST5(a, b, c, d, e)       (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
0403 #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))
0404 
0405 #define ARGP_LIST1(a)                   (ARG_1(a))
0406 #define ARGP_LIST2(a, b)                (ARG_1(a)|ARG_2(b))
0407 #define ARGP_LIST3(a, b, c)             (ARG_1(a)|ARG_2(b)|ARG_3(c))
0408 #define ARGP_LIST4(a, b, c, d)          (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
0409 #define ARGP_LIST5(a, b, c, d, e)       (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
0410 #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))
0411 
0412 #define GET_CURRENT_ARG_TYPE(list)      (list & ((u32) 0x1F))
0413 #define INCREMENT_ARG_LIST(list)        (list >>= ((u32) ARG_TYPE_WIDTH))
0414 
0415 /*
0416  * Ascii error messages can be configured out
0417  */
0418 #ifndef ACPI_NO_ERROR_MESSAGES
0419 /*
0420  * Error reporting. The callers module and line number are inserted by AE_INFO,
0421  * the plist contains a set of parens to allow variable-length lists.
0422  * These macros are used for both the debug and non-debug versions of the code.
0423  */
0424 #define ACPI_ERROR_NAMESPACE(s, p, e)       acpi_ut_prefixed_namespace_error (AE_INFO, s, p, e);
0425 #define ACPI_ERROR_METHOD(s, n, p, e)       acpi_ut_method_error (AE_INFO, s, n, p, e);
0426 #define ACPI_WARN_PREDEFINED(plist)         acpi_ut_predefined_warning plist
0427 #define ACPI_INFO_PREDEFINED(plist)         acpi_ut_predefined_info plist
0428 #define ACPI_BIOS_ERROR_PREDEFINED(plist)   acpi_ut_predefined_bios_error plist
0429 #define ACPI_ERROR_ONLY(s)                  s
0430 
0431 #else
0432 
0433 /* No error messages */
0434 
0435 #define ACPI_ERROR_NAMESPACE(s, p, e)
0436 #define ACPI_ERROR_METHOD(s, n, p, e)
0437 #define ACPI_WARN_PREDEFINED(plist)
0438 #define ACPI_INFO_PREDEFINED(plist)
0439 #define ACPI_BIOS_ERROR_PREDEFINED(plist)
0440 #define ACPI_ERROR_ONLY(s)
0441 
0442 #endif              /* ACPI_NO_ERROR_MESSAGES */
0443 
0444 #if (!ACPI_REDUCED_HARDWARE)
0445 #define ACPI_HW_OPTIONAL_FUNCTION(addr)     addr
0446 #else
0447 #define ACPI_HW_OPTIONAL_FUNCTION(addr)     NULL
0448 #endif
0449 
0450 /*
0451  * Macros used for ACPICA utilities only
0452  */
0453 
0454 /* Generate a UUID */
0455 
0456 #define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
0457     (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \
0458     (b) & 0xFF, ((b) >> 8) & 0xFF, \
0459     (c) & 0xFF, ((c) >> 8) & 0xFF, \
0460     (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)
0461 
0462 #define ACPI_IS_OCTAL_DIGIT(d)              (((char)(d) >= '0') && ((char)(d) <= '7'))
0463 
0464 /*
0465  * Macros used for the ASL-/ASL+ converter utility
0466  */
0467 #ifdef ACPI_ASL_COMPILER
0468 
0469 #define ASL_CV_LABEL_FILENODE(a)         cv_label_file_node(a);
0470 #define ASL_CV_CAPTURE_COMMENTS_ONLY(a)   cv_capture_comments_only (a);
0471 #define ASL_CV_CAPTURE_COMMENTS(a)       cv_capture_comments (a);
0472 #define ASL_CV_TRANSFER_COMMENTS(a)      cv_transfer_comments (a);
0473 #define ASL_CV_CLOSE_PAREN(a,b)          cv_close_paren_write_comment(a,b);
0474 #define ASL_CV_CLOSE_BRACE(a,b)          cv_close_brace_write_comment(a,b);
0475 #define ASL_CV_SWITCH_FILES(a,b)         cv_switch_files(a,b);
0476 #define ASL_CV_CLEAR_OP_COMMENTS(a)       cv_clear_op_comments(a);
0477 #define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d) cv_print_one_comment_type (a,b,c,d);
0478 #define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b) cv_print_one_comment_list (a,b);
0479 #define ASL_CV_FILE_HAS_SWITCHED(a)       cv_file_has_switched(a)
0480 #define ASL_CV_INIT_FILETREE(a,b)      cv_init_file_tree(a,b);
0481 
0482 #else
0483 
0484 #define ASL_CV_LABEL_FILENODE(a)
0485 #define ASL_CV_CAPTURE_COMMENTS_ONLY(a)
0486 #define ASL_CV_CAPTURE_COMMENTS(a)
0487 #define ASL_CV_TRANSFER_COMMENTS(a)
0488 #define ASL_CV_CLOSE_PAREN(a,b)          acpi_os_printf (")");
0489 #define ASL_CV_CLOSE_BRACE(a,b)          acpi_os_printf ("}");
0490 #define ASL_CV_SWITCH_FILES(a,b)
0491 #define ASL_CV_CLEAR_OP_COMMENTS(a)
0492 #define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d)
0493 #define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b)
0494 #define ASL_CV_FILE_HAS_SWITCHED(a)       0
0495 #define ASL_CV_INIT_FILETREE(a,b)
0496 
0497 #endif
0498 
0499 #endif              /* ACMACROS_H */