acmacros.h revision 77424
1/******************************************************************************
2 *
3 * Name: acmacros.h - C macros for the entire subsystem.
4 *       $Revision: 72 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#ifndef __ACMACROS_H__
118#define __ACMACROS_H__
119
120/*
121 * Data manipulation macros
122 */
123
124#ifndef LODWORD
125#define LODWORD(l)                      ((UINT32)(UINT64)(l))
126#endif
127
128#ifndef HIDWORD
129#define HIDWORD(l)                      ((UINT32)((((UINT64)(l)) >> 32) & 0xFFFFFFFF))
130#endif
131
132#ifndef LOWORD
133#define LOWORD(l)                       ((UINT16)(NATIVE_UINT)(l))
134#endif
135
136#ifndef HIWORD
137#define HIWORD(l)                       ((UINT16)((((NATIVE_UINT)(l)) >> 16) & 0xFFFF))
138#endif
139
140#ifndef LOBYTE
141#define LOBYTE(l)                       ((UINT8)(UINT16)(l))
142#endif
143
144#ifndef HIBYTE
145#define HIBYTE(l)                       ((UINT8)((((UINT16)(l)) >> 8) & 0xFF))
146#endif
147
148#define BIT0(x)                         ((((x) & 0x01) > 0) ? 1 : 0)
149#define BIT1(x)                         ((((x) & 0x02) > 0) ? 1 : 0)
150#define BIT2(x)                         ((((x) & 0x04) > 0) ? 1 : 0)
151
152#define BIT3(x)                         ((((x) & 0x08) > 0) ? 1 : 0)
153#define BIT4(x)                         ((((x) & 0x10) > 0) ? 1 : 0)
154#define BIT5(x)                         ((((x) & 0x20) > 0) ? 1 : 0)
155#define BIT6(x)                         ((((x) & 0x40) > 0) ? 1 : 0)
156#define BIT7(x)                         ((((x) & 0x80) > 0) ? 1 : 0)
157
158#define LOW_BASE(w)                     ((UINT16) ((w) & 0x0000FFFF))
159#define MID_BASE(b)                     ((UINT8) (((b) & 0x00FF0000) >> 16))
160#define HI_BASE(b)                      ((UINT8) (((b) & 0xFF000000) >> 24))
161#define LOW_LIMIT(w)                    ((UINT16) ((w) & 0x0000FFFF))
162#define HI_LIMIT(b)                     ((UINT8) (((b) & 0x00FF0000) >> 16))
163
164
165#ifdef _IA16
166/*
167 * For 16-bit addresses, we have to assume that the upper 32 bits
168 * are zero.
169 */
170#define ACPI_GET_ADDRESS(a)             ((a).Lo)
171#define ACPI_STORE_ADDRESS(a,b)         {(a).Hi=0;(a).Lo=(b);}
172#define ACPI_VALID_ADDRESS(a)           ((a).Hi | (a).Lo)
173
174#else
175/*
176 * Full 64-bit address on 32-bit and 64-bit platforms
177 */
178#define ACPI_GET_ADDRESS(a)             (a)
179#define ACPI_STORE_ADDRESS(a,b)         ((a)=(b))
180#define ACPI_VALID_ADDRESS(a)           (a)
181#endif
182
183 /*
184  * Extract a byte of data using a pointer.  Any more than a byte and we
185  * get into potential aligment issues -- see the STORE macros below
186  */
187#define GET8(addr)                      (*(UINT8*)(addr))
188
189/* Pointer arithmetic */
190
191
192#define POINTER_ADD(t,a,b)              (t *) ((NATIVE_UINT)(a) + (NATIVE_UINT)(b))
193#define POINTER_DIFF(a,b)               ((UINT32) ((NATIVE_UINT)(a) - (NATIVE_UINT)(b)))
194
195/*
196 * Macros for moving data around to/from buffers that are possibly unaligned.
197 * If the hardware supports the transfer of unaligned data, just do the store.
198 * Otherwise, we have to move one byte at a time.
199 */
200
201#ifdef _HW_ALIGNMENT_SUPPORT
202
203/* The hardware supports unaligned transfers, just do the move */
204
205#define MOVE_UNALIGNED16_TO_16(d,s)     *(UINT16*)(d) = *(UINT16*)(s)
206#define MOVE_UNALIGNED32_TO_32(d,s)     *(UINT32*)(d) = *(UINT32*)(s)
207#define MOVE_UNALIGNED16_TO_32(d,s)     *(UINT32*)(d) = *(UINT16*)(s)
208#define MOVE_UNALIGNED64_TO_64(d,s)     *(UINT64*)(d) = *(UINT64*)(s)
209
210#else
211/*
212 * The hardware does not support unaligned transfers.  We must move the
213 * data one byte at a time.  These macros work whether the source or
214 * the destination (or both) is/are unaligned.
215 */
216
217#define MOVE_UNALIGNED16_TO_16(d,s)     {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
218                                         ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];}
219
220#define MOVE_UNALIGNED32_TO_32(d,s)     {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
221                                         ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];\
222                                         ((UINT8 *)(d))[2] = ((UINT8 *)(s))[2];\
223                                         ((UINT8 *)(d))[3] = ((UINT8 *)(s))[3];}
224
225#define MOVE_UNALIGNED16_TO_32(d,s)     {(*(UINT32*)(d)) = 0; MOVE_UNALIGNED16_TO_16(d,s);}
226
227#define MOVE_UNALIGNED64_TO_64(d,s)     {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
228                                         ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];\
229                                         ((UINT8 *)(d))[2] = ((UINT8 *)(s))[2];\
230                                         ((UINT8 *)(d))[3] = ((UINT8 *)(s))[3];\
231                                         ((UINT8 *)(d))[4] = ((UINT8 *)(s))[4];\
232                                         ((UINT8 *)(d))[5] = ((UINT8 *)(s))[5];\
233                                         ((UINT8 *)(d))[6] = ((UINT8 *)(s))[6];\
234                                         ((UINT8 *)(d))[7] = ((UINT8 *)(s))[7];}
235
236#endif
237
238
239/*
240 * Fast power-of-two math macros for non-optimized compilers
241 */
242
243#define _DIV(value,PowerOf2)            ((UINT32) ((value) >> (PowerOf2)))
244#define _MUL(value,PowerOf2)            ((UINT32) ((value) << (PowerOf2)))
245#define _MOD(value,Divisor)             ((UINT32) ((value) & ((Divisor) -1)))
246
247#define DIV_2(a)                        _DIV(a,1)
248#define MUL_2(a)                        _MUL(a,1)
249#define MOD_2(a)                        _MOD(a,2)
250
251#define DIV_4(a)                        _DIV(a,2)
252#define MUL_4(a)                        _MUL(a,2)
253#define MOD_4(a)                        _MOD(a,4)
254
255#define DIV_8(a)                        _DIV(a,3)
256#define MUL_8(a)                        _MUL(a,3)
257#define MOD_8(a)                        _MOD(a,8)
258
259#define DIV_16(a)                       _DIV(a,4)
260#define MUL_16(a)                       _MUL(a,4)
261#define MOD_16(a)                       _MOD(a,16)
262
263/*
264 * Divide and Modulo
265 */
266#define ACPI_DIVIDE(n,d)                ((n) / (d))
267#define ACPI_MODULO(n,d)                ((n) % (d))
268
269/*
270 * Rounding macros (Power of two boundaries only)
271 */
272
273#define ROUND_DOWN(value,boundary)      ((value) & (~((boundary)-1)))
274#define ROUND_UP(value,boundary)        (((value) + ((boundary)-1)) & (~((boundary)-1)))
275
276#define ROUND_DOWN_TO_32_BITS(a)        ROUND_DOWN(a,4)
277#define ROUND_DOWN_TO_64_BITS(a)        ROUND_DOWN(a,8)
278#define ROUND_DOWN_TO_NATIVE_WORD(a)    ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
279
280#define ROUND_UP_TO_32BITS(a)           ROUND_UP(a,4)
281#define ROUND_UP_TO_64BITS(a)           ROUND_UP(a,8)
282#define ROUND_UP_TO_NATIVE_WORD(a)      ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
283
284#define ROUND_PTR_UP_TO_4(a,b)          ((b *)(((NATIVE_UINT)(a) + 3) & ~3))
285#define ROUND_PTR_UP_TO_8(a,b)          ((b *)(((NATIVE_UINT)(a) + 7) & ~7))
286
287#define ROUND_BITS_UP_TO_BYTES(a)       DIV_8((a) + 7)
288#define ROUND_BITS_DOWN_TO_BYTES(a)     DIV_8((a))
289
290#define ROUND_UP_TO_1K(a)               (((a) + 1023) >> 10)
291
292/* Generic (non-power-of-two) rounding */
293
294#define ROUND_UP_TO(value,boundary)     (((value) + ((boundary)-1)) / (boundary))
295
296/*
297 * Bitmask creation
298 * Bit positions start at zero.
299 * MASK_BITS_ABOVE creates a mask starting AT the position and above
300 * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
301 */
302
303
304#define MASK_BITS_ABOVE(position)       (~(((UINT32)(-1)) << ((UINT32) (position))))
305#define MASK_BITS_BELOW(position)       (((UINT32)(-1)) << ((UINT32) (position)))
306
307#ifdef DEBUG_ASSERT
308#undef DEBUG_ASSERT
309#endif
310
311
312/* Macros for GAS addressing */
313
314#define ACPI_PCI_DEVICE_MASK            (UINT64) 0x0000FFFF00000000
315#define ACPI_PCI_FUNCTION_MASK          (UINT64) 0x00000000FFFF0000
316#define ACPI_PCI_REGISTER_MASK          (UINT64) 0x000000000000FFFF
317
318#define ACPI_PCI_FUNCTION(a)            (UINT32) ((((a) & ACPI_PCI_FUNCTION_MASK) >> 16))
319#define ACPI_PCI_DEVICE(a)              (UINT32) ((((a) & ACPI_PCI_DEVICE_MASK) >> 32))
320
321#ifndef _IA16
322#define ACPI_PCI_REGISTER(a)            (UINT32) (((a) & ACPI_PCI_REGISTER_MASK))
323#define ACPI_PCI_DEVFUN(a)              (UINT32) ((ACPI_PCI_DEVICE(a) << 16) | ACPI_PCI_FUNCTION(a))
324
325#else
326#define ACPI_PCI_REGISTER(a)            (UINT32) (((a) & 0x0000FFFF))
327#define ACPI_PCI_DEVFUN(a)              (UINT32) ((((a) & 0xFFFF0000) >> 16))
328
329#endif
330
331/*
332 * An ACPI_HANDLE (which is actually an ACPI_NAMESPACE_NODE *) can appear in some contexts,
333 * such as on apObjStack, where a pointer to an ACPI_OPERAND_OBJECT  can also
334 * appear.  This macro is used to distinguish them.
335 *
336 * The DataType field is the first field in both structures.
337 */
338
339#define VALID_DESCRIPTOR_TYPE(d,t)      (((ACPI_NAMESPACE_NODE *)d)->DataType == t)
340
341
342/* Macro to test the object type */
343
344#define IS_THIS_OBJECT_TYPE(d,t)        (((ACPI_OPERAND_OBJECT  *)d)->Common.Type == (UINT8)t)
345
346/* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
347
348#define IS_SINGLE_TABLE(x)              (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
349
350/* Check if ACPI has been initialized properly */
351
352#define ACPI_IS_INITIALIZATION_COMPLETE(s)  {if (AcpiGbl_RootNode) s = AE_OK; else s=AE_NO_NAMESPACE;}
353
354/*
355 * Macro to check if a pointer is within an ACPI table.
356 * Parameter (a) is the pointer to check.  Parameter (b) must be defined
357 * as a pointer to an ACPI_TABLE_HEADER.  (b+1) then points past the header,
358 * and ((UINT8 *)b+b->Length) points one byte past the end of the table.
359 */
360
361#ifndef _IA16
362#define IS_IN_ACPI_TABLE(a,b)           (((UINT8 *)(a) >= (UINT8 *)(b + 1)) &&\
363                                        ((UINT8 *)(a) < ((UINT8 *)b + b->Length)))
364
365#else
366#define IS_IN_ACPI_TABLE(a,b)           (_segment)(a) == (_segment)(b) &&\
367                                        (((UINT8 *)(a) >= (UINT8 *)(b + 1)) &&\
368                                        ((UINT8 *)(a) < ((UINT8 *)b + b->Length)))
369#endif
370
371/*
372 * Macros for the master AML opcode table
373 */
374
375#ifdef ACPI_DEBUG
376#define OP_INFO_ENTRY(Flags,Name,PArgs,IArgs)     {Flags,PArgs,IArgs,Name}
377#else
378#define OP_INFO_ENTRY(Flags,Name,PArgs,IArgs)     {Flags,PArgs,IArgs}
379#endif
380
381#define ARG_TYPE_WIDTH                  5
382#define ARG_1(x)                        ((UINT32)(x))
383#define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
384#define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
385#define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
386#define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
387#define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
388
389#define ARGI_LIST1(a)                   (ARG_1(a))
390#define ARGI_LIST2(a,b)                 (ARG_1(b)|ARG_2(a))
391#define ARGI_LIST3(a,b,c)               (ARG_1(c)|ARG_2(b)|ARG_3(a))
392#define ARGI_LIST4(a,b,c,d)             (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
393#define ARGI_LIST5(a,b,c,d,e)           (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
394#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))
395
396#define ARGP_LIST1(a)                   (ARG_1(a))
397#define ARGP_LIST2(a,b)                 (ARG_1(a)|ARG_2(b))
398#define ARGP_LIST3(a,b,c)               (ARG_1(a)|ARG_2(b)|ARG_3(c))
399#define ARGP_LIST4(a,b,c,d)             (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
400#define ARGP_LIST5(a,b,c,d,e)           (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
401#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))
402
403#define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
404#define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
405
406
407/*
408 * Build a GAS structure from earlier ACPI table entries (V1.0 and 0.71 extensions)
409 *
410 * 1) Address space
411 * 2) Length in bytes -- convert to length in bits
412 * 3) Bit offset is zero
413 * 4) Reserved field is zero
414 * 5) Expand address to 64 bits
415 */
416#define ASL_BUILD_GAS_FROM_ENTRY(a,b,c,d)   {a.AddressSpaceId = (UINT8) d;\
417                                             a.RegisterBitWidth = (UINT8) MUL_8 (b);\
418                                             a.RegisterBitOffset = 0;\
419                                             a.Reserved = 0;\
420                                             ACPI_STORE_ADDRESS (a.Address,c);}
421
422/* ACPI V1.0 entries -- address space is always I/O */
423
424#define ASL_BUILD_GAS_FROM_V1_ENTRY(a,b,c)  ASL_BUILD_GAS_FROM_ENTRY(a,b,c,ACPI_ADR_SPACE_SYSTEM_IO)
425
426
427/*
428 * Reporting macros that are never compiled out
429 */
430
431#define PARAM_LIST(pl)                  pl
432
433/*
434 * Error reporting.  These versions add callers module and line#.  Since
435 * _THIS_MODULE gets compiled out when ACPI_DEBUG isn't defined, only
436 * use it in debug mode.
437 */
438
439#ifdef ACPI_DEBUG
440
441#define REPORT_INFO(fp)                 {_ReportInfo(_THIS_MODULE,__LINE__,_COMPONENT); \
442                                            DebugPrintRaw PARAM_LIST(fp);}
443#define REPORT_ERROR(fp)                {_ReportError(_THIS_MODULE,__LINE__,_COMPONENT); \
444                                            DebugPrintRaw PARAM_LIST(fp);}
445#define REPORT_WARNING(fp)              {_ReportWarning(_THIS_MODULE,__LINE__,_COMPONENT); \
446                                            DebugPrintRaw PARAM_LIST(fp);}
447
448#else
449
450#define REPORT_INFO(fp)                 {_ReportInfo("ACPI",__LINE__,_COMPONENT); \
451                                            DebugPrintRaw PARAM_LIST(fp);}
452#define REPORT_ERROR(fp)                {_ReportError("ACPI",__LINE__,_COMPONENT); \
453                                            DebugPrintRaw PARAM_LIST(fp);}
454#define REPORT_WARNING(fp)              {_ReportWarning("ACPI",__LINE__,_COMPONENT); \
455                                            DebugPrintRaw PARAM_LIST(fp);}
456
457#endif
458
459/* Error reporting.  These versions pass thru the module and line# */
460
461#define _REPORT_INFO(a,b,c,fp)          {_ReportInfo(a,b,c); \
462                                            DebugPrintRaw PARAM_LIST(fp);}
463#define _REPORT_ERROR(a,b,c,fp)         {_ReportError(a,b,c); \
464                                            DebugPrintRaw PARAM_LIST(fp);}
465#define _REPORT_WARNING(a,b,c,fp)       {_ReportWarning(a,b,c); \
466                                            DebugPrintRaw PARAM_LIST(fp);}
467
468/* Buffer dump macros */
469
470#define DUMP_BUFFER(a,b)                AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
471
472/*
473 * Debug macros that are conditionally compiled
474 */
475
476#ifdef ACPI_DEBUG
477
478#define MODULE_NAME(name)               static char *_THIS_MODULE = name;
479
480/*
481 * Function entry tracing.
482 * The first parameter should be the procedure name as a quoted string.  This is declared
483 * as a local string ("_ProcName) so that it can be also used by the function exit macros below.
484 */
485
486#define PROC_NAME(a)                    char * _ProcName = a;
487#define FUNCTION_TRACE(a)               char * _ProcName = a;\
488                                        FunctionTrace(_THIS_MODULE,__LINE__,_COMPONENT,a)
489#define FUNCTION_TRACE_PTR(a,b)         char * _ProcName = a;\
490                                        FunctionTracePtr(_THIS_MODULE,__LINE__,_COMPONENT,a,(void *)b)
491#define FUNCTION_TRACE_U32(a,b)         char * _ProcName = a;\
492                                        FunctionTraceU32(_THIS_MODULE,__LINE__,_COMPONENT,a,(UINT32)b)
493#define FUNCTION_TRACE_STR(a,b)         char * _ProcName = a;\
494                                        FunctionTraceStr(_THIS_MODULE,__LINE__,_COMPONENT,a,(NATIVE_CHAR *)b)
495/*
496 * Function exit tracing.
497 * WARNING: These macros include a return statement.  This is usually considered
498 * bad form, but having a separate exit macro is very ugly and difficult to maintain.
499 * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
500 * so that "_ProcName" is defined.
501 */
502#define return_VOID                     {FunctionExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName);return;}
503#define return_ACPI_STATUS(s)           {FunctionStatusExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,s);return(s);}
504#define return_VALUE(s)                 {FunctionValueExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,s);return(s);}
505#define return_PTR(s)                   {FunctionPtrExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,(UINT8 *)s);return(s);}
506
507
508/* Conditional execution */
509
510#define DEBUG_EXEC(a)                   a
511#define NORMAL_EXEC(a)
512
513#define DEBUG_DEFINE(a)                 a;
514#define DEBUG_ONLY_MEMBERS(a)           a;
515#define _OPCODE_NAMES
516#define _VERBOSE_STRUCTURES
517
518
519/* Stack and buffer dumping */
520
521#define DUMP_STACK_ENTRY(a)             AcpiExDumpOperand(a)
522#define DUMP_OPERANDS(a,b,c,d,e)        AcpiExDumpOperands(a,b,c,d,e,_THIS_MODULE,__LINE__)
523
524
525#define DUMP_ENTRY(a,b)                 AcpiNsDumpEntry (a,b)
526#define DUMP_TABLES(a,b)                AcpiNsDumpTables(a,b)
527#define DUMP_PATHNAME(a,b,c,d)          AcpiNsDumpPathname(a,b,c,d)
528#define DUMP_RESOURCE_LIST(a)           AcpiRsDumpResourceList(a)
529#define BREAK_MSG(a)                    AcpiOsBreakpoint (a)
530
531/*
532 * Generate INT3 on ACPI_ERROR (Debug only!)
533 */
534
535#define ERROR_BREAK
536#ifdef  ERROR_BREAK
537#define BREAK_ON_ERROR(lvl)             if ((lvl)&ACPI_ERROR) AcpiOsBreakpoint("Fatal error encountered\n")
538#else
539#define BREAK_ON_ERROR(lvl)
540#endif
541
542/*
543 * Master debug print macros
544 * Print iff:
545 *    1) Debug print for the current component is enabled
546 *    2) Debug error level or trace level for the print statement is enabled
547 *
548 */
549
550#define TEST_DEBUG_SWITCH(lvl)          if (((lvl) & AcpiDbgLevel) && (_COMPONENT & AcpiDbgLayer))
551
552#define DEBUG_PRINT(lvl,fp)             TEST_DEBUG_SWITCH(lvl) {\
553                                            DebugPrintPrefix (_THIS_MODULE,__LINE__);\
554                                            DebugPrintRaw PARAM_LIST(fp);\
555                                            BREAK_ON_ERROR(lvl);}
556
557#define DEBUG_PRINTP(lvl,fp)            TEST_DEBUG_SWITCH(lvl) {\
558                                            DebugPrintPrefix (_THIS_MODULE,__LINE__);\
559                                            DebugPrintRaw ("%s: ",_ProcName);\
560                                            DebugPrintRaw PARAM_LIST(fp);\
561                                            BREAK_ON_ERROR(lvl);}
562
563#define DEBUG_PRINT_RAW(lvl,fp)         TEST_DEBUG_SWITCH(lvl) {\
564                                            DebugPrintRaw PARAM_LIST(fp);}
565
566
567/* Assert macros */
568
569#define ACPI_ASSERT(exp)                if(!(exp)) \
570                                            AcpiOsDbgAssert(#exp, __FILE__, __LINE__, "Failed Assertion")
571
572#define DEBUG_ASSERT(msg, exp)          if(!(exp)) \
573                                            AcpiOsDbgAssert(#exp, __FILE__, __LINE__, msg)
574
575
576#else
577/*
578 * This is the non-debug case -- make everything go away,
579 * leaving no executable debug code!
580 */
581
582#define MODULE_NAME(name)
583#define _THIS_MODULE ""
584
585#define DEBUG_EXEC(a)
586#define NORMAL_EXEC(a)                  a;
587
588#define DEBUG_DEFINE(a)
589#define DEBUG_ONLY_MEMBERS(a)
590#define PROC_NAME(a)
591#define FUNCTION_TRACE(a)
592#define FUNCTION_TRACE_PTR(a,b)
593#define FUNCTION_TRACE_U32(a,b)
594#define FUNCTION_TRACE_STR(a,b)
595#define FUNCTION_EXIT
596#define FUNCTION_STATUS_EXIT(s)
597#define FUNCTION_VALUE_EXIT(s)
598#define DUMP_STACK_ENTRY(a)
599#define DUMP_OPERANDS(a,b,c,d,e)
600#define DUMP_ENTRY(a,b)
601#define DUMP_TABLES(a,b)
602#define DUMP_PATHNAME(a,b,c,d)
603#define DUMP_RESOURCE_LIST(a)
604#define DEBUG_PRINT(l,f)
605#define DEBUG_PRINTP(l,f)
606#define DEBUG_PRINT_RAW(l,f)
607#define BREAK_MSG(a)
608
609#define return_VOID                     return
610#define return_ACPI_STATUS(s)           return(s)
611#define return_VALUE(s)                 return(s)
612#define return_PTR(s)                   return(s)
613
614#define ACPI_ASSERT(exp)
615#define DEBUG_ASSERT(msg, exp)
616
617#endif
618
619/*
620 * Some code only gets executed when the debugger is built in.
621 * Note that this is entirely independent of whether the
622 * DEBUG_PRINT stuff (set by ACPI_DEBUG) is on, or not.
623 */
624#ifdef ENABLE_DEBUGGER
625#define DEBUGGER_EXEC(a)                a
626#else
627#define DEBUGGER_EXEC(a)
628#endif
629
630
631/*
632 * For 16-bit code, we want to shrink some things even though
633 * we are using ACPI_DEBUG to get the debug output
634 */
635#ifdef _IA16
636#undef DEBUG_ONLY_MEMBERS
637#undef _VERBOSE_STRUCTURES
638#define DEBUG_ONLY_MEMBERS(a)
639#endif
640
641
642#ifdef ACPI_DEBUG
643
644/*
645 * 1) Set name to blanks
646 * 2) Copy the object name
647 */
648
649#define ADD_OBJECT_NAME(a,b)            MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\
650                                        STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name))
651
652#else
653
654#define ADD_OBJECT_NAME(a,b)
655
656#endif
657
658
659/*
660 * Memory allocation tracking (DEBUG ONLY)
661 */
662
663#ifndef ACPI_DEBUG_TRACK_ALLOCATIONS
664
665#define AcpiUtAddElementToAllocList(a,b,c,d,e,f)
666#define AcpiUtDeleteElementFromAllocList(a,b,c,d)
667#define AcpiUtDumpCurrentAllocations(a,b)
668#define AcpiUtDumpAllocationInfo()
669
670#define DECREMENT_OBJECT_METRICS(a)
671#define INCREMENT_OBJECT_METRICS(a)
672#define INITIALIZE_ALLOCATION_METRICS()
673#define DECREMENT_NAME_TABLE_METRICS(a)
674#define INCREMENT_NAME_TABLE_METRICS(a)
675
676#else
677
678#define INITIALIZE_ALLOCATION_METRICS() \
679    AcpiGbl_CurrentObjectCount = 0; \
680    AcpiGbl_CurrentObjectSize = 0; \
681    AcpiGbl_RunningObjectCount = 0; \
682    AcpiGbl_RunningObjectSize = 0; \
683    AcpiGbl_MaxConcurrentObjectCount = 0; \
684    AcpiGbl_MaxConcurrentObjectSize = 0; \
685    AcpiGbl_CurrentAllocSize = 0; \
686    AcpiGbl_CurrentAllocCount = 0; \
687    AcpiGbl_RunningAllocSize = 0; \
688    AcpiGbl_RunningAllocCount = 0; \
689    AcpiGbl_MaxConcurrentAllocSize = 0; \
690    AcpiGbl_MaxConcurrentAllocCount = 0; \
691    AcpiGbl_CurrentNodeCount = 0; \
692    AcpiGbl_CurrentNodeSize = 0; \
693    AcpiGbl_MaxConcurrentNodeCount = 0
694
695
696#define DECREMENT_OBJECT_METRICS(a) \
697    AcpiGbl_CurrentObjectCount--; \
698    AcpiGbl_CurrentObjectSize -= a
699
700#define INCREMENT_OBJECT_METRICS(a) \
701    AcpiGbl_CurrentObjectCount++; \
702    AcpiGbl_RunningObjectCount++; \
703    if (AcpiGbl_MaxConcurrentObjectCount < AcpiGbl_CurrentObjectCount) \
704    { \
705        AcpiGbl_MaxConcurrentObjectCount = AcpiGbl_CurrentObjectCount; \
706    } \
707    AcpiGbl_RunningObjectSize += a; \
708    AcpiGbl_CurrentObjectSize += a; \
709    if (AcpiGbl_MaxConcurrentObjectSize < AcpiGbl_CurrentObjectSize) \
710    { \
711        AcpiGbl_MaxConcurrentObjectSize = AcpiGbl_CurrentObjectSize; \
712    }
713
714#define DECREMENT_NAME_TABLE_METRICS(a) \
715    AcpiGbl_CurrentNodeCount--; \
716    AcpiGbl_CurrentNodeSize -= (a)
717
718#define INCREMENT_NAME_TABLE_METRICS(a) \
719    AcpiGbl_CurrentNodeCount++; \
720    AcpiGbl_CurrentNodeSize+= (a); \
721    if (AcpiGbl_MaxConcurrentNodeCount < AcpiGbl_CurrentNodeCount) \
722    { \
723        AcpiGbl_MaxConcurrentNodeCount = AcpiGbl_CurrentNodeCount; \
724    }
725#endif /* ACPI_DEBUG_TRACK_ALLOCATIONS */
726
727
728#endif /* ACMACROS_H */
729