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");
383 if ((!string
) || !(*string
)) {
395 return_ACPI_STATUS (AE_BAD_PARAMETER
);
398 /* Skip over any white space in the buffer */
400 while (ACPI_IS_SPACE (*string
) || *string
== '\t') {
405 * If the input parameter Base is zero, then we need to
406 * determine if it is decimal or hexadecimal:
409 if ((*string
== '0') &&
410 (ACPI_TOLOWER (*(string
+ 1)) == 'x')) {
420 * For hexadecimal base, skip over the leading
421 * 0 or 0x, if they are present.
425 (ACPI_TOLOWER (*(string
+ 1)) == 'x')) {
429 /* Any string left? */
435 /* Main loop: convert the string to a 64-bit integer */
438 if (ACPI_IS_DIGIT (*string
)) {
439 /* Convert ASCII 0-9 to Decimal value */
441 this_digit
= ((u8
) *string
) - '0';
445 /* Digit is out of range */
450 this_digit
= (u8
) ACPI_TOUPPER (*string
);
451 if (ACPI_IS_XDIGIT ((char) this_digit
)) {
452 /* Convert ASCII Hex char to value */
454 this_digit
= this_digit
- 'A' + 10;
458 * We allow non-hex chars, just stop now, same as end-of-string.
459 * See ACPI spec, string-to-integer conversion.
465 /* Divide the digit into the correct position */
467 (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX
- (acpi_integer
) this_digit
),
468 base
, "ient
, NULL
);
469 if (return_value
> quotient
) {
473 return_value
*= base
;
474 return_value
+= this_digit
;
478 /* All done, normal exit */
480 *ret_integer
= return_value
;
481 return_ACPI_STATUS (AE_OK
);
485 /* Base was set/validated above */
488 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT
);
491 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT
);
496 /*******************************************************************************
498 * FUNCTION: acpi_ut_strupr
500 * PARAMETERS: src_string - The source string to convert to
504 * DESCRIPTION: Convert string to uppercase
506 ******************************************************************************/
507 #ifdef ACPI_FUTURE_USAGE
515 ACPI_FUNCTION_ENTRY ();
518 /* Walk entire string, uppercasing the letters */
520 for (string
= src_string
; *string
; ) {
521 *string
= (char) ACPI_TOUPPER (*string
);
527 #endif /* ACPI_FUTURE_USAGE */
530 /*******************************************************************************
532 * FUNCTION: acpi_ut_mutex_initialize
538 * DESCRIPTION: Create the system mutex objects.
540 ******************************************************************************/
543 acpi_ut_mutex_initialize (
550 ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
554 * Create each of the predefined mutex objects
556 for (i
= 0; i
< NUM_MUTEX
; i
++) {
557 status
= acpi_ut_create_mutex (i
);
558 if (ACPI_FAILURE (status
)) {
559 return_ACPI_STATUS (status
);
563 status
= acpi_os_create_lock (&acpi_gbl_gpe_lock
);
564 return_ACPI_STATUS (status
);
568 /*******************************************************************************
570 * FUNCTION: acpi_ut_mutex_terminate
576 * DESCRIPTION: Delete all of the system mutex objects.
578 ******************************************************************************/
581 acpi_ut_mutex_terminate (
587 ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
591 * Delete each predefined mutex object
593 for (i
= 0; i
< NUM_MUTEX
; i
++) {
594 (void) acpi_ut_delete_mutex (i
);
597 acpi_os_delete_lock (acpi_gbl_gpe_lock
);
602 /*******************************************************************************
604 * FUNCTION: acpi_ut_create_mutex
606 * PARAMETERS: mutex_iD - ID of the mutex to be created
610 * DESCRIPTION: Create a mutex object.
612 ******************************************************************************/
615 acpi_ut_create_mutex (
616 acpi_mutex_handle mutex_id
)
618 acpi_status status
= AE_OK
;
621 ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id
);
624 if (mutex_id
> MAX_MUTEX
) {
625 return_ACPI_STATUS (AE_BAD_PARAMETER
);
628 if (!acpi_gbl_mutex_info
[mutex_id
].mutex
) {
629 status
= acpi_os_create_semaphore (1, 1,
630 &acpi_gbl_mutex_info
[mutex_id
].mutex
);
631 acpi_gbl_mutex_info
[mutex_id
].owner_id
= ACPI_MUTEX_NOT_ACQUIRED
;
632 acpi_gbl_mutex_info
[mutex_id
].use_count
= 0;
635 return_ACPI_STATUS (status
);
639 /*******************************************************************************
641 * FUNCTION: acpi_ut_delete_mutex
643 * PARAMETERS: mutex_iD - ID of the mutex to be deleted
647 * DESCRIPTION: Delete a mutex object.
649 ******************************************************************************/
652 acpi_ut_delete_mutex (
653 acpi_mutex_handle mutex_id
)
658 ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id
);
661 if (mutex_id
> MAX_MUTEX
) {
662 return_ACPI_STATUS (AE_BAD_PARAMETER
);
665 status
= acpi_os_delete_semaphore (acpi_gbl_mutex_info
[mutex_id
].mutex
);
667 acpi_gbl_mutex_info
[mutex_id
].mutex
= NULL
;
668 acpi_gbl_mutex_info
[mutex_id
].owner_id
= ACPI_MUTEX_NOT_ACQUIRED
;
670 return_ACPI_STATUS (status
);
674 /*******************************************************************************
676 * FUNCTION: acpi_ut_acquire_mutex
678 * PARAMETERS: mutex_iD - ID of the mutex to be acquired
682 * DESCRIPTION: Acquire a mutex object.
684 ******************************************************************************/
687 acpi_ut_acquire_mutex (
688 acpi_mutex_handle mutex_id
)
694 ACPI_FUNCTION_NAME ("ut_acquire_mutex");
697 if (mutex_id
> MAX_MUTEX
) {
698 return (AE_BAD_PARAMETER
);
701 this_thread_id
= acpi_os_get_thread_id ();
703 #ifdef ACPI_MUTEX_DEBUG
707 * Mutex debug code, for internal debugging only.
709 * Deadlock prevention. Check if this thread owns any mutexes of value
710 * greater than or equal to this one. If so, the thread has violated
711 * the mutex ordering rule. This indicates a coding error somewhere in
712 * the ACPI subsystem code.
714 for (i
= mutex_id
; i
< MAX_MUTEX
; i
++) {
715 if (acpi_gbl_mutex_info
[i
].owner_id
== this_thread_id
) {
717 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
718 "Mutex [%s] already acquired by this thread [%X]\n",
719 acpi_ut_get_mutex_name (mutex_id
), this_thread_id
));
721 return (AE_ALREADY_ACQUIRED
);
724 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
725 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
726 this_thread_id
, acpi_ut_get_mutex_name (i
),
727 acpi_ut_get_mutex_name (mutex_id
)));
729 return (AE_ACQUIRE_DEADLOCK
);
735 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
,
736 "Thread %X attempting to acquire Mutex [%s]\n",
737 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
)));
739 status
= acpi_os_wait_semaphore (acpi_gbl_mutex_info
[mutex_id
].mutex
,
740 1, ACPI_WAIT_FOREVER
);
741 if (ACPI_SUCCESS (status
)) {
742 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
, "Thread %X acquired Mutex [%s]\n",
743 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
)));
745 acpi_gbl_mutex_info
[mutex_id
].use_count
++;
746 acpi_gbl_mutex_info
[mutex_id
].owner_id
= this_thread_id
;
749 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Thread %X could not acquire Mutex [%s] %s\n",
750 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
),
751 acpi_format_exception (status
)));
758 /*******************************************************************************
760 * FUNCTION: acpi_ut_release_mutex
762 * PARAMETERS: mutex_iD - ID of the mutex to be released
766 * DESCRIPTION: Release a mutex object.
768 ******************************************************************************/
771 acpi_ut_release_mutex (
772 acpi_mutex_handle mutex_id
)
779 ACPI_FUNCTION_NAME ("ut_release_mutex");
782 this_thread_id
= acpi_os_get_thread_id ();
783 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
,
784 "Thread %X releasing Mutex [%s]\n", this_thread_id
,
785 acpi_ut_get_mutex_name (mutex_id
)));
787 if (mutex_id
> MAX_MUTEX
) {
788 return (AE_BAD_PARAMETER
);
792 * Mutex must be acquired in order to release it!
794 if (acpi_gbl_mutex_info
[mutex_id
].owner_id
== ACPI_MUTEX_NOT_ACQUIRED
) {
795 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
796 "Mutex [%s] is not acquired, cannot release\n",
797 acpi_ut_get_mutex_name (mutex_id
)));
799 return (AE_NOT_ACQUIRED
);
803 * Deadlock prevention. Check if this thread owns any mutexes of value
804 * greater than this one. If so, the thread has violated the mutex
805 * ordering rule. This indicates a coding error somewhere in
806 * the ACPI subsystem code.
808 for (i
= mutex_id
; i
< MAX_MUTEX
; i
++) {
809 if (acpi_gbl_mutex_info
[i
].owner_id
== this_thread_id
) {
814 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
815 "Invalid release order: owns [%s], releasing [%s]\n",
816 acpi_ut_get_mutex_name (i
), acpi_ut_get_mutex_name (mutex_id
)));
818 return (AE_RELEASE_DEADLOCK
);
822 /* Mark unlocked FIRST */
824 acpi_gbl_mutex_info
[mutex_id
].owner_id
= ACPI_MUTEX_NOT_ACQUIRED
;
826 status
= acpi_os_signal_semaphore (acpi_gbl_mutex_info
[mutex_id
].mutex
, 1);
828 if (ACPI_FAILURE (status
)) {
829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Thread %X could not release Mutex [%s] %s\n",
830 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
),
831 acpi_format_exception (status
)));
834 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
, "Thread %X released Mutex [%s]\n",
835 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
)));
842 /*******************************************************************************
844 * FUNCTION: acpi_ut_create_update_state_and_push
846 * PARAMETERS: *Object - Object to be added to the new state
847 * Action - Increment/Decrement
848 * state_list - List the state will be added to
852 * DESCRIPTION: Create a new state and push it
854 ******************************************************************************/
857 acpi_ut_create_update_state_and_push (
858 union acpi_operand_object
*object
,
860 union acpi_generic_state
**state_list
)
862 union acpi_generic_state
*state
;
865 ACPI_FUNCTION_ENTRY ();
868 /* Ignore null objects; these are expected */
874 state
= acpi_ut_create_update_state (object
, action
);
876 return (AE_NO_MEMORY
);
879 acpi_ut_push_generic_state (state_list
, state
);
884 /*******************************************************************************
886 * FUNCTION: acpi_ut_create_pkg_state_and_push
888 * PARAMETERS: *Object - Object to be added to the new state
889 * Action - Increment/Decrement
890 * state_list - List the state will be added to
894 * DESCRIPTION: Create a new state and push it
896 ******************************************************************************/
897 #ifdef ACPI_FUTURE_USAGE
899 acpi_ut_create_pkg_state_and_push (
900 void *internal_object
,
901 void *external_object
,
903 union acpi_generic_state
**state_list
)
905 union acpi_generic_state
*state
;
908 ACPI_FUNCTION_ENTRY ();
911 state
= acpi_ut_create_pkg_state (internal_object
, external_object
, index
);
913 return (AE_NO_MEMORY
);
916 acpi_ut_push_generic_state (state_list
, state
);
919 #endif /* ACPI_FUTURE_USAGE */
921 /*******************************************************************************
923 * FUNCTION: acpi_ut_push_generic_state
925 * PARAMETERS: list_head - Head of the state stack
926 * State - State object to push
930 * DESCRIPTION: Push a state object onto a state stack
932 ******************************************************************************/
935 acpi_ut_push_generic_state (
936 union acpi_generic_state
**list_head
,
937 union acpi_generic_state
*state
)
939 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
942 /* Push the state object onto the front of the list (stack) */
944 state
->common
.next
= *list_head
;
951 /*******************************************************************************
953 * FUNCTION: acpi_ut_pop_generic_state
955 * PARAMETERS: list_head - Head of the state stack
959 * DESCRIPTION: Pop a state object from a state stack
961 ******************************************************************************/
963 union acpi_generic_state
*
964 acpi_ut_pop_generic_state (
965 union acpi_generic_state
**list_head
)
967 union acpi_generic_state
*state
;
970 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
973 /* Remove the state object at the head of the list (stack) */
977 /* Update the list head */
979 *list_head
= state
->common
.next
;
986 /*******************************************************************************
988 * FUNCTION: acpi_ut_create_generic_state
994 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
995 * the global state cache; If none available, create a new one.
997 ******************************************************************************/
999 union acpi_generic_state
*
1000 acpi_ut_create_generic_state (void)
1002 union acpi_generic_state
*state
;
1005 ACPI_FUNCTION_ENTRY ();
1008 state
= acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE
);
1013 state
->common
.data_type
= ACPI_DESC_TYPE_STATE
;
1020 /*******************************************************************************
1022 * FUNCTION: acpi_ut_create_thread_state
1026 * RETURN: Thread State
1028 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1029 * to track per-thread info during method execution
1031 ******************************************************************************/
1033 struct acpi_thread_state
*
1034 acpi_ut_create_thread_state (
1037 union acpi_generic_state
*state
;
1040 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
1043 /* Create the generic state object */
1045 state
= acpi_ut_create_generic_state ();
1050 /* Init fields specific to the update struct */
1052 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_THREAD
;
1053 state
->thread
.thread_id
= acpi_os_get_thread_id ();
1055 return_PTR ((struct acpi_thread_state
*) state
);
1059 /*******************************************************************************
1061 * FUNCTION: acpi_ut_create_update_state
1063 * PARAMETERS: Object - Initial Object to be installed in the
1065 * Action - Update action to be performed
1069 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1070 * to update reference counts and delete complex objects such
1073 ******************************************************************************/
1075 union acpi_generic_state
*
1076 acpi_ut_create_update_state (
1077 union acpi_operand_object
*object
,
1080 union acpi_generic_state
*state
;
1083 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object
);
1086 /* Create the generic state object */
1088 state
= acpi_ut_create_generic_state ();
1093 /* Init fields specific to the update struct */
1095 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_UPDATE
;
1096 state
->update
.object
= object
;
1097 state
->update
.value
= action
;
1103 /*******************************************************************************
1105 * FUNCTION: acpi_ut_create_pkg_state
1107 * PARAMETERS: Object - Initial Object to be installed in the
1109 * Action - Update action to be performed
1113 * DESCRIPTION: Create a "Package State"
1115 ******************************************************************************/
1117 union acpi_generic_state
*
1118 acpi_ut_create_pkg_state (
1119 void *internal_object
,
1120 void *external_object
,
1123 union acpi_generic_state
*state
;
1126 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object
);
1129 /* Create the generic state object */
1131 state
= acpi_ut_create_generic_state ();
1136 /* Init fields specific to the update struct */
1138 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_PACKAGE
;
1139 state
->pkg
.source_object
= (union acpi_operand_object
*) internal_object
;
1140 state
->pkg
.dest_object
= external_object
;
1141 state
->pkg
.index
= index
;
1142 state
->pkg
.num_packages
= 1;
1148 /*******************************************************************************
1150 * FUNCTION: acpi_ut_create_control_state
1156 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1157 * to support nested IF/WHILE constructs in the AML.
1159 ******************************************************************************/
1161 union acpi_generic_state
*
1162 acpi_ut_create_control_state (
1165 union acpi_generic_state
*state
;
1168 ACPI_FUNCTION_TRACE ("ut_create_control_state");
1171 /* Create the generic state object */
1173 state
= acpi_ut_create_generic_state ();
1178 /* Init fields specific to the control struct */
1180 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_CONTROL
;
1181 state
->common
.state
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
1187 /*******************************************************************************
1189 * FUNCTION: acpi_ut_delete_generic_state
1191 * PARAMETERS: State - The state object to be deleted
1195 * DESCRIPTION: Put a state object back into the global state cache. The object
1196 * is not actually freed at this time.
1198 ******************************************************************************/
1201 acpi_ut_delete_generic_state (
1202 union acpi_generic_state
*state
)
1204 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
1207 acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE
, state
);
1212 #ifdef ACPI_ENABLE_OBJECT_CACHE
1213 /*******************************************************************************
1215 * FUNCTION: acpi_ut_delete_generic_state_cache
1221 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1224 ******************************************************************************/
1227 acpi_ut_delete_generic_state_cache (
1230 ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
1233 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE
);
1239 /*******************************************************************************
1241 * FUNCTION: acpi_ut_walk_package_tree
1243 * PARAMETERS: obj_desc - The Package object on which to resolve refs
1247 * DESCRIPTION: Walk through a package
1249 ******************************************************************************/
1252 acpi_ut_walk_package_tree (
1253 union acpi_operand_object
*source_object
,
1254 void *target_object
,
1255 acpi_pkg_callback walk_callback
,
1258 acpi_status status
= AE_OK
;
1259 union acpi_generic_state
*state_list
= NULL
;
1260 union acpi_generic_state
*state
;
1262 union acpi_operand_object
*this_source_obj
;
1265 ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
1268 state
= acpi_ut_create_pkg_state (source_object
, target_object
, 0);
1270 return_ACPI_STATUS (AE_NO_MEMORY
);
1274 /* Get one element of the package */
1276 this_index
= state
->pkg
.index
;
1277 this_source_obj
= (union acpi_operand_object
*)
1278 state
->pkg
.source_object
->package
.elements
[this_index
];
1282 * 1) An uninitialized package element. It is completely
1283 * legal to declare a package and leave it uninitialized
1284 * 2) Not an internal object - can be a namespace node instead
1285 * 3) Any type other than a package. Packages are handled in else
1288 if ((!this_source_obj
) ||
1289 (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj
) != ACPI_DESC_TYPE_OPERAND
) ||
1290 (ACPI_GET_OBJECT_TYPE (this_source_obj
) != ACPI_TYPE_PACKAGE
)) {
1291 status
= walk_callback (ACPI_COPY_TYPE_SIMPLE
, this_source_obj
,
1293 if (ACPI_FAILURE (status
)) {
1294 return_ACPI_STATUS (status
);
1298 while (state
->pkg
.index
>= state
->pkg
.source_object
->package
.count
) {
1300 * We've handled all of the objects at this level, This means
1301 * that we have just completed a package. That package may
1302 * have contained one or more packages itself.
1304 * Delete this state and pop the previous state (package).
1306 acpi_ut_delete_generic_state (state
);
1307 state
= acpi_ut_pop_generic_state (&state_list
);
1309 /* Finished when there are no more states */
1313 * We have handled all of the objects in the top level
1314 * package just add the length of the package objects
1317 return_ACPI_STATUS (AE_OK
);
1321 * Go back up a level and move the index past the just
1322 * completed package object.
1328 /* This is a subobject of type package */
1330 status
= walk_callback (ACPI_COPY_TYPE_PACKAGE
, this_source_obj
,
1332 if (ACPI_FAILURE (status
)) {
1333 return_ACPI_STATUS (status
);
1337 * Push the current state and create a new one
1338 * The callback above returned a new target package object.
1340 acpi_ut_push_generic_state (&state_list
, state
);
1341 state
= acpi_ut_create_pkg_state (this_source_obj
,
1342 state
->pkg
.this_target_obj
, 0);
1344 return_ACPI_STATUS (AE_NO_MEMORY
);
1349 /* We should never get here */
1351 return_ACPI_STATUS (AE_AML_INTERNAL
);
1355 /*******************************************************************************
1357 * FUNCTION: acpi_ut_generate_checksum
1359 * PARAMETERS: Buffer - Buffer to be scanned
1360 * Length - number of bytes to examine
1364 * DESCRIPTION: Generate a checksum on a raw buffer
1366 ******************************************************************************/
1369 acpi_ut_generate_checksum (
1374 signed char sum
= 0;
1377 for (i
= 0; i
< length
; i
++) {
1378 sum
= (signed char) (sum
+ buffer
[i
]);
1381 return ((u8
) (0 - sum
));
1385 /*******************************************************************************
1387 * FUNCTION: acpi_ut_get_resource_end_tag
1389 * PARAMETERS: obj_desc - The resource template buffer object
1391 * RETURN: Pointer to the end tag
1393 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1395 ******************************************************************************/
1399 acpi_ut_get_resource_end_tag (
1400 union acpi_operand_object
*obj_desc
)
1407 buffer
= obj_desc
->buffer
.pointer
;
1408 end_buffer
= buffer
+ obj_desc
->buffer
.length
;
1410 while (buffer
< end_buffer
) {
1411 buffer_byte
= *buffer
;
1412 if (buffer_byte
& ACPI_RDESC_TYPE_MASK
) {
1413 /* Large Descriptor - Length is next 2 bytes */
1415 buffer
+= ((*(buffer
+1) | (*(buffer
+2) << 8)) + 3);
1418 /* Small Descriptor. End Tag will be found here */
1420 if ((buffer_byte
& ACPI_RDESC_SMALL_MASK
) == ACPI_RDESC_TYPE_END_TAG
) {
1421 /* Found the end tag descriptor, all done. */
1426 /* Length is in the header */
1428 buffer
+= ((buffer_byte
& 0x07) + 1);
1432 /* End tag not found */
1438 /*******************************************************************************
1440 * FUNCTION: acpi_ut_report_error
1442 * PARAMETERS: module_name - Caller's module name (for error output)
1443 * line_number - Caller's line number (for error output)
1444 * component_id - Caller's component ID (for error output)
1445 * Message - Error message to use on failure
1449 * DESCRIPTION: Print error message
1451 ******************************************************************************/
1454 acpi_ut_report_error (
1461 acpi_os_printf ("%8s-%04d: *** Error: ", module_name
, line_number
);
1465 /*******************************************************************************
1467 * FUNCTION: acpi_ut_report_warning
1469 * PARAMETERS: module_name - Caller's module name (for error output)
1470 * line_number - Caller's line number (for error output)
1471 * component_id - Caller's component ID (for error output)
1472 * Message - Error message to use on failure
1476 * DESCRIPTION: Print warning message
1478 ******************************************************************************/
1481 acpi_ut_report_warning (
1487 acpi_os_printf ("%8s-%04d: *** Warning: ", module_name
, line_number
);
1491 /*******************************************************************************
1493 * FUNCTION: acpi_ut_report_info
1495 * PARAMETERS: module_name - Caller's module name (for error output)
1496 * line_number - Caller's line number (for error output)
1497 * component_id - Caller's component ID (for error output)
1498 * Message - Error message to use on failure
1502 * DESCRIPTION: Print information message
1504 ******************************************************************************/
1507 acpi_ut_report_info (
1513 acpi_os_printf ("%8s-%04d: *** Info: ", module_name
, line_number
);