Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPICA 20050617-0624 from Bob Moore <robert.moore@intel.com>

ACPICA 20050617:

Moved the object cache operations into the OS interface
layer (OSL) to allow the host OS to handle these operations
if desired (for example, the Linux OSL will invoke the
slab allocator). This support is optional; the compile
time define ACPI_USE_LOCAL_CACHE may be used to utilize
the original cache code in the ACPI CA core. The new OSL
interfaces are shown below. See utalloc.c for an example
implementation, and acpiosxf.h for the exact interface
definitions. Thanks to Alexey Starikovskiy.
acpi_os_create_cache
acpi_os_delete_cache
acpi_os_purge_cache
acpi_os_acquire_object
acpi_os_release_object

Modified the interfaces to acpi_os_acquire_lock and
acpi_os_release_lock to return and restore a flags
parameter. This fits better with many OS lock models.
Note: the current execution state (interrupt handler
or not) is no longer passed to these interfaces. If
necessary, the OSL must determine this state by itself, a
simple and fast operation. Thanks to Alexey Starikovskiy.

Fixed a problem in the ACPI table handling where a valid
XSDT was assumed present if the revision of the RSDP
was 2 or greater. According to the ACPI specification,
the XSDT is optional in all cases, and the table manager
therefore now checks for both an RSDP >=2 and a valid
XSDT pointer. Otherwise, the RSDT pointer is used.
Some ACPI 2.0 compliant BIOSs contain only the RSDT.

Fixed an interpreter problem with the Mid() operator in the
case of an input string where the resulting output string
is of zero length. It now correctly returns a valid,
null terminated string object instead of a string object
with a null pointer.

Fixed a problem with the control method argument handling
to allow a store to an Arg object that already contains an
object of type Device. The Device object is now correctly
overwritten. Previously, an error was returned.

ACPICA 20050624:

Modified the new OSL cache interfaces to use ACPI_CACHE_T
as the type for the host-defined cache object. This allows
the OSL implementation to define and type this object in
any manner desired, simplifying the OSL implementation.
For example, ACPI_CACHE_T is defined as kmem_cache_t for
Linux, and should be defined in the OS-specific header
file for other operating systems as required.

Changed the interface to AcpiOsAcquireObject to directly
return the requested object as the function return (instead
of ACPI_STATUS.) This change was made for performance
reasons, since this is the purpose of the interface in the
first place. acpi_os_acquire_object is now similar to the
acpi_os_allocate interface. Thanks to Alexey Starikovskiy.

Modified the initialization sequence in
acpi_initialize_subsystem to call the OSL interface
acpi_osl_initialize first, before any local initialization.
This change was required because the global initialization
now calls OSL interfaces.

Restructured the code base to split some files because
of size and/or because the code logically belonged in a
separate file. New files are listed below.

utilities/utcache.c /* Local cache interfaces */
utilities/utmutex.c /* Local mutex support */
utilities/utstate.c /* State object support */
parser/psloop.c /* Main AML parse loop */

Signed-off-by: Len Brown <len.brown@intel.com>

authored by

Robert Moore and committed by
Len Brown
73459f73 88ac00f5

+2631 -2040
+2 -13
drivers/acpi/dispatcher/dsmthdat.c
··· 633 633 */ 634 634 if (opcode == AML_ARG_OP) { 635 635 /* 636 - * Make sure that the object is the correct type. This may be 637 - * overkill, butit is here because references were NS nodes in 638 - * the past. Now they are operand objects of type Reference. 639 - */ 640 - if (ACPI_GET_DESCRIPTOR_TYPE (current_obj_desc) != ACPI_DESC_TYPE_OPERAND) { 641 - ACPI_REPORT_ERROR (( 642 - "Invalid descriptor type while storing to method arg: [%s]\n", 643 - acpi_ut_get_descriptor_name (current_obj_desc))); 644 - return_ACPI_STATUS (AE_AML_INTERNAL); 645 - } 646 - 647 - /* 648 636 * If we have a valid reference object that came from ref_of(), 649 637 * do the indirect store 650 638 */ 651 - if ((current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && 639 + if ((ACPI_GET_DESCRIPTOR_TYPE (current_obj_desc) == ACPI_DESC_TYPE_OPERAND) && 640 + (current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && 652 641 (current_obj_desc->reference.opcode == AML_REF_OF_OP)) { 653 642 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 654 643 "Arg (%p) is an obj_ref(Node), storing in node %p\n",
+3 -3
drivers/acpi/dispatcher/dswload.c
··· 50 50 #include <acpi/acnamesp.h> 51 51 #include <acpi/acevents.h> 52 52 53 - #ifdef _ACPI_ASL_COMPILER 53 + #ifdef ACPI_ASL_COMPILER 54 54 #include <acpi/acdisasm.h> 55 55 #endif 56 56 ··· 176 176 */ 177 177 status = acpi_ns_lookup (walk_state->scope_info, path, object_type, 178 178 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 179 - #ifdef _ACPI_ASL_COMPILER 179 + #ifdef ACPI_ASL_COMPILER 180 180 if (status == AE_NOT_FOUND) { 181 181 /* 182 182 * Table disassembly: ··· 569 569 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, 570 570 walk_state, &(node)); 571 571 if (ACPI_FAILURE (status)) { 572 - #ifdef _ACPI_ASL_COMPILER 572 + #ifdef ACPI_ASL_COMPILER 573 573 if (status == AE_NOT_FOUND) { 574 574 status = AE_OK; 575 575 }
+3 -30
drivers/acpi/dispatcher/dswstate.c
··· 681 681 ACPI_FUNCTION_TRACE ("ds_create_walk_state"); 682 682 683 683 684 - walk_state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_WALK); 684 + walk_state = ACPI_MEM_CALLOCATE (sizeof (struct acpi_walk_state)); 685 685 if (!walk_state) { 686 686 return_PTR (NULL); 687 687 } ··· 704 704 705 705 status = acpi_ds_result_stack_push (walk_state); 706 706 if (ACPI_FAILURE (status)) { 707 - acpi_ut_release_to_cache (ACPI_MEM_LIST_WALK, walk_state); 707 + ACPI_MEM_FREE (walk_state); 708 708 return_PTR (NULL); 709 709 } 710 710 ··· 900 900 acpi_ut_delete_generic_state (state); 901 901 } 902 902 903 - acpi_ut_release_to_cache (ACPI_MEM_LIST_WALK, walk_state); 903 + ACPI_MEM_FREE (walk_state); 904 904 return_VOID; 905 905 } 906 - 907 - 908 - #ifdef ACPI_ENABLE_OBJECT_CACHE 909 - /****************************************************************************** 910 - * 911 - * FUNCTION: acpi_ds_delete_walk_state_cache 912 - * 913 - * PARAMETERS: None 914 - * 915 - * RETURN: None 916 - * 917 - * DESCRIPTION: Purge the global state object cache. Used during subsystem 918 - * termination. 919 - * 920 - ******************************************************************************/ 921 - 922 - void 923 - acpi_ds_delete_walk_state_cache ( 924 - void) 925 - { 926 - ACPI_FUNCTION_TRACE ("ds_delete_walk_state_cache"); 927 - 928 - 929 - acpi_ut_delete_generic_cache (ACPI_MEM_LIST_WALK); 930 - return_VOID; 931 - } 932 - #endif 933 906 934 907 935 908 #ifdef ACPI_OBSOLETE_FUNCTIONS
+3 -2
drivers/acpi/events/evgpe.c
··· 396 396 struct acpi_gpe_register_info *gpe_register_info; 397 397 u32 status_reg; 398 398 u32 enable_reg; 399 + u32 flags; 399 400 acpi_status status; 400 401 struct acpi_gpe_block_info *gpe_block; 401 402 acpi_native_uint i; ··· 413 412 414 413 /* Examine all GPE blocks attached to this interrupt level */ 415 414 416 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_ISR); 415 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 417 416 gpe_block = gpe_xrupt_list->gpe_block_list_head; 418 417 while (gpe_block) { 419 418 /* ··· 477 476 478 477 unlock_and_exit: 479 478 480 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_ISR); 479 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 481 480 return (int_status); 482 481 } 483 482
+15 -12
drivers/acpi/events/evgpeblk.c
··· 138 138 * FUNCTION: acpi_ev_walk_gpe_list 139 139 * 140 140 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block 141 - * Flags - ACPI_NOT_ISR or ACPI_ISR 142 141 * 143 142 * RETURN: Status 144 143 * ··· 147 148 148 149 acpi_status 149 150 acpi_ev_walk_gpe_list ( 150 - ACPI_GPE_CALLBACK gpe_walk_callback, 151 - u32 flags) 151 + ACPI_GPE_CALLBACK gpe_walk_callback) 152 152 { 153 153 struct acpi_gpe_block_info *gpe_block; 154 154 struct acpi_gpe_xrupt_info *gpe_xrupt_info; 155 155 acpi_status status = AE_OK; 156 + u32 flags; 156 157 157 158 158 159 ACPI_FUNCTION_TRACE ("ev_walk_gpe_list"); 159 160 160 161 161 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, flags); 162 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 162 163 163 164 /* Walk the interrupt level descriptor list */ 164 165 ··· 499 500 struct acpi_gpe_xrupt_info *next_gpe_xrupt; 500 501 struct acpi_gpe_xrupt_info *gpe_xrupt; 501 502 acpi_status status; 503 + u32 flags; 502 504 503 505 504 506 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block"); ··· 527 527 528 528 /* Install new interrupt descriptor with spin lock */ 529 529 530 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 530 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 531 531 if (acpi_gbl_gpe_xrupt_list_head) { 532 532 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; 533 533 while (next_gpe_xrupt->next) { ··· 540 540 else { 541 541 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt; 542 542 } 543 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 543 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 544 544 545 545 /* Install new interrupt handler if not SCI_INT */ 546 546 ··· 577 577 struct acpi_gpe_xrupt_info *gpe_xrupt) 578 578 { 579 579 acpi_status status; 580 + u32 flags; 580 581 581 582 582 583 ACPI_FUNCTION_TRACE ("ev_delete_gpe_xrupt"); ··· 600 599 601 600 /* Unlink the interrupt block with lock */ 602 601 603 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 602 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 604 603 if (gpe_xrupt->previous) { 605 604 gpe_xrupt->previous->next = gpe_xrupt->next; 606 605 } ··· 608 607 if (gpe_xrupt->next) { 609 608 gpe_xrupt->next->previous = gpe_xrupt->previous; 610 609 } 611 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 610 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 612 611 613 612 /* Free the block */ 614 613 ··· 638 637 struct acpi_gpe_block_info *next_gpe_block; 639 638 struct acpi_gpe_xrupt_info *gpe_xrupt_block; 640 639 acpi_status status; 640 + u32 flags; 641 641 642 642 643 643 ACPI_FUNCTION_TRACE ("ev_install_gpe_block"); ··· 657 655 658 656 /* Install the new block at the end of the list with lock */ 659 657 660 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 658 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 661 659 if (gpe_xrupt_block->gpe_block_list_head) { 662 660 next_gpe_block = gpe_xrupt_block->gpe_block_list_head; 663 661 while (next_gpe_block->next) { ··· 672 670 } 673 671 674 672 gpe_block->xrupt_block = gpe_xrupt_block; 675 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 673 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 676 674 677 675 unlock_and_exit: 678 676 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); ··· 697 695 struct acpi_gpe_block_info *gpe_block) 698 696 { 699 697 acpi_status status; 698 + u32 flags; 700 699 701 700 702 701 ACPI_FUNCTION_TRACE ("ev_install_gpe_block"); ··· 723 720 else { 724 721 /* Remove the block on this interrupt with lock */ 725 722 726 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 723 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 727 724 if (gpe_block->previous) { 728 725 gpe_block->previous->next = gpe_block->next; 729 726 } ··· 734 731 if (gpe_block->next) { 735 732 gpe_block->next->previous = gpe_block->previous; 736 733 } 737 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 734 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 738 735 } 739 736 740 737 /* Free the gpe_block */
+2 -2
drivers/acpi/events/evmisc.c
··· 589 589 590 590 /* Disable all GPEs in all GPE blocks */ 591 591 592 - status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, ACPI_NOT_ISR); 592 + status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block); 593 593 594 594 /* Remove SCI handler */ 595 595 ··· 602 602 603 603 /* Deallocate all handler objects installed within GPE info structs */ 604 604 605 - status = acpi_ev_walk_gpe_list (acpi_ev_delete_gpe_handlers, ACPI_NOT_ISR); 605 + status = acpi_ev_walk_gpe_list (acpi_ev_delete_gpe_handlers); 606 606 607 607 /* Return to original mode if necessary */ 608 608
+6 -4
drivers/acpi/events/evxface.c
··· 591 591 struct acpi_gpe_event_info *gpe_event_info; 592 592 struct acpi_handler_info *handler; 593 593 acpi_status status; 594 + u32 flags; 594 595 595 596 596 597 ACPI_FUNCTION_TRACE ("acpi_install_gpe_handler"); ··· 644 643 645 644 /* Install the handler */ 646 645 647 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 646 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 648 647 gpe_event_info->dispatch.handler = handler; 649 648 650 649 /* Setup up dispatch flags to indicate handler (vs. method) */ ··· 652 651 gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */ 653 652 gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); 654 653 655 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 654 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 656 655 657 656 658 657 unlock_and_exit: ··· 686 685 struct acpi_gpe_event_info *gpe_event_info; 687 686 struct acpi_handler_info *handler; 688 687 acpi_status status; 688 + u32 flags; 689 689 690 690 691 691 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_handler"); ··· 743 741 744 742 /* Remove the handler */ 745 743 746 - acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 744 + flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock); 747 745 handler = gpe_event_info->dispatch.handler; 748 746 749 747 /* Restore Method node (if any), set dispatch flags */ ··· 753 751 if (handler->method_node) { 754 752 gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD; 755 753 } 756 - acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 754 + acpi_os_release_lock (acpi_gbl_gpe_lock, flags); 757 755 758 756 /* Now we can free the handler object */ 759 757
+1 -1
drivers/acpi/executer/exconvrt.c
··· 367 367 368 368 /* hex_length: 2 ascii hex chars per data byte */ 369 369 370 - hex_length = ACPI_MUL_2 (data_width); 370 + hex_length = (acpi_native_uint) ACPI_MUL_2 (data_width); 371 371 for (i = 0, j = (hex_length-1); i < hex_length; i++, j--) { 372 372 /* Get one hex digit, most significant digits first */ 373 373
+152 -22
drivers/acpi/executer/exdump.c
··· 80 80 acpi_physical_address value); 81 81 #endif /* ACPI_FUTURE_USAGE */ 82 82 83 + static void 84 + acpi_ex_dump_reference ( 85 + union acpi_operand_object *obj_desc); 86 + 87 + static void 88 + acpi_ex_dump_package ( 89 + union acpi_operand_object *obj_desc, 90 + u32 level, 91 + u32 index); 92 + 83 93 84 94 /******************************************************************************* 85 95 * ··· 518 508 char *title, 519 509 u32 value) 520 510 { 521 - acpi_os_printf ("%20s : %X\n", title, value); 511 + acpi_os_printf ("%20s : %.2X\n", title, value); 522 512 } 523 513 524 514 static void ··· 575 565 576 566 /******************************************************************************* 577 567 * 568 + * FUNCTION: acpi_ex_dump_reference 569 + * 570 + * PARAMETERS: Object - Descriptor to dump 571 + * 572 + * DESCRIPTION: Dumps a reference object 573 + * 574 + ******************************************************************************/ 575 + 576 + static void 577 + acpi_ex_dump_reference ( 578 + union acpi_operand_object *obj_desc) 579 + { 580 + struct acpi_buffer ret_buf; 581 + acpi_status status; 582 + 583 + 584 + if (obj_desc->reference.opcode == AML_INT_NAMEPATH_OP) { 585 + acpi_os_printf ("Named Object %p ", obj_desc->reference.node); 586 + ret_buf.length = ACPI_ALLOCATE_LOCAL_BUFFER; 587 + status = acpi_ns_handle_to_pathname (obj_desc->reference.node, &ret_buf); 588 + if (ACPI_FAILURE (status)) { 589 + acpi_os_printf ("Could not convert name to pathname\n"); 590 + } 591 + else { 592 + acpi_os_printf ("%s\n", ret_buf.pointer); 593 + ACPI_MEM_FREE (ret_buf.pointer); 594 + } 595 + } 596 + else if (obj_desc->reference.object) { 597 + acpi_os_printf ("\nReferenced Object: %p\n", obj_desc->reference.object); 598 + } 599 + } 600 + 601 + 602 + /******************************************************************************* 603 + * 604 + * FUNCTION: acpi_ex_dump_package 605 + * 606 + * PARAMETERS: Object - Descriptor to dump 607 + * Level - Indentation Level 608 + * Index - Package index for this object 609 + * 610 + * DESCRIPTION: Dumps the elements of the package 611 + * 612 + ******************************************************************************/ 613 + 614 + static void 615 + acpi_ex_dump_package ( 616 + union acpi_operand_object *obj_desc, 617 + u32 level, 618 + u32 index) 619 + { 620 + u32 i; 621 + 622 + 623 + /* Indentation and index output */ 624 + 625 + if (level > 0) { 626 + for (i = 0; i < level; i++) { 627 + acpi_os_printf (" "); 628 + } 629 + 630 + acpi_os_printf ("[%.2d] ", index); 631 + } 632 + 633 + acpi_os_printf ("%p ", obj_desc); 634 + 635 + /* Null package elements are allowed */ 636 + 637 + if (!obj_desc) { 638 + acpi_os_printf ("[Null Object]\n"); 639 + return; 640 + } 641 + 642 + /* Packages may only contain a few object types */ 643 + 644 + switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 645 + case ACPI_TYPE_INTEGER: 646 + 647 + acpi_os_printf ("[Integer] = %8.8X%8.8X\n", 648 + ACPI_FORMAT_UINT64 (obj_desc->integer.value)); 649 + break; 650 + 651 + 652 + case ACPI_TYPE_STRING: 653 + 654 + acpi_os_printf ("[String] Value: "); 655 + for (i = 0; i < obj_desc->string.length; i++) { 656 + acpi_os_printf ("%c", obj_desc->string.pointer[i]); 657 + } 658 + acpi_os_printf ("\n"); 659 + break; 660 + 661 + 662 + case ACPI_TYPE_BUFFER: 663 + 664 + acpi_os_printf ("[Buffer] Length %.2X = ", obj_desc->buffer.length); 665 + if (obj_desc->buffer.length) { 666 + acpi_ut_dump_buffer ((u8 *) obj_desc->buffer.pointer, 667 + obj_desc->buffer.length, DB_DWORD_DISPLAY, _COMPONENT); 668 + } 669 + else { 670 + acpi_os_printf ("\n"); 671 + } 672 + break; 673 + 674 + 675 + case ACPI_TYPE_PACKAGE: 676 + 677 + acpi_os_printf ("[Package] Contains %d Elements: \n", 678 + obj_desc->package.count); 679 + 680 + for (i = 0; i < obj_desc->package.count; i++) { 681 + acpi_ex_dump_package (obj_desc->package.elements[i], level+1, i); 682 + } 683 + break; 684 + 685 + 686 + case ACPI_TYPE_LOCAL_REFERENCE: 687 + 688 + acpi_os_printf ("[Object Reference] "); 689 + acpi_ex_dump_reference (obj_desc); 690 + break; 691 + 692 + 693 + default: 694 + 695 + acpi_os_printf ("[Unknown Type] %X\n", ACPI_GET_OBJECT_TYPE (obj_desc)); 696 + break; 697 + } 698 + } 699 + 700 + 701 + /******************************************************************************* 702 + * 578 703 * FUNCTION: acpi_ex_dump_object_descriptor 579 704 * 580 - * PARAMETERS: *Object - Descriptor to dump 705 + * PARAMETERS: Object - Descriptor to dump 581 706 * Flags - Force display if TRUE 582 707 * 583 708 * DESCRIPTION: Dumps the members of the object descriptor given. ··· 724 579 union acpi_operand_object *obj_desc, 725 580 u32 flags) 726 581 { 727 - u32 i; 728 - 729 - 730 582 ACPI_FUNCTION_TRACE ("ex_dump_object_descriptor"); 731 583 732 584 ··· 790 648 case ACPI_TYPE_PACKAGE: 791 649 792 650 acpi_ex_out_integer ("Flags", obj_desc->package.flags); 793 - acpi_ex_out_integer ("Count", obj_desc->package.count); 794 - acpi_ex_out_pointer ("Elements", obj_desc->package.elements); 651 + acpi_ex_out_integer ("Elements", obj_desc->package.count); 652 + acpi_ex_out_pointer ("Element List", obj_desc->package.elements); 795 653 796 654 /* Dump the package contents */ 797 655 798 - if (obj_desc->package.count > 0) { 799 - acpi_os_printf ("\nPackage Contents:\n"); 800 - for (i = 0; i < obj_desc->package.count; i++) { 801 - acpi_os_printf ("[%.3d] %p", i, obj_desc->package.elements[i]); 802 - if (obj_desc->package.elements[i]) { 803 - acpi_os_printf (" %s", 804 - acpi_ut_get_object_type_name (obj_desc->package.elements[i])); 805 - } 806 - acpi_os_printf ("\n"); 807 - } 808 - } 656 + acpi_os_printf ("\nPackage Contents:\n"); 657 + acpi_ex_dump_package (obj_desc, 0, 0); 809 658 break; 810 659 811 660 ··· 923 790 acpi_ex_out_pointer ("Node", obj_desc->reference.node); 924 791 acpi_ex_out_pointer ("Where", obj_desc->reference.where); 925 792 926 - if (obj_desc->reference.object) { 927 - acpi_os_printf ("\nReferenced Object:\n"); 928 - acpi_ex_dump_object_descriptor (obj_desc->reference.object, flags); 929 - } 793 + acpi_ex_dump_reference (obj_desc); 930 794 break; 931 795 932 796
+1 -1
drivers/acpi/executer/exmisc.c
··· 302 302 /* Result of two Integers is a Buffer */ 303 303 /* Need enough buffer space for two integers */ 304 304 305 - return_desc = acpi_ut_create_buffer_object ( 305 + return_desc = acpi_ut_create_buffer_object ((acpi_size) 306 306 ACPI_MUL_2 (acpi_gbl_integer_byte_width)); 307 307 if (!return_desc) { 308 308 status = AE_NO_MEMORY;
+2 -1
drivers/acpi/executer/exoparg1.c
··· 113 113 status = AE_NO_MEMORY; 114 114 goto cleanup; 115 115 } 116 - 116 + #if ACPI_MACHINE_WIDTH != 16 117 117 return_desc->integer.value = acpi_os_get_timer (); 118 + #endif 118 119 break; 119 120 120 121 default: /* Unknown opcode */
+46 -17
drivers/acpi/executer/exoparg3.c
··· 160 160 { 161 161 union acpi_operand_object **operand = &walk_state->operands[0]; 162 162 union acpi_operand_object *return_desc = NULL; 163 - char *buffer; 163 + char *buffer = NULL; 164 164 acpi_status status = AE_OK; 165 165 acpi_integer index; 166 166 acpi_size length; ··· 193 193 * If the index is beyond the length of the String/Buffer, or if the 194 194 * requested length is zero, return a zero-length String/Buffer 195 195 */ 196 - if ((index < operand[0]->string.length) && 197 - (length > 0)) { 198 - /* Truncate request if larger than the actual String/Buffer */ 196 + if (index >= operand[0]->string.length) { 197 + length = 0; 198 + } 199 199 200 - if ((index + length) > 201 - operand[0]->string.length) { 202 - length = (acpi_size) operand[0]->string.length - 203 - (acpi_size) index; 204 - } 200 + /* Truncate request if larger than the actual String/Buffer */ 205 201 206 - /* Allocate a new buffer for the String/Buffer */ 202 + else if ((index + length) > operand[0]->string.length) { 203 + length = (acpi_size) operand[0]->string.length - 204 + (acpi_size) index; 205 + } 206 + 207 + /* Strings always have a sub-pointer, not so for buffers */ 208 + 209 + switch (ACPI_GET_OBJECT_TYPE (operand[0])) { 210 + case ACPI_TYPE_STRING: 211 + 212 + /* Always allocate a new buffer for the String */ 207 213 208 214 buffer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1); 209 215 if (!buffer) { 210 216 status = AE_NO_MEMORY; 211 217 goto cleanup; 212 218 } 219 + break; 213 220 221 + case ACPI_TYPE_BUFFER: 222 + 223 + /* If the requested length is zero, don't allocate a buffer */ 224 + 225 + if (length > 0) { 226 + /* Allocate a new buffer for the Buffer */ 227 + 228 + buffer = ACPI_MEM_CALLOCATE (length); 229 + if (!buffer) { 230 + status = AE_NO_MEMORY; 231 + goto cleanup; 232 + } 233 + } 234 + break; 235 + 236 + default: /* Should not happen */ 237 + 238 + status = AE_AML_OPERAND_TYPE; 239 + goto cleanup; 240 + } 241 + 242 + if (length > 0) { 214 243 /* Copy the portion requested */ 215 244 216 245 ACPI_MEMCPY (buffer, operand[0]->string.pointer + index, 217 246 length); 218 - 219 - /* Set the length of the new String/Buffer */ 220 - 221 - return_desc->string.pointer = buffer; 222 - return_desc->string.length = (u32) length; 223 247 } 248 + 249 + /* Set the length of the new String/Buffer */ 250 + 251 + return_desc->string.pointer = buffer; 252 + return_desc->string.length = (u32) length; 224 253 225 254 /* Mark buffer initialized */ 226 255 ··· 273 244 274 245 /* Delete return object on error */ 275 246 276 - if (ACPI_FAILURE (status)) { 247 + if (ACPI_FAILURE (status) || walk_state->result_obj) { 277 248 acpi_ut_remove_reference (return_desc); 278 249 } 279 250 280 251 /* Set the return object and exit */ 281 252 282 - if (!walk_state->result_obj) { 253 + else { 283 254 walk_state->result_obj = return_desc; 284 255 } 285 256 return_ACPI_STATUS (status);
+1 -1
drivers/acpi/executer/exstore.c
··· 147 147 148 148 case ACPI_TYPE_BUFFER: 149 149 150 - ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]", 150 + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n", 151 151 (u32) source_desc->buffer.length)); 152 152 ACPI_DUMP_BUFFER (source_desc->buffer.pointer, 153 153 (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
+1 -1
drivers/acpi/executer/exutils.c
··· 369 369 * 370 370 * RETURN: None, string 371 371 * 372 - * DESCRIPTOIN: Convert a number to string representation. Assumes string 372 + * DESCRIPTION: Convert a number to string representation. Assumes string 373 373 * buffer is large enough to hold the string. 374 374 * 375 375 ******************************************************************************/
+10 -10
drivers/acpi/hardware/hwgpe.c
··· 374 374 * 375 375 * FUNCTION: acpi_hw_disable_all_gpes 376 376 * 377 - * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR 377 + * PARAMETERS: None 378 378 * 379 379 * RETURN: Status 380 380 * ··· 384 384 385 385 acpi_status 386 386 acpi_hw_disable_all_gpes ( 387 - u32 flags) 387 + void) 388 388 { 389 389 acpi_status status; 390 390 ··· 392 392 ACPI_FUNCTION_TRACE ("hw_disable_all_gpes"); 393 393 394 394 395 - status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, flags); 396 - status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, flags); 395 + status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block); 396 + status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block); 397 397 return_ACPI_STATUS (status); 398 398 } 399 399 ··· 402 402 * 403 403 * FUNCTION: acpi_hw_enable_all_runtime_gpes 404 404 * 405 - * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR 405 + * PARAMETERS: None 406 406 * 407 407 * RETURN: Status 408 408 * ··· 412 412 413 413 acpi_status 414 414 acpi_hw_enable_all_runtime_gpes ( 415 - u32 flags) 415 + void) 416 416 { 417 417 acpi_status status; 418 418 ··· 420 420 ACPI_FUNCTION_TRACE ("hw_enable_all_runtime_gpes"); 421 421 422 422 423 - status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block, flags); 423 + status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block); 424 424 return_ACPI_STATUS (status); 425 425 } 426 426 ··· 429 429 * 430 430 * FUNCTION: acpi_hw_enable_all_wakeup_gpes 431 431 * 432 - * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR 432 + * PARAMETERS: None 433 433 * 434 434 * RETURN: Status 435 435 * ··· 439 439 440 440 acpi_status 441 441 acpi_hw_enable_all_wakeup_gpes ( 442 - u32 flags) 442 + void) 443 443 { 444 444 acpi_status status; 445 445 ··· 447 447 ACPI_FUNCTION_TRACE ("hw_enable_all_wakeup_gpes"); 448 448 449 449 450 - status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block, flags); 450 + status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block); 451 451 return_ACPI_STATUS (status); 452 452 } 453 453
+1 -1
drivers/acpi/hardware/hwregs.c
··· 106 106 107 107 /* Clear the GPE Bits in all GPE registers in all GPE blocks */ 108 108 109 - status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, ACPI_ISR); 109 + status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block); 110 110 111 111 unlock_and_exit: 112 112 if (flags & ACPI_MTX_LOCK) {
+6 -6
drivers/acpi/hardware/hwsleep.c
··· 274 274 * 1) Disable/Clear all GPEs 275 275 * 2) Enable all wakeup GPEs 276 276 */ 277 - status = acpi_hw_disable_all_gpes (ACPI_ISR); 277 + status = acpi_hw_disable_all_gpes (); 278 278 if (ACPI_FAILURE (status)) { 279 279 return_ACPI_STATUS (status); 280 280 } 281 281 acpi_gbl_system_awake_and_running = FALSE; 282 282 283 - status = acpi_hw_enable_all_wakeup_gpes (ACPI_ISR); 283 + status = acpi_hw_enable_all_wakeup_gpes (); 284 284 if (ACPI_FAILURE (status)) { 285 285 return_ACPI_STATUS (status); 286 286 } ··· 424 424 * 1) Disable/Clear all GPEs 425 425 * 2) Enable all wakeup GPEs 426 426 */ 427 - status = acpi_hw_disable_all_gpes (ACPI_ISR); 427 + status = acpi_hw_disable_all_gpes (); 428 428 if (ACPI_FAILURE (status)) { 429 429 return_ACPI_STATUS (status); 430 430 } 431 431 acpi_gbl_system_awake_and_running = FALSE; 432 432 433 - status = acpi_hw_enable_all_wakeup_gpes (ACPI_ISR); 433 + status = acpi_hw_enable_all_wakeup_gpes (); 434 434 if (ACPI_FAILURE (status)) { 435 435 return_ACPI_STATUS (status); 436 436 } ··· 557 557 * 1) Disable/Clear all GPEs 558 558 * 2) Enable all runtime GPEs 559 559 */ 560 - status = acpi_hw_disable_all_gpes (ACPI_NOT_ISR); 560 + status = acpi_hw_disable_all_gpes (); 561 561 if (ACPI_FAILURE (status)) { 562 562 return_ACPI_STATUS (status); 563 563 } 564 564 acpi_gbl_system_awake_and_running = TRUE; 565 565 566 - status = acpi_hw_enable_all_runtime_gpes (ACPI_NOT_ISR); 566 + status = acpi_hw_enable_all_runtime_gpes (); 567 567 if (ACPI_FAILURE (status)) { 568 568 return_ACPI_STATUS (status); 569 569 }
+1 -1
drivers/acpi/namespace/nsaccess.c
··· 159 159 obj_desc->method.param_count = (u8) ACPI_TO_INTEGER (val); 160 160 obj_desc->common.flags |= AOPOBJ_DATA_VALID; 161 161 162 - #if defined (_ACPI_ASL_COMPILER) || defined (_ACPI_DUMP_App) 162 + #if defined (ACPI_ASL_COMPILER) || defined (ACPI_DUMP_App) 163 163 164 164 /* 165 165 * i_aSL Compiler cheats by putting parameter count
+3 -3
drivers/acpi/namespace/nsalloc.c
··· 83 83 return_PTR (NULL); 84 84 } 85 85 86 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_allocated++); 86 + ACPI_MEM_TRACKING (acpi_gbl_ns_node_list->total_allocated++); 87 87 88 88 node->name.integer = name; 89 89 node->reference_count = 1; ··· 151 151 } 152 152 } 153 153 154 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_freed++); 154 + ACPI_MEM_TRACKING (acpi_gbl_ns_node_list->total_freed++); 155 155 156 156 /* 157 157 * Detach an object if there is one then delete the node ··· 362 362 363 363 /* Now we can free this child object */ 364 364 365 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_freed++); 365 + ACPI_MEM_TRACKING (acpi_gbl_ns_node_list->total_freed++); 366 366 367 367 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p, Remaining %X\n", 368 368 child_node, acpi_gbl_current_node_count));
+17 -13
drivers/acpi/namespace/nsdump.c
··· 208 208 return (AE_OK); 209 209 } 210 210 211 - /* Indent the object according to the level */ 211 + if (!(info->display_type & ACPI_DISPLAY_SHORT)) { 212 + /* Indent the object according to the level */ 212 213 213 - acpi_os_printf ("%2d%*s", (u32) level - 1, (int) level * 2, " "); 214 + acpi_os_printf ("%2d%*s", (u32) level - 1, (int) level * 2, " "); 214 215 215 - /* Check the node type and name */ 216 + /* Check the node type and name */ 216 217 217 - if (type > ACPI_TYPE_LOCAL_MAX) { 218 - ACPI_REPORT_WARNING (("Invalid ACPI Type %08X\n", type)); 219 - } 218 + if (type > ACPI_TYPE_LOCAL_MAX) { 219 + ACPI_REPORT_WARNING (("Invalid ACPI Type %08X\n", type)); 220 + } 220 221 221 - if (!acpi_ut_valid_acpi_name (this_node->name.integer)) { 222 - ACPI_REPORT_WARNING (("Invalid ACPI Name %08X\n", 223 - this_node->name.integer)); 222 + if (!acpi_ut_valid_acpi_name (this_node->name.integer)) { 223 + ACPI_REPORT_WARNING (("Invalid ACPI Name %08X\n", 224 + this_node->name.integer)); 225 + } 226 + 227 + acpi_os_printf ("%4.4s", acpi_ut_get_node_name (this_node)); 224 228 } 225 229 226 230 /* 227 231 * Now we can print out the pertinent information 228 232 */ 229 - acpi_os_printf ("%4.4s %-12s %p ", 230 - acpi_ut_get_node_name (this_node), acpi_ut_get_type_name (type), this_node); 233 + acpi_os_printf (" %-12s %p ", 234 + acpi_ut_get_type_name (type), this_node); 231 235 232 236 dbg_level = acpi_dbg_level; 233 237 acpi_dbg_level = 0; 234 238 obj_desc = acpi_ns_get_attached_object (this_node); 235 239 acpi_dbg_level = dbg_level; 236 240 237 - switch (info->display_type) { 241 + switch (info->display_type & ACPI_DISPLAY_MASK) { 238 242 case ACPI_DISPLAY_SUMMARY: 239 243 240 244 if (!obj_desc) { ··· 650 646 } 651 647 652 648 653 - #ifdef _ACPI_ASL_COMPILER 649 + #ifdef ACPI_ASL_COMPILER 654 650 /******************************************************************************* 655 651 * 656 652 * FUNCTION: acpi_ns_dump_tables
+148 -48
drivers/acpi/osl.c
··· 778 778 return_VOID; 779 779 } 780 780 781 - /* 782 - * Acquire a spinlock. 783 - * 784 - * handle is a pointer to the spinlock_t. 785 - * flags is *not* the result of save_flags - it is an ACPI-specific flag variable 786 - * that indicates whether we are at interrupt level. 787 - */ 788 - void 789 - acpi_os_acquire_lock ( 790 - acpi_handle handle, 791 - u32 flags) 792 - { 793 - ACPI_FUNCTION_TRACE ("os_acquire_lock"); 794 - 795 - ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Acquiring spinlock[%p] from %s level\n", handle, 796 - ((flags & ACPI_NOT_ISR) ? "non-interrupt" : "interrupt"))); 797 - 798 - if (flags & ACPI_NOT_ISR) 799 - ACPI_DISABLE_IRQS(); 800 - 801 - spin_lock((spinlock_t *)handle); 802 - 803 - return_VOID; 804 - } 805 - 806 - 807 - /* 808 - * Release a spinlock. See above. 809 - */ 810 - void 811 - acpi_os_release_lock ( 812 - acpi_handle handle, 813 - u32 flags) 814 - { 815 - ACPI_FUNCTION_TRACE ("os_release_lock"); 816 - 817 - ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Releasing spinlock[%p] from %s level\n", handle, 818 - ((flags & ACPI_NOT_ISR) ? "non-interrupt" : "interrupt"))); 819 - 820 - spin_unlock((spinlock_t *)handle); 821 - 822 - if (flags & ACPI_NOT_ISR) 823 - ACPI_ENABLE_IRQS(); 824 - 825 - return_VOID; 826 - } 827 - 828 - 829 781 acpi_status 830 782 acpi_os_create_semaphore( 831 783 u32 max_units, ··· 1124 1172 1125 1173 1126 1174 EXPORT_SYMBOL(max_cstate); 1175 + 1176 + /* 1177 + * Acquire a spinlock. 1178 + * 1179 + * handle is a pointer to the spinlock_t. 1180 + * flags is *not* the result of save_flags - it is an ACPI-specific flag variable 1181 + * that indicates whether we are at interrupt level. 1182 + */ 1183 + 1184 + unsigned long 1185 + acpi_os_acquire_lock ( 1186 + acpi_handle handle) 1187 + { 1188 + unsigned long flags; 1189 + spin_lock_irqsave((spinlock_t *)handle, flags); 1190 + return flags; 1191 + } 1192 + 1193 + /* 1194 + * Release a spinlock. See above. 1195 + */ 1196 + 1197 + void 1198 + acpi_os_release_lock ( 1199 + acpi_handle handle, 1200 + unsigned long flags) 1201 + { 1202 + spin_unlock_irqrestore((spinlock_t *)handle, flags); 1203 + } 1204 + 1205 + 1206 + #ifndef ACPI_USE_LOCAL_CACHE 1207 + 1208 + /******************************************************************************* 1209 + * 1210 + * FUNCTION: acpi_os_create_cache 1211 + * 1212 + * PARAMETERS: CacheName - Ascii name for the cache 1213 + * ObjectSize - Size of each cached object 1214 + * MaxDepth - Maximum depth of the cache (in objects) 1215 + * ReturnCache - Where the new cache object is returned 1216 + * 1217 + * RETURN: Status 1218 + * 1219 + * DESCRIPTION: Create a cache object 1220 + * 1221 + ******************************************************************************/ 1222 + 1223 + acpi_status 1224 + acpi_os_create_cache ( 1225 + char *name, 1226 + u16 size, 1227 + u16 depth, 1228 + acpi_cache_t **cache) 1229 + { 1230 + *cache = kmem_cache_create (name, size, 0, 0, NULL, NULL); 1231 + return AE_OK; 1232 + } 1233 + 1234 + /******************************************************************************* 1235 + * 1236 + * FUNCTION: acpi_os_purge_cache 1237 + * 1238 + * PARAMETERS: Cache - Handle to cache object 1239 + * 1240 + * RETURN: Status 1241 + * 1242 + * DESCRIPTION: Free all objects within the requested cache. 1243 + * 1244 + ******************************************************************************/ 1245 + 1246 + acpi_status 1247 + acpi_os_purge_cache ( 1248 + acpi_cache_t *cache) 1249 + { 1250 + (void) kmem_cache_shrink(cache); 1251 + return (AE_OK); 1252 + } 1253 + 1254 + /******************************************************************************* 1255 + * 1256 + * FUNCTION: acpi_os_delete_cache 1257 + * 1258 + * PARAMETERS: Cache - Handle to cache object 1259 + * 1260 + * RETURN: Status 1261 + * 1262 + * DESCRIPTION: Free all objects within the requested cache and delete the 1263 + * cache object. 1264 + * 1265 + ******************************************************************************/ 1266 + 1267 + acpi_status 1268 + acpi_os_delete_cache ( 1269 + acpi_cache_t *cache) 1270 + { 1271 + (void)kmem_cache_destroy(cache); 1272 + return (AE_OK); 1273 + } 1274 + 1275 + /******************************************************************************* 1276 + * 1277 + * FUNCTION: acpi_os_release_object 1278 + * 1279 + * PARAMETERS: Cache - Handle to cache object 1280 + * Object - The object to be released 1281 + * 1282 + * RETURN: None 1283 + * 1284 + * DESCRIPTION: Release an object to the specified cache. If cache is full, 1285 + * the object is deleted. 1286 + * 1287 + ******************************************************************************/ 1288 + 1289 + acpi_status 1290 + acpi_os_release_object ( 1291 + acpi_cache_t *cache, 1292 + void *object) 1293 + { 1294 + kmem_cache_free(cache, object); 1295 + return (AE_OK); 1296 + } 1297 + 1298 + /******************************************************************************* 1299 + * 1300 + * FUNCTION: acpi_os_acquire_object 1301 + * 1302 + * PARAMETERS: Cache - Handle to cache object 1303 + * ReturnObject - Where the object is returned 1304 + * 1305 + * RETURN: Status 1306 + * 1307 + * DESCRIPTION: Get an object from the specified cache. If cache is empty, 1308 + * the object is allocated. 1309 + * 1310 + ******************************************************************************/ 1311 + 1312 + void * 1313 + acpi_os_acquire_object ( 1314 + acpi_cache_t *cache) 1315 + { 1316 + void *object = kmem_cache_alloc(cache, GFP_KERNEL); 1317 + WARN_ON(!object); 1318 + return object; 1319 + } 1320 + 1321 + #endif 1322 +
+1 -1
drivers/acpi/parser/Makefile
··· 2 2 # Makefile for all Linux ACPI interpreter subdirectories 3 3 # 4 4 5 - obj-y := psargs.o psparse.o pstree.o pswalk.o \ 5 + obj-y := psargs.o psparse.o psloop.o pstree.o pswalk.o \ 6 6 psopcode.o psscope.o psutils.o psxface.o 7 7 8 8 EXTRA_CFLAGS += $(ACPI_CFLAGS)
+775
drivers/acpi/parser/psloop.c
··· 1 + /****************************************************************************** 2 + * 3 + * Module Name: psloop - Main AML parse loop 4 + * 5 + *****************************************************************************/ 6 + 7 + /* 8 + * Copyright (C) 2000 - 2005, R. Byron Moore 9 + * All rights reserved. 10 + * 11 + * Redistribution and use in source and binary forms, with or without 12 + * modification, are permitted provided that the following conditions 13 + * are met: 14 + * 1. Redistributions of source code must retain the above copyright 15 + * notice, this list of conditions, and the following disclaimer, 16 + * without modification. 17 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 + * substantially similar to the "NO WARRANTY" disclaimer below 19 + * ("Disclaimer") and any redistribution must be conditioned upon 20 + * including a substantially similar Disclaimer requirement for further 21 + * binary redistribution. 22 + * 3. Neither the names of the above-listed copyright holders nor the names 23 + * of any contributors may be used to endorse or promote products derived 24 + * from this software without specific prior written permission. 25 + * 26 + * Alternatively, this software may be distributed under the terms of the 27 + * GNU General Public License ("GPL") version 2 as published by the Free 28 + * Software Foundation. 29 + * 30 + * NO WARRANTY 31 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 + * POSSIBILITY OF SUCH DAMAGES. 42 + */ 43 + 44 + 45 + /* 46 + * Parse the AML and build an operation tree as most interpreters, 47 + * like Perl, do. Parsing is done by hand rather than with a YACC 48 + * generated parser to tightly constrain stack and dynamic memory 49 + * usage. At the same time, parsing is kept flexible and the code 50 + * fairly compact by parsing based on a list of AML opcode 51 + * templates in aml_op_info[] 52 + */ 53 + 54 + #include <acpi/acpi.h> 55 + #include <acpi/acparser.h> 56 + #include <acpi/acdispat.h> 57 + #include <acpi/amlcode.h> 58 + #include <acpi/acnamesp.h> 59 + #include <acpi/acinterp.h> 60 + 61 + #define _COMPONENT ACPI_PARSER 62 + ACPI_MODULE_NAME ("psloop") 63 + 64 + static u32 acpi_gbl_depth = 0; 65 + 66 + 67 + /******************************************************************************* 68 + * 69 + * FUNCTION: acpi_ps_parse_loop 70 + * 71 + * PARAMETERS: walk_state - Current state 72 + * 73 + * RETURN: Status 74 + * 75 + * DESCRIPTION: Parse AML (pointed to by the current parser state) and return 76 + * a tree of ops. 77 + * 78 + ******************************************************************************/ 79 + 80 + acpi_status 81 + acpi_ps_parse_loop ( 82 + struct acpi_walk_state *walk_state) 83 + { 84 + acpi_status status = AE_OK; 85 + acpi_status status2; 86 + union acpi_parse_object *op = NULL; /* current op */ 87 + union acpi_parse_object *arg = NULL; 88 + union acpi_parse_object *pre_op = NULL; 89 + struct acpi_parse_state *parser_state; 90 + u8 *aml_op_start = NULL; 91 + 92 + 93 + ACPI_FUNCTION_TRACE_PTR ("ps_parse_loop", walk_state); 94 + 95 + if (walk_state->descending_callback == NULL) { 96 + return_ACPI_STATUS (AE_BAD_PARAMETER); 97 + } 98 + 99 + parser_state = &walk_state->parser_state; 100 + walk_state->arg_types = 0; 101 + 102 + #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 103 + 104 + if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { 105 + /* We are restarting a preempted control method */ 106 + 107 + if (acpi_ps_has_completed_scope (parser_state)) { 108 + /* 109 + * We must check if a predicate to an IF or WHILE statement 110 + * was just completed 111 + */ 112 + if ((parser_state->scope->parse_scope.op) && 113 + ((parser_state->scope->parse_scope.op->common.aml_opcode == AML_IF_OP) || 114 + (parser_state->scope->parse_scope.op->common.aml_opcode == AML_WHILE_OP)) && 115 + (walk_state->control_state) && 116 + (walk_state->control_state->common.state == 117 + ACPI_CONTROL_PREDICATE_EXECUTING)) { 118 + /* 119 + * A predicate was just completed, get the value of the 120 + * predicate and branch based on that value 121 + */ 122 + walk_state->op = NULL; 123 + status = acpi_ds_get_predicate_value (walk_state, ACPI_TO_POINTER (TRUE)); 124 + if (ACPI_FAILURE (status) && 125 + ((status & AE_CODE_MASK) != AE_CODE_CONTROL)) { 126 + if (status == AE_AML_NO_RETURN_VALUE) { 127 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 128 + "Invoked method did not return a value, %s\n", 129 + acpi_format_exception (status))); 130 + 131 + } 132 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 133 + "get_predicate Failed, %s\n", 134 + acpi_format_exception (status))); 135 + return_ACPI_STATUS (status); 136 + } 137 + 138 + status = acpi_ps_next_parse_state (walk_state, op, status); 139 + } 140 + 141 + acpi_ps_pop_scope (parser_state, &op, 142 + &walk_state->arg_types, &walk_state->arg_count); 143 + ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); 144 + } 145 + else if (walk_state->prev_op) { 146 + /* We were in the middle of an op */ 147 + 148 + op = walk_state->prev_op; 149 + walk_state->arg_types = walk_state->prev_arg_types; 150 + } 151 + } 152 + #endif 153 + 154 + /* Iterative parsing loop, while there is more AML to process: */ 155 + 156 + while ((parser_state->aml < parser_state->aml_end) || (op)) { 157 + aml_op_start = parser_state->aml; 158 + if (!op) { 159 + /* Get the next opcode from the AML stream */ 160 + 161 + walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 162 + parser_state->aml_start); 163 + walk_state->opcode = acpi_ps_peek_opcode (parser_state); 164 + 165 + /* 166 + * First cut to determine what we have found: 167 + * 1) A valid AML opcode 168 + * 2) A name string 169 + * 3) An unknown/invalid opcode 170 + */ 171 + walk_state->op_info = acpi_ps_get_opcode_info (walk_state->opcode); 172 + switch (walk_state->op_info->class) { 173 + case AML_CLASS_ASCII: 174 + case AML_CLASS_PREFIX: 175 + /* 176 + * Starts with a valid prefix or ASCII char, this is a name 177 + * string. Convert the bare name string to a namepath. 178 + */ 179 + walk_state->opcode = AML_INT_NAMEPATH_OP; 180 + walk_state->arg_types = ARGP_NAMESTRING; 181 + break; 182 + 183 + case AML_CLASS_UNKNOWN: 184 + 185 + /* The opcode is unrecognized. Just skip unknown opcodes */ 186 + 187 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 188 + "Found unknown opcode %X at AML address %p offset %X, ignoring\n", 189 + walk_state->opcode, parser_state->aml, walk_state->aml_offset)); 190 + 191 + ACPI_DUMP_BUFFER (parser_state->aml, 128); 192 + 193 + /* Assume one-byte bad opcode */ 194 + 195 + parser_state->aml++; 196 + continue; 197 + 198 + default: 199 + 200 + /* Found opcode info, this is a normal opcode */ 201 + 202 + parser_state->aml += acpi_ps_get_opcode_size (walk_state->opcode); 203 + walk_state->arg_types = walk_state->op_info->parse_args; 204 + break; 205 + } 206 + 207 + /* Create Op structure and append to parent's argument list */ 208 + 209 + if (walk_state->op_info->flags & AML_NAMED) { 210 + /* Allocate a new pre_op if necessary */ 211 + 212 + if (!pre_op) { 213 + pre_op = acpi_ps_alloc_op (walk_state->opcode); 214 + if (!pre_op) { 215 + status = AE_NO_MEMORY; 216 + goto close_this_op; 217 + } 218 + } 219 + 220 + pre_op->common.value.arg = NULL; 221 + pre_op->common.aml_opcode = walk_state->opcode; 222 + 223 + /* 224 + * Get and append arguments until we find the node that contains 225 + * the name (the type ARGP_NAME). 226 + */ 227 + while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && 228 + (GET_CURRENT_ARG_TYPE (walk_state->arg_types) != ARGP_NAME)) { 229 + status = acpi_ps_get_next_arg (walk_state, parser_state, 230 + GET_CURRENT_ARG_TYPE (walk_state->arg_types), &arg); 231 + if (ACPI_FAILURE (status)) { 232 + goto close_this_op; 233 + } 234 + 235 + acpi_ps_append_arg (pre_op, arg); 236 + INCREMENT_ARG_LIST (walk_state->arg_types); 237 + } 238 + 239 + /* 240 + * Make sure that we found a NAME and didn't run out of 241 + * arguments 242 + */ 243 + if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) { 244 + status = AE_AML_NO_OPERAND; 245 + goto close_this_op; 246 + } 247 + 248 + /* We know that this arg is a name, move to next arg */ 249 + 250 + INCREMENT_ARG_LIST (walk_state->arg_types); 251 + 252 + /* 253 + * Find the object. This will either insert the object into 254 + * the namespace or simply look it up 255 + */ 256 + walk_state->op = NULL; 257 + 258 + status = walk_state->descending_callback (walk_state, &op); 259 + if (ACPI_FAILURE (status)) { 260 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 261 + "During name lookup/catalog, %s\n", 262 + acpi_format_exception (status))); 263 + goto close_this_op; 264 + } 265 + 266 + if (!op) { 267 + continue; 268 + } 269 + 270 + status = acpi_ps_next_parse_state (walk_state, op, status); 271 + if (status == AE_CTRL_PENDING) { 272 + status = AE_OK; 273 + goto close_this_op; 274 + } 275 + 276 + if (ACPI_FAILURE (status)) { 277 + goto close_this_op; 278 + } 279 + 280 + acpi_ps_append_arg (op, pre_op->common.value.arg); 281 + acpi_gbl_depth++; 282 + 283 + if (op->common.aml_opcode == AML_REGION_OP) { 284 + /* 285 + * Defer final parsing of an operation_region body, 286 + * because we don't have enough info in the first pass 287 + * to parse it correctly (i.e., there may be method 288 + * calls within the term_arg elements of the body.) 289 + * 290 + * However, we must continue parsing because 291 + * the opregion is not a standalone package -- 292 + * we don't know where the end is at this point. 293 + * 294 + * (Length is unknown until parse of the body complete) 295 + */ 296 + op->named.data = aml_op_start; 297 + op->named.length = 0; 298 + } 299 + } 300 + else { 301 + /* Not a named opcode, just allocate Op and append to parent */ 302 + 303 + walk_state->op_info = acpi_ps_get_opcode_info (walk_state->opcode); 304 + op = acpi_ps_alloc_op (walk_state->opcode); 305 + if (!op) { 306 + status = AE_NO_MEMORY; 307 + goto close_this_op; 308 + } 309 + 310 + if (walk_state->op_info->flags & AML_CREATE) { 311 + /* 312 + * Backup to beginning of create_xXXfield declaration 313 + * body_length is unknown until we parse the body 314 + */ 315 + op->named.data = aml_op_start; 316 + op->named.length = 0; 317 + } 318 + 319 + acpi_ps_append_arg (acpi_ps_get_parent_scope (parser_state), op); 320 + 321 + if ((walk_state->descending_callback != NULL)) { 322 + /* 323 + * Find the object. This will either insert the object into 324 + * the namespace or simply look it up 325 + */ 326 + walk_state->op = op; 327 + 328 + status = walk_state->descending_callback (walk_state, &op); 329 + status = acpi_ps_next_parse_state (walk_state, op, status); 330 + if (status == AE_CTRL_PENDING) { 331 + status = AE_OK; 332 + goto close_this_op; 333 + } 334 + 335 + if (ACPI_FAILURE (status)) { 336 + goto close_this_op; 337 + } 338 + } 339 + } 340 + 341 + op->common.aml_offset = walk_state->aml_offset; 342 + 343 + if (walk_state->op_info) { 344 + ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 345 + "Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n", 346 + (u32) op->common.aml_opcode, walk_state->op_info->name, 347 + op, parser_state->aml, op->common.aml_offset)); 348 + } 349 + } 350 + 351 + 352 + /* 353 + * Start arg_count at zero because we don't know if there are 354 + * any args yet 355 + */ 356 + walk_state->arg_count = 0; 357 + 358 + /* Are there any arguments that must be processed? */ 359 + 360 + if (walk_state->arg_types) { 361 + /* Get arguments */ 362 + 363 + switch (op->common.aml_opcode) { 364 + case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ 365 + case AML_WORD_OP: /* AML_WORDDATA_ARG */ 366 + case AML_DWORD_OP: /* AML_DWORDATA_ARG */ 367 + case AML_QWORD_OP: /* AML_QWORDATA_ARG */ 368 + case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */ 369 + 370 + /* Fill in constant or string argument directly */ 371 + 372 + acpi_ps_get_next_simple_arg (parser_state, 373 + GET_CURRENT_ARG_TYPE (walk_state->arg_types), op); 374 + break; 375 + 376 + case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ 377 + 378 + status = acpi_ps_get_next_namepath (walk_state, parser_state, op, 1); 379 + if (ACPI_FAILURE (status)) { 380 + goto close_this_op; 381 + } 382 + 383 + walk_state->arg_types = 0; 384 + break; 385 + 386 + default: 387 + /* 388 + * Op is not a constant or string, append each argument 389 + * to the Op 390 + */ 391 + while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && 392 + !walk_state->arg_count) { 393 + walk_state->aml_offset = (u32) 394 + ACPI_PTR_DIFF (parser_state->aml, parser_state->aml_start); 395 + 396 + status = acpi_ps_get_next_arg (walk_state, parser_state, 397 + GET_CURRENT_ARG_TYPE (walk_state->arg_types), 398 + &arg); 399 + if (ACPI_FAILURE (status)) { 400 + goto close_this_op; 401 + } 402 + 403 + if (arg) { 404 + arg->common.aml_offset = walk_state->aml_offset; 405 + acpi_ps_append_arg (op, arg); 406 + } 407 + INCREMENT_ARG_LIST (walk_state->arg_types); 408 + } 409 + 410 + /* Special processing for certain opcodes */ 411 + 412 + if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS1) && 413 + ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) { 414 + /* 415 + * We want to skip If/Else/While constructs during Pass1 416 + * because we want to actually conditionally execute the 417 + * code during Pass2. 418 + * 419 + * Except for disassembly, where we always want to 420 + * walk the If/Else/While packages 421 + */ 422 + switch (op->common.aml_opcode) { 423 + case AML_IF_OP: 424 + case AML_ELSE_OP: 425 + case AML_WHILE_OP: 426 + 427 + /* Skip body of if/else/while in pass 1 */ 428 + 429 + parser_state->aml = parser_state->pkg_end; 430 + walk_state->arg_count = 0; 431 + break; 432 + 433 + default: 434 + break; 435 + } 436 + } 437 + 438 + switch (op->common.aml_opcode) { 439 + case AML_METHOD_OP: 440 + 441 + /* 442 + * Skip parsing of control method 443 + * because we don't have enough info in the first pass 444 + * to parse it correctly. 445 + * 446 + * Save the length and address of the body 447 + */ 448 + op->named.data = parser_state->aml; 449 + op->named.length = (u32) (parser_state->pkg_end - 450 + parser_state->aml); 451 + 452 + /* Skip body of method */ 453 + 454 + parser_state->aml = parser_state->pkg_end; 455 + walk_state->arg_count = 0; 456 + break; 457 + 458 + case AML_BUFFER_OP: 459 + case AML_PACKAGE_OP: 460 + case AML_VAR_PACKAGE_OP: 461 + 462 + if ((op->common.parent) && 463 + (op->common.parent->common.aml_opcode == AML_NAME_OP) && 464 + (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2)) { 465 + /* 466 + * Skip parsing of Buffers and Packages 467 + * because we don't have enough info in the first pass 468 + * to parse them correctly. 469 + */ 470 + op->named.data = aml_op_start; 471 + op->named.length = (u32) (parser_state->pkg_end - 472 + aml_op_start); 473 + 474 + /* Skip body */ 475 + 476 + parser_state->aml = parser_state->pkg_end; 477 + walk_state->arg_count = 0; 478 + } 479 + break; 480 + 481 + case AML_WHILE_OP: 482 + 483 + if (walk_state->control_state) { 484 + walk_state->control_state->control.package_end = 485 + parser_state->pkg_end; 486 + } 487 + break; 488 + 489 + default: 490 + 491 + /* No action for all other opcodes */ 492 + break; 493 + } 494 + break; 495 + } 496 + } 497 + 498 + /* Check for arguments that need to be processed */ 499 + 500 + if (walk_state->arg_count) { 501 + /* 502 + * There are arguments (complex ones), push Op and 503 + * prepare for argument 504 + */ 505 + status = acpi_ps_push_scope (parser_state, op, 506 + walk_state->arg_types, walk_state->arg_count); 507 + if (ACPI_FAILURE (status)) { 508 + goto close_this_op; 509 + } 510 + op = NULL; 511 + continue; 512 + } 513 + 514 + /* 515 + * All arguments have been processed -- Op is complete, 516 + * prepare for next 517 + */ 518 + walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 519 + if (walk_state->op_info->flags & AML_NAMED) { 520 + if (acpi_gbl_depth) { 521 + acpi_gbl_depth--; 522 + } 523 + 524 + if (op->common.aml_opcode == AML_REGION_OP) { 525 + /* 526 + * Skip parsing of control method or opregion body, 527 + * because we don't have enough info in the first pass 528 + * to parse them correctly. 529 + * 530 + * Completed parsing an op_region declaration, we now 531 + * know the length. 532 + */ 533 + op->named.length = (u32) (parser_state->aml - op->named.data); 534 + } 535 + } 536 + 537 + if (walk_state->op_info->flags & AML_CREATE) { 538 + /* 539 + * Backup to beginning of create_xXXfield declaration (1 for 540 + * Opcode) 541 + * 542 + * body_length is unknown until we parse the body 543 + */ 544 + op->named.length = (u32) (parser_state->aml - op->named.data); 545 + } 546 + 547 + /* This op complete, notify the dispatcher */ 548 + 549 + if (walk_state->ascending_callback != NULL) { 550 + walk_state->op = op; 551 + walk_state->opcode = op->common.aml_opcode; 552 + 553 + status = walk_state->ascending_callback (walk_state); 554 + status = acpi_ps_next_parse_state (walk_state, op, status); 555 + if (status == AE_CTRL_PENDING) { 556 + status = AE_OK; 557 + goto close_this_op; 558 + } 559 + } 560 + 561 + 562 + close_this_op: 563 + /* 564 + * Finished one argument of the containing scope 565 + */ 566 + parser_state->scope->parse_scope.arg_count--; 567 + 568 + /* Finished with pre_op */ 569 + 570 + if (pre_op) { 571 + acpi_ps_free_op (pre_op); 572 + pre_op = NULL; 573 + } 574 + 575 + /* Close this Op (will result in parse subtree deletion) */ 576 + 577 + status2 = acpi_ps_complete_this_op (walk_state, op); 578 + if (ACPI_FAILURE (status2)) { 579 + return_ACPI_STATUS (status2); 580 + } 581 + op = NULL; 582 + 583 + switch (status) { 584 + case AE_OK: 585 + break; 586 + 587 + 588 + case AE_CTRL_TRANSFER: 589 + 590 + /* We are about to transfer to a called method. */ 591 + 592 + walk_state->prev_op = op; 593 + walk_state->prev_arg_types = walk_state->arg_types; 594 + return_ACPI_STATUS (status); 595 + 596 + 597 + case AE_CTRL_END: 598 + 599 + acpi_ps_pop_scope (parser_state, &op, 600 + &walk_state->arg_types, &walk_state->arg_count); 601 + 602 + if (op) { 603 + walk_state->op = op; 604 + walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 605 + walk_state->opcode = op->common.aml_opcode; 606 + 607 + status = walk_state->ascending_callback (walk_state); 608 + status = acpi_ps_next_parse_state (walk_state, op, status); 609 + 610 + status2 = acpi_ps_complete_this_op (walk_state, op); 611 + if (ACPI_FAILURE (status2)) { 612 + return_ACPI_STATUS (status2); 613 + } 614 + op = NULL; 615 + } 616 + status = AE_OK; 617 + break; 618 + 619 + 620 + case AE_CTRL_BREAK: 621 + case AE_CTRL_CONTINUE: 622 + 623 + /* Pop off scopes until we find the While */ 624 + 625 + while (!op || (op->common.aml_opcode != AML_WHILE_OP)) { 626 + acpi_ps_pop_scope (parser_state, &op, 627 + &walk_state->arg_types, &walk_state->arg_count); 628 + } 629 + 630 + /* Close this iteration of the While loop */ 631 + 632 + walk_state->op = op; 633 + walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 634 + walk_state->opcode = op->common.aml_opcode; 635 + 636 + status = walk_state->ascending_callback (walk_state); 637 + status = acpi_ps_next_parse_state (walk_state, op, status); 638 + 639 + status2 = acpi_ps_complete_this_op (walk_state, op); 640 + if (ACPI_FAILURE (status2)) { 641 + return_ACPI_STATUS (status2); 642 + } 643 + op = NULL; 644 + 645 + status = AE_OK; 646 + break; 647 + 648 + 649 + case AE_CTRL_TERMINATE: 650 + 651 + status = AE_OK; 652 + 653 + /* Clean up */ 654 + do { 655 + if (op) { 656 + status2 = acpi_ps_complete_this_op (walk_state, op); 657 + if (ACPI_FAILURE (status2)) { 658 + return_ACPI_STATUS (status2); 659 + } 660 + } 661 + acpi_ps_pop_scope (parser_state, &op, 662 + &walk_state->arg_types, &walk_state->arg_count); 663 + 664 + } while (op); 665 + 666 + return_ACPI_STATUS (status); 667 + 668 + 669 + default: /* All other non-AE_OK status */ 670 + 671 + do { 672 + if (op) { 673 + status2 = acpi_ps_complete_this_op (walk_state, op); 674 + if (ACPI_FAILURE (status2)) { 675 + return_ACPI_STATUS (status2); 676 + } 677 + } 678 + acpi_ps_pop_scope (parser_state, &op, 679 + &walk_state->arg_types, &walk_state->arg_count); 680 + 681 + } while (op); 682 + 683 + 684 + /* 685 + * TBD: Cleanup parse ops on error 686 + */ 687 + #if 0 688 + if (op == NULL) { 689 + acpi_ps_pop_scope (parser_state, &op, 690 + &walk_state->arg_types, &walk_state->arg_count); 691 + } 692 + #endif 693 + walk_state->prev_op = op; 694 + walk_state->prev_arg_types = walk_state->arg_types; 695 + return_ACPI_STATUS (status); 696 + } 697 + 698 + /* This scope complete? */ 699 + 700 + if (acpi_ps_has_completed_scope (parser_state)) { 701 + acpi_ps_pop_scope (parser_state, &op, 702 + &walk_state->arg_types, &walk_state->arg_count); 703 + ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); 704 + } 705 + else { 706 + op = NULL; 707 + } 708 + 709 + } /* while parser_state->Aml */ 710 + 711 + 712 + /* 713 + * Complete the last Op (if not completed), and clear the scope stack. 714 + * It is easily possible to end an AML "package" with an unbounded number 715 + * of open scopes (such as when several ASL blocks are closed with 716 + * sequential closing braces). We want to terminate each one cleanly. 717 + */ 718 + ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", op)); 719 + do { 720 + if (op) { 721 + if (walk_state->ascending_callback != NULL) { 722 + walk_state->op = op; 723 + walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 724 + walk_state->opcode = op->common.aml_opcode; 725 + 726 + status = walk_state->ascending_callback (walk_state); 727 + status = acpi_ps_next_parse_state (walk_state, op, status); 728 + if (status == AE_CTRL_PENDING) { 729 + status = AE_OK; 730 + goto close_this_op; 731 + } 732 + 733 + if (status == AE_CTRL_TERMINATE) { 734 + status = AE_OK; 735 + 736 + /* Clean up */ 737 + do { 738 + if (op) { 739 + status2 = acpi_ps_complete_this_op (walk_state, op); 740 + if (ACPI_FAILURE (status2)) { 741 + return_ACPI_STATUS (status2); 742 + } 743 + } 744 + 745 + acpi_ps_pop_scope (parser_state, &op, 746 + &walk_state->arg_types, &walk_state->arg_count); 747 + 748 + } while (op); 749 + 750 + return_ACPI_STATUS (status); 751 + } 752 + 753 + else if (ACPI_FAILURE (status)) { 754 + /* First error is most important */ 755 + 756 + (void) acpi_ps_complete_this_op (walk_state, op); 757 + return_ACPI_STATUS (status); 758 + } 759 + } 760 + 761 + status2 = acpi_ps_complete_this_op (walk_state, op); 762 + if (ACPI_FAILURE (status2)) { 763 + return_ACPI_STATUS (status2); 764 + } 765 + } 766 + 767 + acpi_ps_pop_scope (parser_state, &op, &walk_state->arg_types, 768 + &walk_state->arg_count); 769 + 770 + } while (op); 771 + 772 + return_ACPI_STATUS (status); 773 + } 774 + 775 +
+11 -21
drivers/acpi/parser/psopcode.c
··· 428 428 /* 429 429 * Detect normal 8-bit opcode or extended 16-bit opcode 430 430 */ 431 - switch ((u8) (opcode >> 8)) { 432 - case 0: 433 - 431 + if (!(opcode & 0xFF00)) { 434 432 /* Simple (8-bit) opcode: 0-255, can't index beyond table */ 435 433 436 434 return (&acpi_gbl_aml_op_info [acpi_gbl_short_op_index [(u8) opcode]]); 437 - 438 - case AML_EXTOP: 439 - 440 - /* Extended (16-bit, prefix+opcode) opcode */ 441 - 442 - if (((u8) opcode) <= MAX_EXTENDED_OPCODE) { 443 - return (&acpi_gbl_aml_op_info [acpi_gbl_long_op_index [(u8) opcode]]); 444 - } 445 - 446 - /* Else fall through to error case below */ 447 - /*lint -fallthrough */ 448 - 449 - default: 450 - 451 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 452 - "Unknown AML opcode [%4.4X]\n", opcode)); 453 - break; 454 435 } 455 436 437 + if (((opcode & 0xFF00) == AML_EXTENDED_OPCODE) && 438 + (((u8) opcode) <= MAX_EXTENDED_OPCODE)) { 439 + /* Valid extended (16-bit) opcode */ 456 440 457 - /* Default is "unknown opcode" */ 441 + return (&acpi_gbl_aml_op_info [acpi_gbl_long_op_index [(u8) opcode]]); 442 + } 443 + 444 + /* Unknown AML opcode */ 445 + 446 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 447 + "Unknown AML opcode [%4.4X]\n", opcode)); 458 448 459 449 return (&acpi_gbl_aml_op_info [_UNK]); 460 450 }
+4 -724
drivers/acpi/parser/psparse.c
··· 62 62 ACPI_MODULE_NAME ("psparse") 63 63 64 64 65 - static u32 acpi_gbl_depth = 0; 66 - 67 - /* Local prototypes */ 68 - 69 - static acpi_status 70 - acpi_ps_complete_this_op ( 71 - struct acpi_walk_state *walk_state, 72 - union acpi_parse_object *op); 73 - 74 - static acpi_status 75 - acpi_ps_next_parse_state ( 76 - struct acpi_walk_state *walk_state, 77 - union acpi_parse_object *op, 78 - acpi_status callback_status); 79 - 80 - static acpi_status 81 - acpi_ps_parse_loop ( 82 - struct acpi_walk_state *walk_state); 83 - 84 - 85 65 /******************************************************************************* 86 66 * 87 67 * FUNCTION: acpi_ps_get_opcode_size ··· 114 134 aml = parser_state->aml; 115 135 opcode = (u16) ACPI_GET8 (aml); 116 136 117 - if (opcode == AML_EXTOP) { 118 - /* Extended opcode */ 137 + if (opcode == AML_EXTENDED_OP_PREFIX) { 138 + /* Extended opcode, get the second opcode byte */ 119 139 120 140 aml++; 121 141 opcode = (u16) ((opcode << 8) | ACPI_GET8 (aml)); ··· 138 158 * 139 159 ******************************************************************************/ 140 160 141 - static acpi_status 161 + acpi_status 142 162 acpi_ps_complete_this_op ( 143 163 struct acpi_walk_state *walk_state, 144 164 union acpi_parse_object *op) ··· 311 331 * 312 332 ******************************************************************************/ 313 333 314 - static acpi_status 334 + acpi_status 315 335 acpi_ps_next_parse_state ( 316 336 struct acpi_walk_state *walk_state, 317 337 union acpi_parse_object *op, ··· 414 434 } 415 435 break; 416 436 } 417 - 418 - return_ACPI_STATUS (status); 419 - } 420 - 421 - 422 - /******************************************************************************* 423 - * 424 - * FUNCTION: acpi_ps_parse_loop 425 - * 426 - * PARAMETERS: walk_state - Current state 427 - * 428 - * RETURN: Status 429 - * 430 - * DESCRIPTION: Parse AML (pointed to by the current parser state) and return 431 - * a tree of ops. 432 - * 433 - ******************************************************************************/ 434 - 435 - static acpi_status 436 - acpi_ps_parse_loop ( 437 - struct acpi_walk_state *walk_state) 438 - { 439 - acpi_status status = AE_OK; 440 - acpi_status status2; 441 - union acpi_parse_object *op = NULL; /* current op */ 442 - union acpi_parse_object *arg = NULL; 443 - union acpi_parse_object *pre_op = NULL; 444 - struct acpi_parse_state *parser_state; 445 - u8 *aml_op_start = NULL; 446 - 447 - 448 - ACPI_FUNCTION_TRACE_PTR ("ps_parse_loop", walk_state); 449 - 450 - if (walk_state->descending_callback == NULL) { 451 - return_ACPI_STATUS (AE_BAD_PARAMETER); 452 - } 453 - 454 - parser_state = &walk_state->parser_state; 455 - walk_state->arg_types = 0; 456 - 457 - #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 458 - 459 - if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { 460 - /* We are restarting a preempted control method */ 461 - 462 - if (acpi_ps_has_completed_scope (parser_state)) { 463 - /* 464 - * We must check if a predicate to an IF or WHILE statement 465 - * was just completed 466 - */ 467 - if ((parser_state->scope->parse_scope.op) && 468 - ((parser_state->scope->parse_scope.op->common.aml_opcode == AML_IF_OP) || 469 - (parser_state->scope->parse_scope.op->common.aml_opcode == AML_WHILE_OP)) && 470 - (walk_state->control_state) && 471 - (walk_state->control_state->common.state == 472 - ACPI_CONTROL_PREDICATE_EXECUTING)) { 473 - /* 474 - * A predicate was just completed, get the value of the 475 - * predicate and branch based on that value 476 - */ 477 - walk_state->op = NULL; 478 - status = acpi_ds_get_predicate_value (walk_state, ACPI_TO_POINTER (TRUE)); 479 - if (ACPI_FAILURE (status) && 480 - ((status & AE_CODE_MASK) != AE_CODE_CONTROL)) { 481 - if (status == AE_AML_NO_RETURN_VALUE) { 482 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 483 - "Invoked method did not return a value, %s\n", 484 - acpi_format_exception (status))); 485 - 486 - } 487 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 488 - "get_predicate Failed, %s\n", 489 - acpi_format_exception (status))); 490 - return_ACPI_STATUS (status); 491 - } 492 - 493 - status = acpi_ps_next_parse_state (walk_state, op, status); 494 - } 495 - 496 - acpi_ps_pop_scope (parser_state, &op, 497 - &walk_state->arg_types, &walk_state->arg_count); 498 - ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); 499 - } 500 - else if (walk_state->prev_op) { 501 - /* We were in the middle of an op */ 502 - 503 - op = walk_state->prev_op; 504 - walk_state->arg_types = walk_state->prev_arg_types; 505 - } 506 - } 507 - #endif 508 - 509 - /* Iterative parsing loop, while there is more AML to process: */ 510 - 511 - while ((parser_state->aml < parser_state->aml_end) || (op)) { 512 - aml_op_start = parser_state->aml; 513 - if (!op) { 514 - /* Get the next opcode from the AML stream */ 515 - 516 - walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 517 - parser_state->aml_start); 518 - walk_state->opcode = acpi_ps_peek_opcode (parser_state); 519 - 520 - /* 521 - * First cut to determine what we have found: 522 - * 1) A valid AML opcode 523 - * 2) A name string 524 - * 3) An unknown/invalid opcode 525 - */ 526 - walk_state->op_info = acpi_ps_get_opcode_info (walk_state->opcode); 527 - switch (walk_state->op_info->class) { 528 - case AML_CLASS_ASCII: 529 - case AML_CLASS_PREFIX: 530 - /* 531 - * Starts with a valid prefix or ASCII char, this is a name 532 - * string. Convert the bare name string to a namepath. 533 - */ 534 - walk_state->opcode = AML_INT_NAMEPATH_OP; 535 - walk_state->arg_types = ARGP_NAMESTRING; 536 - break; 537 - 538 - case AML_CLASS_UNKNOWN: 539 - 540 - /* The opcode is unrecognized. Just skip unknown opcodes */ 541 - 542 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 543 - "Found unknown opcode %X at AML address %p offset %X, ignoring\n", 544 - walk_state->opcode, parser_state->aml, walk_state->aml_offset)); 545 - 546 - ACPI_DUMP_BUFFER (parser_state->aml, 128); 547 - 548 - /* Assume one-byte bad opcode */ 549 - 550 - parser_state->aml++; 551 - continue; 552 - 553 - default: 554 - 555 - /* Found opcode info, this is a normal opcode */ 556 - 557 - parser_state->aml += acpi_ps_get_opcode_size (walk_state->opcode); 558 - walk_state->arg_types = walk_state->op_info->parse_args; 559 - break; 560 - } 561 - 562 - /* Create Op structure and append to parent's argument list */ 563 - 564 - if (walk_state->op_info->flags & AML_NAMED) { 565 - /* Allocate a new pre_op if necessary */ 566 - 567 - if (!pre_op) { 568 - pre_op = acpi_ps_alloc_op (walk_state->opcode); 569 - if (!pre_op) { 570 - status = AE_NO_MEMORY; 571 - goto close_this_op; 572 - } 573 - } 574 - 575 - pre_op->common.value.arg = NULL; 576 - pre_op->common.aml_opcode = walk_state->opcode; 577 - 578 - /* 579 - * Get and append arguments until we find the node that contains 580 - * the name (the type ARGP_NAME). 581 - */ 582 - while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && 583 - (GET_CURRENT_ARG_TYPE (walk_state->arg_types) != ARGP_NAME)) { 584 - status = acpi_ps_get_next_arg (walk_state, parser_state, 585 - GET_CURRENT_ARG_TYPE (walk_state->arg_types), &arg); 586 - if (ACPI_FAILURE (status)) { 587 - goto close_this_op; 588 - } 589 - 590 - acpi_ps_append_arg (pre_op, arg); 591 - INCREMENT_ARG_LIST (walk_state->arg_types); 592 - } 593 - 594 - /* 595 - * Make sure that we found a NAME and didn't run out of 596 - * arguments 597 - */ 598 - if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) { 599 - status = AE_AML_NO_OPERAND; 600 - goto close_this_op; 601 - } 602 - 603 - /* We know that this arg is a name, move to next arg */ 604 - 605 - INCREMENT_ARG_LIST (walk_state->arg_types); 606 - 607 - /* 608 - * Find the object. This will either insert the object into 609 - * the namespace or simply look it up 610 - */ 611 - walk_state->op = NULL; 612 - 613 - status = walk_state->descending_callback (walk_state, &op); 614 - if (ACPI_FAILURE (status)) { 615 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 616 - "During name lookup/catalog, %s\n", 617 - acpi_format_exception (status))); 618 - goto close_this_op; 619 - } 620 - 621 - if (!op) { 622 - continue; 623 - } 624 - 625 - status = acpi_ps_next_parse_state (walk_state, op, status); 626 - if (status == AE_CTRL_PENDING) { 627 - status = AE_OK; 628 - goto close_this_op; 629 - } 630 - 631 - if (ACPI_FAILURE (status)) { 632 - goto close_this_op; 633 - } 634 - 635 - acpi_ps_append_arg (op, pre_op->common.value.arg); 636 - acpi_gbl_depth++; 637 - 638 - if (op->common.aml_opcode == AML_REGION_OP) { 639 - /* 640 - * Defer final parsing of an operation_region body, 641 - * because we don't have enough info in the first pass 642 - * to parse it correctly (i.e., there may be method 643 - * calls within the term_arg elements of the body.) 644 - * 645 - * However, we must continue parsing because 646 - * the opregion is not a standalone package -- 647 - * we don't know where the end is at this point. 648 - * 649 - * (Length is unknown until parse of the body complete) 650 - */ 651 - op->named.data = aml_op_start; 652 - op->named.length = 0; 653 - } 654 - } 655 - else { 656 - /* Not a named opcode, just allocate Op and append to parent */ 657 - 658 - walk_state->op_info = acpi_ps_get_opcode_info (walk_state->opcode); 659 - op = acpi_ps_alloc_op (walk_state->opcode); 660 - if (!op) { 661 - status = AE_NO_MEMORY; 662 - goto close_this_op; 663 - } 664 - 665 - if (walk_state->op_info->flags & AML_CREATE) { 666 - /* 667 - * Backup to beginning of create_xXXfield declaration 668 - * body_length is unknown until we parse the body 669 - */ 670 - op->named.data = aml_op_start; 671 - op->named.length = 0; 672 - } 673 - 674 - acpi_ps_append_arg (acpi_ps_get_parent_scope (parser_state), op); 675 - 676 - if ((walk_state->descending_callback != NULL)) { 677 - /* 678 - * Find the object. This will either insert the object into 679 - * the namespace or simply look it up 680 - */ 681 - walk_state->op = op; 682 - 683 - status = walk_state->descending_callback (walk_state, &op); 684 - status = acpi_ps_next_parse_state (walk_state, op, status); 685 - if (status == AE_CTRL_PENDING) { 686 - status = AE_OK; 687 - goto close_this_op; 688 - } 689 - 690 - if (ACPI_FAILURE (status)) { 691 - goto close_this_op; 692 - } 693 - } 694 - } 695 - 696 - op->common.aml_offset = walk_state->aml_offset; 697 - 698 - if (walk_state->op_info) { 699 - ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 700 - "Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n", 701 - (u32) op->common.aml_opcode, walk_state->op_info->name, 702 - op, parser_state->aml, op->common.aml_offset)); 703 - } 704 - } 705 - 706 - 707 - /* 708 - * Start arg_count at zero because we don't know if there are 709 - * any args yet 710 - */ 711 - walk_state->arg_count = 0; 712 - 713 - /* Are there any arguments that must be processed? */ 714 - 715 - if (walk_state->arg_types) { 716 - /* Get arguments */ 717 - 718 - switch (op->common.aml_opcode) { 719 - case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ 720 - case AML_WORD_OP: /* AML_WORDDATA_ARG */ 721 - case AML_DWORD_OP: /* AML_DWORDATA_ARG */ 722 - case AML_QWORD_OP: /* AML_QWORDATA_ARG */ 723 - case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */ 724 - 725 - /* Fill in constant or string argument directly */ 726 - 727 - acpi_ps_get_next_simple_arg (parser_state, 728 - GET_CURRENT_ARG_TYPE (walk_state->arg_types), op); 729 - break; 730 - 731 - case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ 732 - 733 - status = acpi_ps_get_next_namepath (walk_state, parser_state, op, 1); 734 - if (ACPI_FAILURE (status)) { 735 - goto close_this_op; 736 - } 737 - 738 - walk_state->arg_types = 0; 739 - break; 740 - 741 - default: 742 - /* 743 - * Op is not a constant or string, append each argument 744 - * to the Op 745 - */ 746 - while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && 747 - !walk_state->arg_count) { 748 - walk_state->aml_offset = (u32) 749 - ACPI_PTR_DIFF (parser_state->aml, parser_state->aml_start); 750 - 751 - status = acpi_ps_get_next_arg (walk_state, parser_state, 752 - GET_CURRENT_ARG_TYPE (walk_state->arg_types), 753 - &arg); 754 - if (ACPI_FAILURE (status)) { 755 - goto close_this_op; 756 - } 757 - 758 - if (arg) { 759 - arg->common.aml_offset = walk_state->aml_offset; 760 - acpi_ps_append_arg (op, arg); 761 - } 762 - INCREMENT_ARG_LIST (walk_state->arg_types); 763 - } 764 - 765 - /* Special processing for certain opcodes */ 766 - 767 - if (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS1) { 768 - switch (op->common.aml_opcode) { 769 - case AML_IF_OP: 770 - case AML_ELSE_OP: 771 - case AML_WHILE_OP: 772 - 773 - /* Skip body of if/else/while in pass 1 */ 774 - 775 - parser_state->aml = parser_state->pkg_end; 776 - walk_state->arg_count = 0; 777 - break; 778 - 779 - default: 780 - break; 781 - } 782 - } 783 - 784 - switch (op->common.aml_opcode) { 785 - case AML_METHOD_OP: 786 - 787 - /* 788 - * Skip parsing of control method 789 - * because we don't have enough info in the first pass 790 - * to parse it correctly. 791 - * 792 - * Save the length and address of the body 793 - */ 794 - op->named.data = parser_state->aml; 795 - op->named.length = (u32) (parser_state->pkg_end - 796 - parser_state->aml); 797 - 798 - /* Skip body of method */ 799 - 800 - parser_state->aml = parser_state->pkg_end; 801 - walk_state->arg_count = 0; 802 - break; 803 - 804 - case AML_BUFFER_OP: 805 - case AML_PACKAGE_OP: 806 - case AML_VAR_PACKAGE_OP: 807 - 808 - if ((op->common.parent) && 809 - (op->common.parent->common.aml_opcode == AML_NAME_OP) && 810 - (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2)) { 811 - /* 812 - * Skip parsing of Buffers and Packages 813 - * because we don't have enough info in the first pass 814 - * to parse them correctly. 815 - */ 816 - op->named.data = aml_op_start; 817 - op->named.length = (u32) (parser_state->pkg_end - 818 - aml_op_start); 819 - 820 - /* Skip body */ 821 - 822 - parser_state->aml = parser_state->pkg_end; 823 - walk_state->arg_count = 0; 824 - } 825 - break; 826 - 827 - case AML_WHILE_OP: 828 - 829 - if (walk_state->control_state) { 830 - walk_state->control_state->control.package_end = 831 - parser_state->pkg_end; 832 - } 833 - break; 834 - 835 - default: 836 - 837 - /* No action for all other opcodes */ 838 - break; 839 - } 840 - break; 841 - } 842 - } 843 - 844 - /* Check for arguments that need to be processed */ 845 - 846 - if (walk_state->arg_count) { 847 - /* 848 - * There are arguments (complex ones), push Op and 849 - * prepare for argument 850 - */ 851 - status = acpi_ps_push_scope (parser_state, op, 852 - walk_state->arg_types, walk_state->arg_count); 853 - if (ACPI_FAILURE (status)) { 854 - goto close_this_op; 855 - } 856 - op = NULL; 857 - continue; 858 - } 859 - 860 - /* 861 - * All arguments have been processed -- Op is complete, 862 - * prepare for next 863 - */ 864 - walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 865 - if (walk_state->op_info->flags & AML_NAMED) { 866 - if (acpi_gbl_depth) { 867 - acpi_gbl_depth--; 868 - } 869 - 870 - if (op->common.aml_opcode == AML_REGION_OP) { 871 - /* 872 - * Skip parsing of control method or opregion body, 873 - * because we don't have enough info in the first pass 874 - * to parse them correctly. 875 - * 876 - * Completed parsing an op_region declaration, we now 877 - * know the length. 878 - */ 879 - op->named.length = (u32) (parser_state->aml - op->named.data); 880 - } 881 - } 882 - 883 - if (walk_state->op_info->flags & AML_CREATE) { 884 - /* 885 - * Backup to beginning of create_xXXfield declaration (1 for 886 - * Opcode) 887 - * 888 - * body_length is unknown until we parse the body 889 - */ 890 - op->named.length = (u32) (parser_state->aml - op->named.data); 891 - } 892 - 893 - /* This op complete, notify the dispatcher */ 894 - 895 - if (walk_state->ascending_callback != NULL) { 896 - walk_state->op = op; 897 - walk_state->opcode = op->common.aml_opcode; 898 - 899 - status = walk_state->ascending_callback (walk_state); 900 - status = acpi_ps_next_parse_state (walk_state, op, status); 901 - if (status == AE_CTRL_PENDING) { 902 - status = AE_OK; 903 - goto close_this_op; 904 - } 905 - } 906 - 907 - 908 - close_this_op: 909 - /* 910 - * Finished one argument of the containing scope 911 - */ 912 - parser_state->scope->parse_scope.arg_count--; 913 - 914 - /* Finished with pre_op */ 915 - 916 - if (pre_op) { 917 - acpi_ps_free_op (pre_op); 918 - pre_op = NULL; 919 - } 920 - 921 - /* Close this Op (will result in parse subtree deletion) */ 922 - 923 - status2 = acpi_ps_complete_this_op (walk_state, op); 924 - if (ACPI_FAILURE (status2)) { 925 - return_ACPI_STATUS (status2); 926 - } 927 - op = NULL; 928 - 929 - switch (status) { 930 - case AE_OK: 931 - break; 932 - 933 - 934 - case AE_CTRL_TRANSFER: 935 - 936 - /* We are about to transfer to a called method. */ 937 - 938 - walk_state->prev_op = op; 939 - walk_state->prev_arg_types = walk_state->arg_types; 940 - return_ACPI_STATUS (status); 941 - 942 - 943 - case AE_CTRL_END: 944 - 945 - acpi_ps_pop_scope (parser_state, &op, 946 - &walk_state->arg_types, &walk_state->arg_count); 947 - 948 - if (op) { 949 - walk_state->op = op; 950 - walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 951 - walk_state->opcode = op->common.aml_opcode; 952 - 953 - status = walk_state->ascending_callback (walk_state); 954 - status = acpi_ps_next_parse_state (walk_state, op, status); 955 - 956 - status2 = acpi_ps_complete_this_op (walk_state, op); 957 - if (ACPI_FAILURE (status2)) { 958 - return_ACPI_STATUS (status2); 959 - } 960 - op = NULL; 961 - } 962 - status = AE_OK; 963 - break; 964 - 965 - 966 - case AE_CTRL_BREAK: 967 - case AE_CTRL_CONTINUE: 968 - 969 - /* Pop off scopes until we find the While */ 970 - 971 - while (!op || (op->common.aml_opcode != AML_WHILE_OP)) { 972 - acpi_ps_pop_scope (parser_state, &op, 973 - &walk_state->arg_types, &walk_state->arg_count); 974 - } 975 - 976 - /* Close this iteration of the While loop */ 977 - 978 - walk_state->op = op; 979 - walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 980 - walk_state->opcode = op->common.aml_opcode; 981 - 982 - status = walk_state->ascending_callback (walk_state); 983 - status = acpi_ps_next_parse_state (walk_state, op, status); 984 - 985 - status2 = acpi_ps_complete_this_op (walk_state, op); 986 - if (ACPI_FAILURE (status2)) { 987 - return_ACPI_STATUS (status2); 988 - } 989 - op = NULL; 990 - 991 - status = AE_OK; 992 - break; 993 - 994 - 995 - case AE_CTRL_TERMINATE: 996 - 997 - status = AE_OK; 998 - 999 - /* Clean up */ 1000 - do { 1001 - if (op) { 1002 - status2 = acpi_ps_complete_this_op (walk_state, op); 1003 - if (ACPI_FAILURE (status2)) { 1004 - return_ACPI_STATUS (status2); 1005 - } 1006 - } 1007 - acpi_ps_pop_scope (parser_state, &op, 1008 - &walk_state->arg_types, &walk_state->arg_count); 1009 - 1010 - } while (op); 1011 - 1012 - return_ACPI_STATUS (status); 1013 - 1014 - 1015 - default: /* All other non-AE_OK status */ 1016 - 1017 - do { 1018 - if (op) { 1019 - status2 = acpi_ps_complete_this_op (walk_state, op); 1020 - if (ACPI_FAILURE (status2)) { 1021 - return_ACPI_STATUS (status2); 1022 - } 1023 - } 1024 - acpi_ps_pop_scope (parser_state, &op, 1025 - &walk_state->arg_types, &walk_state->arg_count); 1026 - 1027 - } while (op); 1028 - 1029 - 1030 - /* 1031 - * TBD: Cleanup parse ops on error 1032 - */ 1033 - #if 0 1034 - if (op == NULL) { 1035 - acpi_ps_pop_scope (parser_state, &op, 1036 - &walk_state->arg_types, &walk_state->arg_count); 1037 - } 1038 - #endif 1039 - walk_state->prev_op = op; 1040 - walk_state->prev_arg_types = walk_state->arg_types; 1041 - return_ACPI_STATUS (status); 1042 - } 1043 - 1044 - /* This scope complete? */ 1045 - 1046 - if (acpi_ps_has_completed_scope (parser_state)) { 1047 - acpi_ps_pop_scope (parser_state, &op, 1048 - &walk_state->arg_types, &walk_state->arg_count); 1049 - ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); 1050 - } 1051 - else { 1052 - op = NULL; 1053 - } 1054 - 1055 - } /* while parser_state->Aml */ 1056 - 1057 - 1058 - /* 1059 - * Complete the last Op (if not completed), and clear the scope stack. 1060 - * It is easily possible to end an AML "package" with an unbounded number 1061 - * of open scopes (such as when several ASL blocks are closed with 1062 - * sequential closing braces). We want to terminate each one cleanly. 1063 - */ 1064 - ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", op)); 1065 - do { 1066 - if (op) { 1067 - if (walk_state->ascending_callback != NULL) { 1068 - walk_state->op = op; 1069 - walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 1070 - walk_state->opcode = op->common.aml_opcode; 1071 - 1072 - status = walk_state->ascending_callback (walk_state); 1073 - status = acpi_ps_next_parse_state (walk_state, op, status); 1074 - if (status == AE_CTRL_PENDING) { 1075 - status = AE_OK; 1076 - goto close_this_op; 1077 - } 1078 - 1079 - if (status == AE_CTRL_TERMINATE) { 1080 - status = AE_OK; 1081 - 1082 - /* Clean up */ 1083 - do { 1084 - if (op) { 1085 - status2 = acpi_ps_complete_this_op (walk_state, op); 1086 - if (ACPI_FAILURE (status2)) { 1087 - return_ACPI_STATUS (status2); 1088 - } 1089 - } 1090 - 1091 - acpi_ps_pop_scope (parser_state, &op, 1092 - &walk_state->arg_types, &walk_state->arg_count); 1093 - 1094 - } while (op); 1095 - 1096 - return_ACPI_STATUS (status); 1097 - } 1098 - 1099 - else if (ACPI_FAILURE (status)) { 1100 - /* First error is most important */ 1101 - 1102 - (void) acpi_ps_complete_this_op (walk_state, op); 1103 - return_ACPI_STATUS (status); 1104 - } 1105 - } 1106 - 1107 - status2 = acpi_ps_complete_this_op (walk_state, op); 1108 - if (ACPI_FAILURE (status2)) { 1109 - return_ACPI_STATUS (status2); 1110 - } 1111 - } 1112 - 1113 - acpi_ps_pop_scope (parser_state, &op, &walk_state->arg_types, 1114 - &walk_state->arg_count); 1115 - 1116 - } while (op); 1117 437 1118 438 return_ACPI_STATUS (status); 1119 439 }
+6 -31
drivers/acpi/parser/psutils.c
··· 154 154 if (flags == ACPI_PARSEOP_GENERIC) { 155 155 /* The generic op (default) is by far the most common (16 to 1) */ 156 156 157 - op = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_PSNODE); 157 + op = acpi_os_acquire_object (acpi_gbl_ps_node_cache); 158 + memset(op, 0, sizeof(struct acpi_parse_obj_common)); 158 159 } 159 160 else { 160 161 /* Extended parseop */ 161 162 162 - op = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_PSNODE_EXT); 163 + op = acpi_os_acquire_object (acpi_gbl_ps_node_ext_cache); 164 + memset(op, 0, sizeof(struct acpi_parse_obj_named)); 163 165 } 164 166 165 167 /* Initialize the Op */ ··· 200 198 } 201 199 202 200 if (op->common.flags & ACPI_PARSEOP_GENERIC) { 203 - acpi_ut_release_to_cache (ACPI_MEM_LIST_PSNODE, op); 201 + acpi_os_release_object (acpi_gbl_ps_node_cache, op); 204 202 } 205 203 else { 206 - acpi_ut_release_to_cache (ACPI_MEM_LIST_PSNODE_EXT, op); 204 + acpi_os_release_object (acpi_gbl_ps_node_ext_cache, op); 207 205 } 208 206 } 209 - 210 - 211 - #ifdef ACPI_ENABLE_OBJECT_CACHE 212 - /******************************************************************************* 213 - * 214 - * FUNCTION: acpi_ps_delete_parse_cache 215 - * 216 - * PARAMETERS: None 217 - * 218 - * RETURN: None 219 - * 220 - * DESCRIPTION: Free all objects that are on the parse cache list. 221 - * 222 - ******************************************************************************/ 223 - 224 - void 225 - acpi_ps_delete_parse_cache ( 226 - void) 227 - { 228 - ACPI_FUNCTION_TRACE ("ps_delete_parse_cache"); 229 - 230 - 231 - acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE); 232 - acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE_EXT); 233 - return_VOID; 234 - } 235 - #endif 236 207 237 208 238 209 /*******************************************************************************
+6 -2
drivers/acpi/tables/tbconvrt.c
··· 97 97 ACPI_FUNCTION_ENTRY (); 98 98 99 99 100 - if (RSDP->revision < 2) { 100 + /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */ 101 + 102 + if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 101 103 pointer_size = sizeof (u32); 102 104 } 103 105 else { ··· 160 158 /* Copy the table pointers */ 161 159 162 160 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) { 163 - if (acpi_gbl_RSDP->revision < 2) { 161 + /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */ 162 + 163 + if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 164 164 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i], 165 165 (ACPI_CAST_PTR (struct rsdt_descriptor_rev1, 166 166 table_info->pointer))->table_offset_entry[i]);
+18 -16
drivers/acpi/tables/tbrsdt.c
··· 159 159 * 160 160 * RETURN: None, Address 161 161 * 162 - * DESCRIPTION: Extract the address of the RSDT or XSDT, depending on the 163 - * version of the RSDP 162 + * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the 163 + * version of the RSDP and whether the XSDT pointer is valid 164 164 * 165 165 ******************************************************************************/ 166 166 ··· 174 174 175 175 out_address->pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING; 176 176 177 - /* 178 - * For RSDP revision 0 or 1, we use the RSDT. 179 - * For RSDP revision 2 (and above), we use the XSDT 180 - */ 181 - if (acpi_gbl_RSDP->revision < 2) { 182 - out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address; 183 - } 184 - else { 177 + /* Use XSDT if it is present */ 178 + 179 + if ((acpi_gbl_RSDP->revision >= 2) && 180 + acpi_gbl_RSDP->xsdt_physical_address) { 185 181 out_address->pointer.value = 186 182 acpi_gbl_RSDP->xsdt_physical_address; 183 + acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT; 184 + } 185 + else { 186 + /* No XSDT, use the RSDT */ 187 + 188 + out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address; 189 + acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT; 187 190 } 188 191 } 189 192 ··· 214 211 215 212 216 213 /* 217 - * For RSDP revision 0 or 1, we use the RSDT. 218 - * For RSDP revision 2 and above, we use the XSDT 214 + * Search for appropriate signature, RSDT or XSDT 219 215 */ 220 - if (acpi_gbl_RSDP->revision < 2) { 216 + if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 221 217 no_match = ACPI_STRNCMP ((char *) table_ptr, RSDT_SIG, 222 218 sizeof (RSDT_SIG) -1); 223 219 } ··· 238 236 acpi_gbl_RSDP->rsdt_physical_address, 239 237 (void *) (acpi_native_uint) acpi_gbl_RSDP->rsdt_physical_address)); 240 238 241 - if (acpi_gbl_RSDP->revision < 2) { 242 - ACPI_REPORT_ERROR (("Looking for RSDT (RSDP->Rev < 2)\n")) 239 + if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 240 + ACPI_REPORT_ERROR (("Looking for RSDT\n")) 243 241 } 244 242 else { 245 - ACPI_REPORT_ERROR (("Looking for XSDT (RSDP->Rev >= 2)\n")) 243 + ACPI_REPORT_ERROR (("Looking for XSDT\n")) 246 244 } 247 245 248 246 ACPI_DUMP_BUFFER ((char *) table_ptr, 48);
+5 -3
drivers/acpi/tables/tbxfroot.c
··· 287 287 * requested table 288 288 */ 289 289 for (i = 0, j = 0; i < table_count; i++) { 290 - /* Get the next table pointer, handle RSDT vs. XSDT */ 291 - 292 - if (acpi_gbl_RSDP->revision < 2) { 290 + /* 291 + * Get the next table pointer, handle RSDT vs. XSDT 292 + * RSDT pointers are 32 bits, XSDT pointers are 64 bits 293 + */ 294 + if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 293 295 address.pointer.value = (ACPI_CAST_PTR ( 294 296 RSDT_DESCRIPTOR, rsdt_info->pointer))->table_offset_entry[i]; 295 297 }
+1 -1
drivers/acpi/utilities/Makefile
··· 3 3 # 4 4 5 5 obj-y := utalloc.o utdebug.o uteval.o utinit.o utmisc.o utxface.o \ 6 - utcopy.o utdelete.o utglobal.o utmath.o utobject.o 6 + utcopy.o utdelete.o utglobal.o utmath.o utobject.o utstate.o utmutex.o utobject.o utcache.o 7 7 8 8 EXTRA_CFLAGS += $(ACPI_CFLAGS)
+121 -193
drivers/acpi/utilities/utalloc.c
··· 1 1 /****************************************************************************** 2 2 * 3 - * Module Name: utalloc - local cache and memory allocation routines 3 + * Module Name: utalloc - local memory allocation routines 4 4 * 5 5 *****************************************************************************/ 6 6 ··· 52 52 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 53 53 static struct acpi_debug_mem_block * 54 54 acpi_ut_find_allocation ( 55 - u32 list_id, 56 55 void *allocation); 57 56 58 57 static acpi_status 59 58 acpi_ut_track_allocation ( 60 - u32 list_id, 61 59 struct acpi_debug_mem_block *address, 62 60 acpi_size size, 63 61 u8 alloc_type, ··· 65 67 66 68 static acpi_status 67 69 acpi_ut_remove_allocation ( 68 - u32 list_id, 69 70 struct acpi_debug_mem_block *address, 70 71 u32 component, 71 72 char *module, 72 73 u32 line); 73 74 #endif /* ACPI_DBG_TRACK_ALLOCATIONS */ 74 75 75 - 76 - /******************************************************************************* 77 - * 78 - * FUNCTION: acpi_ut_release_to_cache 79 - * 80 - * PARAMETERS: list_id - Memory list/cache ID 81 - * Object - The object to be released 82 - * 83 - * RETURN: None 84 - * 85 - * DESCRIPTION: Release an object to the specified cache. If cache is full, 86 - * the object is deleted. 87 - * 88 - ******************************************************************************/ 89 - 90 - void 91 - acpi_ut_release_to_cache ( 92 - u32 list_id, 93 - void *object) 94 - { 95 - struct acpi_memory_list *cache_info; 96 - 97 - 98 - ACPI_FUNCTION_ENTRY (); 99 - 100 - 101 - cache_info = &acpi_gbl_memory_lists[list_id]; 102 - 103 - #ifdef ACPI_ENABLE_OBJECT_CACHE 104 - 105 - /* If walk cache is full, just free this wallkstate object */ 106 - 107 - if (cache_info->cache_depth >= cache_info->max_cache_depth) { 108 - ACPI_MEM_FREE (object); 109 - ACPI_MEM_TRACKING (cache_info->total_freed++); 110 - } 111 - 112 - /* Otherwise put this object back into the cache */ 113 - 114 - else { 115 - if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES))) { 116 - return; 117 - } 118 - 119 - /* Mark the object as cached */ 120 - 121 - ACPI_MEMSET (object, 0xCA, cache_info->object_size); 122 - ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_CACHED); 123 - 124 - /* Put the object at the head of the cache list */ 125 - 126 - * (ACPI_CAST_INDIRECT_PTR (char, 127 - &(((char *) object)[cache_info->link_offset]))) = cache_info->list_head; 128 - cache_info->list_head = object; 129 - cache_info->cache_depth++; 130 - 131 - (void) acpi_ut_release_mutex (ACPI_MTX_CACHES); 132 - } 133 - 134 - #else 135 - 136 - /* Object cache is disabled; just free the object */ 137 - 138 - ACPI_MEM_FREE (object); 139 - ACPI_MEM_TRACKING (cache_info->total_freed++); 76 + #ifdef ACPI_DBG_TRACK_ALLOCATIONS 77 + static acpi_status 78 + acpi_ut_create_list ( 79 + char *list_name, 80 + u16 object_size, 81 + acpi_handle *return_cache); 140 82 #endif 141 - } 142 83 143 84 144 85 /******************************************************************************* 145 86 * 146 - * FUNCTION: acpi_ut_acquire_from_cache 87 + * FUNCTION: acpi_ut_create_caches 147 88 * 148 - * PARAMETERS: list_id - Memory list ID 89 + * PARAMETERS: None 149 90 * 150 - * RETURN: A requested object. NULL if the object could not be 151 - * allocated. 91 + * RETURN: Status 152 92 * 153 - * DESCRIPTION: Get an object from the specified cache. If cache is empty, 154 - * the object is allocated. 93 + * DESCRIPTION: Create all local caches 155 94 * 156 95 ******************************************************************************/ 157 96 158 - void * 159 - acpi_ut_acquire_from_cache ( 160 - u32 list_id) 97 + acpi_status 98 + acpi_ut_create_caches ( 99 + void) 161 100 { 162 - struct acpi_memory_list *cache_info; 163 - void *object; 101 + acpi_status status; 164 102 165 - 166 - ACPI_FUNCTION_NAME ("ut_acquire_from_cache"); 167 - 168 - 169 - cache_info = &acpi_gbl_memory_lists[list_id]; 170 - 171 - #ifdef ACPI_ENABLE_OBJECT_CACHE 172 - 173 - if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES))) { 174 - return (NULL); 175 - } 176 - 177 - ACPI_MEM_TRACKING (cache_info->cache_requests++); 178 - 179 - /* Check the cache first */ 180 - 181 - if (cache_info->list_head) { 182 - /* There is an object available, use it */ 183 - 184 - object = cache_info->list_head; 185 - cache_info->list_head = *(ACPI_CAST_INDIRECT_PTR (char, 186 - &(((char *) object)[cache_info->link_offset]))); 187 - 188 - ACPI_MEM_TRACKING (cache_info->cache_hits++); 189 - cache_info->cache_depth--; 190 103 191 104 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 192 - ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n", 193 - object, acpi_gbl_memory_lists[list_id].list_name)); 194 - #endif 195 105 196 - if (ACPI_FAILURE (acpi_ut_release_mutex (ACPI_MTX_CACHES))) { 197 - return (NULL); 198 - } 106 + /* Memory allocation lists */ 199 107 200 - /* Clear (zero) the previously used Object */ 201 - 202 - ACPI_MEMSET (object, 0, cache_info->object_size); 108 + status = acpi_ut_create_list ("Acpi-Global", 0, 109 + &acpi_gbl_global_list); 110 + if (ACPI_FAILURE (status)) { 111 + return (status); 203 112 } 204 113 205 - else { 206 - /* The cache is empty, create a new object */ 207 - 208 - /* Avoid deadlock with ACPI_MEM_CALLOCATE */ 209 - 210 - if (ACPI_FAILURE (acpi_ut_release_mutex (ACPI_MTX_CACHES))) { 211 - return (NULL); 212 - } 213 - 214 - object = ACPI_MEM_CALLOCATE (cache_info->object_size); 215 - ACPI_MEM_TRACKING (cache_info->total_allocated++); 114 + status = acpi_ut_create_list ("Acpi-Namespace", sizeof (struct acpi_namespace_node), 115 + &acpi_gbl_ns_node_list); 116 + if (ACPI_FAILURE (status)) { 117 + return (status); 216 118 } 217 - 218 - #else 219 - 220 - /* Object cache is disabled; just allocate the object */ 221 - 222 - object = ACPI_MEM_CALLOCATE (cache_info->object_size); 223 - ACPI_MEM_TRACKING (cache_info->total_allocated++); 224 119 #endif 225 120 226 - return (object); 121 + /* Object Caches, for frequently used objects */ 122 + 123 + status = acpi_os_create_cache ("acpi_state", sizeof (union acpi_generic_state), 124 + ACPI_MAX_STATE_CACHE_DEPTH, &acpi_gbl_state_cache); 125 + if (ACPI_FAILURE (status)) { 126 + return (status); 127 + } 128 + 129 + status = acpi_os_create_cache ("acpi_parse", sizeof (struct acpi_parse_obj_common), 130 + ACPI_MAX_PARSE_CACHE_DEPTH, &acpi_gbl_ps_node_cache); 131 + if (ACPI_FAILURE (status)) { 132 + return (status); 133 + } 134 + 135 + status = acpi_os_create_cache ("acpi_parse_ext", sizeof (struct acpi_parse_obj_named), 136 + ACPI_MAX_EXTPARSE_CACHE_DEPTH, &acpi_gbl_ps_node_ext_cache); 137 + if (ACPI_FAILURE (status)) { 138 + return (status); 139 + } 140 + 141 + status = acpi_os_create_cache ("acpi_operand", sizeof (union acpi_operand_object), 142 + ACPI_MAX_OBJECT_CACHE_DEPTH, &acpi_gbl_operand_cache); 143 + if (ACPI_FAILURE (status)) { 144 + return (status); 145 + } 146 + 147 + return (AE_OK); 227 148 } 228 149 229 150 230 - #ifdef ACPI_ENABLE_OBJECT_CACHE 231 151 /******************************************************************************* 232 152 * 233 - * FUNCTION: acpi_ut_delete_generic_cache 153 + * FUNCTION: acpi_ut_delete_caches 234 154 * 235 - * PARAMETERS: list_id - Memory list ID 155 + * PARAMETERS: None 236 156 * 237 - * RETURN: None 157 + * RETURN: Status 238 158 * 239 - * DESCRIPTION: Free all objects within the requested cache. 159 + * DESCRIPTION: Purge and delete all local caches 240 160 * 241 161 ******************************************************************************/ 242 162 243 - void 244 - acpi_ut_delete_generic_cache ( 245 - u32 list_id) 163 + acpi_status 164 + acpi_ut_delete_caches ( 165 + void) 246 166 { 247 - struct acpi_memory_list *cache_info; 248 - char *next; 249 167 168 + (void) acpi_os_delete_cache (acpi_gbl_state_cache); 169 + acpi_gbl_state_cache = NULL; 250 170 251 - ACPI_FUNCTION_ENTRY (); 171 + (void) acpi_os_delete_cache (acpi_gbl_operand_cache); 172 + acpi_gbl_operand_cache = NULL; 252 173 174 + (void) acpi_os_delete_cache (acpi_gbl_ps_node_cache); 175 + acpi_gbl_ps_node_cache = NULL; 253 176 254 - cache_info = &acpi_gbl_memory_lists[list_id]; 255 - while (cache_info->list_head) { 256 - /* Delete one cached state object */ 177 + (void) acpi_os_delete_cache (acpi_gbl_ps_node_ext_cache); 178 + acpi_gbl_ps_node_ext_cache = NULL; 257 179 258 - next = *(ACPI_CAST_INDIRECT_PTR (char, 259 - &(((char *) cache_info->list_head)[cache_info->link_offset]))); 260 - ACPI_MEM_FREE (cache_info->list_head); 261 - 262 - cache_info->list_head = next; 263 - cache_info->cache_depth--; 264 - } 180 + return (AE_OK); 265 181 } 266 - #endif 267 - 268 182 269 183 /******************************************************************************* 270 184 * ··· 410 500 * occurs in the body of acpi_ut_free. 411 501 */ 412 502 503 + /******************************************************************************* 504 + * 505 + * FUNCTION: acpi_ut_create_list 506 + * 507 + * PARAMETERS: cache_name - Ascii name for the cache 508 + * object_size - Size of each cached object 509 + * return_cache - Where the new cache object is returned 510 + * 511 + * RETURN: Status 512 + * 513 + * DESCRIPTION: Create a local memory list for tracking purposed 514 + * 515 + ******************************************************************************/ 516 + 517 + static acpi_status 518 + acpi_ut_create_list ( 519 + char *list_name, 520 + u16 object_size, 521 + acpi_handle *return_cache) 522 + { 523 + struct acpi_memory_list *cache; 524 + 525 + 526 + cache = acpi_os_allocate (sizeof (struct acpi_memory_list)); 527 + if (!cache) { 528 + return (AE_NO_MEMORY); 529 + } 530 + 531 + ACPI_MEMSET (cache, 0, sizeof (struct acpi_memory_list)); 532 + 533 + cache->list_name = list_name; 534 + cache->object_size = object_size; 535 + 536 + *return_cache = cache; 537 + return (AE_OK); 538 + } 539 + 413 540 414 541 /******************************************************************************* 415 542 * ··· 480 533 return (NULL); 481 534 } 482 535 483 - status = acpi_ut_track_allocation (ACPI_MEM_LIST_GLOBAL, allocation, size, 536 + status = acpi_ut_track_allocation (allocation, size, 484 537 ACPI_MEM_MALLOC, component, module, line); 485 538 if (ACPI_FAILURE (status)) { 486 539 acpi_os_free (allocation); 487 540 return (NULL); 488 541 } 489 542 490 - acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_allocated++; 491 - acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size += (u32) size; 543 + acpi_gbl_global_list->total_allocated++; 544 + acpi_gbl_global_list->current_total_size += (u32) size; 492 545 493 546 return ((void *) &allocation->user_space); 494 547 } ··· 530 583 return (NULL); 531 584 } 532 585 533 - status = acpi_ut_track_allocation (ACPI_MEM_LIST_GLOBAL, allocation, size, 586 + status = acpi_ut_track_allocation (allocation, size, 534 587 ACPI_MEM_CALLOC, component, module, line); 535 588 if (ACPI_FAILURE (status)) { 536 589 acpi_os_free (allocation); 537 590 return (NULL); 538 591 } 539 592 540 - acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_allocated++; 541 - acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size += (u32) size; 593 + acpi_gbl_global_list->total_allocated++; 594 + acpi_gbl_global_list->current_total_size += (u32) size; 542 595 543 596 return ((void *) &allocation->user_space); 544 597 } ··· 583 636 debug_block = ACPI_CAST_PTR (struct acpi_debug_mem_block, 584 637 (((char *) allocation) - sizeof (struct acpi_debug_mem_header))); 585 638 586 - acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_freed++; 587 - acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size -= debug_block->size; 639 + acpi_gbl_global_list->total_freed++; 640 + acpi_gbl_global_list->current_total_size -= debug_block->size; 588 641 589 - status = acpi_ut_remove_allocation (ACPI_MEM_LIST_GLOBAL, debug_block, 642 + status = acpi_ut_remove_allocation (debug_block, 590 643 component, module, line); 591 644 if (ACPI_FAILURE (status)) { 592 645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n", ··· 605 658 * 606 659 * FUNCTION: acpi_ut_find_allocation 607 660 * 608 - * PARAMETERS: list_id - Memory list to search 609 - * Allocation - Address of allocated memory 661 + * PARAMETERS: Allocation - Address of allocated memory 610 662 * 611 663 * RETURN: A list element if found; NULL otherwise. 612 664 * ··· 615 669 616 670 static struct acpi_debug_mem_block * 617 671 acpi_ut_find_allocation ( 618 - u32 list_id, 619 672 void *allocation) 620 673 { 621 674 struct acpi_debug_mem_block *element; ··· 623 678 ACPI_FUNCTION_ENTRY (); 624 679 625 680 626 - if (list_id > ACPI_MEM_LIST_MAX) { 627 - return (NULL); 628 - } 629 - 630 - element = acpi_gbl_memory_lists[list_id].list_head; 681 + element = acpi_gbl_global_list->list_head; 631 682 632 683 /* Search for the address. */ 633 684 ··· 643 702 * 644 703 * FUNCTION: acpi_ut_track_allocation 645 704 * 646 - * PARAMETERS: list_id - Memory list to search 647 - * Allocation - Address of allocated memory 705 + * PARAMETERS: Allocation - Address of allocated memory 648 706 * Size - Size of the allocation 649 707 * alloc_type - MEM_MALLOC or MEM_CALLOC 650 708 * Component - Component type of caller ··· 658 718 659 719 static acpi_status 660 720 acpi_ut_track_allocation ( 661 - u32 list_id, 662 721 struct acpi_debug_mem_block *allocation, 663 722 acpi_size size, 664 723 u8 alloc_type, ··· 673 734 ACPI_FUNCTION_TRACE_PTR ("ut_track_allocation", allocation); 674 735 675 736 676 - if (list_id > ACPI_MEM_LIST_MAX) { 677 - return_ACPI_STATUS (AE_BAD_PARAMETER); 678 - } 679 - 680 - mem_list = &acpi_gbl_memory_lists[list_id]; 737 + mem_list = acpi_gbl_global_list; 681 738 status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY); 682 739 if (ACPI_FAILURE (status)) { 683 740 return_ACPI_STATUS (status); ··· 683 748 * Search list for this address to make sure it is not already on the list. 684 749 * This will catch several kinds of problems. 685 750 */ 686 - 687 - element = acpi_ut_find_allocation (list_id, allocation); 751 + element = acpi_ut_find_allocation (allocation); 688 752 if (element) { 689 753 ACPI_REPORT_ERROR (( 690 754 "ut_track_allocation: Allocation already present in list! (%p)\n", ··· 727 793 * 728 794 * FUNCTION: acpi_ut_remove_allocation 729 795 * 730 - * PARAMETERS: list_id - Memory list to search 731 - * Allocation - Address of allocated memory 796 + * PARAMETERS: Allocation - Address of allocated memory 732 797 * Component - Component type of caller 733 798 * Module - Source file name of caller 734 799 * Line - Line number of caller ··· 740 807 741 808 static acpi_status 742 809 acpi_ut_remove_allocation ( 743 - u32 list_id, 744 810 struct acpi_debug_mem_block *allocation, 745 811 u32 component, 746 812 char *module, ··· 752 820 ACPI_FUNCTION_TRACE ("ut_remove_allocation"); 753 821 754 822 755 - if (list_id > ACPI_MEM_LIST_MAX) { 756 - return_ACPI_STATUS (AE_BAD_PARAMETER); 757 - } 758 - 759 - mem_list = &acpi_gbl_memory_lists[list_id]; 823 + mem_list = acpi_gbl_global_list; 760 824 if (NULL == mem_list->list_head) { 761 825 /* No allocations! */ 762 826 ··· 887 959 return; 888 960 } 889 961 890 - element = acpi_gbl_memory_lists[0].list_head; 962 + element = acpi_gbl_global_list->list_head; 891 963 while (element) { 892 964 if ((element->component & component) && 893 965 ((module == NULL) || (0 == ACPI_STRCMP (module, element->module)))) {
+322
drivers/acpi/utilities/utcache.c
··· 1 + /****************************************************************************** 2 + * 3 + * Module Name: utcache - local cache allocation routines 4 + * 5 + *****************************************************************************/ 6 + 7 + /* 8 + * Copyright (C) 2000 - 2005, R. Byron Moore 9 + * All rights reserved. 10 + * 11 + * Redistribution and use in source and binary forms, with or without 12 + * modification, are permitted provided that the following conditions 13 + * are met: 14 + * 1. Redistributions of source code must retain the above copyright 15 + * notice, this list of conditions, and the following disclaimer, 16 + * without modification. 17 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 + * substantially similar to the "NO WARRANTY" disclaimer below 19 + * ("Disclaimer") and any redistribution must be conditioned upon 20 + * including a substantially similar Disclaimer requirement for further 21 + * binary redistribution. 22 + * 3. Neither the names of the above-listed copyright holders nor the names 23 + * of any contributors may be used to endorse or promote products derived 24 + * from this software without specific prior written permission. 25 + * 26 + * Alternatively, this software may be distributed under the terms of the 27 + * GNU General Public License ("GPL") version 2 as published by the Free 28 + * Software Foundation. 29 + * 30 + * NO WARRANTY 31 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 + * POSSIBILITY OF SUCH DAMAGES. 42 + */ 43 + 44 + 45 + #include <acpi/acpi.h> 46 + 47 + #define _COMPONENT ACPI_UTILITIES 48 + ACPI_MODULE_NAME ("utcache") 49 + 50 + 51 + #ifdef ACPI_USE_LOCAL_CACHE 52 + /******************************************************************************* 53 + * 54 + * FUNCTION: acpi_os_create_cache 55 + * 56 + * PARAMETERS: cache_name - Ascii name for the cache 57 + * object_size - Size of each cached object 58 + * max_depth - Maximum depth of the cache (in objects) 59 + * return_cache - Where the new cache object is returned 60 + * 61 + * RETURN: Status 62 + * 63 + * DESCRIPTION: Create a cache object 64 + * 65 + ******************************************************************************/ 66 + 67 + acpi_status 68 + acpi_os_create_cache ( 69 + char *cache_name, 70 + u16 object_size, 71 + u16 max_depth, 72 + struct acpi_memory_list **return_cache) 73 + { 74 + struct acpi_memory_list *cache; 75 + 76 + 77 + if (!cache_name || !return_cache || (object_size < 16)) { 78 + return (AE_BAD_PARAMETER); 79 + } 80 + 81 + /* Create the cache object */ 82 + 83 + cache = acpi_os_allocate (sizeof (struct acpi_memory_list)); 84 + if (!cache) { 85 + return (AE_NO_MEMORY); 86 + } 87 + 88 + /* Populate the cache object and return it */ 89 + 90 + ACPI_MEMSET (cache, 0, sizeof (struct acpi_memory_list)); 91 + cache->link_offset = 8; 92 + cache->list_name = cache_name; 93 + cache->object_size = object_size; 94 + cache->max_depth = max_depth; 95 + 96 + *return_cache = cache; 97 + return (AE_OK); 98 + } 99 + 100 + 101 + /******************************************************************************* 102 + * 103 + * FUNCTION: acpi_os_purge_cache 104 + * 105 + * PARAMETERS: Cache - Handle to cache object 106 + * 107 + * RETURN: Status 108 + * 109 + * DESCRIPTION: Free all objects within the requested cache. 110 + * 111 + ******************************************************************************/ 112 + 113 + acpi_status 114 + acpi_os_purge_cache ( 115 + struct acpi_memory_list *cache) 116 + { 117 + char *next; 118 + 119 + 120 + ACPI_FUNCTION_ENTRY (); 121 + 122 + 123 + if (!cache) { 124 + return (AE_BAD_PARAMETER); 125 + } 126 + 127 + /* Walk the list of objects in this cache */ 128 + 129 + while (cache->list_head) { 130 + /* Delete and unlink one cached state object */ 131 + 132 + next = *(ACPI_CAST_INDIRECT_PTR (char, 133 + &(((char *) cache->list_head)[cache->link_offset]))); 134 + ACPI_MEM_FREE (cache->list_head); 135 + 136 + cache->list_head = next; 137 + cache->current_depth--; 138 + } 139 + 140 + return (AE_OK); 141 + } 142 + 143 + 144 + /******************************************************************************* 145 + * 146 + * FUNCTION: acpi_os_delete_cache 147 + * 148 + * PARAMETERS: Cache - Handle to cache object 149 + * 150 + * RETURN: Status 151 + * 152 + * DESCRIPTION: Free all objects within the requested cache and delete the 153 + * cache object. 154 + * 155 + ******************************************************************************/ 156 + 157 + acpi_status 158 + acpi_os_delete_cache ( 159 + struct acpi_memory_list *cache) 160 + { 161 + acpi_status status; 162 + 163 + 164 + /* Purge all objects in the cache */ 165 + 166 + status = acpi_os_purge_cache (cache); 167 + if (ACPI_FAILURE (status)) { 168 + return (status); 169 + } 170 + 171 + /* Now we can delete the cache object */ 172 + 173 + acpi_os_free (cache); 174 + return (AE_OK); 175 + } 176 + 177 + 178 + /******************************************************************************* 179 + * 180 + * FUNCTION: acpi_os_release_object 181 + * 182 + * PARAMETERS: Cache - Handle to cache object 183 + * Object - The object to be released 184 + * 185 + * RETURN: None 186 + * 187 + * DESCRIPTION: Release an object to the specified cache. If cache is full, 188 + * the object is deleted. 189 + * 190 + ******************************************************************************/ 191 + 192 + acpi_status 193 + acpi_os_release_object ( 194 + struct acpi_memory_list *cache, 195 + void *object) 196 + { 197 + acpi_status status; 198 + 199 + 200 + ACPI_FUNCTION_ENTRY (); 201 + 202 + 203 + if (!cache || !object) { 204 + return (AE_BAD_PARAMETER); 205 + } 206 + 207 + /* If cache is full, just free this object */ 208 + 209 + if (cache->current_depth >= cache->max_depth) { 210 + ACPI_MEM_FREE (object); 211 + ACPI_MEM_TRACKING (cache->total_freed++); 212 + } 213 + 214 + /* Otherwise put this object back into the cache */ 215 + 216 + else { 217 + status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES); 218 + if (ACPI_FAILURE (status)) { 219 + return (status); 220 + } 221 + 222 + /* Mark the object as cached */ 223 + 224 + ACPI_MEMSET (object, 0xCA, cache->object_size); 225 + ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_CACHED); 226 + 227 + /* Put the object at the head of the cache list */ 228 + 229 + * (ACPI_CAST_INDIRECT_PTR (char, 230 + &(((char *) object)[cache->link_offset]))) = cache->list_head; 231 + cache->list_head = object; 232 + cache->current_depth++; 233 + 234 + (void) acpi_ut_release_mutex (ACPI_MTX_CACHES); 235 + } 236 + 237 + return (AE_OK); 238 + } 239 + 240 + 241 + /******************************************************************************* 242 + * 243 + * FUNCTION: acpi_os_acquire_object 244 + * 245 + * PARAMETERS: Cache - Handle to cache object 246 + * 247 + * RETURN: the acquired object. NULL on error 248 + * 249 + * DESCRIPTION: Get an object from the specified cache. If cache is empty, 250 + * the object is allocated. 251 + * 252 + ******************************************************************************/ 253 + 254 + void * 255 + acpi_os_acquire_object ( 256 + struct acpi_memory_list *cache) 257 + { 258 + acpi_status status; 259 + void *object; 260 + 261 + 262 + ACPI_FUNCTION_NAME ("ut_acquire_from_cache"); 263 + 264 + 265 + if (!cache) { 266 + return (NULL); 267 + } 268 + 269 + status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES); 270 + if (ACPI_FAILURE (status)) { 271 + return (NULL); 272 + } 273 + 274 + ACPI_MEM_TRACKING (cache->requests++); 275 + 276 + /* Check the cache first */ 277 + 278 + if (cache->list_head) { 279 + /* There is an object available, use it */ 280 + 281 + object = cache->list_head; 282 + cache->list_head = *(ACPI_CAST_INDIRECT_PTR (char, 283 + &(((char *) object)[cache->link_offset]))); 284 + 285 + cache->current_depth--; 286 + 287 + ACPI_MEM_TRACKING (cache->hits++); 288 + ACPI_MEM_TRACKING (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 289 + "Object %p from %s\n", object, cache->list_name))); 290 + 291 + status = acpi_ut_release_mutex (ACPI_MTX_CACHES); 292 + if (ACPI_FAILURE (status)) { 293 + return (NULL); 294 + } 295 + 296 + /* Clear (zero) the previously used Object */ 297 + 298 + ACPI_MEMSET (object, 0, cache->object_size); 299 + } 300 + else { 301 + /* The cache is empty, create a new object */ 302 + 303 + ACPI_MEM_TRACKING (cache->total_allocated++); 304 + 305 + /* Avoid deadlock with ACPI_MEM_CALLOCATE */ 306 + 307 + status = acpi_ut_release_mutex (ACPI_MTX_CACHES); 308 + if (ACPI_FAILURE (status)) { 309 + return (NULL); 310 + } 311 + 312 + object = ACPI_MEM_CALLOCATE (cache->object_size); 313 + if (!object) { 314 + return (NULL); 315 + } 316 + } 317 + 318 + return (object); 319 + } 320 + #endif /* ACPI_USE_LOCAL_CACHE */ 321 + 322 +
+2 -2
drivers/acpi/utilities/utdebug.c
··· 549 549 /* Dump fill spaces */ 550 550 551 551 acpi_os_printf ("%*s", ((display * 2) + 1), " "); 552 - j += display; 552 + j += (acpi_native_uint) display; 553 553 continue; 554 554 } 555 555 ··· 584 584 break; 585 585 } 586 586 587 - j += display; 587 + j += (acpi_native_uint) display; 588 588 } 589 589 590 590 /*
+7 -29
drivers/acpi/utilities/utglobal.c
··· 820 820 acpi_ut_init_globals ( 821 821 void) 822 822 { 823 + acpi_status status; 823 824 u32 i; 824 825 825 826 826 827 ACPI_FUNCTION_TRACE ("ut_init_globals"); 827 828 828 829 829 - /* Memory allocation and cache lists */ 830 + /* Create all memory caches */ 830 831 831 - ACPI_MEMSET (acpi_gbl_memory_lists, 0, sizeof (struct acpi_memory_list) * ACPI_NUM_MEM_LISTS); 832 - 833 - acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_generic_state *) NULL)->common.next), NULL); 834 - acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_parse_object *) NULL)->common.next), NULL); 835 - acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_parse_object *) NULL)->common.next), NULL); 836 - acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_operand_object *) NULL)->cache.next), NULL); 837 - acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].link_offset = (u16) ACPI_PTR_DIFF (&(((struct acpi_walk_state *) NULL)->next), NULL); 838 - 839 - acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].object_size = sizeof (struct acpi_namespace_node); 840 - acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].object_size = sizeof (union acpi_generic_state); 841 - acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].object_size = sizeof (struct acpi_parse_obj_common); 842 - acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].object_size = sizeof (struct acpi_parse_obj_named); 843 - acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].object_size = sizeof (union acpi_operand_object); 844 - acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].object_size = sizeof (struct acpi_walk_state); 845 - 846 - acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].max_cache_depth = ACPI_MAX_STATE_CACHE_DEPTH; 847 - acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].max_cache_depth = ACPI_MAX_PARSE_CACHE_DEPTH; 848 - acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].max_cache_depth = ACPI_MAX_EXTPARSE_CACHE_DEPTH; 849 - acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].max_cache_depth = ACPI_MAX_OBJECT_CACHE_DEPTH; 850 - acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].max_cache_depth = ACPI_MAX_WALK_CACHE_DEPTH; 851 - 852 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].list_name = "Global Memory Allocation"); 853 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].list_name = "Namespace Nodes"); 854 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].list_name = "State Object Cache"); 855 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].list_name = "Parse Node Cache"); 856 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].list_name = "Extended Parse Node Cache"); 857 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].list_name = "Operand Object Cache"); 858 - ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].list_name = "Tree Walk Node Cache"); 832 + status = acpi_ut_create_caches (); 833 + if (ACPI_FAILURE (status)) 834 + { 835 + return; 836 + } 859 837 860 838 /* ACPI table structure */ 861 839
+1 -1
drivers/acpi/utilities/utinit.c
··· 264 264 265 265 /* Purge the local caches */ 266 266 267 - (void) acpi_purge_cached_objects (); 267 + (void) acpi_ut_delete_caches (); 268 268 269 269 /* Debug only - display leftover memory allocation, if any */ 270 270
+4 -685
drivers/acpi/utilities/utmisc.c
··· 49 49 #define _COMPONENT ACPI_UTILITIES 50 50 ACPI_MODULE_NAME ("utmisc") 51 51 52 - /* Local prototypes */ 53 - 54 - static acpi_status 55 - acpi_ut_create_mutex ( 56 - acpi_mutex_handle mutex_id); 57 - 58 - static acpi_status 59 - acpi_ut_delete_mutex ( 60 - acpi_mutex_handle mutex_id); 61 - 62 52 63 53 /******************************************************************************* 64 54 * ··· 73 83 74 84 ACPI_FUNCTION_ENTRY (); 75 85 86 + 87 + if (!src_string) { 88 + return (NULL); 89 + } 76 90 77 91 /* Walk entire string, uppercasing the letters */ 78 92 ··· 537 543 538 544 /******************************************************************************* 539 545 * 540 - * FUNCTION: acpi_ut_mutex_initialize 541 - * 542 - * PARAMETERS: None. 543 - * 544 - * RETURN: Status 545 - * 546 - * DESCRIPTION: Create the system mutex objects. 547 - * 548 - ******************************************************************************/ 549 - 550 - acpi_status 551 - acpi_ut_mutex_initialize ( 552 - void) 553 - { 554 - u32 i; 555 - acpi_status status; 556 - 557 - 558 - ACPI_FUNCTION_TRACE ("ut_mutex_initialize"); 559 - 560 - 561 - /* 562 - * Create each of the predefined mutex objects 563 - */ 564 - for (i = 0; i < NUM_MUTEX; i++) { 565 - status = acpi_ut_create_mutex (i); 566 - if (ACPI_FAILURE (status)) { 567 - return_ACPI_STATUS (status); 568 - } 569 - } 570 - 571 - status = acpi_os_create_lock (&acpi_gbl_gpe_lock); 572 - return_ACPI_STATUS (status); 573 - } 574 - 575 - 576 - /******************************************************************************* 577 - * 578 - * FUNCTION: acpi_ut_mutex_terminate 579 - * 580 - * PARAMETERS: None. 581 - * 582 - * RETURN: None. 583 - * 584 - * DESCRIPTION: Delete all of the system mutex objects. 585 - * 586 - ******************************************************************************/ 587 - 588 - void 589 - acpi_ut_mutex_terminate ( 590 - void) 591 - { 592 - u32 i; 593 - 594 - 595 - ACPI_FUNCTION_TRACE ("ut_mutex_terminate"); 596 - 597 - 598 - /* 599 - * Delete each predefined mutex object 600 - */ 601 - for (i = 0; i < NUM_MUTEX; i++) { 602 - (void) acpi_ut_delete_mutex (i); 603 - } 604 - 605 - acpi_os_delete_lock (acpi_gbl_gpe_lock); 606 - return_VOID; 607 - } 608 - 609 - 610 - /******************************************************************************* 611 - * 612 - * FUNCTION: acpi_ut_create_mutex 613 - * 614 - * PARAMETERS: mutex_iD - ID of the mutex to be created 615 - * 616 - * RETURN: Status 617 - * 618 - * DESCRIPTION: Create a mutex object. 619 - * 620 - ******************************************************************************/ 621 - 622 - static acpi_status 623 - acpi_ut_create_mutex ( 624 - acpi_mutex_handle mutex_id) 625 - { 626 - acpi_status status = AE_OK; 627 - 628 - 629 - ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id); 630 - 631 - 632 - if (mutex_id > MAX_MUTEX) { 633 - return_ACPI_STATUS (AE_BAD_PARAMETER); 634 - } 635 - 636 - if (!acpi_gbl_mutex_info[mutex_id].mutex) { 637 - status = acpi_os_create_semaphore (1, 1, 638 - &acpi_gbl_mutex_info[mutex_id].mutex); 639 - acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 640 - acpi_gbl_mutex_info[mutex_id].use_count = 0; 641 - } 642 - 643 - return_ACPI_STATUS (status); 644 - } 645 - 646 - 647 - /******************************************************************************* 648 - * 649 - * FUNCTION: acpi_ut_delete_mutex 650 - * 651 - * PARAMETERS: mutex_iD - ID of the mutex to be deleted 652 - * 653 - * RETURN: Status 654 - * 655 - * DESCRIPTION: Delete a mutex object. 656 - * 657 - ******************************************************************************/ 658 - 659 - static acpi_status 660 - acpi_ut_delete_mutex ( 661 - acpi_mutex_handle mutex_id) 662 - { 663 - acpi_status status; 664 - 665 - 666 - ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id); 667 - 668 - 669 - if (mutex_id > MAX_MUTEX) { 670 - return_ACPI_STATUS (AE_BAD_PARAMETER); 671 - } 672 - 673 - status = acpi_os_delete_semaphore (acpi_gbl_mutex_info[mutex_id].mutex); 674 - 675 - acpi_gbl_mutex_info[mutex_id].mutex = NULL; 676 - acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 677 - 678 - return_ACPI_STATUS (status); 679 - } 680 - 681 - 682 - /******************************************************************************* 683 - * 684 - * FUNCTION: acpi_ut_acquire_mutex 685 - * 686 - * PARAMETERS: mutex_iD - ID of the mutex to be acquired 687 - * 688 - * RETURN: Status 689 - * 690 - * DESCRIPTION: Acquire a mutex object. 691 - * 692 - ******************************************************************************/ 693 - 694 - acpi_status 695 - acpi_ut_acquire_mutex ( 696 - acpi_mutex_handle mutex_id) 697 - { 698 - acpi_status status; 699 - u32 this_thread_id; 700 - 701 - 702 - ACPI_FUNCTION_NAME ("ut_acquire_mutex"); 703 - 704 - 705 - if (mutex_id > MAX_MUTEX) { 706 - return (AE_BAD_PARAMETER); 707 - } 708 - 709 - this_thread_id = acpi_os_get_thread_id (); 710 - 711 - #ifdef ACPI_MUTEX_DEBUG 712 - { 713 - u32 i; 714 - /* 715 - * Mutex debug code, for internal debugging only. 716 - * 717 - * Deadlock prevention. Check if this thread owns any mutexes of value 718 - * greater than or equal to this one. If so, the thread has violated 719 - * the mutex ordering rule. This indicates a coding error somewhere in 720 - * the ACPI subsystem code. 721 - */ 722 - for (i = mutex_id; i < MAX_MUTEX; i++) { 723 - if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) { 724 - if (i == mutex_id) { 725 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 726 - "Mutex [%s] already acquired by this thread [%X]\n", 727 - acpi_ut_get_mutex_name (mutex_id), this_thread_id)); 728 - 729 - return (AE_ALREADY_ACQUIRED); 730 - } 731 - 732 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 733 - "Invalid acquire order: Thread %X owns [%s], wants [%s]\n", 734 - this_thread_id, acpi_ut_get_mutex_name (i), 735 - acpi_ut_get_mutex_name (mutex_id))); 736 - 737 - return (AE_ACQUIRE_DEADLOCK); 738 - } 739 - } 740 - } 741 - #endif 742 - 743 - ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, 744 - "Thread %X attempting to acquire Mutex [%s]\n", 745 - this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 746 - 747 - status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 748 - 1, ACPI_WAIT_FOREVER); 749 - if (ACPI_SUCCESS (status)) { 750 - ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n", 751 - this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 752 - 753 - acpi_gbl_mutex_info[mutex_id].use_count++; 754 - acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id; 755 - } 756 - else { 757 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 758 - "Thread %X could not acquire Mutex [%s] %s\n", 759 - this_thread_id, acpi_ut_get_mutex_name (mutex_id), 760 - acpi_format_exception (status))); 761 - } 762 - 763 - return (status); 764 - } 765 - 766 - 767 - /******************************************************************************* 768 - * 769 - * FUNCTION: acpi_ut_release_mutex 770 - * 771 - * PARAMETERS: mutex_iD - ID of the mutex to be released 772 - * 773 - * RETURN: Status 774 - * 775 - * DESCRIPTION: Release a mutex object. 776 - * 777 - ******************************************************************************/ 778 - 779 - acpi_status 780 - acpi_ut_release_mutex ( 781 - acpi_mutex_handle mutex_id) 782 - { 783 - acpi_status status; 784 - u32 this_thread_id; 785 - 786 - 787 - ACPI_FUNCTION_NAME ("ut_release_mutex"); 788 - 789 - 790 - this_thread_id = acpi_os_get_thread_id (); 791 - ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, 792 - "Thread %X releasing Mutex [%s]\n", this_thread_id, 793 - acpi_ut_get_mutex_name (mutex_id))); 794 - 795 - if (mutex_id > MAX_MUTEX) { 796 - return (AE_BAD_PARAMETER); 797 - } 798 - 799 - /* 800 - * Mutex must be acquired in order to release it! 801 - */ 802 - if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) { 803 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 804 - "Mutex [%s] is not acquired, cannot release\n", 805 - acpi_ut_get_mutex_name (mutex_id))); 806 - 807 - return (AE_NOT_ACQUIRED); 808 - } 809 - 810 - #ifdef ACPI_MUTEX_DEBUG 811 - { 812 - u32 i; 813 - /* 814 - * Mutex debug code, for internal debugging only. 815 - * 816 - * Deadlock prevention. Check if this thread owns any mutexes of value 817 - * greater than this one. If so, the thread has violated the mutex 818 - * ordering rule. This indicates a coding error somewhere in 819 - * the ACPI subsystem code. 820 - */ 821 - for (i = mutex_id; i < MAX_MUTEX; i++) { 822 - if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) { 823 - if (i == mutex_id) { 824 - continue; 825 - } 826 - 827 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 828 - "Invalid release order: owns [%s], releasing [%s]\n", 829 - acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id))); 830 - 831 - return (AE_RELEASE_DEADLOCK); 832 - } 833 - } 834 - } 835 - #endif 836 - 837 - /* Mark unlocked FIRST */ 838 - 839 - acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 840 - 841 - status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1); 842 - 843 - if (ACPI_FAILURE (status)) { 844 - ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 845 - "Thread %X could not release Mutex [%s] %s\n", 846 - this_thread_id, acpi_ut_get_mutex_name (mutex_id), 847 - acpi_format_exception (status))); 848 - } 849 - else { 850 - ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n", 851 - this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 852 - } 853 - 854 - return (status); 855 - } 856 - 857 - 858 - /******************************************************************************* 859 - * 860 546 * FUNCTION: acpi_ut_create_update_state_and_push 861 547 * 862 548 * PARAMETERS: Object - Object to be added to the new state ··· 575 901 acpi_ut_push_generic_state (state_list, state); 576 902 return (AE_OK); 577 903 } 578 - 579 - 580 - /******************************************************************************* 581 - * 582 - * FUNCTION: acpi_ut_create_pkg_state_and_push 583 - * 584 - * PARAMETERS: Object - Object to be added to the new state 585 - * Action - Increment/Decrement 586 - * state_list - List the state will be added to 587 - * 588 - * RETURN: Status 589 - * 590 - * DESCRIPTION: Create a new state and push it 591 - * 592 - ******************************************************************************/ 593 - 594 - #ifdef ACPI_FUTURE_USAGE 595 - acpi_status 596 - acpi_ut_create_pkg_state_and_push ( 597 - void *internal_object, 598 - void *external_object, 599 - u16 index, 600 - union acpi_generic_state **state_list) 601 - { 602 - union acpi_generic_state *state; 603 - 604 - 605 - ACPI_FUNCTION_ENTRY (); 606 - 607 - 608 - state = acpi_ut_create_pkg_state (internal_object, external_object, index); 609 - if (!state) { 610 - return (AE_NO_MEMORY); 611 - } 612 - 613 - acpi_ut_push_generic_state (state_list, state); 614 - return (AE_OK); 615 - } 616 - #endif /* ACPI_FUTURE_USAGE */ 617 - 618 - /******************************************************************************* 619 - * 620 - * FUNCTION: acpi_ut_push_generic_state 621 - * 622 - * PARAMETERS: list_head - Head of the state stack 623 - * State - State object to push 624 - * 625 - * RETURN: None 626 - * 627 - * DESCRIPTION: Push a state object onto a state stack 628 - * 629 - ******************************************************************************/ 630 - 631 - void 632 - acpi_ut_push_generic_state ( 633 - union acpi_generic_state **list_head, 634 - union acpi_generic_state *state) 635 - { 636 - ACPI_FUNCTION_TRACE ("ut_push_generic_state"); 637 - 638 - 639 - /* Push the state object onto the front of the list (stack) */ 640 - 641 - state->common.next = *list_head; 642 - *list_head = state; 643 - 644 - return_VOID; 645 - } 646 - 647 - 648 - /******************************************************************************* 649 - * 650 - * FUNCTION: acpi_ut_pop_generic_state 651 - * 652 - * PARAMETERS: list_head - Head of the state stack 653 - * 654 - * RETURN: The popped state object 655 - * 656 - * DESCRIPTION: Pop a state object from a state stack 657 - * 658 - ******************************************************************************/ 659 - 660 - union acpi_generic_state * 661 - acpi_ut_pop_generic_state ( 662 - union acpi_generic_state **list_head) 663 - { 664 - union acpi_generic_state *state; 665 - 666 - 667 - ACPI_FUNCTION_TRACE ("ut_pop_generic_state"); 668 - 669 - 670 - /* Remove the state object at the head of the list (stack) */ 671 - 672 - state = *list_head; 673 - if (state) { 674 - /* Update the list head */ 675 - 676 - *list_head = state->common.next; 677 - } 678 - 679 - return_PTR (state); 680 - } 681 - 682 - 683 - /******************************************************************************* 684 - * 685 - * FUNCTION: acpi_ut_create_generic_state 686 - * 687 - * PARAMETERS: None 688 - * 689 - * RETURN: The new state object. NULL on failure. 690 - * 691 - * DESCRIPTION: Create a generic state object. Attempt to obtain one from 692 - * the global state cache; If none available, create a new one. 693 - * 694 - ******************************************************************************/ 695 - 696 - union acpi_generic_state * 697 - acpi_ut_create_generic_state ( 698 - void) 699 - { 700 - union acpi_generic_state *state; 701 - 702 - 703 - ACPI_FUNCTION_ENTRY (); 704 - 705 - 706 - state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE); 707 - 708 - /* Initialize */ 709 - 710 - if (state) { 711 - state->common.data_type = ACPI_DESC_TYPE_STATE; 712 - } 713 - 714 - return (state); 715 - } 716 - 717 - 718 - /******************************************************************************* 719 - * 720 - * FUNCTION: acpi_ut_create_thread_state 721 - * 722 - * PARAMETERS: None 723 - * 724 - * RETURN: New Thread State. NULL on failure 725 - * 726 - * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used 727 - * to track per-thread info during method execution 728 - * 729 - ******************************************************************************/ 730 - 731 - struct acpi_thread_state * 732 - acpi_ut_create_thread_state ( 733 - void) 734 - { 735 - union acpi_generic_state *state; 736 - 737 - 738 - ACPI_FUNCTION_TRACE ("ut_create_thread_state"); 739 - 740 - 741 - /* Create the generic state object */ 742 - 743 - state = acpi_ut_create_generic_state (); 744 - if (!state) { 745 - return_PTR (NULL); 746 - } 747 - 748 - /* Init fields specific to the update struct */ 749 - 750 - state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD; 751 - state->thread.thread_id = acpi_os_get_thread_id (); 752 - 753 - return_PTR ((struct acpi_thread_state *) state); 754 - } 755 - 756 - 757 - /******************************************************************************* 758 - * 759 - * FUNCTION: acpi_ut_create_update_state 760 - * 761 - * PARAMETERS: Object - Initial Object to be installed in the state 762 - * Action - Update action to be performed 763 - * 764 - * RETURN: New state object, null on failure 765 - * 766 - * DESCRIPTION: Create an "Update State" - a flavor of the generic state used 767 - * to update reference counts and delete complex objects such 768 - * as packages. 769 - * 770 - ******************************************************************************/ 771 - 772 - union acpi_generic_state * 773 - acpi_ut_create_update_state ( 774 - union acpi_operand_object *object, 775 - u16 action) 776 - { 777 - union acpi_generic_state *state; 778 - 779 - 780 - ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object); 781 - 782 - 783 - /* Create the generic state object */ 784 - 785 - state = acpi_ut_create_generic_state (); 786 - if (!state) { 787 - return_PTR (NULL); 788 - } 789 - 790 - /* Init fields specific to the update struct */ 791 - 792 - state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE; 793 - state->update.object = object; 794 - state->update.value = action; 795 - 796 - return_PTR (state); 797 - } 798 - 799 - 800 - /******************************************************************************* 801 - * 802 - * FUNCTION: acpi_ut_create_pkg_state 803 - * 804 - * PARAMETERS: Object - Initial Object to be installed in the state 805 - * Action - Update action to be performed 806 - * 807 - * RETURN: New state object, null on failure 808 - * 809 - * DESCRIPTION: Create a "Package State" 810 - * 811 - ******************************************************************************/ 812 - 813 - union acpi_generic_state * 814 - acpi_ut_create_pkg_state ( 815 - void *internal_object, 816 - void *external_object, 817 - u16 index) 818 - { 819 - union acpi_generic_state *state; 820 - 821 - 822 - ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object); 823 - 824 - 825 - /* Create the generic state object */ 826 - 827 - state = acpi_ut_create_generic_state (); 828 - if (!state) { 829 - return_PTR (NULL); 830 - } 831 - 832 - /* Init fields specific to the update struct */ 833 - 834 - state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE; 835 - state->pkg.source_object = (union acpi_operand_object *) internal_object; 836 - state->pkg.dest_object = external_object; 837 - state->pkg.index = index; 838 - state->pkg.num_packages = 1; 839 - 840 - return_PTR (state); 841 - } 842 - 843 - 844 - /******************************************************************************* 845 - * 846 - * FUNCTION: acpi_ut_create_control_state 847 - * 848 - * PARAMETERS: None 849 - * 850 - * RETURN: New state object, null on failure 851 - * 852 - * DESCRIPTION: Create a "Control State" - a flavor of the generic state used 853 - * to support nested IF/WHILE constructs in the AML. 854 - * 855 - ******************************************************************************/ 856 - 857 - union acpi_generic_state * 858 - acpi_ut_create_control_state ( 859 - void) 860 - { 861 - union acpi_generic_state *state; 862 - 863 - 864 - ACPI_FUNCTION_TRACE ("ut_create_control_state"); 865 - 866 - 867 - /* Create the generic state object */ 868 - 869 - state = acpi_ut_create_generic_state (); 870 - if (!state) { 871 - return_PTR (NULL); 872 - } 873 - 874 - /* Init fields specific to the control struct */ 875 - 876 - state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL; 877 - state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; 878 - 879 - return_PTR (state); 880 - } 881 - 882 - 883 - /******************************************************************************* 884 - * 885 - * FUNCTION: acpi_ut_delete_generic_state 886 - * 887 - * PARAMETERS: State - The state object to be deleted 888 - * 889 - * RETURN: None 890 - * 891 - * DESCRIPTION: Put a state object back into the global state cache. The object 892 - * is not actually freed at this time. 893 - * 894 - ******************************************************************************/ 895 - 896 - void 897 - acpi_ut_delete_generic_state ( 898 - union acpi_generic_state *state) 899 - { 900 - ACPI_FUNCTION_TRACE ("ut_delete_generic_state"); 901 - 902 - 903 - acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE, state); 904 - return_VOID; 905 - } 906 - 907 - 908 - #ifdef ACPI_ENABLE_OBJECT_CACHE 909 - /******************************************************************************* 910 - * 911 - * FUNCTION: acpi_ut_delete_generic_state_cache 912 - * 913 - * PARAMETERS: None 914 - * 915 - * RETURN: None 916 - * 917 - * DESCRIPTION: Purge the global state object cache. Used during subsystem 918 - * termination. 919 - * 920 - ******************************************************************************/ 921 - 922 - void 923 - acpi_ut_delete_generic_state_cache ( 924 - void) 925 - { 926 - ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache"); 927 - 928 - 929 - acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE); 930 - return_VOID; 931 - } 932 - #endif 933 904 934 905 935 906 /*******************************************************************************
+380
drivers/acpi/utilities/utmutex.c
··· 1 + /******************************************************************************* 2 + * 3 + * Module Name: utmutex - local mutex support 4 + * 5 + ******************************************************************************/ 6 + 7 + /* 8 + * Copyright (C) 2000 - 2005, R. Byron Moore 9 + * All rights reserved. 10 + * 11 + * Redistribution and use in source and binary forms, with or without 12 + * modification, are permitted provided that the following conditions 13 + * are met: 14 + * 1. Redistributions of source code must retain the above copyright 15 + * notice, this list of conditions, and the following disclaimer, 16 + * without modification. 17 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 + * substantially similar to the "NO WARRANTY" disclaimer below 19 + * ("Disclaimer") and any redistribution must be conditioned upon 20 + * including a substantially similar Disclaimer requirement for further 21 + * binary redistribution. 22 + * 3. Neither the names of the above-listed copyright holders nor the names 23 + * of any contributors may be used to endorse or promote products derived 24 + * from this software without specific prior written permission. 25 + * 26 + * Alternatively, this software may be distributed under the terms of the 27 + * GNU General Public License ("GPL") version 2 as published by the Free 28 + * Software Foundation. 29 + * 30 + * NO WARRANTY 31 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 + * POSSIBILITY OF SUCH DAMAGES. 42 + */ 43 + 44 + 45 + #include <acpi/acpi.h> 46 + 47 + #define _COMPONENT ACPI_UTILITIES 48 + ACPI_MODULE_NAME ("utmutex") 49 + 50 + /* Local prototypes */ 51 + 52 + static acpi_status 53 + acpi_ut_create_mutex ( 54 + acpi_mutex_handle mutex_id); 55 + 56 + static acpi_status 57 + acpi_ut_delete_mutex ( 58 + acpi_mutex_handle mutex_id); 59 + 60 + 61 + /******************************************************************************* 62 + * 63 + * FUNCTION: acpi_ut_mutex_initialize 64 + * 65 + * PARAMETERS: None. 66 + * 67 + * RETURN: Status 68 + * 69 + * DESCRIPTION: Create the system mutex objects. 70 + * 71 + ******************************************************************************/ 72 + 73 + acpi_status 74 + acpi_ut_mutex_initialize ( 75 + void) 76 + { 77 + u32 i; 78 + acpi_status status; 79 + 80 + 81 + ACPI_FUNCTION_TRACE ("ut_mutex_initialize"); 82 + 83 + 84 + /* 85 + * Create each of the predefined mutex objects 86 + */ 87 + for (i = 0; i < NUM_MUTEX; i++) { 88 + status = acpi_ut_create_mutex (i); 89 + if (ACPI_FAILURE (status)) { 90 + return_ACPI_STATUS (status); 91 + } 92 + } 93 + 94 + status = acpi_os_create_lock (&acpi_gbl_gpe_lock); 95 + return_ACPI_STATUS (status); 96 + } 97 + 98 + 99 + /******************************************************************************* 100 + * 101 + * FUNCTION: acpi_ut_mutex_terminate 102 + * 103 + * PARAMETERS: None. 104 + * 105 + * RETURN: None. 106 + * 107 + * DESCRIPTION: Delete all of the system mutex objects. 108 + * 109 + ******************************************************************************/ 110 + 111 + void 112 + acpi_ut_mutex_terminate ( 113 + void) 114 + { 115 + u32 i; 116 + 117 + 118 + ACPI_FUNCTION_TRACE ("ut_mutex_terminate"); 119 + 120 + 121 + /* 122 + * Delete each predefined mutex object 123 + */ 124 + for (i = 0; i < NUM_MUTEX; i++) { 125 + (void) acpi_ut_delete_mutex (i); 126 + } 127 + 128 + acpi_os_delete_lock (acpi_gbl_gpe_lock); 129 + return_VOID; 130 + } 131 + 132 + 133 + /******************************************************************************* 134 + * 135 + * FUNCTION: acpi_ut_create_mutex 136 + * 137 + * PARAMETERS: mutex_iD - ID of the mutex to be created 138 + * 139 + * RETURN: Status 140 + * 141 + * DESCRIPTION: Create a mutex object. 142 + * 143 + ******************************************************************************/ 144 + 145 + static acpi_status 146 + acpi_ut_create_mutex ( 147 + acpi_mutex_handle mutex_id) 148 + { 149 + acpi_status status = AE_OK; 150 + 151 + 152 + ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id); 153 + 154 + 155 + if (mutex_id > MAX_MUTEX) { 156 + return_ACPI_STATUS (AE_BAD_PARAMETER); 157 + } 158 + 159 + if (!acpi_gbl_mutex_info[mutex_id].mutex) { 160 + status = acpi_os_create_semaphore (1, 1, 161 + &acpi_gbl_mutex_info[mutex_id].mutex); 162 + acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 163 + acpi_gbl_mutex_info[mutex_id].use_count = 0; 164 + } 165 + 166 + return_ACPI_STATUS (status); 167 + } 168 + 169 + 170 + /******************************************************************************* 171 + * 172 + * FUNCTION: acpi_ut_delete_mutex 173 + * 174 + * PARAMETERS: mutex_iD - ID of the mutex to be deleted 175 + * 176 + * RETURN: Status 177 + * 178 + * DESCRIPTION: Delete a mutex object. 179 + * 180 + ******************************************************************************/ 181 + 182 + static acpi_status 183 + acpi_ut_delete_mutex ( 184 + acpi_mutex_handle mutex_id) 185 + { 186 + acpi_status status; 187 + 188 + 189 + ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id); 190 + 191 + 192 + if (mutex_id > MAX_MUTEX) { 193 + return_ACPI_STATUS (AE_BAD_PARAMETER); 194 + } 195 + 196 + status = acpi_os_delete_semaphore (acpi_gbl_mutex_info[mutex_id].mutex); 197 + 198 + acpi_gbl_mutex_info[mutex_id].mutex = NULL; 199 + acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 200 + 201 + return_ACPI_STATUS (status); 202 + } 203 + 204 + 205 + /******************************************************************************* 206 + * 207 + * FUNCTION: acpi_ut_acquire_mutex 208 + * 209 + * PARAMETERS: mutex_iD - ID of the mutex to be acquired 210 + * 211 + * RETURN: Status 212 + * 213 + * DESCRIPTION: Acquire a mutex object. 214 + * 215 + ******************************************************************************/ 216 + 217 + acpi_status 218 + acpi_ut_acquire_mutex ( 219 + acpi_mutex_handle mutex_id) 220 + { 221 + acpi_status status; 222 + u32 this_thread_id; 223 + 224 + 225 + ACPI_FUNCTION_NAME ("ut_acquire_mutex"); 226 + 227 + 228 + if (mutex_id > MAX_MUTEX) { 229 + return (AE_BAD_PARAMETER); 230 + } 231 + 232 + this_thread_id = acpi_os_get_thread_id (); 233 + 234 + #ifdef ACPI_MUTEX_DEBUG 235 + { 236 + u32 i; 237 + /* 238 + * Mutex debug code, for internal debugging only. 239 + * 240 + * Deadlock prevention. Check if this thread owns any mutexes of value 241 + * greater than or equal to this one. If so, the thread has violated 242 + * the mutex ordering rule. This indicates a coding error somewhere in 243 + * the ACPI subsystem code. 244 + */ 245 + for (i = mutex_id; i < MAX_MUTEX; i++) { 246 + if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) { 247 + if (i == mutex_id) { 248 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 249 + "Mutex [%s] already acquired by this thread [%X]\n", 250 + acpi_ut_get_mutex_name (mutex_id), this_thread_id)); 251 + 252 + return (AE_ALREADY_ACQUIRED); 253 + } 254 + 255 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 256 + "Invalid acquire order: Thread %X owns [%s], wants [%s]\n", 257 + this_thread_id, acpi_ut_get_mutex_name (i), 258 + acpi_ut_get_mutex_name (mutex_id))); 259 + 260 + return (AE_ACQUIRE_DEADLOCK); 261 + } 262 + } 263 + } 264 + #endif 265 + 266 + ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, 267 + "Thread %X attempting to acquire Mutex [%s]\n", 268 + this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 269 + 270 + status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 271 + 1, ACPI_WAIT_FOREVER); 272 + if (ACPI_SUCCESS (status)) { 273 + ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n", 274 + this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 275 + 276 + acpi_gbl_mutex_info[mutex_id].use_count++; 277 + acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id; 278 + } 279 + else { 280 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 281 + "Thread %X could not acquire Mutex [%s] %s\n", 282 + this_thread_id, acpi_ut_get_mutex_name (mutex_id), 283 + acpi_format_exception (status))); 284 + } 285 + 286 + return (status); 287 + } 288 + 289 + 290 + /******************************************************************************* 291 + * 292 + * FUNCTION: acpi_ut_release_mutex 293 + * 294 + * PARAMETERS: mutex_iD - ID of the mutex to be released 295 + * 296 + * RETURN: Status 297 + * 298 + * DESCRIPTION: Release a mutex object. 299 + * 300 + ******************************************************************************/ 301 + 302 + acpi_status 303 + acpi_ut_release_mutex ( 304 + acpi_mutex_handle mutex_id) 305 + { 306 + acpi_status status; 307 + u32 this_thread_id; 308 + 309 + 310 + ACPI_FUNCTION_NAME ("ut_release_mutex"); 311 + 312 + 313 + this_thread_id = acpi_os_get_thread_id (); 314 + ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, 315 + "Thread %X releasing Mutex [%s]\n", this_thread_id, 316 + acpi_ut_get_mutex_name (mutex_id))); 317 + 318 + if (mutex_id > MAX_MUTEX) { 319 + return (AE_BAD_PARAMETER); 320 + } 321 + 322 + /* 323 + * Mutex must be acquired in order to release it! 324 + */ 325 + if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) { 326 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 327 + "Mutex [%s] is not acquired, cannot release\n", 328 + acpi_ut_get_mutex_name (mutex_id))); 329 + 330 + return (AE_NOT_ACQUIRED); 331 + } 332 + 333 + #ifdef ACPI_MUTEX_DEBUG 334 + { 335 + u32 i; 336 + /* 337 + * Mutex debug code, for internal debugging only. 338 + * 339 + * Deadlock prevention. Check if this thread owns any mutexes of value 340 + * greater than this one. If so, the thread has violated the mutex 341 + * ordering rule. This indicates a coding error somewhere in 342 + * the ACPI subsystem code. 343 + */ 344 + for (i = mutex_id; i < MAX_MUTEX; i++) { 345 + if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) { 346 + if (i == mutex_id) { 347 + continue; 348 + } 349 + 350 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 351 + "Invalid release order: owns [%s], releasing [%s]\n", 352 + acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id))); 353 + 354 + return (AE_RELEASE_DEADLOCK); 355 + } 356 + } 357 + } 358 + #endif 359 + 360 + /* Mark unlocked FIRST */ 361 + 362 + acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 363 + 364 + status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1); 365 + 366 + if (ACPI_FAILURE (status)) { 367 + ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 368 + "Thread %X could not release Mutex [%s] %s\n", 369 + this_thread_id, acpi_ut_get_mutex_name (mutex_id), 370 + acpi_format_exception (status))); 371 + } 372 + else { 373 + ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n", 374 + this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 375 + } 376 + 377 + return (status); 378 + } 379 + 380 +
+3 -31
drivers/acpi/utilities/utobject.c
··· 338 338 ACPI_FUNCTION_TRACE ("ut_allocate_object_desc_dbg"); 339 339 340 340 341 - object = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_OPERAND); 341 + object = acpi_os_acquire_object (acpi_gbl_operand_cache); 342 342 if (!object) { 343 343 _ACPI_REPORT_ERROR (module_name, line_number, component_id, 344 344 ("Could not allocate an object descriptor\n")); ··· 347 347 } 348 348 349 349 /* Mark the descriptor type */ 350 - 350 + memset(object, 0, sizeof(union acpi_operand_object)); 351 351 ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_OPERAND); 352 352 353 353 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", ··· 385 385 return_VOID; 386 386 } 387 387 388 - acpi_ut_release_to_cache (ACPI_MEM_LIST_OPERAND, object); 389 - 388 + (void) acpi_os_release_object (acpi_gbl_operand_cache, object); 390 389 return_VOID; 391 390 } 392 - 393 - 394 - #ifdef ACPI_ENABLE_OBJECT_CACHE 395 - /******************************************************************************* 396 - * 397 - * FUNCTION: acpi_ut_delete_object_cache 398 - * 399 - * PARAMETERS: None 400 - * 401 - * RETURN: None 402 - * 403 - * DESCRIPTION: Purge the global state object cache. Used during subsystem 404 - * termination. 405 - * 406 - ******************************************************************************/ 407 - 408 - void 409 - acpi_ut_delete_object_cache ( 410 - void) 411 - { 412 - ACPI_FUNCTION_TRACE ("ut_delete_object_cache"); 413 - 414 - 415 - acpi_ut_delete_generic_cache (ACPI_MEM_LIST_OPERAND); 416 - return_VOID; 417 - } 418 - #endif 419 391 420 392 421 393 /*******************************************************************************
+376
drivers/acpi/utilities/utstate.c
··· 1 + /******************************************************************************* 2 + * 3 + * Module Name: utstate - state object support procedures 4 + * 5 + ******************************************************************************/ 6 + 7 + /* 8 + * Copyright (C) 2000 - 2005, R. Byron Moore 9 + * All rights reserved. 10 + * 11 + * Redistribution and use in source and binary forms, with or without 12 + * modification, are permitted provided that the following conditions 13 + * are met: 14 + * 1. Redistributions of source code must retain the above copyright 15 + * notice, this list of conditions, and the following disclaimer, 16 + * without modification. 17 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 + * substantially similar to the "NO WARRANTY" disclaimer below 19 + * ("Disclaimer") and any redistribution must be conditioned upon 20 + * including a substantially similar Disclaimer requirement for further 21 + * binary redistribution. 22 + * 3. Neither the names of the above-listed copyright holders nor the names 23 + * of any contributors may be used to endorse or promote products derived 24 + * from this software without specific prior written permission. 25 + * 26 + * Alternatively, this software may be distributed under the terms of the 27 + * GNU General Public License ("GPL") version 2 as published by the Free 28 + * Software Foundation. 29 + * 30 + * NO WARRANTY 31 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 + * POSSIBILITY OF SUCH DAMAGES. 42 + */ 43 + 44 + 45 + #include <acpi/acpi.h> 46 + 47 + #define _COMPONENT ACPI_UTILITIES 48 + ACPI_MODULE_NAME ("utstate") 49 + 50 + 51 + /******************************************************************************* 52 + * 53 + * FUNCTION: acpi_ut_create_pkg_state_and_push 54 + * 55 + * PARAMETERS: Object - Object to be added to the new state 56 + * Action - Increment/Decrement 57 + * state_list - List the state will be added to 58 + * 59 + * RETURN: Status 60 + * 61 + * DESCRIPTION: Create a new state and push it 62 + * 63 + ******************************************************************************/ 64 + 65 + acpi_status 66 + acpi_ut_create_pkg_state_and_push ( 67 + void *internal_object, 68 + void *external_object, 69 + u16 index, 70 + union acpi_generic_state **state_list) 71 + { 72 + union acpi_generic_state *state; 73 + 74 + 75 + ACPI_FUNCTION_ENTRY (); 76 + 77 + 78 + state = acpi_ut_create_pkg_state (internal_object, external_object, index); 79 + if (!state) { 80 + return (AE_NO_MEMORY); 81 + } 82 + 83 + acpi_ut_push_generic_state (state_list, state); 84 + return (AE_OK); 85 + } 86 + 87 + 88 + /******************************************************************************* 89 + * 90 + * FUNCTION: acpi_ut_push_generic_state 91 + * 92 + * PARAMETERS: list_head - Head of the state stack 93 + * State - State object to push 94 + * 95 + * RETURN: None 96 + * 97 + * DESCRIPTION: Push a state object onto a state stack 98 + * 99 + ******************************************************************************/ 100 + 101 + void 102 + acpi_ut_push_generic_state ( 103 + union acpi_generic_state **list_head, 104 + union acpi_generic_state *state) 105 + { 106 + ACPI_FUNCTION_TRACE ("ut_push_generic_state"); 107 + 108 + 109 + /* Push the state object onto the front of the list (stack) */ 110 + 111 + state->common.next = *list_head; 112 + *list_head = state; 113 + 114 + return_VOID; 115 + } 116 + 117 + 118 + /******************************************************************************* 119 + * 120 + * FUNCTION: acpi_ut_pop_generic_state 121 + * 122 + * PARAMETERS: list_head - Head of the state stack 123 + * 124 + * RETURN: The popped state object 125 + * 126 + * DESCRIPTION: Pop a state object from a state stack 127 + * 128 + ******************************************************************************/ 129 + 130 + union acpi_generic_state * 131 + acpi_ut_pop_generic_state ( 132 + union acpi_generic_state **list_head) 133 + { 134 + union acpi_generic_state *state; 135 + 136 + 137 + ACPI_FUNCTION_TRACE ("ut_pop_generic_state"); 138 + 139 + 140 + /* Remove the state object at the head of the list (stack) */ 141 + 142 + state = *list_head; 143 + if (state) { 144 + /* Update the list head */ 145 + 146 + *list_head = state->common.next; 147 + } 148 + 149 + return_PTR (state); 150 + } 151 + 152 + 153 + /******************************************************************************* 154 + * 155 + * FUNCTION: acpi_ut_create_generic_state 156 + * 157 + * PARAMETERS: None 158 + * 159 + * RETURN: The new state object. NULL on failure. 160 + * 161 + * DESCRIPTION: Create a generic state object. Attempt to obtain one from 162 + * the global state cache; If none available, create a new one. 163 + * 164 + ******************************************************************************/ 165 + 166 + union acpi_generic_state * 167 + acpi_ut_create_generic_state ( 168 + void) 169 + { 170 + union acpi_generic_state *state; 171 + 172 + 173 + ACPI_FUNCTION_ENTRY (); 174 + 175 + 176 + state = acpi_os_acquire_object (acpi_gbl_state_cache); 177 + if (state) { 178 + /* Initialize */ 179 + memset(state, 0, sizeof(union acpi_generic_state)); 180 + state->common.data_type = ACPI_DESC_TYPE_STATE; 181 + } 182 + 183 + return (state); 184 + } 185 + 186 + 187 + /******************************************************************************* 188 + * 189 + * FUNCTION: acpi_ut_create_thread_state 190 + * 191 + * PARAMETERS: None 192 + * 193 + * RETURN: New Thread State. NULL on failure 194 + * 195 + * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used 196 + * to track per-thread info during method execution 197 + * 198 + ******************************************************************************/ 199 + 200 + struct acpi_thread_state * 201 + acpi_ut_create_thread_state ( 202 + void) 203 + { 204 + union acpi_generic_state *state; 205 + 206 + 207 + ACPI_FUNCTION_TRACE ("ut_create_thread_state"); 208 + 209 + 210 + /* Create the generic state object */ 211 + 212 + state = acpi_ut_create_generic_state (); 213 + if (!state) { 214 + return_PTR (NULL); 215 + } 216 + 217 + /* Init fields specific to the update struct */ 218 + 219 + state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD; 220 + state->thread.thread_id = acpi_os_get_thread_id (); 221 + 222 + return_PTR ((struct acpi_thread_state *) state); 223 + } 224 + 225 + 226 + /******************************************************************************* 227 + * 228 + * FUNCTION: acpi_ut_create_update_state 229 + * 230 + * PARAMETERS: Object - Initial Object to be installed in the state 231 + * Action - Update action to be performed 232 + * 233 + * RETURN: New state object, null on failure 234 + * 235 + * DESCRIPTION: Create an "Update State" - a flavor of the generic state used 236 + * to update reference counts and delete complex objects such 237 + * as packages. 238 + * 239 + ******************************************************************************/ 240 + 241 + union acpi_generic_state * 242 + acpi_ut_create_update_state ( 243 + union acpi_operand_object *object, 244 + u16 action) 245 + { 246 + union acpi_generic_state *state; 247 + 248 + 249 + ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object); 250 + 251 + 252 + /* Create the generic state object */ 253 + 254 + state = acpi_ut_create_generic_state (); 255 + if (!state) { 256 + return_PTR (NULL); 257 + } 258 + 259 + /* Init fields specific to the update struct */ 260 + 261 + state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE; 262 + state->update.object = object; 263 + state->update.value = action; 264 + 265 + return_PTR (state); 266 + } 267 + 268 + 269 + /******************************************************************************* 270 + * 271 + * FUNCTION: acpi_ut_create_pkg_state 272 + * 273 + * PARAMETERS: Object - Initial Object to be installed in the state 274 + * Action - Update action to be performed 275 + * 276 + * RETURN: New state object, null on failure 277 + * 278 + * DESCRIPTION: Create a "Package State" 279 + * 280 + ******************************************************************************/ 281 + 282 + union acpi_generic_state * 283 + acpi_ut_create_pkg_state ( 284 + void *internal_object, 285 + void *external_object, 286 + u16 index) 287 + { 288 + union acpi_generic_state *state; 289 + 290 + 291 + ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object); 292 + 293 + 294 + /* Create the generic state object */ 295 + 296 + state = acpi_ut_create_generic_state (); 297 + if (!state) { 298 + return_PTR (NULL); 299 + } 300 + 301 + /* Init fields specific to the update struct */ 302 + 303 + state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE; 304 + state->pkg.source_object = (union acpi_operand_object *) internal_object; 305 + state->pkg.dest_object = external_object; 306 + state->pkg.index = index; 307 + state->pkg.num_packages = 1; 308 + 309 + return_PTR (state); 310 + } 311 + 312 + 313 + /******************************************************************************* 314 + * 315 + * FUNCTION: acpi_ut_create_control_state 316 + * 317 + * PARAMETERS: None 318 + * 319 + * RETURN: New state object, null on failure 320 + * 321 + * DESCRIPTION: Create a "Control State" - a flavor of the generic state used 322 + * to support nested IF/WHILE constructs in the AML. 323 + * 324 + ******************************************************************************/ 325 + 326 + union acpi_generic_state * 327 + acpi_ut_create_control_state ( 328 + void) 329 + { 330 + union acpi_generic_state *state; 331 + 332 + 333 + ACPI_FUNCTION_TRACE ("ut_create_control_state"); 334 + 335 + 336 + /* Create the generic state object */ 337 + 338 + state = acpi_ut_create_generic_state (); 339 + if (!state) { 340 + return_PTR (NULL); 341 + } 342 + 343 + /* Init fields specific to the control struct */ 344 + 345 + state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL; 346 + state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; 347 + 348 + return_PTR (state); 349 + } 350 + 351 + 352 + /******************************************************************************* 353 + * 354 + * FUNCTION: acpi_ut_delete_generic_state 355 + * 356 + * PARAMETERS: State - The state object to be deleted 357 + * 358 + * RETURN: None 359 + * 360 + * DESCRIPTION: Put a state object back into the global state cache. The object 361 + * is not actually freed at this time. 362 + * 363 + ******************************************************************************/ 364 + 365 + void 366 + acpi_ut_delete_generic_state ( 367 + union acpi_generic_state *state) 368 + { 369 + ACPI_FUNCTION_TRACE ("ut_delete_generic_state"); 370 + 371 + 372 + (void) acpi_os_release_object (acpi_gbl_state_cache, state); 373 + return_VOID; 374 + } 375 + 376 +
+8 -15
drivers/acpi/utilities/utxface.c
··· 46 46 #include <acpi/acpi.h> 47 47 #include <acpi/acevents.h> 48 48 #include <acpi/acnamesp.h> 49 - #include <acpi/acparser.h> 50 - #include <acpi/acdispat.h> 51 49 #include <acpi/acdebug.h> 52 50 53 51 #define _COMPONENT ACPI_UTILITIES ··· 77 79 78 80 ACPI_DEBUG_EXEC (acpi_ut_init_stack_ptr_trace ()); 79 81 80 - 81 - /* Initialize all globals used by the subsystem */ 82 - 83 - acpi_ut_init_globals (); 84 - 85 82 /* Initialize the OS-Dependent layer */ 86 83 87 84 status = acpi_os_initialize (); ··· 85 92 acpi_format_exception (status))); 86 93 return_ACPI_STATUS (status); 87 94 } 95 + 96 + /* Initialize all globals used by the subsystem */ 97 + 98 + acpi_ut_init_globals (); 88 99 89 100 /* Create the default mutex objects */ 90 101 ··· 519 522 { 520 523 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects"); 521 524 522 - 523 - #ifdef ACPI_ENABLE_OBJECT_CACHE 524 - acpi_ut_delete_generic_state_cache (); 525 - acpi_ut_delete_object_cache (); 526 - acpi_ds_delete_walk_state_cache (); 527 - acpi_ps_delete_parse_cache (); 528 - #endif 529 - 525 + (void) acpi_os_purge_cache (acpi_gbl_state_cache); 526 + (void) acpi_os_purge_cache (acpi_gbl_operand_cache); 527 + (void) acpi_os_purge_cache (acpi_gbl_ps_node_cache); 528 + (void) acpi_os_purge_cache (acpi_gbl_ps_node_ext_cache); 530 529 return_ACPI_STATUS (AE_OK); 531 530 }
+4 -5
include/acpi/acconfig.h
··· 64 64 65 65 /* Version string */ 66 66 67 - #define ACPI_CA_VERSION 0x20050526 67 + #define ACPI_CA_VERSION 0x20050624 68 68 69 69 /* 70 70 * OS name, used for the _OS object. The _OS object is essentially obsolete, ··· 78 78 79 79 /* Maximum objects in the various object caches */ 80 80 81 - #define ACPI_MAX_STATE_CACHE_DEPTH 64 /* State objects */ 81 + #define ACPI_MAX_STATE_CACHE_DEPTH 96 /* State objects */ 82 82 #define ACPI_MAX_PARSE_CACHE_DEPTH 96 /* Parse tree objects */ 83 - #define ACPI_MAX_EXTPARSE_CACHE_DEPTH 64 /* Parse tree objects */ 84 - #define ACPI_MAX_OBJECT_CACHE_DEPTH 64 /* Interpreter operand objects */ 85 - #define ACPI_MAX_WALK_CACHE_DEPTH 4 /* Objects for parse tree walks */ 83 + #define ACPI_MAX_EXTPARSE_CACHE_DEPTH 96 /* Parse tree objects */ 84 + #define ACPI_MAX_OBJECT_CACHE_DEPTH 96 /* Interpreter operand objects */ 86 85 87 86 /* 88 87 * Should the subystem abort the loading of an ACPI table if the
+5 -1
include/acpi/acdebug.h
··· 114 114 union acpi_parse_object *op); 115 115 116 116 void 117 + acpi_db_get_bus_info ( 118 + void); 119 + 120 + void 117 121 acpi_db_disassemble_aml ( 118 122 char *statements, 119 123 union acpi_parse_object *op); ··· 331 327 u32 where); 332 328 333 329 void 334 - acpi_db_dump_object ( 330 + acpi_db_dump_external_object ( 335 331 union acpi_object *obj_desc, 336 332 u32 level); 337 333
+1
include/acpi/acdisasm.h
··· 90 90 { 91 91 u32 level; 92 92 u32 bit_offset; 93 + struct acpi_walk_state *walk_state; 93 94 }; 94 95 95 96 typedef
-6
include/acpi/acdispat.h
··· 450 450 union acpi_operand_object **object, 451 451 struct acpi_walk_state *walk_state); 452 452 453 - #ifdef ACPI_ENABLE_OBJECT_CACHE 454 - void 455 - acpi_ds_delete_walk_state_cache ( 456 - void); 457 - #endif 458 - 459 453 #endif /* _ACDISPAT_H_ */
+1 -2
include/acpi/acevents.h
··· 122 122 123 123 acpi_status 124 124 acpi_ev_walk_gpe_list ( 125 - ACPI_GPE_CALLBACK gpe_walk_callback, 126 - u32 flags); 125 + ACPI_GPE_CALLBACK gpe_walk_callback); 127 126 128 127 acpi_status 129 128 acpi_ev_delete_gpe_handlers (
+25 -1
include/acpi/acglobal.h
··· 151 151 */ 152 152 153 153 154 + /* The root table can be either an RSDT or an XSDT */ 155 + 156 + ACPI_EXTERN u8 acpi_gbl_root_table_type; 157 + #define ACPI_TABLE_TYPE_RSDT 'R' 158 + #define ACPI_TABLE_TYPE_XSDT 'X' 159 + 160 + 154 161 /* 155 162 * Handle both ACPI 1.0 and ACPI 2.0 Integer widths: 156 163 * If we are executing a method that exists in a 32-bit ACPI table, ··· 187 180 * 188 181 ****************************************************************************/ 189 182 183 + #ifdef ACPI_DBG_TRACK_ALLOCATIONS 190 184 191 - ACPI_EXTERN struct acpi_memory_list acpi_gbl_memory_lists[ACPI_NUM_MEM_LISTS]; 185 + /* Lists for tracking memory allocations */ 186 + 187 + ACPI_EXTERN struct acpi_memory_list *acpi_gbl_global_list; 188 + ACPI_EXTERN struct acpi_memory_list *acpi_gbl_ns_node_list; 189 + #endif 190 + 191 + /* Object caches */ 192 + 193 + ACPI_EXTERN acpi_cache_t *acpi_gbl_state_cache; 194 + ACPI_EXTERN acpi_cache_t *acpi_gbl_ps_node_cache; 195 + ACPI_EXTERN acpi_cache_t *acpi_gbl_ps_node_ext_cache; 196 + ACPI_EXTERN acpi_cache_t *acpi_gbl_operand_cache; 197 + 198 + /* Global handlers */ 199 + 192 200 ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_device_notify; 193 201 ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_system_notify; 194 202 ACPI_EXTERN acpi_exception_handler acpi_gbl_exception_handler; 195 203 ACPI_EXTERN acpi_init_handler acpi_gbl_init_handler; 196 204 ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk; 197 205 ACPI_EXTERN acpi_handle acpi_gbl_global_lock_semaphore; 206 + 207 + /* Misc */ 198 208 199 209 ACPI_EXTERN u32 acpi_gbl_global_lock_thread_count; 200 210 ACPI_EXTERN u32 acpi_gbl_original_mode;
+3 -3
include/acpi/achware.h
··· 143 143 144 144 acpi_status 145 145 acpi_hw_disable_all_gpes ( 146 - u32 flags); 146 + void); 147 147 148 148 acpi_status 149 149 acpi_hw_enable_all_runtime_gpes ( 150 - u32 flags); 150 + void); 151 151 152 152 acpi_status 153 153 acpi_hw_enable_all_wakeup_gpes ( 154 - u32 flags); 154 + void); 155 155 156 156 acpi_status 157 157 acpi_hw_enable_runtime_gpe_block (
+8 -16
include/acpi/aclocal.h
··· 953 953 954 954 #define ACPI_MEM_LIST_GLOBAL 0 955 955 #define ACPI_MEM_LIST_NSNODE 1 956 - 957 - #define ACPI_MEM_LIST_FIRST_CACHE_LIST 2 958 - #define ACPI_MEM_LIST_STATE 2 959 - #define ACPI_MEM_LIST_PSNODE 3 960 - #define ACPI_MEM_LIST_PSNODE_EXT 4 961 - #define ACPI_MEM_LIST_OPERAND 5 962 - #define ACPI_MEM_LIST_WALK 6 963 - #define ACPI_MEM_LIST_MAX 6 964 - #define ACPI_NUM_MEM_LISTS 7 956 + #define ACPI_MEM_LIST_MAX 1 957 + #define ACPI_NUM_MEM_LISTS 2 965 958 966 959 967 960 struct acpi_memory_list 968 961 { 962 + char *list_name; 969 963 void *list_head; 970 - u16 link_offset; 971 - u16 max_cache_depth; 972 - u16 cache_depth; 973 964 u16 object_size; 965 + u16 max_depth; 966 + u16 current_depth; 967 + u16 link_offset; 974 968 975 969 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 976 970 ··· 973 979 u32 total_allocated; 974 980 u32 total_freed; 975 981 u32 current_total_size; 976 - u32 cache_requests; 977 - u32 cache_hits; 978 - char *list_name; 982 + u32 requests; 983 + u32 hits; 979 984 #endif 980 985 }; 981 - 982 986 983 987 #endif /* __ACLOCAL_H__ */
+20 -6
include/acpi/acparser.h
··· 63 63 #define ACPI_PARSE_MODE_MASK 0x0030 64 64 65 65 #define ACPI_PARSE_DEFERRED_OP 0x0100 66 + #define ACPI_PARSE_DISASSEMBLE 0x0200 66 67 67 68 68 69 /****************************************************************************** ··· 158 157 u16 159 158 acpi_ps_peek_opcode ( 160 159 struct acpi_parse_state *state); 160 + 161 + acpi_status 162 + acpi_ps_complete_this_op ( 163 + struct acpi_walk_state *walk_state, 164 + union acpi_parse_object *op); 165 + 166 + acpi_status 167 + acpi_ps_next_parse_state ( 168 + struct acpi_walk_state *walk_state, 169 + union acpi_parse_object *op, 170 + acpi_status callback_status); 171 + 172 + 173 + /* 174 + * psloop - main parse loop 175 + */ 176 + acpi_status 177 + acpi_ps_parse_loop ( 178 + struct acpi_walk_state *walk_state); 161 179 162 180 163 181 /* ··· 310 290 acpi_ps_set_name( 311 291 union acpi_parse_object *op, 312 292 u32 name); 313 - 314 - #ifdef ACPI_ENABLE_OBJECT_CACHE 315 - void 316 - acpi_ps_delete_parse_cache ( 317 - void); 318 - #endif 319 293 320 294 321 295 /*
+31 -4
include/acpi/acpiosxf.h
··· 139 139 acpi_os_delete_lock ( 140 140 acpi_handle handle); 141 141 142 - void 142 + unsigned long 143 143 acpi_os_acquire_lock ( 144 - acpi_handle handle, 145 - u32 flags); 144 + acpi_handle handle); 146 145 147 146 void 148 147 acpi_os_release_lock ( 149 148 acpi_handle handle, 150 - u32 flags); 149 + unsigned long flags); 151 150 152 151 153 152 /* ··· 178 179 acpi_physical_address *physical_address); 179 180 #endif 180 181 182 + 183 + 184 + /* 185 + * Memory/Object Cache 186 + */ 187 + acpi_status 188 + acpi_os_create_cache ( 189 + char *cache_name, 190 + u16 object_size, 191 + u16 max_depth, 192 + acpi_cache_t **return_cache); 193 + 194 + acpi_status 195 + acpi_os_delete_cache ( 196 + acpi_cache_t *cache); 197 + 198 + acpi_status 199 + acpi_os_purge_cache ( 200 + acpi_cache_t *cache); 201 + 202 + void * 203 + acpi_os_acquire_object ( 204 + acpi_cache_t *cache); 205 + 206 + acpi_status 207 + acpi_os_release_object ( 208 + acpi_cache_t *cache, 209 + void *object); 181 210 182 211 /* 183 212 * Interrupt handlers
+3
include/acpi/acstruct.h
··· 162 162 163 163 #define ACPI_DISPLAY_SUMMARY 0 164 164 #define ACPI_DISPLAY_OBJECTS 1 165 + #define ACPI_DISPLAY_MASK 1 166 + 167 + #define ACPI_DISPLAY_SHORT 2 165 168 166 169 struct acpi_get_devices_info 167 170 {
+5
include/acpi/actypes.h
··· 243 243 #define ACPI_LOGMODE_PHYSPTR ACPI_LOGICAL_ADDRESSING | ACPI_PHYSICAL_POINTER 244 244 #define ACPI_LOGMODE_LOGPTR ACPI_LOGICAL_ADDRESSING | ACPI_LOGICAL_POINTER 245 245 246 + /* Types for the OS interface layer (OSL) */ 247 + 248 + #ifdef ACPI_USE_LOCAL_CACHE 249 + #define acpi_cache_t struct acpi_memory_list 250 + #endif 246 251 247 252 /* 248 253 * Useful defines
+26 -39
include/acpi/acutils.h
··· 557 557 acpi_ut_delete_generic_state ( 558 558 union acpi_generic_state *state); 559 559 560 - #ifdef ACPI_ENABLE_OBJECT_CACHE 561 - void 562 - acpi_ut_delete_generic_state_cache ( 563 - void); 564 - 565 - void 566 - acpi_ut_delete_object_cache ( 567 - void); 568 - #endif 569 - 570 560 571 561 /* 572 562 * utmath ··· 612 622 613 623 #define ACPI_ANY_BASE 0 614 624 615 - acpi_status 616 - acpi_ut_mutex_initialize ( 617 - void); 618 - 619 - void 620 - acpi_ut_mutex_terminate ( 621 - void); 622 - 623 - acpi_status 624 - acpi_ut_acquire_mutex ( 625 - acpi_mutex_handle mutex_id); 626 - 627 - acpi_status 628 - acpi_ut_release_mutex ( 629 - acpi_mutex_handle mutex_id); 630 - 631 625 u8 * 632 626 acpi_ut_get_resource_end_tag ( 633 627 union acpi_operand_object *obj_desc); ··· 640 666 641 667 642 668 /* 669 + * utmutex - mutex support 670 + */ 671 + acpi_status 672 + acpi_ut_mutex_initialize ( 673 + void); 674 + 675 + void 676 + acpi_ut_mutex_terminate ( 677 + void); 678 + 679 + acpi_status 680 + acpi_ut_acquire_mutex ( 681 + acpi_mutex_handle mutex_id); 682 + 683 + acpi_status 684 + acpi_ut_release_mutex ( 685 + acpi_mutex_handle mutex_id); 686 + 687 + 688 + /* 643 689 * utalloc - memory allocation and object caching 644 690 */ 645 - void * 646 - acpi_ut_acquire_from_cache ( 647 - u32 list_id); 691 + acpi_status 692 + acpi_ut_create_caches ( 693 + void); 648 694 649 - void 650 - acpi_ut_release_to_cache ( 651 - u32 list_id, 652 - void *object); 653 - 654 - #ifdef ACPI_ENABLE_OBJECT_CACHE 655 - void 656 - acpi_ut_delete_generic_cache ( 657 - u32 list_id); 658 - #endif 695 + acpi_status 696 + acpi_ut_delete_caches ( 697 + void); 659 698 660 699 acpi_status 661 700 acpi_ut_validate_buffer (
+2 -2
include/acpi/amlcode.h
··· 69 69 #define AML_MULTI_NAME_PREFIX_OP (u16) 0x2f 70 70 #define AML_NAME_CHAR_SUBSEQ (u16) 0x30 71 71 #define AML_NAME_CHAR_FIRST (u16) 0x41 72 - #define AML_OP_PREFIX (u16) 0x5b 72 + #define AML_EXTENDED_OP_PREFIX (u16) 0x5b 73 73 #define AML_ROOT_PREFIX (u16) 0x5c 74 74 #define AML_PARENT_PREFIX (u16) 0x5e 75 75 #define AML_LOCAL_OP (u16) 0x60 ··· 146 146 147 147 /* prefixed opcodes */ 148 148 149 - #define AML_EXTOP (u16) 0x005b /* prefix for 2-byte opcodes */ 149 + #define AML_EXTENDED_OPCODE (u16) 0x5b00 /* prefix for 2-byte opcodes */ 150 150 151 151 #define AML_MUTEX_OP (u16) 0x5b01 152 152 #define AML_EVENT_OP (u16) 0x5b02
+11 -8
include/acpi/platform/acenv.h
··· 49 49 * Configuration for ACPI tools and utilities 50 50 */ 51 51 52 - #ifdef _ACPI_DUMP_APP 52 + #ifdef ACPI_LIBRARY 53 + #define ACPI_USE_LOCAL_CACHE 54 + #endif 55 + 56 + #ifdef ACPI_DUMP_APP 53 57 #ifndef MSDOS 54 58 #define ACPI_DEBUG_OUTPUT 55 59 #endif 56 60 #define ACPI_APPLICATION 57 61 #define ACPI_DISASSEMBLER 58 62 #define ACPI_NO_METHOD_EXECUTION 59 - #define ACPI_USE_SYSTEM_CLIBRARY 60 - #define ACPI_ENABLE_OBJECT_CACHE 61 63 #endif 62 64 63 - #ifdef _ACPI_EXEC_APP 65 + #ifdef ACPI_EXEC_APP 64 66 #undef DEBUGGER_THREADING 65 67 #define DEBUGGER_THREADING DEBUGGER_SINGLE_THREADED 66 68 #define ACPI_DEBUG_OUTPUT 67 69 #define ACPI_APPLICATION 68 70 #define ACPI_DEBUGGER 69 71 #define ACPI_DISASSEMBLER 70 - #define ACPI_USE_SYSTEM_CLIBRARY 71 - #define ACPI_ENABLE_OBJECT_CACHE 72 72 #endif 73 73 74 - #ifdef _ACPI_ASL_COMPILER 74 + #ifdef ACPI_ASL_COMPILER 75 75 #define ACPI_DEBUG_OUTPUT 76 76 #define ACPI_APPLICATION 77 77 #define ACPI_DISASSEMBLER 78 78 #define ACPI_CONSTANT_EVAL_ONLY 79 + #endif 80 + 81 + #ifdef ACPI_APPLICATION 79 82 #define ACPI_USE_SYSTEM_CLIBRARY 80 - #define ACPI_ENABLE_OBJECT_CACHE 83 + #define ACPI_USE_LOCAL_CACHE 81 84 #endif 82 85 83 86 /*
+11
include/acpi/platform/aclinux.h
··· 62 62 63 63 #define ACPI_MACHINE_WIDTH BITS_PER_LONG 64 64 65 + /* Type(s) for the OSL */ 66 + 67 + #ifdef ACPI_USE_LOCAL_CACHE 68 + #define acpi_cache_t struct acpi_memory_list 69 + #else 70 + #include <linux/slab.h> 71 + #define acpi_cache_t kmem_cache_t 72 + #endif 73 + 74 + 75 + 65 76 #else /* !__KERNEL__ */ 66 77 67 78 #include <stdarg.h>