1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utmisc")
52 /* Local prototypes */
55 acpi_ut_create_mutex (
56 acpi_mutex_handle mutex_id);
59 acpi_ut_delete_mutex (
60 acpi_mutex_handle mutex_id);
63 /*******************************************************************************
65 * FUNCTION: acpi_ut_strupr (strupr)
67 * PARAMETERS: src_string - The source string to convert
69 * RETURN: Converted src_string (same as input pointer)
71 * DESCRIPTION: Convert string to uppercase
73 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
75 ******************************************************************************/
84 ACPI_FUNCTION_ENTRY ();
87 /* Walk entire string, uppercasing the letters */
89 for (string = src_string; *string; string++) {
90 *string = (char) ACPI_TOUPPER (*string);
97 /*******************************************************************************
99 * FUNCTION: acpi_ut_print_string
101 * PARAMETERS: String - Null terminated ASCII string
102 * max_length - Maximum output length
106 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
109 ******************************************************************************/
112 acpi_ut_print_string (
120 acpi_os_printf ("<\"NULL STRING PTR\">");
124 acpi_os_printf ("\"");
125 for (i = 0; string[i] && (i < max_length); i++) {
126 /* Escape sequences */
130 acpi_os_printf ("\\a"); /* BELL */
134 acpi_os_printf ("\\b"); /* BACKSPACE */
138 acpi_os_printf ("\\f"); /* FORMFEED */
142 acpi_os_printf ("\\n"); /* LINEFEED */
146 acpi_os_printf ("\\r"); /* CARRIAGE RETURN*/
150 acpi_os_printf ("\\t"); /* HORIZONTAL TAB */
154 acpi_os_printf ("\\v"); /* VERTICAL TAB */
157 case '\'': /* Single Quote */
158 case '\"': /* Double Quote */
159 case '\\': /* Backslash */
160 acpi_os_printf ("\\%c", (int) string[i]);
165 /* Check for printable character or hex escape */
167 if (ACPI_IS_PRINT (string[i]))
169 /* This is a normal character */
171 acpi_os_printf ("%c", (int) string[i]);
175 /* All others will be Hex escapes */
177 acpi_os_printf ("\\x%2.2X", (s32) string[i]);
182 acpi_os_printf ("\"");
184 if (i == max_length && string[i]) {
185 acpi_os_printf ("...");
190 /*******************************************************************************
192 * FUNCTION: acpi_ut_dword_byte_swap
194 * PARAMETERS: Value - Value to be converted
196 * RETURN: u32 integer with bytes swapped
198 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
200 ******************************************************************************/
203 acpi_ut_dword_byte_swap (
216 ACPI_FUNCTION_ENTRY ();
221 out.bytes[0] = in.bytes[3];
222 out.bytes[1] = in.bytes[2];
223 out.bytes[2] = in.bytes[1];
224 out.bytes[3] = in.bytes[0];
230 /*******************************************************************************
232 * FUNCTION: acpi_ut_set_integer_width
234 * PARAMETERS: Revision From DSDT header
238 * DESCRIPTION: Set the global integer bit width based upon the revision
239 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
240 * For Revision 2 and above, Integers are 64 bits. Yes, this
241 * makes a difference.
243 ******************************************************************************/
246 acpi_ut_set_integer_width (
251 acpi_gbl_integer_bit_width = 32;
252 acpi_gbl_integer_nybble_width = 8;
253 acpi_gbl_integer_byte_width = 4;
256 acpi_gbl_integer_bit_width = 64;
257 acpi_gbl_integer_nybble_width = 16;
258 acpi_gbl_integer_byte_width = 8;
263 #ifdef ACPI_DEBUG_OUTPUT
264 /*******************************************************************************
266 * FUNCTION: acpi_ut_display_init_pathname
268 * PARAMETERS: Type - Object type of the node
269 * obj_handle - Handle whose pathname will be displayed
270 * Path - Additional path string to be appended.
271 * (NULL if no extra path)
273 * RETURN: acpi_status
275 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
277 ******************************************************************************/
280 acpi_ut_display_init_pathname (
282 struct acpi_namespace_node *obj_handle,
286 struct acpi_buffer buffer;
289 ACPI_FUNCTION_ENTRY ();
292 /* Only print the path if the appropriate debug level is enabled */
294 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
298 /* Get the full pathname to the node */
300 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
301 status = acpi_ns_handle_to_pathname (obj_handle, &buffer);
302 if (ACPI_FAILURE (status)) {
306 /* Print what we're doing */
309 case ACPI_TYPE_METHOD:
310 acpi_os_printf ("Executing ");
314 acpi_os_printf ("Initializing ");
318 /* Print the object type and pathname */
320 acpi_os_printf ("%-12s %s",
321 acpi_ut_get_type_name (type), (char *) buffer.pointer);
323 /* Extra path is used to append names like _STA, _INI, etc. */
326 acpi_os_printf (".%s", path);
328 acpi_os_printf ("\n");
330 ACPI_MEM_FREE (buffer.pointer);
335 /*******************************************************************************
337 * FUNCTION: acpi_ut_valid_acpi_name
339 * PARAMETERS: Name - The name to be examined
341 * RETURN: TRUE if the name is valid, FALSE otherwise
343 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
344 * 1) Upper case alpha
348 ******************************************************************************/
351 acpi_ut_valid_acpi_name (
354 char *name_ptr = (char *) &name;
359 ACPI_FUNCTION_ENTRY ();
362 for (i = 0; i < ACPI_NAME_SIZE; i++) {
363 character = *name_ptr;
366 if (!((character == '_') ||
367 (character >= 'A' && character <= 'Z') ||
368 (character >= '0' && character <= '9'))) {
377 /*******************************************************************************
379 * FUNCTION: acpi_ut_valid_acpi_character
381 * PARAMETERS: Character - The character to be examined
383 * RETURN: 1 if Character may appear in a name, else 0
385 * DESCRIPTION: Check for a printable character
387 ******************************************************************************/
390 acpi_ut_valid_acpi_character (
394 ACPI_FUNCTION_ENTRY ();
396 return ((u8) ((character == '_') ||
397 (character >= 'A' && character <= 'Z') ||
398 (character >= '0' && character <= '9')));
402 /*******************************************************************************
404 * FUNCTION: acpi_ut_strtoul64
406 * PARAMETERS: String - Null terminated string
407 * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE
408 * ret_integer - Where the converted integer is returned
410 * RETURN: Status and Converted value
412 * DESCRIPTION: Convert a string into an unsigned value.
413 * NOTE: Does not support Octal strings, not needed.
415 ******************************************************************************/
421 acpi_integer *ret_integer)
424 acpi_integer return_value = 0;
425 acpi_integer quotient;
428 ACPI_FUNCTION_TRACE ("ut_stroul64");
431 if ((!string) || !(*string)) {
443 return_ACPI_STATUS (AE_BAD_PARAMETER);
446 /* Skip over any white space in the buffer */
448 while (ACPI_IS_SPACE (*string) || *string == '\t') {
453 * If the input parameter Base is zero, then we need to
454 * determine if it is decimal or hexadecimal:
457 if ((*string == '0') &&
458 (ACPI_TOLOWER (*(string + 1)) == 'x')) {
468 * For hexadecimal base, skip over the leading
469 * 0 or 0x, if they are present.
473 (ACPI_TOLOWER (*(string + 1)) == 'x')) {
477 /* Any string left? */
483 /* Main loop: convert the string to a 64-bit integer */
486 if (ACPI_IS_DIGIT (*string)) {
487 /* Convert ASCII 0-9 to Decimal value */
489 this_digit = ((u8) *string) - '0';
493 /* Digit is out of range */
498 this_digit = (u8) ACPI_TOUPPER (*string);
499 if (ACPI_IS_XDIGIT ((char) this_digit)) {
500 /* Convert ASCII Hex char to value */
502 this_digit = this_digit - 'A' + 10;
506 * We allow non-hex chars, just stop now, same as end-of-string.
507 * See ACPI spec, string-to-integer conversion.
513 /* Divide the digit into the correct position */
515 (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX - (acpi_integer) this_digit),
516 base, "ient, NULL);
517 if (return_value > quotient) {
521 return_value *= base;
522 return_value += this_digit;
526 /* All done, normal exit */
528 *ret_integer = return_value;
529 return_ACPI_STATUS (AE_OK);
533 /* Base was set/validated above */
536 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
539 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
544 /*******************************************************************************
546 * FUNCTION: acpi_ut_mutex_initialize
552 * DESCRIPTION: Create the system mutex objects.
554 ******************************************************************************/
557 acpi_ut_mutex_initialize (
564 ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
568 * Create each of the predefined mutex objects
570 for (i = 0; i < NUM_MUTEX; i++) {
571 status = acpi_ut_create_mutex (i);
572 if (ACPI_FAILURE (status)) {
573 return_ACPI_STATUS (status);
577 status = acpi_os_create_lock (&acpi_gbl_gpe_lock);
578 return_ACPI_STATUS (status);
582 /*******************************************************************************
584 * FUNCTION: acpi_ut_mutex_terminate
590 * DESCRIPTION: Delete all of the system mutex objects.
592 ******************************************************************************/
595 acpi_ut_mutex_terminate (
601 ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
605 * Delete each predefined mutex object
607 for (i = 0; i < NUM_MUTEX; i++) {
608 (void) acpi_ut_delete_mutex (i);
611 acpi_os_delete_lock (acpi_gbl_gpe_lock);
616 /*******************************************************************************
618 * FUNCTION: acpi_ut_create_mutex
620 * PARAMETERS: mutex_iD - ID of the mutex to be created
624 * DESCRIPTION: Create a mutex object.
626 ******************************************************************************/
629 acpi_ut_create_mutex (
630 acpi_mutex_handle mutex_id)
632 acpi_status status = AE_OK;
635 ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id);
638 if (mutex_id > MAX_MUTEX) {
639 return_ACPI_STATUS (AE_BAD_PARAMETER);
642 if (!acpi_gbl_mutex_info[mutex_id].mutex) {
643 status = acpi_os_create_semaphore (1, 1,
644 &acpi_gbl_mutex_info[mutex_id].mutex);
645 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
646 acpi_gbl_mutex_info[mutex_id].use_count = 0;
649 return_ACPI_STATUS (status);
653 /*******************************************************************************
655 * FUNCTION: acpi_ut_delete_mutex
657 * PARAMETERS: mutex_iD - ID of the mutex to be deleted
661 * DESCRIPTION: Delete a mutex object.
663 ******************************************************************************/
666 acpi_ut_delete_mutex (
667 acpi_mutex_handle mutex_id)
672 ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id);
675 if (mutex_id > MAX_MUTEX) {
676 return_ACPI_STATUS (AE_BAD_PARAMETER);
679 status = acpi_os_delete_semaphore (acpi_gbl_mutex_info[mutex_id].mutex);
681 acpi_gbl_mutex_info[mutex_id].mutex = NULL;
682 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
684 return_ACPI_STATUS (status);
688 /*******************************************************************************
690 * FUNCTION: acpi_ut_acquire_mutex
692 * PARAMETERS: mutex_iD - ID of the mutex to be acquired
696 * DESCRIPTION: Acquire a mutex object.
698 ******************************************************************************/
701 acpi_ut_acquire_mutex (
702 acpi_mutex_handle mutex_id)
708 ACPI_FUNCTION_NAME ("ut_acquire_mutex");
711 if (mutex_id > MAX_MUTEX) {
712 return (AE_BAD_PARAMETER);
715 this_thread_id = acpi_os_get_thread_id ();
717 #ifdef ACPI_MUTEX_DEBUG
721 * Mutex debug code, for internal debugging only.
723 * Deadlock prevention. Check if this thread owns any mutexes of value
724 * greater than or equal to this one. If so, the thread has violated
725 * the mutex ordering rule. This indicates a coding error somewhere in
726 * the ACPI subsystem code.
728 for (i = mutex_id; i < MAX_MUTEX; i++) {
729 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
732 "Mutex [%s] already acquired by this thread [%X]\n",
733 acpi_ut_get_mutex_name (mutex_id), this_thread_id));
735 return (AE_ALREADY_ACQUIRED);
738 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
739 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
740 this_thread_id, acpi_ut_get_mutex_name (i),
741 acpi_ut_get_mutex_name (mutex_id)));
743 return (AE_ACQUIRE_DEADLOCK);
749 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
750 "Thread %X attempting to acquire Mutex [%s]\n",
751 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
753 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex,
754 1, ACPI_WAIT_FOREVER);
755 if (ACPI_SUCCESS (status)) {
756 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
757 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
759 acpi_gbl_mutex_info[mutex_id].use_count++;
760 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id;
763 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
764 "Thread %X could not acquire Mutex [%s] %s\n",
765 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
766 acpi_format_exception (status)));
773 /*******************************************************************************
775 * FUNCTION: acpi_ut_release_mutex
777 * PARAMETERS: mutex_iD - ID of the mutex to be released
781 * DESCRIPTION: Release a mutex object.
783 ******************************************************************************/
786 acpi_ut_release_mutex (
787 acpi_mutex_handle mutex_id)
793 ACPI_FUNCTION_NAME ("ut_release_mutex");
796 this_thread_id = acpi_os_get_thread_id ();
797 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
798 "Thread %X releasing Mutex [%s]\n", this_thread_id,
799 acpi_ut_get_mutex_name (mutex_id)));
801 if (mutex_id > MAX_MUTEX) {
802 return (AE_BAD_PARAMETER);
806 * Mutex must be acquired in order to release it!
808 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) {
809 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
810 "Mutex [%s] is not acquired, cannot release\n",
811 acpi_ut_get_mutex_name (mutex_id)));
813 return (AE_NOT_ACQUIRED);
816 #ifdef ACPI_MUTEX_DEBUG
820 * Mutex debug code, for internal debugging only.
822 * Deadlock prevention. Check if this thread owns any mutexes of value
823 * greater than this one. If so, the thread has violated the mutex
824 * ordering rule. This indicates a coding error somewhere in
825 * the ACPI subsystem code.
827 for (i = mutex_id; i < MAX_MUTEX; i++) {
828 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
833 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
834 "Invalid release order: owns [%s], releasing [%s]\n",
835 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
837 return (AE_RELEASE_DEADLOCK);
843 /* Mark unlocked FIRST */
845 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
847 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
849 if (ACPI_FAILURE (status)) {
850 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
851 "Thread %X could not release Mutex [%s] %s\n",
852 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
853 acpi_format_exception (status)));
856 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
857 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
864 /*******************************************************************************
866 * FUNCTION: acpi_ut_create_update_state_and_push
868 * PARAMETERS: Object - Object to be added to the new state
869 * Action - Increment/Decrement
870 * state_list - List the state will be added to
874 * DESCRIPTION: Create a new state and push it
876 ******************************************************************************/
879 acpi_ut_create_update_state_and_push (
880 union acpi_operand_object *object,
882 union acpi_generic_state **state_list)
884 union acpi_generic_state *state;
887 ACPI_FUNCTION_ENTRY ();
890 /* Ignore null objects; these are expected */
896 state = acpi_ut_create_update_state (object, action);
898 return (AE_NO_MEMORY);
901 acpi_ut_push_generic_state (state_list, state);
906 /*******************************************************************************
908 * FUNCTION: acpi_ut_create_pkg_state_and_push
910 * PARAMETERS: Object - Object to be added to the new state
911 * Action - Increment/Decrement
912 * state_list - List the state will be added to
916 * DESCRIPTION: Create a new state and push it
918 ******************************************************************************/
920 #ifdef ACPI_FUTURE_USAGE
922 acpi_ut_create_pkg_state_and_push (
923 void *internal_object,
924 void *external_object,
926 union acpi_generic_state **state_list)
928 union acpi_generic_state *state;
931 ACPI_FUNCTION_ENTRY ();
934 state = acpi_ut_create_pkg_state (internal_object, external_object, index);
936 return (AE_NO_MEMORY);
939 acpi_ut_push_generic_state (state_list, state);
942 #endif /* ACPI_FUTURE_USAGE */
944 /*******************************************************************************
946 * FUNCTION: acpi_ut_push_generic_state
948 * PARAMETERS: list_head - Head of the state stack
949 * State - State object to push
953 * DESCRIPTION: Push a state object onto a state stack
955 ******************************************************************************/
958 acpi_ut_push_generic_state (
959 union acpi_generic_state **list_head,
960 union acpi_generic_state *state)
962 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
965 /* Push the state object onto the front of the list (stack) */
967 state->common.next = *list_head;
974 /*******************************************************************************
976 * FUNCTION: acpi_ut_pop_generic_state
978 * PARAMETERS: list_head - Head of the state stack
980 * RETURN: The popped state object
982 * DESCRIPTION: Pop a state object from a state stack
984 ******************************************************************************/
986 union acpi_generic_state *
987 acpi_ut_pop_generic_state (
988 union acpi_generic_state **list_head)
990 union acpi_generic_state *state;
993 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
996 /* Remove the state object at the head of the list (stack) */
1000 /* Update the list head */
1002 *list_head = state->common.next;
1009 /*******************************************************************************
1011 * FUNCTION: acpi_ut_create_generic_state
1015 * RETURN: The new state object. NULL on failure.
1017 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1018 * the global state cache; If none available, create a new one.
1020 ******************************************************************************/
1022 union acpi_generic_state *
1023 acpi_ut_create_generic_state (
1026 union acpi_generic_state *state;
1029 ACPI_FUNCTION_ENTRY ();
1032 state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE);
1037 state->common.data_type = ACPI_DESC_TYPE_STATE;
1044 /*******************************************************************************
1046 * FUNCTION: acpi_ut_create_thread_state
1050 * RETURN: New Thread State. NULL on failure
1052 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1053 * to track per-thread info during method execution
1055 ******************************************************************************/
1057 struct acpi_thread_state *
1058 acpi_ut_create_thread_state (
1061 union acpi_generic_state *state;
1064 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
1067 /* Create the generic state object */
1069 state = acpi_ut_create_generic_state ();
1074 /* Init fields specific to the update struct */
1076 state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
1077 state->thread.thread_id = acpi_os_get_thread_id ();
1079 return_PTR ((struct acpi_thread_state *) state);
1083 /*******************************************************************************
1085 * FUNCTION: acpi_ut_create_update_state
1087 * PARAMETERS: Object - Initial Object to be installed in the state
1088 * Action - Update action to be performed
1090 * RETURN: New state object, null on failure
1092 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1093 * to update reference counts and delete complex objects such
1096 ******************************************************************************/
1098 union acpi_generic_state *
1099 acpi_ut_create_update_state (
1100 union acpi_operand_object *object,
1103 union acpi_generic_state *state;
1106 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
1109 /* Create the generic state object */
1111 state = acpi_ut_create_generic_state ();
1116 /* Init fields specific to the update struct */
1118 state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
1119 state->update.object = object;
1120 state->update.value = action;
1126 /*******************************************************************************
1128 * FUNCTION: acpi_ut_create_pkg_state
1130 * PARAMETERS: Object - Initial Object to be installed in the state
1131 * Action - Update action to be performed
1133 * RETURN: New state object, null on failure
1135 * DESCRIPTION: Create a "Package State"
1137 ******************************************************************************/
1139 union acpi_generic_state *
1140 acpi_ut_create_pkg_state (
1141 void *internal_object,
1142 void *external_object,
1145 union acpi_generic_state *state;
1148 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
1151 /* Create the generic state object */
1153 state = acpi_ut_create_generic_state ();
1158 /* Init fields specific to the update struct */
1160 state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE;
1161 state->pkg.source_object = (union acpi_operand_object *) internal_object;
1162 state->pkg.dest_object = external_object;
1163 state->pkg.index = index;
1164 state->pkg.num_packages = 1;
1170 /*******************************************************************************
1172 * FUNCTION: acpi_ut_create_control_state
1176 * RETURN: New state object, null on failure
1178 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1179 * to support nested IF/WHILE constructs in the AML.
1181 ******************************************************************************/
1183 union acpi_generic_state *
1184 acpi_ut_create_control_state (
1187 union acpi_generic_state *state;
1190 ACPI_FUNCTION_TRACE ("ut_create_control_state");
1193 /* Create the generic state object */
1195 state = acpi_ut_create_generic_state ();
1200 /* Init fields specific to the control struct */
1202 state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
1203 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1209 /*******************************************************************************
1211 * FUNCTION: acpi_ut_delete_generic_state
1213 * PARAMETERS: State - The state object to be deleted
1217 * DESCRIPTION: Put a state object back into the global state cache. The object
1218 * is not actually freed at this time.
1220 ******************************************************************************/
1223 acpi_ut_delete_generic_state (
1224 union acpi_generic_state *state)
1226 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
1229 acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE, state);
1234 #ifdef ACPI_ENABLE_OBJECT_CACHE
1235 /*******************************************************************************
1237 * FUNCTION: acpi_ut_delete_generic_state_cache
1243 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1246 ******************************************************************************/
1249 acpi_ut_delete_generic_state_cache (
1252 ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
1255 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE);
1261 /*******************************************************************************
1263 * FUNCTION: acpi_ut_walk_package_tree
1265 * PARAMETERS: source_object - The package to walk
1266 * target_object - Target object (if package is being copied)
1267 * walk_callback - Called once for each package element
1268 * Context - Passed to the callback function
1272 * DESCRIPTION: Walk through a package
1274 ******************************************************************************/
1277 acpi_ut_walk_package_tree (
1278 union acpi_operand_object *source_object,
1279 void *target_object,
1280 acpi_pkg_callback walk_callback,
1283 acpi_status status = AE_OK;
1284 union acpi_generic_state *state_list = NULL;
1285 union acpi_generic_state *state;
1287 union acpi_operand_object *this_source_obj;
1290 ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
1293 state = acpi_ut_create_pkg_state (source_object, target_object, 0);
1295 return_ACPI_STATUS (AE_NO_MEMORY);
1299 /* Get one element of the package */
1301 this_index = state->pkg.index;
1302 this_source_obj = (union acpi_operand_object *)
1303 state->pkg.source_object->package.elements[this_index];
1307 * 1) An uninitialized package element. It is completely
1308 * legal to declare a package and leave it uninitialized
1309 * 2) Not an internal object - can be a namespace node instead
1310 * 3) Any type other than a package. Packages are handled in else
1313 if ((!this_source_obj) ||
1314 (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj) != ACPI_DESC_TYPE_OPERAND) ||
1315 (ACPI_GET_OBJECT_TYPE (this_source_obj) != ACPI_TYPE_PACKAGE)) {
1316 status = walk_callback (ACPI_COPY_TYPE_SIMPLE, this_source_obj,
1318 if (ACPI_FAILURE (status)) {
1319 return_ACPI_STATUS (status);
1323 while (state->pkg.index >= state->pkg.source_object->package.count) {
1325 * We've handled all of the objects at this level, This means
1326 * that we have just completed a package. That package may
1327 * have contained one or more packages itself.
1329 * Delete this state and pop the previous state (package).
1331 acpi_ut_delete_generic_state (state);
1332 state = acpi_ut_pop_generic_state (&state_list);
1334 /* Finished when there are no more states */
1338 * We have handled all of the objects in the top level
1339 * package just add the length of the package objects
1342 return_ACPI_STATUS (AE_OK);
1346 * Go back up a level and move the index past the just
1347 * completed package object.
1353 /* This is a subobject of type package */
1355 status = walk_callback (ACPI_COPY_TYPE_PACKAGE, this_source_obj,
1357 if (ACPI_FAILURE (status)) {
1358 return_ACPI_STATUS (status);
1362 * Push the current state and create a new one
1363 * The callback above returned a new target package object.
1365 acpi_ut_push_generic_state (&state_list, state);
1366 state = acpi_ut_create_pkg_state (this_source_obj,
1367 state->pkg.this_target_obj, 0);
1369 return_ACPI_STATUS (AE_NO_MEMORY);
1374 /* We should never get here */
1376 return_ACPI_STATUS (AE_AML_INTERNAL);
1380 /*******************************************************************************
1382 * FUNCTION: acpi_ut_generate_checksum
1384 * PARAMETERS: Buffer - Buffer to be scanned
1385 * Length - number of bytes to examine
1387 * RETURN: The generated checksum
1389 * DESCRIPTION: Generate a checksum on a raw buffer
1391 ******************************************************************************/
1394 acpi_ut_generate_checksum (
1399 signed char sum = 0;
1402 for (i = 0; i < length; i++) {
1403 sum = (signed char) (sum + buffer[i]);
1406 return ((u8) (0 - sum));
1410 /*******************************************************************************
1412 * FUNCTION: acpi_ut_get_resource_end_tag
1414 * PARAMETERS: obj_desc - The resource template buffer object
1416 * RETURN: Pointer to the end tag
1418 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1420 ******************************************************************************/
1424 acpi_ut_get_resource_end_tag (
1425 union acpi_operand_object *obj_desc)
1432 buffer = obj_desc->buffer.pointer;
1433 end_buffer = buffer + obj_desc->buffer.length;
1435 while (buffer < end_buffer) {
1436 buffer_byte = *buffer;
1437 if (buffer_byte & ACPI_RDESC_TYPE_MASK) {
1438 /* Large Descriptor - Length is next 2 bytes */
1440 buffer += ((*(buffer+1) | (*(buffer+2) << 8)) + 3);
1443 /* Small Descriptor. End Tag will be found here */
1445 if ((buffer_byte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG) {
1446 /* Found the end tag descriptor, all done. */
1451 /* Length is in the header */
1453 buffer += ((buffer_byte & 0x07) + 1);
1457 /* End tag not found */
1463 /*******************************************************************************
1465 * FUNCTION: acpi_ut_report_error
1467 * PARAMETERS: module_name - Caller's module name (for error output)
1468 * line_number - Caller's line number (for error output)
1469 * component_id - Caller's component ID (for error output)
1473 * DESCRIPTION: Print error message
1475 ******************************************************************************/
1478 acpi_ut_report_error (
1484 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
1488 /*******************************************************************************
1490 * FUNCTION: acpi_ut_report_warning
1492 * PARAMETERS: module_name - Caller's module name (for error output)
1493 * line_number - Caller's line number (for error output)
1494 * component_id - Caller's component ID (for error output)
1498 * DESCRIPTION: Print warning message
1500 ******************************************************************************/
1503 acpi_ut_report_warning (
1509 acpi_os_printf ("%8s-%04d: *** Warning: ", module_name, line_number);
1513 /*******************************************************************************
1515 * FUNCTION: acpi_ut_report_info
1517 * PARAMETERS: module_name - Caller's module name (for error output)
1518 * line_number - Caller's line number (for error output)
1519 * component_id - Caller's component ID (for error output)
1523 * DESCRIPTION: Print information message
1525 ******************************************************************************/
1528 acpi_ut_report_info (
1534 acpi_os_printf ("%8s-%04d: *** Info: ", module_name, line_number);