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)
794 ACPI_FUNCTION_NAME ("ut_release_mutex");
797 this_thread_id = acpi_os_get_thread_id ();
798 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
799 "Thread %X releasing Mutex [%s]\n", this_thread_id,
800 acpi_ut_get_mutex_name (mutex_id)));
802 if (mutex_id > MAX_MUTEX) {
803 return (AE_BAD_PARAMETER);
807 * Mutex must be acquired in order to release it!
809 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) {
810 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
811 "Mutex [%s] is not acquired, cannot release\n",
812 acpi_ut_get_mutex_name (mutex_id)));
814 return (AE_NOT_ACQUIRED);
818 * Deadlock prevention. Check if this thread owns any mutexes of value
819 * greater than this one. If so, the thread has violated the mutex
820 * ordering rule. This indicates a coding error somewhere in
821 * the ACPI subsystem code.
823 for (i = mutex_id; i < MAX_MUTEX; i++) {
824 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
830 "Invalid release order: owns [%s], releasing [%s]\n",
831 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
833 return (AE_RELEASE_DEADLOCK);
837 /* Mark unlocked FIRST */
839 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
841 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
843 if (ACPI_FAILURE (status)) {
844 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
845 "Thread %X could not release Mutex [%s] %s\n",
846 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
847 acpi_format_exception (status)));
850 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
851 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
858 /*******************************************************************************
860 * FUNCTION: acpi_ut_create_update_state_and_push
862 * PARAMETERS: Object - Object to be added to the new state
863 * Action - Increment/Decrement
864 * state_list - List the state will be added to
868 * DESCRIPTION: Create a new state and push it
870 ******************************************************************************/
873 acpi_ut_create_update_state_and_push (
874 union acpi_operand_object *object,
876 union acpi_generic_state **state_list)
878 union acpi_generic_state *state;
881 ACPI_FUNCTION_ENTRY ();
884 /* Ignore null objects; these are expected */
890 state = acpi_ut_create_update_state (object, action);
892 return (AE_NO_MEMORY);
895 acpi_ut_push_generic_state (state_list, state);
900 /*******************************************************************************
902 * FUNCTION: acpi_ut_create_pkg_state_and_push
904 * PARAMETERS: Object - Object to be added to the new state
905 * Action - Increment/Decrement
906 * state_list - List the state will be added to
910 * DESCRIPTION: Create a new state and push it
912 ******************************************************************************/
914 #ifdef ACPI_FUTURE_USAGE
916 acpi_ut_create_pkg_state_and_push (
917 void *internal_object,
918 void *external_object,
920 union acpi_generic_state **state_list)
922 union acpi_generic_state *state;
925 ACPI_FUNCTION_ENTRY ();
928 state = acpi_ut_create_pkg_state (internal_object, external_object, index);
930 return (AE_NO_MEMORY);
933 acpi_ut_push_generic_state (state_list, state);
936 #endif /* ACPI_FUTURE_USAGE */
938 /*******************************************************************************
940 * FUNCTION: acpi_ut_push_generic_state
942 * PARAMETERS: list_head - Head of the state stack
943 * State - State object to push
947 * DESCRIPTION: Push a state object onto a state stack
949 ******************************************************************************/
952 acpi_ut_push_generic_state (
953 union acpi_generic_state **list_head,
954 union acpi_generic_state *state)
956 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
959 /* Push the state object onto the front of the list (stack) */
961 state->common.next = *list_head;
968 /*******************************************************************************
970 * FUNCTION: acpi_ut_pop_generic_state
972 * PARAMETERS: list_head - Head of the state stack
974 * RETURN: The popped state object
976 * DESCRIPTION: Pop a state object from a state stack
978 ******************************************************************************/
980 union acpi_generic_state *
981 acpi_ut_pop_generic_state (
982 union acpi_generic_state **list_head)
984 union acpi_generic_state *state;
987 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
990 /* Remove the state object at the head of the list (stack) */
994 /* Update the list head */
996 *list_head = state->common.next;
1003 /*******************************************************************************
1005 * FUNCTION: acpi_ut_create_generic_state
1009 * RETURN: The new state object. NULL on failure.
1011 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1012 * the global state cache; If none available, create a new one.
1014 ******************************************************************************/
1016 union acpi_generic_state *
1017 acpi_ut_create_generic_state (
1020 union acpi_generic_state *state;
1023 ACPI_FUNCTION_ENTRY ();
1026 state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE);
1031 state->common.data_type = ACPI_DESC_TYPE_STATE;
1038 /*******************************************************************************
1040 * FUNCTION: acpi_ut_create_thread_state
1044 * RETURN: New Thread State. NULL on failure
1046 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1047 * to track per-thread info during method execution
1049 ******************************************************************************/
1051 struct acpi_thread_state *
1052 acpi_ut_create_thread_state (
1055 union acpi_generic_state *state;
1058 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
1061 /* Create the generic state object */
1063 state = acpi_ut_create_generic_state ();
1068 /* Init fields specific to the update struct */
1070 state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
1071 state->thread.thread_id = acpi_os_get_thread_id ();
1073 return_PTR ((struct acpi_thread_state *) state);
1077 /*******************************************************************************
1079 * FUNCTION: acpi_ut_create_update_state
1081 * PARAMETERS: Object - Initial Object to be installed in the state
1082 * Action - Update action to be performed
1084 * RETURN: New state object, null on failure
1086 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1087 * to update reference counts and delete complex objects such
1090 ******************************************************************************/
1092 union acpi_generic_state *
1093 acpi_ut_create_update_state (
1094 union acpi_operand_object *object,
1097 union acpi_generic_state *state;
1100 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
1103 /* Create the generic state object */
1105 state = acpi_ut_create_generic_state ();
1110 /* Init fields specific to the update struct */
1112 state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
1113 state->update.object = object;
1114 state->update.value = action;
1120 /*******************************************************************************
1122 * FUNCTION: acpi_ut_create_pkg_state
1124 * PARAMETERS: Object - Initial Object to be installed in the state
1125 * Action - Update action to be performed
1127 * RETURN: New state object, null on failure
1129 * DESCRIPTION: Create a "Package State"
1131 ******************************************************************************/
1133 union acpi_generic_state *
1134 acpi_ut_create_pkg_state (
1135 void *internal_object,
1136 void *external_object,
1139 union acpi_generic_state *state;
1142 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
1145 /* Create the generic state object */
1147 state = acpi_ut_create_generic_state ();
1152 /* Init fields specific to the update struct */
1154 state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE;
1155 state->pkg.source_object = (union acpi_operand_object *) internal_object;
1156 state->pkg.dest_object = external_object;
1157 state->pkg.index = index;
1158 state->pkg.num_packages = 1;
1164 /*******************************************************************************
1166 * FUNCTION: acpi_ut_create_control_state
1170 * RETURN: New state object, null on failure
1172 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1173 * to support nested IF/WHILE constructs in the AML.
1175 ******************************************************************************/
1177 union acpi_generic_state *
1178 acpi_ut_create_control_state (
1181 union acpi_generic_state *state;
1184 ACPI_FUNCTION_TRACE ("ut_create_control_state");
1187 /* Create the generic state object */
1189 state = acpi_ut_create_generic_state ();
1194 /* Init fields specific to the control struct */
1196 state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
1197 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1203 /*******************************************************************************
1205 * FUNCTION: acpi_ut_delete_generic_state
1207 * PARAMETERS: State - The state object to be deleted
1211 * DESCRIPTION: Put a state object back into the global state cache. The object
1212 * is not actually freed at this time.
1214 ******************************************************************************/
1217 acpi_ut_delete_generic_state (
1218 union acpi_generic_state *state)
1220 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
1223 acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE, state);
1228 #ifdef ACPI_ENABLE_OBJECT_CACHE
1229 /*******************************************************************************
1231 * FUNCTION: acpi_ut_delete_generic_state_cache
1237 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1240 ******************************************************************************/
1243 acpi_ut_delete_generic_state_cache (
1246 ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
1249 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE);
1255 /*******************************************************************************
1257 * FUNCTION: acpi_ut_walk_package_tree
1259 * PARAMETERS: source_object - The package to walk
1260 * target_object - Target object (if package is being copied)
1261 * walk_callback - Called once for each package element
1262 * Context - Passed to the callback function
1266 * DESCRIPTION: Walk through a package
1268 ******************************************************************************/
1271 acpi_ut_walk_package_tree (
1272 union acpi_operand_object *source_object,
1273 void *target_object,
1274 acpi_pkg_callback walk_callback,
1277 acpi_status status = AE_OK;
1278 union acpi_generic_state *state_list = NULL;
1279 union acpi_generic_state *state;
1281 union acpi_operand_object *this_source_obj;
1284 ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
1287 state = acpi_ut_create_pkg_state (source_object, target_object, 0);
1289 return_ACPI_STATUS (AE_NO_MEMORY);
1293 /* Get one element of the package */
1295 this_index = state->pkg.index;
1296 this_source_obj = (union acpi_operand_object *)
1297 state->pkg.source_object->package.elements[this_index];
1301 * 1) An uninitialized package element. It is completely
1302 * legal to declare a package and leave it uninitialized
1303 * 2) Not an internal object - can be a namespace node instead
1304 * 3) Any type other than a package. Packages are handled in else
1307 if ((!this_source_obj) ||
1308 (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj) != ACPI_DESC_TYPE_OPERAND) ||
1309 (ACPI_GET_OBJECT_TYPE (this_source_obj) != ACPI_TYPE_PACKAGE)) {
1310 status = walk_callback (ACPI_COPY_TYPE_SIMPLE, this_source_obj,
1312 if (ACPI_FAILURE (status)) {
1313 return_ACPI_STATUS (status);
1317 while (state->pkg.index >= state->pkg.source_object->package.count) {
1319 * We've handled all of the objects at this level, This means
1320 * that we have just completed a package. That package may
1321 * have contained one or more packages itself.
1323 * Delete this state and pop the previous state (package).
1325 acpi_ut_delete_generic_state (state);
1326 state = acpi_ut_pop_generic_state (&state_list);
1328 /* Finished when there are no more states */
1332 * We have handled all of the objects in the top level
1333 * package just add the length of the package objects
1336 return_ACPI_STATUS (AE_OK);
1340 * Go back up a level and move the index past the just
1341 * completed package object.
1347 /* This is a subobject of type package */
1349 status = walk_callback (ACPI_COPY_TYPE_PACKAGE, this_source_obj,
1351 if (ACPI_FAILURE (status)) {
1352 return_ACPI_STATUS (status);
1356 * Push the current state and create a new one
1357 * The callback above returned a new target package object.
1359 acpi_ut_push_generic_state (&state_list, state);
1360 state = acpi_ut_create_pkg_state (this_source_obj,
1361 state->pkg.this_target_obj, 0);
1363 return_ACPI_STATUS (AE_NO_MEMORY);
1368 /* We should never get here */
1370 return_ACPI_STATUS (AE_AML_INTERNAL);
1374 /*******************************************************************************
1376 * FUNCTION: acpi_ut_generate_checksum
1378 * PARAMETERS: Buffer - Buffer to be scanned
1379 * Length - number of bytes to examine
1381 * RETURN: The generated checksum
1383 * DESCRIPTION: Generate a checksum on a raw buffer
1385 ******************************************************************************/
1388 acpi_ut_generate_checksum (
1393 signed char sum = 0;
1396 for (i = 0; i < length; i++) {
1397 sum = (signed char) (sum + buffer[i]);
1400 return ((u8) (0 - sum));
1404 /*******************************************************************************
1406 * FUNCTION: acpi_ut_get_resource_end_tag
1408 * PARAMETERS: obj_desc - The resource template buffer object
1410 * RETURN: Pointer to the end tag
1412 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1414 ******************************************************************************/
1418 acpi_ut_get_resource_end_tag (
1419 union acpi_operand_object *obj_desc)
1426 buffer = obj_desc->buffer.pointer;
1427 end_buffer = buffer + obj_desc->buffer.length;
1429 while (buffer < end_buffer) {
1430 buffer_byte = *buffer;
1431 if (buffer_byte & ACPI_RDESC_TYPE_MASK) {
1432 /* Large Descriptor - Length is next 2 bytes */
1434 buffer += ((*(buffer+1) | (*(buffer+2) << 8)) + 3);
1437 /* Small Descriptor. End Tag will be found here */
1439 if ((buffer_byte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG) {
1440 /* Found the end tag descriptor, all done. */
1445 /* Length is in the header */
1447 buffer += ((buffer_byte & 0x07) + 1);
1451 /* End tag not found */
1457 /*******************************************************************************
1459 * FUNCTION: acpi_ut_report_error
1461 * PARAMETERS: module_name - Caller's module name (for error output)
1462 * line_number - Caller's line number (for error output)
1463 * component_id - Caller's component ID (for error output)
1467 * DESCRIPTION: Print error message
1469 ******************************************************************************/
1472 acpi_ut_report_error (
1478 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
1482 /*******************************************************************************
1484 * FUNCTION: acpi_ut_report_warning
1486 * PARAMETERS: module_name - Caller's module name (for error output)
1487 * line_number - Caller's line number (for error output)
1488 * component_id - Caller's component ID (for error output)
1492 * DESCRIPTION: Print warning message
1494 ******************************************************************************/
1497 acpi_ut_report_warning (
1503 acpi_os_printf ("%8s-%04d: *** Warning: ", module_name, line_number);
1507 /*******************************************************************************
1509 * FUNCTION: acpi_ut_report_info
1511 * PARAMETERS: module_name - Caller's module name (for error output)
1512 * line_number - Caller's line number (for error output)
1513 * component_id - Caller's component ID (for error output)
1517 * DESCRIPTION: Print information message
1519 ******************************************************************************/
1522 acpi_ut_report_info (
1528 acpi_os_printf ("%8s-%04d: *** Info: ", module_name, line_number);