ACPICA: Fix possible negative array index in acpi_ut_validate_exception
[linux-2.6/mini2440.git] / drivers / acpi / utilities / utmisc.c
blob47354d9b0e568e365bb6cea8d2e15491dcb43c10
1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acnamesp.h>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME("utmisc")
52 /*******************************************************************************
54 * FUNCTION: acpi_ut_validate_exception
56 * PARAMETERS: Status - The acpi_status code to be formatted
58 * RETURN: A string containing the exception text. NULL if exception is
59 * not valid.
61 * DESCRIPTION: This function validates and translates an ACPI exception into
62 * an ASCII string.
64 ******************************************************************************/
65 const char *acpi_ut_validate_exception(acpi_status status)
67 u32 sub_status;
68 const char *exception = NULL;
70 ACPI_FUNCTION_ENTRY();
73 * Status is composed of two parts, a "type" and an actual code
75 sub_status = (status & ~AE_CODE_MASK);
77 switch (status & AE_CODE_MASK) {
78 case AE_CODE_ENVIRONMENTAL:
80 if (sub_status <= AE_CODE_ENV_MAX) {
81 exception = acpi_gbl_exception_names_env[sub_status];
83 break;
85 case AE_CODE_PROGRAMMER:
87 if (sub_status <= AE_CODE_PGM_MAX) {
88 exception = acpi_gbl_exception_names_pgm[sub_status];
90 break;
92 case AE_CODE_ACPI_TABLES:
94 if (sub_status <= AE_CODE_TBL_MAX) {
95 exception = acpi_gbl_exception_names_tbl[sub_status];
97 break;
99 case AE_CODE_AML:
101 if (sub_status <= AE_CODE_AML_MAX) {
102 exception = acpi_gbl_exception_names_aml[sub_status];
104 break;
106 case AE_CODE_CONTROL:
108 if (sub_status <= AE_CODE_CTRL_MAX) {
109 exception = acpi_gbl_exception_names_ctrl[sub_status];
111 break;
113 default:
114 break;
117 return (ACPI_CAST_PTR(const char, exception));
120 /*******************************************************************************
122 * FUNCTION: acpi_ut_is_aml_table
124 * PARAMETERS: Table - An ACPI table
126 * RETURN: TRUE if table contains executable AML; FALSE otherwise
128 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
129 * Currently, these are DSDT,SSDT,PSDT. All other table types are
130 * data tables that do not contain AML code.
132 ******************************************************************************/
134 u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
137 /* These are the only tables that contain executable AML */
139 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
140 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
141 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
142 return (TRUE);
145 return (FALSE);
148 /*******************************************************************************
150 * FUNCTION: acpi_ut_allocate_owner_id
152 * PARAMETERS: owner_id - Where the new owner ID is returned
154 * RETURN: Status
156 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
157 * track objects created by the table or method, to be deleted
158 * when the method exits or the table is unloaded.
160 ******************************************************************************/
162 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
164 acpi_native_uint i;
165 acpi_native_uint j;
166 acpi_native_uint k;
167 acpi_status status;
169 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
171 /* Guard against multiple allocations of ID to the same location */
173 if (*owner_id) {
174 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
175 *owner_id));
176 return_ACPI_STATUS(AE_ALREADY_EXISTS);
179 /* Mutex for the global ID mask */
181 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
182 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status);
187 * Find a free owner ID, cycle through all possible IDs on repeated
188 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
189 * to be scanned twice.
191 for (i = 0, j = acpi_gbl_last_owner_id_index;
192 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
193 if (j >= ACPI_NUM_OWNERID_MASKS) {
194 j = 0; /* Wraparound to start of mask array */
197 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
198 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
200 /* There are no free IDs in this mask */
202 break;
205 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
207 * Found a free ID. The actual ID is the bit index plus one,
208 * making zero an invalid Owner ID. Save this as the last ID
209 * allocated and update the global ID mask.
211 acpi_gbl_owner_id_mask[j] |= (1 << k);
213 acpi_gbl_last_owner_id_index = (u8) j;
214 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
217 * Construct encoded ID from the index and bit position
219 * Note: Last [j].k (bit 255) is never used and is marked
220 * permanently allocated (prevents +1 overflow)
222 *owner_id =
223 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
225 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
226 "Allocated OwnerId: %2.2X\n",
227 (unsigned int)*owner_id));
228 goto exit;
232 acpi_gbl_next_owner_id_offset = 0;
236 * All owner_ids have been allocated. This typically should
237 * not happen since the IDs are reused after deallocation. The IDs are
238 * allocated upon table load (one per table) and method execution, and
239 * they are released when a table is unloaded or a method completes
240 * execution.
242 * If this error happens, there may be very deep nesting of invoked control
243 * methods, or there may be a bug where the IDs are not released.
245 status = AE_OWNER_ID_LIMIT;
246 ACPI_ERROR((AE_INFO,
247 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
249 exit:
250 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
251 return_ACPI_STATUS(status);
254 /*******************************************************************************
256 * FUNCTION: acpi_ut_release_owner_id
258 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
260 * RETURN: None. No error is returned because we are either exiting a
261 * control method or unloading a table. Either way, we would
262 * ignore any error anyway.
264 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
266 ******************************************************************************/
268 void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
270 acpi_owner_id owner_id = *owner_id_ptr;
271 acpi_status status;
272 acpi_native_uint index;
273 u32 bit;
275 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
277 /* Always clear the input owner_id (zero is an invalid ID) */
279 *owner_id_ptr = 0;
281 /* Zero is not a valid owner_iD */
283 if (owner_id == 0) {
284 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
285 return_VOID;
288 /* Mutex for the global ID mask */
290 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
291 if (ACPI_FAILURE(status)) {
292 return_VOID;
295 /* Normalize the ID to zero */
297 owner_id--;
299 /* Decode ID to index/offset pair */
301 index = ACPI_DIV_32(owner_id);
302 bit = 1 << ACPI_MOD_32(owner_id);
304 /* Free the owner ID only if it is valid */
306 if (acpi_gbl_owner_id_mask[index] & bit) {
307 acpi_gbl_owner_id_mask[index] ^= bit;
308 } else {
309 ACPI_ERROR((AE_INFO,
310 "Release of non-allocated OwnerId: %2.2X",
311 owner_id + 1));
314 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
315 return_VOID;
318 /*******************************************************************************
320 * FUNCTION: acpi_ut_strupr (strupr)
322 * PARAMETERS: src_string - The source string to convert
324 * RETURN: None
326 * DESCRIPTION: Convert string to uppercase
328 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
330 ******************************************************************************/
332 void acpi_ut_strupr(char *src_string)
334 char *string;
336 ACPI_FUNCTION_ENTRY();
338 if (!src_string) {
339 return;
342 /* Walk entire string, uppercasing the letters */
344 for (string = src_string; *string; string++) {
345 *string = (char)ACPI_TOUPPER(*string);
348 return;
351 /*******************************************************************************
353 * FUNCTION: acpi_ut_print_string
355 * PARAMETERS: String - Null terminated ASCII string
356 * max_length - Maximum output length
358 * RETURN: None
360 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
361 * sequences.
363 ******************************************************************************/
365 void acpi_ut_print_string(char *string, u8 max_length)
367 u32 i;
369 if (!string) {
370 acpi_os_printf("<\"NULL STRING PTR\">");
371 return;
374 acpi_os_printf("\"");
375 for (i = 0; string[i] && (i < max_length); i++) {
377 /* Escape sequences */
379 switch (string[i]) {
380 case 0x07:
381 acpi_os_printf("\\a"); /* BELL */
382 break;
384 case 0x08:
385 acpi_os_printf("\\b"); /* BACKSPACE */
386 break;
388 case 0x0C:
389 acpi_os_printf("\\f"); /* FORMFEED */
390 break;
392 case 0x0A:
393 acpi_os_printf("\\n"); /* LINEFEED */
394 break;
396 case 0x0D:
397 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
398 break;
400 case 0x09:
401 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
402 break;
404 case 0x0B:
405 acpi_os_printf("\\v"); /* VERTICAL TAB */
406 break;
408 case '\'': /* Single Quote */
409 case '\"': /* Double Quote */
410 case '\\': /* Backslash */
411 acpi_os_printf("\\%c", (int)string[i]);
412 break;
414 default:
416 /* Check for printable character or hex escape */
418 if (ACPI_IS_PRINT(string[i])) {
419 /* This is a normal character */
421 acpi_os_printf("%c", (int)string[i]);
422 } else {
423 /* All others will be Hex escapes */
425 acpi_os_printf("\\x%2.2X", (s32) string[i]);
427 break;
430 acpi_os_printf("\"");
432 if (i == max_length && string[i]) {
433 acpi_os_printf("...");
437 /*******************************************************************************
439 * FUNCTION: acpi_ut_dword_byte_swap
441 * PARAMETERS: Value - Value to be converted
443 * RETURN: u32 integer with bytes swapped
445 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
447 ******************************************************************************/
449 u32 acpi_ut_dword_byte_swap(u32 value)
451 union {
452 u32 value;
453 u8 bytes[4];
454 } out;
455 union {
456 u32 value;
457 u8 bytes[4];
458 } in;
460 ACPI_FUNCTION_ENTRY();
462 in.value = value;
464 out.bytes[0] = in.bytes[3];
465 out.bytes[1] = in.bytes[2];
466 out.bytes[2] = in.bytes[1];
467 out.bytes[3] = in.bytes[0];
469 return (out.value);
472 /*******************************************************************************
474 * FUNCTION: acpi_ut_set_integer_width
476 * PARAMETERS: Revision From DSDT header
478 * RETURN: None
480 * DESCRIPTION: Set the global integer bit width based upon the revision
481 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
482 * For Revision 2 and above, Integers are 64 bits. Yes, this
483 * makes a difference.
485 ******************************************************************************/
487 void acpi_ut_set_integer_width(u8 revision)
490 if (revision < 2) {
492 /* 32-bit case */
494 acpi_gbl_integer_bit_width = 32;
495 acpi_gbl_integer_nybble_width = 8;
496 acpi_gbl_integer_byte_width = 4;
497 } else {
498 /* 64-bit case (ACPI 2.0+) */
500 acpi_gbl_integer_bit_width = 64;
501 acpi_gbl_integer_nybble_width = 16;
502 acpi_gbl_integer_byte_width = 8;
506 #ifdef ACPI_DEBUG_OUTPUT
507 /*******************************************************************************
509 * FUNCTION: acpi_ut_display_init_pathname
511 * PARAMETERS: Type - Object type of the node
512 * obj_handle - Handle whose pathname will be displayed
513 * Path - Additional path string to be appended.
514 * (NULL if no extra path)
516 * RETURN: acpi_status
518 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
520 ******************************************************************************/
522 void
523 acpi_ut_display_init_pathname(u8 type,
524 struct acpi_namespace_node *obj_handle,
525 char *path)
527 acpi_status status;
528 struct acpi_buffer buffer;
530 ACPI_FUNCTION_ENTRY();
532 /* Only print the path if the appropriate debug level is enabled */
534 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
535 return;
538 /* Get the full pathname to the node */
540 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
541 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
542 if (ACPI_FAILURE(status)) {
543 return;
546 /* Print what we're doing */
548 switch (type) {
549 case ACPI_TYPE_METHOD:
550 acpi_os_printf("Executing ");
551 break;
553 default:
554 acpi_os_printf("Initializing ");
555 break;
558 /* Print the object type and pathname */
560 acpi_os_printf("%-12s %s",
561 acpi_ut_get_type_name(type), (char *)buffer.pointer);
563 /* Extra path is used to append names like _STA, _INI, etc. */
565 if (path) {
566 acpi_os_printf(".%s", path);
568 acpi_os_printf("\n");
570 ACPI_FREE(buffer.pointer);
572 #endif
574 /*******************************************************************************
576 * FUNCTION: acpi_ut_valid_acpi_char
578 * PARAMETERS: Char - The character to be examined
579 * Position - Byte position (0-3)
581 * RETURN: TRUE if the character is valid, FALSE otherwise
583 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
584 * 1) Upper case alpha
585 * 2) numeric
586 * 3) underscore
588 * We allow a '!' as the last character because of the ASF! table
590 ******************************************************************************/
592 u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position)
595 if (!((character >= 'A' && character <= 'Z') ||
596 (character >= '0' && character <= '9') || (character == '_'))) {
598 /* Allow a '!' in the last position */
600 if (character == '!' && position == 3) {
601 return (TRUE);
604 return (FALSE);
607 return (TRUE);
610 /*******************************************************************************
612 * FUNCTION: acpi_ut_valid_acpi_name
614 * PARAMETERS: Name - The name to be examined
616 * RETURN: TRUE if the name is valid, FALSE otherwise
618 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
619 * 1) Upper case alpha
620 * 2) numeric
621 * 3) underscore
623 ******************************************************************************/
625 u8 acpi_ut_valid_acpi_name(u32 name)
627 acpi_native_uint i;
629 ACPI_FUNCTION_ENTRY();
631 for (i = 0; i < ACPI_NAME_SIZE; i++) {
632 if (!acpi_ut_valid_acpi_char
633 ((ACPI_CAST_PTR(char, &name))[i], i)) {
634 return (FALSE);
638 return (TRUE);
641 /*******************************************************************************
643 * FUNCTION: acpi_ut_repair_name
645 * PARAMETERS: Name - The ACPI name to be repaired
647 * RETURN: Repaired version of the name
649 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
650 * return the new name.
652 ******************************************************************************/
654 acpi_name acpi_ut_repair_name(char *name)
656 acpi_native_uint i;
657 char new_name[ACPI_NAME_SIZE];
659 for (i = 0; i < ACPI_NAME_SIZE; i++) {
660 new_name[i] = name[i];
663 * Replace a bad character with something printable, yet technically
664 * still invalid. This prevents any collisions with existing "good"
665 * names in the namespace.
667 if (!acpi_ut_valid_acpi_char(name[i], i)) {
668 new_name[i] = '*';
672 return (*(u32 *) new_name);
675 /*******************************************************************************
677 * FUNCTION: acpi_ut_strtoul64
679 * PARAMETERS: String - Null terminated string
680 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
681 * ACPI_ANY_BASE means 'in behalf of to_integer'
682 * ret_integer - Where the converted integer is returned
684 * RETURN: Status and Converted value
686 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
687 * 32-bit or 64-bit conversion, depending on the current mode
688 * of the interpreter.
689 * NOTE: Does not support Octal strings, not needed.
691 ******************************************************************************/
693 acpi_status
694 acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
696 u32 this_digit = 0;
697 acpi_integer return_value = 0;
698 acpi_integer quotient;
699 acpi_integer dividend;
700 u32 to_integer_op = (base == ACPI_ANY_BASE);
701 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
702 u8 valid_digits = 0;
703 u8 sign_of0x = 0;
704 u8 term = 0;
706 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
708 switch (base) {
709 case ACPI_ANY_BASE:
710 case 16:
711 break;
713 default:
714 /* Invalid Base */
715 return_ACPI_STATUS(AE_BAD_PARAMETER);
718 if (!string) {
719 goto error_exit;
722 /* Skip over any white space in the buffer */
724 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
725 string++;
728 if (to_integer_op) {
730 * Base equal to ACPI_ANY_BASE means 'to_integer operation case'.
731 * We need to determine if it is decimal or hexadecimal.
733 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
734 sign_of0x = 1;
735 base = 16;
737 /* Skip over the leading '0x' */
738 string += 2;
739 } else {
740 base = 10;
744 /* Any string left? Check that '0x' is not followed by white space. */
746 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
747 if (to_integer_op) {
748 goto error_exit;
749 } else {
750 goto all_done;
755 * Perform a 32-bit or 64-bit conversion, depending upon the current
756 * execution mode of the interpreter
758 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
760 /* Main loop: convert the string to a 32- or 64-bit integer */
762 while (*string) {
763 if (ACPI_IS_DIGIT(*string)) {
765 /* Convert ASCII 0-9 to Decimal value */
767 this_digit = ((u8) * string) - '0';
768 } else if (base == 10) {
770 /* Digit is out of range; possible in to_integer case only */
772 term = 1;
773 } else {
774 this_digit = (u8) ACPI_TOUPPER(*string);
775 if (ACPI_IS_XDIGIT((char)this_digit)) {
777 /* Convert ASCII Hex char to value */
779 this_digit = this_digit - 'A' + 10;
780 } else {
781 term = 1;
785 if (term) {
786 if (to_integer_op) {
787 goto error_exit;
788 } else {
789 break;
791 } else if ((valid_digits == 0) && (this_digit == 0)
792 && !sign_of0x) {
794 /* Skip zeros */
795 string++;
796 continue;
799 valid_digits++;
801 if (sign_of0x && ((valid_digits > 16)
802 || ((valid_digits > 8) && mode32))) {
804 * This is to_integer operation case.
805 * No any restrictions for string-to-integer conversion,
806 * see ACPI spec.
808 goto error_exit;
811 /* Divide the digit into the correct position */
813 (void)
814 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
815 base, &quotient, NULL);
817 if (return_value > quotient) {
818 if (to_integer_op) {
819 goto error_exit;
820 } else {
821 break;
825 return_value *= base;
826 return_value += this_digit;
827 string++;
830 /* All done, normal exit */
832 all_done:
834 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
835 ACPI_FORMAT_UINT64(return_value)));
837 *ret_integer = return_value;
838 return_ACPI_STATUS(AE_OK);
840 error_exit:
841 /* Base was set/validated above */
843 if (base == 10) {
844 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
845 } else {
846 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
850 /*******************************************************************************
852 * FUNCTION: acpi_ut_create_update_state_and_push
854 * PARAMETERS: Object - Object to be added to the new state
855 * Action - Increment/Decrement
856 * state_list - List the state will be added to
858 * RETURN: Status
860 * DESCRIPTION: Create a new state and push it
862 ******************************************************************************/
864 acpi_status
865 acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
866 u16 action,
867 union acpi_generic_state **state_list)
869 union acpi_generic_state *state;
871 ACPI_FUNCTION_ENTRY();
873 /* Ignore null objects; these are expected */
875 if (!object) {
876 return (AE_OK);
879 state = acpi_ut_create_update_state(object, action);
880 if (!state) {
881 return (AE_NO_MEMORY);
884 acpi_ut_push_generic_state(state_list, state);
885 return (AE_OK);
888 /*******************************************************************************
890 * FUNCTION: acpi_ut_walk_package_tree
892 * PARAMETERS: source_object - The package to walk
893 * target_object - Target object (if package is being copied)
894 * walk_callback - Called once for each package element
895 * Context - Passed to the callback function
897 * RETURN: Status
899 * DESCRIPTION: Walk through a package
901 ******************************************************************************/
903 acpi_status
904 acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
905 void *target_object,
906 acpi_pkg_callback walk_callback, void *context)
908 acpi_status status = AE_OK;
909 union acpi_generic_state *state_list = NULL;
910 union acpi_generic_state *state;
911 u32 this_index;
912 union acpi_operand_object *this_source_obj;
914 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
916 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
917 if (!state) {
918 return_ACPI_STATUS(AE_NO_MEMORY);
921 while (state) {
923 /* Get one element of the package */
925 this_index = state->pkg.index;
926 this_source_obj = (union acpi_operand_object *)
927 state->pkg.source_object->package.elements[this_index];
930 * Check for:
931 * 1) An uninitialized package element. It is completely
932 * legal to declare a package and leave it uninitialized
933 * 2) Not an internal object - can be a namespace node instead
934 * 3) Any type other than a package. Packages are handled in else
935 * case below.
937 if ((!this_source_obj) ||
938 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
939 ACPI_DESC_TYPE_OPERAND)
940 || (ACPI_GET_OBJECT_TYPE(this_source_obj) !=
941 ACPI_TYPE_PACKAGE)) {
942 status =
943 walk_callback(ACPI_COPY_TYPE_SIMPLE,
944 this_source_obj, state, context);
945 if (ACPI_FAILURE(status)) {
946 return_ACPI_STATUS(status);
949 state->pkg.index++;
950 while (state->pkg.index >=
951 state->pkg.source_object->package.count) {
953 * We've handled all of the objects at this level, This means
954 * that we have just completed a package. That package may
955 * have contained one or more packages itself.
957 * Delete this state and pop the previous state (package).
959 acpi_ut_delete_generic_state(state);
960 state = acpi_ut_pop_generic_state(&state_list);
962 /* Finished when there are no more states */
964 if (!state) {
966 * We have handled all of the objects in the top level
967 * package just add the length of the package objects
968 * and exit
970 return_ACPI_STATUS(AE_OK);
974 * Go back up a level and move the index past the just
975 * completed package object.
977 state->pkg.index++;
979 } else {
980 /* This is a subobject of type package */
982 status =
983 walk_callback(ACPI_COPY_TYPE_PACKAGE,
984 this_source_obj, state, context);
985 if (ACPI_FAILURE(status)) {
986 return_ACPI_STATUS(status);
990 * Push the current state and create a new one
991 * The callback above returned a new target package object.
993 acpi_ut_push_generic_state(&state_list, state);
994 state = acpi_ut_create_pkg_state(this_source_obj,
995 state->pkg.
996 this_target_obj, 0);
997 if (!state) {
998 return_ACPI_STATUS(AE_NO_MEMORY);
1003 /* We should never get here */
1005 return_ACPI_STATUS(AE_AML_INTERNAL);
1008 /*******************************************************************************
1010 * FUNCTION: acpi_ut_error, acpi_ut_warning, acpi_ut_info
1012 * PARAMETERS: module_name - Caller's module name (for error output)
1013 * line_number - Caller's line number (for error output)
1014 * Format - Printf format string + additional args
1016 * RETURN: None
1018 * DESCRIPTION: Print message with module/line/version info
1020 ******************************************************************************/
1022 void ACPI_INTERNAL_VAR_XFACE
1023 acpi_ut_error(char *module_name, u32 line_number, char *format, ...)
1025 va_list args;
1027 acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number);
1029 va_start(args, format);
1030 acpi_os_vprintf(format, args);
1031 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
1032 va_end(args);
1035 void ACPI_INTERNAL_VAR_XFACE
1036 acpi_ut_exception(char *module_name,
1037 u32 line_number, acpi_status status, char *format, ...)
1039 va_list args;
1041 acpi_os_printf("ACPI Exception (%s-%04d): %s, ", module_name,
1042 line_number, acpi_format_exception(status));
1044 va_start(args, format);
1045 acpi_os_vprintf(format, args);
1046 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
1047 va_end(args);
1050 EXPORT_SYMBOL(acpi_ut_exception);
1052 void ACPI_INTERNAL_VAR_XFACE
1053 acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
1055 va_list args;
1057 acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number);
1059 va_start(args, format);
1060 acpi_os_vprintf(format, args);
1061 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
1062 va_end(args);
1065 void ACPI_INTERNAL_VAR_XFACE
1066 acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
1068 va_list args;
1071 * Removed module_name, line_number, and acpica version, not needed
1072 * for info output
1074 acpi_os_printf("ACPI: ");
1076 va_start(args, format);
1077 acpi_os_vprintf(format, args);
1078 acpi_os_printf("\n");
1079 va_end(args);