acmacros.h revision 127175
133965Sjdp/******************************************************************************
260484Sobrien *
360484Sobrien * Name: acmacros.h - C macros for the entire subsystem.
433965Sjdp *       $Revision: 149 $
533965Sjdp *
633965Sjdp *****************************************************************************/
733965Sjdp
833965Sjdp/******************************************************************************
933965Sjdp *
1033965Sjdp * 1. Copyright Notice
1133965Sjdp *
1233965Sjdp * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
1333965Sjdp * All rights reserved.
1433965Sjdp *
1533965Sjdp * 2. License
1633965Sjdp *
1733965Sjdp * 2.1. This is your license from Intel Corp. under its intellectual property
1833965Sjdp * rights.  You may have additional license terms from the party that provided
1933965Sjdp * you this software, covering your right to use that party's intellectual
2033965Sjdp * property rights.
2133965Sjdp *
2233965Sjdp * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2333965Sjdp * copy of the source code appearing in this file ("Covered Code") an
2433965Sjdp * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2533965Sjdp * base code distributed originally by Intel ("Original Intel Code") to copy,
2633965Sjdp * make derivatives, distribute, use and display any portion of the Covered
2777298Sobrien * Code in any form, with the right to sublicense such rights; and
2833965Sjdp *
2933965Sjdp * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3033965Sjdp * license (with the right to sublicense), under only those claims of Intel
3177298Sobrien * patents that are infringed by the Original Intel Code, to make, use, sell,
3233965Sjdp * offer to sell, and import the Covered Code and derivative works thereof
3333965Sjdp * solely to the minimum extent necessary to exercise the above copyright
3433965Sjdp * license, and in no event shall the patent license extend to any additions
3533965Sjdp * to or modifications of the Original Intel Code.  No other license or right
3633965Sjdp * is granted directly or by implication, estoppel or otherwise;
3733965Sjdp *
3833965Sjdp * The above copyright and patent license is granted only if the following
3933965Sjdp * conditions are met:
4033965Sjdp *
4133965Sjdp * 3. Conditions
4233965Sjdp *
4333965Sjdp * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4433965Sjdp * Redistribution of source code of any substantial portion of the Covered
4533965Sjdp * Code or modification with rights to further distribute source must include
4633965Sjdp * the above Copyright Notice, the above License, this list of Conditions,
4733965Sjdp * and the following Disclaimer and Export Compliance provision.  In addition,
4833965Sjdp * Licensee must cause all Covered Code to which Licensee contributes to
4933965Sjdp * contain a file documenting the changes Licensee made to create that Covered
5033965Sjdp * Code and the date of any change.  Licensee must include in that file the
5133965Sjdp * documentation of any changes made by any predecessor Licensee.  Licensee
5233965Sjdp * must include a prominent statement that the modification is derived,
5333965Sjdp * directly or indirectly, from Original Intel Code.
5433965Sjdp *
5577298Sobrien * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5633965Sjdp * Redistribution of source code of any substantial portion of the Covered
5733965Sjdp * Code or modification without rights to further distribute source must
5833965Sjdp * include the following Disclaimer and Export Compliance provision in the
5933965Sjdp * documentation and/or other materials provided with distribution.  In
6033965Sjdp * addition, Licensee may not authorize further sublicense of source of any
6133965Sjdp * portion of the Covered Code, and must include terms to the effect that the
6233965Sjdp * license from Licensee to its licensee is limited to the intellectual
6333965Sjdp * property embodied in the software Licensee provides to its licensee, and
6433965Sjdp * not to intellectual property embodied in modifications its licensee may
6533965Sjdp * make.
6633965Sjdp *
6733965Sjdp * 3.3. Redistribution of Executable. Redistribution in executable form of any
6833965Sjdp * substantial portion of the Covered Code or modification must reproduce the
6933965Sjdp * above Copyright Notice, and the following Disclaimer and Export Compliance
7033965Sjdp * provision in the documentation and/or other materials provided with the
7133965Sjdp * distribution.
7233965Sjdp *
7333965Sjdp * 3.4. Intel retains all right, title, and interest in and to the Original
7433965Sjdp * Intel Code.
7533965Sjdp *
7633965Sjdp * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7733965Sjdp * Intel shall be used in advertising or otherwise to promote the sale, use or
7833965Sjdp * other dealings in products derived from or relating to the Covered Code
7933965Sjdp * without prior written authorization from Intel.
8033965Sjdp *
8133965Sjdp * 4. Disclaimer and Export Compliance
8233965Sjdp *
8333965Sjdp * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8433965Sjdp * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8533965Sjdp * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8633965Sjdp * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8733965Sjdp * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8833965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8933965Sjdp * PARTICULAR PURPOSE.
9033965Sjdp *
9133965Sjdp * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9233965Sjdp * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9333965Sjdp * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9433965Sjdp * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9533965Sjdp * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9633965Sjdp * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9733965Sjdp * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9833965Sjdp * LIMITED REMEDY.
9933965Sjdp *
10033965Sjdp * 4.3. Licensee shall not export, either directly or indirectly, any of this
10133965Sjdp * software or system incorporating such software without first obtaining any
10233965Sjdp * required license or other approval from the U. S. Department of Commerce or
10333965Sjdp * any other agency or department of the United States Government.  In the
10433965Sjdp * event Licensee exports any such software from the United States or
10533965Sjdp * re-exports any such software from a foreign destination, Licensee shall
10633965Sjdp * ensure that the distribution and export/re-export of the software is in
10733965Sjdp * compliance with all laws, regulations, orders, or other restrictions of the
10833965Sjdp * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10933965Sjdp * any of its subsidiaries will export/re-export any technical data, process,
11033965Sjdp * software, or service, directly or indirectly, to any country for which the
11133965Sjdp * United States government or any agency thereof requires an export license,
11233965Sjdp * other governmental approval, or letter of assurance, without first obtaining
11333965Sjdp * such license, approval or letter.
11433965Sjdp *
11533965Sjdp *****************************************************************************/
11633965Sjdp
11733965Sjdp#ifndef __ACMACROS_H__
11833965Sjdp#define __ACMACROS_H__
11933965Sjdp
12033965Sjdp
12133965Sjdp/*
12233965Sjdp * Data manipulation macros
12333965Sjdp */
12477298Sobrien#define ACPI_LOWORD(l)                  ((UINT16)(UINT32)(l))
12533965Sjdp#define ACPI_HIWORD(l)                  ((UINT16)((((UINT32)(l)) >> 16) & 0xFFFF))
12633965Sjdp#define ACPI_LOBYTE(l)                  ((UINT8)(UINT16)(l))
12733965Sjdp#define ACPI_HIBYTE(l)                  ((UINT8)((((UINT16)(l)) >> 8) & 0xFF))
12833965Sjdp
12933965Sjdp
13033965Sjdp#if ACPI_MACHINE_WIDTH == 16
13133965Sjdp
13233965Sjdp/*
13333965Sjdp * For 16-bit addresses, we have to assume that the upper 32 bits
13433965Sjdp * are zero.
13533965Sjdp */
13633965Sjdp#define ACPI_LODWORD(l)                 ((UINT32)(l))
13733965Sjdp#define ACPI_HIDWORD(l)                 ((UINT32)(0))
13833965Sjdp
13933965Sjdp#define ACPI_GET_ADDRESS(a)             ((a).Lo)
14033965Sjdp#define ACPI_STORE_ADDRESS(a,b)         {(a).Hi=0;(a).Lo=(UINT32)(b);}
14133965Sjdp#define ACPI_VALID_ADDRESS(a)           ((a).Hi | (a).Lo)
14233965Sjdp
14333965Sjdp#else
14433965Sjdp#ifdef ACPI_NO_INTEGER64_SUPPORT
14533965Sjdp/*
14633965Sjdp * ACPI_INTEGER is 32-bits, no 64-bit support on this platform
14733965Sjdp */
14833965Sjdp#define ACPI_LODWORD(l)                 ((UINT32)(l))
14933965Sjdp#define ACPI_HIDWORD(l)                 ((UINT32)(0))
15033965Sjdp
15133965Sjdp#define ACPI_GET_ADDRESS(a)             (a)
15233965Sjdp#define ACPI_STORE_ADDRESS(a,b)         ((a)=(b))
15333965Sjdp#define ACPI_VALID_ADDRESS(a)           (a)
15433965Sjdp
15533965Sjdp#else
15633965Sjdp
15733965Sjdp/*
15833965Sjdp * Full 64-bit address/integer on both 32-bit and 64-bit platforms
15933965Sjdp */
16033965Sjdp#define ACPI_LODWORD(l)                 ((UINT32)(UINT64)(l))
16133965Sjdp#define ACPI_HIDWORD(l)                 ((UINT32)(((*(UINT64_STRUCT *)(void *)(&l))).Hi))
16233965Sjdp
16333965Sjdp#define ACPI_GET_ADDRESS(a)             (a)
16433965Sjdp#define ACPI_STORE_ADDRESS(a,b)         ((a)=(ACPI_PHYSICAL_ADDRESS)(b))
16533965Sjdp#define ACPI_VALID_ADDRESS(a)           (a)
16633965Sjdp#endif
16733965Sjdp#endif
16833965Sjdp
16933965Sjdp/*
17033965Sjdp * printf() format helpers
17133965Sjdp */
17233965Sjdp
17333965Sjdp/* Split 64-bit integer into two 32-bit values. Use with %8,8X%8.8X */
17433965Sjdp
17533965Sjdp#define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i),ACPI_LODWORD(i)
17633965Sjdp
17733965Sjdp/*
17833965Sjdp * Extract a byte of data using a pointer.  Any more than a byte and we
17933965Sjdp * get into potential aligment issues -- see the STORE macros below
18033965Sjdp */
18133965Sjdp#define ACPI_GET8(addr)                 (*(UINT8*)(addr))
18233965Sjdp
18333965Sjdp/* Pointer arithmetic */
18433965Sjdp
18533965Sjdp#define ACPI_PTR_ADD(t,a,b)             (t *) (void *)((char *)(a) + (ACPI_NATIVE_UINT)(b))
18633965Sjdp#define ACPI_PTR_DIFF(a,b)              (ACPI_NATIVE_UINT) ((char *)(a) - (char *)(b))
18733965Sjdp
18833965Sjdp/* Pointer/Integer type conversions */
18933965Sjdp
19033965Sjdp#define ACPI_TO_POINTER(i)              ACPI_PTR_ADD (void, (void *) NULL,(ACPI_NATIVE_UINT)i)
19133965Sjdp#define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p,(void *) NULL)
19233965Sjdp#define ACPI_OFFSET(d,f)                (ACPI_SIZE) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
19333965Sjdp#define ACPI_FADT_OFFSET(f)             ACPI_OFFSET (FADT_DESCRIPTOR, f)
19433965Sjdp
19533965Sjdp#define ACPI_CAST_PTR(t, p)             ((t *)(void *)(p))
19633965Sjdp#define ACPI_CAST_INDIRECT_PTR(t, p)    ((t **)(void *)(p))
19733965Sjdp
19833965Sjdp#if ACPI_MACHINE_WIDTH == 16
19933965Sjdp#define ACPI_STORE_POINTER(d,s)         ACPI_MOVE_32_TO_32(d,s)
20033965Sjdp#define ACPI_PHYSADDR_TO_PTR(i)         (void *)(i)
20133965Sjdp#define ACPI_PTR_TO_PHYSADDR(i)         (UINT32) (char *)(i)
20233965Sjdp#else
20333965Sjdp#define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
20433965Sjdp#define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
20533965Sjdp#endif
20633965Sjdp
20733965Sjdp/*
20833965Sjdp * Macros for moving data around to/from buffers that are possibly unaligned.
20933965Sjdp * If the hardware supports the transfer of unaligned data, just do the store.
21033965Sjdp * Otherwise, we have to move one byte at a time.
21133965Sjdp */
21233965Sjdp#ifdef ACPI_BIG_ENDIAN
21333965Sjdp/*
21433965Sjdp * Macros for big-endian machines
21533965Sjdp */
21633965Sjdp
21733965Sjdp/* This macro sets a buffer index, starting from the end of the buffer */
21833965Sjdp
21933965Sjdp#define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran)  ((BufLen) - (((BufOffset)+1) * (ByteGran)))
22033965Sjdp
22133965Sjdp/* These macros reverse the bytes during the move, converting little-endian to big endian */
22233965Sjdp
22333965Sjdp                                                     /* Big Endian      <==        Little Endian */
22433965Sjdp                                                     /*  Hi...Lo                     Lo...Hi     */
22533965Sjdp/* 16-bit source, 16/32/64 destination */
22633965Sjdp
22733965Sjdp#define ACPI_MOVE_16_TO_16(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
22833965Sjdp                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
22933965Sjdp
23033965Sjdp#define ACPI_MOVE_16_TO_32(d,s)         {(*(UINT32 *)(void *)(d))=0;\
23133965Sjdp                                           ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
23233965Sjdp                                           ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
23333965Sjdp
23433965Sjdp#define ACPI_MOVE_16_TO_64(d,s)         {(*(UINT64 *)(void *)(d))=0;\
23533965Sjdp                                           ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
23633965Sjdp                                           ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
23733965Sjdp
23833965Sjdp/* 32-bit source, 16/32/64 destination */
23933965Sjdp
24033965Sjdp#define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
24133965Sjdp
24233965Sjdp#define ACPI_MOVE_32_TO_32(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
24333965Sjdp                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
24433965Sjdp                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
24533965Sjdp                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
24633965Sjdp
24733965Sjdp#define ACPI_MOVE_32_TO_64(d,s)         {(*(UINT64 *)(void *)(d))=0;\
24833965Sjdp                                           ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
24933965Sjdp                                           ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
25033965Sjdp                                           ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
25133965Sjdp                                           ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
25233965Sjdp
25333965Sjdp/* 64-bit source, 16/32/64 destination */
25433965Sjdp
25533965Sjdp#define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
25633965Sjdp
25733965Sjdp#define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
25833965Sjdp
25933965Sjdp#define ACPI_MOVE_64_TO_64(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
26033965Sjdp                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
26133965Sjdp                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
26233965Sjdp                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
26333965Sjdp                                         ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
26433965Sjdp                                         ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
26533965Sjdp                                         ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
26633965Sjdp                                         ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
26733965Sjdp#else
26833965Sjdp/*
26933965Sjdp * Macros for little-endian machines
27033965Sjdp */
27133965Sjdp
27233965Sjdp/* This macro sets a buffer index, starting from the beginning of the buffer */
27333965Sjdp
27433965Sjdp#define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran)  (BufOffset)
27533965Sjdp
27633965Sjdp#ifdef ACPI_MISALIGNED_TRANSFERS
27733965Sjdp
27833965Sjdp/* The hardware supports unaligned transfers, just do the little-endian move */
27933965Sjdp
28033965Sjdp#if ACPI_MACHINE_WIDTH == 16
28133965Sjdp
28233965Sjdp/* No 64-bit integers */
28333965Sjdp/* 16-bit source, 16/32/64 destination */
28433965Sjdp
28533965Sjdp#define ACPI_MOVE_16_TO_16(d,s)         *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
28633965Sjdp#define ACPI_MOVE_16_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
28733965Sjdp#define ACPI_MOVE_16_TO_64(d,s)         ACPI_MOVE_16_TO_32(d,s)
28833965Sjdp
28933965Sjdp/* 32-bit source, 16/32/64 destination */
29033965Sjdp
29133965Sjdp#define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
29233965Sjdp#define ACPI_MOVE_32_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
29333965Sjdp#define ACPI_MOVE_32_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
29433965Sjdp
29533965Sjdp/* 64-bit source, 16/32/64 destination */
29633965Sjdp
29733965Sjdp#define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
29833965Sjdp#define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
29933965Sjdp#define ACPI_MOVE_64_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
30033965Sjdp
30133965Sjdp#else
30233965Sjdp/* 16-bit source, 16/32/64 destination */
30333965Sjdp
30433965Sjdp#define ACPI_MOVE_16_TO_16(d,s)         *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
30533965Sjdp#define ACPI_MOVE_16_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
30633965Sjdp#define ACPI_MOVE_16_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s)
30733965Sjdp
30833965Sjdp/* 32-bit source, 16/32/64 destination */
30933965Sjdp
31033965Sjdp#define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
31133965Sjdp#define ACPI_MOVE_32_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
31233965Sjdp#define ACPI_MOVE_32_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s)
31333965Sjdp
31433965Sjdp/* 64-bit source, 16/32/64 destination */
31533965Sjdp
31633965Sjdp#define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
31733965Sjdp#define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
31833965Sjdp#define ACPI_MOVE_64_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s)
31933965Sjdp#endif
32033965Sjdp
32133965Sjdp#else
32233965Sjdp/*
32333965Sjdp * The hardware does not support unaligned transfers.  We must move the
32433965Sjdp * data one byte at a time.  These macros work whether the source or
32533965Sjdp * the destination (or both) is/are unaligned.  (Little-endian move)
32633965Sjdp */
32733965Sjdp
32833965Sjdp/* 16-bit source, 16/32/64 destination */
32933965Sjdp
33033965Sjdp#define ACPI_MOVE_16_TO_16(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
33133965Sjdp                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];}
33233965Sjdp
33333965Sjdp#define ACPI_MOVE_16_TO_32(d,s)         {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);}
33433965Sjdp#define ACPI_MOVE_16_TO_64(d,s)         {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);}
33533965Sjdp
33633965Sjdp/* 32-bit source, 16/32/64 destination */
33733965Sjdp
33833965Sjdp#define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
33933965Sjdp
34033965Sjdp#define ACPI_MOVE_32_TO_32(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
34133965Sjdp                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
34233965Sjdp                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
34333965Sjdp                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];}
34433965Sjdp
34533965Sjdp#define ACPI_MOVE_32_TO_64(d,s)         {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d,s);}
34633965Sjdp
34733965Sjdp/* 64-bit source, 16/32/64 destination */
34833965Sjdp
34933965Sjdp#define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
35033965Sjdp#define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
35133965Sjdp#define ACPI_MOVE_64_TO_64(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
35233965Sjdp                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
35333965Sjdp                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
35433965Sjdp                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\
35533965Sjdp                                         ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\
35633965Sjdp                                         ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\
35733965Sjdp                                         ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
35833965Sjdp                                         ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
35933965Sjdp#endif
36033965Sjdp#endif
36133965Sjdp
36233965Sjdp/* Macros based on machine integer width */
36333965Sjdp
36433965Sjdp#if ACPI_MACHINE_WIDTH == 16
36533965Sjdp#define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_16_TO_16(d,s)
36633965Sjdp
36733965Sjdp#elif ACPI_MACHINE_WIDTH == 32
36833965Sjdp#define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_32_TO_16(d,s)
36933965Sjdp
37033965Sjdp#elif ACPI_MACHINE_WIDTH == 64
37133965Sjdp#define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_64_TO_16(d,s)
37233965Sjdp
37333965Sjdp#else
37433965Sjdp#error unknown ACPI_MACHINE_WIDTH
37533965Sjdp#endif
37633965Sjdp
37733965Sjdp
37833965Sjdp/*
37933965Sjdp * Fast power-of-two math macros for non-optimized compilers
38033965Sjdp */
38133965Sjdp#define _ACPI_DIV(value,PowerOf2)       ((UINT32) ((value) >> (PowerOf2)))
38233965Sjdp#define _ACPI_MUL(value,PowerOf2)       ((UINT32) ((value) << (PowerOf2)))
38333965Sjdp#define _ACPI_MOD(value,Divisor)        ((UINT32) ((value) & ((Divisor) -1)))
38433965Sjdp
38533965Sjdp#define ACPI_DIV_2(a)                   _ACPI_DIV(a,1)
38633965Sjdp#define ACPI_MUL_2(a)                   _ACPI_MUL(a,1)
38733965Sjdp#define ACPI_MOD_2(a)                   _ACPI_MOD(a,2)
38833965Sjdp
38933965Sjdp#define ACPI_DIV_4(a)                   _ACPI_DIV(a,2)
39033965Sjdp#define ACPI_MUL_4(a)                   _ACPI_MUL(a,2)
39133965Sjdp#define ACPI_MOD_4(a)                   _ACPI_MOD(a,4)
39233965Sjdp
39333965Sjdp#define ACPI_DIV_8(a)                   _ACPI_DIV(a,3)
39433965Sjdp#define ACPI_MUL_8(a)                   _ACPI_MUL(a,3)
39533965Sjdp#define ACPI_MOD_8(a)                   _ACPI_MOD(a,8)
39633965Sjdp
39733965Sjdp#define ACPI_DIV_16(a)                  _ACPI_DIV(a,4)
39833965Sjdp#define ACPI_MUL_16(a)                  _ACPI_MUL(a,4)
39933965Sjdp#define ACPI_MOD_16(a)                  _ACPI_MOD(a,16)
40033965Sjdp
40133965Sjdp
40233965Sjdp/*
40333965Sjdp * Rounding macros (Power of two boundaries only)
40433965Sjdp */
40533965Sjdp#define ACPI_ROUND_DOWN(value,boundary)      (((ACPI_NATIVE_UINT)(value)) & (~(((ACPI_NATIVE_UINT) boundary)-1)))
40633965Sjdp#define ACPI_ROUND_UP(value,boundary)        ((((ACPI_NATIVE_UINT)(value)) + (((ACPI_NATIVE_UINT) boundary)-1)) & (~(((ACPI_NATIVE_UINT) boundary)-1)))
40733965Sjdp
40833965Sjdp#define ACPI_ROUND_DOWN_TO_32_BITS(a)        ACPI_ROUND_DOWN(a,4)
40933965Sjdp#define ACPI_ROUND_DOWN_TO_64_BITS(a)        ACPI_ROUND_DOWN(a,8)
41033965Sjdp#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)    ACPI_ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
41133965Sjdp
41233965Sjdp#define ACPI_ROUND_UP_TO_32BITS(a)           ACPI_ROUND_UP(a,4)
41333965Sjdp#define ACPI_ROUND_UP_TO_64BITS(a)           ACPI_ROUND_UP(a,8)
41433965Sjdp#define ACPI_ROUND_UP_TO_NATIVE_WORD(a)      ACPI_ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
41533965Sjdp
41633965Sjdp
41733965Sjdp#define ACPI_ROUND_BITS_UP_TO_BYTES(a)       ACPI_DIV_8((a) + 7)
41833965Sjdp#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)     ACPI_DIV_8((a))
41933965Sjdp
42033965Sjdp#define ACPI_ROUND_UP_TO_1K(a)               (((a) + 1023) >> 10)
42133965Sjdp
42233965Sjdp/* Generic (non-power-of-two) rounding */
42333965Sjdp
42433965Sjdp#define ACPI_ROUND_UP_TO(value,boundary)     (((value) + ((boundary)-1)) / (boundary))
42577298Sobrien
42633965Sjdp/*
42733965Sjdp * Bitmask creation
42833965Sjdp * Bit positions start at zero.
42933965Sjdp * MASK_BITS_ABOVE creates a mask starting AT the position and above
43033965Sjdp * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
43133965Sjdp */
43233965Sjdp#define ACPI_MASK_BITS_ABOVE(position)       (~((ACPI_INTEGER_MAX) << ((UINT32) (position))))
43333965Sjdp#define ACPI_MASK_BITS_BELOW(position)       ((ACPI_INTEGER_MAX) << ((UINT32) (position)))
43433965Sjdp
43533965Sjdp#define ACPI_IS_OCTAL_DIGIT(d)               (((char)(d) >= '0') && ((char)(d) <= '7'))
43633965Sjdp
43733965Sjdp/* Macros for GAS addressing */
43833965Sjdp
43933965Sjdp#if ACPI_MACHINE_WIDTH != 16
44033965Sjdp
44133965Sjdp#define ACPI_PCI_DEVICE(a)              (UINT16) ((ACPI_HIDWORD ((a))) & 0x0000FFFF)
44233965Sjdp#define ACPI_PCI_FUNCTION(a)            (UINT16) ((ACPI_LODWORD ((a))) >> 16)
44333965Sjdp#define ACPI_PCI_REGISTER(a)            (UINT16) ((ACPI_LODWORD ((a))) & 0x0000FFFF)
44433965Sjdp
44533965Sjdp#else
44633965Sjdp
44733965Sjdp/* No support for GAS and PCI IDs in 16-bit mode  */
44833965Sjdp
44933965Sjdp#define ACPI_PCI_FUNCTION(a)            (UINT16) ((a) & 0xFFFF0000)
45033965Sjdp#define ACPI_PCI_DEVICE(a)              (UINT16) ((a) & 0x0000FFFF)
45133965Sjdp#define ACPI_PCI_REGISTER(a)            (UINT16) ((a) & 0x0000FFFF)
45233965Sjdp
45333965Sjdp#endif
45477298Sobrien
45533965Sjdp
45633965Sjdp/* Bitfields within ACPI registers */
45733965Sjdp
45833965Sjdp#define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)      ((Val << Pos) & Mask)
45933965Sjdp#define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val)  Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
46033965Sjdp
46133965Sjdp/*
46233965Sjdp * An ACPI_NAMESPACE_NODE * can appear in some contexts,
46333965Sjdp * where a pointer to an ACPI_OPERAND_OBJECT  can also
46477298Sobrien * appear.  This macro is used to distinguish them.
46533965Sjdp *
46633965Sjdp * The "Descriptor" field is the first field in both structures.
46733965Sjdp */
46833965Sjdp#define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId)
46933965Sjdp#define ACPI_SET_DESCRIPTOR_TYPE(d,t)   (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId = t)
47033965Sjdp
47133965Sjdp
47233965Sjdp/* Macro to test the object type */
47333965Sjdp
47433965Sjdp#define ACPI_GET_OBJECT_TYPE(d)         (((ACPI_OPERAND_OBJECT *)(void *)(d))->Common.Type)
47533965Sjdp
47633965Sjdp/* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
47733965Sjdp
47833965Sjdp#define ACPI_IS_SINGLE_TABLE(x)         (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
47933965Sjdp
48033965Sjdp/*
48133965Sjdp * Macros for the master AML opcode table
48233965Sjdp */
48333965Sjdp#if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
48433965Sjdp#define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags)     {Name,(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type}
48533965Sjdp#else
48633965Sjdp#define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags)     {(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type}
48733965Sjdp#endif
48833965Sjdp
48933965Sjdp#ifdef ACPI_DISASSEMBLER
49033965Sjdp#define ACPI_DISASM_ONLY_MEMBERS(a)     a;
49133965Sjdp#else
49233965Sjdp#define ACPI_DISASM_ONLY_MEMBERS(a)
49333965Sjdp#endif
49433965Sjdp
49533965Sjdp#define ARG_TYPE_WIDTH                  5
49633965Sjdp#define ARG_1(x)                        ((UINT32)(x))
49733965Sjdp#define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
49833965Sjdp#define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
49933965Sjdp#define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
50033965Sjdp#define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
50133965Sjdp#define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
50233965Sjdp
50333965Sjdp#define ARGI_LIST1(a)                   (ARG_1(a))
50433965Sjdp#define ARGI_LIST2(a,b)                 (ARG_1(b)|ARG_2(a))
50533965Sjdp#define ARGI_LIST3(a,b,c)               (ARG_1(c)|ARG_2(b)|ARG_3(a))
50633965Sjdp#define ARGI_LIST4(a,b,c,d)             (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
50733965Sjdp#define ARGI_LIST5(a,b,c,d,e)           (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
50833965Sjdp#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))
50933965Sjdp
51033965Sjdp#define ARGP_LIST1(a)                   (ARG_1(a))
51133965Sjdp#define ARGP_LIST2(a,b)                 (ARG_1(a)|ARG_2(b))
51233965Sjdp#define ARGP_LIST3(a,b,c)               (ARG_1(a)|ARG_2(b)|ARG_3(c))
51333965Sjdp#define ARGP_LIST4(a,b,c,d)             (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
51433965Sjdp#define ARGP_LIST5(a,b,c,d,e)           (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
51533965Sjdp#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))
51633965Sjdp
51733965Sjdp#define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
51833965Sjdp#define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
51933965Sjdp
52033965Sjdp
52133965Sjdp/*
52233965Sjdp * Reporting macros that are never compiled out
52333965Sjdp */
52433965Sjdp#define ACPI_PARAM_LIST(pl)                 pl
52533965Sjdp
52633965Sjdp/*
52733965Sjdp * Error reporting.  These versions add callers module and line#.  Since
52833965Sjdp * _THIS_MODULE gets compiled out when ACPI_DEBUG_OUTPUT isn't defined, only
52933965Sjdp * use it in debug mode.
53033965Sjdp */
53133965Sjdp#ifdef ACPI_DEBUG_OUTPUT
53233965Sjdp
53333965Sjdp#define ACPI_REPORT_INFO(fp)                {AcpiUtReportInfo(_THIS_MODULE,__LINE__,_COMPONENT); \
53433965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
53533965Sjdp#define ACPI_REPORT_ERROR(fp)               {AcpiUtReportError(_THIS_MODULE,__LINE__,_COMPONENT); \
53633965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
53733965Sjdp#define ACPI_REPORT_WARNING(fp)             {AcpiUtReportWarning(_THIS_MODULE,__LINE__,_COMPONENT); \
53833965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
53933965Sjdp#define ACPI_REPORT_NSERROR(s,e)            AcpiNsReportError(_THIS_MODULE,__LINE__,_COMPONENT, s, e);
54033965Sjdp
54133965Sjdp#define ACPI_REPORT_METHOD_ERROR(s,n,p,e)   AcpiNsReportMethodError(_THIS_MODULE,__LINE__,_COMPONENT, s, n, p, e);
54233965Sjdp
54333965Sjdp#else
54433965Sjdp
54533965Sjdp#define ACPI_REPORT_INFO(fp)                {AcpiUtReportInfo("ACPI",__LINE__,_COMPONENT); \
54633965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
54733965Sjdp#define ACPI_REPORT_ERROR(fp)               {AcpiUtReportError("ACPI",__LINE__,_COMPONENT); \
54833965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
54933965Sjdp#define ACPI_REPORT_WARNING(fp)             {AcpiUtReportWarning("ACPI",__LINE__,_COMPONENT); \
55033965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
55133965Sjdp#define ACPI_REPORT_NSERROR(s,e)            AcpiNsReportError("ACPI",__LINE__,_COMPONENT, s, e);
55233965Sjdp
55333965Sjdp#define ACPI_REPORT_METHOD_ERROR(s,n,p,e)   AcpiNsReportMethodError("ACPI",__LINE__,_COMPONENT, s, n, p, e);
55433965Sjdp
55533965Sjdp#endif
55633965Sjdp
55733965Sjdp/* Error reporting.  These versions pass thru the module and line# */
55833965Sjdp
55933965Sjdp#define _ACPI_REPORT_INFO(a,b,c,fp)         {AcpiUtReportInfo(a,b,c); \
56033965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
56133965Sjdp#define _ACPI_REPORT_ERROR(a,b,c,fp)        {AcpiUtReportError(a,b,c); \
56233965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
56333965Sjdp#define _ACPI_REPORT_WARNING(a,b,c,fp)      {AcpiUtReportWarning(a,b,c); \
56433965Sjdp                                                AcpiOsPrintf ACPI_PARAM_LIST(fp);}
56533965Sjdp
56633965Sjdp/*
56733965Sjdp * Debug macros that are conditionally compiled
56833965Sjdp */
56933965Sjdp#ifdef ACPI_DEBUG_OUTPUT
57033965Sjdp
57133965Sjdp#define ACPI_MODULE_NAME(name)               static char ACPI_UNUSED_VAR *_THIS_MODULE = name;
57233965Sjdp
57333965Sjdp/*
57433965Sjdp * Function entry tracing.
57533965Sjdp * The first parameter should be the procedure name as a quoted string.  This is declared
57633965Sjdp * as a local string ("_ProcName) so that it can be also used by the function exit macros below.
57733965Sjdp */
57833965Sjdp#define ACPI_FUNCTION_NAME(a)               ACPI_DEBUG_PRINT_INFO _Dbg; \
57933965Sjdp                                                _Dbg.ComponentId = _COMPONENT; \
58033965Sjdp                                                _Dbg.ProcName    = a; \
58133965Sjdp                                                _Dbg.ModuleName  = _THIS_MODULE;
58233965Sjdp
58333965Sjdp#define ACPI_FUNCTION_TRACE(a)              ACPI_FUNCTION_NAME(a) \
58433965Sjdp                                                AcpiUtTrace(__LINE__,&_Dbg)
58533965Sjdp#define ACPI_FUNCTION_TRACE_PTR(a,b)        ACPI_FUNCTION_NAME(a) \
58633965Sjdp                                                AcpiUtTracePtr(__LINE__,&_Dbg,(void *)b)
58733965Sjdp#define ACPI_FUNCTION_TRACE_U32(a,b)        ACPI_FUNCTION_NAME(a) \
58833965Sjdp                                                AcpiUtTraceU32(__LINE__,&_Dbg,(UINT32)b)
58933965Sjdp#define ACPI_FUNCTION_TRACE_STR(a,b)        ACPI_FUNCTION_NAME(a) \
59033965Sjdp                                                AcpiUtTraceStr(__LINE__,&_Dbg,(char *)b)
59133965Sjdp
59233965Sjdp#define ACPI_FUNCTION_ENTRY()               AcpiUtTrackStackPtr()
59333965Sjdp
59433965Sjdp/*
59533965Sjdp * Function exit tracing.
59633965Sjdp * WARNING: These macros include a return statement.  This is usually considered
59733965Sjdp * bad form, but having a separate exit macro is very ugly and difficult to maintain.
59833965Sjdp * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
59933965Sjdp * so that "_ProcName" is defined.
60060484Sobrien */
60133965Sjdp#ifdef ACPI_USE_DO_WHILE_0
60233965Sjdp#define ACPI_DO_WHILE0(a)               do a while(0)
60333965Sjdp#else
60433965Sjdp#define ACPI_DO_WHILE0(a)               a
60533965Sjdp#endif
60633965Sjdp
60733965Sjdp#define return_VOID                     ACPI_DO_WHILE0 ({AcpiUtExit(__LINE__,&_Dbg);return;})
60833965Sjdp#define return_ACPI_STATUS(s)           ACPI_DO_WHILE0 ({AcpiUtStatusExit(__LINE__,&_Dbg,(s));return((s));})
60933965Sjdp#define return_VALUE(s)                 ACPI_DO_WHILE0 ({AcpiUtValueExit(__LINE__,&_Dbg,(ACPI_INTEGER)(s));return((s));})
61033965Sjdp#define return_PTR(s)                   ACPI_DO_WHILE0 ({AcpiUtPtrExit(__LINE__,&_Dbg,(UINT8 *)(s));return((s));})
61133965Sjdp
61233965Sjdp/* Conditional execution */
61333965Sjdp
61433965Sjdp#define ACPI_DEBUG_EXEC(a)              a
61533965Sjdp#define ACPI_NORMAL_EXEC(a)
61633965Sjdp
61733965Sjdp#define ACPI_DEBUG_DEFINE(a)            a;
61833965Sjdp#define ACPI_DEBUG_ONLY_MEMBERS(a)      a;
61933965Sjdp#define _VERBOSE_STRUCTURES
62033965Sjdp
62133965Sjdp
62233965Sjdp/* Stack and buffer dumping */
62333965Sjdp
62433965Sjdp#define ACPI_DUMP_STACK_ENTRY(a)        AcpiExDumpOperand(a)
62533965Sjdp#define ACPI_DUMP_OPERANDS(a,b,c,d,e)   AcpiExDumpOperands(a,b,c,d,e,_THIS_MODULE,__LINE__)
62633965Sjdp
62733965Sjdp
62833965Sjdp#define ACPI_DUMP_ENTRY(a,b)            AcpiNsDumpEntry (a,b)
62933965Sjdp#define ACPI_DUMP_TABLES(a,b)           AcpiNsDumpTables(a,b)
63033965Sjdp#define ACPI_DUMP_PATHNAME(a,b,c,d)     AcpiNsDumpPathname(a,b,c,d)
63133965Sjdp#define ACPI_DUMP_RESOURCE_LIST(a)      AcpiRsDumpResourceList(a)
63233965Sjdp#define ACPI_DUMP_BUFFER(a,b)           AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
63333965Sjdp#define ACPI_BREAK_MSG(a)               AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,(a))
63433965Sjdp
63533965Sjdp
63633965Sjdp/*
63733965Sjdp * Generate INT3 on ACPI_ERROR (Debug only!)
63833965Sjdp */
63933965Sjdp#define ACPI_ERROR_BREAK
64033965Sjdp#ifdef  ACPI_ERROR_BREAK
64133965Sjdp#define ACPI_BREAK_ON_ERROR(lvl)        if ((lvl)&ACPI_ERROR) \
64233965Sjdp                                            AcpiOsSignal(ACPI_SIGNAL_BREAKPOINT,"Fatal error encountered\n")
64333965Sjdp#else
64433965Sjdp#define ACPI_BREAK_ON_ERROR(lvl)
64533965Sjdp#endif
64633965Sjdp
64733965Sjdp/*
64833965Sjdp * Master debug print macros
64933965Sjdp * Print iff:
65033965Sjdp *    1) Debug print for the current component is enabled
65133965Sjdp *    2) Debug error level or trace level for the print statement is enabled
65233965Sjdp */
65333965Sjdp#define ACPI_DEBUG_PRINT(pl)            AcpiUtDebugPrint ACPI_PARAM_LIST(pl)
65433965Sjdp#define ACPI_DEBUG_PRINT_RAW(pl)        AcpiUtDebugPrintRaw ACPI_PARAM_LIST(pl)
65533965Sjdp
65633965Sjdp
65733965Sjdp#else
65833965Sjdp/*
65933965Sjdp * This is the non-debug case -- make everything go away,
66033965Sjdp * leaving no executable debug code!
66133965Sjdp */
66233965Sjdp#define ACPI_MODULE_NAME(name)
66333965Sjdp#define _THIS_MODULE ""
66433965Sjdp
66533965Sjdp#define ACPI_DEBUG_EXEC(a)
66633965Sjdp#define ACPI_NORMAL_EXEC(a)             a;
66733965Sjdp
66833965Sjdp#define ACPI_DEBUG_DEFINE(a)
66933965Sjdp#define ACPI_DEBUG_ONLY_MEMBERS(a)
67033965Sjdp#define ACPI_FUNCTION_NAME(a)
67133965Sjdp#define ACPI_FUNCTION_TRACE(a)
67233965Sjdp#define ACPI_FUNCTION_TRACE_PTR(a,b)
67333965Sjdp#define ACPI_FUNCTION_TRACE_U32(a,b)
67433965Sjdp#define ACPI_FUNCTION_TRACE_STR(a,b)
67533965Sjdp#define ACPI_FUNCTION_EXIT
67633965Sjdp#define ACPI_FUNCTION_STATUS_EXIT(s)
67733965Sjdp#define ACPI_FUNCTION_VALUE_EXIT(s)
67833965Sjdp#define ACPI_FUNCTION_ENTRY()
67933965Sjdp#define ACPI_DUMP_STACK_ENTRY(a)
68033965Sjdp#define ACPI_DUMP_OPERANDS(a,b,c,d,e)
68133965Sjdp#define ACPI_DUMP_ENTRY(a,b)
68233965Sjdp#define ACPI_DUMP_TABLES(a,b)
68333965Sjdp#define ACPI_DUMP_PATHNAME(a,b,c,d)
68433965Sjdp#define ACPI_DUMP_RESOURCE_LIST(a)
68533965Sjdp#define ACPI_DUMP_BUFFER(a,b)
68633965Sjdp#define ACPI_DEBUG_PRINT(pl)
68733965Sjdp#define ACPI_DEBUG_PRINT_RAW(pl)
68833965Sjdp#define ACPI_BREAK_MSG(a)
68933965Sjdp
69033965Sjdp#define return_VOID                     return
69133965Sjdp#define return_ACPI_STATUS(s)           return(s)
69233965Sjdp#define return_VALUE(s)                 return(s)
69333965Sjdp#define return_PTR(s)                   return(s)
69433965Sjdp
69533965Sjdp#endif
69633965Sjdp
69733965Sjdp/*
69833965Sjdp * Some code only gets executed when the debugger is built in.
69933965Sjdp * Note that this is entirely independent of whether the
70033965Sjdp * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not.
70133965Sjdp */
70233965Sjdp#ifdef ACPI_DEBUGGER
70333965Sjdp#define ACPI_DEBUGGER_EXEC(a)           a
70433965Sjdp#else
70533965Sjdp#define ACPI_DEBUGGER_EXEC(a)
70633965Sjdp#endif
70733965Sjdp
70833965Sjdp
70933965Sjdp/*
71033965Sjdp * For 16-bit code, we want to shrink some things even though
71133965Sjdp * we are using ACPI_DEBUG_OUTPUT to get the debug output
71233965Sjdp */
71333965Sjdp#if ACPI_MACHINE_WIDTH == 16
71433965Sjdp#undef ACPI_DEBUG_ONLY_MEMBERS
71533965Sjdp#undef _VERBOSE_STRUCTURES
71633965Sjdp#define ACPI_DEBUG_ONLY_MEMBERS(a)
71733965Sjdp#endif
71833965Sjdp
71933965Sjdp
72033965Sjdp#ifdef ACPI_DEBUG_OUTPUT
72133965Sjdp/*
72233965Sjdp * 1) Set name to blanks
72333965Sjdp * 2) Copy the object name
72433965Sjdp */
72533965Sjdp#define ACPI_ADD_OBJECT_NAME(a,b)       ACPI_MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\
72633965Sjdp                                        ACPI_STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name))
72733965Sjdp#else
72833965Sjdp
72933965Sjdp#define ACPI_ADD_OBJECT_NAME(a,b)
73033965Sjdp#endif
73133965Sjdp
73233965Sjdp
73333965Sjdp/*
73433965Sjdp * Memory allocation tracking (DEBUG ONLY)
73533965Sjdp */
73633965Sjdp#ifndef ACPI_DBG_TRACK_ALLOCATIONS
73733965Sjdp
73833965Sjdp/* Memory allocation */
73933965Sjdp
74033965Sjdp#define ACPI_MEM_ALLOCATE(a)            AcpiUtAllocate((ACPI_SIZE)(a),_COMPONENT,_THIS_MODULE,__LINE__)
74133965Sjdp#define ACPI_MEM_CALLOCATE(a)           AcpiUtCallocate((ACPI_SIZE)(a), _COMPONENT,_THIS_MODULE,__LINE__)
74233965Sjdp#define ACPI_MEM_FREE(a)                AcpiOsFree(a)
74333965Sjdp#define ACPI_MEM_TRACKING(a)
74433965Sjdp
74533965Sjdp
74633965Sjdp#else
74733965Sjdp
74833965Sjdp/* Memory allocation */
74933965Sjdp
75033965Sjdp#define ACPI_MEM_ALLOCATE(a)            AcpiUtAllocateAndTrack((ACPI_SIZE)(a),_COMPONENT,_THIS_MODULE,__LINE__)
75133965Sjdp#define ACPI_MEM_CALLOCATE(a)           AcpiUtCallocateAndTrack((ACPI_SIZE)(a), _COMPONENT,_THIS_MODULE,__LINE__)
75233965Sjdp#define ACPI_MEM_FREE(a)                AcpiUtFreeAndTrack(a,_COMPONENT,_THIS_MODULE,__LINE__)
75333965Sjdp#define ACPI_MEM_TRACKING(a)            a
75433965Sjdp
75533965Sjdp#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
75633965Sjdp
75733965Sjdp#endif /* ACMACROS_H */
75833965Sjdp