xref: /illumos-gate/usr/src/uts/intel/sys/acpi/acmacros.h (revision d5dbd18d69de8954ab5ceb588e99d43fc9b21d46)
1 /******************************************************************************
2  *
3  * Name: acmacros.h - C macros for the entire subsystem.
4  *       $Revision: 160 $
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2005, 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 #define ACPI_LOWORD(l)                  ((UINT16)(UINT32)(l))
125 #define ACPI_HIWORD(l)                  ((UINT16)((((UINT32)(l)) >> 16) & 0xFFFF))
126 #define ACPI_LOBYTE(l)                  ((UINT8)(UINT16)(l))
127 #define ACPI_HIBYTE(l)                  ((UINT8)((((UINT16)(l)) >> 8) & 0xFF))
128 
129 #define ACPI_SET_BIT(target,bit)        ((target) |= (bit))
130 #define ACPI_CLEAR_BIT(target,bit)      ((target) &= ~(bit))
131 #define ACPI_MIN(a,b)                   (((a)<(b))?(a):(b))
132 
133 
134 #if ACPI_MACHINE_WIDTH == 16
135 
136 /*
137  * For 16-bit addresses, we have to assume that the upper 32 bits
138  * are zero.
139  */
140 #define ACPI_LODWORD(l)                 ((UINT32)(l))
141 #define ACPI_HIDWORD(l)                 ((UINT32)(0))
142 
143 #define ACPI_GET_ADDRESS(a)             ((a).Lo)
144 #define ACPI_STORE_ADDRESS(a,b)         {(a).Hi=0;(a).Lo=(UINT32)(b);}
145 #define ACPI_VALID_ADDRESS(a)           ((a).Hi | (a).Lo)
146 
147 #else
148 #ifdef ACPI_NO_INTEGER64_SUPPORT
149 /*
150  * ACPI_INTEGER is 32-bits, no 64-bit support on this platform
151  */
152 #define ACPI_LODWORD(l)                 ((UINT32)(l))
153 #define ACPI_HIDWORD(l)                 ((UINT32)(0))
154 
155 #define ACPI_GET_ADDRESS(a)             (a)
156 #define ACPI_STORE_ADDRESS(a,b)         ((a)=(b))
157 #define ACPI_VALID_ADDRESS(a)           (a)
158 
159 #else
160 
161 /*
162  * Full 64-bit address/integer on both 32-bit and 64-bit platforms
163  */
164 #define ACPI_LODWORD(l)                 ((UINT32)(UINT64)(l))
165 #define ACPI_HIDWORD(l)                 ((UINT32)(((*(UINT64_STRUCT *)(void *)(&l))).Hi))
166 
167 #define ACPI_GET_ADDRESS(a)             (a)
168 #define ACPI_STORE_ADDRESS(a,b)         ((a)=(ACPI_PHYSICAL_ADDRESS)(b))
169 #define ACPI_VALID_ADDRESS(a)           (a)
170 #endif
171 #endif
172 
173 /*
174  * printf() format helpers
175  */
176 
177 /* Split 64-bit integer into two 32-bit values. Use with %8.8X%8.8X */
178 
179 #define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i),ACPI_LODWORD(i)
180 
181 /*
182  * Extract a byte of data using a pointer.  Any more than a byte and we
183  * get into potential aligment issues -- see the STORE macros below
184  */
185 #define ACPI_GET8(addr)                 (*(UINT8*)(addr))
186 
187 /* Pointer arithmetic */
188 
189 #define ACPI_PTR_ADD(t,a,b)             (t *) (void *)((char *)(a) + (ACPI_NATIVE_UINT)(b))
190 #define ACPI_PTR_DIFF(a,b)              (ACPI_NATIVE_UINT) ((char *)(a) - (char *)(b))
191 
192 /* Pointer/Integer type conversions */
193 
194 #define ACPI_TO_POINTER(i)              ACPI_PTR_ADD (void, (void *) NULL,(ACPI_NATIVE_UINT)i)
195 #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p,(void *) NULL)
196 #define ACPI_OFFSET(d,f)                (ACPI_SIZE) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
197 #define ACPI_FADT_OFFSET(f)             ACPI_OFFSET (FADT_DESCRIPTOR, f)
198 
199 #define ACPI_CAST_PTR(t, p)             ((t *)(void *)(p))
200 #define ACPI_CAST_INDIRECT_PTR(t, p)    ((t **)(void *)(p))
201 
202 #if ACPI_MACHINE_WIDTH == 16
203 #define ACPI_STORE_POINTER(d,s)         ACPI_MOVE_32_TO_32(d,s)
204 #define ACPI_PHYSADDR_TO_PTR(i)         (void *)(i)
205 #define ACPI_PTR_TO_PHYSADDR(i)         (UINT32) (char *)(i)
206 #else
207 #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
208 #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
209 #endif
210 
211 /*
212  * Macros for moving data around to/from buffers that are possibly unaligned.
213  * If the hardware supports the transfer of unaligned data, just do the store.
214  * Otherwise, we have to move one byte at a time.
215  */
216 #ifdef ACPI_BIG_ENDIAN
217 /*
218  * Macros for big-endian machines
219  */
220 
221 /* This macro sets a buffer index, starting from the end of the buffer */
222 
223 #define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran)  ((BufLen) - (((BufOffset)+1) * (ByteGran)))
224 
225 /* These macros reverse the bytes during the move, converting little-endian to big endian */
226 
227                                                      /* Big Endian      <==        Little Endian */
228                                                      /*  Hi...Lo                     Lo...Hi     */
229 /* 16-bit source, 16/32/64 destination */
230 
231 #define ACPI_MOVE_16_TO_16(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
232                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
233 
234 #define ACPI_MOVE_16_TO_32(d,s)         {(*(UINT32 *)(void *)(d))=0;\
235                                            ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
236                                            ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
237 
238 #define ACPI_MOVE_16_TO_64(d,s)         {(*(UINT64 *)(void *)(d))=0;\
239                                            ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
240                                            ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
241 
242 /* 32-bit source, 16/32/64 destination */
243 
244 #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
245 
246 #define ACPI_MOVE_32_TO_32(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
247                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
248                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
249                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
250 
251 #define ACPI_MOVE_32_TO_64(d,s)         {(*(UINT64 *)(void *)(d))=0;\
252                                            ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
253                                            ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
254                                            ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
255                                            ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
256 
257 /* 64-bit source, 16/32/64 destination */
258 
259 #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
260 
261 #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
262 
263 #define ACPI_MOVE_64_TO_64(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
264                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
265                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
266                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
267                                          ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
268                                          ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
269                                          ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
270                                          ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
271 #else
272 /*
273  * Macros for little-endian machines
274  */
275 
276 /* This macro sets a buffer index, starting from the beginning of the buffer */
277 
278 #define ACPI_BUFFER_INDEX(BufLen,BufOffset,ByteGran)  (BufOffset)
279 
280 #ifdef ACPI_MISALIGNED_TRANSFERS
281 
282 /* The hardware supports unaligned transfers, just do the little-endian move */
283 
284 #if ACPI_MACHINE_WIDTH == 16
285 
286 /* No 64-bit integers */
287 /* 16-bit source, 16/32/64 destination */
288 
289 #define ACPI_MOVE_16_TO_16(d,s)         *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
290 #define ACPI_MOVE_16_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
291 #define ACPI_MOVE_16_TO_64(d,s)         ACPI_MOVE_16_TO_32(d,s)
292 
293 /* 32-bit source, 16/32/64 destination */
294 
295 #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
296 #define ACPI_MOVE_32_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
297 #define ACPI_MOVE_32_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
298 
299 /* 64-bit source, 16/32/64 destination */
300 
301 #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
302 #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
303 #define ACPI_MOVE_64_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
304 
305 #else
306 /* 16-bit source, 16/32/64 destination */
307 
308 #define ACPI_MOVE_16_TO_16(d,s)         *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
309 #define ACPI_MOVE_16_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
310 #define ACPI_MOVE_16_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s)
311 
312 /* 32-bit source, 16/32/64 destination */
313 
314 #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
315 #define ACPI_MOVE_32_TO_32(d,s)         *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
316 #define ACPI_MOVE_32_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s)
317 
318 /* 64-bit source, 16/32/64 destination */
319 
320 #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
321 #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
322 #define ACPI_MOVE_64_TO_64(d,s)         *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s)
323 #endif
324 
325 #else
326 /*
327  * The hardware does not support unaligned transfers.  We must move the
328  * data one byte at a time.  These macros work whether the source or
329  * the destination (or both) is/are unaligned.  (Little-endian move)
330  */
331 
332 /* 16-bit source, 16/32/64 destination */
333 
334 #define ACPI_MOVE_16_TO_16(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
335                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];}
336 
337 #define ACPI_MOVE_16_TO_32(d,s)         {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);}
338 #define ACPI_MOVE_16_TO_64(d,s)         {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d,s);}
339 
340 /* 32-bit source, 16/32/64 destination */
341 
342 #define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
343 
344 #define ACPI_MOVE_32_TO_32(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
345                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
346                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
347                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];}
348 
349 #define ACPI_MOVE_32_TO_64(d,s)         {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d,s);}
350 
351 /* 64-bit source, 16/32/64 destination */
352 
353 #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)    /* Truncate to 16 */
354 #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)    /* Truncate to 32 */
355 #define ACPI_MOVE_64_TO_64(d,s)         {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
356                                          ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
357                                          ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
358                                          ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\
359                                          ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\
360                                          ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\
361                                          ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
362                                          ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
363 #endif
364 #endif
365 
366 /* Macros based on machine integer width */
367 
368 #if ACPI_MACHINE_WIDTH == 16
369 #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_16_TO_16(d,s)
370 
371 #elif ACPI_MACHINE_WIDTH == 32
372 #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_32_TO_16(d,s)
373 
374 #elif ACPI_MACHINE_WIDTH == 64
375 #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_64_TO_16(d,s)
376 
377 #else
378 #error unknown ACPI_MACHINE_WIDTH
379 #endif
380 
381 
382 /*
383  * Fast power-of-two math macros for non-optimized compilers
384  */
385 #define _ACPI_DIV(value,PowerOf2)       ((UINT32) ((value) >> (PowerOf2)))
386 #define _ACPI_MUL(value,PowerOf2)       ((UINT32) ((value) << (PowerOf2)))
387 #define _ACPI_MOD(value,Divisor)        ((UINT32) ((value) & ((Divisor) -1)))
388 
389 #define ACPI_DIV_2(a)                   _ACPI_DIV(a,1)
390 #define ACPI_MUL_2(a)                   _ACPI_MUL(a,1)
391 #define ACPI_MOD_2(a)                   _ACPI_MOD(a,2)
392 
393 #define ACPI_DIV_4(a)                   _ACPI_DIV(a,2)
394 #define ACPI_MUL_4(a)                   _ACPI_MUL(a,2)
395 #define ACPI_MOD_4(a)                   _ACPI_MOD(a,4)
396 
397 #define ACPI_DIV_8(a)                   _ACPI_DIV(a,3)
398 #define ACPI_MUL_8(a)                   _ACPI_MUL(a,3)
399 #define ACPI_MOD_8(a)                   _ACPI_MOD(a,8)
400 
401 #define ACPI_DIV_16(a)                  _ACPI_DIV(a,4)
402 #define ACPI_MUL_16(a)                  _ACPI_MUL(a,4)
403 #define ACPI_MOD_16(a)                  _ACPI_MOD(a,16)
404 
405 
406 /*
407  * Rounding macros (Power of two boundaries only)
408  */
409 #define ACPI_ROUND_DOWN(value,boundary)      (((ACPI_NATIVE_UINT)(value)) & (~(((ACPI_NATIVE_UINT) boundary)-1)))
410 #define ACPI_ROUND_UP(value,boundary)        ((((ACPI_NATIVE_UINT)(value)) + (((ACPI_NATIVE_UINT) boundary)-1)) & (~(((ACPI_NATIVE_UINT) boundary)-1)))
411 
412 #define ACPI_ROUND_DOWN_TO_32_BITS(a)        ACPI_ROUND_DOWN(a,4)
413 #define ACPI_ROUND_DOWN_TO_64_BITS(a)        ACPI_ROUND_DOWN(a,8)
414 #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)    ACPI_ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
415 
416 #define ACPI_ROUND_UP_TO_32BITS(a)           ACPI_ROUND_UP(a,4)
417 #define ACPI_ROUND_UP_TO_64BITS(a)           ACPI_ROUND_UP(a,8)
418 #define ACPI_ROUND_UP_TO_NATIVE_WORD(a)      ACPI_ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
419 
420 
421 #define ACPI_ROUND_BITS_UP_TO_BYTES(a)       ACPI_DIV_8((a) + 7)
422 #define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)     ACPI_DIV_8((a))
423 
424 #define ACPI_ROUND_UP_TO_1K(a)               (((a) + 1023) >> 10)
425 
426 /* Generic (non-power-of-two) rounding */
427 
428 #define ACPI_ROUND_UP_TO(value,boundary)     (((value) + ((boundary)-1)) / (boundary))
429 
430 /*
431  * Bitmask creation
432  * Bit positions start at zero.
433  * MASK_BITS_ABOVE creates a mask starting AT the position and above
434  * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
435  */
436 #define ACPI_MASK_BITS_ABOVE(position)       (~((ACPI_INTEGER_MAX) << ((UINT32) (position))))
437 #define ACPI_MASK_BITS_BELOW(position)       ((ACPI_INTEGER_MAX) << ((UINT32) (position)))
438 
439 #define ACPI_IS_OCTAL_DIGIT(d)               (((char)(d) >= '0') && ((char)(d) <= '7'))
440 
441 
442 /* Bitfields within ACPI registers */
443 
444 #define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)      ((Val << Pos) & Mask)
445 #define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val)  Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
446 
447 /*
448  * An ACPI_NAMESPACE_NODE * can appear in some contexts,
449  * where a pointer to an ACPI_OPERAND_OBJECT  can also
450  * appear.  This macro is used to distinguish them.
451  *
452  * The "Descriptor" field is the first field in both structures.
453  */
454 #define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId)
455 #define ACPI_SET_DESCRIPTOR_TYPE(d,t)   (((ACPI_DESCRIPTOR *)(void *)(d))->DescriptorId = t)
456 
457 
458 /* Macro to test the object type */
459 
460 #define ACPI_GET_OBJECT_TYPE(d)         (((ACPI_OPERAND_OBJECT *)(void *)(d))->Common.Type)
461 
462 /* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
463 
464 #define ACPI_IS_SINGLE_TABLE(x)         (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
465 
466 /*
467  * Macros for the master AML opcode table
468  */
469 #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
470 #define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags)     {Name,(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type}
471 #else
472 #define ACPI_OP(Name,PArgs,IArgs,ObjType,Class,Type,Flags)     {(UINT32)(PArgs),(UINT32)(IArgs),(UINT32)(Flags),ObjType,Class,Type}
473 #endif
474 
475 #ifdef ACPI_DISASSEMBLER
476 #define ACPI_DISASM_ONLY_MEMBERS(a)     a;
477 #else
478 #define ACPI_DISASM_ONLY_MEMBERS(a)
479 #endif
480 
481 #define ARG_TYPE_WIDTH                  5
482 #define ARG_1(x)                        ((UINT32)(x))
483 #define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
484 #define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
485 #define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
486 #define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
487 #define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
488 
489 #define ARGI_LIST1(a)                   (ARG_1(a))
490 #define ARGI_LIST2(a,b)                 (ARG_1(b)|ARG_2(a))
491 #define ARGI_LIST3(a,b,c)               (ARG_1(c)|ARG_2(b)|ARG_3(a))
492 #define ARGI_LIST4(a,b,c,d)             (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
493 #define ARGI_LIST5(a,b,c,d,e)           (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
494 #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))
495 
496 #define ARGP_LIST1(a)                   (ARG_1(a))
497 #define ARGP_LIST2(a,b)                 (ARG_1(a)|ARG_2(b))
498 #define ARGP_LIST3(a,b,c)               (ARG_1(a)|ARG_2(b)|ARG_3(c))
499 #define ARGP_LIST4(a,b,c,d)             (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
500 #define ARGP_LIST5(a,b,c,d,e)           (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
501 #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))
502 
503 #define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
504 #define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
505 
506 
507 /*
508  * Reporting macros that are never compiled out
509  */
510 #define ACPI_PARAM_LIST(pl)                 pl
511 
512 /*
513  * Error reporting.  These versions add callers module and line#.
514  *
515  * Since _AcpiModuleName gets compiled out when ACPI_DEBUG_OUTPUT
516  * isn't defined, only use it in debug mode.
517  */
518 #ifdef ACPI_DEBUG_OUTPUT
519 
520 #define ACPI_REPORT_INFO(fp)                {AcpiUtReportInfo(_AcpiModuleName,__LINE__,_COMPONENT); \
521                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
522 #define ACPI_REPORT_ERROR(fp)               {AcpiUtReportError(_AcpiModuleName,__LINE__,_COMPONENT); \
523                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
524 #define ACPI_REPORT_WARNING(fp)             {AcpiUtReportWarning(_AcpiModuleName,__LINE__,_COMPONENT); \
525                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
526 #define ACPI_REPORT_NSERROR(s,e)            AcpiNsReportError(_AcpiModuleName,__LINE__,_COMPONENT, s, e);
527 
528 #define ACPI_REPORT_METHOD_ERROR(s,n,p,e)   AcpiNsReportMethodError(_AcpiModuleName,__LINE__,_COMPONENT, s, n, p, e);
529 
530 #else
531 
532 #define ACPI_REPORT_INFO(fp)                {AcpiUtReportInfo("ACPI",__LINE__,_COMPONENT); \
533                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
534 #define ACPI_REPORT_ERROR(fp)               {AcpiUtReportError("ACPI",__LINE__,_COMPONENT); \
535                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
536 #define ACPI_REPORT_WARNING(fp)             {AcpiUtReportWarning("ACPI",__LINE__,_COMPONENT); \
537                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
538 #define ACPI_REPORT_NSERROR(s,e)            AcpiNsReportError("ACPI",__LINE__,_COMPONENT, s, e);
539 
540 #define ACPI_REPORT_METHOD_ERROR(s,n,p,e)   AcpiNsReportMethodError("ACPI",__LINE__,_COMPONENT, s, n, p, e);
541 
542 #endif
543 
544 /* Error reporting.  These versions pass thru the module and line# */
545 
546 #define _ACPI_REPORT_INFO(a,b,c,fp)         {AcpiUtReportInfo(a,b,c); \
547                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
548 #define _ACPI_REPORT_ERROR(a,b,c,fp)        {AcpiUtReportError(a,b,c); \
549                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
550 #define _ACPI_REPORT_WARNING(a,b,c,fp)      {AcpiUtReportWarning(a,b,c); \
551                                                 AcpiOsPrintf ACPI_PARAM_LIST(fp);}
552 
553 /*
554  * Debug macros that are conditionally compiled
555  */
556 #ifdef ACPI_DEBUG_OUTPUT
557 #define ACPI_MODULE_NAME(Name)          static char ACPI_UNUSED_VAR *_AcpiModuleName = Name;
558 
559 /*
560  * Common parameters used for debug output functions:
561  * line number, function name, module(file) name, component ID
562  */
563 #define ACPI_DEBUG_PARAMETERS           __LINE__, ACPI_GET_FUNCTION_NAME, _AcpiModuleName, _COMPONENT
564 
565 /*
566  * Function entry tracing
567  */
568 
569 /*
570  * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header,
571  * define it now. This is the case where there the compiler does not support
572  * a __FUNCTION__ macro or equivalent. We save the function name on the
573  * local stack.
574  */
575 #ifndef ACPI_GET_FUNCTION_NAME
576 #define ACPI_GET_FUNCTION_NAME          _AcpiFunctionName
577 /*
578  * The Name parameter should be the procedure name as a quoted string.
579  * This is declared as a local string ("MyFunctionName") so that it can
580  * be also used by the function exit macros below.
581  */
582 #define ACPI_FUNCTION_NAME(Name)        char *_AcpiFunctionName = Name;
583 
584 #else
585 /* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */
586 
587 #define ACPI_FUNCTION_NAME(Name)
588 #endif
589 
590 #define ACPI_FUNCTION_TRACE(a)          ACPI_FUNCTION_NAME(a) \
591                                             AcpiUtTrace(ACPI_DEBUG_PARAMETERS)
592 #define ACPI_FUNCTION_TRACE_PTR(a,b)    ACPI_FUNCTION_NAME(a) \
593                                             AcpiUtTracePtr(ACPI_DEBUG_PARAMETERS,(void *)b)
594 #define ACPI_FUNCTION_TRACE_U32(a,b)    ACPI_FUNCTION_NAME(a) \
595                                             AcpiUtTraceU32(ACPI_DEBUG_PARAMETERS,(UINT32)b)
596 #define ACPI_FUNCTION_TRACE_STR(a,b)    ACPI_FUNCTION_NAME(a) \
597                                             AcpiUtTraceStr(ACPI_DEBUG_PARAMETERS,(char *)b)
598 
599 #define ACPI_FUNCTION_ENTRY()           AcpiUtTrackStackPtr()
600 
601 /*
602  * Function exit tracing.
603  * WARNING: These macros include a return statement.  This is usually considered
604  * bad form, but having a separate exit macro is very ugly and difficult to maintain.
605  * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
606  * so that "_AcpiFunctionName" is defined.
607  */
608 #ifdef ACPI_USE_DO_WHILE_0
609 #define ACPI_DO_WHILE0(a)               do a while(0)
610 #else
611 #define ACPI_DO_WHILE0(a)               a
612 #endif
613 
614 #define return_VOID                     ACPI_DO_WHILE0 ({AcpiUtExit(ACPI_DEBUG_PARAMETERS);return;})
615 #define return_ACPI_STATUS(s)           ACPI_DO_WHILE0 ({AcpiUtStatusExit(ACPI_DEBUG_PARAMETERS,(s));return((s));})
616 #define return_VALUE(s)                 ACPI_DO_WHILE0 ({AcpiUtValueExit(ACPI_DEBUG_PARAMETERS,(ACPI_INTEGER)(s));return((s));})
617 #define return_PTR(s)                   ACPI_DO_WHILE0 ({AcpiUtPtrExit(ACPI_DEBUG_PARAMETERS,(UINT8 *)(s));return((s));})
618 
619 /* Conditional execution */
620 
621 #define ACPI_DEBUG_EXEC(a)              a
622 #define ACPI_NORMAL_EXEC(a)
623 
624 #define ACPI_DEBUG_DEFINE(a)            a;
625 #define ACPI_DEBUG_ONLY_MEMBERS(a)      a;
626 #define _VERBOSE_STRUCTURES
627 
628 
629 /* Stack and buffer dumping */
630 
631 #define ACPI_DUMP_STACK_ENTRY(a)        AcpiExDumpOperand((a),0)
632 #define ACPI_DUMP_OPERANDS(a,b,c,d,e)   AcpiExDumpOperands(a,b,c,d,e,_AcpiModuleName,__LINE__)
633 
634 
635 #define ACPI_DUMP_ENTRY(a,b)            AcpiNsDumpEntry (a,b)
636 #define ACPI_DUMP_PATHNAME(a,b,c,d)     AcpiNsDumpPathname(a,b,c,d)
637 #define ACPI_DUMP_RESOURCE_LIST(a)      AcpiRsDumpResourceList(a)
638 #define ACPI_DUMP_BUFFER(a,b)           AcpiUtDumpBuffer((UINT8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
639 #define ACPI_BREAK_MSG(a)               AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,(a))
640 
641 
642 /*
643  * Generate INT3 on ACPI_ERROR (Debug only!)
644  */
645 #define ACPI_ERROR_BREAK
646 #ifdef  ACPI_ERROR_BREAK
647 #define ACPI_BREAK_ON_ERROR(lvl)        if ((lvl)&ACPI_ERROR) \
648                                             AcpiOsSignal(ACPI_SIGNAL_BREAKPOINT,"Fatal error encountered\n")
649 #else
650 #define ACPI_BREAK_ON_ERROR(lvl)
651 #endif
652 
653 /*
654  * Master debug print macros
655  * Print iff:
656  *    1) Debug print for the current component is enabled
657  *    2) Debug error level or trace level for the print statement is enabled
658  */
659 #define ACPI_DEBUG_PRINT(pl)            AcpiUtDebugPrint ACPI_PARAM_LIST(pl)
660 #define ACPI_DEBUG_PRINT_RAW(pl)        AcpiUtDebugPrintRaw ACPI_PARAM_LIST(pl)
661 
662 
663 #else
664 /*
665  * This is the non-debug case -- make everything go away,
666  * leaving no executable debug code!
667  */
668 #define ACPI_MODULE_NAME(Name)
669 #define _AcpiModuleName ""
670 
671 #define ACPI_DEBUG_EXEC(a)
672 #define ACPI_NORMAL_EXEC(a)             a;
673 
674 #define ACPI_DEBUG_DEFINE(a)
675 #define ACPI_DEBUG_ONLY_MEMBERS(a)
676 #define ACPI_FUNCTION_NAME(a)
677 #define ACPI_FUNCTION_TRACE(a)
678 #define ACPI_FUNCTION_TRACE_PTR(a,b)
679 #define ACPI_FUNCTION_TRACE_U32(a,b)
680 #define ACPI_FUNCTION_TRACE_STR(a,b)
681 #define ACPI_FUNCTION_EXIT
682 #define ACPI_FUNCTION_STATUS_EXIT(s)
683 #define ACPI_FUNCTION_VALUE_EXIT(s)
684 #define ACPI_FUNCTION_ENTRY()
685 #define ACPI_DUMP_STACK_ENTRY(a)
686 #define ACPI_DUMP_OPERANDS(a,b,c,d,e)
687 #define ACPI_DUMP_ENTRY(a,b)
688 #define ACPI_DUMP_TABLES(a,b)
689 #define ACPI_DUMP_PATHNAME(a,b,c,d)
690 #define ACPI_DUMP_RESOURCE_LIST(a)
691 #define ACPI_DUMP_BUFFER(a,b)
692 #define ACPI_DEBUG_PRINT(pl)
693 #define ACPI_DEBUG_PRINT_RAW(pl)
694 #define ACPI_BREAK_MSG(a)
695 
696 #define return_VOID                     return
697 #define return_ACPI_STATUS(s)           return(s)
698 #define return_VALUE(s)                 return(s)
699 #define return_PTR(s)                   return(s)
700 
701 #endif
702 
703 /*
704  * Some code only gets executed when the debugger is built in.
705  * Note that this is entirely independent of whether the
706  * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not.
707  */
708 #ifdef ACPI_DEBUGGER
709 #define ACPI_DEBUGGER_EXEC(a)           a
710 #else
711 #define ACPI_DEBUGGER_EXEC(a)
712 #endif
713 
714 
715 /*
716  * For 16-bit code, we want to shrink some things even though
717  * we are using ACPI_DEBUG_OUTPUT to get the debug output
718  */
719 #if ACPI_MACHINE_WIDTH == 16
720 #undef ACPI_DEBUG_ONLY_MEMBERS
721 #undef _VERBOSE_STRUCTURES
722 #define ACPI_DEBUG_ONLY_MEMBERS(a)
723 #endif
724 
725 
726 #ifdef ACPI_DEBUG_OUTPUT
727 /*
728  * 1) Set name to blanks
729  * 2) Copy the object name
730  */
731 #define ACPI_ADD_OBJECT_NAME(a,b)       ACPI_MEMSET (a->Common.Name, ' ', sizeof (a->Common.Name));\
732                                         ACPI_STRNCPY (a->Common.Name, AcpiGbl_NsTypeNames[b], sizeof (a->Common.Name))
733 #else
734 
735 #define ACPI_ADD_OBJECT_NAME(a,b)
736 #endif
737 
738 
739 /*
740  * Memory allocation tracking (DEBUG ONLY)
741  */
742 #ifndef ACPI_DBG_TRACK_ALLOCATIONS
743 
744 /* Memory allocation */
745 
746 #define ACPI_MEM_ALLOCATE(a)            AcpiUtAllocate((ACPI_SIZE)(a),_COMPONENT,_AcpiModuleName,__LINE__)
747 #define ACPI_MEM_CALLOCATE(a)           AcpiUtCallocate((ACPI_SIZE)(a), _COMPONENT,_AcpiModuleName,__LINE__)
748 #define ACPI_MEM_FREE(a)                AcpiOsFree(a)
749 #define ACPI_MEM_TRACKING(a)
750 
751 #else
752 
753 /* Memory allocation */
754 
755 #define ACPI_MEM_ALLOCATE(a)            AcpiUtAllocateAndTrack((ACPI_SIZE)(a),_COMPONENT,_AcpiModuleName,__LINE__)
756 #define ACPI_MEM_CALLOCATE(a)           AcpiUtCallocateAndTrack((ACPI_SIZE)(a), _COMPONENT,_AcpiModuleName,__LINE__)
757 #define ACPI_MEM_FREE(a)                AcpiUtFreeAndTrack(a,_COMPONENT,_AcpiModuleName,__LINE__)
758 #define ACPI_MEM_TRACKING(a)            a
759 
760 #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
761 
762 #endif /* ACMACROS_H */
763