1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2004, 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 * Terminater - Where a pointer to the terminating byte is returned
360 * Base - Radix of the string
362 * RETURN: Converted value
364 * DESCRIPTION: Convert a string into an unsigned value.
366 ******************************************************************************/
374 acpi_integer
*ret_integer
)
377 acpi_integer return_value
= 0;
378 acpi_status status
= AE_OK
;
379 acpi_integer dividend
;
380 acpi_integer quotient
;
394 * The specified Base parameter is not in the domain of
397 return (AE_BAD_PARAMETER
);
401 * skip over any white space in the buffer:
403 while (ACPI_IS_SPACE (*string
) || *string
== '\t') {
408 * If the input parameter Base is zero, then we need to
409 * determine if it is octal, decimal, or hexadecimal:
412 if (*string
== '0') {
413 if (ACPI_TOLOWER (*(++string
)) == 'x') {
427 * For octal and hexadecimal bases, skip over the leading
428 * 0 or 0x, if they are present.
430 if (base
== 8 && *string
== '0') {
436 ACPI_TOLOWER (*(++string
)) == 'x') {
440 /* Main loop: convert the string to an unsigned long */
443 if (ACPI_IS_DIGIT (*string
)) {
444 index
= ((u8
) *string
) - '0';
447 index
= (u8
) ACPI_TOUPPER (*string
);
448 if (ACPI_IS_UPPER ((char) index
)) {
449 index
= index
- 'A' + 10;
460 /* Check to see if value is out of range: */
462 dividend
= ACPI_INTEGER_MAX
- (acpi_integer
) index
;
463 (void) acpi_ut_short_divide (÷nd
, base
, "ient
, NULL
);
464 if (return_value
> quotient
) {
468 return_value
*= base
;
469 return_value
+= index
;
473 *ret_integer
= return_value
;
480 status
= AE_BAD_OCTAL_CONSTANT
;
484 status
= AE_BAD_DECIMAL_CONSTANT
;
488 status
= AE_BAD_HEX_CONSTANT
;
492 /* Base validated above */
500 /*******************************************************************************
502 * FUNCTION: acpi_ut_strupr
504 * PARAMETERS: src_string - The source string to convert to
508 * DESCRIPTION: Convert string to uppercase
510 ******************************************************************************/
519 ACPI_FUNCTION_ENTRY ();
522 /* Walk entire string, uppercasing the letters */
524 for (string
= src_string
; *string
; ) {
525 *string
= (char) ACPI_TOUPPER (*string
);
533 /*******************************************************************************
535 * FUNCTION: acpi_ut_mutex_initialize
541 * DESCRIPTION: Create the system mutex objects.
543 ******************************************************************************/
546 acpi_ut_mutex_initialize (
553 ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
557 * Create each of the predefined mutex objects
559 for (i
= 0; i
< NUM_MUTEX
; i
++) {
560 status
= acpi_ut_create_mutex (i
);
561 if (ACPI_FAILURE (status
)) {
562 return_ACPI_STATUS (status
);
566 status
= acpi_os_create_lock (&acpi_gbl_gpe_lock
);
567 return_ACPI_STATUS (status
);
571 /*******************************************************************************
573 * FUNCTION: acpi_ut_mutex_terminate
579 * DESCRIPTION: Delete all of the system mutex objects.
581 ******************************************************************************/
584 acpi_ut_mutex_terminate (
590 ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
594 * Delete each predefined mutex object
596 for (i
= 0; i
< NUM_MUTEX
; i
++) {
597 (void) acpi_ut_delete_mutex (i
);
600 acpi_os_delete_lock (acpi_gbl_gpe_lock
);
605 /*******************************************************************************
607 * FUNCTION: acpi_ut_create_mutex
609 * PARAMETERS: mutex_iD - ID of the mutex to be created
613 * DESCRIPTION: Create a mutex object.
615 ******************************************************************************/
618 acpi_ut_create_mutex (
619 acpi_mutex_handle mutex_id
)
621 acpi_status status
= AE_OK
;
624 ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id
);
627 if (mutex_id
> MAX_MUTEX
) {
628 return_ACPI_STATUS (AE_BAD_PARAMETER
);
631 if (!acpi_gbl_mutex_info
[mutex_id
].mutex
) {
632 status
= acpi_os_create_semaphore (1, 1,
633 &acpi_gbl_mutex_info
[mutex_id
].mutex
);
634 acpi_gbl_mutex_info
[mutex_id
].owner_id
= ACPI_MUTEX_NOT_ACQUIRED
;
635 acpi_gbl_mutex_info
[mutex_id
].use_count
= 0;
638 return_ACPI_STATUS (status
);
642 /*******************************************************************************
644 * FUNCTION: acpi_ut_delete_mutex
646 * PARAMETERS: mutex_iD - ID of the mutex to be deleted
650 * DESCRIPTION: Delete a mutex object.
652 ******************************************************************************/
655 acpi_ut_delete_mutex (
656 acpi_mutex_handle mutex_id
)
661 ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id
);
664 if (mutex_id
> MAX_MUTEX
) {
665 return_ACPI_STATUS (AE_BAD_PARAMETER
);
668 status
= acpi_os_delete_semaphore (acpi_gbl_mutex_info
[mutex_id
].mutex
);
670 acpi_gbl_mutex_info
[mutex_id
].mutex
= NULL
;
671 acpi_gbl_mutex_info
[mutex_id
].owner_id
= ACPI_MUTEX_NOT_ACQUIRED
;
673 return_ACPI_STATUS (status
);
677 /*******************************************************************************
679 * FUNCTION: acpi_ut_acquire_mutex
681 * PARAMETERS: mutex_iD - ID of the mutex to be acquired
685 * DESCRIPTION: Acquire a mutex object.
687 ******************************************************************************/
690 acpi_ut_acquire_mutex (
691 acpi_mutex_handle mutex_id
)
698 ACPI_FUNCTION_NAME ("ut_acquire_mutex");
701 if (mutex_id
> MAX_MUTEX
) {
702 return (AE_BAD_PARAMETER
);
705 this_thread_id
= acpi_os_get_thread_id ();
708 * Deadlock prevention. Check if this thread owns any mutexes of value
709 * greater than or equal to this one. If so, the thread has violated
710 * the mutex ordering rule. This indicates a coding error somewhere in
711 * the ACPI subsystem code.
713 for (i
= mutex_id
; i
< MAX_MUTEX
; i
++) {
714 if (acpi_gbl_mutex_info
[i
].owner_id
== this_thread_id
) {
716 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
717 "Mutex [%s] already acquired by this thread [%X]\n",
718 acpi_ut_get_mutex_name (mutex_id
), this_thread_id
));
720 return (AE_ALREADY_ACQUIRED
);
723 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
724 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
725 this_thread_id
, acpi_ut_get_mutex_name (i
),
726 acpi_ut_get_mutex_name (mutex_id
)));
728 return (AE_ACQUIRE_DEADLOCK
);
732 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
,
733 "Thread %X attempting to acquire Mutex [%s]\n",
734 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
)));
736 status
= acpi_os_wait_semaphore (acpi_gbl_mutex_info
[mutex_id
].mutex
,
737 1, ACPI_WAIT_FOREVER
);
738 if (ACPI_SUCCESS (status
)) {
739 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
, "Thread %X acquired Mutex [%s]\n",
740 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
)));
742 acpi_gbl_mutex_info
[mutex_id
].use_count
++;
743 acpi_gbl_mutex_info
[mutex_id
].owner_id
= this_thread_id
;
746 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Thread %X could not acquire Mutex [%s] %s\n",
747 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
),
748 acpi_format_exception (status
)));
755 /*******************************************************************************
757 * FUNCTION: acpi_ut_release_mutex
759 * PARAMETERS: mutex_iD - ID of the mutex to be released
763 * DESCRIPTION: Release a mutex object.
765 ******************************************************************************/
768 acpi_ut_release_mutex (
769 acpi_mutex_handle mutex_id
)
776 ACPI_FUNCTION_NAME ("ut_release_mutex");
779 this_thread_id
= acpi_os_get_thread_id ();
780 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
,
781 "Thread %X releasing Mutex [%s]\n", this_thread_id
,
782 acpi_ut_get_mutex_name (mutex_id
)));
784 if (mutex_id
> MAX_MUTEX
) {
785 return (AE_BAD_PARAMETER
);
789 * Mutex must be acquired in order to release it!
791 if (acpi_gbl_mutex_info
[mutex_id
].owner_id
== ACPI_MUTEX_NOT_ACQUIRED
) {
792 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
793 "Mutex [%s] is not acquired, cannot release\n",
794 acpi_ut_get_mutex_name (mutex_id
)));
796 return (AE_NOT_ACQUIRED
);
800 * Deadlock prevention. Check if this thread owns any mutexes of value
801 * greater than this one. If so, the thread has violated the mutex
802 * ordering rule. This indicates a coding error somewhere in
803 * the ACPI subsystem code.
805 for (i
= mutex_id
; i
< MAX_MUTEX
; i
++) {
806 if (acpi_gbl_mutex_info
[i
].owner_id
== this_thread_id
) {
811 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
812 "Invalid release order: owns [%s], releasing [%s]\n",
813 acpi_ut_get_mutex_name (i
), acpi_ut_get_mutex_name (mutex_id
)));
815 return (AE_RELEASE_DEADLOCK
);
819 /* Mark unlocked FIRST */
821 acpi_gbl_mutex_info
[mutex_id
].owner_id
= ACPI_MUTEX_NOT_ACQUIRED
;
823 status
= acpi_os_signal_semaphore (acpi_gbl_mutex_info
[mutex_id
].mutex
, 1);
825 if (ACPI_FAILURE (status
)) {
826 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Thread %X could not release Mutex [%s] %s\n",
827 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
),
828 acpi_format_exception (status
)));
831 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
, "Thread %X released Mutex [%s]\n",
832 this_thread_id
, acpi_ut_get_mutex_name (mutex_id
)));
839 /*******************************************************************************
841 * FUNCTION: acpi_ut_create_update_state_and_push
843 * PARAMETERS: *Object - Object to be added to the new state
844 * Action - Increment/Decrement
845 * state_list - List the state will be added to
849 * DESCRIPTION: Create a new state and push it
851 ******************************************************************************/
854 acpi_ut_create_update_state_and_push (
855 union acpi_operand_object
*object
,
857 union acpi_generic_state
**state_list
)
859 union acpi_generic_state
*state
;
862 ACPI_FUNCTION_ENTRY ();
865 /* Ignore null objects; these are expected */
871 state
= acpi_ut_create_update_state (object
, action
);
873 return (AE_NO_MEMORY
);
876 acpi_ut_push_generic_state (state_list
, state
);
881 /*******************************************************************************
883 * FUNCTION: acpi_ut_create_pkg_state_and_push
885 * PARAMETERS: *Object - Object to be added to the new state
886 * Action - Increment/Decrement
887 * state_list - List the state will be added to
891 * DESCRIPTION: Create a new state and push it
893 ******************************************************************************/
896 acpi_ut_create_pkg_state_and_push (
897 void *internal_object
,
898 void *external_object
,
900 union acpi_generic_state
**state_list
)
902 union acpi_generic_state
*state
;
905 ACPI_FUNCTION_ENTRY ();
908 state
= acpi_ut_create_pkg_state (internal_object
, external_object
, index
);
910 return (AE_NO_MEMORY
);
913 acpi_ut_push_generic_state (state_list
, state
);
918 /*******************************************************************************
920 * FUNCTION: acpi_ut_push_generic_state
922 * PARAMETERS: list_head - Head of the state stack
923 * State - State object to push
927 * DESCRIPTION: Push a state object onto a state stack
929 ******************************************************************************/
932 acpi_ut_push_generic_state (
933 union acpi_generic_state
**list_head
,
934 union acpi_generic_state
*state
)
936 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
939 /* Push the state object onto the front of the list (stack) */
941 state
->common
.next
= *list_head
;
948 /*******************************************************************************
950 * FUNCTION: acpi_ut_pop_generic_state
952 * PARAMETERS: list_head - Head of the state stack
956 * DESCRIPTION: Pop a state object from a state stack
958 ******************************************************************************/
960 union acpi_generic_state
*
961 acpi_ut_pop_generic_state (
962 union acpi_generic_state
**list_head
)
964 union acpi_generic_state
*state
;
967 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
970 /* Remove the state object at the head of the list (stack) */
974 /* Update the list head */
976 *list_head
= state
->common
.next
;
983 /*******************************************************************************
985 * FUNCTION: acpi_ut_create_generic_state
991 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
992 * the global state cache; If none available, create a new one.
994 ******************************************************************************/
996 union acpi_generic_state
*
997 acpi_ut_create_generic_state (void)
999 union acpi_generic_state
*state
;
1002 ACPI_FUNCTION_ENTRY ();
1005 state
= acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE
);
1010 state
->common
.data_type
= ACPI_DESC_TYPE_STATE
;
1017 /*******************************************************************************
1019 * FUNCTION: acpi_ut_create_thread_state
1023 * RETURN: Thread State
1025 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1026 * to track per-thread info during method execution
1028 ******************************************************************************/
1030 struct acpi_thread_state
*
1031 acpi_ut_create_thread_state (
1034 union acpi_generic_state
*state
;
1037 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
1040 /* Create the generic state object */
1042 state
= acpi_ut_create_generic_state ();
1047 /* Init fields specific to the update struct */
1049 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_THREAD
;
1050 state
->thread
.thread_id
= acpi_os_get_thread_id ();
1052 return_PTR ((struct acpi_thread_state
*) state
);
1056 /*******************************************************************************
1058 * FUNCTION: acpi_ut_create_update_state
1060 * PARAMETERS: Object - Initial Object to be installed in the
1062 * Action - Update action to be performed
1066 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1067 * to update reference counts and delete complex objects such
1070 ******************************************************************************/
1072 union acpi_generic_state
*
1073 acpi_ut_create_update_state (
1074 union acpi_operand_object
*object
,
1077 union acpi_generic_state
*state
;
1080 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object
);
1083 /* Create the generic state object */
1085 state
= acpi_ut_create_generic_state ();
1090 /* Init fields specific to the update struct */
1092 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_UPDATE
;
1093 state
->update
.object
= object
;
1094 state
->update
.value
= action
;
1100 /*******************************************************************************
1102 * FUNCTION: acpi_ut_create_pkg_state
1104 * PARAMETERS: Object - Initial Object to be installed in the
1106 * Action - Update action to be performed
1110 * DESCRIPTION: Create a "Package State"
1112 ******************************************************************************/
1114 union acpi_generic_state
*
1115 acpi_ut_create_pkg_state (
1116 void *internal_object
,
1117 void *external_object
,
1120 union acpi_generic_state
*state
;
1123 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object
);
1126 /* Create the generic state object */
1128 state
= acpi_ut_create_generic_state ();
1133 /* Init fields specific to the update struct */
1135 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_PACKAGE
;
1136 state
->pkg
.source_object
= (union acpi_operand_object
*) internal_object
;
1137 state
->pkg
.dest_object
= external_object
;
1138 state
->pkg
.index
= index
;
1139 state
->pkg
.num_packages
= 1;
1145 /*******************************************************************************
1147 * FUNCTION: acpi_ut_create_control_state
1153 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1154 * to support nested IF/WHILE constructs in the AML.
1156 ******************************************************************************/
1158 union acpi_generic_state
*
1159 acpi_ut_create_control_state (
1162 union acpi_generic_state
*state
;
1165 ACPI_FUNCTION_TRACE ("ut_create_control_state");
1168 /* Create the generic state object */
1170 state
= acpi_ut_create_generic_state ();
1175 /* Init fields specific to the control struct */
1177 state
->common
.data_type
= ACPI_DESC_TYPE_STATE_CONTROL
;
1178 state
->common
.state
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
1184 /*******************************************************************************
1186 * FUNCTION: acpi_ut_delete_generic_state
1188 * PARAMETERS: State - The state object to be deleted
1192 * DESCRIPTION: Put a state object back into the global state cache. The object
1193 * is not actually freed at this time.
1195 ******************************************************************************/
1198 acpi_ut_delete_generic_state (
1199 union acpi_generic_state
*state
)
1201 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
1204 acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE
, state
);
1209 /*******************************************************************************
1211 * FUNCTION: acpi_ut_delete_generic_state_cache
1217 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1220 ******************************************************************************/
1223 acpi_ut_delete_generic_state_cache (
1226 ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
1229 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE
);
1234 /*******************************************************************************
1236 * FUNCTION: acpi_ut_walk_package_tree
1238 * PARAMETERS: obj_desc - The Package object on which to resolve refs
1242 * DESCRIPTION: Walk through a package
1244 ******************************************************************************/
1247 acpi_ut_walk_package_tree (
1248 union acpi_operand_object
*source_object
,
1249 void *target_object
,
1250 acpi_pkg_callback walk_callback
,
1253 acpi_status status
= AE_OK
;
1254 union acpi_generic_state
*state_list
= NULL
;
1255 union acpi_generic_state
*state
;
1257 union acpi_operand_object
*this_source_obj
;
1260 ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
1263 state
= acpi_ut_create_pkg_state (source_object
, target_object
, 0);
1265 return_ACPI_STATUS (AE_NO_MEMORY
);
1269 /* Get one element of the package */
1271 this_index
= state
->pkg
.index
;
1272 this_source_obj
= (union acpi_operand_object
*)
1273 state
->pkg
.source_object
->package
.elements
[this_index
];
1277 * 1) An uninitialized package element. It is completely
1278 * legal to declare a package and leave it uninitialized
1279 * 2) Not an internal object - can be a namespace node instead
1280 * 3) Any type other than a package. Packages are handled in else
1283 if ((!this_source_obj
) ||
1284 (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj
) != ACPI_DESC_TYPE_OPERAND
) ||
1285 (ACPI_GET_OBJECT_TYPE (this_source_obj
) != ACPI_TYPE_PACKAGE
)) {
1286 status
= walk_callback (ACPI_COPY_TYPE_SIMPLE
, this_source_obj
,
1288 if (ACPI_FAILURE (status
)) {
1289 return_ACPI_STATUS (status
);
1293 while (state
->pkg
.index
>= state
->pkg
.source_object
->package
.count
) {
1295 * We've handled all of the objects at this level, This means
1296 * that we have just completed a package. That package may
1297 * have contained one or more packages itself.
1299 * Delete this state and pop the previous state (package).
1301 acpi_ut_delete_generic_state (state
);
1302 state
= acpi_ut_pop_generic_state (&state_list
);
1304 /* Finished when there are no more states */
1308 * We have handled all of the objects in the top level
1309 * package just add the length of the package objects
1312 return_ACPI_STATUS (AE_OK
);
1316 * Go back up a level and move the index past the just
1317 * completed package object.
1323 /* This is a subobject of type package */
1325 status
= walk_callback (ACPI_COPY_TYPE_PACKAGE
, this_source_obj
,
1327 if (ACPI_FAILURE (status
)) {
1328 return_ACPI_STATUS (status
);
1332 * Push the current state and create a new one
1333 * The callback above returned a new target package object.
1335 acpi_ut_push_generic_state (&state_list
, state
);
1336 state
= acpi_ut_create_pkg_state (this_source_obj
,
1337 state
->pkg
.this_target_obj
, 0);
1339 return_ACPI_STATUS (AE_NO_MEMORY
);
1344 /* We should never get here */
1346 return_ACPI_STATUS (AE_AML_INTERNAL
);
1350 /*******************************************************************************
1352 * FUNCTION: acpi_ut_generate_checksum
1354 * PARAMETERS: Buffer - Buffer to be scanned
1355 * Length - number of bytes to examine
1359 * DESCRIPTION: Generate a checksum on a raw buffer
1361 ******************************************************************************/
1364 acpi_ut_generate_checksum (
1369 signed char sum
= 0;
1372 for (i
= 0; i
< length
; i
++) {
1373 sum
= (signed char) (sum
+ buffer
[i
]);
1376 return ((u8
) (0 - sum
));
1380 /*******************************************************************************
1382 * FUNCTION: acpi_ut_get_resource_end_tag
1384 * PARAMETERS: obj_desc - The resource template buffer object
1386 * RETURN: Pointer to the end tag
1388 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1390 ******************************************************************************/
1394 acpi_ut_get_resource_end_tag (
1395 union acpi_operand_object
*obj_desc
)
1402 buffer
= obj_desc
->buffer
.pointer
;
1403 end_buffer
= buffer
+ obj_desc
->buffer
.length
;
1405 while (buffer
< end_buffer
) {
1406 buffer_byte
= *buffer
;
1407 if (buffer_byte
& ACPI_RDESC_TYPE_MASK
) {
1408 /* Large Descriptor - Length is next 2 bytes */
1410 buffer
+= ((*(buffer
+1) | (*(buffer
+2) << 8)) + 3);
1413 /* Small Descriptor. End Tag will be found here */
1415 if ((buffer_byte
& ACPI_RDESC_SMALL_MASK
) == ACPI_RDESC_TYPE_END_TAG
) {
1416 /* Found the end tag descriptor, all done. */
1421 /* Length is in the header */
1423 buffer
+= ((buffer_byte
& 0x07) + 1);
1427 /* End tag not found */
1433 /*******************************************************************************
1435 * FUNCTION: acpi_ut_report_error
1437 * PARAMETERS: module_name - Caller's module name (for error output)
1438 * line_number - Caller's line number (for error output)
1439 * component_id - Caller's component ID (for error output)
1440 * Message - Error message to use on failure
1444 * DESCRIPTION: Print error message
1446 ******************************************************************************/
1449 acpi_ut_report_error (
1456 acpi_os_printf ("%8s-%04d: *** Error: ", module_name
, line_number
);
1460 /*******************************************************************************
1462 * FUNCTION: acpi_ut_report_warning
1464 * PARAMETERS: module_name - Caller's module name (for error output)
1465 * line_number - Caller's line number (for error output)
1466 * component_id - Caller's component ID (for error output)
1467 * Message - Error message to use on failure
1471 * DESCRIPTION: Print warning message
1473 ******************************************************************************/
1476 acpi_ut_report_warning (
1482 acpi_os_printf ("%8s-%04d: *** Warning: ", module_name
, line_number
);
1486 /*******************************************************************************
1488 * FUNCTION: acpi_ut_report_info
1490 * PARAMETERS: module_name - Caller's module name (for error output)
1491 * line_number - Caller's line number (for error output)
1492 * component_id - Caller's component ID (for error output)
1493 * Message - Error message to use on failure
1497 * DESCRIPTION: Print information message
1499 ******************************************************************************/
1502 acpi_ut_report_info (
1508 acpi_os_printf ("%8s-%04d: *** Info: ", module_name
, line_number
);