xref: /onnv-gate/usr/src/uts/intel/sys/acpi/acmacros.h (revision 7851:e828bbb1689c)
10Sstevel@tonic-gate /******************************************************************************
20Sstevel@tonic-gate  *
30Sstevel@tonic-gate  * Name: acmacros.h - C macros for the entire subsystem.
4*7851SDana.Myers@Sun.COM  *       $Revision: 1.199 $
50Sstevel@tonic-gate  *
60Sstevel@tonic-gate  *****************************************************************************/
70Sstevel@tonic-gate 
80Sstevel@tonic-gate /******************************************************************************
90Sstevel@tonic-gate  *
100Sstevel@tonic-gate  * 1. Copyright Notice
110Sstevel@tonic-gate  *
12*7851SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
130Sstevel@tonic-gate  * All rights reserved.
140Sstevel@tonic-gate  *
150Sstevel@tonic-gate  * 2. License
160Sstevel@tonic-gate  *
170Sstevel@tonic-gate  * 2.1. This is your license from Intel Corp. under its intellectual property
180Sstevel@tonic-gate  * rights.  You may have additional license terms from the party that provided
190Sstevel@tonic-gate  * you this software, covering your right to use that party's intellectual
200Sstevel@tonic-gate  * property rights.
210Sstevel@tonic-gate  *
220Sstevel@tonic-gate  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
230Sstevel@tonic-gate  * copy of the source code appearing in this file ("Covered Code") an
240Sstevel@tonic-gate  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
250Sstevel@tonic-gate  * base code distributed originally by Intel ("Original Intel Code") to copy,
260Sstevel@tonic-gate  * make derivatives, distribute, use and display any portion of the Covered
270Sstevel@tonic-gate  * Code in any form, with the right to sublicense such rights; and
280Sstevel@tonic-gate  *
290Sstevel@tonic-gate  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
300Sstevel@tonic-gate  * license (with the right to sublicense), under only those claims of Intel
310Sstevel@tonic-gate  * patents that are infringed by the Original Intel Code, to make, use, sell,
320Sstevel@tonic-gate  * offer to sell, and import the Covered Code and derivative works thereof
330Sstevel@tonic-gate  * solely to the minimum extent necessary to exercise the above copyright
340Sstevel@tonic-gate  * license, and in no event shall the patent license extend to any additions
350Sstevel@tonic-gate  * to or modifications of the Original Intel Code.  No other license or right
360Sstevel@tonic-gate  * is granted directly or by implication, estoppel or otherwise;
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * The above copyright and patent license is granted only if the following
390Sstevel@tonic-gate  * conditions are met:
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * 3. Conditions
420Sstevel@tonic-gate  *
430Sstevel@tonic-gate  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
440Sstevel@tonic-gate  * Redistribution of source code of any substantial portion of the Covered
450Sstevel@tonic-gate  * Code or modification with rights to further distribute source must include
460Sstevel@tonic-gate  * the above Copyright Notice, the above License, this list of Conditions,
470Sstevel@tonic-gate  * and the following Disclaimer and Export Compliance provision.  In addition,
480Sstevel@tonic-gate  * Licensee must cause all Covered Code to which Licensee contributes to
490Sstevel@tonic-gate  * contain a file documenting the changes Licensee made to create that Covered
500Sstevel@tonic-gate  * Code and the date of any change.  Licensee must include in that file the
510Sstevel@tonic-gate  * documentation of any changes made by any predecessor Licensee.  Licensee
520Sstevel@tonic-gate  * must include a prominent statement that the modification is derived,
530Sstevel@tonic-gate  * directly or indirectly, from Original Intel Code.
540Sstevel@tonic-gate  *
550Sstevel@tonic-gate  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
560Sstevel@tonic-gate  * Redistribution of source code of any substantial portion of the Covered
570Sstevel@tonic-gate  * Code or modification without rights to further distribute source must
580Sstevel@tonic-gate  * include the following Disclaimer and Export Compliance provision in the
590Sstevel@tonic-gate  * documentation and/or other materials provided with distribution.  In
600Sstevel@tonic-gate  * addition, Licensee may not authorize further sublicense of source of any
610Sstevel@tonic-gate  * portion of the Covered Code, and must include terms to the effect that the
620Sstevel@tonic-gate  * license from Licensee to its licensee is limited to the intellectual
630Sstevel@tonic-gate  * property embodied in the software Licensee provides to its licensee, and
640Sstevel@tonic-gate  * not to intellectual property embodied in modifications its licensee may
650Sstevel@tonic-gate  * make.
660Sstevel@tonic-gate  *
670Sstevel@tonic-gate  * 3.3. Redistribution of Executable. Redistribution in executable form of any
680Sstevel@tonic-gate  * substantial portion of the Covered Code or modification must reproduce the
690Sstevel@tonic-gate  * above Copyright Notice, and the following Disclaimer and Export Compliance
700Sstevel@tonic-gate  * provision in the documentation and/or other materials provided with the
710Sstevel@tonic-gate  * distribution.
720Sstevel@tonic-gate  *
730Sstevel@tonic-gate  * 3.4. Intel retains all right, title, and interest in and to the Original
740Sstevel@tonic-gate  * Intel Code.
750Sstevel@tonic-gate  *
760Sstevel@tonic-gate  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
770Sstevel@tonic-gate  * Intel shall be used in advertising or otherwise to promote the sale, use or
780Sstevel@tonic-gate  * other dealings in products derived from or relating to the Covered Code
790Sstevel@tonic-gate  * without prior written authorization from Intel.
800Sstevel@tonic-gate  *
810Sstevel@tonic-gate  * 4. Disclaimer and Export Compliance
820Sstevel@tonic-gate  *
830Sstevel@tonic-gate  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
840Sstevel@tonic-gate  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
850Sstevel@tonic-gate  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
860Sstevel@tonic-gate  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
870Sstevel@tonic-gate  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
880Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
890Sstevel@tonic-gate  * PARTICULAR PURPOSE.
900Sstevel@tonic-gate  *
910Sstevel@tonic-gate  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
920Sstevel@tonic-gate  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
930Sstevel@tonic-gate  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
940Sstevel@tonic-gate  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
950Sstevel@tonic-gate  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
960Sstevel@tonic-gate  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
970Sstevel@tonic-gate  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
980Sstevel@tonic-gate  * LIMITED REMEDY.
990Sstevel@tonic-gate  *
1000Sstevel@tonic-gate  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1010Sstevel@tonic-gate  * software or system incorporating such software without first obtaining any
1020Sstevel@tonic-gate  * required license or other approval from the U. S. Department of Commerce or
1030Sstevel@tonic-gate  * any other agency or department of the United States Government.  In the
1040Sstevel@tonic-gate  * event Licensee exports any such software from the United States or
1050Sstevel@tonic-gate  * re-exports any such software from a foreign destination, Licensee shall
1060Sstevel@tonic-gate  * ensure that the distribution and export/re-export of the software is in
1070Sstevel@tonic-gate  * compliance with all laws, regulations, orders, or other restrictions of the
1080Sstevel@tonic-gate  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1090Sstevel@tonic-gate  * any of its subsidiaries will export/re-export any technical data, process,
1100Sstevel@tonic-gate  * software, or service, directly or indirectly, to any country for which the
1110Sstevel@tonic-gate  * United States government or any agency thereof requires an export license,
1120Sstevel@tonic-gate  * other governmental approval, or letter of assurance, without first obtaining
1130Sstevel@tonic-gate  * such license, approval or letter.
1140Sstevel@tonic-gate  *
1150Sstevel@tonic-gate  *****************************************************************************/
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate #ifndef __ACMACROS_H__
1180Sstevel@tonic-gate #define __ACMACROS_H__
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate  * Data manipulation macros
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate #define ACPI_LOWORD(l)                  ((UINT16)(UINT32)(l))
1250Sstevel@tonic-gate #define ACPI_HIWORD(l)                  ((UINT16)((((UINT32)(l)) >> 16) & 0xFFFF))
1260Sstevel@tonic-gate #define ACPI_LOBYTE(l)                  ((UINT8)(UINT16)(l))
1270Sstevel@tonic-gate #define ACPI_HIBYTE(l)                  ((UINT8)((((UINT16)(l)) >> 8) & 0xFF))
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate #define ACPI_SET_BIT(target,bit)        ((target) |= (bit))
1300Sstevel@tonic-gate #define ACPI_CLEAR_BIT(target,bit)      ((target) &= ~(bit))
1310Sstevel@tonic-gate #define ACPI_MIN(a,b)                   (((a)<(b))?(a):(b))
132*7851SDana.Myers@Sun.COM #define ACPI_MAX(a,b)                   (((a)>(b))?(a):(b))
1330Sstevel@tonic-gate 
1342623Smyers /* Size calculation */
1352623Smyers 
1362623Smyers #define ACPI_ARRAY_LENGTH(x)            (sizeof(x) / sizeof((x)[0]))
1372623Smyers 
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
140*7851SDana.Myers@Sun.COM  * Extract data using a pointer. Any more than a byte and we
1411560Smyers  * get into potential aligment issues -- see the STORE macros below.
1421560Smyers  * Use with care.
1430Sstevel@tonic-gate  */
1441560Smyers #define ACPI_GET8(ptr)                  *ACPI_CAST_PTR (UINT8, ptr)
1451560Smyers #define ACPI_GET16(ptr)                 *ACPI_CAST_PTR (UINT16, ptr)
1461560Smyers #define ACPI_GET32(ptr)                 *ACPI_CAST_PTR (UINT32, ptr)
1471560Smyers #define ACPI_GET64(ptr)                 *ACPI_CAST_PTR (UINT64, ptr)
1481560Smyers #define ACPI_SET8(ptr)                  *ACPI_CAST_PTR (UINT8, ptr)
1491560Smyers #define ACPI_SET16(ptr)                 *ACPI_CAST_PTR (UINT16, ptr)
1501560Smyers #define ACPI_SET32(ptr)                 *ACPI_CAST_PTR (UINT32, ptr)
1511560Smyers #define ACPI_SET64(ptr)                 *ACPI_CAST_PTR (UINT64, ptr)
1520Sstevel@tonic-gate 
1531560Smyers /*
1541560Smyers  * Pointer manipulation
1551560Smyers  */
1561560Smyers #define ACPI_CAST_PTR(t, p)             ((t *) (ACPI_UINTPTR_T) (p))
1571560Smyers #define ACPI_CAST_INDIRECT_PTR(t, p)    ((t **) (ACPI_UINTPTR_T) (p))
158*7851SDana.Myers@Sun.COM #define ACPI_ADD_PTR(t, a, b)           ACPI_CAST_PTR (t, (ACPI_CAST_PTR (UINT8, (a)) + (ACPI_SIZE)(b)))
159*7851SDana.Myers@Sun.COM #define ACPI_PTR_DIFF(a, b)             (ACPI_SIZE) (ACPI_CAST_PTR (UINT8, (a)) - ACPI_CAST_PTR (UINT8, (b)))
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /* Pointer/Integer type conversions */
1620Sstevel@tonic-gate 
163*7851SDana.Myers@Sun.COM #define ACPI_TO_POINTER(i)              ACPI_ADD_PTR (void, (void *) NULL,(ACPI_SIZE) i)
164*7851SDana.Myers@Sun.COM #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p, (void *) NULL)
165*7851SDana.Myers@Sun.COM #define ACPI_OFFSET(d, f)               (ACPI_SIZE) ACPI_PTR_DIFF (&(((d *)0)->f), (void *) NULL)
1660Sstevel@tonic-gate #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
1670Sstevel@tonic-gate #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
1680Sstevel@tonic-gate 
1692623Smyers #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
170*7851SDana.Myers@Sun.COM #define ACPI_COMPARE_NAME(a,b)          (*ACPI_CAST_PTR (UINT32, (a)) == *ACPI_CAST_PTR (UINT32, (b)))
1712623Smyers #else
172*7851SDana.Myers@Sun.COM #define ACPI_COMPARE_NAME(a,b)          (!ACPI_STRNCMP (ACPI_CAST_PTR (char, (a)), ACPI_CAST_PTR (char, (b)), ACPI_NAME_SIZE))
1732623Smyers #endif
1742623Smyers 
1750Sstevel@tonic-gate /*
176*7851SDana.Myers@Sun.COM  * Full 64-bit integer must be available on both 32-bit and 64-bit platforms
177*7851SDana.Myers@Sun.COM  */
178*7851SDana.Myers@Sun.COM typedef struct acpi_integer_overlay
179*7851SDana.Myers@Sun.COM {
180*7851SDana.Myers@Sun.COM     UINT32              LoDword;
181*7851SDana.Myers@Sun.COM     UINT32              HiDword;
182*7851SDana.Myers@Sun.COM 
183*7851SDana.Myers@Sun.COM } ACPI_INTEGER_OVERLAY;
184*7851SDana.Myers@Sun.COM 
185*7851SDana.Myers@Sun.COM #define ACPI_LODWORD(Integer)           (ACPI_CAST_PTR (ACPI_INTEGER_OVERLAY, &Integer)->LoDword)
186*7851SDana.Myers@Sun.COM #define ACPI_HIDWORD(Integer)           (ACPI_CAST_PTR (ACPI_INTEGER_OVERLAY, &Integer)->HiDword)
187*7851SDana.Myers@Sun.COM 
188*7851SDana.Myers@Sun.COM /*
189*7851SDana.Myers@Sun.COM  * printf() format helpers
190*7851SDana.Myers@Sun.COM  */
191*7851SDana.Myers@Sun.COM 
192*7851SDana.Myers@Sun.COM /* Split 64-bit integer into two 32-bit values. Use with %8.8X%8.8X */
193*7851SDana.Myers@Sun.COM 
194*7851SDana.Myers@Sun.COM #define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i), ACPI_LODWORD(i)
195*7851SDana.Myers@Sun.COM 
196*7851SDana.Myers@Sun.COM #if ACPI_MACHINE_WIDTH == 64
197*7851SDana.Myers@Sun.COM #define ACPI_FORMAT_NATIVE_UINT(i)      ACPI_FORMAT_UINT64(i)
198*7851SDana.Myers@Sun.COM #else
199*7851SDana.Myers@Sun.COM #define ACPI_FORMAT_NATIVE_UINT(i)      0, (i)
200*7851SDana.Myers@Sun.COM #endif
201*7851SDana.Myers@Sun.COM 
202*7851SDana.Myers@Sun.COM 
203*7851SDana.Myers@Sun.COM /*
2040Sstevel@tonic-gate  * Macros for moving data around to/from buffers that are possibly unaligned.
2050Sstevel@tonic-gate  * If the hardware supports the transfer of unaligned data, just do the store.
2060Sstevel@tonic-gate  * Otherwise, we have to move one byte at a time.
2070Sstevel@tonic-gate  */
2080Sstevel@tonic-gate #ifdef ACPI_BIG_ENDIAN
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate  * Macros for big-endian machines
2110Sstevel@tonic-gate  */
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate /* These macros reverse the bytes during the move, converting little-endian to big endian */
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate                                                      /* Big Endian      <==        Little Endian */
2160Sstevel@tonic-gate                                                      /*  Hi...Lo                     Lo...Hi     */
2170Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
2180Sstevel@tonic-gate 
219*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_16(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
2200Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
2210Sstevel@tonic-gate 
222*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_32(d, s)        {(*(UINT32 *)(void *)(d))=0;\
2230Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
2240Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
2250Sstevel@tonic-gate 
226*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_64(d, s)        {(*(UINT64 *)(void *)(d))=0;\
2270Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
2280Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
2310Sstevel@tonic-gate 
232*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
2330Sstevel@tonic-gate 
234*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_32(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
2350Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
2360Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
2370Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
2380Sstevel@tonic-gate 
239*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_64(d, s)        {(*(UINT64 *)(void *)(d))=0;\
2400Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
2410Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
2420Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
2430Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
2460Sstevel@tonic-gate 
247*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
2480Sstevel@tonic-gate 
249*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
2500Sstevel@tonic-gate 
251*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_64(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
2520Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
2530Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
2540Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
2550Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
2560Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
2570Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
2580Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
2590Sstevel@tonic-gate #else
2600Sstevel@tonic-gate /*
2610Sstevel@tonic-gate  * Macros for little-endian machines
2620Sstevel@tonic-gate  */
2630Sstevel@tonic-gate 
2641560Smyers #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /* The hardware supports unaligned transfers, just do the little-endian move */
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
2690Sstevel@tonic-gate 
270*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_16(d, s)        *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
271*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_32(d, s)        *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
272*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s)
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
2750Sstevel@tonic-gate 
276*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
277*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_32(d, s)        *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
278*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s)
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
2810Sstevel@tonic-gate 
282*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
283*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
284*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s)
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate #else
2870Sstevel@tonic-gate /*
288*7851SDana.Myers@Sun.COM  * The hardware does not support unaligned transfers. We must move the
289*7851SDana.Myers@Sun.COM  * data one byte at a time. These macros work whether the source or
2900Sstevel@tonic-gate  * the destination (or both) is/are unaligned.  (Little-endian move)
2910Sstevel@tonic-gate  */
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
2940Sstevel@tonic-gate 
295*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_16(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
2960Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];}
2970Sstevel@tonic-gate 
298*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_32(d, s)        {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
299*7851SDana.Myers@Sun.COM #define ACPI_MOVE_16_TO_64(d, s)        {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
3020Sstevel@tonic-gate 
303*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
3040Sstevel@tonic-gate 
305*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_32(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
3060Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
3070Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
3080Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];}
3090Sstevel@tonic-gate 
310*7851SDana.Myers@Sun.COM #define ACPI_MOVE_32_TO_64(d, s)        {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);}
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
3130Sstevel@tonic-gate 
314*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
315*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
316*7851SDana.Myers@Sun.COM #define ACPI_MOVE_64_TO_64(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
3170Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
3180Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
3190Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\
3200Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\
3210Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\
3220Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
3230Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
3240Sstevel@tonic-gate #endif
3250Sstevel@tonic-gate #endif
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate /*
3290Sstevel@tonic-gate  * Fast power-of-two math macros for non-optimized compilers
3300Sstevel@tonic-gate  */
331*7851SDana.Myers@Sun.COM #define _ACPI_DIV(value, PowerOf2)      ((UINT32) ((value) >> (PowerOf2)))
332*7851SDana.Myers@Sun.COM #define _ACPI_MUL(value, PowerOf2)      ((UINT32) ((value) << (PowerOf2)))
333*7851SDana.Myers@Sun.COM #define _ACPI_MOD(value, Divisor)       ((UINT32) ((value) & ((Divisor) -1)))
3340Sstevel@tonic-gate 
335*7851SDana.Myers@Sun.COM #define ACPI_DIV_2(a)                   _ACPI_DIV(a, 1)
336*7851SDana.Myers@Sun.COM #define ACPI_MUL_2(a)                   _ACPI_MUL(a, 1)
337*7851SDana.Myers@Sun.COM #define ACPI_MOD_2(a)                   _ACPI_MOD(a, 2)
3380Sstevel@tonic-gate 
339*7851SDana.Myers@Sun.COM #define ACPI_DIV_4(a)                   _ACPI_DIV(a, 2)
340*7851SDana.Myers@Sun.COM #define ACPI_MUL_4(a)                   _ACPI_MUL(a, 2)
341*7851SDana.Myers@Sun.COM #define ACPI_MOD_4(a)                   _ACPI_MOD(a, 4)
3420Sstevel@tonic-gate 
343*7851SDana.Myers@Sun.COM #define ACPI_DIV_8(a)                   _ACPI_DIV(a, 3)
344*7851SDana.Myers@Sun.COM #define ACPI_MUL_8(a)                   _ACPI_MUL(a, 3)
345*7851SDana.Myers@Sun.COM #define ACPI_MOD_8(a)                   _ACPI_MOD(a, 8)
3460Sstevel@tonic-gate 
347*7851SDana.Myers@Sun.COM #define ACPI_DIV_16(a)                  _ACPI_DIV(a, 4)
348*7851SDana.Myers@Sun.COM #define ACPI_MUL_16(a)                  _ACPI_MUL(a, 4)
349*7851SDana.Myers@Sun.COM #define ACPI_MOD_16(a)                  _ACPI_MOD(a, 16)
3500Sstevel@tonic-gate 
351*7851SDana.Myers@Sun.COM #define ACPI_DIV_32(a)                  _ACPI_DIV(a, 5)
352*7851SDana.Myers@Sun.COM #define ACPI_MUL_32(a)                  _ACPI_MUL(a, 5)
353*7851SDana.Myers@Sun.COM #define ACPI_MOD_32(a)                  _ACPI_MOD(a, 32)
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate /*
3560Sstevel@tonic-gate  * Rounding macros (Power of two boundaries only)
3570Sstevel@tonic-gate  */
358*7851SDana.Myers@Sun.COM #define ACPI_ROUND_DOWN(value, boundary)    (((ACPI_SIZE)(value)) & \
359*7851SDana.Myers@Sun.COM                                                 (~(((ACPI_SIZE) boundary)-1)))
3600Sstevel@tonic-gate 
361*7851SDana.Myers@Sun.COM #define ACPI_ROUND_UP(value, boundary)      ((((ACPI_SIZE)(value)) + \
362*7851SDana.Myers@Sun.COM                                                 (((ACPI_SIZE) boundary)-1)) & \
363*7851SDana.Myers@Sun.COM                                                 (~(((ACPI_SIZE) boundary)-1)))
3641560Smyers 
365*7851SDana.Myers@Sun.COM /* Note: sizeof(ACPI_SIZE) evaluates to either 4 or 8 (32- vs 64-bit mode) */
3660Sstevel@tonic-gate 
367*7851SDana.Myers@Sun.COM #define ACPI_ROUND_DOWN_TO_32BIT(a)         ACPI_ROUND_DOWN(a, 4)
368*7851SDana.Myers@Sun.COM #define ACPI_ROUND_DOWN_TO_64BIT(a)         ACPI_ROUND_DOWN(a, 8)
369*7851SDana.Myers@Sun.COM #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)   ACPI_ROUND_DOWN(a, sizeof(ACPI_SIZE))
3700Sstevel@tonic-gate 
371*7851SDana.Myers@Sun.COM #define ACPI_ROUND_UP_TO_32BIT(a)           ACPI_ROUND_UP(a, 4)
372*7851SDana.Myers@Sun.COM #define ACPI_ROUND_UP_TO_64BIT(a)           ACPI_ROUND_UP(a, 8)
373*7851SDana.Myers@Sun.COM #define ACPI_ROUND_UP_TO_NATIVE_WORD(a)     ACPI_ROUND_UP(a, sizeof(ACPI_SIZE))
3740Sstevel@tonic-gate 
3751560Smyers #define ACPI_ROUND_BITS_UP_TO_BYTES(a)      ACPI_DIV_8((a) + 7)
3761560Smyers #define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)    ACPI_DIV_8((a))
3771560Smyers 
3781560Smyers #define ACPI_ROUND_UP_TO_1K(a)              (((a) + 1023) >> 10)
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate /* Generic (non-power-of-two) rounding */
3810Sstevel@tonic-gate 
382*7851SDana.Myers@Sun.COM #define ACPI_ROUND_UP_TO(value, boundary)   (((value) + ((boundary)-1)) / (boundary))
3831560Smyers 
384*7851SDana.Myers@Sun.COM #define ACPI_IS_MISALIGNED(value)           (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1))
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate /*
3870Sstevel@tonic-gate  * Bitmask creation
3880Sstevel@tonic-gate  * Bit positions start at zero.
3890Sstevel@tonic-gate  * MASK_BITS_ABOVE creates a mask starting AT the position and above
3900Sstevel@tonic-gate  * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
3910Sstevel@tonic-gate  */
3921560Smyers #define ACPI_MASK_BITS_ABOVE(position)      (~((ACPI_INTEGER_MAX) << ((UINT32) (position))))
3931560Smyers #define ACPI_MASK_BITS_BELOW(position)      ((ACPI_INTEGER_MAX) << ((UINT32) (position)))
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate /* Bitfields within ACPI registers */
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate #define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)      ((Val << Pos) & Mask)
3980Sstevel@tonic-gate #define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val)  Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
3990Sstevel@tonic-gate 
4002623Smyers #define ACPI_INSERT_BITS(Target, Mask, Source)          Target = ((Target & (~(Mask))) | (Source & Mask))
4012623Smyers 
4020Sstevel@tonic-gate /*
403*7851SDana.Myers@Sun.COM  * An ACPI_NAMESPACE_NODE can appear in some contexts
404*7851SDana.Myers@Sun.COM  * where a pointer to an ACPI_OPERAND_OBJECT can also
405*7851SDana.Myers@Sun.COM  * appear. This macro is used to distinguish them.
4060Sstevel@tonic-gate  *
4070Sstevel@tonic-gate  * The "Descriptor" field is the first field in both structures.
4080Sstevel@tonic-gate  */
4092623Smyers #define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType)
410*7851SDana.Myers@Sun.COM #define ACPI_SET_DESCRIPTOR_TYPE(d, t)  (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType = t)
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate /* Macro to test the object type */
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate #define ACPI_GET_OBJECT_TYPE(d)         (((ACPI_OPERAND_OBJECT *)(void *)(d))->Common.Type)
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate /*
4170Sstevel@tonic-gate  * Macros for the master AML opcode table
4180Sstevel@tonic-gate  */
419*7851SDana.Myers@Sun.COM #if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
420*7851SDana.Myers@Sun.COM #define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \
421*7851SDana.Myers@Sun.COM     {Name, (UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type}
4220Sstevel@tonic-gate #else
423*7851SDana.Myers@Sun.COM #define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \
424*7851SDana.Myers@Sun.COM     {(UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type}
4250Sstevel@tonic-gate #endif
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate #ifdef ACPI_DISASSEMBLER
4280Sstevel@tonic-gate #define ACPI_DISASM_ONLY_MEMBERS(a)     a;
4290Sstevel@tonic-gate #else
4300Sstevel@tonic-gate #define ACPI_DISASM_ONLY_MEMBERS(a)
4310Sstevel@tonic-gate #endif
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate #define ARG_TYPE_WIDTH                  5
4340Sstevel@tonic-gate #define ARG_1(x)                        ((UINT32)(x))
4350Sstevel@tonic-gate #define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
4360Sstevel@tonic-gate #define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
4370Sstevel@tonic-gate #define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
4380Sstevel@tonic-gate #define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
4390Sstevel@tonic-gate #define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate #define ARGI_LIST1(a)                   (ARG_1(a))
442*7851SDana.Myers@Sun.COM #define ARGI_LIST2(a, b)                (ARG_1(b)|ARG_2(a))
443*7851SDana.Myers@Sun.COM #define ARGI_LIST3(a, b, c)             (ARG_1(c)|ARG_2(b)|ARG_3(a))
444*7851SDana.Myers@Sun.COM #define ARGI_LIST4(a, b, c, d)          (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
445*7851SDana.Myers@Sun.COM #define ARGI_LIST5(a, b, c, d, e)       (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
446*7851SDana.Myers@Sun.COM #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))
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate #define ARGP_LIST1(a)                   (ARG_1(a))
449*7851SDana.Myers@Sun.COM #define ARGP_LIST2(a, b)                (ARG_1(a)|ARG_2(b))
450*7851SDana.Myers@Sun.COM #define ARGP_LIST3(a, b, c)             (ARG_1(a)|ARG_2(b)|ARG_3(c))
451*7851SDana.Myers@Sun.COM #define ARGP_LIST4(a, b, c, d)          (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
452*7851SDana.Myers@Sun.COM #define ARGP_LIST5(a, b, c, d, e)       (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
453*7851SDana.Myers@Sun.COM #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))
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate #define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
4560Sstevel@tonic-gate #define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 
4591560Smyers #if defined (ACPI_DEBUG_OUTPUT) || !defined (ACPI_NO_ERROR_MESSAGES)
4600Sstevel@tonic-gate /*
4611560Smyers  * Module name is include in both debug and non-debug versions primarily for
4621560Smyers  * error messages. The __FILE__ macro is not very useful for this, because it
4631560Smyers  * often includes the entire pathname to the module
4640Sstevel@tonic-gate  */
465*7851SDana.Myers@Sun.COM #define ACPI_MODULE_NAME(Name)          static const char ACPI_UNUSED_VAR _AcpiModuleName[] = Name;
4661560Smyers #else
4671560Smyers #define ACPI_MODULE_NAME(Name)
4681560Smyers #endif
4691560Smyers 
4701560Smyers /*
4711560Smyers  * Ascii error messages can be configured out
4721560Smyers  */
4731560Smyers #ifndef ACPI_NO_ERROR_MESSAGES
4741560Smyers #define AE_INFO                         _AcpiModuleName, __LINE__
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate /*
4771560Smyers  * Error reporting. Callers module and line number are inserted by AE_INFO,
4781560Smyers  * the plist contains a set of parens to allow variable-length lists.
4791560Smyers  * These macros are used for both the debug and non-debug versions of the code.
4800Sstevel@tonic-gate  */
4811560Smyers #define ACPI_INFO(plist)                AcpiUtInfo plist
4821560Smyers #define ACPI_WARNING(plist)             AcpiUtWarning plist
4831560Smyers #define ACPI_EXCEPTION(plist)           AcpiUtException plist
4841560Smyers #define ACPI_ERROR(plist)               AcpiUtError plist
485*7851SDana.Myers@Sun.COM #define ACPI_ERROR_NAMESPACE(s, e)      AcpiNsReportError (AE_INFO, s, e);
486*7851SDana.Myers@Sun.COM #define ACPI_ERROR_METHOD(s, n, p, e)   AcpiNsReportMethodError (AE_INFO, s, n, p, e);
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate #else
4890Sstevel@tonic-gate 
4901560Smyers /* No error messages */
4910Sstevel@tonic-gate 
4921560Smyers #define ACPI_INFO(plist)
4931560Smyers #define ACPI_WARNING(plist)
4941560Smyers #define ACPI_EXCEPTION(plist)
4951560Smyers #define ACPI_ERROR(plist)
496*7851SDana.Myers@Sun.COM #define ACPI_ERROR_NAMESPACE(s, e)
497*7851SDana.Myers@Sun.COM #define ACPI_ERROR_METHOD(s, n, p, e)
4981560Smyers #endif
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate /*
5010Sstevel@tonic-gate  * Debug macros that are conditionally compiled
5020Sstevel@tonic-gate  */
5030Sstevel@tonic-gate #ifdef ACPI_DEBUG_OUTPUT
5040Sstevel@tonic-gate 
505347Smyers /*
506347Smyers  * Common parameters used for debug output functions:
507347Smyers  * line number, function name, module(file) name, component ID
508347Smyers  */
509347Smyers #define ACPI_DEBUG_PARAMETERS           __LINE__, ACPI_GET_FUNCTION_NAME, _AcpiModuleName, _COMPONENT
510347Smyers 
511347Smyers /*
512347Smyers  * Function entry tracing
513347Smyers  */
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate /*
516347Smyers  * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header,
517347Smyers  * define it now. This is the case where there the compiler does not support
518*7851SDana.Myers@Sun.COM  * a __FUNCTION__ macro or equivalent.
5190Sstevel@tonic-gate  */
520347Smyers #ifndef ACPI_GET_FUNCTION_NAME
521347Smyers #define ACPI_GET_FUNCTION_NAME          _AcpiFunctionName
522347Smyers /*
523347Smyers  * The Name parameter should be the procedure name as a quoted string.
524*7851SDana.Myers@Sun.COM  * The function name is also used by the function exit macros below.
525941Smyers  * Note: (const char) is used to be compatible with the debug interfaces
526941Smyers  * and macros such as __FUNCTION__.
527347Smyers  */
528*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_NAME(Name)        static const char _AcpiFunctionName[] = #Name;
5290Sstevel@tonic-gate 
530347Smyers #else
531347Smyers /* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */
532347Smyers 
533347Smyers #define ACPI_FUNCTION_NAME(Name)
534347Smyers #endif
5350Sstevel@tonic-gate 
536347Smyers #define ACPI_FUNCTION_TRACE(a)          ACPI_FUNCTION_NAME(a) \
537347Smyers                                             AcpiUtTrace(ACPI_DEBUG_PARAMETERS)
538*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_TRACE_PTR(a, b)   ACPI_FUNCTION_NAME(a) \
539*7851SDana.Myers@Sun.COM                                             AcpiUtTracePtr(ACPI_DEBUG_PARAMETERS, (void *)b)
540*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_TRACE_U32(a, b)   ACPI_FUNCTION_NAME(a) \
541*7851SDana.Myers@Sun.COM                                             AcpiUtTraceU32(ACPI_DEBUG_PARAMETERS, (UINT32)b)
542*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_TRACE_STR(a, b)   ACPI_FUNCTION_NAME(a) \
543*7851SDana.Myers@Sun.COM                                             AcpiUtTraceStr(ACPI_DEBUG_PARAMETERS, (char *)b)
544347Smyers 
545347Smyers #define ACPI_FUNCTION_ENTRY()           AcpiUtTrackStackPtr()
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate  * Function exit tracing.
549*7851SDana.Myers@Sun.COM  * WARNING: These macros include a return statement. This is usually considered
5500Sstevel@tonic-gate  * bad form, but having a separate exit macro is very ugly and difficult to maintain.
5510Sstevel@tonic-gate  * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
552347Smyers  * so that "_AcpiFunctionName" is defined.
553941Smyers  *
554941Smyers  * Note: the DO_WHILE0 macro is used to prevent some compilers from complaining
555941Smyers  * about these constructs.
5560Sstevel@tonic-gate  */
5570Sstevel@tonic-gate #ifdef ACPI_USE_DO_WHILE_0
5580Sstevel@tonic-gate #define ACPI_DO_WHILE0(a)               do a while(0)
5590Sstevel@tonic-gate #else
5600Sstevel@tonic-gate #define ACPI_DO_WHILE0(a)               a
5610Sstevel@tonic-gate #endif
5620Sstevel@tonic-gate 
563941Smyers #define return_VOID                     ACPI_DO_WHILE0 ({ \
564941Smyers                                             AcpiUtExit (ACPI_DEBUG_PARAMETERS); \
565941Smyers                                             return;})
566941Smyers /*
567941Smyers  * There are two versions of most of the return macros. The default version is
568941Smyers  * safer, since it avoids side-effects by guaranteeing that the argument will
569941Smyers  * not be evaluated twice.
5701560Smyers  *
571941Smyers  * A less-safe version of the macros is provided for optional use if the
572941Smyers  * compiler uses excessive CPU stack (for example, this may happen in the
573941Smyers  * debug case if code optimzation is disabled.)
574941Smyers  */
575941Smyers #ifndef ACPI_SIMPLE_RETURN_MACROS
576941Smyers 
577941Smyers #define return_ACPI_STATUS(s)           ACPI_DO_WHILE0 ({ \
578941Smyers                                             register ACPI_STATUS _s = (s); \
579941Smyers                                             AcpiUtStatusExit (ACPI_DEBUG_PARAMETERS, _s); \
580941Smyers                                             return (_s); })
581941Smyers #define return_PTR(s)                   ACPI_DO_WHILE0 ({ \
582941Smyers                                             register void *_s = (void *) (s); \
583941Smyers                                             AcpiUtPtrExit (ACPI_DEBUG_PARAMETERS, (UINT8 *) _s); \
584941Smyers                                             return (_s); })
585941Smyers #define return_VALUE(s)                 ACPI_DO_WHILE0 ({ \
586941Smyers                                             register ACPI_INTEGER _s = (s); \
587941Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, _s); \
588941Smyers                                             return (_s); })
589941Smyers #define return_UINT8(s)                 ACPI_DO_WHILE0 ({ \
590941Smyers                                             register UINT8 _s = (UINT8) (s); \
5911560Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (ACPI_INTEGER) _s); \
592941Smyers                                             return (_s); })
593941Smyers #define return_UINT32(s)                ACPI_DO_WHILE0 ({ \
594941Smyers                                             register UINT32 _s = (UINT32) (s); \
5951560Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (ACPI_INTEGER) _s); \
596941Smyers                                             return (_s); })
597941Smyers #else /* Use original less-safe macros */
598941Smyers 
599941Smyers #define return_ACPI_STATUS(s)           ACPI_DO_WHILE0 ({ \
600941Smyers                                             AcpiUtStatusExit (ACPI_DEBUG_PARAMETERS, (s)); \
601941Smyers                                             return((s)); })
602941Smyers #define return_PTR(s)                   ACPI_DO_WHILE0 ({ \
603941Smyers                                             AcpiUtPtrExit (ACPI_DEBUG_PARAMETERS, (UINT8 *) (s)); \
604941Smyers                                             return((s)); })
605941Smyers #define return_VALUE(s)                 ACPI_DO_WHILE0 ({ \
606941Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (ACPI_INTEGER) (s)); \
607941Smyers                                             return((s)); })
608941Smyers #define return_UINT8(s)                 return_VALUE(s)
609941Smyers #define return_UINT32(s)                return_VALUE(s)
610941Smyers 
611941Smyers #endif /* ACPI_SIMPLE_RETURN_MACROS */
612941Smyers 
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate /* Conditional execution */
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate #define ACPI_DEBUG_EXEC(a)              a
6170Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a)      a;
6180Sstevel@tonic-gate #define _VERBOSE_STRUCTURES
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate 
621*7851SDana.Myers@Sun.COM /* Various object display routines for debug */
6220Sstevel@tonic-gate 
623*7851SDana.Myers@Sun.COM #define ACPI_DUMP_STACK_ENTRY(a)        AcpiExDumpOperand((a), 0)
624*7851SDana.Myers@Sun.COM #define ACPI_DUMP_OPERANDS(a, b ,c)     AcpiExDumpOperands(a, b, c)
625*7851SDana.Myers@Sun.COM #define ACPI_DUMP_ENTRY(a, b)           AcpiNsDumpEntry (a, b)
626*7851SDana.Myers@Sun.COM #define ACPI_DUMP_PATHNAME(a, b, c, d)  AcpiNsDumpPathname(a, b, c, d)
627*7851SDana.Myers@Sun.COM #define ACPI_DUMP_BUFFER(a, b)          AcpiUtDumpBuffer((UINT8 *) a, b, DB_BYTE_DISPLAY, _COMPONENT)
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate /*
6300Sstevel@tonic-gate  * Master debug print macros
6310Sstevel@tonic-gate  * Print iff:
6320Sstevel@tonic-gate  *    1) Debug print for the current component is enabled
6330Sstevel@tonic-gate  *    2) Debug error level or trace level for the print statement is enabled
6340Sstevel@tonic-gate  */
6351560Smyers #define ACPI_DEBUG_PRINT(plist)         AcpiUtDebugPrint plist
6361560Smyers #define ACPI_DEBUG_PRINT_RAW(plist)     AcpiUtDebugPrintRaw plist
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate #else
6400Sstevel@tonic-gate /*
6410Sstevel@tonic-gate  * This is the non-debug case -- make everything go away,
6420Sstevel@tonic-gate  * leaving no executable debug code!
6430Sstevel@tonic-gate  */
6440Sstevel@tonic-gate #define ACPI_DEBUG_EXEC(a)
6450Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a)
6460Sstevel@tonic-gate #define ACPI_FUNCTION_NAME(a)
6470Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE(a)
648*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_TRACE_PTR(a, b)
649*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_TRACE_U32(a, b)
650*7851SDana.Myers@Sun.COM #define ACPI_FUNCTION_TRACE_STR(a, b)
6510Sstevel@tonic-gate #define ACPI_FUNCTION_EXIT
6520Sstevel@tonic-gate #define ACPI_FUNCTION_STATUS_EXIT(s)
6530Sstevel@tonic-gate #define ACPI_FUNCTION_VALUE_EXIT(s)
6540Sstevel@tonic-gate #define ACPI_FUNCTION_ENTRY()
6550Sstevel@tonic-gate #define ACPI_DUMP_STACK_ENTRY(a)
656*7851SDana.Myers@Sun.COM #define ACPI_DUMP_OPERANDS(a, b, c)
657*7851SDana.Myers@Sun.COM #define ACPI_DUMP_ENTRY(a, b)
658*7851SDana.Myers@Sun.COM #define ACPI_DUMP_TABLES(a, b)
659*7851SDana.Myers@Sun.COM #define ACPI_DUMP_PATHNAME(a, b, c, d)
660*7851SDana.Myers@Sun.COM #define ACPI_DUMP_BUFFER(a, b)
6610Sstevel@tonic-gate #define ACPI_DEBUG_PRINT(pl)
6620Sstevel@tonic-gate #define ACPI_DEBUG_PRINT_RAW(pl)
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate #define return_VOID                     return
6650Sstevel@tonic-gate #define return_ACPI_STATUS(s)           return(s)
6660Sstevel@tonic-gate #define return_VALUE(s)                 return(s)
667941Smyers #define return_UINT8(s)                 return(s)
668941Smyers #define return_UINT32(s)                return(s)
6690Sstevel@tonic-gate #define return_PTR(s)                   return(s)
6700Sstevel@tonic-gate 
6710Sstevel@tonic-gate #endif
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate /*
6740Sstevel@tonic-gate  * Some code only gets executed when the debugger is built in.
6750Sstevel@tonic-gate  * Note that this is entirely independent of whether the
6760Sstevel@tonic-gate  * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not.
6770Sstevel@tonic-gate  */
6780Sstevel@tonic-gate #ifdef ACPI_DEBUGGER
6790Sstevel@tonic-gate #define ACPI_DEBUGGER_EXEC(a)           a
6800Sstevel@tonic-gate #else
6810Sstevel@tonic-gate #define ACPI_DEBUGGER_EXEC(a)
6820Sstevel@tonic-gate #endif
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate /*
6860Sstevel@tonic-gate  * Memory allocation tracking (DEBUG ONLY)
6870Sstevel@tonic-gate  */
688*7851SDana.Myers@Sun.COM #define ACPI_MEM_PARAMETERS         _COMPONENT, _AcpiModuleName, __LINE__
689*7851SDana.Myers@Sun.COM 
6900Sstevel@tonic-gate #ifndef ACPI_DBG_TRACK_ALLOCATIONS
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate /* Memory allocation */
6930Sstevel@tonic-gate 
694*7851SDana.Myers@Sun.COM #define ACPI_ALLOCATE(a)            AcpiUtAllocate((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS)
695*7851SDana.Myers@Sun.COM #define ACPI_ALLOCATE_ZEROED(a)     AcpiUtAllocateZeroed((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS)
6962623Smyers #define ACPI_FREE(a)                AcpiOsFree(a)
6970Sstevel@tonic-gate #define ACPI_MEM_TRACKING(a)
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate #else
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate /* Memory allocation */
7020Sstevel@tonic-gate 
703*7851SDana.Myers@Sun.COM #define ACPI_ALLOCATE(a)            AcpiUtAllocateAndTrack((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS)
704*7851SDana.Myers@Sun.COM #define ACPI_ALLOCATE_ZEROED(a)     AcpiUtAllocateZeroedAndTrack((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS)
705*7851SDana.Myers@Sun.COM #define ACPI_FREE(a)                AcpiUtFreeAndTrack(a, ACPI_MEM_PARAMETERS)
7062623Smyers #define ACPI_MEM_TRACKING(a)        a
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
7090Sstevel@tonic-gate 
710*7851SDana.Myers@Sun.COM 
711*7851SDana.Myers@Sun.COM /*
712*7851SDana.Myers@Sun.COM  * Macros used for ACPICA utilities only
713*7851SDana.Myers@Sun.COM  */
714*7851SDana.Myers@Sun.COM 
715*7851SDana.Myers@Sun.COM /* Generate a UUID */
716*7851SDana.Myers@Sun.COM 
717*7851SDana.Myers@Sun.COM #define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
718*7851SDana.Myers@Sun.COM     (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \
719*7851SDana.Myers@Sun.COM     (b) & 0xFF, ((b) >> 8) & 0xFF, \
720*7851SDana.Myers@Sun.COM     (c) & 0xFF, ((c) >> 8) & 0xFF, \
721*7851SDana.Myers@Sun.COM     (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)
722*7851SDana.Myers@Sun.COM 
723*7851SDana.Myers@Sun.COM #define ACPI_IS_OCTAL_DIGIT(d)              (((char)(d) >= '0') && ((char)(d) <= '7'))
724*7851SDana.Myers@Sun.COM 
725*7851SDana.Myers@Sun.COM 
7260Sstevel@tonic-gate #endif /* ACMACROS_H */
727