diff options
Diffstat (limited to 'include/acpi/acmacros.h')
-rw-r--r-- | include/acpi/acmacros.h | 190 |
1 files changed, 133 insertions, 57 deletions
diff --git a/include/acpi/acmacros.h b/include/acpi/acmacros.h index 702cc4e57f5f..49ba151766de 100644 --- a/include/acpi/acmacros.h +++ b/include/acpi/acmacros.h | |||
@@ -5,7 +5,7 @@ | |||
5 | *****************************************************************************/ | 5 | *****************************************************************************/ |
6 | 6 | ||
7 | /* | 7 | /* |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
9 | * All rights reserved. | 9 | * All rights reserved. |
10 | * | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without |
@@ -60,7 +60,7 @@ | |||
60 | 60 | ||
61 | /* | 61 | /* |
62 | * For 16-bit addresses, we have to assume that the upper 32 bits | 62 | * For 16-bit addresses, we have to assume that the upper 32 bits |
63 | * are zero. | 63 | * (out of 64) are zero. |
64 | */ | 64 | */ |
65 | #define ACPI_LODWORD(l) ((u32)(l)) | 65 | #define ACPI_LODWORD(l) ((u32)(l)) |
66 | #define ACPI_HIDWORD(l) ((u32)(0)) | 66 | #define ACPI_HIDWORD(l) ((u32)(0)) |
@@ -104,30 +104,38 @@ | |||
104 | #define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i),ACPI_LODWORD(i) | 104 | #define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i),ACPI_LODWORD(i) |
105 | 105 | ||
106 | /* | 106 | /* |
107 | * Extract a byte of data using a pointer. Any more than a byte and we | 107 | * Extract data using a pointer. Any more than a byte and we |
108 | * get into potential aligment issues -- see the STORE macros below | 108 | * get into potential aligment issues -- see the STORE macros below. |
109 | * Use with care. | ||
109 | */ | 110 | */ |
110 | #define ACPI_GET8(addr) (*(u8*)(addr)) | 111 | #define ACPI_GET8(ptr) *ACPI_CAST_PTR (u8, ptr) |
112 | #define ACPI_GET16(ptr) *ACPI_CAST_PTR (u16, ptr) | ||
113 | #define ACPI_GET32(ptr) *ACPI_CAST_PTR (u32, ptr) | ||
114 | #define ACPI_GET64(ptr) *ACPI_CAST_PTR (u64, ptr) | ||
115 | #define ACPI_SET8(ptr) *ACPI_CAST_PTR (u8, ptr) | ||
116 | #define ACPI_SET16(ptr) *ACPI_CAST_PTR (u16, ptr) | ||
117 | #define ACPI_SET32(ptr) *ACPI_CAST_PTR (u32, ptr) | ||
118 | #define ACPI_SET64(ptr) *ACPI_CAST_PTR (u64, ptr) | ||
111 | 119 | ||
112 | /* Pointer arithmetic */ | 120 | /* |
113 | 121 | * Pointer manipulation | |
114 | #define ACPI_PTR_ADD(t,a,b) (t *) (void *)((char *)(a) + (acpi_native_uint)(b)) | 122 | */ |
115 | #define ACPI_PTR_DIFF(a,b) (acpi_native_uint) ((char *)(a) - (char *)(b)) | 123 | #define ACPI_CAST_PTR(t, p) ((t *) (acpi_uintptr_t) (p)) |
124 | #define ACPI_CAST_INDIRECT_PTR(t, p) ((t **) (acpi_uintptr_t) (p)) | ||
125 | #define ACPI_ADD_PTR(t,a,b) ACPI_CAST_PTR (t, (ACPI_CAST_PTR (u8,(a)) + (acpi_native_uint)(b))) | ||
126 | #define ACPI_PTR_DIFF(a,b) (acpi_native_uint) (ACPI_CAST_PTR (u8,(a)) - ACPI_CAST_PTR (u8,(b))) | ||
116 | 127 | ||
117 | /* Pointer/Integer type conversions */ | 128 | /* Pointer/Integer type conversions */ |
118 | 129 | ||
119 | #define ACPI_TO_POINTER(i) ACPI_PTR_ADD (void, (void *) NULL,(acpi_native_uint)i) | 130 | #define ACPI_TO_POINTER(i) ACPI_ADD_PTR (void,(void *) NULL,(acpi_native_uint) i) |
120 | #define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p,(void *) NULL) | 131 | #define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p,(void *) NULL) |
121 | #define ACPI_OFFSET(d,f) (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL) | 132 | #define ACPI_OFFSET(d,f) (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL) |
122 | #define ACPI_FADT_OFFSET(f) ACPI_OFFSET (FADT_DESCRIPTOR, f) | 133 | #define ACPI_FADT_OFFSET(f) ACPI_OFFSET (FADT_DESCRIPTOR, f) |
123 | 134 | ||
124 | #define ACPI_CAST_PTR(t, p) ((t *)(void *)(p)) | ||
125 | #define ACPI_CAST_INDIRECT_PTR(t, p) ((t **)(void *)(p)) | ||
126 | |||
127 | #if ACPI_MACHINE_WIDTH == 16 | 135 | #if ACPI_MACHINE_WIDTH == 16 |
128 | #define ACPI_STORE_POINTER(d,s) ACPI_MOVE_32_TO_32(d,s) | 136 | #define ACPI_STORE_POINTER(d,s) ACPI_MOVE_32_TO_32(d,s) |
129 | #define ACPI_PHYSADDR_TO_PTR(i) (void *)(i) | 137 | #define ACPI_PHYSADDR_TO_PTR(i) (void *)(i) |
130 | #define ACPI_PTR_TO_PHYSADDR(i) (u32) (char *)(i) | 138 | #define ACPI_PTR_TO_PHYSADDR(i) (u32) ACPI_CAST_PTR (u8,(i)) |
131 | #else | 139 | #else |
132 | #define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) | 140 | #define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) |
133 | #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i) | 141 | #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i) |
@@ -202,7 +210,7 @@ | |||
202 | 210 | ||
203 | #define ACPI_BUFFER_INDEX(buf_len,buf_offset,byte_gran) (buf_offset) | 211 | #define ACPI_BUFFER_INDEX(buf_len,buf_offset,byte_gran) (buf_offset) |
204 | 212 | ||
205 | #ifdef ACPI_MISALIGNED_TRANSFERS | 213 | #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED |
206 | 214 | ||
207 | /* The hardware supports unaligned transfers, just do the little-endian move */ | 215 | /* The hardware supports unaligned transfers, just do the little-endian move */ |
208 | 216 | ||
@@ -326,6 +334,10 @@ | |||
326 | #define ACPI_MUL_16(a) _ACPI_MUL(a,4) | 334 | #define ACPI_MUL_16(a) _ACPI_MUL(a,4) |
327 | #define ACPI_MOD_16(a) _ACPI_MOD(a,16) | 335 | #define ACPI_MOD_16(a) _ACPI_MOD(a,16) |
328 | 336 | ||
337 | #define ACPI_DIV_32(a) _ACPI_DIV(a,5) | ||
338 | #define ACPI_MUL_32(a) _ACPI_MUL(a,5) | ||
339 | #define ACPI_MOD_32(a) _ACPI_MOD(a,32) | ||
340 | |||
329 | /* | 341 | /* |
330 | * Rounding macros (Power of two boundaries only) | 342 | * Rounding macros (Power of two boundaries only) |
331 | */ | 343 | */ |
@@ -365,6 +377,13 @@ | |||
365 | #define ACPI_REGISTER_PREPARE_BITS(val, pos, mask) ((val << pos) & mask) | 377 | #define ACPI_REGISTER_PREPARE_BITS(val, pos, mask) ((val << pos) & mask) |
366 | #define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val) reg = (reg & (~(mask))) | ACPI_REGISTER_PREPARE_BITS(val, pos, mask) | 378 | #define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val) reg = (reg & (~(mask))) | ACPI_REGISTER_PREPARE_BITS(val, pos, mask) |
367 | 379 | ||
380 | /* Generate a UUID */ | ||
381 | |||
382 | #define ACPI_INIT_UUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \ | ||
383 | (b) & 0xFF, ((b) >> 8) & 0xFF, \ | ||
384 | (c) & 0xFF, ((c) >> 8) & 0xFF, \ | ||
385 | (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) | ||
386 | |||
368 | /* | 387 | /* |
369 | * An struct acpi_namespace_node * can appear in some contexts, | 388 | * An struct acpi_namespace_node * can appear in some contexts, |
370 | * where a pointer to an union acpi_operand_object can also | 389 | * where a pointer to an union acpi_operand_object can also |
@@ -424,56 +443,66 @@ | |||
424 | #define INCREMENT_ARG_LIST(list) (list >>= ((u32) ARG_TYPE_WIDTH)) | 443 | #define INCREMENT_ARG_LIST(list) (list >>= ((u32) ARG_TYPE_WIDTH)) |
425 | 444 | ||
426 | /* | 445 | /* |
427 | * Reporting macros that are never compiled out | 446 | * Module name is include in both debug and non-debug versions primarily for |
447 | * error messages. The __FILE__ macro is not very useful for this, because it | ||
448 | * often includes the entire pathname to the module | ||
428 | */ | 449 | */ |
429 | #define ACPI_PARAM_LIST(pl) pl | 450 | #if defined (ACPI_DEBUG_OUTPUT) || !defined (ACPI_NO_ERROR_MESSAGES) |
451 | |||
452 | #define ACPI_MODULE_NAME(name) static char ACPI_UNUSED_VAR *_acpi_module_name = name; | ||
453 | #else | ||
454 | #define ACPI_MODULE_NAME(name) | ||
455 | #endif | ||
430 | 456 | ||
431 | /* | 457 | /* |
432 | * Error reporting. These versions add callers module and line#. | 458 | * Ascii error messages can be configured out |
433 | * | ||
434 | * Since _acpi_module_name gets compiled out when ACPI_DEBUG_OUTPUT | ||
435 | * isn't defined, only use it in debug mode. | ||
436 | */ | 459 | */ |
437 | #ifdef ACPI_DEBUG_OUTPUT | 460 | #ifndef ACPI_NO_ERROR_MESSAGES |
438 | 461 | ||
439 | #define ACPI_REPORT_INFO(fp) {acpi_ut_report_info(_acpi_module_name,__LINE__,_COMPONENT); \ | 462 | #define ACPI_PARAM_LIST(pl) pl |
440 | acpi_os_printf ACPI_PARAM_LIST(fp);} | 463 | #define ACPI_LOCATION_INFO _acpi_module_name, __LINE__ |
441 | #define ACPI_REPORT_ERROR(fp) {acpi_ut_report_error(_acpi_module_name,__LINE__,_COMPONENT); \ | ||
442 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
443 | #define ACPI_REPORT_WARNING(fp) {acpi_ut_report_warning(_acpi_module_name,__LINE__,_COMPONENT); \ | ||
444 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
445 | #define ACPI_REPORT_NSERROR(s,e) acpi_ns_report_error(_acpi_module_name,__LINE__,_COMPONENT, s, e); | ||
446 | |||
447 | #define ACPI_REPORT_METHOD_ERROR(s,n,p,e) acpi_ns_report_method_error(_acpi_module_name,__LINE__,_COMPONENT, s, n, p, e); | ||
448 | 464 | ||
465 | /* | ||
466 | * Error reporting. Callers module and line number are inserted automatically | ||
467 | * These macros are used for both the debug and non-debug versions of the code | ||
468 | */ | ||
469 | #define ACPI_REPORT_INFO(fp) {acpi_ut_report_info (ACPI_LOCATION_INFO); \ | ||
470 | acpi_os_printf ACPI_PARAM_LIST (fp);} | ||
471 | #define ACPI_REPORT_ERROR(fp) {acpi_ut_report_error (ACPI_LOCATION_INFO); \ | ||
472 | acpi_os_printf ACPI_PARAM_LIST (fp);} | ||
473 | #define ACPI_REPORT_WARNING(fp) {acpi_ut_report_warning (ACPI_LOCATION_INFO); \ | ||
474 | acpi_os_printf ACPI_PARAM_LIST (fp);} | ||
475 | #define ACPI_REPORT_NSERROR(s,e) acpi_ns_report_error (ACPI_LOCATION_INFO, \ | ||
476 | s, e); | ||
477 | #define ACPI_REPORT_MTERROR(s,n,p,e) acpi_ns_report_method_error (ACPI_LOCATION_INFO, \ | ||
478 | s, n, p, e); | ||
479 | |||
480 | /* Error reporting. These versions pass thru the module and lineno */ | ||
481 | |||
482 | #define _ACPI_REPORT_INFO(a,b,fp) {acpi_ut_report_info (a,b); \ | ||
483 | acpi_os_printf ACPI_PARAM_LIST (fp);} | ||
484 | #define _ACPI_REPORT_ERROR(a,b,fp) {acpi_ut_report_error (a,b); \ | ||
485 | acpi_os_printf ACPI_PARAM_LIST (fp);} | ||
486 | #define _ACPI_REPORT_WARNING(a,b,fp) {acpi_ut_report_warning (a,b); \ | ||
487 | acpi_os_printf ACPI_PARAM_LIST (fp);} | ||
449 | #else | 488 | #else |
450 | 489 | ||
451 | #define ACPI_REPORT_INFO(fp) {acpi_ut_report_info("ACPI",__LINE__,_COMPONENT); \ | 490 | /* No error messages */ |
452 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
453 | #define ACPI_REPORT_ERROR(fp) {acpi_ut_report_error("ACPI",__LINE__,_COMPONENT); \ | ||
454 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
455 | #define ACPI_REPORT_WARNING(fp) {acpi_ut_report_warning("ACPI",__LINE__,_COMPONENT); \ | ||
456 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
457 | #define ACPI_REPORT_NSERROR(s,e) acpi_ns_report_error("ACPI",__LINE__,_COMPONENT, s, e); | ||
458 | |||
459 | #define ACPI_REPORT_METHOD_ERROR(s,n,p,e) acpi_ns_report_method_error("ACPI",__LINE__,_COMPONENT, s, n, p, e); | ||
460 | 491 | ||
492 | #define ACPI_REPORT_INFO(fp) | ||
493 | #define ACPI_REPORT_ERROR(fp) | ||
494 | #define ACPI_REPORT_WARNING(fp) | ||
495 | #define ACPI_REPORT_NSERROR(s,e) | ||
496 | #define ACPI_REPORT_MTERROR(s,n,p,e) | ||
497 | #define _ACPI_REPORT_INFO(a,b,c,fp) | ||
498 | #define _ACPI_REPORT_ERROR(a,b,c,fp) | ||
499 | #define _ACPI_REPORT_WARNING(a,b,c,fp) | ||
461 | #endif | 500 | #endif |
462 | 501 | ||
463 | /* Error reporting. These versions pass thru the module and line# */ | ||
464 | |||
465 | #define _ACPI_REPORT_INFO(a,b,c,fp) {acpi_ut_report_info(a,b,c); \ | ||
466 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
467 | #define _ACPI_REPORT_ERROR(a,b,c,fp) {acpi_ut_report_error(a,b,c); \ | ||
468 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
469 | #define _ACPI_REPORT_WARNING(a,b,c,fp) {acpi_ut_report_warning(a,b,c); \ | ||
470 | acpi_os_printf ACPI_PARAM_LIST(fp);} | ||
471 | |||
472 | /* | 502 | /* |
473 | * Debug macros that are conditionally compiled | 503 | * Debug macros that are conditionally compiled |
474 | */ | 504 | */ |
475 | #ifdef ACPI_DEBUG_OUTPUT | 505 | #ifdef ACPI_DEBUG_OUTPUT |
476 | #define ACPI_MODULE_NAME(name) static char ACPI_UNUSED_VAR *_acpi_module_name = name; | ||
477 | 506 | ||
478 | /* | 507 | /* |
479 | * Common parameters used for debug output functions: | 508 | * Common parameters used for debug output functions: |
@@ -525,6 +554,9 @@ | |||
525 | * bad form, but having a separate exit macro is very ugly and difficult to maintain. | 554 | * bad form, but having a separate exit macro is very ugly and difficult to maintain. |
526 | * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros | 555 | * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros |
527 | * so that "_acpi_function_name" is defined. | 556 | * so that "_acpi_function_name" is defined. |
557 | * | ||
558 | * Note: the DO_WHILE0 macro is used to prevent some compilers from complaining | ||
559 | * about these constructs. | ||
528 | */ | 560 | */ |
529 | #ifdef ACPI_USE_DO_WHILE_0 | 561 | #ifdef ACPI_USE_DO_WHILE_0 |
530 | #define ACPI_DO_WHILE0(a) do a while(0) | 562 | #define ACPI_DO_WHILE0(a) do a while(0) |
@@ -532,10 +564,55 @@ | |||
532 | #define ACPI_DO_WHILE0(a) a | 564 | #define ACPI_DO_WHILE0(a) a |
533 | #endif | 565 | #endif |
534 | 566 | ||
535 | #define return_VOID ACPI_DO_WHILE0 ({acpi_ut_exit(ACPI_DEBUG_PARAMETERS);return;}) | 567 | #define return_VOID ACPI_DO_WHILE0 ({ \ |
536 | #define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({acpi_ut_status_exit(ACPI_DEBUG_PARAMETERS,(s));return((s));}) | 568 | acpi_ut_exit (ACPI_DEBUG_PARAMETERS); \ |
537 | #define return_VALUE(s) ACPI_DO_WHILE0 ({acpi_ut_value_exit(ACPI_DEBUG_PARAMETERS,(acpi_integer)(s));return((s));}) | 569 | return;}) |
538 | #define return_PTR(s) ACPI_DO_WHILE0 ({acpi_ut_ptr_exit(ACPI_DEBUG_PARAMETERS,(u8 *)(s));return((s));}) | 570 | /* |
571 | * There are two versions of most of the return macros. The default version is | ||
572 | * safer, since it avoids side-effects by guaranteeing that the argument will | ||
573 | * not be evaluated twice. | ||
574 | * | ||
575 | * A less-safe version of the macros is provided for optional use if the | ||
576 | * compiler uses excessive CPU stack (for example, this may happen in the | ||
577 | * debug case if code optimzation is disabled.) | ||
578 | */ | ||
579 | #ifndef ACPI_SIMPLE_RETURN_MACROS | ||
580 | |||
581 | #define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({ \ | ||
582 | register acpi_status _s = (s); \ | ||
583 | acpi_ut_status_exit (ACPI_DEBUG_PARAMETERS, _s); \ | ||
584 | return (_s); }) | ||
585 | #define return_PTR(s) ACPI_DO_WHILE0 ({ \ | ||
586 | register void *_s = (void *) (s); \ | ||
587 | acpi_ut_ptr_exit (ACPI_DEBUG_PARAMETERS, (u8 *) _s); \ | ||
588 | return (_s); }) | ||
589 | #define return_VALUE(s) ACPI_DO_WHILE0 ({ \ | ||
590 | register acpi_integer _s = (s); \ | ||
591 | acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, _s); \ | ||
592 | return (_s); }) | ||
593 | #define return_UINT8(s) ACPI_DO_WHILE0 ({ \ | ||
594 | register u8 _s = (u8) (s); \ | ||
595 | acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, (acpi_integer) _s); \ | ||
596 | return (_s); }) | ||
597 | #define return_UINT32(s) ACPI_DO_WHILE0 ({ \ | ||
598 | register u32 _s = (u32) (s); \ | ||
599 | acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, (acpi_integer) _s); \ | ||
600 | return (_s); }) | ||
601 | #else /* Use original less-safe macros */ | ||
602 | |||
603 | #define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({ \ | ||
604 | acpi_ut_status_exit (ACPI_DEBUG_PARAMETERS, (s)); \ | ||
605 | return((s)); }) | ||
606 | #define return_PTR(s) ACPI_DO_WHILE0 ({ \ | ||
607 | acpi_ut_ptr_exit (ACPI_DEBUG_PARAMETERS, (u8 *) (s)); \ | ||
608 | return((s)); }) | ||
609 | #define return_VALUE(s) ACPI_DO_WHILE0 ({ \ | ||
610 | acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, (acpi_integer) (s)); \ | ||
611 | return((s)); }) | ||
612 | #define return_UINT8(s) return_VALUE(s) | ||
613 | #define return_UINT32(s) return_VALUE(s) | ||
614 | |||
615 | #endif /* ACPI_SIMPLE_RETURN_MACROS */ | ||
539 | 616 | ||
540 | /* Conditional execution */ | 617 | /* Conditional execution */ |
541 | 618 | ||
@@ -582,9 +659,6 @@ | |||
582 | * This is the non-debug case -- make everything go away, | 659 | * This is the non-debug case -- make everything go away, |
583 | * leaving no executable debug code! | 660 | * leaving no executable debug code! |
584 | */ | 661 | */ |
585 | #define ACPI_MODULE_NAME(name) | ||
586 | #define _acpi_module_name "" | ||
587 | |||
588 | #define ACPI_DEBUG_EXEC(a) | 662 | #define ACPI_DEBUG_EXEC(a) |
589 | #define ACPI_NORMAL_EXEC(a) a; | 663 | #define ACPI_NORMAL_EXEC(a) a; |
590 | 664 | ||
@@ -612,6 +686,8 @@ | |||
612 | #define return_VOID return | 686 | #define return_VOID return |
613 | #define return_ACPI_STATUS(s) return(s) | 687 | #define return_ACPI_STATUS(s) return(s) |
614 | #define return_VALUE(s) return(s) | 688 | #define return_VALUE(s) return(s) |
689 | #define return_UINT8(s) return(s) | ||
690 | #define return_UINT32(s) return(s) | ||
615 | #define return_PTR(s) return(s) | 691 | #define return_PTR(s) return(s) |
616 | 692 | ||
617 | #endif | 693 | #endif |