Deleted Added
full compact
acmacros.h (80062) acmacros.h (82367)
1/******************************************************************************
2 *
3 * Name: acmacros.h - C macros for the entire subsystem.
1/******************************************************************************
2 *
3 * Name: acmacros.h - C macros for the entire subsystem.
4 * $Revision: 80 $
4 * $Revision: 86 $
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/*
122 * Data manipulation macros
123 */
124
125#ifndef LOWORD
126#define LOWORD(l) ((UINT16)(NATIVE_UINT)(l))
127#endif
128
129#ifndef HIWORD
130#define HIWORD(l) ((UINT16)((((NATIVE_UINT)(l)) >> 16) & 0xFFFF))
131#endif
132
133#ifndef LOBYTE
134#define LOBYTE(l) ((UINT8)(UINT16)(l))
135#endif
136
137#ifndef HIBYTE
138#define HIBYTE(l) ((UINT8)((((UINT16)(l)) >> 8) & 0xFF))
139#endif
140
141#define BIT0(x) ((((x) & 0x01) > 0) ? 1 : 0)
142#define BIT1(x) ((((x) & 0x02) > 0) ? 1 : 0)
143#define BIT2(x) ((((x) & 0x04) > 0) ? 1 : 0)
144
145#define BIT3(x) ((((x) & 0x08) > 0) ? 1 : 0)
146#define BIT4(x) ((((x) & 0x10) > 0) ? 1 : 0)
147#define BIT5(x) ((((x) & 0x20) > 0) ? 1 : 0)
148#define BIT6(x) ((((x) & 0x40) > 0) ? 1 : 0)
149#define BIT7(x) ((((x) & 0x80) > 0) ? 1 : 0)
150
151#define LOW_BASE(w) ((UINT16) ((w) & 0x0000FFFF))
152#define MID_BASE(b) ((UINT8) (((b) & 0x00FF0000) >> 16))
153#define HI_BASE(b) ((UINT8) (((b) & 0xFF000000) >> 24))
154#define LOW_LIMIT(w) ((UINT16) ((w) & 0x0000FFFF))
155#define HI_LIMIT(b) ((UINT8) (((b) & 0x00FF0000) >> 16))
156
157
158#ifdef _IA16
159/*
160 * For 16-bit addresses, we have to assume that the upper 32 bits
161 * are zero.
162 */
163#ifndef LODWORD
164#define LODWORD(l) (l)
165#endif
166
167#ifndef HIDWORD
168#define HIDWORD(l) (0)
169#endif
170
171#define ACPI_GET_ADDRESS(a) ((a).Lo)
172#define ACPI_STORE_ADDRESS(a,b) {(a).Hi=0;(a).Lo=(b);}
173#define ACPI_VALID_ADDRESS(a) ((a).Hi | (a).Lo)
174
175#else
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/*
122 * Data manipulation macros
123 */
124
125#ifndef LOWORD
126#define LOWORD(l) ((UINT16)(NATIVE_UINT)(l))
127#endif
128
129#ifndef HIWORD
130#define HIWORD(l) ((UINT16)((((NATIVE_UINT)(l)) >> 16) & 0xFFFF))
131#endif
132
133#ifndef LOBYTE
134#define LOBYTE(l) ((UINT8)(UINT16)(l))
135#endif
136
137#ifndef HIBYTE
138#define HIBYTE(l) ((UINT8)((((UINT16)(l)) >> 8) & 0xFF))
139#endif
140
141#define BIT0(x) ((((x) & 0x01) > 0) ? 1 : 0)
142#define BIT1(x) ((((x) & 0x02) > 0) ? 1 : 0)
143#define BIT2(x) ((((x) & 0x04) > 0) ? 1 : 0)
144
145#define BIT3(x) ((((x) & 0x08) > 0) ? 1 : 0)
146#define BIT4(x) ((((x) & 0x10) > 0) ? 1 : 0)
147#define BIT5(x) ((((x) & 0x20) > 0) ? 1 : 0)
148#define BIT6(x) ((((x) & 0x40) > 0) ? 1 : 0)
149#define BIT7(x) ((((x) & 0x80) > 0) ? 1 : 0)
150
151#define LOW_BASE(w) ((UINT16) ((w) & 0x0000FFFF))
152#define MID_BASE(b) ((UINT8) (((b) & 0x00FF0000) >> 16))
153#define HI_BASE(b) ((UINT8) (((b) & 0xFF000000) >> 24))
154#define LOW_LIMIT(w) ((UINT16) ((w) & 0x0000FFFF))
155#define HI_LIMIT(b) ((UINT8) (((b) & 0x00FF0000) >> 16))
156
157
158#ifdef _IA16
159/*
160 * For 16-bit addresses, we have to assume that the upper 32 bits
161 * are zero.
162 */
163#ifndef LODWORD
164#define LODWORD(l) (l)
165#endif
166
167#ifndef HIDWORD
168#define HIDWORD(l) (0)
169#endif
170
171#define ACPI_GET_ADDRESS(a) ((a).Lo)
172#define ACPI_STORE_ADDRESS(a,b) {(a).Hi=0;(a).Lo=(b);}
173#define ACPI_VALID_ADDRESS(a) ((a).Hi | (a).Lo)
174
175#else
176#ifdef ACPI_NO_INTEGER64_SUPPORT
176/*
177/*
177 * Full 64-bit address on 32-bit and 64-bit platforms
178 * ACPI_INTEGER is 32-bits, no 64-bit support on this platform
178 */
179#ifndef LODWORD
179 */
180#ifndef LODWORD
181#define LODWORD(l) ((UINT32)(l))
182#endif
183
184#ifndef HIDWORD
185#define HIDWORD(l) (0)
186#endif
187
188#define ACPI_GET_ADDRESS(a) (a)
189#define ACPI_STORE_ADDRESS(a,b) ((a)=(b))
190#define ACPI_VALID_ADDRESS(a) (a)
191
192#else
193
194/*
195 * Full 64-bit address/integer on both 32-bit and 64-bit platforms
196 */
197#ifndef LODWORD
180#define LODWORD(l) ((UINT32)(UINT64)(l))
181#endif
182
183#ifndef HIDWORD
198#define LODWORD(l) ((UINT32)(UINT64)(l))
199#endif
200
201#ifndef HIDWORD
184#define HIDWORD(l) ((UINT32)((((UINT64)(l)) >> 32) & 0xFFFFFFFF))
202#define HIDWORD(l) ((UINT32)(((*(UINT64_STRUCT *)(&l))).Hi))
185#endif
186
187#define ACPI_GET_ADDRESS(a) (a)
188#define ACPI_STORE_ADDRESS(a,b) ((a)=(b))
189#define ACPI_VALID_ADDRESS(a) (a)
190#endif
203#endif
204
205#define ACPI_GET_ADDRESS(a) (a)
206#define ACPI_STORE_ADDRESS(a,b) ((a)=(b))
207#define ACPI_VALID_ADDRESS(a) (a)
208#endif
209#endif
191
192 /*
193 * Extract a byte of data using a pointer. Any more than a byte and we
194 * get into potential aligment issues -- see the STORE macros below
195 */
196#define GET8(addr) (*(UINT8*)(addr))
197
198/* Pointer arithmetic */
199
200
201#define POINTER_ADD(t,a,b) (t *) ((NATIVE_UINT)(a) + (NATIVE_UINT)(b))
202#define POINTER_DIFF(a,b) ((UINT32) ((NATIVE_UINT)(a) - (NATIVE_UINT)(b)))
203
204/*
205 * Macros for moving data around to/from buffers that are possibly unaligned.
206 * If the hardware supports the transfer of unaligned data, just do the store.
207 * Otherwise, we have to move one byte at a time.
208 */
209
210#ifdef _HW_ALIGNMENT_SUPPORT
211
212/* The hardware supports unaligned transfers, just do the move */
213
214#define MOVE_UNALIGNED16_TO_16(d,s) *(UINT16*)(d) = *(UINT16*)(s)
215#define MOVE_UNALIGNED32_TO_32(d,s) *(UINT32*)(d) = *(UINT32*)(s)
216#define MOVE_UNALIGNED16_TO_32(d,s) *(UINT32*)(d) = *(UINT16*)(s)
217#define MOVE_UNALIGNED64_TO_64(d,s) *(UINT64*)(d) = *(UINT64*)(s)
218
219#else
220/*
221 * The hardware does not support unaligned transfers. We must move the
222 * data one byte at a time. These macros work whether the source or
223 * the destination (or both) is/are unaligned.
224 */
225
226#define MOVE_UNALIGNED16_TO_16(d,s) {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
227 ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];}
228
229#define MOVE_UNALIGNED32_TO_32(d,s) {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
230 ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];\
231 ((UINT8 *)(d))[2] = ((UINT8 *)(s))[2];\
232 ((UINT8 *)(d))[3] = ((UINT8 *)(s))[3];}
233
234#define MOVE_UNALIGNED16_TO_32(d,s) {(*(UINT32*)(d)) = 0; MOVE_UNALIGNED16_TO_16(d,s);}
235
236#define MOVE_UNALIGNED64_TO_64(d,s) {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
237 ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];\
238 ((UINT8 *)(d))[2] = ((UINT8 *)(s))[2];\
239 ((UINT8 *)(d))[3] = ((UINT8 *)(s))[3];\
240 ((UINT8 *)(d))[4] = ((UINT8 *)(s))[4];\
241 ((UINT8 *)(d))[5] = ((UINT8 *)(s))[5];\
242 ((UINT8 *)(d))[6] = ((UINT8 *)(s))[6];\
243 ((UINT8 *)(d))[7] = ((UINT8 *)(s))[7];}
244
245#endif
246
247
248/*
249 * Fast power-of-two math macros for non-optimized compilers
250 */
251
252#define _DIV(value,PowerOf2) ((UINT32) ((value) >> (PowerOf2)))
253#define _MUL(value,PowerOf2) ((UINT32) ((value) << (PowerOf2)))
254#define _MOD(value,Divisor) ((UINT32) ((value) & ((Divisor) -1)))
255
256#define DIV_2(a) _DIV(a,1)
257#define MUL_2(a) _MUL(a,1)
258#define MOD_2(a) _MOD(a,2)
259
260#define DIV_4(a) _DIV(a,2)
261#define MUL_4(a) _MUL(a,2)
262#define MOD_4(a) _MOD(a,4)
263
264#define DIV_8(a) _DIV(a,3)
265#define MUL_8(a) _MUL(a,3)
266#define MOD_8(a) _MOD(a,8)
267
268#define DIV_16(a) _DIV(a,4)
269#define MUL_16(a) _MUL(a,4)
270#define MOD_16(a) _MOD(a,16)
271
272/*
273 * Divide and Modulo
274 */
275#define ACPI_DIVIDE(n,d) ((n) / (d))
276#define ACPI_MODULO(n,d) ((n) % (d))
277
278/*
279 * Rounding macros (Power of two boundaries only)
280 */
281#define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
282#define ROUND_UP(value,boundary) (((value) + ((boundary)-1)) & (~((boundary)-1)))
283
284#define ROUND_DOWN_TO_32_BITS(a) ROUND_DOWN(a,4)
285#define ROUND_DOWN_TO_64_BITS(a) ROUND_DOWN(a,8)
286#define ROUND_DOWN_TO_NATIVE_WORD(a) ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
287
288#define ROUND_UP_TO_32BITS(a) ROUND_UP(a,4)
289#define ROUND_UP_TO_64BITS(a) ROUND_UP(a,8)
290#define ROUND_UP_TO_NATIVE_WORD(a) ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
291
292#define ROUND_PTR_UP_TO_4(a,b) ((b *)(((NATIVE_UINT)(a) + 3) & ~3))
293#define ROUND_PTR_UP_TO_8(a,b) ((b *)(((NATIVE_UINT)(a) + 7) & ~7))
294
295#define ROUND_BITS_UP_TO_BYTES(a) DIV_8((a) + 7)
296#define ROUND_BITS_DOWN_TO_BYTES(a) DIV_8((a))
297
298#define ROUND_UP_TO_1K(a) (((a) + 1023) >> 10)
299
300/* Generic (non-power-of-two) rounding */
301
302#define ROUND_UP_TO(value,boundary) (((value) + ((boundary)-1)) / (boundary))
303
304/*
305 * Bitmask creation
306 * Bit positions start at zero.
307 * MASK_BITS_ABOVE creates a mask starting AT the position and above
308 * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
309 */
310#define MASK_BITS_ABOVE(position) (~(((UINT32)(-1)) << ((UINT32) (position))))
311#define MASK_BITS_BELOW(position) (((UINT32)(-1)) << ((UINT32) (position)))
312
313
314
315/* Macros for GAS addressing */
316
317#ifndef _IA16
318
319#define ACPI_PCI_DEVICE_MASK (UINT64) 0x0000FFFF00000000
320#define ACPI_PCI_FUNCTION_MASK (UINT64) 0x00000000FFFF0000
321#define ACPI_PCI_REGISTER_MASK (UINT64) 0x000000000000FFFF
322
323#define ACPI_PCI_FUNCTION(a) (UINT16) ((((a) & ACPI_PCI_FUNCTION_MASK) >> 16))
324#define ACPI_PCI_DEVICE(a) (UINT16) ((((a) & ACPI_PCI_DEVICE_MASK) >> 32))
325#define ACPI_PCI_REGISTER(a) (UINT16) (((a) & ACPI_PCI_REGISTER_MASK))
326
327#else
328
329/* No support for GAS and PCI IDs in 16-bit mode */
330
331#define ACPI_PCI_FUNCTION(a) (UINT16) ((a) & 0xFFFF0000)
332#define ACPI_PCI_DEVICE(a) (UINT16) ((a) & 0x0000FFFF)
333#define ACPI_PCI_REGISTER(a) (UINT16) ((a) & 0x0000FFFF)
334
335#endif
336
337/*
338 * An ACPI_HANDLE (which is actually an ACPI_NAMESPACE_NODE *) can appear in some contexts,
339 * such as on apObjStack, where a pointer to an ACPI_OPERAND_OBJECT can also
340 * appear. This macro is used to distinguish them.
341 *
342 * The DataType field is the first field in both structures.
343 */
344#define VALID_DESCRIPTOR_TYPE(d,t) (((ACPI_NAMESPACE_NODE *)d)->DataType == t)
345
346
347/* Macro to test the object type */
348
349#define IS_THIS_OBJECT_TYPE(d,t) (((ACPI_OPERAND_OBJECT *)d)->Common.Type == (UINT8)t)
350
351/* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
352
353#define IS_SINGLE_TABLE(x) (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
354
355/* Check if ACPI has been initialized properly */
356
357#define ACPI_IS_INITIALIZATION_COMPLETE(s) {if (AcpiGbl_RootNode) s = AE_OK; else s=AE_NO_NAMESPACE;}
358
359/*
360 * Macro to check if a pointer is within an ACPI table.
361 * Parameter (a) is the pointer to check. Parameter (b) must be defined
362 * as a pointer to an ACPI_TABLE_HEADER. (b+1) then points past the header,
363 * and ((UINT8 *)b+b->Length) points one byte past the end of the table.
364 */
365#ifndef _IA16
366#define IS_IN_ACPI_TABLE(a,b) (((UINT8 *)(a) >= (UINT8 *)(b + 1)) &&\
367 ((UINT8 *)(a) < ((UINT8 *)b + b->Length)))
368
369#else
370#define IS_IN_ACPI_TABLE(a,b) (_segment)(a) == (_segment)(b) &&\
371 (((UINT8 *)(a) >= (UINT8 *)(b + 1)) &&\
372 ((UINT8 *)(a) < ((UINT8 *)b + b->Length)))
373#endif
374
375/*
376 * Macros for the master AML opcode table
377 */
378#ifdef ACPI_DEBUG
379#define OP_INFO_ENTRY(Flags,Name,PArgs,IArgs) {Flags,PArgs,IArgs,Name}
380#else
381#define OP_INFO_ENTRY(Flags,Name,PArgs,IArgs) {Flags,PArgs,IArgs}
382#endif
383
384#define ARG_TYPE_WIDTH 5
385#define ARG_1(x) ((UINT32)(x))
386#define ARG_2(x) ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
387#define ARG_3(x) ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
388#define ARG_4(x) ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
389#define ARG_5(x) ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
390#define ARG_6(x) ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
391
392#define ARGI_LIST1(a) (ARG_1(a))
393#define ARGI_LIST2(a,b) (ARG_1(b)|ARG_2(a))
394#define ARGI_LIST3(a,b,c) (ARG_1(c)|ARG_2(b)|ARG_3(a))
395#define ARGI_LIST4(a,b,c,d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
396#define ARGI_LIST5(a,b,c,d,e) (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
397#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))
398
399#define ARGP_LIST1(a) (ARG_1(a))
400#define ARGP_LIST2(a,b) (ARG_1(a)|ARG_2(b))
401#define ARGP_LIST3(a,b,c) (ARG_1(a)|ARG_2(b)|ARG_3(c))
402#define ARGP_LIST4(a,b,c,d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
403#define ARGP_LIST5(a,b,c,d,e) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
404#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))
405
406#define GET_CURRENT_ARG_TYPE(List) (List & ((UINT32) 0x1F))
407#define INCREMENT_ARG_LIST(List) (List >>= ((UINT32) ARG_TYPE_WIDTH))
408
409
410/*
411 * Build a GAS structure from earlier ACPI table entries (V1.0 and 0.71 extensions)
412 *
413 * 1) Address space
414 * 2) Length in bytes -- convert to length in bits
415 * 3) Bit offset is zero
416 * 4) Reserved field is zero
417 * 5) Expand address to 64 bits
418 */
419#define ASL_BUILD_GAS_FROM_ENTRY(a,b,c,d) {a.AddressSpaceId = (UINT8) d;\
420 a.RegisterBitWidth = (UINT8) MUL_8 (b);\
421 a.RegisterBitOffset = 0;\
422 a.Reserved = 0;\
423 ACPI_STORE_ADDRESS (a.Address,c);}
424
425/* ACPI V1.0 entries -- address space is always I/O */
426
427#define ASL_BUILD_GAS_FROM_V1_ENTRY(a,b,c) ASL_BUILD_GAS_FROM_ENTRY(a,b,c,ACPI_ADR_SPACE_SYSTEM_IO)
428
429
430/*
431 * Reporting macros that are never compiled out
432 */
433
434#define PARAM_LIST(pl) pl
435
436/*
437 * Error reporting. These versions add callers module and line#. Since
438 * _THIS_MODULE gets compiled out when ACPI_DEBUG isn't defined, only
439 * use it in debug mode.
440 */
441
442#ifdef ACPI_DEBUG
443
444#define REPORT_INFO(fp) {_ReportInfo(_THIS_MODULE,__LINE__,_COMPONENT); \
210
211 /*
212 * Extract a byte of data using a pointer. Any more than a byte and we
213 * get into potential aligment issues -- see the STORE macros below
214 */
215#define GET8(addr) (*(UINT8*)(addr))
216
217/* Pointer arithmetic */
218
219
220#define POINTER_ADD(t,a,b) (t *) ((NATIVE_UINT)(a) + (NATIVE_UINT)(b))
221#define POINTER_DIFF(a,b) ((UINT32) ((NATIVE_UINT)(a) - (NATIVE_UINT)(b)))
222
223/*
224 * Macros for moving data around to/from buffers that are possibly unaligned.
225 * If the hardware supports the transfer of unaligned data, just do the store.
226 * Otherwise, we have to move one byte at a time.
227 */
228
229#ifdef _HW_ALIGNMENT_SUPPORT
230
231/* The hardware supports unaligned transfers, just do the move */
232
233#define MOVE_UNALIGNED16_TO_16(d,s) *(UINT16*)(d) = *(UINT16*)(s)
234#define MOVE_UNALIGNED32_TO_32(d,s) *(UINT32*)(d) = *(UINT32*)(s)
235#define MOVE_UNALIGNED16_TO_32(d,s) *(UINT32*)(d) = *(UINT16*)(s)
236#define MOVE_UNALIGNED64_TO_64(d,s) *(UINT64*)(d) = *(UINT64*)(s)
237
238#else
239/*
240 * The hardware does not support unaligned transfers. We must move the
241 * data one byte at a time. These macros work whether the source or
242 * the destination (or both) is/are unaligned.
243 */
244
245#define MOVE_UNALIGNED16_TO_16(d,s) {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
246 ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];}
247
248#define MOVE_UNALIGNED32_TO_32(d,s) {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
249 ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];\
250 ((UINT8 *)(d))[2] = ((UINT8 *)(s))[2];\
251 ((UINT8 *)(d))[3] = ((UINT8 *)(s))[3];}
252
253#define MOVE_UNALIGNED16_TO_32(d,s) {(*(UINT32*)(d)) = 0; MOVE_UNALIGNED16_TO_16(d,s);}
254
255#define MOVE_UNALIGNED64_TO_64(d,s) {((UINT8 *)(d))[0] = ((UINT8 *)(s))[0];\
256 ((UINT8 *)(d))[1] = ((UINT8 *)(s))[1];\
257 ((UINT8 *)(d))[2] = ((UINT8 *)(s))[2];\
258 ((UINT8 *)(d))[3] = ((UINT8 *)(s))[3];\
259 ((UINT8 *)(d))[4] = ((UINT8 *)(s))[4];\
260 ((UINT8 *)(d))[5] = ((UINT8 *)(s))[5];\
261 ((UINT8 *)(d))[6] = ((UINT8 *)(s))[6];\
262 ((UINT8 *)(d))[7] = ((UINT8 *)(s))[7];}
263
264#endif
265
266
267/*
268 * Fast power-of-two math macros for non-optimized compilers
269 */
270
271#define _DIV(value,PowerOf2) ((UINT32) ((value) >> (PowerOf2)))
272#define _MUL(value,PowerOf2) ((UINT32) ((value) << (PowerOf2)))
273#define _MOD(value,Divisor) ((UINT32) ((value) & ((Divisor) -1)))
274
275#define DIV_2(a) _DIV(a,1)
276#define MUL_2(a) _MUL(a,1)
277#define MOD_2(a) _MOD(a,2)
278
279#define DIV_4(a) _DIV(a,2)
280#define MUL_4(a) _MUL(a,2)
281#define MOD_4(a) _MOD(a,4)
282
283#define DIV_8(a) _DIV(a,3)
284#define MUL_8(a) _MUL(a,3)
285#define MOD_8(a) _MOD(a,8)
286
287#define DIV_16(a) _DIV(a,4)
288#define MUL_16(a) _MUL(a,4)
289#define MOD_16(a) _MOD(a,16)
290
291/*
292 * Divide and Modulo
293 */
294#define ACPI_DIVIDE(n,d) ((n) / (d))
295#define ACPI_MODULO(n,d) ((n) % (d))
296
297/*
298 * Rounding macros (Power of two boundaries only)
299 */
300#define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
301#define ROUND_UP(value,boundary) (((value) + ((boundary)-1)) & (~((boundary)-1)))
302
303#define ROUND_DOWN_TO_32_BITS(a) ROUND_DOWN(a,4)
304#define ROUND_DOWN_TO_64_BITS(a) ROUND_DOWN(a,8)
305#define ROUND_DOWN_TO_NATIVE_WORD(a) ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
306
307#define ROUND_UP_TO_32BITS(a) ROUND_UP(a,4)
308#define ROUND_UP_TO_64BITS(a) ROUND_UP(a,8)
309#define ROUND_UP_TO_NATIVE_WORD(a) ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
310
311#define ROUND_PTR_UP_TO_4(a,b) ((b *)(((NATIVE_UINT)(a) + 3) & ~3))
312#define ROUND_PTR_UP_TO_8(a,b) ((b *)(((NATIVE_UINT)(a) + 7) & ~7))
313
314#define ROUND_BITS_UP_TO_BYTES(a) DIV_8((a) + 7)
315#define ROUND_BITS_DOWN_TO_BYTES(a) DIV_8((a))
316
317#define ROUND_UP_TO_1K(a) (((a) + 1023) >> 10)
318
319/* Generic (non-power-of-two) rounding */
320
321#define ROUND_UP_TO(value,boundary) (((value) + ((boundary)-1)) / (boundary))
322
323/*
324 * Bitmask creation
325 * Bit positions start at zero.
326 * MASK_BITS_ABOVE creates a mask starting AT the position and above
327 * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
328 */
329#define MASK_BITS_ABOVE(position) (~(((UINT32)(-1)) << ((UINT32) (position))))
330#define MASK_BITS_BELOW(position) (((UINT32)(-1)) << ((UINT32) (position)))
331
332
333
334/* Macros for GAS addressing */
335
336#ifndef _IA16
337
338#define ACPI_PCI_DEVICE_MASK (UINT64) 0x0000FFFF00000000
339#define ACPI_PCI_FUNCTION_MASK (UINT64) 0x00000000FFFF0000
340#define ACPI_PCI_REGISTER_MASK (UINT64) 0x000000000000FFFF
341
342#define ACPI_PCI_FUNCTION(a) (UINT16) ((((a) & ACPI_PCI_FUNCTION_MASK) >> 16))
343#define ACPI_PCI_DEVICE(a) (UINT16) ((((a) & ACPI_PCI_DEVICE_MASK) >> 32))
344#define ACPI_PCI_REGISTER(a) (UINT16) (((a) & ACPI_PCI_REGISTER_MASK))
345
346#else
347
348/* No support for GAS and PCI IDs in 16-bit mode */
349
350#define ACPI_PCI_FUNCTION(a) (UINT16) ((a) & 0xFFFF0000)
351#define ACPI_PCI_DEVICE(a) (UINT16) ((a) & 0x0000FFFF)
352#define ACPI_PCI_REGISTER(a) (UINT16) ((a) & 0x0000FFFF)
353
354#endif
355
356/*
357 * An ACPI_HANDLE (which is actually an ACPI_NAMESPACE_NODE *) can appear in some contexts,
358 * such as on apObjStack, where a pointer to an ACPI_OPERAND_OBJECT can also
359 * appear. This macro is used to distinguish them.
360 *
361 * The DataType field is the first field in both structures.
362 */
363#define VALID_DESCRIPTOR_TYPE(d,t) (((ACPI_NAMESPACE_NODE *)d)->DataType == t)
364
365
366/* Macro to test the object type */
367
368#define IS_THIS_OBJECT_TYPE(d,t) (((ACPI_OPERAND_OBJECT *)d)->Common.Type == (UINT8)t)
369
370/* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
371
372#define IS_SINGLE_TABLE(x) (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
373
374/* Check if ACPI has been initialized properly */
375
376#define ACPI_IS_INITIALIZATION_COMPLETE(s) {if (AcpiGbl_RootNode) s = AE_OK; else s=AE_NO_NAMESPACE;}
377
378/*
379 * Macro to check if a pointer is within an ACPI table.
380 * Parameter (a) is the pointer to check. Parameter (b) must be defined
381 * as a pointer to an ACPI_TABLE_HEADER. (b+1) then points past the header,
382 * and ((UINT8 *)b+b->Length) points one byte past the end of the table.
383 */
384#ifndef _IA16
385#define IS_IN_ACPI_TABLE(a,b) (((UINT8 *)(a) >= (UINT8 *)(b + 1)) &&\
386 ((UINT8 *)(a) < ((UINT8 *)b + b->Length)))
387
388#else
389#define IS_IN_ACPI_TABLE(a,b) (_segment)(a) == (_segment)(b) &&\
390 (((UINT8 *)(a) >= (UINT8 *)(b + 1)) &&\
391 ((UINT8 *)(a) < ((UINT8 *)b + b->Length)))
392#endif
393
394/*
395 * Macros for the master AML opcode table
396 */
397#ifdef ACPI_DEBUG
398#define OP_INFO_ENTRY(Flags,Name,PArgs,IArgs) {Flags,PArgs,IArgs,Name}
399#else
400#define OP_INFO_ENTRY(Flags,Name,PArgs,IArgs) {Flags,PArgs,IArgs}
401#endif
402
403#define ARG_TYPE_WIDTH 5
404#define ARG_1(x) ((UINT32)(x))
405#define ARG_2(x) ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
406#define ARG_3(x) ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
407#define ARG_4(x) ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
408#define ARG_5(x) ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
409#define ARG_6(x) ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
410
411#define ARGI_LIST1(a) (ARG_1(a))
412#define ARGI_LIST2(a,b) (ARG_1(b)|ARG_2(a))
413#define ARGI_LIST3(a,b,c) (ARG_1(c)|ARG_2(b)|ARG_3(a))
414#define ARGI_LIST4(a,b,c,d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
415#define ARGI_LIST5(a,b,c,d,e) (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
416#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))
417
418#define ARGP_LIST1(a) (ARG_1(a))
419#define ARGP_LIST2(a,b) (ARG_1(a)|ARG_2(b))
420#define ARGP_LIST3(a,b,c) (ARG_1(a)|ARG_2(b)|ARG_3(c))
421#define ARGP_LIST4(a,b,c,d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
422#define ARGP_LIST5(a,b,c,d,e) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
423#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))
424
425#define GET_CURRENT_ARG_TYPE(List) (List & ((UINT32) 0x1F))
426#define INCREMENT_ARG_LIST(List) (List >>= ((UINT32) ARG_TYPE_WIDTH))
427
428
429/*
430 * Build a GAS structure from earlier ACPI table entries (V1.0 and 0.71 extensions)
431 *
432 * 1) Address space
433 * 2) Length in bytes -- convert to length in bits
434 * 3) Bit offset is zero
435 * 4) Reserved field is zero
436 * 5) Expand address to 64 bits
437 */
438#define ASL_BUILD_GAS_FROM_ENTRY(a,b,c,d) {a.AddressSpaceId = (UINT8) d;\
439 a.RegisterBitWidth = (UINT8) MUL_8 (b);\
440 a.RegisterBitOffset = 0;\
441 a.Reserved = 0;\
442 ACPI_STORE_ADDRESS (a.Address,c);}
443
444/* ACPI V1.0 entries -- address space is always I/O */
445
446#define ASL_BUILD_GAS_FROM_V1_ENTRY(a,b,c) ASL_BUILD_GAS_FROM_ENTRY(a,b,c,ACPI_ADR_SPACE_SYSTEM_IO)
447
448
449/*
450 * Reporting macros that are never compiled out
451 */
452
453#define PARAM_LIST(pl) pl
454
455/*
456 * Error reporting. These versions add callers module and line#. Since
457 * _THIS_MODULE gets compiled out when ACPI_DEBUG isn't defined, only
458 * use it in debug mode.
459 */
460
461#ifdef ACPI_DEBUG
462
463#define REPORT_INFO(fp) {_ReportInfo(_THIS_MODULE,__LINE__,_COMPONENT); \
445 DebugPrintRaw PARAM_LIST(fp);}
464 AcpiOsPrintf PARAM_LIST(fp);}
446#define REPORT_ERROR(fp) {_ReportError(_THIS_MODULE,__LINE__,_COMPONENT); \
465#define REPORT_ERROR(fp) {_ReportError(_THIS_MODULE,__LINE__,_COMPONENT); \
447 DebugPrintRaw PARAM_LIST(fp);}
466 AcpiOsPrintf PARAM_LIST(fp);}
448#define REPORT_WARNING(fp) {_ReportWarning(_THIS_MODULE,__LINE__,_COMPONENT); \
467#define REPORT_WARNING(fp) {_ReportWarning(_THIS_MODULE,__LINE__,_COMPONENT); \
449 DebugPrintRaw PARAM_LIST(fp);}
468 AcpiOsPrintf PARAM_LIST(fp);}
450
451#else
452
453#define REPORT_INFO(fp) {_ReportInfo("ACPI",__LINE__,_COMPONENT); \
469
470#else
471
472#define REPORT_INFO(fp) {_ReportInfo("ACPI",__LINE__,_COMPONENT); \
454 DebugPrintRaw PARAM_LIST(fp);}
473 AcpiOsPrintf PARAM_LIST(fp);}
455#define REPORT_ERROR(fp) {_ReportError("ACPI",__LINE__,_COMPONENT); \
474#define REPORT_ERROR(fp) {_ReportError("ACPI",__LINE__,_COMPONENT); \
456 DebugPrintRaw PARAM_LIST(fp);}
475 AcpiOsPrintf PARAM_LIST(fp);}
457#define REPORT_WARNING(fp) {_ReportWarning("ACPI",__LINE__,_COMPONENT); \
476#define REPORT_WARNING(fp) {_ReportWarning("ACPI",__LINE__,_COMPONENT); \
458 DebugPrintRaw PARAM_LIST(fp);}
477 AcpiOsPrintf PARAM_LIST(fp);}
459
460#endif
461
462/* Error reporting. These versions pass thru the module and line# */
463
464#define _REPORT_INFO(a,b,c,fp) {_ReportInfo(a,b,c); \
478
479#endif
480
481/* Error reporting. These versions pass thru the module and line# */
482
483#define _REPORT_INFO(a,b,c,fp) {_ReportInfo(a,b,c); \
465 DebugPrintRaw PARAM_LIST(fp);}
484 AcpiOsPrintf PARAM_LIST(fp);}
466#define _REPORT_ERROR(a,b,c,fp) {_ReportError(a,b,c); \
485#define _REPORT_ERROR(a,b,c,fp) {_ReportError(a,b,c); \
467 DebugPrintRaw PARAM_LIST(fp);}
486 AcpiOsPrintf PARAM_LIST(fp);}
468#define _REPORT_WARNING(a,b,c,fp) {_ReportWarning(a,b,c); \
487#define _REPORT_WARNING(a,b,c,fp) {_ReportWarning(a,b,c); \
469 DebugPrintRaw PARAM_LIST(fp);}
488 AcpiOsPrintf PARAM_LIST(fp);}
470
471/* Buffer dump macros */
472
473#define DUMP_BUFFER(a,b) AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
474
475/*
476 * Debug macros that are conditionally compiled
477 */
478
479#ifdef ACPI_DEBUG
480
481#define MODULE_NAME(name) static char *_THIS_MODULE = name;
482
483/*
484 * Function entry tracing.
485 * The first parameter should be the procedure name as a quoted string. This is declared
486 * as a local string ("_ProcName) so that it can be also used by the function exit macros below.
487 */
488
489#define PROC_NAME(a) char * _ProcName = a;
490#define FUNCTION_TRACE(a) char * _ProcName = a;\
491 FunctionTrace(_THIS_MODULE,__LINE__,_COMPONENT,a)
492#define FUNCTION_TRACE_PTR(a,b) char * _ProcName = a;\
493 FunctionTracePtr(_THIS_MODULE,__LINE__,_COMPONENT,a,(void *)b)
494#define FUNCTION_TRACE_U32(a,b) char * _ProcName = a;\
495 FunctionTraceU32(_THIS_MODULE,__LINE__,_COMPONENT,a,(UINT32)b)
496#define FUNCTION_TRACE_STR(a,b) char * _ProcName = a;\
497 FunctionTraceStr(_THIS_MODULE,__LINE__,_COMPONENT,a,(NATIVE_CHAR *)b)
498/*
499 * Function exit tracing.
500 * WARNING: These macros include a return statement. This is usually considered
501 * bad form, but having a separate exit macro is very ugly and difficult to maintain.
502 * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
503 * so that "_ProcName" is defined.
504 */
505#define return_VOID {FunctionExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName);return;}
506#define return_ACPI_STATUS(s) {FunctionStatusExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,s);return(s);}
507#define return_VALUE(s) {FunctionValueExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,s);return(s);}
508#define return_PTR(s) {FunctionPtrExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,(UINT8 *)s);return(s);}
509
510
511/* Conditional execution */
512
513#define DEBUG_EXEC(a) a
514#define NORMAL_EXEC(a)
515
516#define DEBUG_DEFINE(a) a;
517#define DEBUG_ONLY_MEMBERS(a) a;
518#define _OPCODE_NAMES
519#define _VERBOSE_STRUCTURES
520
521
522/* Stack and buffer dumping */
523
524#define DUMP_STACK_ENTRY(a) AcpiExDumpOperand(a)
525#define DUMP_OPERANDS(a,b,c,d,e) AcpiExDumpOperands(a,b,c,d,e,_THIS_MODULE,__LINE__)
526
527
528#define DUMP_ENTRY(a,b) AcpiNsDumpEntry (a,b)
529#define DUMP_TABLES(a,b) AcpiNsDumpTables(a,b)
530#define DUMP_PATHNAME(a,b,c,d) AcpiNsDumpPathname(a,b,c,d)
531#define DUMP_RESOURCE_LIST(a) AcpiRsDumpResourceList(a)
532#define BREAK_MSG(a) AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,(a))
533
534
535/*
536 * Generate INT3 on ACPI_ERROR (Debug only!)
537 */
538
539#define ERROR_BREAK
540#ifdef ERROR_BREAK
541#define BREAK_ON_ERROR(lvl) if ((lvl)&ACPI_ERROR) AcpiOsSignal(ACPI_SIGNAL_BREAKPOINT,"Fatal error encountered\n")
542#else
543#define BREAK_ON_ERROR(lvl)
544#endif
545
546/*
547 * Master debug print macros
548 * Print iff:
549 * 1) Debug print for the current component is enabled
550 * 2) Debug error level or trace level for the print statement is enabled
489
490/* Buffer dump macros */
491
492#define DUMP_BUFFER(a,b) AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
493
494/*
495 * Debug macros that are conditionally compiled
496 */
497
498#ifdef ACPI_DEBUG
499
500#define MODULE_NAME(name) static char *_THIS_MODULE = name;
501
502/*
503 * Function entry tracing.
504 * The first parameter should be the procedure name as a quoted string. This is declared
505 * as a local string ("_ProcName) so that it can be also used by the function exit macros below.
506 */
507
508#define PROC_NAME(a) char * _ProcName = a;
509#define FUNCTION_TRACE(a) char * _ProcName = a;\
510 FunctionTrace(_THIS_MODULE,__LINE__,_COMPONENT,a)
511#define FUNCTION_TRACE_PTR(a,b) char * _ProcName = a;\
512 FunctionTracePtr(_THIS_MODULE,__LINE__,_COMPONENT,a,(void *)b)
513#define FUNCTION_TRACE_U32(a,b) char * _ProcName = a;\
514 FunctionTraceU32(_THIS_MODULE,__LINE__,_COMPONENT,a,(UINT32)b)
515#define FUNCTION_TRACE_STR(a,b) char * _ProcName = a;\
516 FunctionTraceStr(_THIS_MODULE,__LINE__,_COMPONENT,a,(NATIVE_CHAR *)b)
517/*
518 * Function exit tracing.
519 * WARNING: These macros include a return statement. This is usually considered
520 * bad form, but having a separate exit macro is very ugly and difficult to maintain.
521 * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
522 * so that "_ProcName" is defined.
523 */
524#define return_VOID {FunctionExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName);return;}
525#define return_ACPI_STATUS(s) {FunctionStatusExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,s);return(s);}
526#define return_VALUE(s) {FunctionValueExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,s);return(s);}
527#define return_PTR(s) {FunctionPtrExit(_THIS_MODULE,__LINE__,_COMPONENT,_ProcName,(UINT8 *)s);return(s);}
528
529
530/* Conditional execution */
531
532#define DEBUG_EXEC(a) a
533#define NORMAL_EXEC(a)
534
535#define DEBUG_DEFINE(a) a;
536#define DEBUG_ONLY_MEMBERS(a) a;
537#define _OPCODE_NAMES
538#define _VERBOSE_STRUCTURES
539
540
541/* Stack and buffer dumping */
542
543#define DUMP_STACK_ENTRY(a) AcpiExDumpOperand(a)
544#define DUMP_OPERANDS(a,b,c,d,e) AcpiExDumpOperands(a,b,c,d,e,_THIS_MODULE,__LINE__)
545
546
547#define DUMP_ENTRY(a,b) AcpiNsDumpEntry (a,b)
548#define DUMP_TABLES(a,b) AcpiNsDumpTables(a,b)
549#define DUMP_PATHNAME(a,b,c,d) AcpiNsDumpPathname(a,b,c,d)
550#define DUMP_RESOURCE_LIST(a) AcpiRsDumpResourceList(a)
551#define BREAK_MSG(a) AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,(a))
552
553
554/*
555 * Generate INT3 on ACPI_ERROR (Debug only!)
556 */
557
558#define ERROR_BREAK
559#ifdef ERROR_BREAK
560#define BREAK_ON_ERROR(lvl) if ((lvl)&ACPI_ERROR) AcpiOsSignal(ACPI_SIGNAL_BREAKPOINT,"Fatal error encountered\n")
561#else
562#define BREAK_ON_ERROR(lvl)
563#endif
564
565/*
566 * Master debug print macros
567 * Print iff:
568 * 1) Debug print for the current component is enabled
569 * 2) Debug error level or trace level for the print statement is enabled
551 *
552 */
553
570 */
571
554#define TEST_DEBUG_SWITCH(lvl) if (((lvl) & AcpiDbgLevel) && (_COMPONENT & AcpiDbgLayer))
572#define ACPI_DEBUG_PRINT(pl) AcpiUtDebugPrint PARAM_LIST(pl)
573#define ACPI_DEBUG_PRINT_RAW(pl) AcpiUtDebugPrintRaw PARAM_LIST(pl)
555
574
556#define DEBUG_PRINT(lvl,fp) TEST_DEBUG_SWITCH(lvl) {\
557 DebugPrintPrefix (_THIS_MODULE,__LINE__);\
558 DebugPrintRaw PARAM_LIST(fp);\
559 BREAK_ON_ERROR(lvl);}
560
575
561#define DEBUG_PRINTP(lvl,fp) TEST_DEBUG_SWITCH(lvl) {\
562 DebugPrintPrefix (_THIS_MODULE,__LINE__);\
563 DebugPrintRaw ("%s: ",_ProcName);\
564 DebugPrintRaw PARAM_LIST(fp);\
565 BREAK_ON_ERROR(lvl);}
566
567#define DEBUG_PRINT_RAW(lvl,fp) TEST_DEBUG_SWITCH(lvl) {\
568 DebugPrintRaw PARAM_LIST(fp);}
569
570#else
571/*
572 * This is the non-debug case -- make everything go away,
573 * leaving no executable debug code!
574 */
575
576#define MODULE_NAME(name)
577#define _THIS_MODULE ""
578
579#define DEBUG_EXEC(a)
580#define NORMAL_EXEC(a) a;
581
582#define DEBUG_DEFINE(a)
583#define DEBUG_ONLY_MEMBERS(a)
584#define PROC_NAME(a)
585#define FUNCTION_TRACE(a)
586#define FUNCTION_TRACE_PTR(a,b)
587#define FUNCTION_TRACE_U32(a,b)
588#define FUNCTION_TRACE_STR(a,b)
589#define FUNCTION_EXIT
590#define FUNCTION_STATUS_EXIT(s)
591#define FUNCTION_VALUE_EXIT(s)
592#define DUMP_STACK_ENTRY(a)
593#define DUMP_OPERANDS(a,b,c,d,e)
594#define DUMP_ENTRY(a,b)
595#define DUMP_TABLES(a,b)
596#define DUMP_PATHNAME(a,b,c,d)
597#define DUMP_RESOURCE_LIST(a)
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)
598#define DEBUG_PRINT(l,f)
599#define DEBUG_PRINTP(l,f)
600#define DEBUG_PRINT_RAW(l,f)
604#define ACPI_DEBUG_PRINT(pl)
605#define ACPI_DEBUG_PRINT_RAW(pl)
601#define BREAK_MSG(a)
602
603#define return_VOID return
604#define return_ACPI_STATUS(s) return(s)
605#define return_VALUE(s) return(s)
606#define return_PTR(s) return(s)
607
608#endif
609
610/*
611 * Some code only gets executed when the debugger is built in.
612 * Note that this is entirely independent of whether the
613 * DEBUG_PRINT stuff (set by ACPI_DEBUG) is on, or not.
614 */
615#ifdef ENABLE_DEBUGGER
616#define DEBUGGER_EXEC(a) a
617#else
618#define DEBUGGER_EXEC(a)
619#endif
620
621
622/*
623 * For 16-bit code, we want to shrink some things even though
624 * we are using ACPI_DEBUG to get the debug output
625 */
626#ifdef _IA16
627#undef DEBUG_ONLY_MEMBERS
628#undef _VERBOSE_STRUCTURES
629#define DEBUG_ONLY_MEMBERS(a)
630#endif
631
632
633#ifdef ACPI_DEBUG
634
635/*
636 * 1) Set name to blanks
637 * 2) Copy the object name
638 */
639
640#define ADD_OBJECT_NAME(a,b) MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\
641 STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name))
642
643#else
644
645#define ADD_OBJECT_NAME(a,b)
646
647#endif
648
649
650/*
651 * Memory allocation tracking (DEBUG ONLY)
652 */
653
654#ifndef ACPI_DBG_TRACK_ALLOCATIONS
655
656/* Memory allocation */
657
658#define ACPI_MEM_ALLOCATE(a) AcpiOsAllocate(a)
659#define ACPI_MEM_CALLOCATE(a) AcpiOsCallocate(a)
660#define ACPI_MEM_FREE(a) AcpiOsFree(a)
606#define BREAK_MSG(a)
607
608#define return_VOID return
609#define return_ACPI_STATUS(s) return(s)
610#define return_VALUE(s) return(s)
611#define return_PTR(s) return(s)
612
613#endif
614
615/*
616 * Some code only gets executed when the debugger is built in.
617 * Note that this is entirely independent of whether the
618 * DEBUG_PRINT stuff (set by ACPI_DEBUG) is on, or not.
619 */
620#ifdef ENABLE_DEBUGGER
621#define DEBUGGER_EXEC(a) a
622#else
623#define DEBUGGER_EXEC(a)
624#endif
625
626
627/*
628 * For 16-bit code, we want to shrink some things even though
629 * we are using ACPI_DEBUG to get the debug output
630 */
631#ifdef _IA16
632#undef DEBUG_ONLY_MEMBERS
633#undef _VERBOSE_STRUCTURES
634#define DEBUG_ONLY_MEMBERS(a)
635#endif
636
637
638#ifdef ACPI_DEBUG
639
640/*
641 * 1) Set name to blanks
642 * 2) Copy the object name
643 */
644
645#define ADD_OBJECT_NAME(a,b) MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\
646 STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name))
647
648#else
649
650#define ADD_OBJECT_NAME(a,b)
651
652#endif
653
654
655/*
656 * Memory allocation tracking (DEBUG ONLY)
657 */
658
659#ifndef ACPI_DBG_TRACK_ALLOCATIONS
660
661/* Memory allocation */
662
663#define ACPI_MEM_ALLOCATE(a) AcpiOsAllocate(a)
664#define ACPI_MEM_CALLOCATE(a) AcpiOsCallocate(a)
665#define ACPI_MEM_FREE(a) AcpiOsFree(a)
666#define ACPI_MEM_TRACKING(a)
661
662
667
668
663#define DECREMENT_OBJECT_METRICS(a)
664#define INCREMENT_OBJECT_METRICS(a)
665#define INITIALIZE_ALLOCATION_METRICS()
666#define DECREMENT_NAME_TABLE_METRICS(a)
667#define INCREMENT_NAME_TABLE_METRICS(a)
668
669#else
670
671/* Memory allocation */
672
673#define ACPI_MEM_ALLOCATE(a) AcpiUtAllocate(a,_COMPONENT,_THIS_MODULE,__LINE__)
674#define ACPI_MEM_CALLOCATE(a) AcpiUtCallocate(a, _COMPONENT,_THIS_MODULE,__LINE__)
675#define ACPI_MEM_FREE(a) AcpiUtFree(a,_COMPONENT,_THIS_MODULE,__LINE__)
669#else
670
671/* Memory allocation */
672
673#define ACPI_MEM_ALLOCATE(a) AcpiUtAllocate(a,_COMPONENT,_THIS_MODULE,__LINE__)
674#define ACPI_MEM_CALLOCATE(a) AcpiUtCallocate(a, _COMPONENT,_THIS_MODULE,__LINE__)
675#define ACPI_MEM_FREE(a) AcpiUtFree(a,_COMPONENT,_THIS_MODULE,__LINE__)
676#define ACPI_MEM_TRACKING(a) a
676
677
677#define INITIALIZE_ALLOCATION_METRICS() \
678 AcpiGbl_CurrentObjectCount = 0; \
679 AcpiGbl_CurrentObjectSize = 0; \
680 AcpiGbl_RunningObjectCount = 0; \
681 AcpiGbl_RunningObjectSize = 0; \
682 AcpiGbl_MaxConcurrentObjectCount = 0; \
683 AcpiGbl_MaxConcurrentObjectSize = 0; \
684 AcpiGbl_CurrentAllocSize = 0; \
685 AcpiGbl_CurrentAllocCount = 0; \
686 AcpiGbl_RunningAllocSize = 0; \
687 AcpiGbl_RunningAllocCount = 0; \
688 AcpiGbl_MaxConcurrentAllocSize = 0; \
689 AcpiGbl_MaxConcurrentAllocCount = 0; \
690 AcpiGbl_CurrentNodeCount = 0; \
691 AcpiGbl_CurrentNodeSize = 0; \
692 AcpiGbl_MaxConcurrentNodeCount = 0
693
694
695#define DECREMENT_OBJECT_METRICS(a) \
696 AcpiGbl_CurrentObjectCount--; \
697 AcpiGbl_CurrentObjectSize -= a
698
699#define INCREMENT_OBJECT_METRICS(a) \
700 AcpiGbl_CurrentObjectCount++; \
701 AcpiGbl_RunningObjectCount++; \
702 if (AcpiGbl_MaxConcurrentObjectCount < AcpiGbl_CurrentObjectCount) \
703 { \
704 AcpiGbl_MaxConcurrentObjectCount = AcpiGbl_CurrentObjectCount; \
705 } \
706 AcpiGbl_RunningObjectSize += a; \
707 AcpiGbl_CurrentObjectSize += a; \
708 if (AcpiGbl_MaxConcurrentObjectSize < AcpiGbl_CurrentObjectSize) \
709 { \
710 AcpiGbl_MaxConcurrentObjectSize = AcpiGbl_CurrentObjectSize; \
711 }
712
713#define DECREMENT_NAME_TABLE_METRICS(a) \
714 AcpiGbl_CurrentNodeCount--; \
715 AcpiGbl_CurrentNodeSize -= (a)
716
717#define INCREMENT_NAME_TABLE_METRICS(a) \
718 AcpiGbl_CurrentNodeCount++; \
719 AcpiGbl_CurrentNodeSize+= (a); \
720 if (AcpiGbl_MaxConcurrentNodeCount < AcpiGbl_CurrentNodeCount) \
721 { \
722 AcpiGbl_MaxConcurrentNodeCount = AcpiGbl_CurrentNodeCount; \
723 }
724#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
725
726
727#endif /* ACMACROS_H */
678#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
679
680
681#endif /* ACMACROS_H */