167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Name: acmacros.h - C macros for the entire subsystem. 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 4467754Smsmith#ifndef __ACMACROS_H__ 4567754Smsmith#define __ACMACROS_H__ 4667754Smsmith 4780062Smsmith 4867754Smsmith/* 49193267Sjkim * Extract data using a pointer. Any more than a byte and we 50167802Sjkim * get into potential aligment issues -- see the STORE macros below. 51167802Sjkim * Use with care. 52123315Snjl */ 53167802Sjkim#define ACPI_GET8(ptr) *ACPI_CAST_PTR (UINT8, ptr) 54167802Sjkim#define ACPI_GET16(ptr) *ACPI_CAST_PTR (UINT16, ptr) 55167802Sjkim#define ACPI_GET32(ptr) *ACPI_CAST_PTR (UINT32, ptr) 56167802Sjkim#define ACPI_GET64(ptr) *ACPI_CAST_PTR (UINT64, ptr) 57167802Sjkim#define ACPI_SET8(ptr) *ACPI_CAST_PTR (UINT8, ptr) 58167802Sjkim#define ACPI_SET16(ptr) *ACPI_CAST_PTR (UINT16, ptr) 59167802Sjkim#define ACPI_SET32(ptr) *ACPI_CAST_PTR (UINT32, ptr) 60167802Sjkim#define ACPI_SET64(ptr) *ACPI_CAST_PTR (UINT64, ptr) 6167754Smsmith 62167802Sjkim/* 63193267Sjkim * printf() format helpers 64167802Sjkim */ 6567754Smsmith 66193267Sjkim/* Split 64-bit integer into two 32-bit values. Use with %8.8X%8.8X */ 6777424Smsmith 68193267Sjkim#define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i), ACPI_LODWORD(i) 6991116Smsmith 70193267Sjkim#if ACPI_MACHINE_WIDTH == 64 71193267Sjkim#define ACPI_FORMAT_NATIVE_UINT(i) ACPI_FORMAT_UINT64(i) 7291116Smsmith#else 73193267Sjkim#define ACPI_FORMAT_NATIVE_UINT(i) 0, (i) 7491116Smsmith#endif 7591116Smsmith 76193267Sjkim 7767754Smsmith/* 7867754Smsmith * Macros for moving data around to/from buffers that are possibly unaligned. 7967754Smsmith * If the hardware supports the transfer of unaligned data, just do the store. 8067754Smsmith * Otherwise, we have to move one byte at a time. 8167754Smsmith */ 82117521Snjl#ifdef ACPI_BIG_ENDIAN 83117521Snjl/* 84117521Snjl * Macros for big-endian machines 85117521Snjl */ 8667754Smsmith 87117521Snjl/* These macros reverse the bytes during the move, converting little-endian to big endian */ 88117521Snjl 89117521Snjl /* Big Endian <== Little Endian */ 90117521Snjl /* Hi...Lo Lo...Hi */ 91117521Snjl/* 16-bit source, 16/32/64 destination */ 92117521Snjl 93193267Sjkim#define ACPI_MOVE_16_TO_16(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\ 94117521Snjl (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];} 95117521Snjl 96193267Sjkim#define ACPI_MOVE_16_TO_32(d, s) {(*(UINT32 *)(void *)(d))=0;\ 97117521Snjl ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\ 98117521Snjl ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];} 99117521Snjl 100193267Sjkim#define ACPI_MOVE_16_TO_64(d, s) {(*(UINT64 *)(void *)(d))=0;\ 101117521Snjl ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\ 102117521Snjl ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];} 103117521Snjl 104117521Snjl/* 32-bit source, 16/32/64 destination */ 105117521Snjl 106193267Sjkim#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ 107117521Snjl 108193267Sjkim#define ACPI_MOVE_32_TO_32(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\ 109117521Snjl (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\ 110117521Snjl (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\ 111117521Snjl (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];} 112117521Snjl 113193267Sjkim#define ACPI_MOVE_32_TO_64(d, s) {(*(UINT64 *)(void *)(d))=0;\ 114117521Snjl ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\ 115117521Snjl ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\ 116117521Snjl ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\ 117117521Snjl ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];} 118117521Snjl 119117521Snjl/* 64-bit source, 16/32/64 destination */ 120117521Snjl 121193267Sjkim#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ 122117521Snjl 123193267Sjkim#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */ 124117521Snjl 125193267Sjkim#define ACPI_MOVE_64_TO_64(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\ 126117521Snjl (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\ 127117521Snjl (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\ 128117521Snjl (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\ 129117521Snjl (( UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\ 130117521Snjl (( UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\ 131117521Snjl (( UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\ 132117521Snjl (( UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];} 13367754Smsmith#else 13467754Smsmith/* 135117521Snjl * Macros for little-endian machines 136117521Snjl */ 137117521Snjl 138151937Sjkim#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED 139117521Snjl 140117521Snjl/* The hardware supports unaligned transfers, just do the little-endian move */ 141117521Snjl 142117521Snjl/* 16-bit source, 16/32/64 destination */ 143117521Snjl 144193267Sjkim#define ACPI_MOVE_16_TO_16(d, s) *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s) 145193267Sjkim#define ACPI_MOVE_16_TO_32(d, s) *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s) 146193267Sjkim#define ACPI_MOVE_16_TO_64(d, s) *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s) 147117521Snjl 148117521Snjl/* 32-bit source, 16/32/64 destination */ 149117521Snjl 150193267Sjkim#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ 151193267Sjkim#define ACPI_MOVE_32_TO_32(d, s) *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s) 152193267Sjkim#define ACPI_MOVE_32_TO_64(d, s) *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s) 153117521Snjl 154117521Snjl/* 64-bit source, 16/32/64 destination */ 155117521Snjl 156193267Sjkim#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ 157193267Sjkim#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */ 158193267Sjkim#define ACPI_MOVE_64_TO_64(d, s) *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s) 159117521Snjl 160117521Snjl#else 161117521Snjl/* 162193267Sjkim * The hardware does not support unaligned transfers. We must move the 163193267Sjkim * data one byte at a time. These macros work whether the source or 164193267Sjkim * the destination (or both) is/are unaligned. (Little-endian move) 16567754Smsmith */ 16667754Smsmith 167117521Snjl/* 16-bit source, 16/32/64 destination */ 16867754Smsmith 169193267Sjkim#define ACPI_MOVE_16_TO_16(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\ 170117521Snjl (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];} 17167754Smsmith 172193267Sjkim#define ACPI_MOVE_16_TO_32(d, s) {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);} 173193267Sjkim#define ACPI_MOVE_16_TO_64(d, s) {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);} 17467754Smsmith 175117521Snjl/* 32-bit source, 16/32/64 destination */ 17677424Smsmith 177193267Sjkim#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ 178117521Snjl 179193267Sjkim#define ACPI_MOVE_32_TO_32(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\ 180117521Snjl (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\ 181117521Snjl (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\ 182117521Snjl (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];} 183117521Snjl 184193267Sjkim#define ACPI_MOVE_32_TO_64(d, s) {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);} 185117521Snjl 186117521Snjl/* 64-bit source, 16/32/64 destination */ 187117521Snjl 188193267Sjkim#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ 189193267Sjkim#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */ 190193267Sjkim#define ACPI_MOVE_64_TO_64(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\ 191117521Snjl (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\ 192117521Snjl (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\ 193117521Snjl (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\ 194117521Snjl (( UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\ 195117521Snjl (( UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\ 196117521Snjl (( UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\ 197117521Snjl (( UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];} 19867754Smsmith#endif 199117521Snjl#endif 20067754Smsmith 20167754Smsmith 20267754Smsmith/* 20367754Smsmith * Fast power-of-two math macros for non-optimized compilers 20467754Smsmith */ 205193267Sjkim#define _ACPI_DIV(value, PowerOf2) ((UINT32) ((value) >> (PowerOf2))) 206193267Sjkim#define _ACPI_MUL(value, PowerOf2) ((UINT32) ((value) << (PowerOf2))) 207193267Sjkim#define _ACPI_MOD(value, Divisor) ((UINT32) ((value) & ((Divisor) -1))) 20867754Smsmith 209193267Sjkim#define ACPI_DIV_2(a) _ACPI_DIV(a, 1) 210193267Sjkim#define ACPI_MUL_2(a) _ACPI_MUL(a, 1) 211193267Sjkim#define ACPI_MOD_2(a) _ACPI_MOD(a, 2) 21267754Smsmith 213193267Sjkim#define ACPI_DIV_4(a) _ACPI_DIV(a, 2) 214193267Sjkim#define ACPI_MUL_4(a) _ACPI_MUL(a, 2) 215193267Sjkim#define ACPI_MOD_4(a) _ACPI_MOD(a, 4) 21667754Smsmith 217193267Sjkim#define ACPI_DIV_8(a) _ACPI_DIV(a, 3) 218193267Sjkim#define ACPI_MUL_8(a) _ACPI_MUL(a, 3) 219193267Sjkim#define ACPI_MOD_8(a) _ACPI_MOD(a, 8) 22067754Smsmith 221193267Sjkim#define ACPI_DIV_16(a) _ACPI_DIV(a, 4) 222193267Sjkim#define ACPI_MUL_16(a) _ACPI_MUL(a, 4) 223193267Sjkim#define ACPI_MOD_16(a) _ACPI_MOD(a, 16) 22467754Smsmith 225193267Sjkim#define ACPI_DIV_32(a) _ACPI_DIV(a, 5) 226193267Sjkim#define ACPI_MUL_32(a) _ACPI_MUL(a, 5) 227193267Sjkim#define ACPI_MOD_32(a) _ACPI_MOD(a, 32) 22867754Smsmith 22967754Smsmith/* 23067754Smsmith * Rounding macros (Power of two boundaries only) 23167754Smsmith */ 232193267Sjkim#define ACPI_ROUND_DOWN(value, boundary) (((ACPI_SIZE)(value)) & \ 233193267Sjkim (~(((ACPI_SIZE) boundary)-1))) 23467754Smsmith 235193267Sjkim#define ACPI_ROUND_UP(value, boundary) ((((ACPI_SIZE)(value)) + \ 236193267Sjkim (((ACPI_SIZE) boundary)-1)) & \ 237193267Sjkim (~(((ACPI_SIZE) boundary)-1))) 23867754Smsmith 239193267Sjkim/* Note: sizeof(ACPI_SIZE) evaluates to either 4 or 8 (32- vs 64-bit mode) */ 24067754Smsmith 241193267Sjkim#define ACPI_ROUND_DOWN_TO_32BIT(a) ACPI_ROUND_DOWN(a, 4) 242193267Sjkim#define ACPI_ROUND_DOWN_TO_64BIT(a) ACPI_ROUND_DOWN(a, 8) 243193267Sjkim#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a, sizeof(ACPI_SIZE)) 24467754Smsmith 245193267Sjkim#define ACPI_ROUND_UP_TO_32BIT(a) ACPI_ROUND_UP(a, 4) 246193267Sjkim#define ACPI_ROUND_UP_TO_64BIT(a) ACPI_ROUND_UP(a, 8) 247193267Sjkim#define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a, sizeof(ACPI_SIZE)) 24877424Smsmith 249167802Sjkim#define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7) 250167802Sjkim#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a)) 25169450Smsmith 252167802Sjkim#define ACPI_ROUND_UP_TO_1K(a) (((a) + 1023) >> 10) 253167802Sjkim 25477424Smsmith/* Generic (non-power-of-two) rounding */ 25577424Smsmith 256193267Sjkim#define ACPI_ROUND_UP_TO(value, boundary) (((value) + ((boundary)-1)) / (boundary)) 25777424Smsmith 258193267Sjkim#define ACPI_IS_MISALIGNED(value) (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1)) 259167802Sjkim 26083174Smsmith/* 26177424Smsmith * Bitmask creation 26277424Smsmith * Bit positions start at zero. 26377424Smsmith * MASK_BITS_ABOVE creates a mask starting AT the position and above 26477424Smsmith * MASK_BITS_BELOW creates a mask starting one bit BELOW the position 26577424Smsmith */ 266202771Sjkim#define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_UINT64_MAX) << ((UINT32) (position)))) 267202771Sjkim#define ACPI_MASK_BITS_BELOW(position) ((ACPI_UINT64_MAX) << ((UINT32) (position))) 26877424Smsmith 26991116Smsmith/* Bitfields within ACPI registers */ 27091116Smsmith 27191116Smsmith#define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask) ((Val << Pos) & Mask) 27291116Smsmith#define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val) Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask) 27391116Smsmith 274167802Sjkim#define ACPI_INSERT_BITS(Target, Mask, Source) Target = ((Target & (~(Mask))) | (Source & Mask)) 275167802Sjkim 27667754Smsmith/* 277193267Sjkim * An ACPI_NAMESPACE_NODE can appear in some contexts 278193267Sjkim * where a pointer to an ACPI_OPERAND_OBJECT can also 279193267Sjkim * appear. This macro is used to distinguish them. 28067754Smsmith * 28191116Smsmith * The "Descriptor" field is the first field in both structures. 28267754Smsmith */ 283167802Sjkim#define ACPI_GET_DESCRIPTOR_TYPE(d) (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType) 284193267Sjkim#define ACPI_SET_DESCRIPTOR_TYPE(d, t) (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType = t) 28567754Smsmith 28667754Smsmith/* 28767754Smsmith * Macros for the master AML opcode table 28867754Smsmith */ 289193267Sjkim#if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT) 290193267Sjkim#define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \ 291193267Sjkim {Name, (UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type} 29267754Smsmith#else 293193267Sjkim#define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \ 294193267Sjkim {(UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type} 29567754Smsmith#endif 29667754Smsmith 29767754Smsmith#define ARG_TYPE_WIDTH 5 29867754Smsmith#define ARG_1(x) ((UINT32)(x)) 29967754Smsmith#define ARG_2(x) ((UINT32)(x) << (1 * ARG_TYPE_WIDTH)) 30067754Smsmith#define ARG_3(x) ((UINT32)(x) << (2 * ARG_TYPE_WIDTH)) 30167754Smsmith#define ARG_4(x) ((UINT32)(x) << (3 * ARG_TYPE_WIDTH)) 30267754Smsmith#define ARG_5(x) ((UINT32)(x) << (4 * ARG_TYPE_WIDTH)) 30367754Smsmith#define ARG_6(x) ((UINT32)(x) << (5 * ARG_TYPE_WIDTH)) 30467754Smsmith 30567754Smsmith#define ARGI_LIST1(a) (ARG_1(a)) 306193267Sjkim#define ARGI_LIST2(a, b) (ARG_1(b)|ARG_2(a)) 307193267Sjkim#define ARGI_LIST3(a, b, c) (ARG_1(c)|ARG_2(b)|ARG_3(a)) 308193267Sjkim#define ARGI_LIST4(a, b, c, d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a)) 309193267Sjkim#define ARGI_LIST5(a, b, c, d, e) (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a)) 310193267Sjkim#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)) 31167754Smsmith 31267754Smsmith#define ARGP_LIST1(a) (ARG_1(a)) 313193267Sjkim#define ARGP_LIST2(a, b) (ARG_1(a)|ARG_2(b)) 314193267Sjkim#define ARGP_LIST3(a, b, c) (ARG_1(a)|ARG_2(b)|ARG_3(c)) 315193267Sjkim#define ARGP_LIST4(a, b, c, d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)) 316193267Sjkim#define ARGP_LIST5(a, b, c, d, e) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e)) 317193267Sjkim#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)) 31867754Smsmith 31967754Smsmith#define GET_CURRENT_ARG_TYPE(List) (List & ((UINT32) 0x1F)) 32067754Smsmith#define INCREMENT_ARG_LIST(List) (List >>= ((UINT32) ARG_TYPE_WIDTH)) 32167754Smsmith 32267754Smsmith/* 323167802Sjkim * Ascii error messages can be configured out 32467754Smsmith */ 325167802Sjkim#ifndef ACPI_NO_ERROR_MESSAGES 326167802Sjkim/* 327167802Sjkim * Error reporting. Callers module and line number are inserted by AE_INFO, 328167802Sjkim * the plist contains a set of parens to allow variable-length lists. 329167802Sjkim * These macros are used for both the debug and non-debug versions of the code. 330167802Sjkim */ 331212761Sjkim#define ACPI_ERROR_NAMESPACE(s, e) AcpiUtNamespaceError (AE_INFO, s, e); 332212761Sjkim#define ACPI_ERROR_METHOD(s, n, p, e) AcpiUtMethodError (AE_INFO, s, n, p, e); 333197104Sjkim#define ACPI_WARN_PREDEFINED(plist) AcpiUtPredefinedWarning plist 334199337Sjkim#define ACPI_INFO_PREDEFINED(plist) AcpiUtPredefinedInfo plist 33567754Smsmith 33667754Smsmith#else 33767754Smsmith 338167802Sjkim/* No error messages */ 33967754Smsmith 340193267Sjkim#define ACPI_ERROR_NAMESPACE(s, e) 341193267Sjkim#define ACPI_ERROR_METHOD(s, n, p, e) 342197104Sjkim#define ACPI_WARN_PREDEFINED(plist) 343199337Sjkim#define ACPI_INFO_PREDEFINED(plist) 34467754Smsmith 345193267Sjkim#endif /* ACPI_NO_ERROR_MESSAGES */ 346193267Sjkim 34767754Smsmith/* 34867754Smsmith * Debug macros that are conditionally compiled 34967754Smsmith */ 350102550Siwasaki#ifdef ACPI_DEBUG_OUTPUT 351151937Sjkim/* 352151937Sjkim * Function entry tracing 35367754Smsmith */ 354151937Sjkim#define ACPI_FUNCTION_TRACE(a) ACPI_FUNCTION_NAME(a) \ 355151937Sjkim AcpiUtTrace(ACPI_DEBUG_PARAMETERS) 356193267Sjkim#define ACPI_FUNCTION_TRACE_PTR(a, b) ACPI_FUNCTION_NAME(a) \ 357193267Sjkim AcpiUtTracePtr(ACPI_DEBUG_PARAMETERS, (void *)b) 358193267Sjkim#define ACPI_FUNCTION_TRACE_U32(a, b) ACPI_FUNCTION_NAME(a) \ 359193267Sjkim AcpiUtTraceU32(ACPI_DEBUG_PARAMETERS, (UINT32)b) 360193267Sjkim#define ACPI_FUNCTION_TRACE_STR(a, b) ACPI_FUNCTION_NAME(a) \ 361193267Sjkim AcpiUtTraceStr(ACPI_DEBUG_PARAMETERS, (char *)b) 362151937Sjkim 363151937Sjkim#define ACPI_FUNCTION_ENTRY() AcpiUtTrackStackPtr() 364151937Sjkim 36567754Smsmith/* 36667754Smsmith * Function exit tracing. 367193267Sjkim * WARNING: These macros include a return statement. This is usually considered 36867754Smsmith * bad form, but having a separate exit macro is very ugly and difficult to maintain. 36967754Smsmith * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros 370151937Sjkim * so that "_AcpiFunctionName" is defined. 371151937Sjkim * 372151937Sjkim * Note: the DO_WHILE0 macro is used to prevent some compilers from complaining 373151937Sjkim * about these constructs. 37467754Smsmith */ 37599679Siwasaki#ifdef ACPI_USE_DO_WHILE_0 37699679Siwasaki#define ACPI_DO_WHILE0(a) do a while(0) 37799679Siwasaki#else 37899679Siwasaki#define ACPI_DO_WHILE0(a) a 37999679Siwasaki#endif 38067754Smsmith 381151937Sjkim#define return_VOID ACPI_DO_WHILE0 ({ \ 382151937Sjkim AcpiUtExit (ACPI_DEBUG_PARAMETERS); \ 383151937Sjkim return;}) 384151937Sjkim/* 385151937Sjkim * There are two versions of most of the return macros. The default version is 386151937Sjkim * safer, since it avoids side-effects by guaranteeing that the argument will 387151937Sjkim * not be evaluated twice. 388151937Sjkim * 389151937Sjkim * A less-safe version of the macros is provided for optional use if the 390151937Sjkim * compiler uses excessive CPU stack (for example, this may happen in the 391151937Sjkim * debug case if code optimzation is disabled.) 392151937Sjkim */ 393151937Sjkim#ifndef ACPI_SIMPLE_RETURN_MACROS 39467754Smsmith 395151937Sjkim#define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({ \ 396151937Sjkim register ACPI_STATUS _s = (s); \ 397151937Sjkim AcpiUtStatusExit (ACPI_DEBUG_PARAMETERS, _s); \ 398151937Sjkim return (_s); }) 399151937Sjkim#define return_PTR(s) ACPI_DO_WHILE0 ({ \ 400151937Sjkim register void *_s = (void *) (s); \ 401151937Sjkim AcpiUtPtrExit (ACPI_DEBUG_PARAMETERS, (UINT8 *) _s); \ 402151937Sjkim return (_s); }) 403151937Sjkim#define return_VALUE(s) ACPI_DO_WHILE0 ({ \ 404202771Sjkim register UINT64 _s = (s); \ 405151937Sjkim AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, _s); \ 406151937Sjkim return (_s); }) 407151937Sjkim#define return_UINT8(s) ACPI_DO_WHILE0 ({ \ 408151937Sjkim register UINT8 _s = (UINT8) (s); \ 409202771Sjkim AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (UINT64) _s); \ 410151937Sjkim return (_s); }) 411151937Sjkim#define return_UINT32(s) ACPI_DO_WHILE0 ({ \ 412151937Sjkim register UINT32 _s = (UINT32) (s); \ 413202771Sjkim AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (UINT64) _s); \ 414151937Sjkim return (_s); }) 415151937Sjkim#else /* Use original less-safe macros */ 416151937Sjkim 417151937Sjkim#define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({ \ 418151937Sjkim AcpiUtStatusExit (ACPI_DEBUG_PARAMETERS, (s)); \ 419151937Sjkim return((s)); }) 420151937Sjkim#define return_PTR(s) ACPI_DO_WHILE0 ({ \ 421151937Sjkim AcpiUtPtrExit (ACPI_DEBUG_PARAMETERS, (UINT8 *) (s)); \ 422151937Sjkim return((s)); }) 423151937Sjkim#define return_VALUE(s) ACPI_DO_WHILE0 ({ \ 424202771Sjkim AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (UINT64) (s)); \ 425151937Sjkim return((s)); }) 426151937Sjkim#define return_UINT8(s) return_VALUE(s) 427151937Sjkim#define return_UINT32(s) return_VALUE(s) 428151937Sjkim 429151937Sjkim#endif /* ACPI_SIMPLE_RETURN_MACROS */ 430151937Sjkim 431151937Sjkim 43267754Smsmith/* Conditional execution */ 43367754Smsmith 43491116Smsmith#define ACPI_DEBUG_EXEC(a) a 43591116Smsmith#define ACPI_DEBUG_ONLY_MEMBERS(a) a; 43671867Smsmith#define _VERBOSE_STRUCTURES 43767754Smsmith 43867754Smsmith 439193267Sjkim/* Various object display routines for debug */ 44067754Smsmith 441193267Sjkim#define ACPI_DUMP_STACK_ENTRY(a) AcpiExDumpOperand((a), 0) 442193267Sjkim#define ACPI_DUMP_OPERANDS(a, b ,c) AcpiExDumpOperands(a, b, c) 443193267Sjkim#define ACPI_DUMP_ENTRY(a, b) AcpiNsDumpEntry (a, b) 444193267Sjkim#define ACPI_DUMP_PATHNAME(a, b, c, d) AcpiNsDumpPathname(a, b, c, d) 445193267Sjkim#define ACPI_DUMP_BUFFER(a, b) AcpiUtDumpBuffer((UINT8 *) a, b, DB_BYTE_DISPLAY, _COMPONENT) 44667754Smsmith 44767754Smsmith#else 44867754Smsmith/* 44967754Smsmith * This is the non-debug case -- make everything go away, 45067754Smsmith * leaving no executable debug code! 45167754Smsmith */ 45291116Smsmith#define ACPI_DEBUG_EXEC(a) 45391116Smsmith#define ACPI_DEBUG_ONLY_MEMBERS(a) 45491116Smsmith#define ACPI_FUNCTION_TRACE(a) 455193267Sjkim#define ACPI_FUNCTION_TRACE_PTR(a, b) 456193267Sjkim#define ACPI_FUNCTION_TRACE_U32(a, b) 457193267Sjkim#define ACPI_FUNCTION_TRACE_STR(a, b) 45891116Smsmith#define ACPI_FUNCTION_EXIT 45991116Smsmith#define ACPI_FUNCTION_STATUS_EXIT(s) 46091116Smsmith#define ACPI_FUNCTION_VALUE_EXIT(s) 46191116Smsmith#define ACPI_FUNCTION_ENTRY() 46291116Smsmith#define ACPI_DUMP_STACK_ENTRY(a) 463193267Sjkim#define ACPI_DUMP_OPERANDS(a, b, c) 464193267Sjkim#define ACPI_DUMP_ENTRY(a, b) 465193267Sjkim#define ACPI_DUMP_TABLES(a, b) 466193267Sjkim#define ACPI_DUMP_PATHNAME(a, b, c, d) 467193267Sjkim#define ACPI_DUMP_BUFFER(a, b) 46882367Smsmith#define ACPI_DEBUG_PRINT(pl) 46982367Smsmith#define ACPI_DEBUG_PRINT_RAW(pl) 47067754Smsmith 47167754Smsmith#define return_VOID return 47267754Smsmith#define return_ACPI_STATUS(s) return(s) 47367754Smsmith#define return_VALUE(s) return(s) 474151937Sjkim#define return_UINT8(s) return(s) 475151937Sjkim#define return_UINT32(s) return(s) 47667754Smsmith#define return_PTR(s) return(s) 47767754Smsmith 478193267Sjkim#endif /* ACPI_DEBUG_OUTPUT */ 47967754Smsmith 48067754Smsmith/* 48167754Smsmith * Some code only gets executed when the debugger is built in. 48267754Smsmith * Note that this is entirely independent of whether the 483102550Siwasaki * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not. 48467754Smsmith */ 485102550Siwasaki#ifdef ACPI_DEBUGGER 48691116Smsmith#define ACPI_DEBUGGER_EXEC(a) a 48767754Smsmith#else 48891116Smsmith#define ACPI_DEBUGGER_EXEC(a) 48967754Smsmith#endif 49067754Smsmith 49167754Smsmith 49267754Smsmith/* 493193267Sjkim * Memory allocation tracking (DEBUG ONLY) 49467754Smsmith */ 495193267Sjkim#define ACPI_MEM_PARAMETERS _COMPONENT, _AcpiModuleName, __LINE__ 49667754Smsmith 49780062Smsmith#ifndef ACPI_DBG_TRACK_ALLOCATIONS 49877424Smsmith 49980062Smsmith/* Memory allocation */ 50077424Smsmith 501193267Sjkim#define ACPI_ALLOCATE(a) AcpiUtAllocate((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS) 502193267Sjkim#define ACPI_ALLOCATE_ZEROED(a) AcpiUtAllocateZeroed((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS) 503167802Sjkim#define ACPI_FREE(a) AcpiOsFree(a) 50482367Smsmith#define ACPI_MEM_TRACKING(a) 50580062Smsmith 50677424Smsmith#else 50777424Smsmith 50880062Smsmith/* Memory allocation */ 50980062Smsmith 510193267Sjkim#define ACPI_ALLOCATE(a) AcpiUtAllocateAndTrack((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS) 511193267Sjkim#define ACPI_ALLOCATE_ZEROED(a) AcpiUtAllocateZeroedAndTrack((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS) 512193267Sjkim#define ACPI_FREE(a) AcpiUtFreeAndTrack(a, ACPI_MEM_PARAMETERS) 513167802Sjkim#define ACPI_MEM_TRACKING(a) a 51480062Smsmith 51580062Smsmith#endif /* ACPI_DBG_TRACK_ALLOCATIONS */ 51677424Smsmith 517193267Sjkim 518193267Sjkim/* 519193267Sjkim * Macros used for ACPICA utilities only 520193267Sjkim */ 521193267Sjkim 522193267Sjkim/* Generate a UUID */ 523193267Sjkim 524193267Sjkim#define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ 525193267Sjkim (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \ 526193267Sjkim (b) & 0xFF, ((b) >> 8) & 0xFF, \ 527193267Sjkim (c) & 0xFF, ((c) >> 8) & 0xFF, \ 528193267Sjkim (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) 529193267Sjkim 530193267Sjkim#define ACPI_IS_OCTAL_DIGIT(d) (((char)(d) >= '0') && ((char)(d) <= '7')) 531193267Sjkim 532193267Sjkim 53367754Smsmith#endif /* ACMACROS_H */ 534