More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / drivers / acpi / include / acmacros.h
blob19cfa05913d77d35c50fdc34677a9fcab0ef7508
1 /******************************************************************************
3 * Name: acmacros.h - C macros for the entire subsystem.
4 * $Revision: 59 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef __ACMACROS_H__
27 #define __ACMACROS_H__
30 * Data manipulation macros
33 #ifndef LOWORD
34 #define LOWORD(l) ((u16)(NATIVE_UINT)(l))
35 #endif
37 #ifndef HIWORD
38 #define HIWORD(l) ((u16)((((NATIVE_UINT)(l)) >> 16) & 0xFFFF))
39 #endif
41 #ifndef LOBYTE
42 #define LOBYTE(l) ((u8)(u16)(l))
43 #endif
45 #ifndef HIBYTE
46 #define HIBYTE(l) ((u8)((((u16)(l)) >> 8) & 0xFF))
47 #endif
49 #define BIT0(x) ((((x) & 0x01) > 0) ? 1 : 0)
50 #define BIT1(x) ((((x) & 0x02) > 0) ? 1 : 0)
51 #define BIT2(x) ((((x) & 0x04) > 0) ? 1 : 0)
53 #define BIT3(x) ((((x) & 0x08) > 0) ? 1 : 0)
54 #define BIT4(x) ((((x) & 0x10) > 0) ? 1 : 0)
55 #define BIT5(x) ((((x) & 0x20) > 0) ? 1 : 0)
56 #define BIT6(x) ((((x) & 0x40) > 0) ? 1 : 0)
57 #define BIT7(x) ((((x) & 0x80) > 0) ? 1 : 0)
59 #define LOW_BASE(w) ((u16) ((w) & 0x0000FFFF))
60 #define MID_BASE(b) ((u8) (((b) & 0x00FF0000) >> 16))
61 #define HI_BASE(b) ((u8) (((b) & 0xFF000000) >> 24))
62 #define LOW_LIMIT(w) ((u16) ((w) & 0x0000FFFF))
63 #define HI_LIMIT(b) ((u8) (((b) & 0x00FF0000) >> 16))
66 #ifdef _IA16
67 #define ACPI_GET_ADDRESS(a) ((a).lo)
68 #define ACPI_STORE_ADDRESS(a,b) {(a).hi=0;(a).lo=(b);}
69 #define ACPI_VALID_ADDRESS(a) ((a).hi && (a).lo)
70 #else
71 #define ACPI_GET_ADDRESS(a) (a)
72 #define ACPI_STORE_ADDRESS(a,b) ((a)=(b))
73 #define ACPI_VALID_ADDRESS(a) (a)
74 #endif
76 * Extract a byte of data using a pointer. Any more than a byte and we
77 * get into potential aligment issues -- see the STORE macros below
79 #define GET8(addr) (*(u8*)(addr))
83 * Macros for moving data around to/from buffers that are possibly unaligned.
84 * If the hardware supports the transfer of unaligned data, just do the store.
85 * Otherwise, we have to move one byte at a time.
88 #ifdef _HW_ALIGNMENT_SUPPORT
90 /* The hardware supports unaligned transfers, just do the move */
92 #define MOVE_UNALIGNED16_TO_16(d,s) *(u16*)(d) = *(u16*)(s)
93 #define MOVE_UNALIGNED32_TO_32(d,s) *(u32*)(d) = *(u32*)(s)
94 #define MOVE_UNALIGNED16_TO_32(d,s) *(u32*)(d) = *(u16*)(s)
96 #else
98 * The hardware does not support unaligned transfers. We must move the
99 * data one byte at a time. These macros work whether the source or
100 * the destination (or both) is/are unaligned.
103 #define MOVE_UNALIGNED16_TO_16(d,s) {((u8 *)(d))[0] = ((u8 *)(s))[0];\
104 ((u8 *)(d))[1] = ((u8 *)(s))[1];}
106 #define MOVE_UNALIGNED32_TO_32(d,s) {((u8 *)(d))[0] = ((u8 *)(s))[0];\
107 ((u8 *)(d))[1] = ((u8 *)(s))[1];\
108 ((u8 *)(d))[2] = ((u8 *)(s))[2];\
109 ((u8 *)(d))[3] = ((u8 *)(s))[3];}
111 #define MOVE_UNALIGNED16_TO_32(d,s) {(*(u32*)(d)) = 0; MOVE_UNALIGNED16_TO_16(d,s);}
113 #endif
117 * Fast power-of-two math macros for non-optimized compilers
120 #define _DIV(value,power_of2) ((u32) ((value) >> (power_of2)))
121 #define _MUL(value,power_of2) ((u32) ((value) << (power_of2)))
122 #define _MOD(value,divisor) ((u32) ((value) & ((divisor) -1)))
124 #define DIV_2(a) _DIV(a,1)
125 #define MUL_2(a) _MUL(a,1)
126 #define MOD_2(a) _MOD(a,2)
128 #define DIV_4(a) _DIV(a,2)
129 #define MUL_4(a) _MUL(a,2)
130 #define MOD_4(a) _MOD(a,4)
132 #define DIV_8(a) _DIV(a,3)
133 #define MUL_8(a) _MUL(a,3)
134 #define MOD_8(a) _MOD(a,8)
136 #define DIV_16(a) _DIV(a,4)
137 #define MUL_16(a) _MUL(a,4)
138 #define MOD_16(a) _MOD(a,16)
141 * Divide and Modulo
143 #define ACPI_DIVIDE(n,d) ((n) / (d))
144 #define ACPI_MODULO(n,d) ((n) % (d))
147 * Rounding macros (Power of two boundaries only)
150 #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
151 #define ROUND_UP(value,boundary) (((value) + ((boundary)-1)) & (~((boundary)-1)))
153 #define ROUND_DOWN_TO_32_BITS(a) ROUND_DOWN(a,4)
154 #define ROUND_DOWN_TO_64_BITS(a) ROUND_DOWN(a,8)
155 #define ROUND_DOWN_TO_NATIVE_WORD(a) ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
157 #define ROUND_UP_TO_32_bITS(a) ROUND_UP(a,4)
158 #define ROUND_UP_TO_64_bITS(a) ROUND_UP(a,8)
159 #define ROUND_UP_TO_NATIVE_WORD(a) ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
161 #define ROUND_PTR_UP_TO_4(a,b) ((b *)(((NATIVE_UINT)(a) + 3) & ~3))
162 #define ROUND_PTR_UP_TO_8(a,b) ((b *)(((NATIVE_UINT)(a) + 7) & ~7))
164 #define ROUND_UP_TO_1_k(a) (((a) + 1023) >> 10)
166 #ifdef DEBUG_ASSERT
167 #undef DEBUG_ASSERT
168 #endif
171 /* Macros for GAS addressing */
173 #define ACPI_PCI_DEVICE_MASK (UINT64) 0x0000FFFF00000000
174 #define ACPI_PCI_FUNCTION_MASK (UINT64) 0x00000000FFFF0000
175 #define ACPI_PCI_REGISTER_MASK (UINT64) 0x000000000000FFFF
177 #define ACPI_PCI_FUNCTION(a) (u32) ((((a) & ACPI_PCI_FUNCTION_MASK) >> 16))
178 #define ACPI_PCI_DEVICE(a) (u32) ((((a) & ACPI_PCI_DEVICE_MASK) >> 32))
180 #ifndef _IA16
181 #define ACPI_PCI_REGISTER(a) (u32) (((a) & ACPI_PCI_REGISTER_MASK))
182 #define ACPI_PCI_DEVFUN(a) (u32) ((ACPI_PCI_DEVICE(a) << 16) | ACPI_PCI_FUNCTION(a))
184 #else
185 #define ACPI_PCI_REGISTER(a) (u32) (((a) & 0x0000FFFF))
186 #define ACPI_PCI_DEVFUN(a) (u32) ((((a) & 0xFFFF0000) >> 16))
188 #endif
191 * An ACPI_HANDLE (which is actually an ACPI_NAMESPACE_NODE *) can appear in some contexts,
192 * such as on ap_obj_stack, where a pointer to an ACPI_OPERAND_OBJECT can also
193 * appear. This macro is used to distinguish them.
195 * The Data_type field is the first field in both structures.
198 #define VALID_DESCRIPTOR_TYPE(d,t) (((ACPI_NAMESPACE_NODE *)d)->data_type == t)
201 /* Macro to test the object type */
203 #define IS_THIS_OBJECT_TYPE(d,t) (((ACPI_OPERAND_OBJECT *)d)->common.type == (u8)t)
205 /* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */
207 #define IS_SINGLE_TABLE(x) (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
210 * Macro to check if a pointer is within an ACPI table.
211 * Parameter (a) is the pointer to check. Parameter (b) must be defined
212 * as a pointer to an ACPI_TABLE_HEADER. (b+1) then points past the header,
213 * and ((u8 *)b+b->Length) points one byte past the end of the table.
216 #ifndef _IA16
217 #define IS_IN_ACPI_TABLE(a,b) (((u8 *)(a) >= (u8 *)(b + 1)) &&\
218 ((u8 *)(a) < ((u8 *)b + b->length)))
220 #else
221 #define IS_IN_ACPI_TABLE(a,b) (_segment)(a) == (_segment)(b) &&\
222 (((u8 *)(a) >= (u8 *)(b + 1)) &&\
223 ((u8 *)(a) < ((u8 *)b + b->length)))
224 #endif
227 * Macros for the master AML opcode table
230 #ifdef ACPI_DEBUG
231 #define OP_INFO_ENTRY(flags,name,Pargs,Iargs) {flags,Pargs,Iargs,name}
232 #else
233 #define OP_INFO_ENTRY(flags,name,Pargs,Iargs) {flags,Pargs,Iargs}
234 #endif
236 #define ARG_TYPE_WIDTH 5
237 #define ARG_1(x) ((u32)(x))
238 #define ARG_2(x) ((u32)(x) << (1 * ARG_TYPE_WIDTH))
239 #define ARG_3(x) ((u32)(x) << (2 * ARG_TYPE_WIDTH))
240 #define ARG_4(x) ((u32)(x) << (3 * ARG_TYPE_WIDTH))
241 #define ARG_5(x) ((u32)(x) << (4 * ARG_TYPE_WIDTH))
242 #define ARG_6(x) ((u32)(x) << (5 * ARG_TYPE_WIDTH))
244 #define ARGI_LIST1(a) (ARG_1(a))
245 #define ARGI_LIST2(a,b) (ARG_1(b)|ARG_2(a))
246 #define ARGI_LIST3(a,b,c) (ARG_1(c)|ARG_2(b)|ARG_3(a))
247 #define ARGI_LIST4(a,b,c,d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
248 #define ARGI_LIST5(a,b,c,d,e) (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
249 #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))
251 #define ARGP_LIST1(a) (ARG_1(a))
252 #define ARGP_LIST2(a,b) (ARG_1(a)|ARG_2(b))
253 #define ARGP_LIST3(a,b,c) (ARG_1(a)|ARG_2(b)|ARG_3(c))
254 #define ARGP_LIST4(a,b,c,d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
255 #define ARGP_LIST5(a,b,c,d,e) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
256 #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))
258 #define GET_CURRENT_ARG_TYPE(list) (list & ((u32) 0x1F))
259 #define INCREMENT_ARG_LIST(list) (list >>= ((u32) ARG_TYPE_WIDTH))
263 * Reporting macros that are never compiled out
266 #define PARAM_LIST(pl) pl
269 * Error reporting. These versions add callers module and line#. Since
270 * _THIS_MODULE gets compiled out when ACPI_DEBUG isn't defined, only
271 * use it in debug mode.
274 #ifdef ACPI_DEBUG
276 #define REPORT_INFO(fp) {_report_info(_THIS_MODULE,__LINE__,_COMPONENT); \
277 debug_print_raw PARAM_LIST(fp);}
278 #define REPORT_ERROR(fp) {_report_error(_THIS_MODULE,__LINE__,_COMPONENT); \
279 debug_print_raw PARAM_LIST(fp);}
280 #define REPORT_WARNING(fp) {_report_warning(_THIS_MODULE,__LINE__,_COMPONENT); \
281 debug_print_raw PARAM_LIST(fp);}
283 #else
285 #define REPORT_INFO(fp) {_report_info("ACPI",__LINE__,_COMPONENT); \
286 debug_print_raw PARAM_LIST(fp);}
287 #define REPORT_ERROR(fp) {_report_error("ACPI",__LINE__,_COMPONENT); \
288 debug_print_raw PARAM_LIST(fp);}
289 #define REPORT_WARNING(fp) {_report_warning("ACPI",__LINE__,_COMPONENT); \
290 debug_print_raw PARAM_LIST(fp);}
292 #endif
294 /* Error reporting. These versions pass thru the module and line# */
296 #define _REPORT_INFO(a,b,c,fp) {_report_info(a,b,c); \
297 debug_print_raw PARAM_LIST(fp);}
298 #define _REPORT_ERROR(a,b,c,fp) {_report_error(a,b,c); \
299 debug_print_raw PARAM_LIST(fp);}
300 #define _REPORT_WARNING(a,b,c,fp) {_report_warning(a,b,c); \
301 debug_print_raw PARAM_LIST(fp);}
303 /* Buffer dump macros */
305 #define DUMP_BUFFER(a,b) acpi_cm_dump_buffer((u8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
308 * Debug macros that are conditionally compiled
311 #ifdef ACPI_DEBUG
313 #define MODULE_NAME(name) static char *_THIS_MODULE = name;
316 * Function entry tracing.
317 * The first parameter should be the procedure name as a quoted string. This is declared
318 * as a local string ("_Proc_name) so that it can be also used by the function exit macros below.
321 #define FUNCTION_TRACE(a) char * _proc_name = a;\
322 function_trace(_THIS_MODULE,__LINE__,_COMPONENT,a)
323 #define FUNCTION_TRACE_PTR(a,b) char * _proc_name = a;\
324 function_trace_ptr(_THIS_MODULE,__LINE__,_COMPONENT,a,(void *)b)
325 #define FUNCTION_TRACE_U32(a,b) char * _proc_name = a;\
326 function_trace_u32(_THIS_MODULE,__LINE__,_COMPONENT,a,(u32)b)
327 #define FUNCTION_TRACE_STR(a,b) char * _proc_name = a;\
328 function_trace_str(_THIS_MODULE,__LINE__,_COMPONENT,a,(NATIVE_CHAR *)b)
330 * Function exit tracing.
331 * WARNING: These macros include a return statement. This is usually considered
332 * bad form, but having a separate exit macro is very ugly and difficult to maintain.
333 * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
334 * so that "_Proc_name" is defined.
336 #define return_VOID {function_exit(_THIS_MODULE,__LINE__,_COMPONENT,_proc_name);return;}
337 #define return_ACPI_STATUS(s) {function_status_exit(_THIS_MODULE,__LINE__,_COMPONENT,_proc_name,s);return(s);}
338 #define return_VALUE(s) {function_value_exit(_THIS_MODULE,__LINE__,_COMPONENT,_proc_name,(NATIVE_UINT)s);return(s);}
339 #define return_PTR(s) {function_ptr_exit(_THIS_MODULE,__LINE__,_COMPONENT,_proc_name,(u8 *)s);return(s);}
342 /* Conditional execution */
344 #define DEBUG_EXEC(a) a
345 #define NORMAL_EXEC(a)
347 #define DEBUG_DEFINE(a) a;
348 #define DEBUG_ONLY_MEMBERS(a) a;
351 /* Stack and buffer dumping */
353 #define DUMP_STACK_ENTRY(a) acpi_aml_dump_operand(a)
354 #define DUMP_OPERANDS(a,b,c,d,e) acpi_aml_dump_operands(a,b,c,d,e,_THIS_MODULE,__LINE__)
357 #define DUMP_ENTRY(a,b) acpi_ns_dump_entry (a,b)
358 #define DUMP_TABLES(a,b) acpi_ns_dump_tables(a,b)
359 #define DUMP_PATHNAME(a,b,c,d) acpi_ns_dump_pathname(a,b,c,d)
360 #define DUMP_RESOURCE_LIST(a) acpi_rs_dump_resource_list(a)
361 #define BREAK_MSG(a) acpi_os_breakpoint (a)
364 * Generate INT3 on ACPI_ERROR (Debug only!)
367 #define ERROR_BREAK
368 #ifdef ERROR_BREAK
369 #define BREAK_ON_ERROR(lvl) if ((lvl)&ACPI_ERROR) acpi_os_breakpoint("Fatal error encountered\n")
370 #else
371 #define BREAK_ON_ERROR(lvl)
372 #endif
375 * Master debug print macros
376 * Print iff:
377 * 1) Debug print for the current component is enabled
378 * 2) Debug error level or trace level for the print statement is enabled
382 #define TEST_DEBUG_SWITCH(lvl) if (((lvl) & acpi_dbg_level) && (_COMPONENT & acpi_dbg_layer))
384 #define DEBUG_PRINT(lvl,fp) TEST_DEBUG_SWITCH(lvl) {\
385 debug_print_prefix (_THIS_MODULE,__LINE__);\
386 debug_print_raw PARAM_LIST(fp);\
387 BREAK_ON_ERROR(lvl);}
389 #define DEBUG_PRINT_RAW(lvl,fp) TEST_DEBUG_SWITCH(lvl) {\
390 debug_print_raw PARAM_LIST(fp);}
393 /* Assert macros */
395 #define ACPI_ASSERT(exp) if(!(exp)) \
396 acpi_os_dbg_assert(#exp, __FILE__, __LINE__, "Failed Assertion")
398 #define DEBUG_ASSERT(msg, exp) if(!(exp)) \
399 acpi_os_dbg_assert(#exp, __FILE__, __LINE__, msg)
402 #else
404 * This is the non-debug case -- make everything go away,
405 * leaving no executable debug code!
408 #define MODULE_NAME(name)
409 #define _THIS_MODULE ""
411 #define DEBUG_EXEC(a)
412 #define NORMAL_EXEC(a) a;
414 #define DEBUG_DEFINE(a)
415 #define DEBUG_ONLY_MEMBERS(a)
416 #define FUNCTION_TRACE(a)
417 #define FUNCTION_TRACE_PTR(a,b)
418 #define FUNCTION_TRACE_U32(a,b)
419 #define FUNCTION_TRACE_STR(a,b)
420 #define FUNCTION_EXIT
421 #define FUNCTION_STATUS_EXIT(s)
422 #define FUNCTION_VALUE_EXIT(s)
423 #define DUMP_STACK_ENTRY(a)
424 #define DUMP_OPERANDS(a,b,c,d,e)
425 #define DUMP_ENTRY(a,b)
426 #define DUMP_TABLES(a,b)
427 #define DUMP_PATHNAME(a,b,c,d)
428 #define DUMP_RESOURCE_LIST(a)
429 #define DEBUG_PRINT(l,f)
430 #define DEBUG_PRINT_RAW(l,f)
431 #define BREAK_MSG(a)
433 #define return_VOID return
434 #define return_ACPI_STATUS(s) return(s)
435 #define return_VALUE(s) return(s)
436 #define return_PTR(s) return(s)
438 #define ACPI_ASSERT(exp)
439 #define DEBUG_ASSERT(msg, exp)
441 #endif
444 * Some code only gets executed when the debugger is built in.
445 * Note that this is entirely independent of whether the
446 * DEBUG_PRINT stuff (set by ACPI_DEBUG) is on, or not.
448 #ifdef ENABLE_DEBUGGER
449 #define DEBUGGER_EXEC(a) a
450 #else
451 #define DEBUGGER_EXEC(a)
452 #endif
456 * For 16-bit code, we want to shrink some things even though
457 * we are using ACPI_DEBUG to get the debug output
459 #ifdef _IA16
460 #undef DEBUG_ONLY_MEMBERS
461 #define DEBUG_ONLY_MEMBERS(a)
462 #undef OP_INFO_ENTRY
463 #define OP_INFO_ENTRY(flags,name,Pargs,Iargs) {flags,Pargs,Iargs}
464 #endif
467 #ifdef ACPI_DEBUG
470 * 1) Set name to blanks
471 * 2) Copy the object name
474 #define ADD_OBJECT_NAME(a,b) MEMSET (a->common.name, ' ', sizeof (a->common.name));\
475 STRNCPY (a->common.name, acpi_gbl_ns_type_names[b], sizeof (a->common.name))
477 #else
479 #define ADD_OBJECT_NAME(a,b)
481 #endif
484 #endif /* ACMACROS_H */