mm-only debug patch...
[mmotm.git] / drivers / acpi / acpica / utmisc.c
blob61f6315fce9f44cb888c37866aa2743968254f8f
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")
54 * Common suffix for messages
56 #define ACPI_COMMON_MSG_SUFFIX \
57 acpi_os_printf(" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
58 /*******************************************************************************
60 * FUNCTION: acpi_ut_validate_exception
62 * PARAMETERS: Status - The acpi_status code to be formatted
64 * RETURN: A string containing the exception text. NULL if exception is
65 * not valid.
67 * DESCRIPTION: This function validates and translates an ACPI exception into
68 * an ASCII string.
70 ******************************************************************************/
71 const char *acpi_ut_validate_exception(acpi_status status)
73 u32 sub_status;
74 const char *exception = NULL;
76 ACPI_FUNCTION_ENTRY();
79 * Status is composed of two parts, a "type" and an actual code
81 sub_status = (status & ~AE_CODE_MASK);
83 switch (status & AE_CODE_MASK) {
84 case AE_CODE_ENVIRONMENTAL:
86 if (sub_status <= AE_CODE_ENV_MAX) {
87 exception = acpi_gbl_exception_names_env[sub_status];
89 break;
91 case AE_CODE_PROGRAMMER:
93 if (sub_status <= AE_CODE_PGM_MAX) {
94 exception = acpi_gbl_exception_names_pgm[sub_status];
96 break;
98 case AE_CODE_ACPI_TABLES:
100 if (sub_status <= AE_CODE_TBL_MAX) {
101 exception = acpi_gbl_exception_names_tbl[sub_status];
103 break;
105 case AE_CODE_AML:
107 if (sub_status <= AE_CODE_AML_MAX) {
108 exception = acpi_gbl_exception_names_aml[sub_status];
110 break;
112 case AE_CODE_CONTROL:
114 if (sub_status <= AE_CODE_CTRL_MAX) {
115 exception = acpi_gbl_exception_names_ctrl[sub_status];
117 break;
119 default:
120 break;
123 return (ACPI_CAST_PTR(const char, exception));
126 /*******************************************************************************
128 * FUNCTION: acpi_ut_is_pci_root_bridge
130 * PARAMETERS: Id - The HID/CID in string format
132 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
134 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
136 ******************************************************************************/
138 u8 acpi_ut_is_pci_root_bridge(char *id)
142 * Check if this is a PCI root bridge.
143 * ACPI 3.0+: check for a PCI Express root also.
145 if (!(ACPI_STRCMP(id,
146 PCI_ROOT_HID_STRING)) ||
147 !(ACPI_STRCMP(id, PCI_EXPRESS_ROOT_HID_STRING))) {
148 return (TRUE);
151 return (FALSE);
154 /*******************************************************************************
156 * FUNCTION: acpi_ut_is_aml_table
158 * PARAMETERS: Table - An ACPI table
160 * RETURN: TRUE if table contains executable AML; FALSE otherwise
162 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
163 * Currently, these are DSDT,SSDT,PSDT. All other table types are
164 * data tables that do not contain AML code.
166 ******************************************************************************/
168 u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
171 /* These are the only tables that contain executable AML */
173 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
174 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
175 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
176 return (TRUE);
179 return (FALSE);
182 /*******************************************************************************
184 * FUNCTION: acpi_ut_allocate_owner_id
186 * PARAMETERS: owner_id - Where the new owner ID is returned
188 * RETURN: Status
190 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
191 * track objects created by the table or method, to be deleted
192 * when the method exits or the table is unloaded.
194 ******************************************************************************/
196 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
198 u32 i;
199 u32 j;
200 u32 k;
201 acpi_status status;
203 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
205 /* Guard against multiple allocations of ID to the same location */
207 if (*owner_id) {
208 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
209 *owner_id));
210 return_ACPI_STATUS(AE_ALREADY_EXISTS);
213 /* Mutex for the global ID mask */
215 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
216 if (ACPI_FAILURE(status)) {
217 return_ACPI_STATUS(status);
221 * Find a free owner ID, cycle through all possible IDs on repeated
222 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
223 * to be scanned twice.
225 for (i = 0, j = acpi_gbl_last_owner_id_index;
226 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
227 if (j >= ACPI_NUM_OWNERID_MASKS) {
228 j = 0; /* Wraparound to start of mask array */
231 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
232 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
234 /* There are no free IDs in this mask */
236 break;
239 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
241 * Found a free ID. The actual ID is the bit index plus one,
242 * making zero an invalid Owner ID. Save this as the last ID
243 * allocated and update the global ID mask.
245 acpi_gbl_owner_id_mask[j] |= (1 << k);
247 acpi_gbl_last_owner_id_index = (u8) j;
248 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
251 * Construct encoded ID from the index and bit position
253 * Note: Last [j].k (bit 255) is never used and is marked
254 * permanently allocated (prevents +1 overflow)
256 *owner_id =
257 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
259 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
260 "Allocated OwnerId: %2.2X\n",
261 (unsigned int)*owner_id));
262 goto exit;
266 acpi_gbl_next_owner_id_offset = 0;
270 * All owner_ids have been allocated. This typically should
271 * not happen since the IDs are reused after deallocation. The IDs are
272 * allocated upon table load (one per table) and method execution, and
273 * they are released when a table is unloaded or a method completes
274 * execution.
276 * If this error happens, there may be very deep nesting of invoked control
277 * methods, or there may be a bug where the IDs are not released.
279 status = AE_OWNER_ID_LIMIT;
280 ACPI_ERROR((AE_INFO,
281 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
283 exit:
284 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
285 return_ACPI_STATUS(status);
288 /*******************************************************************************
290 * FUNCTION: acpi_ut_release_owner_id
292 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
294 * RETURN: None. No error is returned because we are either exiting a
295 * control method or unloading a table. Either way, we would
296 * ignore any error anyway.
298 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
300 ******************************************************************************/
302 void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
304 acpi_owner_id owner_id = *owner_id_ptr;
305 acpi_status status;
306 u32 index;
307 u32 bit;
309 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
311 /* Always clear the input owner_id (zero is an invalid ID) */
313 *owner_id_ptr = 0;
315 /* Zero is not a valid owner_iD */
317 if (owner_id == 0) {
318 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
319 return_VOID;
322 /* Mutex for the global ID mask */
324 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
325 if (ACPI_FAILURE(status)) {
326 return_VOID;
329 /* Normalize the ID to zero */
331 owner_id--;
333 /* Decode ID to index/offset pair */
335 index = ACPI_DIV_32(owner_id);
336 bit = 1 << ACPI_MOD_32(owner_id);
338 /* Free the owner ID only if it is valid */
340 if (acpi_gbl_owner_id_mask[index] & bit) {
341 acpi_gbl_owner_id_mask[index] ^= bit;
342 } else {
343 ACPI_ERROR((AE_INFO,
344 "Release of non-allocated OwnerId: %2.2X",
345 owner_id + 1));
348 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
349 return_VOID;
352 /*******************************************************************************
354 * FUNCTION: acpi_ut_strupr (strupr)
356 * PARAMETERS: src_string - The source string to convert
358 * RETURN: None
360 * DESCRIPTION: Convert string to uppercase
362 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
364 ******************************************************************************/
366 void acpi_ut_strupr(char *src_string)
368 char *string;
370 ACPI_FUNCTION_ENTRY();
372 if (!src_string) {
373 return;
376 /* Walk entire string, uppercasing the letters */
378 for (string = src_string; *string; string++) {
379 *string = (char)ACPI_TOUPPER(*string);
382 return;
385 /*******************************************************************************
387 * FUNCTION: acpi_ut_print_string
389 * PARAMETERS: String - Null terminated ASCII string
390 * max_length - Maximum output length
392 * RETURN: None
394 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
395 * sequences.
397 ******************************************************************************/
399 void acpi_ut_print_string(char *string, u8 max_length)
401 u32 i;
403 if (!string) {
404 acpi_os_printf("<\"NULL STRING PTR\">");
405 return;
408 acpi_os_printf("\"");
409 for (i = 0; string[i] && (i < max_length); i++) {
411 /* Escape sequences */
413 switch (string[i]) {
414 case 0x07:
415 acpi_os_printf("\\a"); /* BELL */
416 break;
418 case 0x08:
419 acpi_os_printf("\\b"); /* BACKSPACE */
420 break;
422 case 0x0C:
423 acpi_os_printf("\\f"); /* FORMFEED */
424 break;
426 case 0x0A:
427 acpi_os_printf("\\n"); /* LINEFEED */
428 break;
430 case 0x0D:
431 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
432 break;
434 case 0x09:
435 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
436 break;
438 case 0x0B:
439 acpi_os_printf("\\v"); /* VERTICAL TAB */
440 break;
442 case '\'': /* Single Quote */
443 case '\"': /* Double Quote */
444 case '\\': /* Backslash */
445 acpi_os_printf("\\%c", (int)string[i]);
446 break;
448 default:
450 /* Check for printable character or hex escape */
452 if (ACPI_IS_PRINT(string[i])) {
453 /* This is a normal character */
455 acpi_os_printf("%c", (int)string[i]);
456 } else {
457 /* All others will be Hex escapes */
459 acpi_os_printf("\\x%2.2X", (s32) string[i]);
461 break;
464 acpi_os_printf("\"");
466 if (i == max_length && string[i]) {
467 acpi_os_printf("...");
471 /*******************************************************************************
473 * FUNCTION: acpi_ut_dword_byte_swap
475 * PARAMETERS: Value - Value to be converted
477 * RETURN: u32 integer with bytes swapped
479 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
481 ******************************************************************************/
483 u32 acpi_ut_dword_byte_swap(u32 value)
485 union {
486 u32 value;
487 u8 bytes[4];
488 } out;
489 union {
490 u32 value;
491 u8 bytes[4];
492 } in;
494 ACPI_FUNCTION_ENTRY();
496 in.value = value;
498 out.bytes[0] = in.bytes[3];
499 out.bytes[1] = in.bytes[2];
500 out.bytes[2] = in.bytes[1];
501 out.bytes[3] = in.bytes[0];
503 return (out.value);
506 /*******************************************************************************
508 * FUNCTION: acpi_ut_set_integer_width
510 * PARAMETERS: Revision From DSDT header
512 * RETURN: None
514 * DESCRIPTION: Set the global integer bit width based upon the revision
515 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
516 * For Revision 2 and above, Integers are 64 bits. Yes, this
517 * makes a difference.
519 ******************************************************************************/
521 void acpi_ut_set_integer_width(u8 revision)
524 if (revision < 2) {
526 /* 32-bit case */
528 acpi_gbl_integer_bit_width = 32;
529 acpi_gbl_integer_nybble_width = 8;
530 acpi_gbl_integer_byte_width = 4;
531 } else {
532 /* 64-bit case (ACPI 2.0+) */
534 acpi_gbl_integer_bit_width = 64;
535 acpi_gbl_integer_nybble_width = 16;
536 acpi_gbl_integer_byte_width = 8;
540 #ifdef ACPI_DEBUG_OUTPUT
541 /*******************************************************************************
543 * FUNCTION: acpi_ut_display_init_pathname
545 * PARAMETERS: Type - Object type of the node
546 * obj_handle - Handle whose pathname will be displayed
547 * Path - Additional path string to be appended.
548 * (NULL if no extra path)
550 * RETURN: acpi_status
552 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
554 ******************************************************************************/
556 void
557 acpi_ut_display_init_pathname(u8 type,
558 struct acpi_namespace_node *obj_handle,
559 char *path)
561 acpi_status status;
562 struct acpi_buffer buffer;
564 ACPI_FUNCTION_ENTRY();
566 /* Only print the path if the appropriate debug level is enabled */
568 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
569 return;
572 /* Get the full pathname to the node */
574 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
575 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
576 if (ACPI_FAILURE(status)) {
577 return;
580 /* Print what we're doing */
582 switch (type) {
583 case ACPI_TYPE_METHOD:
584 acpi_os_printf("Executing ");
585 break;
587 default:
588 acpi_os_printf("Initializing ");
589 break;
592 /* Print the object type and pathname */
594 acpi_os_printf("%-12s %s",
595 acpi_ut_get_type_name(type), (char *)buffer.pointer);
597 /* Extra path is used to append names like _STA, _INI, etc. */
599 if (path) {
600 acpi_os_printf(".%s", path);
602 acpi_os_printf("\n");
604 ACPI_FREE(buffer.pointer);
606 #endif
608 /*******************************************************************************
610 * FUNCTION: acpi_ut_valid_acpi_char
612 * PARAMETERS: Char - The character to be examined
613 * Position - Byte position (0-3)
615 * RETURN: TRUE if the character is valid, FALSE otherwise
617 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
618 * 1) Upper case alpha
619 * 2) numeric
620 * 3) underscore
622 * We allow a '!' as the last character because of the ASF! table
624 ******************************************************************************/
626 u8 acpi_ut_valid_acpi_char(char character, u32 position)
629 if (!((character >= 'A' && character <= 'Z') ||
630 (character >= '0' && character <= '9') || (character == '_'))) {
632 /* Allow a '!' in the last position */
634 if (character == '!' && position == 3) {
635 return (TRUE);
638 return (FALSE);
641 return (TRUE);
644 /*******************************************************************************
646 * FUNCTION: acpi_ut_valid_acpi_name
648 * PARAMETERS: Name - The name to be examined
650 * RETURN: TRUE if the name is valid, FALSE otherwise
652 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
653 * 1) Upper case alpha
654 * 2) numeric
655 * 3) underscore
657 ******************************************************************************/
659 u8 acpi_ut_valid_acpi_name(u32 name)
661 u32 i;
663 ACPI_FUNCTION_ENTRY();
665 for (i = 0; i < ACPI_NAME_SIZE; i++) {
666 if (!acpi_ut_valid_acpi_char
667 ((ACPI_CAST_PTR(char, &name))[i], i)) {
668 return (FALSE);
672 return (TRUE);
675 /*******************************************************************************
677 * FUNCTION: acpi_ut_repair_name
679 * PARAMETERS: Name - The ACPI name to be repaired
681 * RETURN: Repaired version of the name
683 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
684 * return the new name.
686 ******************************************************************************/
688 acpi_name acpi_ut_repair_name(char *name)
690 u32 i;
691 char new_name[ACPI_NAME_SIZE];
693 for (i = 0; i < ACPI_NAME_SIZE; i++) {
694 new_name[i] = name[i];
697 * Replace a bad character with something printable, yet technically
698 * still invalid. This prevents any collisions with existing "good"
699 * names in the namespace.
701 if (!acpi_ut_valid_acpi_char(name[i], i)) {
702 new_name[i] = '*';
706 return (*(u32 *) new_name);
709 /*******************************************************************************
711 * FUNCTION: acpi_ut_strtoul64
713 * PARAMETERS: String - Null terminated string
714 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
715 * ACPI_ANY_BASE means 'in behalf of to_integer'
716 * ret_integer - Where the converted integer is returned
718 * RETURN: Status and Converted value
720 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
721 * 32-bit or 64-bit conversion, depending on the current mode
722 * of the interpreter.
723 * NOTE: Does not support Octal strings, not needed.
725 ******************************************************************************/
727 acpi_status
728 acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
730 u32 this_digit = 0;
731 acpi_integer return_value = 0;
732 acpi_integer quotient;
733 acpi_integer dividend;
734 u32 to_integer_op = (base == ACPI_ANY_BASE);
735 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
736 u8 valid_digits = 0;
737 u8 sign_of0x = 0;
738 u8 term = 0;
740 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
742 switch (base) {
743 case ACPI_ANY_BASE:
744 case 16:
745 break;
747 default:
748 /* Invalid Base */
749 return_ACPI_STATUS(AE_BAD_PARAMETER);
752 if (!string) {
753 goto error_exit;
756 /* Skip over any white space in the buffer */
758 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
759 string++;
762 if (to_integer_op) {
764 * Base equal to ACPI_ANY_BASE means 'to_integer operation case'.
765 * We need to determine if it is decimal or hexadecimal.
767 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
768 sign_of0x = 1;
769 base = 16;
771 /* Skip over the leading '0x' */
772 string += 2;
773 } else {
774 base = 10;
778 /* Any string left? Check that '0x' is not followed by white space. */
780 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
781 if (to_integer_op) {
782 goto error_exit;
783 } else {
784 goto all_done;
789 * Perform a 32-bit or 64-bit conversion, depending upon the current
790 * execution mode of the interpreter
792 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
794 /* Main loop: convert the string to a 32- or 64-bit integer */
796 while (*string) {
797 if (ACPI_IS_DIGIT(*string)) {
799 /* Convert ASCII 0-9 to Decimal value */
801 this_digit = ((u8) * string) - '0';
802 } else if (base == 10) {
804 /* Digit is out of range; possible in to_integer case only */
806 term = 1;
807 } else {
808 this_digit = (u8) ACPI_TOUPPER(*string);
809 if (ACPI_IS_XDIGIT((char)this_digit)) {
811 /* Convert ASCII Hex char to value */
813 this_digit = this_digit - 'A' + 10;
814 } else {
815 term = 1;
819 if (term) {
820 if (to_integer_op) {
821 goto error_exit;
822 } else {
823 break;
825 } else if ((valid_digits == 0) && (this_digit == 0)
826 && !sign_of0x) {
828 /* Skip zeros */
829 string++;
830 continue;
833 valid_digits++;
835 if (sign_of0x && ((valid_digits > 16)
836 || ((valid_digits > 8) && mode32))) {
838 * This is to_integer operation case.
839 * No any restrictions for string-to-integer conversion,
840 * see ACPI spec.
842 goto error_exit;
845 /* Divide the digit into the correct position */
847 (void)
848 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
849 base, &quotient, NULL);
851 if (return_value > quotient) {
852 if (to_integer_op) {
853 goto error_exit;
854 } else {
855 break;
859 return_value *= base;
860 return_value += this_digit;
861 string++;
864 /* All done, normal exit */
866 all_done:
868 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
869 ACPI_FORMAT_UINT64(return_value)));
871 *ret_integer = return_value;
872 return_ACPI_STATUS(AE_OK);
874 error_exit:
875 /* Base was set/validated above */
877 if (base == 10) {
878 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
879 } else {
880 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
884 /*******************************************************************************
886 * FUNCTION: acpi_ut_create_update_state_and_push
888 * PARAMETERS: Object - Object to be added to the new state
889 * Action - Increment/Decrement
890 * state_list - List the state will be added to
892 * RETURN: Status
894 * DESCRIPTION: Create a new state and push it
896 ******************************************************************************/
898 acpi_status
899 acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
900 u16 action,
901 union acpi_generic_state **state_list)
903 union acpi_generic_state *state;
905 ACPI_FUNCTION_ENTRY();
907 /* Ignore null objects; these are expected */
909 if (!object) {
910 return (AE_OK);
913 state = acpi_ut_create_update_state(object, action);
914 if (!state) {
915 return (AE_NO_MEMORY);
918 acpi_ut_push_generic_state(state_list, state);
919 return (AE_OK);
922 /*******************************************************************************
924 * FUNCTION: acpi_ut_walk_package_tree
926 * PARAMETERS: source_object - The package to walk
927 * target_object - Target object (if package is being copied)
928 * walk_callback - Called once for each package element
929 * Context - Passed to the callback function
931 * RETURN: Status
933 * DESCRIPTION: Walk through a package
935 ******************************************************************************/
937 acpi_status
938 acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
939 void *target_object,
940 acpi_pkg_callback walk_callback, void *context)
942 acpi_status status = AE_OK;
943 union acpi_generic_state *state_list = NULL;
944 union acpi_generic_state *state;
945 u32 this_index;
946 union acpi_operand_object *this_source_obj;
948 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
950 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
951 if (!state) {
952 return_ACPI_STATUS(AE_NO_MEMORY);
955 while (state) {
957 /* Get one element of the package */
959 this_index = state->pkg.index;
960 this_source_obj = (union acpi_operand_object *)
961 state->pkg.source_object->package.elements[this_index];
964 * Check for:
965 * 1) An uninitialized package element. It is completely
966 * legal to declare a package and leave it uninitialized
967 * 2) Not an internal object - can be a namespace node instead
968 * 3) Any type other than a package. Packages are handled in else
969 * case below.
971 if ((!this_source_obj) ||
972 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
973 ACPI_DESC_TYPE_OPERAND)
974 || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) {
975 status =
976 walk_callback(ACPI_COPY_TYPE_SIMPLE,
977 this_source_obj, state, context);
978 if (ACPI_FAILURE(status)) {
979 return_ACPI_STATUS(status);
982 state->pkg.index++;
983 while (state->pkg.index >=
984 state->pkg.source_object->package.count) {
986 * We've handled all of the objects at this level, This means
987 * that we have just completed a package. That package may
988 * have contained one or more packages itself.
990 * Delete this state and pop the previous state (package).
992 acpi_ut_delete_generic_state(state);
993 state = acpi_ut_pop_generic_state(&state_list);
995 /* Finished when there are no more states */
997 if (!state) {
999 * We have handled all of the objects in the top level
1000 * package just add the length of the package objects
1001 * and exit
1003 return_ACPI_STATUS(AE_OK);
1007 * Go back up a level and move the index past the just
1008 * completed package object.
1010 state->pkg.index++;
1012 } else {
1013 /* This is a subobject of type package */
1015 status =
1016 walk_callback(ACPI_COPY_TYPE_PACKAGE,
1017 this_source_obj, state, context);
1018 if (ACPI_FAILURE(status)) {
1019 return_ACPI_STATUS(status);
1023 * Push the current state and create a new one
1024 * The callback above returned a new target package object.
1026 acpi_ut_push_generic_state(&state_list, state);
1027 state = acpi_ut_create_pkg_state(this_source_obj,
1028 state->pkg.
1029 this_target_obj, 0);
1030 if (!state) {
1032 /* Free any stacked Update State objects */
1034 while (state_list) {
1035 state =
1036 acpi_ut_pop_generic_state
1037 (&state_list);
1038 acpi_ut_delete_generic_state(state);
1040 return_ACPI_STATUS(AE_NO_MEMORY);
1045 /* We should never get here */
1047 return_ACPI_STATUS(AE_AML_INTERNAL);
1050 /*******************************************************************************
1052 * FUNCTION: acpi_error, acpi_exception, acpi_warning, acpi_info
1054 * PARAMETERS: module_name - Caller's module name (for error output)
1055 * line_number - Caller's line number (for error output)
1056 * Format - Printf format string + additional args
1058 * RETURN: None
1060 * DESCRIPTION: Print message with module/line/version info
1062 ******************************************************************************/
1064 void ACPI_INTERNAL_VAR_XFACE
1065 acpi_error(const char *module_name, u32 line_number, const char *format, ...)
1067 va_list args;
1069 acpi_os_printf("ACPI Error: ");
1071 va_start(args, format);
1072 acpi_os_vprintf(format, args);
1073 ACPI_COMMON_MSG_SUFFIX;
1074 va_end(args);
1077 void ACPI_INTERNAL_VAR_XFACE
1078 acpi_exception(const char *module_name,
1079 u32 line_number, acpi_status status, const char *format, ...)
1081 va_list args;
1083 acpi_os_printf("ACPI Exception: %s, ", acpi_format_exception(status));
1085 va_start(args, format);
1086 acpi_os_vprintf(format, args);
1087 ACPI_COMMON_MSG_SUFFIX;
1088 va_end(args);
1091 void ACPI_INTERNAL_VAR_XFACE
1092 acpi_warning(const char *module_name, u32 line_number, const char *format, ...)
1094 va_list args;
1096 acpi_os_printf("ACPI Warning: ");
1098 va_start(args, format);
1099 acpi_os_vprintf(format, args);
1100 ACPI_COMMON_MSG_SUFFIX;
1101 va_end(args);
1104 void ACPI_INTERNAL_VAR_XFACE
1105 acpi_info(const char *module_name, u32 line_number, const char *format, ...)
1107 va_list args;
1109 acpi_os_printf("ACPI: ");
1111 va_start(args, format);
1112 acpi_os_vprintf(format, args);
1113 acpi_os_printf("\n");
1114 va_end(args);
1117 ACPI_EXPORT_SYMBOL(acpi_error)
1118 ACPI_EXPORT_SYMBOL(acpi_exception)
1119 ACPI_EXPORT_SYMBOL(acpi_warning)
1120 ACPI_EXPORT_SYMBOL(acpi_info)
1122 /*******************************************************************************
1124 * FUNCTION: acpi_ut_predefined_warning
1126 * PARAMETERS: module_name - Caller's module name (for error output)
1127 * line_number - Caller's line number (for error output)
1128 * Pathname - Full pathname to the node
1129 * node_flags - From Namespace node for the method/object
1130 * Format - Printf format string + additional args
1132 * RETURN: None
1134 * DESCRIPTION: Warnings for the predefined validation module. Messages are
1135 * only emitted the first time a problem with a particular
1136 * method/object is detected. This prevents a flood of error
1137 * messages for methods that are repeatedly evaluated.
1139 ******************************************************************************/
1141 void ACPI_INTERNAL_VAR_XFACE
1142 acpi_ut_predefined_warning(const char *module_name,
1143 u32 line_number,
1144 char *pathname,
1145 u8 node_flags, const char *format, ...)
1147 va_list args;
1150 * Warning messages for this method/object will be disabled after the
1151 * first time a validation fails or an object is successfully repaired.
1153 if (node_flags & ANOBJ_EVALUATED) {
1154 return;
1157 acpi_os_printf("ACPI Warning for %s: ", pathname);
1159 va_start(args, format);
1160 acpi_os_vprintf(format, args);
1161 ACPI_COMMON_MSG_SUFFIX;
1162 va_end(args);