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")
53 /*******************************************************************************
55 * FUNCTION: acpi_ut_print_string
57 * PARAMETERS: String - Null terminated ASCII string
61 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
64 ******************************************************************************/
67 acpi_ut_print_string (
75 acpi_os_printf ("<\"NULL STRING PTR\">");
79 acpi_os_printf ("\"");
80 for (i = 0; string[i] && (i < max_length); i++) {
81 /* Escape sequences */
85 acpi_os_printf ("\\a"); /* BELL */
89 acpi_os_printf ("\\b"); /* BACKSPACE */
93 acpi_os_printf ("\\f"); /* FORMFEED */
97 acpi_os_printf ("\\n"); /* LINEFEED */
101 acpi_os_printf ("\\r"); /* CARRIAGE RETURN*/
105 acpi_os_printf ("\\t"); /* HORIZONTAL TAB */
109 acpi_os_printf ("\\v"); /* VERTICAL TAB */
112 case '\'': /* Single Quote */
113 case '\"': /* Double Quote */
114 case '\\': /* Backslash */
115 acpi_os_printf ("\\%c", (int) string[i]);
120 /* Check for printable character or hex escape */
122 if (ACPI_IS_PRINT (string[i]))
124 /* This is a normal character */
126 acpi_os_printf ("%c", (int) string[i]);
130 /* All others will be Hex escapes */
132 acpi_os_printf ("\\x%2.2X", (s32) string[i]);
137 acpi_os_printf ("\"");
139 if (i == max_length && string[i]) {
140 acpi_os_printf ("...");
145 /*******************************************************************************
147 * FUNCTION: acpi_ut_dword_byte_swap
149 * PARAMETERS: Value - Value to be converted
151 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
153 ******************************************************************************/
156 acpi_ut_dword_byte_swap (
170 ACPI_FUNCTION_ENTRY ();
175 out.bytes[0] = in.bytes[3];
176 out.bytes[1] = in.bytes[2];
177 out.bytes[2] = in.bytes[1];
178 out.bytes[3] = in.bytes[0];
184 /*******************************************************************************
186 * FUNCTION: acpi_ut_set_integer_width
188 * PARAMETERS: Revision From DSDT header
192 * DESCRIPTION: Set the global integer bit width based upon the revision
193 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
194 * For Revision 2 and above, Integers are 64 bits. Yes, this
195 * makes a difference.
197 ******************************************************************************/
200 acpi_ut_set_integer_width (
205 acpi_gbl_integer_bit_width = 32;
206 acpi_gbl_integer_nybble_width = 8;
207 acpi_gbl_integer_byte_width = 4;
210 acpi_gbl_integer_bit_width = 64;
211 acpi_gbl_integer_nybble_width = 16;
212 acpi_gbl_integer_byte_width = 8;
217 #ifdef ACPI_DEBUG_OUTPUT
218 /*******************************************************************************
220 * FUNCTION: acpi_ut_display_init_pathname
222 * PARAMETERS: obj_handle - Handle whose pathname will be displayed
223 * Path - Additional path string to be appended.
224 * (NULL if no extra path)
226 * RETURN: acpi_status
228 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
230 ******************************************************************************/
233 acpi_ut_display_init_pathname (
235 struct acpi_namespace_node *obj_handle,
239 struct acpi_buffer buffer;
242 ACPI_FUNCTION_ENTRY ();
245 /* Only print the path if the appropriate debug level is enabled */
247 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
251 /* Get the full pathname to the node */
253 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
254 status = acpi_ns_handle_to_pathname (obj_handle, &buffer);
255 if (ACPI_FAILURE (status)) {
259 /* Print what we're doing */
262 case ACPI_TYPE_METHOD:
263 acpi_os_printf ("Executing ");
267 acpi_os_printf ("Initializing ");
271 /* Print the object type and pathname */
273 acpi_os_printf ("%-12s %s", acpi_ut_get_type_name (type), (char *) buffer.pointer);
275 /* Extra path is used to append names like _STA, _INI, etc. */
278 acpi_os_printf (".%s", path);
280 acpi_os_printf ("\n");
282 ACPI_MEM_FREE (buffer.pointer);
287 /*******************************************************************************
289 * FUNCTION: acpi_ut_valid_acpi_name
291 * PARAMETERS: Character - The character to be examined
293 * RETURN: 1 if Character may appear in a name, else 0
295 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
296 * 1) Upper case alpha
300 ******************************************************************************/
303 acpi_ut_valid_acpi_name (
306 char *name_ptr = (char *) &name;
311 ACPI_FUNCTION_ENTRY ();
314 for (i = 0; i < ACPI_NAME_SIZE; i++) {
315 character = *name_ptr;
318 if (!((character == '_') ||
319 (character >= 'A' && character <= 'Z') ||
320 (character >= '0' && character <= '9'))) {
329 /*******************************************************************************
331 * FUNCTION: acpi_ut_valid_acpi_character
333 * PARAMETERS: Character - The character to be examined
335 * RETURN: 1 if Character may appear in a name, else 0
337 * DESCRIPTION: Check for a printable character
339 ******************************************************************************/
342 acpi_ut_valid_acpi_character (
346 ACPI_FUNCTION_ENTRY ();
348 return ((u8) ((character == '_') ||
349 (character >= 'A' && character <= 'Z') ||
350 (character >= '0' && character <= '9')));
354 /*******************************************************************************
356 * FUNCTION: acpi_ut_strtoul64
358 * PARAMETERS: String - Null terminated string
359 * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE
360 * ret_integer - Where the converted integer is returned
362 * RETURN: Status and Converted value
364 * DESCRIPTION: Convert a string into an unsigned value.
365 * NOTE: Does not support Octal strings, not needed.
367 ******************************************************************************/
373 acpi_integer *ret_integer)
376 acpi_integer return_value = 0;
377 acpi_integer quotient;
380 ACPI_FUNCTION_TRACE ("ut_stroul64");
391 return_ACPI_STATUS (AE_BAD_PARAMETER);
394 /* Skip over any white space in the buffer */
396 while (ACPI_IS_SPACE (*string) || *string == '\t') {
401 * If the input parameter Base is zero, then we need to
402 * determine if it is decimal or hexadecimal:
405 if ((*string == '0') &&
406 (ACPI_TOLOWER (*(++string)) == 'x')) {
416 * For hexadecimal base, skip over the leading
417 * 0 or 0x, if they are present.
421 ACPI_TOLOWER (*(++string)) == 'x') {
425 /* Any string left? */
431 /* Main loop: convert the string to a 64-bit integer */
434 if (ACPI_IS_DIGIT (*string)) {
435 /* Convert ASCII 0-9 to Decimal value */
437 this_digit = ((u8) *string) - '0';
440 this_digit = (u8) ACPI_TOUPPER (*string);
441 if (ACPI_IS_UPPER ((char) this_digit)) {
442 /* Convert ASCII Hex char to value */
444 this_digit = this_digit - 'A' + 10;
451 /* Check to see if digit is out of range */
453 if (this_digit >= base) {
457 /* Divide the digit into the correct position */
459 (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX - (acpi_integer) this_digit),
460 base, "ient, NULL);
461 if (return_value > quotient) {
465 return_value *= base;
466 return_value += this_digit;
470 *ret_integer = return_value;
471 return_ACPI_STATUS (AE_OK);
475 /* Base was set/validated above */
478 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
481 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
486 /*******************************************************************************
488 * FUNCTION: acpi_ut_strupr
490 * PARAMETERS: src_string - The source string to convert to
494 * DESCRIPTION: Convert string to uppercase
496 ******************************************************************************/
497 #ifdef ACPI_FUTURE_USAGE
505 ACPI_FUNCTION_ENTRY ();
508 /* Walk entire string, uppercasing the letters */
510 for (string = src_string; *string; ) {
511 *string = (char) ACPI_TOUPPER (*string);
517 #endif /* ACPI_FUTURE_USAGE */
520 /*******************************************************************************
522 * FUNCTION: acpi_ut_mutex_initialize
528 * DESCRIPTION: Create the system mutex objects.
530 ******************************************************************************/
533 acpi_ut_mutex_initialize (
540 ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
544 * Create each of the predefined mutex objects
546 for (i = 0; i < NUM_MUTEX; i++) {
547 status = acpi_ut_create_mutex (i);
548 if (ACPI_FAILURE (status)) {
549 return_ACPI_STATUS (status);
553 status = acpi_os_create_lock (&acpi_gbl_gpe_lock);
554 return_ACPI_STATUS (status);
558 /*******************************************************************************
560 * FUNCTION: acpi_ut_mutex_terminate
566 * DESCRIPTION: Delete all of the system mutex objects.
568 ******************************************************************************/
571 acpi_ut_mutex_terminate (
577 ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
581 * Delete each predefined mutex object
583 for (i = 0; i < NUM_MUTEX; i++) {
584 (void) acpi_ut_delete_mutex (i);
587 acpi_os_delete_lock (acpi_gbl_gpe_lock);
592 /*******************************************************************************
594 * FUNCTION: acpi_ut_create_mutex
596 * PARAMETERS: mutex_iD - ID of the mutex to be created
600 * DESCRIPTION: Create a mutex object.
602 ******************************************************************************/
605 acpi_ut_create_mutex (
606 acpi_mutex_handle mutex_id)
608 acpi_status status = AE_OK;
611 ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id);
614 if (mutex_id > MAX_MUTEX) {
615 return_ACPI_STATUS (AE_BAD_PARAMETER);
618 if (!acpi_gbl_mutex_info[mutex_id].mutex) {
619 status = acpi_os_create_semaphore (1, 1,
620 &acpi_gbl_mutex_info[mutex_id].mutex);
621 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
622 acpi_gbl_mutex_info[mutex_id].use_count = 0;
625 return_ACPI_STATUS (status);
629 /*******************************************************************************
631 * FUNCTION: acpi_ut_delete_mutex
633 * PARAMETERS: mutex_iD - ID of the mutex to be deleted
637 * DESCRIPTION: Delete a mutex object.
639 ******************************************************************************/
642 acpi_ut_delete_mutex (
643 acpi_mutex_handle mutex_id)
648 ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id);
651 if (mutex_id > MAX_MUTEX) {
652 return_ACPI_STATUS (AE_BAD_PARAMETER);
655 status = acpi_os_delete_semaphore (acpi_gbl_mutex_info[mutex_id].mutex);
657 acpi_gbl_mutex_info[mutex_id].mutex = NULL;
658 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
660 return_ACPI_STATUS (status);
664 /*******************************************************************************
666 * FUNCTION: acpi_ut_acquire_mutex
668 * PARAMETERS: mutex_iD - ID of the mutex to be acquired
672 * DESCRIPTION: Acquire a mutex object.
674 ******************************************************************************/
677 acpi_ut_acquire_mutex (
678 acpi_mutex_handle mutex_id)
684 ACPI_FUNCTION_NAME ("ut_acquire_mutex");
687 if (mutex_id > MAX_MUTEX) {
688 return (AE_BAD_PARAMETER);
691 this_thread_id = acpi_os_get_thread_id ();
693 #ifdef ACPI_MUTEX_DEBUG
697 * Mutex debug code, for internal debugging only.
699 * Deadlock prevention. Check if this thread owns any mutexes of value
700 * greater than or equal to this one. If so, the thread has violated
701 * the mutex ordering rule. This indicates a coding error somewhere in
702 * the ACPI subsystem code.
704 for (i = mutex_id; i < MAX_MUTEX; i++) {
705 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
707 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
708 "Mutex [%s] already acquired by this thread [%X]\n",
709 acpi_ut_get_mutex_name (mutex_id), this_thread_id));
711 return (AE_ALREADY_ACQUIRED);
714 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
715 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
716 this_thread_id, acpi_ut_get_mutex_name (i),
717 acpi_ut_get_mutex_name (mutex_id)));
719 return (AE_ACQUIRE_DEADLOCK);
725 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
726 "Thread %X attempting to acquire Mutex [%s]\n",
727 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
729 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex,
730 1, ACPI_WAIT_FOREVER);
731 if (ACPI_SUCCESS (status)) {
732 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
733 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
735 acpi_gbl_mutex_info[mutex_id].use_count++;
736 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id;
739 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n",
740 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
741 acpi_format_exception (status)));
748 /*******************************************************************************
750 * FUNCTION: acpi_ut_release_mutex
752 * PARAMETERS: mutex_iD - ID of the mutex to be released
756 * DESCRIPTION: Release a mutex object.
758 ******************************************************************************/
761 acpi_ut_release_mutex (
762 acpi_mutex_handle mutex_id)
769 ACPI_FUNCTION_NAME ("ut_release_mutex");
772 this_thread_id = acpi_os_get_thread_id ();
773 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
774 "Thread %X releasing Mutex [%s]\n", this_thread_id,
775 acpi_ut_get_mutex_name (mutex_id)));
777 if (mutex_id > MAX_MUTEX) {
778 return (AE_BAD_PARAMETER);
782 * Mutex must be acquired in order to release it!
784 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) {
785 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
786 "Mutex [%s] is not acquired, cannot release\n",
787 acpi_ut_get_mutex_name (mutex_id)));
789 return (AE_NOT_ACQUIRED);
793 * Deadlock prevention. Check if this thread owns any mutexes of value
794 * greater than this one. If so, the thread has violated the mutex
795 * ordering rule. This indicates a coding error somewhere in
796 * the ACPI subsystem code.
798 for (i = mutex_id; i < MAX_MUTEX; i++) {
799 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
804 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
805 "Invalid release order: owns [%s], releasing [%s]\n",
806 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
808 return (AE_RELEASE_DEADLOCK);
812 /* Mark unlocked FIRST */
814 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
816 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
818 if (ACPI_FAILURE (status)) {
819 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n",
820 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
821 acpi_format_exception (status)));
824 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
825 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
832 /*******************************************************************************
834 * FUNCTION: acpi_ut_create_update_state_and_push
836 * PARAMETERS: *Object - Object to be added to the new state
837 * Action - Increment/Decrement
838 * state_list - List the state will be added to
842 * DESCRIPTION: Create a new state and push it
844 ******************************************************************************/
847 acpi_ut_create_update_state_and_push (
848 union acpi_operand_object *object,
850 union acpi_generic_state **state_list)
852 union acpi_generic_state *state;
855 ACPI_FUNCTION_ENTRY ();
858 /* Ignore null objects; these are expected */
864 state = acpi_ut_create_update_state (object, action);
866 return (AE_NO_MEMORY);
869 acpi_ut_push_generic_state (state_list, state);
874 /*******************************************************************************
876 * FUNCTION: acpi_ut_create_pkg_state_and_push
878 * PARAMETERS: *Object - Object to be added to the new state
879 * Action - Increment/Decrement
880 * state_list - List the state will be added to
884 * DESCRIPTION: Create a new state and push it
886 ******************************************************************************/
887 #ifdef ACPI_FUTURE_USAGE
889 acpi_ut_create_pkg_state_and_push (
890 void *internal_object,
891 void *external_object,
893 union acpi_generic_state **state_list)
895 union acpi_generic_state *state;
898 ACPI_FUNCTION_ENTRY ();
901 state = acpi_ut_create_pkg_state (internal_object, external_object, index);
903 return (AE_NO_MEMORY);
906 acpi_ut_push_generic_state (state_list, state);
909 #endif /* ACPI_FUTURE_USAGE */
911 /*******************************************************************************
913 * FUNCTION: acpi_ut_push_generic_state
915 * PARAMETERS: list_head - Head of the state stack
916 * State - State object to push
920 * DESCRIPTION: Push a state object onto a state stack
922 ******************************************************************************/
925 acpi_ut_push_generic_state (
926 union acpi_generic_state **list_head,
927 union acpi_generic_state *state)
929 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
932 /* Push the state object onto the front of the list (stack) */
934 state->common.next = *list_head;
941 /*******************************************************************************
943 * FUNCTION: acpi_ut_pop_generic_state
945 * PARAMETERS: list_head - Head of the state stack
949 * DESCRIPTION: Pop a state object from a state stack
951 ******************************************************************************/
953 union acpi_generic_state *
954 acpi_ut_pop_generic_state (
955 union acpi_generic_state **list_head)
957 union acpi_generic_state *state;
960 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
963 /* Remove the state object at the head of the list (stack) */
967 /* Update the list head */
969 *list_head = state->common.next;
976 /*******************************************************************************
978 * FUNCTION: acpi_ut_create_generic_state
984 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
985 * the global state cache; If none available, create a new one.
987 ******************************************************************************/
989 union acpi_generic_state *
990 acpi_ut_create_generic_state (void)
992 union acpi_generic_state *state;
995 ACPI_FUNCTION_ENTRY ();
998 state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE);
1003 state->common.data_type = ACPI_DESC_TYPE_STATE;
1010 /*******************************************************************************
1012 * FUNCTION: acpi_ut_create_thread_state
1016 * RETURN: Thread State
1018 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1019 * to track per-thread info during method execution
1021 ******************************************************************************/
1023 struct acpi_thread_state *
1024 acpi_ut_create_thread_state (
1027 union acpi_generic_state *state;
1030 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
1033 /* Create the generic state object */
1035 state = acpi_ut_create_generic_state ();
1040 /* Init fields specific to the update struct */
1042 state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
1043 state->thread.thread_id = acpi_os_get_thread_id ();
1045 return_PTR ((struct acpi_thread_state *) state);
1049 /*******************************************************************************
1051 * FUNCTION: acpi_ut_create_update_state
1053 * PARAMETERS: Object - Initial Object to be installed in the
1055 * Action - Update action to be performed
1059 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1060 * to update reference counts and delete complex objects such
1063 ******************************************************************************/
1065 union acpi_generic_state *
1066 acpi_ut_create_update_state (
1067 union acpi_operand_object *object,
1070 union acpi_generic_state *state;
1073 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
1076 /* Create the generic state object */
1078 state = acpi_ut_create_generic_state ();
1083 /* Init fields specific to the update struct */
1085 state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
1086 state->update.object = object;
1087 state->update.value = action;
1093 /*******************************************************************************
1095 * FUNCTION: acpi_ut_create_pkg_state
1097 * PARAMETERS: Object - Initial Object to be installed in the
1099 * Action - Update action to be performed
1103 * DESCRIPTION: Create a "Package State"
1105 ******************************************************************************/
1107 union acpi_generic_state *
1108 acpi_ut_create_pkg_state (
1109 void *internal_object,
1110 void *external_object,
1113 union acpi_generic_state *state;
1116 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
1119 /* Create the generic state object */
1121 state = acpi_ut_create_generic_state ();
1126 /* Init fields specific to the update struct */
1128 state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE;
1129 state->pkg.source_object = (union acpi_operand_object *) internal_object;
1130 state->pkg.dest_object = external_object;
1131 state->pkg.index = index;
1132 state->pkg.num_packages = 1;
1138 /*******************************************************************************
1140 * FUNCTION: acpi_ut_create_control_state
1146 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1147 * to support nested IF/WHILE constructs in the AML.
1149 ******************************************************************************/
1151 union acpi_generic_state *
1152 acpi_ut_create_control_state (
1155 union acpi_generic_state *state;
1158 ACPI_FUNCTION_TRACE ("ut_create_control_state");
1161 /* Create the generic state object */
1163 state = acpi_ut_create_generic_state ();
1168 /* Init fields specific to the control struct */
1170 state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
1171 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1177 /*******************************************************************************
1179 * FUNCTION: acpi_ut_delete_generic_state
1181 * PARAMETERS: State - The state object to be deleted
1185 * DESCRIPTION: Put a state object back into the global state cache. The object
1186 * is not actually freed at this time.
1188 ******************************************************************************/
1191 acpi_ut_delete_generic_state (
1192 union acpi_generic_state *state)
1194 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
1197 acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE, state);
1202 #ifdef ACPI_ENABLE_OBJECT_CACHE
1203 /*******************************************************************************
1205 * FUNCTION: acpi_ut_delete_generic_state_cache
1211 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1214 ******************************************************************************/
1217 acpi_ut_delete_generic_state_cache (
1220 ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
1223 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE);
1229 /*******************************************************************************
1231 * FUNCTION: acpi_ut_walk_package_tree
1233 * PARAMETERS: obj_desc - The Package object on which to resolve refs
1237 * DESCRIPTION: Walk through a package
1239 ******************************************************************************/
1242 acpi_ut_walk_package_tree (
1243 union acpi_operand_object *source_object,
1244 void *target_object,
1245 acpi_pkg_callback walk_callback,
1248 acpi_status status = AE_OK;
1249 union acpi_generic_state *state_list = NULL;
1250 union acpi_generic_state *state;
1252 union acpi_operand_object *this_source_obj;
1255 ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
1258 state = acpi_ut_create_pkg_state (source_object, target_object, 0);
1260 return_ACPI_STATUS (AE_NO_MEMORY);
1264 /* Get one element of the package */
1266 this_index = state->pkg.index;
1267 this_source_obj = (union acpi_operand_object *)
1268 state->pkg.source_object->package.elements[this_index];
1272 * 1) An uninitialized package element. It is completely
1273 * legal to declare a package and leave it uninitialized
1274 * 2) Not an internal object - can be a namespace node instead
1275 * 3) Any type other than a package. Packages are handled in else
1278 if ((!this_source_obj) ||
1279 (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj) != ACPI_DESC_TYPE_OPERAND) ||
1280 (ACPI_GET_OBJECT_TYPE (this_source_obj) != ACPI_TYPE_PACKAGE)) {
1281 status = walk_callback (ACPI_COPY_TYPE_SIMPLE, this_source_obj,
1283 if (ACPI_FAILURE (status)) {
1284 return_ACPI_STATUS (status);
1288 while (state->pkg.index >= state->pkg.source_object->package.count) {
1290 * We've handled all of the objects at this level, This means
1291 * that we have just completed a package. That package may
1292 * have contained one or more packages itself.
1294 * Delete this state and pop the previous state (package).
1296 acpi_ut_delete_generic_state (state);
1297 state = acpi_ut_pop_generic_state (&state_list);
1299 /* Finished when there are no more states */
1303 * We have handled all of the objects in the top level
1304 * package just add the length of the package objects
1307 return_ACPI_STATUS (AE_OK);
1311 * Go back up a level and move the index past the just
1312 * completed package object.
1318 /* This is a subobject of type package */
1320 status = walk_callback (ACPI_COPY_TYPE_PACKAGE, this_source_obj,
1322 if (ACPI_FAILURE (status)) {
1323 return_ACPI_STATUS (status);
1327 * Push the current state and create a new one
1328 * The callback above returned a new target package object.
1330 acpi_ut_push_generic_state (&state_list, state);
1331 state = acpi_ut_create_pkg_state (this_source_obj,
1332 state->pkg.this_target_obj, 0);
1334 return_ACPI_STATUS (AE_NO_MEMORY);
1339 /* We should never get here */
1341 return_ACPI_STATUS (AE_AML_INTERNAL);
1345 /*******************************************************************************
1347 * FUNCTION: acpi_ut_generate_checksum
1349 * PARAMETERS: Buffer - Buffer to be scanned
1350 * Length - number of bytes to examine
1354 * DESCRIPTION: Generate a checksum on a raw buffer
1356 ******************************************************************************/
1359 acpi_ut_generate_checksum (
1364 signed char sum = 0;
1367 for (i = 0; i < length; i++) {
1368 sum = (signed char) (sum + buffer[i]);
1371 return ((u8) (0 - sum));
1375 /*******************************************************************************
1377 * FUNCTION: acpi_ut_get_resource_end_tag
1379 * PARAMETERS: obj_desc - The resource template buffer object
1381 * RETURN: Pointer to the end tag
1383 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1385 ******************************************************************************/
1389 acpi_ut_get_resource_end_tag (
1390 union acpi_operand_object *obj_desc)
1397 buffer = obj_desc->buffer.pointer;
1398 end_buffer = buffer + obj_desc->buffer.length;
1400 while (buffer < end_buffer) {
1401 buffer_byte = *buffer;
1402 if (buffer_byte & ACPI_RDESC_TYPE_MASK) {
1403 /* Large Descriptor - Length is next 2 bytes */
1405 buffer += ((*(buffer+1) | (*(buffer+2) << 8)) + 3);
1408 /* Small Descriptor. End Tag will be found here */
1410 if ((buffer_byte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG) {
1411 /* Found the end tag descriptor, all done. */
1416 /* Length is in the header */
1418 buffer += ((buffer_byte & 0x07) + 1);
1422 /* End tag not found */
1428 /*******************************************************************************
1430 * FUNCTION: acpi_ut_report_error
1432 * PARAMETERS: module_name - Caller's module name (for error output)
1433 * line_number - Caller's line number (for error output)
1434 * component_id - Caller's component ID (for error output)
1435 * Message - Error message to use on failure
1439 * DESCRIPTION: Print error message
1441 ******************************************************************************/
1444 acpi_ut_report_error (
1451 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
1455 /*******************************************************************************
1457 * FUNCTION: acpi_ut_report_warning
1459 * PARAMETERS: module_name - Caller's module name (for error output)
1460 * line_number - Caller's line number (for error output)
1461 * component_id - Caller's component ID (for error output)
1462 * Message - Error message to use on failure
1466 * DESCRIPTION: Print warning message
1468 ******************************************************************************/
1471 acpi_ut_report_warning (
1477 acpi_os_printf ("%8s-%04d: *** Warning: ", module_name, line_number);
1481 /*******************************************************************************
1483 * FUNCTION: acpi_ut_report_info
1485 * PARAMETERS: module_name - Caller's module name (for error output)
1486 * line_number - Caller's line number (for error output)
1487 * component_id - Caller's component ID (for error output)
1488 * Message - Error message to use on failure
1492 * DESCRIPTION: Print information message
1494 ******************************************************************************/
1497 acpi_ut_report_info (
1503 acpi_os_printf ("%8s-%04d: *** Info: ", module_name, line_number);