10Sstevel@tonic-gate /******************************************************************************
20Sstevel@tonic-gate  *
30Sstevel@tonic-gate  * Name: acmacros.h - C macros for the entire subsystem.
4*1560Smyers  *       $Revision: 1.180 $
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*1560Smyers  * Some or all of this work - Copyright (c) 1999 - 2006, 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))
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * For 16-bit addresses, we have to assume that the upper 32 bits
138*1560Smyers  * (out of 64) are zero.
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate #define ACPI_LODWORD(l)                 ((UINT32)(l))
1410Sstevel@tonic-gate #define ACPI_HIDWORD(l)                 ((UINT32)(0))
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #define ACPI_GET_ADDRESS(a)             ((a).Lo)
1440Sstevel@tonic-gate #define ACPI_STORE_ADDRESS(a,b)         {(a).Hi=0;(a).Lo=(UINT32)(b);}
1450Sstevel@tonic-gate #define ACPI_VALID_ADDRESS(a)           ((a).Hi | (a).Lo)
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #else
1480Sstevel@tonic-gate #ifdef ACPI_NO_INTEGER64_SUPPORT
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate  * ACPI_INTEGER is 32-bits, no 64-bit support on this platform
1510Sstevel@tonic-gate  */
1520Sstevel@tonic-gate #define ACPI_LODWORD(l)                 ((UINT32)(l))
1530Sstevel@tonic-gate #define ACPI_HIDWORD(l)                 ((UINT32)(0))
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate #define ACPI_GET_ADDRESS(a)             (a)
1560Sstevel@tonic-gate #define ACPI_STORE_ADDRESS(a,b)         ((a)=(b))
1570Sstevel@tonic-gate #define ACPI_VALID_ADDRESS(a)           (a)
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #else
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * Full 64-bit address/integer on both 32-bit and 64-bit platforms
1630Sstevel@tonic-gate  */
1640Sstevel@tonic-gate #define ACPI_LODWORD(l)                 ((UINT32)(UINT64)(l))
1650Sstevel@tonic-gate #define ACPI_HIDWORD(l)                 ((UINT32)(((*(UINT64_STRUCT *)(void *)(&l))).Hi))
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #define ACPI_GET_ADDRESS(a)             (a)
1680Sstevel@tonic-gate #define ACPI_STORE_ADDRESS(a,b)         ((a)=(ACPI_PHYSICAL_ADDRESS)(b))
1690Sstevel@tonic-gate #define ACPI_VALID_ADDRESS(a)           (a)
1700Sstevel@tonic-gate #endif
1710Sstevel@tonic-gate #endif
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate /*
1740Sstevel@tonic-gate  * printf() format helpers
1750Sstevel@tonic-gate  */
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate /* Split 64-bit integer into two 32-bit values. Use with %8.8X%8.8X */
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate #define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i),ACPI_LODWORD(i)
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate /*
182*1560Smyers  * Extract data using a pointer.  Any more than a byte and we
183*1560Smyers  * get into potential aligment issues -- see the STORE macros below.
184*1560Smyers  * Use with care.
1850Sstevel@tonic-gate  */
186*1560Smyers #define ACPI_GET8(ptr)                  *ACPI_CAST_PTR (UINT8, ptr)
187*1560Smyers #define ACPI_GET16(ptr)                 *ACPI_CAST_PTR (UINT16, ptr)
188*1560Smyers #define ACPI_GET32(ptr)                 *ACPI_CAST_PTR (UINT32, ptr)
189*1560Smyers #define ACPI_GET64(ptr)                 *ACPI_CAST_PTR (UINT64, ptr)
190*1560Smyers #define ACPI_SET8(ptr)                  *ACPI_CAST_PTR (UINT8, ptr)
191*1560Smyers #define ACPI_SET16(ptr)                 *ACPI_CAST_PTR (UINT16, ptr)
192*1560Smyers #define ACPI_SET32(ptr)                 *ACPI_CAST_PTR (UINT32, ptr)
193*1560Smyers #define ACPI_SET64(ptr)                 *ACPI_CAST_PTR (UINT64, ptr)
1940Sstevel@tonic-gate 
195*1560Smyers /*
196*1560Smyers  * Pointer manipulation
197*1560Smyers  */
198*1560Smyers #define ACPI_CAST_PTR(t, p)             ((t *) (ACPI_UINTPTR_T) (p))
199*1560Smyers #define ACPI_CAST_INDIRECT_PTR(t, p)    ((t **) (ACPI_UINTPTR_T) (p))
200*1560Smyers #define ACPI_ADD_PTR(t,a,b)             ACPI_CAST_PTR (t, (ACPI_CAST_PTR (UINT8,(a)) + (ACPI_NATIVE_UINT)(b)))
201*1560Smyers #define ACPI_PTR_DIFF(a,b)              (ACPI_NATIVE_UINT) (ACPI_CAST_PTR (UINT8,(a)) - ACPI_CAST_PTR (UINT8,(b)))
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate /* Pointer/Integer type conversions */
2040Sstevel@tonic-gate 
205*1560Smyers #define ACPI_TO_POINTER(i)              ACPI_ADD_PTR (void,(void *) NULL,(ACPI_NATIVE_UINT) i)
2060Sstevel@tonic-gate #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p,(void *) NULL)
2070Sstevel@tonic-gate #define ACPI_OFFSET(d,f)                (ACPI_SIZE) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
2080Sstevel@tonic-gate #define ACPI_FADT_OFFSET(f)             ACPI_OFFSET (FADT_DESCRIPTOR, f)
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16
2110Sstevel@tonic-gate #define ACPI_STORE_POINTER(d,s)         ACPI_MOVE_32_TO_32(d,s)
2120Sstevel@tonic-gate #define ACPI_PHYSADDR_TO_PTR(i)         (void *)(i)
213*1560Smyers #define ACPI_PTR_TO_PHYSADDR(i)         (UINT32) ACPI_CAST_PTR (UINT8,(i))
2140Sstevel@tonic-gate #else
2150Sstevel@tonic-gate #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
2160Sstevel@tonic-gate #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
2170Sstevel@tonic-gate #endif
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate  * Macros for moving data around to/from buffers that are possibly unaligned.
2210Sstevel@tonic-gate  * If the hardware supports the transfer of unaligned data, just do the store.
2220Sstevel@tonic-gate  * Otherwise, we have to move one byte at a time.
2230Sstevel@tonic-gate  */
2240Sstevel@tonic-gate #ifdef ACPI_BIG_ENDIAN
2250Sstevel@tonic-gate /*
2260Sstevel@tonic-gate  * Macros for big-endian machines
2270Sstevel@tonic-gate  */
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate /* This macro sets a buffer index, starting from the end of the buffer */
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate #define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran)  ((BufLen) - (((BufOffset)+1) * (ByteGran)))
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate /* These macros reverse the bytes during the move, converting little-endian to big endian */
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate                                                      /* Big Endian      <==        Little Endian */
2360Sstevel@tonic-gate                                                      /*  Hi...Lo                     Lo...Hi     */
2370Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
2400Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s)         {(*(UINT32 *)(void *)(d))=0;\
2430Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
2440Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s)         {(*(UINT64 *)(void *)(d))=0;\
2470Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
2480Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
2550Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
2560Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
2570Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s)         {(*(UINT64 *)(void *)(d))=0;\
2600Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
2610Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
2620Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
2630Sstevel@tonic-gate                                            ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
2720Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
2730Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
2740Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
2750Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
2760Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
2770Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
2780Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
2790Sstevel@tonic-gate #else
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate  * Macros for little-endian machines
2820Sstevel@tonic-gate  */
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate /* This macro sets a buffer index, starting from the beginning of the buffer */
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate #define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran)  (BufOffset)
2870Sstevel@tonic-gate 
288*1560Smyers #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate /* The hardware supports unaligned transfers, just do the little-endian move */
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate /* No 64-bit integers */
2950Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s)         *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
2980Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
2990Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s)         ACPI_MOVE_16_TO_32(d,s)
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
3040Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
3050Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
3100Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
3110Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate #else
3140Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s)         *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
3170Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
3180Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s)
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
3230Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
3240Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s)
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
3290Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
3300Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s)
3310Sstevel@tonic-gate #endif
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate #else
3340Sstevel@tonic-gate /*
3350Sstevel@tonic-gate  * The hardware does not support unaligned transfers.  We must move the
3360Sstevel@tonic-gate  * data one byte at a time.  These macros work whether the source or
3370Sstevel@tonic-gate  * the destination (or both) is/are unaligned.  (Little-endian move)
3380Sstevel@tonic-gate  */
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
3430Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];}
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s)         {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);}
3460Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s)         {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);}
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
3530Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
3540Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
3550Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];}
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s)         {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d,s);}
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
3620Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
3630Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
3640Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
3650Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
3660Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\
3670Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\
3680Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\
3690Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
3700Sstevel@tonic-gate                                          ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
3710Sstevel@tonic-gate #endif
3720Sstevel@tonic-gate #endif
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate /* Macros based on machine integer width */
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16
3770Sstevel@tonic-gate #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_16_TO_16(d,s)
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate #elif ACPI_MACHINE_WIDTH == 32
3800Sstevel@tonic-gate #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_32_TO_16(d,s)
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate #elif ACPI_MACHINE_WIDTH == 64
3830Sstevel@tonic-gate #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_64_TO_16(d,s)
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate #else
3860Sstevel@tonic-gate #error unknown ACPI_MACHINE_WIDTH
3870Sstevel@tonic-gate #endif
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate /*
3910Sstevel@tonic-gate  * Fast power-of-two math macros for non-optimized compilers
3920Sstevel@tonic-gate  */
3930Sstevel@tonic-gate #define _ACPI_DIV(value,PowerOf2)       ((UINT32) ((value) >> (PowerOf2)))
3940Sstevel@tonic-gate #define _ACPI_MUL(value,PowerOf2)       ((UINT32) ((value) << (PowerOf2)))
3950Sstevel@tonic-gate #define _ACPI_MOD(value,Divisor)        ((UINT32) ((value) & ((Divisor) -1)))
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate #define ACPI_DIV_2(a)                   _ACPI_DIV(a,1)
3980Sstevel@tonic-gate #define ACPI_MUL_2(a)                   _ACPI_MUL(a,1)
3990Sstevel@tonic-gate #define ACPI_MOD_2(a)                   _ACPI_MOD(a,2)
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate #define ACPI_DIV_4(a)                   _ACPI_DIV(a,2)
4020Sstevel@tonic-gate #define ACPI_MUL_4(a)                   _ACPI_MUL(a,2)
4030Sstevel@tonic-gate #define ACPI_MOD_4(a)                   _ACPI_MOD(a,4)
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate #define ACPI_DIV_8(a)                   _ACPI_DIV(a,3)
4060Sstevel@tonic-gate #define ACPI_MUL_8(a)                   _ACPI_MUL(a,3)
4070Sstevel@tonic-gate #define ACPI_MOD_8(a)                   _ACPI_MOD(a,8)
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate #define ACPI_DIV_16(a)                  _ACPI_DIV(a,4)
4100Sstevel@tonic-gate #define ACPI_MUL_16(a)                  _ACPI_MUL(a,4)
4110Sstevel@tonic-gate #define ACPI_MOD_16(a)                  _ACPI_MOD(a,16)
4120Sstevel@tonic-gate 
413*1560Smyers #define ACPI_DIV_32(a)                  _ACPI_DIV(a,5)
414*1560Smyers #define ACPI_MUL_32(a)                  _ACPI_MUL(a,5)
415*1560Smyers #define ACPI_MOD_32(a)                  _ACPI_MOD(a,32)
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate /*
4180Sstevel@tonic-gate  * Rounding macros (Power of two boundaries only)
4190Sstevel@tonic-gate  */
420*1560Smyers #define ACPI_ROUND_DOWN(value,boundary)     (((ACPI_NATIVE_UINT)(value)) & \
421*1560Smyers                                                 (~(((ACPI_NATIVE_UINT) boundary)-1)))
4220Sstevel@tonic-gate 
423*1560Smyers #define ACPI_ROUND_UP(value,boundary)       ((((ACPI_NATIVE_UINT)(value)) + \
424*1560Smyers                                                 (((ACPI_NATIVE_UINT) boundary)-1)) & \
425*1560Smyers                                                 (~(((ACPI_NATIVE_UINT) boundary)-1)))
426*1560Smyers 
427*1560Smyers /* Note: sizeof(ACPI_NATIVE_UINT) evaluates to either 2, 4, or 8 */
4280Sstevel@tonic-gate 
429*1560Smyers #define ACPI_ROUND_DOWN_TO_32BIT(a)         ACPI_ROUND_DOWN(a,4)
430*1560Smyers #define ACPI_ROUND_DOWN_TO_64BIT(a)         ACPI_ROUND_DOWN(a,8)
431*1560Smyers #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)   ACPI_ROUND_DOWN(a,sizeof(ACPI_NATIVE_UINT))
4320Sstevel@tonic-gate 
433*1560Smyers #define ACPI_ROUND_UP_TO_32BIT(a)           ACPI_ROUND_UP(a,4)
434*1560Smyers #define ACPI_ROUND_UP_TO_64BIT(a)           ACPI_ROUND_UP(a,8)
435*1560Smyers #define ACPI_ROUND_UP_TO_NATIVE_WORD(a)     ACPI_ROUND_UP(a,sizeof(ACPI_NATIVE_UINT))
4360Sstevel@tonic-gate 
437*1560Smyers #define ACPI_ROUND_BITS_UP_TO_BYTES(a)      ACPI_DIV_8((a) + 7)
438*1560Smyers #define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)    ACPI_DIV_8((a))
439*1560Smyers 
440*1560Smyers #define ACPI_ROUND_UP_TO_1K(a)              (((a) + 1023) >> 10)
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate /* Generic (non-power-of-two) rounding */
4430Sstevel@tonic-gate 
444*1560Smyers #define ACPI_ROUND_UP_TO(value,boundary)    (((value) + ((boundary)-1)) / (boundary))
445*1560Smyers 
446*1560Smyers #define ACPI_IS_MISALIGNED(value)           (((ACPI_NATIVE_UINT)value) & (sizeof(ACPI_NATIVE_UINT)-1))
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate /*
4490Sstevel@tonic-gate  * Bitmask creation
4500Sstevel@tonic-gate  * Bit positions start at zero.
4510Sstevel@tonic-gate  * MASK_BITS_ABOVE creates a mask starting AT the position and above
4520Sstevel@tonic-gate  * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
4530Sstevel@tonic-gate  */
454*1560Smyers #define ACPI_MASK_BITS_ABOVE(position)      (~((ACPI_INTEGER_MAX) << ((UINT32) (position))))
455*1560Smyers #define ACPI_MASK_BITS_BELOW(position)      ((ACPI_INTEGER_MAX) << ((UINT32) (position)))
4560Sstevel@tonic-gate 
457*1560Smyers #define ACPI_IS_OCTAL_DIGIT(d)              (((char)(d) >= '0') && ((char)(d) <= '7'))
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate /* Bitfields within ACPI registers */
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate #define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)      ((Val << Pos) & Mask)
4630Sstevel@tonic-gate #define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val)  Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
4640Sstevel@tonic-gate 
465*1560Smyers /* Generate a UUID */
466*1560Smyers 
467*1560Smyers #define ACPI_INIT_UUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
468*1560Smyers     (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \
469*1560Smyers     (b) & 0xFF, ((b) >> 8) & 0xFF, \
470*1560Smyers     (c) & 0xFF, ((c) >> 8) & 0xFF, \
471*1560Smyers     (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)
472*1560Smyers 
4730Sstevel@tonic-gate /*
4740Sstevel@tonic-gate  * An ACPI_NAMESPACE_NODE * can appear in some contexts,
4750Sstevel@tonic-gate  * where a pointer to an ACPI_OPERAND_OBJECT  can also
4760Sstevel@tonic-gate  * appear.  This macro is used to distinguish them.
4770Sstevel@tonic-gate  *
4780Sstevel@tonic-gate  * The "Descriptor" field is the first field in both structures.
4790Sstevel@tonic-gate  */
4800Sstevel@tonic-gate #define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId)
4810Sstevel@tonic-gate #define ACPI_SET_DESCRIPTOR_TYPE(d,t)   (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId = t)
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate /* Macro to test the object type */
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate #define ACPI_GET_OBJECT_TYPE(d)         (((ACPI_OPERAND_OBJECT *)(void *)(d))->Common.Type)
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate /* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate #define ACPI_IS_SINGLE_TABLE(x)         (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate /*
4930Sstevel@tonic-gate  * Macros for the master AML opcode table
4940Sstevel@tonic-gate  */
4950Sstevel@tonic-gate #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
4960Sstevel@tonic-gate #define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags)     {Name,(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type}
4970Sstevel@tonic-gate #else
4980Sstevel@tonic-gate #define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags)     {(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type}
4990Sstevel@tonic-gate #endif
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate #ifdef ACPI_DISASSEMBLER
5020Sstevel@tonic-gate #define ACPI_DISASM_ONLY_MEMBERS(a)     a;
5030Sstevel@tonic-gate #else
5040Sstevel@tonic-gate #define ACPI_DISASM_ONLY_MEMBERS(a)
5050Sstevel@tonic-gate #endif
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate #define ARG_TYPE_WIDTH                  5
5080Sstevel@tonic-gate #define ARG_1(x)                        ((UINT32)(x))
5090Sstevel@tonic-gate #define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
5100Sstevel@tonic-gate #define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
5110Sstevel@tonic-gate #define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
5120Sstevel@tonic-gate #define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
5130Sstevel@tonic-gate #define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate #define ARGI_LIST1(a)                   (ARG_1(a))
5160Sstevel@tonic-gate #define ARGI_LIST2(a,b)                 (ARG_1(b)|ARG_2(a))
5170Sstevel@tonic-gate #define ARGI_LIST3(a,b,c)               (ARG_1(c)|ARG_2(b)|ARG_3(a))
5180Sstevel@tonic-gate #define ARGI_LIST4(a,b,c,d)             (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
5190Sstevel@tonic-gate #define ARGI_LIST5(a,b,c,d,e)           (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
5200Sstevel@tonic-gate #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))
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate #define ARGP_LIST1(a)                   (ARG_1(a))
5230Sstevel@tonic-gate #define ARGP_LIST2(a,b)                 (ARG_1(a)|ARG_2(b))
5240Sstevel@tonic-gate #define ARGP_LIST3(a,b,c)               (ARG_1(a)|ARG_2(b)|ARG_3(c))
5250Sstevel@tonic-gate #define ARGP_LIST4(a,b,c,d)             (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
5260Sstevel@tonic-gate #define ARGP_LIST5(a,b,c,d,e)           (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
5270Sstevel@tonic-gate #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))
5280Sstevel@tonic-gate 
5290Sstevel@tonic-gate #define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
5300Sstevel@tonic-gate #define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate 
533*1560Smyers #if defined (ACPI_DEBUG_OUTPUT) || !defined (ACPI_NO_ERROR_MESSAGES)
5340Sstevel@tonic-gate /*
535*1560Smyers  * Module name is include in both debug and non-debug versions primarily for
536*1560Smyers  * error messages. The __FILE__ macro is not very useful for this, because it
537*1560Smyers  * often includes the entire pathname to the module
5380Sstevel@tonic-gate  */
539*1560Smyers #define ACPI_MODULE_NAME(Name)          static char ACPI_UNUSED_VAR *_AcpiModuleName = Name;
540*1560Smyers #else
541*1560Smyers #define ACPI_MODULE_NAME(Name)
542*1560Smyers #endif
543*1560Smyers 
544*1560Smyers /*
545*1560Smyers  * Ascii error messages can be configured out
546*1560Smyers  */
547*1560Smyers #ifndef ACPI_NO_ERROR_MESSAGES
548*1560Smyers #define AE_INFO                         _AcpiModuleName, __LINE__
5490Sstevel@tonic-gate 
5500Sstevel@tonic-gate /*
551*1560Smyers  * Error reporting. Callers module and line number are inserted by AE_INFO,
552*1560Smyers  * the plist contains a set of parens to allow variable-length lists.
553*1560Smyers  * These macros are used for both the debug and non-debug versions of the code.
5540Sstevel@tonic-gate  */
555*1560Smyers #define ACPI_INFO(plist)                AcpiUtInfo plist
556*1560Smyers #define ACPI_WARNING(plist)             AcpiUtWarning plist
557*1560Smyers #define ACPI_EXCEPTION(plist)           AcpiUtException plist
558*1560Smyers #define ACPI_ERROR(plist)               AcpiUtError plist
559*1560Smyers #define ACPI_ERROR_NAMESPACE(s,e)       AcpiNsReportError (AE_INFO, s, e);
560*1560Smyers #define ACPI_ERROR_METHOD(s,n,p,e)      AcpiNsReportMethodError (AE_INFO, s, n, p, e);
5610Sstevel@tonic-gate 
562*1560Smyers /* Legacy interfaces. Remove when migration is complete */
5630Sstevel@tonic-gate 
564*1560Smyers #define ACPI_REPORT_INFO(fp)            {AcpiUtReportInfo (AE_INFO); \
565*1560Smyers                                             AcpiOsPrintf fp;}
566*1560Smyers #define ACPI_REPORT_ERROR(fp)           {AcpiUtReportError (AE_INFO); \
567*1560Smyers                                             AcpiOsPrintf fp;}
568*1560Smyers #define ACPI_REPORT_WARNING(fp)         {AcpiUtReportWarning (AE_INFO); \
569*1560Smyers                                             AcpiOsPrintf fp;}
5700Sstevel@tonic-gate #else
5710Sstevel@tonic-gate 
572*1560Smyers /* No error messages */
5730Sstevel@tonic-gate 
574*1560Smyers #define ACPI_INFO(plist)
575*1560Smyers #define ACPI_WARNING(plist)
576*1560Smyers #define ACPI_EXCEPTION(plist)
577*1560Smyers #define ACPI_ERROR(plist)
578*1560Smyers #define ACPI_ERROR_NAMESPACE(s,e)
579*1560Smyers #define ACPI_ERROR_METHOD(s,n,p,e)
5800Sstevel@tonic-gate 
581*1560Smyers #define ACPI_REPORT_INFO(fp)
582*1560Smyers #define ACPI_REPORT_ERROR(fp)
583*1560Smyers #define ACPI_REPORT_WARNING(fp)
584*1560Smyers #endif
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate /*
5870Sstevel@tonic-gate  * Debug macros that are conditionally compiled
5880Sstevel@tonic-gate  */
5890Sstevel@tonic-gate #ifdef ACPI_DEBUG_OUTPUT
5900Sstevel@tonic-gate 
591347Smyers /*
592347Smyers  * Common parameters used for debug output functions:
593347Smyers  * line number, function name, module(file) name, component ID
594347Smyers  */
595347Smyers #define ACPI_DEBUG_PARAMETERS           __LINE__, ACPI_GET_FUNCTION_NAME, _AcpiModuleName, _COMPONENT
596347Smyers 
597347Smyers /*
598347Smyers  * Function entry tracing
599347Smyers  */
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate /*
602347Smyers  * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header,
603347Smyers  * define it now. This is the case where there the compiler does not support
604941Smyers  * a __FUNCTION__ macro or equivalent. We save the function name on the
605347Smyers  * local stack.
6060Sstevel@tonic-gate  */
607347Smyers #ifndef ACPI_GET_FUNCTION_NAME
608347Smyers #define ACPI_GET_FUNCTION_NAME          _AcpiFunctionName
609347Smyers /*
610347Smyers  * The Name parameter should be the procedure name as a quoted string.
611347Smyers  * This is declared as a local string ("MyFunctionName") so that it can
612347Smyers  * be also used by the function exit macros below.
613941Smyers  * Note: (const char) is used to be compatible with the debug interfaces
614941Smyers  * and macros such as __FUNCTION__.
615347Smyers  */
616941Smyers #define ACPI_FUNCTION_NAME(Name)        const char *_AcpiFunctionName = Name;
6170Sstevel@tonic-gate 
618347Smyers #else
619347Smyers /* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */
620347Smyers 
621347Smyers #define ACPI_FUNCTION_NAME(Name)
622347Smyers #endif
6230Sstevel@tonic-gate 
624347Smyers #define ACPI_FUNCTION_TRACE(a)          ACPI_FUNCTION_NAME(a) \
625347Smyers                                             AcpiUtTrace(ACPI_DEBUG_PARAMETERS)
626347Smyers #define ACPI_FUNCTION_TRACE_PTR(a,b)    ACPI_FUNCTION_NAME(a) \
627347Smyers                                             AcpiUtTracePtr(ACPI_DEBUG_PARAMETERS,(void *)b)
628347Smyers #define ACPI_FUNCTION_TRACE_U32(a,b)    ACPI_FUNCTION_NAME(a) \
629347Smyers                                             AcpiUtTraceU32(ACPI_DEBUG_PARAMETERS,(UINT32)b)
630347Smyers #define ACPI_FUNCTION_TRACE_STR(a,b)    ACPI_FUNCTION_NAME(a) \
631347Smyers                                             AcpiUtTraceStr(ACPI_DEBUG_PARAMETERS,(char *)b)
632347Smyers 
633347Smyers #define ACPI_FUNCTION_ENTRY()           AcpiUtTrackStackPtr()
6340Sstevel@tonic-gate 
6350Sstevel@tonic-gate /*
6360Sstevel@tonic-gate  * Function exit tracing.
6370Sstevel@tonic-gate  * WARNING: These macros include a return statement.  This is usually considered
6380Sstevel@tonic-gate  * bad form, but having a separate exit macro is very ugly and difficult to maintain.
6390Sstevel@tonic-gate  * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
640347Smyers  * so that "_AcpiFunctionName" is defined.
641941Smyers  *
642941Smyers  * Note: the DO_WHILE0 macro is used to prevent some compilers from complaining
643941Smyers  * about these constructs.
6440Sstevel@tonic-gate  */
6450Sstevel@tonic-gate #ifdef ACPI_USE_DO_WHILE_0
6460Sstevel@tonic-gate #define ACPI_DO_WHILE0(a)               do a while(0)
6470Sstevel@tonic-gate #else
6480Sstevel@tonic-gate #define ACPI_DO_WHILE0(a)               a
6490Sstevel@tonic-gate #endif
6500Sstevel@tonic-gate 
651941Smyers #define return_VOID                     ACPI_DO_WHILE0 ({ \
652941Smyers                                             AcpiUtExit (ACPI_DEBUG_PARAMETERS); \
653941Smyers                                             return;})
654941Smyers /*
655941Smyers  * There are two versions of most of the return macros. The default version is
656941Smyers  * safer, since it avoids side-effects by guaranteeing that the argument will
657941Smyers  * not be evaluated twice.
658*1560Smyers  *
659941Smyers  * A less-safe version of the macros is provided for optional use if the
660941Smyers  * compiler uses excessive CPU stack (for example, this may happen in the
661941Smyers  * debug case if code optimzation is disabled.)
662941Smyers  */
663941Smyers #ifndef ACPI_SIMPLE_RETURN_MACROS
664941Smyers 
665941Smyers #define return_ACPI_STATUS(s)           ACPI_DO_WHILE0 ({ \
666941Smyers                                             register ACPI_STATUS _s = (s); \
667941Smyers                                             AcpiUtStatusExit (ACPI_DEBUG_PARAMETERS, _s); \
668941Smyers                                             return (_s); })
669941Smyers #define return_PTR(s)                   ACPI_DO_WHILE0 ({ \
670941Smyers                                             register void *_s = (void *) (s); \
671941Smyers                                             AcpiUtPtrExit (ACPI_DEBUG_PARAMETERS, (UINT8 *) _s); \
672941Smyers                                             return (_s); })
673941Smyers #define return_VALUE(s)                 ACPI_DO_WHILE0 ({ \
674941Smyers                                             register ACPI_INTEGER _s = (s); \
675941Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, _s); \
676941Smyers                                             return (_s); })
677941Smyers #define return_UINT8(s)                 ACPI_DO_WHILE0 ({ \
678941Smyers                                             register UINT8 _s = (UINT8) (s); \
679*1560Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (ACPI_INTEGER) _s); \
680941Smyers                                             return (_s); })
681941Smyers #define return_UINT32(s)                ACPI_DO_WHILE0 ({ \
682941Smyers                                             register UINT32 _s = (UINT32) (s); \
683*1560Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (ACPI_INTEGER) _s); \
684941Smyers                                             return (_s); })
685941Smyers #else /* Use original less-safe macros */
686941Smyers 
687941Smyers #define return_ACPI_STATUS(s)           ACPI_DO_WHILE0 ({ \
688941Smyers                                             AcpiUtStatusExit (ACPI_DEBUG_PARAMETERS, (s)); \
689941Smyers                                             return((s)); })
690941Smyers #define return_PTR(s)                   ACPI_DO_WHILE0 ({ \
691941Smyers                                             AcpiUtPtrExit (ACPI_DEBUG_PARAMETERS, (UINT8 *) (s)); \
692941Smyers                                             return((s)); })
693941Smyers #define return_VALUE(s)                 ACPI_DO_WHILE0 ({ \
694941Smyers                                             AcpiUtValueExit (ACPI_DEBUG_PARAMETERS, (ACPI_INTEGER) (s)); \
695941Smyers                                             return((s)); })
696941Smyers #define return_UINT8(s)                 return_VALUE(s)
697941Smyers #define return_UINT32(s)                return_VALUE(s)
698941Smyers 
699941Smyers #endif /* ACPI_SIMPLE_RETURN_MACROS */
700941Smyers 
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate /* Conditional execution */
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate #define ACPI_DEBUG_EXEC(a)              a
7050Sstevel@tonic-gate #define ACPI_NORMAL_EXEC(a)
7060Sstevel@tonic-gate 
7070Sstevel@tonic-gate #define ACPI_DEBUG_DEFINE(a)            a;
7080Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a)      a;
7090Sstevel@tonic-gate #define _VERBOSE_STRUCTURES
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate /* Stack and buffer dumping */
7130Sstevel@tonic-gate 
7140Sstevel@tonic-gate #define ACPI_DUMP_STACK_ENTRY(a)        AcpiExDumpOperand((a),0)
715347Smyers #define ACPI_DUMP_OPERANDS(a,b,c,d,e)   AcpiExDumpOperands(a,b,c,d,e,_AcpiModuleName,__LINE__)
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate #define ACPI_DUMP_ENTRY(a,b)            AcpiNsDumpEntry (a,b)
7190Sstevel@tonic-gate #define ACPI_DUMP_PATHNAME(a,b,c,d)     AcpiNsDumpPathname(a,b,c,d)
7200Sstevel@tonic-gate #define ACPI_DUMP_RESOURCE_LIST(a)      AcpiRsDumpResourceList(a)
7210Sstevel@tonic-gate #define ACPI_DUMP_BUFFER(a,b)           AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate /*
7240Sstevel@tonic-gate  * Master debug print macros
7250Sstevel@tonic-gate  * Print iff:
7260Sstevel@tonic-gate  *    1) Debug print for the current component is enabled
7270Sstevel@tonic-gate  *    2) Debug error level or trace level for the print statement is enabled
7280Sstevel@tonic-gate  */
729*1560Smyers #define ACPI_DEBUG_PRINT(plist)         AcpiUtDebugPrint plist
730*1560Smyers #define ACPI_DEBUG_PRINT_RAW(plist)     AcpiUtDebugPrintRaw plist
7310Sstevel@tonic-gate 
7320Sstevel@tonic-gate 
7330Sstevel@tonic-gate #else
7340Sstevel@tonic-gate /*
7350Sstevel@tonic-gate  * This is the non-debug case -- make everything go away,
7360Sstevel@tonic-gate  * leaving no executable debug code!
7370Sstevel@tonic-gate  */
7380Sstevel@tonic-gate #define ACPI_DEBUG_EXEC(a)
7390Sstevel@tonic-gate #define ACPI_NORMAL_EXEC(a)             a;
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate #define ACPI_DEBUG_DEFINE(a)
7420Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a)
7430Sstevel@tonic-gate #define ACPI_FUNCTION_NAME(a)
7440Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE(a)
7450Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE_PTR(a,b)
7460Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE_U32(a,b)
7470Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE_STR(a,b)
7480Sstevel@tonic-gate #define ACPI_FUNCTION_EXIT
7490Sstevel@tonic-gate #define ACPI_FUNCTION_STATUS_EXIT(s)
7500Sstevel@tonic-gate #define ACPI_FUNCTION_VALUE_EXIT(s)
7510Sstevel@tonic-gate #define ACPI_FUNCTION_ENTRY()
7520Sstevel@tonic-gate #define ACPI_DUMP_STACK_ENTRY(a)
7530Sstevel@tonic-gate #define ACPI_DUMP_OPERANDS(a,b,c,d,e)
7540Sstevel@tonic-gate #define ACPI_DUMP_ENTRY(a,b)
7550Sstevel@tonic-gate #define ACPI_DUMP_TABLES(a,b)
7560Sstevel@tonic-gate #define ACPI_DUMP_PATHNAME(a,b,c,d)
7570Sstevel@tonic-gate #define ACPI_DUMP_RESOURCE_LIST(a)
7580Sstevel@tonic-gate #define ACPI_DUMP_BUFFER(a,b)
7590Sstevel@tonic-gate #define ACPI_DEBUG_PRINT(pl)
7600Sstevel@tonic-gate #define ACPI_DEBUG_PRINT_RAW(pl)
7610Sstevel@tonic-gate 
7620Sstevel@tonic-gate #define return_VOID                     return
7630Sstevel@tonic-gate #define return_ACPI_STATUS(s)           return(s)
7640Sstevel@tonic-gate #define return_VALUE(s)                 return(s)
765941Smyers #define return_UINT8(s)                 return(s)
766941Smyers #define return_UINT32(s)                return(s)
7670Sstevel@tonic-gate #define return_PTR(s)                   return(s)
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate #endif
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate /*
7720Sstevel@tonic-gate  * Some code only gets executed when the debugger is built in.
7730Sstevel@tonic-gate  * Note that this is entirely independent of whether the
7740Sstevel@tonic-gate  * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not.
7750Sstevel@tonic-gate  */
7760Sstevel@tonic-gate #ifdef ACPI_DEBUGGER
7770Sstevel@tonic-gate #define ACPI_DEBUGGER_EXEC(a)           a
7780Sstevel@tonic-gate #else
7790Sstevel@tonic-gate #define ACPI_DEBUGGER_EXEC(a)
7800Sstevel@tonic-gate #endif
7810Sstevel@tonic-gate 
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate /*
7840Sstevel@tonic-gate  * For 16-bit code, we want to shrink some things even though
7850Sstevel@tonic-gate  * we are using ACPI_DEBUG_OUTPUT to get the debug output
7860Sstevel@tonic-gate  */
7870Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16
7880Sstevel@tonic-gate #undef ACPI_DEBUG_ONLY_MEMBERS
7890Sstevel@tonic-gate #undef _VERBOSE_STRUCTURES
7900Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a)
7910Sstevel@tonic-gate #endif
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate #ifdef ACPI_DEBUG_OUTPUT
7950Sstevel@tonic-gate /*
7960Sstevel@tonic-gate  * 1) Set name to blanks
7970Sstevel@tonic-gate  * 2) Copy the object name
7980Sstevel@tonic-gate  */
7990Sstevel@tonic-gate #define ACPI_ADD_OBJECT_NAME(a,b)       ACPI_MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\
8000Sstevel@tonic-gate                                         ACPI_STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name))
8010Sstevel@tonic-gate #else
8020Sstevel@tonic-gate 
8030Sstevel@tonic-gate #define ACPI_ADD_OBJECT_NAME(a,b)
8040Sstevel@tonic-gate #endif
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate 
8070Sstevel@tonic-gate /*
8080Sstevel@tonic-gate  * Memory allocation tracking (DEBUG ONLY)
8090Sstevel@tonic-gate  */
8100Sstevel@tonic-gate #ifndef ACPI_DBG_TRACK_ALLOCATIONS
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate /* Memory allocation */
8130Sstevel@tonic-gate 
814347Smyers #define ACPI_MEM_ALLOCATE(a)            AcpiUtAllocate((ACPI_SIZE)(a),_COMPONENT,_AcpiModuleName,__LINE__)
815347Smyers #define ACPI_MEM_CALLOCATE(a)           AcpiUtCallocate((ACPI_SIZE)(a), _COMPONENT,_AcpiModuleName,__LINE__)
8160Sstevel@tonic-gate #define ACPI_MEM_FREE(a)                AcpiOsFree(a)
8170Sstevel@tonic-gate #define ACPI_MEM_TRACKING(a)
8180Sstevel@tonic-gate 
8190Sstevel@tonic-gate #else
8200Sstevel@tonic-gate 
8210Sstevel@tonic-gate /* Memory allocation */
8220Sstevel@tonic-gate 
823347Smyers #define ACPI_MEM_ALLOCATE(a)            AcpiUtAllocateAndTrack((ACPI_SIZE)(a),_COMPONENT,_AcpiModuleName,__LINE__)
824347Smyers #define ACPI_MEM_CALLOCATE(a)           AcpiUtCallocateAndTrack((ACPI_SIZE)(a), _COMPONENT,_AcpiModuleName,__LINE__)
825347Smyers #define ACPI_MEM_FREE(a)                AcpiUtFreeAndTrack(a,_COMPONENT,_AcpiModuleName,__LINE__)
8260Sstevel@tonic-gate #define ACPI_MEM_TRACKING(a)            a
8270Sstevel@tonic-gate 
8280Sstevel@tonic-gate #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate #endif /* ACMACROS_H */
831