1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
121 #include "acnamesp.h"
124 #define _COMPONENT ACPI_UTILITIES
125 ACPI_MODULE_NAME ("utmisc")
128 /*******************************************************************************
130 * FUNCTION: AcpiUtPrintString
132 * PARAMETERS: String - Null terminated ASCII string
136 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
139 ******************************************************************************/
151 AcpiOsPrintf ("<\"NULL STRING PTR\">");
156 for (i = 0; String[i] && (i < MaxLength); i++)
158 /* Escape sequences */
163 AcpiOsPrintf ("\\a"); /* BELL */
167 AcpiOsPrintf ("\\b"); /* BACKSPACE */
171 AcpiOsPrintf ("\\f"); /* FORMFEED */
175 AcpiOsPrintf ("\\n"); /* LINEFEED */
179 AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
183 AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
187 AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
190 case '\'': /* Single Quote */
191 case '\"': /* Double Quote */
192 case '\\': /* Backslash */
193 AcpiOsPrintf ("\\%c", (int) String[i]);
198 /* Check for printable character or hex escape */
200 if (ACPI_IS_PRINT (String[i]))
202 /* This is a normal character */
204 AcpiOsPrintf ("%c", (int) String[i]);
208 /* All others will be Hex escapes */
210 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
217 if (i == MaxLength && String[i])
219 AcpiOsPrintf ("...");
224 /*******************************************************************************
226 * FUNCTION: AcpiUtDwordByteSwap
228 * PARAMETERS: Value - Value to be converted
230 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
232 ******************************************************************************/
235 AcpiUtDwordByteSwap (
251 ACPI_FUNCTION_ENTRY ();
256 Out.Bytes[0] = In.Bytes[3];
257 Out.Bytes[1] = In.Bytes[2];
258 Out.Bytes[2] = In.Bytes[1];
259 Out.Bytes[3] = In.Bytes[0];
265 /*******************************************************************************
267 * FUNCTION: AcpiUtSetIntegerWidth
269 * PARAMETERS: Revision From DSDT header
273 * DESCRIPTION: Set the global integer bit width based upon the revision
274 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
275 * For Revision 2 and above, Integers are 64 bits. Yes, this
276 * makes a difference.
278 ******************************************************************************/
281 AcpiUtSetIntegerWidth (
287 AcpiGbl_IntegerBitWidth = 32;
288 AcpiGbl_IntegerNybbleWidth = 8;
289 AcpiGbl_IntegerByteWidth = 4;
293 AcpiGbl_IntegerBitWidth = 64;
294 AcpiGbl_IntegerNybbleWidth = 16;
295 AcpiGbl_IntegerByteWidth = 8;
300 #ifdef ACPI_DEBUG_OUTPUT
301 /*******************************************************************************
303 * FUNCTION: AcpiUtDisplayInitPathname
305 * PARAMETERS: ObjHandle - Handle whose pathname will be displayed
306 * Path - Additional path string to be appended.
307 * (NULL if no extra path)
309 * RETURN: ACPI_STATUS
311 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
313 ******************************************************************************/
316 AcpiUtDisplayInitPathname (
318 ACPI_NAMESPACE_NODE *ObjHandle,
325 ACPI_FUNCTION_ENTRY ();
328 /* Only print the path if the appropriate debug level is enabled */
330 if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
335 /* Get the full pathname to the node */
337 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
338 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
339 if (ACPI_FAILURE (Status))
344 /* Print what we're doing */
348 case ACPI_TYPE_METHOD:
349 AcpiOsPrintf ("Executing ");
353 AcpiOsPrintf ("Initializing ");
357 /* Print the object type and pathname */
359 AcpiOsPrintf ("%-12s %s", AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
361 /* Extra path is used to append names like _STA, _INI, etc. */
365 AcpiOsPrintf (".%s", Path);
369 ACPI_MEM_FREE (Buffer.Pointer);
374 /*******************************************************************************
376 * FUNCTION: AcpiUtValidAcpiName
378 * PARAMETERS: Character - The character to be examined
380 * RETURN: 1 if Character may appear in a name, else 0
382 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
383 * 1) Upper case alpha
387 ******************************************************************************/
390 AcpiUtValidAcpiName (
393 char *NamePtr = (char *) &Name;
398 ACPI_FUNCTION_ENTRY ();
401 for (i = 0; i < ACPI_NAME_SIZE; i++)
403 Character = *NamePtr;
406 if (!((Character == '_') ||
407 (Character >= 'A' && Character <= 'Z') ||
408 (Character >= '0' && Character <= '9')))
418 /*******************************************************************************
420 * FUNCTION: AcpiUtValidAcpiCharacter
422 * PARAMETERS: Character - The character to be examined
424 * RETURN: 1 if Character may appear in a name, else 0
426 * DESCRIPTION: Check for a printable character
428 ******************************************************************************/
431 AcpiUtValidAcpiCharacter (
435 ACPI_FUNCTION_ENTRY ();
437 return ((BOOLEAN) ((Character == '_') ||
438 (Character >= 'A' && Character <= 'Z') ||
439 (Character >= '0' && Character <= '9')));
443 /*******************************************************************************
445 * FUNCTION: AcpiUtStrtoul64
447 * PARAMETERS: String - Null terminated string
448 * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE
449 * RetInteger - Where the converted integer is returned
451 * RETURN: Status and Converted value
453 * DESCRIPTION: Convert a string into an unsigned value.
454 * NOTE: Does not support Octal strings, not needed.
456 ******************************************************************************/
462 ACPI_INTEGER *RetInteger)
465 ACPI_INTEGER ReturnValue = 0;
466 ACPI_INTEGER Quotient;
469 ACPI_FUNCTION_TRACE ("UtStroul64");
481 return_ACPI_STATUS (AE_BAD_PARAMETER);
484 /* Skip over any white space in the buffer */
486 while (ACPI_IS_SPACE (*String) || *String == '\t')
492 * If the input parameter Base is zero, then we need to
493 * determine if it is decimal or hexadecimal:
497 if ((*String == '0') &&
498 (ACPI_TOLOWER (*(++String)) == 'x'))
510 * For hexadecimal base, skip over the leading
511 * 0 or 0x, if they are present.
515 ACPI_TOLOWER (*(++String)) == 'x')
520 /* Any string left? */
527 /* Main loop: convert the string to a 64-bit integer */
531 if (ACPI_IS_DIGIT (*String))
533 /* Convert ASCII 0-9 to Decimal value */
535 ThisDigit = ((UINT8) *String) - '0';
539 ThisDigit = (UINT8) ACPI_TOUPPER (*String);
540 if (ACPI_IS_UPPER ((char) ThisDigit))
542 /* Convert ASCII Hex char to value */
544 ThisDigit = ThisDigit - 'A' + 10;
552 /* Check to see if digit is out of range */
554 if (ThisDigit >= Base)
559 /* Divide the digit into the correct position */
561 (void) AcpiUtShortDivide ((ACPI_INTEGER_MAX - (ACPI_INTEGER) ThisDigit),
562 Base, &Quotient, NULL);
563 if (ReturnValue > Quotient)
569 ReturnValue += ThisDigit;
573 *RetInteger = ReturnValue;
574 return_ACPI_STATUS (AE_OK);
578 /* Base was set/validated above */
582 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
586 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
591 /*******************************************************************************
593 * FUNCTION: AcpiUtStrupr
595 * PARAMETERS: SrcString - The source string to convert to
599 * DESCRIPTION: Convert string to uppercase
601 ******************************************************************************/
610 ACPI_FUNCTION_ENTRY ();
613 /* Walk entire string, uppercasing the letters */
615 for (String = SrcString; *String; )
617 *String = (char) ACPI_TOUPPER (*String);
625 /*******************************************************************************
627 * FUNCTION: AcpiUtMutexInitialize
633 * DESCRIPTION: Create the system mutex objects.
635 ******************************************************************************/
638 AcpiUtMutexInitialize (
645 ACPI_FUNCTION_TRACE ("UtMutexInitialize");
649 * Create each of the predefined mutex objects
651 for (i = 0; i < NUM_MUTEX; i++)
653 Status = AcpiUtCreateMutex (i);
654 if (ACPI_FAILURE (Status))
656 return_ACPI_STATUS (Status);
660 Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
661 return_ACPI_STATUS (Status);
665 /*******************************************************************************
667 * FUNCTION: AcpiUtMutexTerminate
673 * DESCRIPTION: Delete all of the system mutex objects.
675 ******************************************************************************/
678 AcpiUtMutexTerminate (
684 ACPI_FUNCTION_TRACE ("UtMutexTerminate");
688 * Delete each predefined mutex object
690 for (i = 0; i < NUM_MUTEX; i++)
692 (void) AcpiUtDeleteMutex (i);
695 AcpiOsDeleteLock (AcpiGbl_GpeLock);
700 /*******************************************************************************
702 * FUNCTION: AcpiUtCreateMutex
704 * PARAMETERS: MutexID - ID of the mutex to be created
708 * DESCRIPTION: Create a mutex object.
710 ******************************************************************************/
714 ACPI_MUTEX_HANDLE MutexId)
716 ACPI_STATUS Status = AE_OK;
719 ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId);
722 if (MutexId > MAX_MUTEX)
724 return_ACPI_STATUS (AE_BAD_PARAMETER);
727 if (!AcpiGbl_MutexInfo[MutexId].Mutex)
729 Status = AcpiOsCreateSemaphore (1, 1,
730 &AcpiGbl_MutexInfo[MutexId].Mutex);
731 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
732 AcpiGbl_MutexInfo[MutexId].UseCount = 0;
735 return_ACPI_STATUS (Status);
739 /*******************************************************************************
741 * FUNCTION: AcpiUtDeleteMutex
743 * PARAMETERS: MutexID - ID of the mutex to be deleted
747 * DESCRIPTION: Delete a mutex object.
749 ******************************************************************************/
753 ACPI_MUTEX_HANDLE MutexId)
758 ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId);
761 if (MutexId > MAX_MUTEX)
763 return_ACPI_STATUS (AE_BAD_PARAMETER);
766 Status = AcpiOsDeleteSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex);
768 AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
769 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
771 return_ACPI_STATUS (Status);
775 /*******************************************************************************
777 * FUNCTION: AcpiUtAcquireMutex
779 * PARAMETERS: MutexID - ID of the mutex to be acquired
783 * DESCRIPTION: Acquire a mutex object.
785 ******************************************************************************/
789 ACPI_MUTEX_HANDLE MutexId)
795 ACPI_FUNCTION_NAME ("UtAcquireMutex");
798 if (MutexId > MAX_MUTEX)
800 return (AE_BAD_PARAMETER);
803 ThisThreadId = AcpiOsGetThreadId ();
805 #ifdef ACPI_MUTEX_DEBUG
809 * Mutex debug code, for internal debugging only.
811 * Deadlock prevention. Check if this thread owns any mutexes of value
812 * greater than or equal to this one. If so, the thread has violated
813 * the mutex ordering rule. This indicates a coding error somewhere in
814 * the ACPI subsystem code.
816 for (i = MutexId; i < MAX_MUTEX; i++)
818 if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
822 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
823 "Mutex [%s] already acquired by this thread [%X]\n",
824 AcpiUtGetMutexName (MutexId), ThisThreadId));
826 return (AE_ALREADY_ACQUIRED);
829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
830 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
831 ThisThreadId, AcpiUtGetMutexName (i),
832 AcpiUtGetMutexName (MutexId)));
834 return (AE_ACQUIRE_DEADLOCK);
840 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
841 "Thread %X attempting to acquire Mutex [%s]\n",
842 ThisThreadId, AcpiUtGetMutexName (MutexId)));
844 Status = AcpiOsWaitSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex,
845 1, ACPI_WAIT_FOREVER);
846 if (ACPI_SUCCESS (Status))
848 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
849 ThisThreadId, AcpiUtGetMutexName (MutexId)));
851 AcpiGbl_MutexInfo[MutexId].UseCount++;
852 AcpiGbl_MutexInfo[MutexId].OwnerId = ThisThreadId;
856 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n",
857 ThisThreadId, AcpiUtGetMutexName (MutexId),
858 AcpiFormatException (Status)));
865 /*******************************************************************************
867 * FUNCTION: AcpiUtReleaseMutex
869 * PARAMETERS: MutexID - ID of the mutex to be released
873 * DESCRIPTION: Release a mutex object.
875 ******************************************************************************/
879 ACPI_MUTEX_HANDLE MutexId)
886 ACPI_FUNCTION_NAME ("UtReleaseMutex");
889 ThisThreadId = AcpiOsGetThreadId ();
890 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
891 "Thread %X releasing Mutex [%s]\n", ThisThreadId,
892 AcpiUtGetMutexName (MutexId)));
894 if (MutexId > MAX_MUTEX)
896 return (AE_BAD_PARAMETER);
900 * Mutex must be acquired in order to release it!
902 if (AcpiGbl_MutexInfo[MutexId].OwnerId == ACPI_MUTEX_NOT_ACQUIRED)
904 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
905 "Mutex [%s] is not acquired, cannot release\n",
906 AcpiUtGetMutexName (MutexId)));
908 return (AE_NOT_ACQUIRED);
912 * Deadlock prevention. Check if this thread owns any mutexes of value
913 * greater than this one. If so, the thread has violated the mutex
914 * ordering rule. This indicates a coding error somewhere in
915 * the ACPI subsystem code.
917 for (i = MutexId; i < MAX_MUTEX; i++)
919 if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
926 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
927 "Invalid release order: owns [%s], releasing [%s]\n",
928 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
930 return (AE_RELEASE_DEADLOCK);
934 /* Mark unlocked FIRST */
936 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
938 Status = AcpiOsSignalSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex, 1);
940 if (ACPI_FAILURE (Status))
942 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n",
943 ThisThreadId, AcpiUtGetMutexName (MutexId),
944 AcpiFormatException (Status)));
948 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
949 ThisThreadId, AcpiUtGetMutexName (MutexId)));
956 /*******************************************************************************
958 * FUNCTION: AcpiUtCreateUpdateStateAndPush
960 * PARAMETERS: *Object - Object to be added to the new state
961 * Action - Increment/Decrement
962 * StateList - List the state will be added to
966 * DESCRIPTION: Create a new state and push it
968 ******************************************************************************/
971 AcpiUtCreateUpdateStateAndPush (
972 ACPI_OPERAND_OBJECT *Object,
974 ACPI_GENERIC_STATE **StateList)
976 ACPI_GENERIC_STATE *State;
979 ACPI_FUNCTION_ENTRY ();
982 /* Ignore null objects; these are expected */
989 State = AcpiUtCreateUpdateState (Object, Action);
992 return (AE_NO_MEMORY);
995 AcpiUtPushGenericState (StateList, State);
1000 /*******************************************************************************
1002 * FUNCTION: AcpiUtCreatePkgStateAndPush
1004 * PARAMETERS: *Object - Object to be added to the new state
1005 * Action - Increment/Decrement
1006 * StateList - List the state will be added to
1010 * DESCRIPTION: Create a new state and push it
1012 ******************************************************************************/
1015 AcpiUtCreatePkgStateAndPush (
1016 void *InternalObject,
1017 void *ExternalObject,
1019 ACPI_GENERIC_STATE **StateList)
1021 ACPI_GENERIC_STATE *State;
1024 ACPI_FUNCTION_ENTRY ();
1027 State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
1030 return (AE_NO_MEMORY);
1033 AcpiUtPushGenericState (StateList, State);
1038 /*******************************************************************************
1040 * FUNCTION: AcpiUtPushGenericState
1042 * PARAMETERS: ListHead - Head of the state stack
1043 * State - State object to push
1047 * DESCRIPTION: Push a state object onto a state stack
1049 ******************************************************************************/
1052 AcpiUtPushGenericState (
1053 ACPI_GENERIC_STATE **ListHead,
1054 ACPI_GENERIC_STATE *State)
1056 ACPI_FUNCTION_TRACE ("UtPushGenericState");
1059 /* Push the state object onto the front of the list (stack) */
1061 State->Common.Next = *ListHead;
1068 /*******************************************************************************
1070 * FUNCTION: AcpiUtPopGenericState
1072 * PARAMETERS: ListHead - Head of the state stack
1076 * DESCRIPTION: Pop a state object from a state stack
1078 ******************************************************************************/
1080 ACPI_GENERIC_STATE *
1081 AcpiUtPopGenericState (
1082 ACPI_GENERIC_STATE **ListHead)
1084 ACPI_GENERIC_STATE *State;
1087 ACPI_FUNCTION_TRACE ("UtPopGenericState");
1090 /* Remove the state object at the head of the list (stack) */
1095 /* Update the list head */
1097 *ListHead = State->Common.Next;
1104 /*******************************************************************************
1106 * FUNCTION: AcpiUtCreateGenericState
1112 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1113 * the global state cache; If none available, create a new one.
1115 ******************************************************************************/
1117 ACPI_GENERIC_STATE *
1118 AcpiUtCreateGenericState (void)
1120 ACPI_GENERIC_STATE *State;
1123 ACPI_FUNCTION_ENTRY ();
1126 State = AcpiUtAcquireFromCache (ACPI_MEM_LIST_STATE);
1132 State->Common.DataType = ACPI_DESC_TYPE_STATE;
1139 /*******************************************************************************
1141 * FUNCTION: AcpiUtCreateThreadState
1145 * RETURN: Thread State
1147 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1148 * to track per-thread info during method execution
1150 ******************************************************************************/
1153 AcpiUtCreateThreadState (
1156 ACPI_GENERIC_STATE *State;
1159 ACPI_FUNCTION_TRACE ("UtCreateThreadState");
1162 /* Create the generic state object */
1164 State = AcpiUtCreateGenericState ();
1170 /* Init fields specific to the update struct */
1172 State->Common.DataType = ACPI_DESC_TYPE_STATE_THREAD;
1173 State->Thread.ThreadId = AcpiOsGetThreadId ();
1175 return_PTR ((ACPI_THREAD_STATE *) State);
1179 /*******************************************************************************
1181 * FUNCTION: AcpiUtCreateUpdateState
1183 * PARAMETERS: Object - Initial Object to be installed in the
1185 * Action - Update action to be performed
1189 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1190 * to update reference counts and delete complex objects such
1193 ******************************************************************************/
1195 ACPI_GENERIC_STATE *
1196 AcpiUtCreateUpdateState (
1197 ACPI_OPERAND_OBJECT *Object,
1200 ACPI_GENERIC_STATE *State;
1203 ACPI_FUNCTION_TRACE_PTR ("UtCreateUpdateState", Object);
1206 /* Create the generic state object */
1208 State = AcpiUtCreateGenericState ();
1214 /* Init fields specific to the update struct */
1216 State->Common.DataType = ACPI_DESC_TYPE_STATE_UPDATE;
1217 State->Update.Object = Object;
1218 State->Update.Value = Action;
1224 /*******************************************************************************
1226 * FUNCTION: AcpiUtCreatePkgState
1228 * PARAMETERS: Object - Initial Object to be installed in the
1230 * Action - Update action to be performed
1234 * DESCRIPTION: Create a "Package State"
1236 ******************************************************************************/
1238 ACPI_GENERIC_STATE *
1239 AcpiUtCreatePkgState (
1240 void *InternalObject,
1241 void *ExternalObject,
1244 ACPI_GENERIC_STATE *State;
1247 ACPI_FUNCTION_TRACE_PTR ("UtCreatePkgState", InternalObject);
1250 /* Create the generic state object */
1252 State = AcpiUtCreateGenericState ();
1258 /* Init fields specific to the update struct */
1260 State->Common.DataType = ACPI_DESC_TYPE_STATE_PACKAGE;
1261 State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
1262 State->Pkg.DestObject = ExternalObject;
1263 State->Pkg.Index = Index;
1264 State->Pkg.NumPackages = 1;
1270 /*******************************************************************************
1272 * FUNCTION: AcpiUtCreateControlState
1278 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1279 * to support nested IF/WHILE constructs in the AML.
1281 ******************************************************************************/
1283 ACPI_GENERIC_STATE *
1284 AcpiUtCreateControlState (
1287 ACPI_GENERIC_STATE *State;
1290 ACPI_FUNCTION_TRACE ("UtCreateControlState");
1293 /* Create the generic state object */
1295 State = AcpiUtCreateGenericState ();
1301 /* Init fields specific to the control struct */
1303 State->Common.DataType = ACPI_DESC_TYPE_STATE_CONTROL;
1304 State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1310 /*******************************************************************************
1312 * FUNCTION: AcpiUtDeleteGenericState
1314 * PARAMETERS: State - The state object to be deleted
1318 * DESCRIPTION: Put a state object back into the global state cache. The object
1319 * is not actually freed at this time.
1321 ******************************************************************************/
1324 AcpiUtDeleteGenericState (
1325 ACPI_GENERIC_STATE *State)
1327 ACPI_FUNCTION_TRACE ("UtDeleteGenericState");
1330 AcpiUtReleaseToCache (ACPI_MEM_LIST_STATE, State);
1335 #ifdef ACPI_ENABLE_OBJECT_CACHE
1336 /*******************************************************************************
1338 * FUNCTION: AcpiUtDeleteGenericStateCache
1344 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1347 ******************************************************************************/
1350 AcpiUtDeleteGenericStateCache (
1353 ACPI_FUNCTION_TRACE ("UtDeleteGenericStateCache");
1356 AcpiUtDeleteGenericCache (ACPI_MEM_LIST_STATE);
1362 /*******************************************************************************
1364 * FUNCTION: AcpiUtWalkPackageTree
1366 * PARAMETERS: ObjDesc - The Package object on which to resolve refs
1370 * DESCRIPTION: Walk through a package
1372 ******************************************************************************/
1375 AcpiUtWalkPackageTree (
1376 ACPI_OPERAND_OBJECT *SourceObject,
1378 ACPI_PKG_CALLBACK WalkCallback,
1381 ACPI_STATUS Status = AE_OK;
1382 ACPI_GENERIC_STATE *StateList = NULL;
1383 ACPI_GENERIC_STATE *State;
1385 ACPI_OPERAND_OBJECT *ThisSourceObj;
1388 ACPI_FUNCTION_TRACE ("UtWalkPackageTree");
1391 State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1394 return_ACPI_STATUS (AE_NO_MEMORY);
1399 /* Get one element of the package */
1401 ThisIndex = State->Pkg.Index;
1402 ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1403 State->Pkg.SourceObject->Package.Elements[ThisIndex];
1407 * 1) An uninitialized package element. It is completely
1408 * legal to declare a package and leave it uninitialized
1409 * 2) Not an internal object - can be a namespace node instead
1410 * 3) Any type other than a package. Packages are handled in else
1413 if ((!ThisSourceObj) ||
1414 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1415 (ACPI_GET_OBJECT_TYPE (ThisSourceObj) != ACPI_TYPE_PACKAGE))
1417 Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1419 if (ACPI_FAILURE (Status))
1421 return_ACPI_STATUS (Status);
1425 while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1428 * We've handled all of the objects at this level, This means
1429 * that we have just completed a package. That package may
1430 * have contained one or more packages itself.
1432 * Delete this state and pop the previous state (package).
1434 AcpiUtDeleteGenericState (State);
1435 State = AcpiUtPopGenericState (&StateList);
1437 /* Finished when there are no more states */
1442 * We have handled all of the objects in the top level
1443 * package just add the length of the package objects
1446 return_ACPI_STATUS (AE_OK);
1450 * Go back up a level and move the index past the just
1451 * completed package object.
1458 /* This is a subobject of type package */
1460 Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1462 if (ACPI_FAILURE (Status))
1464 return_ACPI_STATUS (Status);
1468 * Push the current state and create a new one
1469 * The callback above returned a new target package object.
1471 AcpiUtPushGenericState (&StateList, State);
1472 State = AcpiUtCreatePkgState (ThisSourceObj,
1473 State->Pkg.ThisTargetObj, 0);
1476 return_ACPI_STATUS (AE_NO_MEMORY);
1481 /* We should never get here */
1483 return_ACPI_STATUS (AE_AML_INTERNAL);
1487 /*******************************************************************************
1489 * FUNCTION: AcpiUtGenerateChecksum
1491 * PARAMETERS: Buffer - Buffer to be scanned
1492 * Length - number of bytes to examine
1496 * DESCRIPTION: Generate a checksum on a raw buffer
1498 ******************************************************************************/
1501 AcpiUtGenerateChecksum (
1506 signed char Sum = 0;
1509 for (i = 0; i < Length; i++)
1511 Sum = (signed char) (Sum + Buffer[i]);
1514 return ((UINT8) (0 - Sum));
1518 /*******************************************************************************
1520 * FUNCTION: AcpiUtGetResourceEndTag
1522 * PARAMETERS: ObjDesc - The resource template buffer object
1524 * RETURN: Pointer to the end tag
1526 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1528 ******************************************************************************/
1532 AcpiUtGetResourceEndTag (
1533 ACPI_OPERAND_OBJECT *ObjDesc)
1540 Buffer = ObjDesc->Buffer.Pointer;
1541 EndBuffer = Buffer + ObjDesc->Buffer.Length;
1543 while (Buffer < EndBuffer)
1545 BufferByte = *Buffer;
1546 if (BufferByte & ACPI_RDESC_TYPE_MASK)
1548 /* Large Descriptor - Length is next 2 bytes */
1550 Buffer += ((*(Buffer+1) | (*(Buffer+2) << 8)) + 3);
1554 /* Small Descriptor. End Tag will be found here */
1556 if ((BufferByte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG)
1558 /* Found the end tag descriptor, all done. */
1563 /* Length is in the header */
1565 Buffer += ((BufferByte & 0x07) + 1);
1569 /* End tag not found */
1575 /*******************************************************************************
1577 * FUNCTION: AcpiUtReportError
1579 * PARAMETERS: ModuleName - Caller's module name (for error output)
1580 * LineNumber - Caller's line number (for error output)
1581 * ComponentId - Caller's component ID (for error output)
1582 * Message - Error message to use on failure
1586 * DESCRIPTION: Print error message
1588 ******************************************************************************/
1598 AcpiOsPrintf ("%8s-%04d: *** Error: ", ModuleName, LineNumber);
1602 /*******************************************************************************
1604 * FUNCTION: AcpiUtReportWarning
1606 * PARAMETERS: ModuleName - Caller's module name (for error output)
1607 * LineNumber - Caller's line number (for error output)
1608 * ComponentId - Caller's component ID (for error output)
1609 * Message - Error message to use on failure
1613 * DESCRIPTION: Print warning message
1615 ******************************************************************************/
1618 AcpiUtReportWarning (
1624 AcpiOsPrintf ("%8s-%04d: *** Warning: ", ModuleName, LineNumber);
1628 /*******************************************************************************
1630 * FUNCTION: AcpiUtReportInfo
1632 * PARAMETERS: ModuleName - Caller's module name (for error output)
1633 * LineNumber - Caller's line number (for error output)
1634 * ComponentId - Caller's component ID (for error output)
1635 * Message - Error message to use on failure
1639 * DESCRIPTION: Print information message
1641 ******************************************************************************/
1650 AcpiOsPrintf ("%8s-%04d: *** Info: ", ModuleName, LineNumber);