close_port, kpacket_gen kmalloc oom, formard.c wake_sender/skb receive oom handling...
[cor_2_6_31.git] / drivers / acpi / acpica / utmisc.c
blobfbe782348b0bcf0111971398ac0dc752b2f6e92d
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 "accommon.h"
48 #include "acnamesp.h"
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME("utmisc")
53 /*******************************************************************************
55 * FUNCTION: acpi_ut_validate_exception
57 * PARAMETERS: Status - The acpi_status code to be formatted
59 * RETURN: A string containing the exception text. NULL if exception is
60 * not valid.
62 * DESCRIPTION: This function validates and translates an ACPI exception into
63 * an ASCII string.
65 ******************************************************************************/
66 const char *acpi_ut_validate_exception(acpi_status status)
68 u32 sub_status;
69 const char *exception = NULL;
71 ACPI_FUNCTION_ENTRY();
74 * Status is composed of two parts, a "type" and an actual code
76 sub_status = (status & ~AE_CODE_MASK);
78 switch (status & AE_CODE_MASK) {
79 case AE_CODE_ENVIRONMENTAL:
81 if (sub_status <= AE_CODE_ENV_MAX) {
82 exception = acpi_gbl_exception_names_env[sub_status];
84 break;
86 case AE_CODE_PROGRAMMER:
88 if (sub_status <= AE_CODE_PGM_MAX) {
89 exception = acpi_gbl_exception_names_pgm[sub_status];
91 break;
93 case AE_CODE_ACPI_TABLES:
95 if (sub_status <= AE_CODE_TBL_MAX) {
96 exception = acpi_gbl_exception_names_tbl[sub_status];
98 break;
100 case AE_CODE_AML:
102 if (sub_status <= AE_CODE_AML_MAX) {
103 exception = acpi_gbl_exception_names_aml[sub_status];
105 break;
107 case AE_CODE_CONTROL:
109 if (sub_status <= AE_CODE_CTRL_MAX) {
110 exception = acpi_gbl_exception_names_ctrl[sub_status];
112 break;
114 default:
115 break;
118 return (ACPI_CAST_PTR(const char, exception));
121 /*******************************************************************************
123 * FUNCTION: acpi_ut_is_aml_table
125 * PARAMETERS: Table - An ACPI table
127 * RETURN: TRUE if table contains executable AML; FALSE otherwise
129 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
130 * Currently, these are DSDT,SSDT,PSDT. All other table types are
131 * data tables that do not contain AML code.
133 ******************************************************************************/
135 u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
138 /* These are the only tables that contain executable AML */
140 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
141 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
142 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
143 return (TRUE);
146 return (FALSE);
149 /*******************************************************************************
151 * FUNCTION: acpi_ut_allocate_owner_id
153 * PARAMETERS: owner_id - Where the new owner ID is returned
155 * RETURN: Status
157 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
158 * track objects created by the table or method, to be deleted
159 * when the method exits or the table is unloaded.
161 ******************************************************************************/
163 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
165 u32 i;
166 u32 j;
167 u32 k;
168 acpi_status status;
170 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
172 /* Guard against multiple allocations of ID to the same location */
174 if (*owner_id) {
175 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
176 *owner_id));
177 return_ACPI_STATUS(AE_ALREADY_EXISTS);
180 /* Mutex for the global ID mask */
182 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
183 if (ACPI_FAILURE(status)) {
184 return_ACPI_STATUS(status);
188 * Find a free owner ID, cycle through all possible IDs on repeated
189 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
190 * to be scanned twice.
192 for (i = 0, j = acpi_gbl_last_owner_id_index;
193 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
194 if (j >= ACPI_NUM_OWNERID_MASKS) {
195 j = 0; /* Wraparound to start of mask array */
198 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
199 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
201 /* There are no free IDs in this mask */
203 break;
206 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
208 * Found a free ID. The actual ID is the bit index plus one,
209 * making zero an invalid Owner ID. Save this as the last ID
210 * allocated and update the global ID mask.
212 acpi_gbl_owner_id_mask[j] |= (1 << k);
214 acpi_gbl_last_owner_id_index = (u8) j;
215 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
218 * Construct encoded ID from the index and bit position
220 * Note: Last [j].k (bit 255) is never used and is marked
221 * permanently allocated (prevents +1 overflow)
223 *owner_id =
224 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
226 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
227 "Allocated OwnerId: %2.2X\n",
228 (unsigned int)*owner_id));
229 goto exit;
233 acpi_gbl_next_owner_id_offset = 0;
237 * All owner_ids have been allocated. This typically should
238 * not happen since the IDs are reused after deallocation. The IDs are
239 * allocated upon table load (one per table) and method execution, and
240 * they are released when a table is unloaded or a method completes
241 * execution.
243 * If this error happens, there may be very deep nesting of invoked control
244 * methods, or there may be a bug where the IDs are not released.
246 status = AE_OWNER_ID_LIMIT;
247 ACPI_ERROR((AE_INFO,
248 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
250 exit:
251 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
252 return_ACPI_STATUS(status);
255 /*******************************************************************************
257 * FUNCTION: acpi_ut_release_owner_id
259 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
261 * RETURN: None. No error is returned because we are either exiting a
262 * control method or unloading a table. Either way, we would
263 * ignore any error anyway.
265 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
267 ******************************************************************************/
269 void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
271 acpi_owner_id owner_id = *owner_id_ptr;
272 acpi_status status;
273 u32 index;
274 u32 bit;
276 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
278 /* Always clear the input owner_id (zero is an invalid ID) */
280 *owner_id_ptr = 0;
282 /* Zero is not a valid owner_iD */
284 if (owner_id == 0) {
285 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
286 return_VOID;
289 /* Mutex for the global ID mask */
291 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
292 if (ACPI_FAILURE(status)) {
293 return_VOID;
296 /* Normalize the ID to zero */
298 owner_id--;
300 /* Decode ID to index/offset pair */
302 index = ACPI_DIV_32(owner_id);
303 bit = 1 << ACPI_MOD_32(owner_id);
305 /* Free the owner ID only if it is valid */
307 if (acpi_gbl_owner_id_mask[index] & bit) {
308 acpi_gbl_owner_id_mask[index] ^= bit;
309 } else {
310 ACPI_ERROR((AE_INFO,
311 "Release of non-allocated OwnerId: %2.2X",
312 owner_id + 1));
315 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
316 return_VOID;
319 /*******************************************************************************
321 * FUNCTION: acpi_ut_strupr (strupr)
323 * PARAMETERS: src_string - The source string to convert
325 * RETURN: None
327 * DESCRIPTION: Convert string to uppercase
329 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
331 ******************************************************************************/
333 void acpi_ut_strupr(char *src_string)
335 char *string;
337 ACPI_FUNCTION_ENTRY();
339 if (!src_string) {
340 return;
343 /* Walk entire string, uppercasing the letters */
345 for (string = src_string; *string; string++) {
346 *string = (char)ACPI_TOUPPER(*string);
349 return;
352 /*******************************************************************************
354 * FUNCTION: acpi_ut_print_string
356 * PARAMETERS: String - Null terminated ASCII string
357 * max_length - Maximum output length
359 * RETURN: None
361 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
362 * sequences.
364 ******************************************************************************/
366 void acpi_ut_print_string(char *string, u8 max_length)
368 u32 i;
370 if (!string) {
371 acpi_os_printf("<\"NULL STRING PTR\">");
372 return;
375 acpi_os_printf("\"");
376 for (i = 0; string[i] && (i < max_length); i++) {
378 /* Escape sequences */
380 switch (string[i]) {
381 case 0x07:
382 acpi_os_printf("\\a"); /* BELL */
383 break;
385 case 0x08:
386 acpi_os_printf("\\b"); /* BACKSPACE */
387 break;
389 case 0x0C:
390 acpi_os_printf("\\f"); /* FORMFEED */
391 break;
393 case 0x0A:
394 acpi_os_printf("\\n"); /* LINEFEED */
395 break;
397 case 0x0D:
398 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
399 break;
401 case 0x09:
402 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
403 break;
405 case 0x0B:
406 acpi_os_printf("\\v"); /* VERTICAL TAB */
407 break;
409 case '\'': /* Single Quote */
410 case '\"': /* Double Quote */
411 case '\\': /* Backslash */
412 acpi_os_printf("\\%c", (int)string[i]);
413 break;
415 default:
417 /* Check for printable character or hex escape */
419 if (ACPI_IS_PRINT(string[i])) {
420 /* This is a normal character */
422 acpi_os_printf("%c", (int)string[i]);
423 } else {
424 /* All others will be Hex escapes */
426 acpi_os_printf("\\x%2.2X", (s32) string[i]);
428 break;
431 acpi_os_printf("\"");
433 if (i == max_length && string[i]) {
434 acpi_os_printf("...");
438 /*******************************************************************************
440 * FUNCTION: acpi_ut_dword_byte_swap
442 * PARAMETERS: Value - Value to be converted
444 * RETURN: u32 integer with bytes swapped
446 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
448 ******************************************************************************/
450 u32 acpi_ut_dword_byte_swap(u32 value)
452 union {
453 u32 value;
454 u8 bytes[4];
455 } out;
456 union {
457 u32 value;
458 u8 bytes[4];
459 } in;
461 ACPI_FUNCTION_ENTRY();
463 in.value = value;
465 out.bytes[0] = in.bytes[3];
466 out.bytes[1] = in.bytes[2];
467 out.bytes[2] = in.bytes[1];
468 out.bytes[3] = in.bytes[0];
470 return (out.value);
473 /*******************************************************************************
475 * FUNCTION: acpi_ut_set_integer_width
477 * PARAMETERS: Revision From DSDT header
479 * RETURN: None
481 * DESCRIPTION: Set the global integer bit width based upon the revision
482 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
483 * For Revision 2 and above, Integers are 64 bits. Yes, this
484 * makes a difference.
486 ******************************************************************************/
488 void acpi_ut_set_integer_width(u8 revision)
491 if (revision < 2) {
493 /* 32-bit case */
495 acpi_gbl_integer_bit_width = 32;
496 acpi_gbl_integer_nybble_width = 8;
497 acpi_gbl_integer_byte_width = 4;
498 } else {
499 /* 64-bit case (ACPI 2.0+) */
501 acpi_gbl_integer_bit_width = 64;
502 acpi_gbl_integer_nybble_width = 16;
503 acpi_gbl_integer_byte_width = 8;
507 #ifdef ACPI_DEBUG_OUTPUT
508 /*******************************************************************************
510 * FUNCTION: acpi_ut_display_init_pathname
512 * PARAMETERS: Type - Object type of the node
513 * obj_handle - Handle whose pathname will be displayed
514 * Path - Additional path string to be appended.
515 * (NULL if no extra path)
517 * RETURN: acpi_status
519 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
521 ******************************************************************************/
523 void
524 acpi_ut_display_init_pathname(u8 type,
525 struct acpi_namespace_node *obj_handle,
526 char *path)
528 acpi_status status;
529 struct acpi_buffer buffer;
531 ACPI_FUNCTION_ENTRY();
533 /* Only print the path if the appropriate debug level is enabled */
535 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
536 return;
539 /* Get the full pathname to the node */
541 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
542 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
543 if (ACPI_FAILURE(status)) {
544 return;
547 /* Print what we're doing */
549 switch (type) {
550 case ACPI_TYPE_METHOD:
551 acpi_os_printf("Executing ");
552 break;
554 default:
555 acpi_os_printf("Initializing ");
556 break;
559 /* Print the object type and pathname */
561 acpi_os_printf("%-12s %s",
562 acpi_ut_get_type_name(type), (char *)buffer.pointer);
564 /* Extra path is used to append names like _STA, _INI, etc. */
566 if (path) {
567 acpi_os_printf(".%s", path);
569 acpi_os_printf("\n");
571 ACPI_FREE(buffer.pointer);
573 #endif
575 /*******************************************************************************
577 * FUNCTION: acpi_ut_valid_acpi_char
579 * PARAMETERS: Char - The character to be examined
580 * Position - Byte position (0-3)
582 * RETURN: TRUE if the character is valid, FALSE otherwise
584 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
585 * 1) Upper case alpha
586 * 2) numeric
587 * 3) underscore
589 * We allow a '!' as the last character because of the ASF! table
591 ******************************************************************************/
593 u8 acpi_ut_valid_acpi_char(char character, u32 position)
596 if (!((character >= 'A' && character <= 'Z') ||
597 (character >= '0' && character <= '9') || (character == '_'))) {
599 /* Allow a '!' in the last position */
601 if (character == '!' && position == 3) {
602 return (TRUE);
605 return (FALSE);
608 return (TRUE);
611 /*******************************************************************************
613 * FUNCTION: acpi_ut_valid_acpi_name
615 * PARAMETERS: Name - The name to be examined
617 * RETURN: TRUE if the name is valid, FALSE otherwise
619 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
620 * 1) Upper case alpha
621 * 2) numeric
622 * 3) underscore
624 ******************************************************************************/
626 u8 acpi_ut_valid_acpi_name(u32 name)
628 u32 i;
630 ACPI_FUNCTION_ENTRY();
632 for (i = 0; i < ACPI_NAME_SIZE; i++) {
633 if (!acpi_ut_valid_acpi_char
634 ((ACPI_CAST_PTR(char, &name))[i], i)) {
635 return (FALSE);
639 return (TRUE);
642 /*******************************************************************************
644 * FUNCTION: acpi_ut_repair_name
646 * PARAMETERS: Name - The ACPI name to be repaired
648 * RETURN: Repaired version of the name
650 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
651 * return the new name.
653 ******************************************************************************/
655 acpi_name acpi_ut_repair_name(char *name)
657 u32 i;
658 char new_name[ACPI_NAME_SIZE];
660 for (i = 0; i < ACPI_NAME_SIZE; i++) {
661 new_name[i] = name[i];
664 * Replace a bad character with something printable, yet technically
665 * still invalid. This prevents any collisions with existing "good"
666 * names in the namespace.
668 if (!acpi_ut_valid_acpi_char(name[i], i)) {
669 new_name[i] = '*';
673 return (*(u32 *) new_name);
676 /*******************************************************************************
678 * FUNCTION: acpi_ut_strtoul64
680 * PARAMETERS: String - Null terminated string
681 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
682 * ACPI_ANY_BASE means 'in behalf of to_integer'
683 * ret_integer - Where the converted integer is returned
685 * RETURN: Status and Converted value
687 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
688 * 32-bit or 64-bit conversion, depending on the current mode
689 * of the interpreter.
690 * NOTE: Does not support Octal strings, not needed.
692 ******************************************************************************/
694 acpi_status
695 acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
697 u32 this_digit = 0;
698 acpi_integer return_value = 0;
699 acpi_integer quotient;
700 acpi_integer dividend;
701 u32 to_integer_op = (base == ACPI_ANY_BASE);
702 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
703 u8 valid_digits = 0;
704 u8 sign_of0x = 0;
705 u8 term = 0;
707 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
709 switch (base) {
710 case ACPI_ANY_BASE:
711 case 16:
712 break;
714 default:
715 /* Invalid Base */
716 return_ACPI_STATUS(AE_BAD_PARAMETER);
719 if (!string) {
720 goto error_exit;
723 /* Skip over any white space in the buffer */
725 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
726 string++;
729 if (to_integer_op) {
731 * Base equal to ACPI_ANY_BASE means 'to_integer operation case'.
732 * We need to determine if it is decimal or hexadecimal.
734 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
735 sign_of0x = 1;
736 base = 16;
738 /* Skip over the leading '0x' */
739 string += 2;
740 } else {
741 base = 10;
745 /* Any string left? Check that '0x' is not followed by white space. */
747 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
748 if (to_integer_op) {
749 goto error_exit;
750 } else {
751 goto all_done;
756 * Perform a 32-bit or 64-bit conversion, depending upon the current
757 * execution mode of the interpreter
759 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
761 /* Main loop: convert the string to a 32- or 64-bit integer */
763 while (*string) {
764 if (ACPI_IS_DIGIT(*string)) {
766 /* Convert ASCII 0-9 to Decimal value */
768 this_digit = ((u8) * string) - '0';
769 } else if (base == 10) {
771 /* Digit is out of range; possible in to_integer case only */
773 term = 1;
774 } else {
775 this_digit = (u8) ACPI_TOUPPER(*string);
776 if (ACPI_IS_XDIGIT((char)this_digit)) {
778 /* Convert ASCII Hex char to value */
780 this_digit = this_digit - 'A' + 10;
781 } else {
782 term = 1;
786 if (term) {
787 if (to_integer_op) {
788 goto error_exit;
789 } else {
790 break;
792 } else if ((valid_digits == 0) && (this_digit == 0)
793 && !sign_of0x) {
795 /* Skip zeros */
796 string++;
797 continue;
800 valid_digits++;
802 if (sign_of0x && ((valid_digits > 16)
803 || ((valid_digits > 8) && mode32))) {
805 * This is to_integer operation case.
806 * No any restrictions for string-to-integer conversion,
807 * see ACPI spec.
809 goto error_exit;
812 /* Divide the digit into the correct position */
814 (void)
815 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
816 base, &quotient, NULL);
818 if (return_value > quotient) {
819 if (to_integer_op) {
820 goto error_exit;
821 } else {
822 break;
826 return_value *= base;
827 return_value += this_digit;
828 string++;
831 /* All done, normal exit */
833 all_done:
835 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
836 ACPI_FORMAT_UINT64(return_value)));
838 *ret_integer = return_value;
839 return_ACPI_STATUS(AE_OK);
841 error_exit:
842 /* Base was set/validated above */
844 if (base == 10) {
845 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
846 } else {
847 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
851 /*******************************************************************************
853 * FUNCTION: acpi_ut_create_update_state_and_push
855 * PARAMETERS: Object - Object to be added to the new state
856 * Action - Increment/Decrement
857 * state_list - List the state will be added to
859 * RETURN: Status
861 * DESCRIPTION: Create a new state and push it
863 ******************************************************************************/
865 acpi_status
866 acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
867 u16 action,
868 union acpi_generic_state **state_list)
870 union acpi_generic_state *state;
872 ACPI_FUNCTION_ENTRY();
874 /* Ignore null objects; these are expected */
876 if (!object) {
877 return (AE_OK);
880 state = acpi_ut_create_update_state(object, action);
881 if (!state) {
882 return (AE_NO_MEMORY);
885 acpi_ut_push_generic_state(state_list, state);
886 return (AE_OK);
889 /*******************************************************************************
891 * FUNCTION: acpi_ut_walk_package_tree
893 * PARAMETERS: source_object - The package to walk
894 * target_object - Target object (if package is being copied)
895 * walk_callback - Called once for each package element
896 * Context - Passed to the callback function
898 * RETURN: Status
900 * DESCRIPTION: Walk through a package
902 ******************************************************************************/
904 acpi_status
905 acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
906 void *target_object,
907 acpi_pkg_callback walk_callback, void *context)
909 acpi_status status = AE_OK;
910 union acpi_generic_state *state_list = NULL;
911 union acpi_generic_state *state;
912 u32 this_index;
913 union acpi_operand_object *this_source_obj;
915 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
917 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
918 if (!state) {
919 return_ACPI_STATUS(AE_NO_MEMORY);
922 while (state) {
924 /* Get one element of the package */
926 this_index = state->pkg.index;
927 this_source_obj = (union acpi_operand_object *)
928 state->pkg.source_object->package.elements[this_index];
931 * Check for:
932 * 1) An uninitialized package element. It is completely
933 * legal to declare a package and leave it uninitialized
934 * 2) Not an internal object - can be a namespace node instead
935 * 3) Any type other than a package. Packages are handled in else
936 * case below.
938 if ((!this_source_obj) ||
939 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
940 ACPI_DESC_TYPE_OPERAND)
941 || (this_source_obj->common.type != 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) {
999 /* Free any stacked Update State objects */
1001 while (state_list) {
1002 state =
1003 acpi_ut_pop_generic_state
1004 (&state_list);
1005 acpi_ut_delete_generic_state(state);
1007 return_ACPI_STATUS(AE_NO_MEMORY);
1012 /* We should never get here */
1014 return_ACPI_STATUS(AE_AML_INTERNAL);
1017 /*******************************************************************************
1019 * FUNCTION: acpi_error, acpi_exception, acpi_warning, acpi_info
1021 * PARAMETERS: module_name - Caller's module name (for error output)
1022 * line_number - Caller's line number (for error output)
1023 * Format - Printf format string + additional args
1025 * RETURN: None
1027 * DESCRIPTION: Print message with module/line/version info
1029 ******************************************************************************/
1031 void ACPI_INTERNAL_VAR_XFACE
1032 acpi_error(const char *module_name, u32 line_number, const char *format, ...)
1034 va_list args;
1036 acpi_os_printf("ACPI Error: ");
1038 va_start(args, format);
1039 acpi_os_vprintf(format, args);
1040 acpi_os_printf(" %8.8X %s-%u\n", ACPI_CA_VERSION, module_name,
1041 line_number);
1042 va_end(args);
1045 void ACPI_INTERNAL_VAR_XFACE
1046 acpi_exception(const char *module_name,
1047 u32 line_number, acpi_status status, const char *format, ...)
1049 va_list args;
1051 acpi_os_printf("ACPI Exception: %s, ", acpi_format_exception(status));
1053 va_start(args, format);
1054 acpi_os_vprintf(format, args);
1055 acpi_os_printf(" %8.8X %s-%u\n", ACPI_CA_VERSION, module_name,
1056 line_number);
1057 va_end(args);
1060 void ACPI_INTERNAL_VAR_XFACE
1061 acpi_warning(const char *module_name, u32 line_number, const char *format, ...)
1063 va_list args;
1065 acpi_os_printf("ACPI Warning: ");
1067 va_start(args, format);
1068 acpi_os_vprintf(format, args);
1069 acpi_os_printf(" %8.8X %s-%u\n", ACPI_CA_VERSION, module_name,
1070 line_number);
1071 va_end(args);
1074 void ACPI_INTERNAL_VAR_XFACE
1075 acpi_info(const char *module_name, u32 line_number, const char *format, ...)
1077 va_list args;
1079 acpi_os_printf("ACPI: ");
1081 va_start(args, format);
1082 acpi_os_vprintf(format, args);
1083 acpi_os_printf("\n");
1084 va_end(args);
1087 ACPI_EXPORT_SYMBOL(acpi_error)
1088 ACPI_EXPORT_SYMBOL(acpi_exception)
1089 ACPI_EXPORT_SYMBOL(acpi_warning)
1090 ACPI_EXPORT_SYMBOL(acpi_info)