initial commit with v3.6.7
[linux-3.6.7-moxart.git] / drivers / acpi / acpica / utmisc.c
blob33c6cf7ff4675b896df5c44920eeab2ddd8f7f41
1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <linux/module.h>
46 #include <acpi/acpi.h>
47 #include "accommon.h"
48 #include "acnamesp.h"
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME("utmisc")
53 #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
54 /*******************************************************************************
56 * FUNCTION: ut_convert_backslashes
58 * PARAMETERS: pathname - File pathname string to be converted
60 * RETURN: Modifies the input Pathname
62 * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
63 * the entire input file pathname string.
65 ******************************************************************************/
66 void ut_convert_backslashes(char *pathname)
69 if (!pathname) {
70 return;
73 while (*pathname) {
74 if (*pathname == '\\') {
75 *pathname = '/';
78 pathname++;
81 #endif
83 /*******************************************************************************
85 * FUNCTION: acpi_ut_is_pci_root_bridge
87 * PARAMETERS: id - The HID/CID in string format
89 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
91 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
93 ******************************************************************************/
95 u8 acpi_ut_is_pci_root_bridge(char *id)
99 * Check if this is a PCI root bridge.
100 * ACPI 3.0+: check for a PCI Express root also.
102 if (!(ACPI_STRCMP(id,
103 PCI_ROOT_HID_STRING)) ||
104 !(ACPI_STRCMP(id, PCI_EXPRESS_ROOT_HID_STRING))) {
105 return (TRUE);
108 return (FALSE);
111 /*******************************************************************************
113 * FUNCTION: acpi_ut_is_aml_table
115 * PARAMETERS: table - An ACPI table
117 * RETURN: TRUE if table contains executable AML; FALSE otherwise
119 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
120 * Currently, these are DSDT,SSDT,PSDT. All other table types are
121 * data tables that do not contain AML code.
123 ******************************************************************************/
125 u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
128 /* These are the only tables that contain executable AML */
130 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
131 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
132 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
133 return (TRUE);
136 return (FALSE);
139 /*******************************************************************************
141 * FUNCTION: acpi_ut_allocate_owner_id
143 * PARAMETERS: owner_id - Where the new owner ID is returned
145 * RETURN: Status
147 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
148 * track objects created by the table or method, to be deleted
149 * when the method exits or the table is unloaded.
151 ******************************************************************************/
153 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
155 u32 i;
156 u32 j;
157 u32 k;
158 acpi_status status;
160 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
162 /* Guard against multiple allocations of ID to the same location */
164 if (*owner_id) {
165 ACPI_ERROR((AE_INFO, "Owner ID [0x%2.2X] already exists",
166 *owner_id));
167 return_ACPI_STATUS(AE_ALREADY_EXISTS);
170 /* Mutex for the global ID mask */
172 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
173 if (ACPI_FAILURE(status)) {
174 return_ACPI_STATUS(status);
178 * Find a free owner ID, cycle through all possible IDs on repeated
179 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
180 * to be scanned twice.
182 for (i = 0, j = acpi_gbl_last_owner_id_index;
183 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
184 if (j >= ACPI_NUM_OWNERID_MASKS) {
185 j = 0; /* Wraparound to start of mask array */
188 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
189 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
191 /* There are no free IDs in this mask */
193 break;
196 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
198 * Found a free ID. The actual ID is the bit index plus one,
199 * making zero an invalid Owner ID. Save this as the last ID
200 * allocated and update the global ID mask.
202 acpi_gbl_owner_id_mask[j] |= (1 << k);
204 acpi_gbl_last_owner_id_index = (u8) j;
205 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
208 * Construct encoded ID from the index and bit position
210 * Note: Last [j].k (bit 255) is never used and is marked
211 * permanently allocated (prevents +1 overflow)
213 *owner_id =
214 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
216 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
217 "Allocated OwnerId: %2.2X\n",
218 (unsigned int)*owner_id));
219 goto exit;
223 acpi_gbl_next_owner_id_offset = 0;
227 * All owner_ids have been allocated. This typically should
228 * not happen since the IDs are reused after deallocation. The IDs are
229 * allocated upon table load (one per table) and method execution, and
230 * they are released when a table is unloaded or a method completes
231 * execution.
233 * If this error happens, there may be very deep nesting of invoked control
234 * methods, or there may be a bug where the IDs are not released.
236 status = AE_OWNER_ID_LIMIT;
237 ACPI_ERROR((AE_INFO,
238 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
240 exit:
241 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
242 return_ACPI_STATUS(status);
245 /*******************************************************************************
247 * FUNCTION: acpi_ut_release_owner_id
249 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_ID
251 * RETURN: None. No error is returned because we are either exiting a
252 * control method or unloading a table. Either way, we would
253 * ignore any error anyway.
255 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
257 ******************************************************************************/
259 void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
261 acpi_owner_id owner_id = *owner_id_ptr;
262 acpi_status status;
263 u32 index;
264 u32 bit;
266 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
268 /* Always clear the input owner_id (zero is an invalid ID) */
270 *owner_id_ptr = 0;
272 /* Zero is not a valid owner_ID */
274 if (owner_id == 0) {
275 ACPI_ERROR((AE_INFO, "Invalid OwnerId: 0x%2.2X", owner_id));
276 return_VOID;
279 /* Mutex for the global ID mask */
281 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
282 if (ACPI_FAILURE(status)) {
283 return_VOID;
286 /* Normalize the ID to zero */
288 owner_id--;
290 /* Decode ID to index/offset pair */
292 index = ACPI_DIV_32(owner_id);
293 bit = 1 << ACPI_MOD_32(owner_id);
295 /* Free the owner ID only if it is valid */
297 if (acpi_gbl_owner_id_mask[index] & bit) {
298 acpi_gbl_owner_id_mask[index] ^= bit;
299 } else {
300 ACPI_ERROR((AE_INFO,
301 "Release of non-allocated OwnerId: 0x%2.2X",
302 owner_id + 1));
305 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
306 return_VOID;
309 /*******************************************************************************
311 * FUNCTION: acpi_ut_strupr (strupr)
313 * PARAMETERS: src_string - The source string to convert
315 * RETURN: None
317 * DESCRIPTION: Convert string to uppercase
319 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
321 ******************************************************************************/
323 void acpi_ut_strupr(char *src_string)
325 char *string;
327 ACPI_FUNCTION_ENTRY();
329 if (!src_string) {
330 return;
333 /* Walk entire string, uppercasing the letters */
335 for (string = src_string; *string; string++) {
336 *string = (char)ACPI_TOUPPER(*string);
339 return;
342 /*******************************************************************************
344 * FUNCTION: acpi_ut_print_string
346 * PARAMETERS: string - Null terminated ASCII string
347 * max_length - Maximum output length
349 * RETURN: None
351 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
352 * sequences.
354 ******************************************************************************/
356 void acpi_ut_print_string(char *string, u8 max_length)
358 u32 i;
360 if (!string) {
361 acpi_os_printf("<\"NULL STRING PTR\">");
362 return;
365 acpi_os_printf("\"");
366 for (i = 0; string[i] && (i < max_length); i++) {
368 /* Escape sequences */
370 switch (string[i]) {
371 case 0x07:
372 acpi_os_printf("\\a"); /* BELL */
373 break;
375 case 0x08:
376 acpi_os_printf("\\b"); /* BACKSPACE */
377 break;
379 case 0x0C:
380 acpi_os_printf("\\f"); /* FORMFEED */
381 break;
383 case 0x0A:
384 acpi_os_printf("\\n"); /* LINEFEED */
385 break;
387 case 0x0D:
388 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
389 break;
391 case 0x09:
392 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
393 break;
395 case 0x0B:
396 acpi_os_printf("\\v"); /* VERTICAL TAB */
397 break;
399 case '\'': /* Single Quote */
400 case '\"': /* Double Quote */
401 case '\\': /* Backslash */
402 acpi_os_printf("\\%c", (int)string[i]);
403 break;
405 default:
407 /* Check for printable character or hex escape */
409 if (ACPI_IS_PRINT(string[i])) {
410 /* This is a normal character */
412 acpi_os_printf("%c", (int)string[i]);
413 } else {
414 /* All others will be Hex escapes */
416 acpi_os_printf("\\x%2.2X", (s32) string[i]);
418 break;
421 acpi_os_printf("\"");
423 if (i == max_length && string[i]) {
424 acpi_os_printf("...");
428 /*******************************************************************************
430 * FUNCTION: acpi_ut_dword_byte_swap
432 * PARAMETERS: value - Value to be converted
434 * RETURN: u32 integer with bytes swapped
436 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
438 ******************************************************************************/
440 u32 acpi_ut_dword_byte_swap(u32 value)
442 union {
443 u32 value;
444 u8 bytes[4];
445 } out;
446 union {
447 u32 value;
448 u8 bytes[4];
449 } in;
451 ACPI_FUNCTION_ENTRY();
453 in.value = value;
455 out.bytes[0] = in.bytes[3];
456 out.bytes[1] = in.bytes[2];
457 out.bytes[2] = in.bytes[1];
458 out.bytes[3] = in.bytes[0];
460 return (out.value);
463 /*******************************************************************************
465 * FUNCTION: acpi_ut_set_integer_width
467 * PARAMETERS: Revision From DSDT header
469 * RETURN: None
471 * DESCRIPTION: Set the global integer bit width based upon the revision
472 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
473 * For Revision 2 and above, Integers are 64 bits. Yes, this
474 * makes a difference.
476 ******************************************************************************/
478 void acpi_ut_set_integer_width(u8 revision)
481 if (revision < 2) {
483 /* 32-bit case */
485 acpi_gbl_integer_bit_width = 32;
486 acpi_gbl_integer_nybble_width = 8;
487 acpi_gbl_integer_byte_width = 4;
488 } else {
489 /* 64-bit case (ACPI 2.0+) */
491 acpi_gbl_integer_bit_width = 64;
492 acpi_gbl_integer_nybble_width = 16;
493 acpi_gbl_integer_byte_width = 8;
497 #ifdef ACPI_DEBUG_OUTPUT
498 /*******************************************************************************
500 * FUNCTION: acpi_ut_display_init_pathname
502 * PARAMETERS: type - Object type of the node
503 * obj_handle - Handle whose pathname will be displayed
504 * path - Additional path string to be appended.
505 * (NULL if no extra path)
507 * RETURN: acpi_status
509 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
511 ******************************************************************************/
513 void
514 acpi_ut_display_init_pathname(u8 type,
515 struct acpi_namespace_node *obj_handle,
516 char *path)
518 acpi_status status;
519 struct acpi_buffer buffer;
521 ACPI_FUNCTION_ENTRY();
523 /* Only print the path if the appropriate debug level is enabled */
525 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
526 return;
529 /* Get the full pathname to the node */
531 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
532 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
533 if (ACPI_FAILURE(status)) {
534 return;
537 /* Print what we're doing */
539 switch (type) {
540 case ACPI_TYPE_METHOD:
541 acpi_os_printf("Executing ");
542 break;
544 default:
545 acpi_os_printf("Initializing ");
546 break;
549 /* Print the object type and pathname */
551 acpi_os_printf("%-12s %s",
552 acpi_ut_get_type_name(type), (char *)buffer.pointer);
554 /* Extra path is used to append names like _STA, _INI, etc. */
556 if (path) {
557 acpi_os_printf(".%s", path);
559 acpi_os_printf("\n");
561 ACPI_FREE(buffer.pointer);
563 #endif
565 /*******************************************************************************
567 * FUNCTION: acpi_ut_valid_acpi_char
569 * PARAMETERS: char - The character to be examined
570 * position - Byte position (0-3)
572 * RETURN: TRUE if the character is valid, FALSE otherwise
574 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
575 * 1) Upper case alpha
576 * 2) numeric
577 * 3) underscore
579 * We allow a '!' as the last character because of the ASF! table
581 ******************************************************************************/
583 u8 acpi_ut_valid_acpi_char(char character, u32 position)
586 if (!((character >= 'A' && character <= 'Z') ||
587 (character >= '0' && character <= '9') || (character == '_'))) {
589 /* Allow a '!' in the last position */
591 if (character == '!' && position == 3) {
592 return (TRUE);
595 return (FALSE);
598 return (TRUE);
601 /*******************************************************************************
603 * FUNCTION: acpi_ut_valid_acpi_name
605 * PARAMETERS: name - The name to be examined
607 * RETURN: TRUE if the name is valid, FALSE otherwise
609 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
610 * 1) Upper case alpha
611 * 2) numeric
612 * 3) underscore
614 ******************************************************************************/
616 u8 acpi_ut_valid_acpi_name(u32 name)
618 u32 i;
620 ACPI_FUNCTION_ENTRY();
622 for (i = 0; i < ACPI_NAME_SIZE; i++) {
623 if (!acpi_ut_valid_acpi_char
624 ((ACPI_CAST_PTR(char, &name))[i], i)) {
625 return (FALSE);
629 return (TRUE);
632 /*******************************************************************************
634 * FUNCTION: acpi_ut_repair_name
636 * PARAMETERS: name - The ACPI name to be repaired
638 * RETURN: Repaired version of the name
640 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
641 * return the new name.
643 ******************************************************************************/
645 acpi_name acpi_ut_repair_name(char *name)
647 u32 i;
648 char new_name[ACPI_NAME_SIZE];
650 for (i = 0; i < ACPI_NAME_SIZE; i++) {
651 new_name[i] = name[i];
654 * Replace a bad character with something printable, yet technically
655 * still invalid. This prevents any collisions with existing "good"
656 * names in the namespace.
658 if (!acpi_ut_valid_acpi_char(name[i], i)) {
659 new_name[i] = '*';
663 return (*(u32 *) new_name);
666 /*******************************************************************************
668 * FUNCTION: acpi_ut_strtoul64
670 * PARAMETERS: string - Null terminated string
671 * base - Radix of the string: 16 or ACPI_ANY_BASE;
672 * ACPI_ANY_BASE means 'in behalf of to_integer'
673 * ret_integer - Where the converted integer is returned
675 * RETURN: Status and Converted value
677 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
678 * 32-bit or 64-bit conversion, depending on the current mode
679 * of the interpreter.
680 * NOTE: Does not support Octal strings, not needed.
682 ******************************************************************************/
684 acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer)
686 u32 this_digit = 0;
687 u64 return_value = 0;
688 u64 quotient;
689 u64 dividend;
690 u32 to_integer_op = (base == ACPI_ANY_BASE);
691 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
692 u8 valid_digits = 0;
693 u8 sign_of0x = 0;
694 u8 term = 0;
696 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
698 switch (base) {
699 case ACPI_ANY_BASE:
700 case 16:
701 break;
703 default:
704 /* Invalid Base */
705 return_ACPI_STATUS(AE_BAD_PARAMETER);
708 if (!string) {
709 goto error_exit;
712 /* Skip over any white space in the buffer */
714 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
715 string++;
718 if (to_integer_op) {
720 * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
721 * We need to determine if it is decimal or hexadecimal.
723 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
724 sign_of0x = 1;
725 base = 16;
727 /* Skip over the leading '0x' */
728 string += 2;
729 } else {
730 base = 10;
734 /* Any string left? Check that '0x' is not followed by white space. */
736 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
737 if (to_integer_op) {
738 goto error_exit;
739 } else {
740 goto all_done;
745 * Perform a 32-bit or 64-bit conversion, depending upon the current
746 * execution mode of the interpreter
748 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
750 /* Main loop: convert the string to a 32- or 64-bit integer */
752 while (*string) {
753 if (ACPI_IS_DIGIT(*string)) {
755 /* Convert ASCII 0-9 to Decimal value */
757 this_digit = ((u8) * string) - '0';
758 } else if (base == 10) {
760 /* Digit is out of range; possible in to_integer case only */
762 term = 1;
763 } else {
764 this_digit = (u8) ACPI_TOUPPER(*string);
765 if (ACPI_IS_XDIGIT((char)this_digit)) {
767 /* Convert ASCII Hex char to value */
769 this_digit = this_digit - 'A' + 10;
770 } else {
771 term = 1;
775 if (term) {
776 if (to_integer_op) {
777 goto error_exit;
778 } else {
779 break;
781 } else if ((valid_digits == 0) && (this_digit == 0)
782 && !sign_of0x) {
784 /* Skip zeros */
785 string++;
786 continue;
789 valid_digits++;
791 if (sign_of0x && ((valid_digits > 16)
792 || ((valid_digits > 8) && mode32))) {
794 * This is to_integer operation case.
795 * No any restrictions for string-to-integer conversion,
796 * see ACPI spec.
798 goto error_exit;
801 /* Divide the digit into the correct position */
803 (void)acpi_ut_short_divide((dividend - (u64) this_digit),
804 base, &quotient, NULL);
806 if (return_value > quotient) {
807 if (to_integer_op) {
808 goto error_exit;
809 } else {
810 break;
814 return_value *= base;
815 return_value += this_digit;
816 string++;
819 /* All done, normal exit */
821 all_done:
823 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
824 ACPI_FORMAT_UINT64(return_value)));
826 *ret_integer = return_value;
827 return_ACPI_STATUS(AE_OK);
829 error_exit:
830 /* Base was set/validated above */
832 if (base == 10) {
833 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
834 } else {
835 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
839 /*******************************************************************************
841 * FUNCTION: acpi_ut_create_update_state_and_push
843 * PARAMETERS: object - Object to be added to the new state
844 * action - Increment/Decrement
845 * state_list - List the state will be added to
847 * RETURN: Status
849 * DESCRIPTION: Create a new state and push it
851 ******************************************************************************/
853 acpi_status
854 acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
855 u16 action,
856 union acpi_generic_state **state_list)
858 union acpi_generic_state *state;
860 ACPI_FUNCTION_ENTRY();
862 /* Ignore null objects; these are expected */
864 if (!object) {
865 return (AE_OK);
868 state = acpi_ut_create_update_state(object, action);
869 if (!state) {
870 return (AE_NO_MEMORY);
873 acpi_ut_push_generic_state(state_list, state);
874 return (AE_OK);
877 /*******************************************************************************
879 * FUNCTION: acpi_ut_walk_package_tree
881 * PARAMETERS: source_object - The package to walk
882 * target_object - Target object (if package is being copied)
883 * walk_callback - Called once for each package element
884 * context - Passed to the callback function
886 * RETURN: Status
888 * DESCRIPTION: Walk through a package
890 ******************************************************************************/
892 acpi_status
893 acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
894 void *target_object,
895 acpi_pkg_callback walk_callback, void *context)
897 acpi_status status = AE_OK;
898 union acpi_generic_state *state_list = NULL;
899 union acpi_generic_state *state;
900 u32 this_index;
901 union acpi_operand_object *this_source_obj;
903 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
905 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
906 if (!state) {
907 return_ACPI_STATUS(AE_NO_MEMORY);
910 while (state) {
912 /* Get one element of the package */
914 this_index = state->pkg.index;
915 this_source_obj = (union acpi_operand_object *)
916 state->pkg.source_object->package.elements[this_index];
919 * Check for:
920 * 1) An uninitialized package element. It is completely
921 * legal to declare a package and leave it uninitialized
922 * 2) Not an internal object - can be a namespace node instead
923 * 3) Any type other than a package. Packages are handled in else
924 * case below.
926 if ((!this_source_obj) ||
927 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
928 ACPI_DESC_TYPE_OPERAND)
929 || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) {
930 status =
931 walk_callback(ACPI_COPY_TYPE_SIMPLE,
932 this_source_obj, state, context);
933 if (ACPI_FAILURE(status)) {
934 return_ACPI_STATUS(status);
937 state->pkg.index++;
938 while (state->pkg.index >=
939 state->pkg.source_object->package.count) {
941 * We've handled all of the objects at this level, This means
942 * that we have just completed a package. That package may
943 * have contained one or more packages itself.
945 * Delete this state and pop the previous state (package).
947 acpi_ut_delete_generic_state(state);
948 state = acpi_ut_pop_generic_state(&state_list);
950 /* Finished when there are no more states */
952 if (!state) {
954 * We have handled all of the objects in the top level
955 * package just add the length of the package objects
956 * and exit
958 return_ACPI_STATUS(AE_OK);
962 * Go back up a level and move the index past the just
963 * completed package object.
965 state->pkg.index++;
967 } else {
968 /* This is a subobject of type package */
970 status =
971 walk_callback(ACPI_COPY_TYPE_PACKAGE,
972 this_source_obj, state, context);
973 if (ACPI_FAILURE(status)) {
974 return_ACPI_STATUS(status);
978 * Push the current state and create a new one
979 * The callback above returned a new target package object.
981 acpi_ut_push_generic_state(&state_list, state);
982 state = acpi_ut_create_pkg_state(this_source_obj,
983 state->pkg.
984 this_target_obj, 0);
985 if (!state) {
987 /* Free any stacked Update State objects */
989 while (state_list) {
990 state =
991 acpi_ut_pop_generic_state
992 (&state_list);
993 acpi_ut_delete_generic_state(state);
995 return_ACPI_STATUS(AE_NO_MEMORY);
1000 /* We should never get here */
1002 return_ACPI_STATUS(AE_AML_INTERNAL);