10Sstevel@tonic-gate /****************************************************************************** 20Sstevel@tonic-gate * 30Sstevel@tonic-gate * Name: acmacros.h - C macros for the entire subsystem. 4*347Smyers * $Revision: 160 $ 50Sstevel@tonic-gate * 60Sstevel@tonic-gate *****************************************************************************/ 70Sstevel@tonic-gate 80Sstevel@tonic-gate /****************************************************************************** 90Sstevel@tonic-gate * 100Sstevel@tonic-gate * 1. Copyright Notice 110Sstevel@tonic-gate * 120Sstevel@tonic-gate * Some or all of this work - Copyright (c) 1999 - 2005, 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 1380Sstevel@tonic-gate * 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 /* 1820Sstevel@tonic-gate * Extract a byte of data using a pointer. Any more than a byte and we 1830Sstevel@tonic-gate * get into potential aligment issues -- see the STORE macros below 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate #define ACPI_GET8(addr) (*(UINT8*)(addr)) 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* Pointer arithmetic */ 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define ACPI_PTR_ADD(t,a,b) (t *) (void *)((char *)(a) + (ACPI_NATIVE_UINT)(b)) 1900Sstevel@tonic-gate #define ACPI_PTR_DIFF(a,b) (ACPI_NATIVE_UINT) ((char *)(a) - (char *)(b)) 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate /* Pointer/Integer type conversions */ 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #define ACPI_TO_POINTER(i) ACPI_PTR_ADD (void, (void *) NULL,(ACPI_NATIVE_UINT)i) 1950Sstevel@tonic-gate #define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p,(void *) NULL) 1960Sstevel@tonic-gate #define ACPI_OFFSET(d,f) (ACPI_SIZE) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL) 1970Sstevel@tonic-gate #define ACPI_FADT_OFFSET(f) ACPI_OFFSET (FADT_DESCRIPTOR, f) 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate #define ACPI_CAST_PTR(t, p) ((t *)(void *)(p)) 2000Sstevel@tonic-gate #define ACPI_CAST_INDIRECT_PTR(t, p) ((t **)(void *)(p)) 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16 2030Sstevel@tonic-gate #define ACPI_STORE_POINTER(d,s) ACPI_MOVE_32_TO_32(d,s) 2040Sstevel@tonic-gate #define ACPI_PHYSADDR_TO_PTR(i) (void *)(i) 2050Sstevel@tonic-gate #define ACPI_PTR_TO_PHYSADDR(i) (UINT32) (char *)(i) 2060Sstevel@tonic-gate #else 2070Sstevel@tonic-gate #define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) 2080Sstevel@tonic-gate #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i) 2090Sstevel@tonic-gate #endif 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate /* 2120Sstevel@tonic-gate * Macros for moving data around to/from buffers that are possibly unaligned. 2130Sstevel@tonic-gate * If the hardware supports the transfer of unaligned data, just do the store. 2140Sstevel@tonic-gate * Otherwise, we have to move one byte at a time. 2150Sstevel@tonic-gate */ 2160Sstevel@tonic-gate #ifdef ACPI_BIG_ENDIAN 2170Sstevel@tonic-gate /* 2180Sstevel@tonic-gate * Macros for big-endian machines 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate /* This macro sets a buffer index, starting from the end of the buffer */ 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate #define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran) ((BufLen) - (((BufOffset)+1) * (ByteGran))) 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* These macros reverse the bytes during the move, converting little-endian to big endian */ 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* Big Endian <== Little Endian */ 2280Sstevel@tonic-gate /* Hi...Lo Lo...Hi */ 2290Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */ 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\ 2320Sstevel@tonic-gate (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];} 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s) {(*(UINT32 *)(void *)(d))=0;\ 2350Sstevel@tonic-gate ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\ 2360Sstevel@tonic-gate ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];} 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s) {(*(UINT64 *)(void *)(d))=0;\ 2390Sstevel@tonic-gate ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\ 2400Sstevel@tonic-gate ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];} 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */ 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\ 2470Sstevel@tonic-gate (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\ 2480Sstevel@tonic-gate (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\ 2490Sstevel@tonic-gate (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];} 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s) {(*(UINT64 *)(void *)(d))=0;\ 2520Sstevel@tonic-gate ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\ 2530Sstevel@tonic-gate ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\ 2540Sstevel@tonic-gate ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\ 2550Sstevel@tonic-gate ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];} 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */ 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s) ACPI_MOVE_32_TO_32(d,s) /* Truncate to 32 */ 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\ 2640Sstevel@tonic-gate (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\ 2650Sstevel@tonic-gate (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\ 2660Sstevel@tonic-gate (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\ 2670Sstevel@tonic-gate (( UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\ 2680Sstevel@tonic-gate (( UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\ 2690Sstevel@tonic-gate (( UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\ 2700Sstevel@tonic-gate (( UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];} 2710Sstevel@tonic-gate #else 2720Sstevel@tonic-gate /* 2730Sstevel@tonic-gate * Macros for little-endian machines 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* This macro sets a buffer index, starting from the beginning of the buffer */ 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate #define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran) (BufOffset) 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate #ifdef ACPI_MISALIGNED_TRANSFERS 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* The hardware supports unaligned transfers, just do the little-endian move */ 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* No 64-bit integers */ 2870Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */ 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s) *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s) 2900Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s) *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s) 2910Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s) ACPI_MOVE_16_TO_32(d,s) 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */ 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 2960Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s) *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s) 2970Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s) ACPI_MOVE_32_TO_32(d,s) 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */ 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 3020Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s) ACPI_MOVE_32_TO_32(d,s) /* Truncate to 32 */ 3030Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s) ACPI_MOVE_32_TO_32(d,s) 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate #else 3060Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */ 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s) *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s) 3090Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s) *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s) 3100Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s) *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s) 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */ 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 3150Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s) *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s) 3160Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s) *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s) 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */ 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 3210Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s) ACPI_MOVE_32_TO_32(d,s) /* Truncate to 32 */ 3220Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s) *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s) 3230Sstevel@tonic-gate #endif 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate #else 3260Sstevel@tonic-gate /* 3270Sstevel@tonic-gate * The hardware does not support unaligned transfers. We must move the 3280Sstevel@tonic-gate * data one byte at a time. These macros work whether the source or 3290Sstevel@tonic-gate * the destination (or both) is/are unaligned. (Little-endian move) 3300Sstevel@tonic-gate */ 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate /* 16-bit source, 16/32/64 destination */ 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate #define ACPI_MOVE_16_TO_16(d,s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\ 3350Sstevel@tonic-gate (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];} 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate #define ACPI_MOVE_16_TO_32(d,s) {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);} 3380Sstevel@tonic-gate #define ACPI_MOVE_16_TO_64(d,s) {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);} 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate /* 32-bit source, 16/32/64 destination */ 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate #define ACPI_MOVE_32_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate #define ACPI_MOVE_32_TO_32(d,s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\ 3450Sstevel@tonic-gate (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\ 3460Sstevel@tonic-gate (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\ 3470Sstevel@tonic-gate (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];} 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate #define ACPI_MOVE_32_TO_64(d,s) {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d,s);} 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 64-bit source, 16/32/64 destination */ 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate #define ACPI_MOVE_64_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 3540Sstevel@tonic-gate #define ACPI_MOVE_64_TO_32(d,s) ACPI_MOVE_32_TO_32(d,s) /* Truncate to 32 */ 3550Sstevel@tonic-gate #define ACPI_MOVE_64_TO_64(d,s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\ 3560Sstevel@tonic-gate (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\ 3570Sstevel@tonic-gate (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\ 3580Sstevel@tonic-gate (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\ 3590Sstevel@tonic-gate (( UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\ 3600Sstevel@tonic-gate (( UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\ 3610Sstevel@tonic-gate (( UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\ 3620Sstevel@tonic-gate (( UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];} 3630Sstevel@tonic-gate #endif 3640Sstevel@tonic-gate #endif 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate /* Macros based on machine integer width */ 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16 3690Sstevel@tonic-gate #define ACPI_MOVE_SIZE_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate #elif ACPI_MACHINE_WIDTH == 32 3720Sstevel@tonic-gate #define ACPI_MOVE_SIZE_TO_16(d,s) ACPI_MOVE_32_TO_16(d,s) 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate #elif ACPI_MACHINE_WIDTH == 64 3750Sstevel@tonic-gate #define ACPI_MOVE_SIZE_TO_16(d,s) ACPI_MOVE_64_TO_16(d,s) 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate #else 3780Sstevel@tonic-gate #error unknown ACPI_MACHINE_WIDTH 3790Sstevel@tonic-gate #endif 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* 3830Sstevel@tonic-gate * Fast power-of-two math macros for non-optimized compilers 3840Sstevel@tonic-gate */ 3850Sstevel@tonic-gate #define _ACPI_DIV(value,PowerOf2) ((UINT32) ((value) >> (PowerOf2))) 3860Sstevel@tonic-gate #define _ACPI_MUL(value,PowerOf2) ((UINT32) ((value) << (PowerOf2))) 3870Sstevel@tonic-gate #define _ACPI_MOD(value,Divisor) ((UINT32) ((value) & ((Divisor) -1))) 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate #define ACPI_DIV_2(a) _ACPI_DIV(a,1) 3900Sstevel@tonic-gate #define ACPI_MUL_2(a) _ACPI_MUL(a,1) 3910Sstevel@tonic-gate #define ACPI_MOD_2(a) _ACPI_MOD(a,2) 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate #define ACPI_DIV_4(a) _ACPI_DIV(a,2) 3940Sstevel@tonic-gate #define ACPI_MUL_4(a) _ACPI_MUL(a,2) 3950Sstevel@tonic-gate #define ACPI_MOD_4(a) _ACPI_MOD(a,4) 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate #define ACPI_DIV_8(a) _ACPI_DIV(a,3) 3980Sstevel@tonic-gate #define ACPI_MUL_8(a) _ACPI_MUL(a,3) 3990Sstevel@tonic-gate #define ACPI_MOD_8(a) _ACPI_MOD(a,8) 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate #define ACPI_DIV_16(a) _ACPI_DIV(a,4) 4020Sstevel@tonic-gate #define ACPI_MUL_16(a) _ACPI_MUL(a,4) 4030Sstevel@tonic-gate #define ACPI_MOD_16(a) _ACPI_MOD(a,16) 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate /* 4070Sstevel@tonic-gate * Rounding macros (Power of two boundaries only) 4080Sstevel@tonic-gate */ 4090Sstevel@tonic-gate #define ACPI_ROUND_DOWN(value,boundary) (((ACPI_NATIVE_UINT)(value)) & (~(((ACPI_NATIVE_UINT) boundary)-1))) 4100Sstevel@tonic-gate #define ACPI_ROUND_UP(value,boundary) ((((ACPI_NATIVE_UINT)(value)) + (((ACPI_NATIVE_UINT) boundary)-1)) & (~(((ACPI_NATIVE_UINT) boundary)-1))) 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate #define ACPI_ROUND_DOWN_TO_32_BITS(a) ACPI_ROUND_DOWN(a,4) 4130Sstevel@tonic-gate #define ACPI_ROUND_DOWN_TO_64_BITS(a) ACPI_ROUND_DOWN(a,8) 4140Sstevel@tonic-gate #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY) 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate #define ACPI_ROUND_UP_TO_32BITS(a) ACPI_ROUND_UP(a,4) 4170Sstevel@tonic-gate #define ACPI_ROUND_UP_TO_64BITS(a) ACPI_ROUND_UP(a,8) 4180Sstevel@tonic-gate #define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY) 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate #define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7) 4220Sstevel@tonic-gate #define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a)) 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate #define ACPI_ROUND_UP_TO_1K(a) (((a) + 1023) >> 10) 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate /* Generic (non-power-of-two) rounding */ 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate #define ACPI_ROUND_UP_TO(value,boundary) (((value) + ((boundary)-1)) / (boundary)) 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * Bitmask creation 4320Sstevel@tonic-gate * Bit positions start at zero. 4330Sstevel@tonic-gate * MASK_BITS_ABOVE creates a mask starting AT the position and above 4340Sstevel@tonic-gate * MASK_BITS_BELOW creates a mask starting one bit BELOW the position 4350Sstevel@tonic-gate */ 4360Sstevel@tonic-gate #define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_INTEGER_MAX) << ((UINT32) (position)))) 4370Sstevel@tonic-gate #define ACPI_MASK_BITS_BELOW(position) ((ACPI_INTEGER_MAX) << ((UINT32) (position))) 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate #define ACPI_IS_OCTAL_DIGIT(d) (((char)(d) >= '0') && ((char)(d) <= '7')) 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate /* Bitfields within ACPI registers */ 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate #define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask) ((Val << Pos) & Mask) 4450Sstevel@tonic-gate #define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val) Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask) 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate /* 4480Sstevel@tonic-gate * An ACPI_NAMESPACE_NODE * can appear in some contexts, 4490Sstevel@tonic-gate * where a pointer to an ACPI_OPERAND_OBJECT can also 4500Sstevel@tonic-gate * appear. This macro is used to distinguish them. 4510Sstevel@tonic-gate * 4520Sstevel@tonic-gate * The "Descriptor" field is the first field in both structures. 4530Sstevel@tonic-gate */ 4540Sstevel@tonic-gate #define ACPI_GET_DESCRIPTOR_TYPE(d) (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId) 4550Sstevel@tonic-gate #define ACPI_SET_DESCRIPTOR_TYPE(d,t) (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId = t) 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate /* Macro to test the object type */ 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate #define ACPI_GET_OBJECT_TYPE(d) (((ACPI_OPERAND_OBJECT *)(void *)(d))->Common.Type) 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate /* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */ 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate #define ACPI_IS_SINGLE_TABLE(x) (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0) 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* 4670Sstevel@tonic-gate * Macros for the master AML opcode table 4680Sstevel@tonic-gate */ 4690Sstevel@tonic-gate #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT) 4700Sstevel@tonic-gate #define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags) {Name,(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type} 4710Sstevel@tonic-gate #else 4720Sstevel@tonic-gate #define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags) {(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type} 4730Sstevel@tonic-gate #endif 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate #ifdef ACPI_DISASSEMBLER 4760Sstevel@tonic-gate #define ACPI_DISASM_ONLY_MEMBERS(a) a; 4770Sstevel@tonic-gate #else 4780Sstevel@tonic-gate #define ACPI_DISASM_ONLY_MEMBERS(a) 4790Sstevel@tonic-gate #endif 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate #define ARG_TYPE_WIDTH 5 4820Sstevel@tonic-gate #define ARG_1(x) ((UINT32)(x)) 4830Sstevel@tonic-gate #define ARG_2(x) ((UINT32)(x) << (1 * ARG_TYPE_WIDTH)) 4840Sstevel@tonic-gate #define ARG_3(x) ((UINT32)(x) << (2 * ARG_TYPE_WIDTH)) 4850Sstevel@tonic-gate #define ARG_4(x) ((UINT32)(x) << (3 * ARG_TYPE_WIDTH)) 4860Sstevel@tonic-gate #define ARG_5(x) ((UINT32)(x) << (4 * ARG_TYPE_WIDTH)) 4870Sstevel@tonic-gate #define ARG_6(x) ((UINT32)(x) << (5 * ARG_TYPE_WIDTH)) 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate #define ARGI_LIST1(a) (ARG_1(a)) 4900Sstevel@tonic-gate #define ARGI_LIST2(a,b) (ARG_1(b)|ARG_2(a)) 4910Sstevel@tonic-gate #define ARGI_LIST3(a,b,c) (ARG_1(c)|ARG_2(b)|ARG_3(a)) 4920Sstevel@tonic-gate #define ARGI_LIST4(a,b,c,d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a)) 4930Sstevel@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)) 4940Sstevel@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)) 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate #define ARGP_LIST1(a) (ARG_1(a)) 4970Sstevel@tonic-gate #define ARGP_LIST2(a,b) (ARG_1(a)|ARG_2(b)) 4980Sstevel@tonic-gate #define ARGP_LIST3(a,b,c) (ARG_1(a)|ARG_2(b)|ARG_3(c)) 4990Sstevel@tonic-gate #define ARGP_LIST4(a,b,c,d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)) 5000Sstevel@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)) 5010Sstevel@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)) 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate #define GET_CURRENT_ARG_TYPE(List) (List & ((UINT32) 0x1F)) 5040Sstevel@tonic-gate #define INCREMENT_ARG_LIST(List) (List >>= ((UINT32) ARG_TYPE_WIDTH)) 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* 5080Sstevel@tonic-gate * Reporting macros that are never compiled out 5090Sstevel@tonic-gate */ 5100Sstevel@tonic-gate #define ACPI_PARAM_LIST(pl) pl 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate /* 513*347Smyers * Error reporting. These versions add callers module and line#. 514*347Smyers * 515*347Smyers * Since _AcpiModuleName gets compiled out when ACPI_DEBUG_OUTPUT 516*347Smyers * isn't defined, only use it in debug mode. 5170Sstevel@tonic-gate */ 5180Sstevel@tonic-gate #ifdef ACPI_DEBUG_OUTPUT 5190Sstevel@tonic-gate 520*347Smyers #define ACPI_REPORT_INFO(fp) {AcpiUtReportInfo(_AcpiModuleName,__LINE__,_COMPONENT); \ 5210Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 522*347Smyers #define ACPI_REPORT_ERROR(fp) {AcpiUtReportError(_AcpiModuleName,__LINE__,_COMPONENT); \ 5230Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 524*347Smyers #define ACPI_REPORT_WARNING(fp) {AcpiUtReportWarning(_AcpiModuleName,__LINE__,_COMPONENT); \ 5250Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 526*347Smyers #define ACPI_REPORT_NSERROR(s,e) AcpiNsReportError(_AcpiModuleName,__LINE__,_COMPONENT, s, e); 5270Sstevel@tonic-gate 528*347Smyers #define ACPI_REPORT_METHOD_ERROR(s,n,p,e) AcpiNsReportMethodError(_AcpiModuleName,__LINE__,_COMPONENT, s, n, p, e); 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate #else 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate #define ACPI_REPORT_INFO(fp) {AcpiUtReportInfo("ACPI",__LINE__,_COMPONENT); \ 5330Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 5340Sstevel@tonic-gate #define ACPI_REPORT_ERROR(fp) {AcpiUtReportError("ACPI",__LINE__,_COMPONENT); \ 5350Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 5360Sstevel@tonic-gate #define ACPI_REPORT_WARNING(fp) {AcpiUtReportWarning("ACPI",__LINE__,_COMPONENT); \ 5370Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 5380Sstevel@tonic-gate #define ACPI_REPORT_NSERROR(s,e) AcpiNsReportError("ACPI",__LINE__,_COMPONENT, s, e); 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate #define ACPI_REPORT_METHOD_ERROR(s,n,p,e) AcpiNsReportMethodError("ACPI",__LINE__,_COMPONENT, s, n, p, e); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate #endif 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate /* Error reporting. These versions pass thru the module and line# */ 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate #define _ACPI_REPORT_INFO(a,b,c,fp) {AcpiUtReportInfo(a,b,c); \ 5470Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 5480Sstevel@tonic-gate #define _ACPI_REPORT_ERROR(a,b,c,fp) {AcpiUtReportError(a,b,c); \ 5490Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 5500Sstevel@tonic-gate #define _ACPI_REPORT_WARNING(a,b,c,fp) {AcpiUtReportWarning(a,b,c); \ 5510Sstevel@tonic-gate AcpiOsPrintf ACPI_PARAM_LIST(fp);} 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate /* 5540Sstevel@tonic-gate * Debug macros that are conditionally compiled 5550Sstevel@tonic-gate */ 5560Sstevel@tonic-gate #ifdef ACPI_DEBUG_OUTPUT 557*347Smyers #define ACPI_MODULE_NAME(Name) static char ACPI_UNUSED_VAR *_AcpiModuleName = Name; 5580Sstevel@tonic-gate 559*347Smyers /* 560*347Smyers * Common parameters used for debug output functions: 561*347Smyers * line number, function name, module(file) name, component ID 562*347Smyers */ 563*347Smyers #define ACPI_DEBUG_PARAMETERS __LINE__, ACPI_GET_FUNCTION_NAME, _AcpiModuleName, _COMPONENT 564*347Smyers 565*347Smyers /* 566*347Smyers * Function entry tracing 567*347Smyers */ 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate /* 570*347Smyers * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header, 571*347Smyers * define it now. This is the case where there the compiler does not support 572*347Smyers * a __FUNCTION__ macro or equivalent. We save the function name on the 573*347Smyers * local stack. 5740Sstevel@tonic-gate */ 575*347Smyers #ifndef ACPI_GET_FUNCTION_NAME 576*347Smyers #define ACPI_GET_FUNCTION_NAME _AcpiFunctionName 577*347Smyers /* 578*347Smyers * The Name parameter should be the procedure name as a quoted string. 579*347Smyers * This is declared as a local string ("MyFunctionName") so that it can 580*347Smyers * be also used by the function exit macros below. 581*347Smyers */ 582*347Smyers #define ACPI_FUNCTION_NAME(Name) char *_AcpiFunctionName = Name; 5830Sstevel@tonic-gate 584*347Smyers #else 585*347Smyers /* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */ 586*347Smyers 587*347Smyers #define ACPI_FUNCTION_NAME(Name) 588*347Smyers #endif 5890Sstevel@tonic-gate 590*347Smyers #define ACPI_FUNCTION_TRACE(a) ACPI_FUNCTION_NAME(a) \ 591*347Smyers AcpiUtTrace(ACPI_DEBUG_PARAMETERS) 592*347Smyers #define ACPI_FUNCTION_TRACE_PTR(a,b) ACPI_FUNCTION_NAME(a) \ 593*347Smyers AcpiUtTracePtr(ACPI_DEBUG_PARAMETERS,(void *)b) 594*347Smyers #define ACPI_FUNCTION_TRACE_U32(a,b) ACPI_FUNCTION_NAME(a) \ 595*347Smyers AcpiUtTraceU32(ACPI_DEBUG_PARAMETERS,(UINT32)b) 596*347Smyers #define ACPI_FUNCTION_TRACE_STR(a,b) ACPI_FUNCTION_NAME(a) \ 597*347Smyers AcpiUtTraceStr(ACPI_DEBUG_PARAMETERS,(char *)b) 598*347Smyers 599*347Smyers #define ACPI_FUNCTION_ENTRY() AcpiUtTrackStackPtr() 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* 6020Sstevel@tonic-gate * Function exit tracing. 6030Sstevel@tonic-gate * WARNING: These macros include a return statement. This is usually considered 6040Sstevel@tonic-gate * bad form, but having a separate exit macro is very ugly and difficult to maintain. 6050Sstevel@tonic-gate * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros 606*347Smyers * so that "_AcpiFunctionName" is defined. 6070Sstevel@tonic-gate */ 6080Sstevel@tonic-gate #ifdef ACPI_USE_DO_WHILE_0 6090Sstevel@tonic-gate #define ACPI_DO_WHILE0(a) do a while(0) 6100Sstevel@tonic-gate #else 6110Sstevel@tonic-gate #define ACPI_DO_WHILE0(a) a 6120Sstevel@tonic-gate #endif 6130Sstevel@tonic-gate 614*347Smyers #define return_VOID ACPI_DO_WHILE0 ({AcpiUtExit(ACPI_DEBUG_PARAMETERS);return;}) 615*347Smyers #define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({AcpiUtStatusExit(ACPI_DEBUG_PARAMETERS,(s));return((s));}) 616*347Smyers #define return_VALUE(s) ACPI_DO_WHILE0 ({AcpiUtValueExit(ACPI_DEBUG_PARAMETERS,(ACPI_INTEGER)(s));return((s));}) 617*347Smyers #define return_PTR(s) ACPI_DO_WHILE0 ({AcpiUtPtrExit(ACPI_DEBUG_PARAMETERS,(UINT8 *)(s));return((s));}) 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate /* Conditional execution */ 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate #define ACPI_DEBUG_EXEC(a) a 6220Sstevel@tonic-gate #define ACPI_NORMAL_EXEC(a) 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate #define ACPI_DEBUG_DEFINE(a) a; 6250Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a) a; 6260Sstevel@tonic-gate #define _VERBOSE_STRUCTURES 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate /* Stack and buffer dumping */ 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate #define ACPI_DUMP_STACK_ENTRY(a) AcpiExDumpOperand((a),0) 632*347Smyers #define ACPI_DUMP_OPERANDS(a,b,c,d,e) AcpiExDumpOperands(a,b,c,d,e,_AcpiModuleName,__LINE__) 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate #define ACPI_DUMP_ENTRY(a,b) AcpiNsDumpEntry (a,b) 6360Sstevel@tonic-gate #define ACPI_DUMP_PATHNAME(a,b,c,d) AcpiNsDumpPathname(a,b,c,d) 6370Sstevel@tonic-gate #define ACPI_DUMP_RESOURCE_LIST(a) AcpiRsDumpResourceList(a) 6380Sstevel@tonic-gate #define ACPI_DUMP_BUFFER(a,b) AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT) 6390Sstevel@tonic-gate #define ACPI_BREAK_MSG(a) AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,(a)) 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate /* 6430Sstevel@tonic-gate * Generate INT3 on ACPI_ERROR (Debug only!) 6440Sstevel@tonic-gate */ 6450Sstevel@tonic-gate #define ACPI_ERROR_BREAK 6460Sstevel@tonic-gate #ifdef ACPI_ERROR_BREAK 6470Sstevel@tonic-gate #define ACPI_BREAK_ON_ERROR(lvl) if ((lvl)&ACPI_ERROR) \ 6480Sstevel@tonic-gate AcpiOsSignal(ACPI_SIGNAL_BREAKPOINT,"Fatal error encountered\n") 6490Sstevel@tonic-gate #else 6500Sstevel@tonic-gate #define ACPI_BREAK_ON_ERROR(lvl) 6510Sstevel@tonic-gate #endif 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate /* 6540Sstevel@tonic-gate * Master debug print macros 6550Sstevel@tonic-gate * Print iff: 6560Sstevel@tonic-gate * 1) Debug print for the current component is enabled 6570Sstevel@tonic-gate * 2) Debug error level or trace level for the print statement is enabled 6580Sstevel@tonic-gate */ 6590Sstevel@tonic-gate #define ACPI_DEBUG_PRINT(pl) AcpiUtDebugPrint ACPI_PARAM_LIST(pl) 6600Sstevel@tonic-gate #define ACPI_DEBUG_PRINT_RAW(pl) AcpiUtDebugPrintRaw ACPI_PARAM_LIST(pl) 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate #else 6640Sstevel@tonic-gate /* 6650Sstevel@tonic-gate * This is the non-debug case -- make everything go away, 6660Sstevel@tonic-gate * leaving no executable debug code! 6670Sstevel@tonic-gate */ 668*347Smyers #define ACPI_MODULE_NAME(Name) 669*347Smyers #define _AcpiModuleName "" 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate #define ACPI_DEBUG_EXEC(a) 6720Sstevel@tonic-gate #define ACPI_NORMAL_EXEC(a) a; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate #define ACPI_DEBUG_DEFINE(a) 6750Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a) 6760Sstevel@tonic-gate #define ACPI_FUNCTION_NAME(a) 6770Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE(a) 6780Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE_PTR(a,b) 6790Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE_U32(a,b) 6800Sstevel@tonic-gate #define ACPI_FUNCTION_TRACE_STR(a,b) 6810Sstevel@tonic-gate #define ACPI_FUNCTION_EXIT 6820Sstevel@tonic-gate #define ACPI_FUNCTION_STATUS_EXIT(s) 6830Sstevel@tonic-gate #define ACPI_FUNCTION_VALUE_EXIT(s) 6840Sstevel@tonic-gate #define ACPI_FUNCTION_ENTRY() 6850Sstevel@tonic-gate #define ACPI_DUMP_STACK_ENTRY(a) 6860Sstevel@tonic-gate #define ACPI_DUMP_OPERANDS(a,b,c,d,e) 6870Sstevel@tonic-gate #define ACPI_DUMP_ENTRY(a,b) 6880Sstevel@tonic-gate #define ACPI_DUMP_TABLES(a,b) 6890Sstevel@tonic-gate #define ACPI_DUMP_PATHNAME(a,b,c,d) 6900Sstevel@tonic-gate #define ACPI_DUMP_RESOURCE_LIST(a) 6910Sstevel@tonic-gate #define ACPI_DUMP_BUFFER(a,b) 6920Sstevel@tonic-gate #define ACPI_DEBUG_PRINT(pl) 6930Sstevel@tonic-gate #define ACPI_DEBUG_PRINT_RAW(pl) 6940Sstevel@tonic-gate #define ACPI_BREAK_MSG(a) 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate #define return_VOID return 6970Sstevel@tonic-gate #define return_ACPI_STATUS(s) return(s) 6980Sstevel@tonic-gate #define return_VALUE(s) return(s) 6990Sstevel@tonic-gate #define return_PTR(s) return(s) 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate #endif 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate /* 7040Sstevel@tonic-gate * Some code only gets executed when the debugger is built in. 7050Sstevel@tonic-gate * Note that this is entirely independent of whether the 7060Sstevel@tonic-gate * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not. 7070Sstevel@tonic-gate */ 7080Sstevel@tonic-gate #ifdef ACPI_DEBUGGER 7090Sstevel@tonic-gate #define ACPI_DEBUGGER_EXEC(a) a 7100Sstevel@tonic-gate #else 7110Sstevel@tonic-gate #define ACPI_DEBUGGER_EXEC(a) 7120Sstevel@tonic-gate #endif 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate /* 7160Sstevel@tonic-gate * For 16-bit code, we want to shrink some things even though 7170Sstevel@tonic-gate * we are using ACPI_DEBUG_OUTPUT to get the debug output 7180Sstevel@tonic-gate */ 7190Sstevel@tonic-gate #if ACPI_MACHINE_WIDTH == 16 7200Sstevel@tonic-gate #undef ACPI_DEBUG_ONLY_MEMBERS 7210Sstevel@tonic-gate #undef _VERBOSE_STRUCTURES 7220Sstevel@tonic-gate #define ACPI_DEBUG_ONLY_MEMBERS(a) 7230Sstevel@tonic-gate #endif 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate #ifdef ACPI_DEBUG_OUTPUT 7270Sstevel@tonic-gate /* 7280Sstevel@tonic-gate * 1) Set name to blanks 7290Sstevel@tonic-gate * 2) Copy the object name 7300Sstevel@tonic-gate */ 7310Sstevel@tonic-gate #define ACPI_ADD_OBJECT_NAME(a,b) ACPI_MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\ 7320Sstevel@tonic-gate ACPI_STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name)) 7330Sstevel@tonic-gate #else 7340Sstevel@tonic-gate 7350Sstevel@tonic-gate #define ACPI_ADD_OBJECT_NAME(a,b) 7360Sstevel@tonic-gate #endif 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate /* 7400Sstevel@tonic-gate * Memory allocation tracking (DEBUG ONLY) 7410Sstevel@tonic-gate */ 7420Sstevel@tonic-gate #ifndef ACPI_DBG_TRACK_ALLOCATIONS 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate /* Memory allocation */ 7450Sstevel@tonic-gate 746*347Smyers #define ACPI_MEM_ALLOCATE(a) AcpiUtAllocate((ACPI_SIZE)(a),_COMPONENT,_AcpiModuleName,__LINE__) 747*347Smyers #define ACPI_MEM_CALLOCATE(a) AcpiUtCallocate((ACPI_SIZE)(a), _COMPONENT,_AcpiModuleName,__LINE__) 7480Sstevel@tonic-gate #define ACPI_MEM_FREE(a) AcpiOsFree(a) 7490Sstevel@tonic-gate #define ACPI_MEM_TRACKING(a) 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate #else 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate /* Memory allocation */ 7540Sstevel@tonic-gate 755*347Smyers #define ACPI_MEM_ALLOCATE(a) AcpiUtAllocateAndTrack((ACPI_SIZE)(a),_COMPONENT,_AcpiModuleName,__LINE__) 756*347Smyers #define ACPI_MEM_CALLOCATE(a) AcpiUtCallocateAndTrack((ACPI_SIZE)(a), _COMPONENT,_AcpiModuleName,__LINE__) 757*347Smyers #define ACPI_MEM_FREE(a) AcpiUtFreeAndTrack(a,_COMPONENT,_AcpiModuleName,__LINE__) 7580Sstevel@tonic-gate #define ACPI_MEM_TRACKING(a) a 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate #endif /* ACPI_DBG_TRACK_ALLOCATIONS */ 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate #endif /* ACMACROS_H */ 763