1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2004, 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 * Terminater - Where a pointer to the terminating byte is returned
449 * Base - Radix of the string
451 * RETURN: Converted value
453 * DESCRIPTION: Convert a string into an unsigned value.
455 ******************************************************************************/
463 ACPI_INTEGER *RetInteger)
466 ACPI_INTEGER ReturnValue = 0;
467 ACPI_STATUS Status = AE_OK;
468 ACPI_INTEGER Dividend;
469 ACPI_INTEGER Quotient;
484 * The specified Base parameter is not in the domain of
487 return (AE_BAD_PARAMETER);
491 * skip over any white space in the buffer:
493 while (ACPI_IS_SPACE (*String) || *String == '\t')
499 * If the input parameter Base is zero, then we need to
500 * determine if it is octal, decimal, or hexadecimal:
506 if (ACPI_TOLOWER (*(++String)) == 'x')
523 * For octal and hexadecimal bases, skip over the leading
524 * 0 or 0x, if they are present.
526 if (Base == 8 && *String == '0')
533 ACPI_TOLOWER (*(++String)) == 'x')
538 /* Main loop: convert the string to an unsigned long */
542 if (ACPI_IS_DIGIT (*String))
544 Index = ((UINT8) *String) - '0';
548 Index = (UINT8) ACPI_TOUPPER (*String);
549 if (ACPI_IS_UPPER ((char) Index))
551 Index = Index - 'A' + 10;
564 /* Check to see if value is out of range: */
566 Dividend = ACPI_INTEGER_MAX - (ACPI_INTEGER) Index;
567 (void) AcpiUtShortDivide (&Dividend, Base, &Quotient, NULL);
568 if (ReturnValue > Quotient)
574 ReturnValue += Index;
578 *RetInteger = ReturnValue;
586 Status = AE_BAD_OCTAL_CONSTANT;
590 Status = AE_BAD_DECIMAL_CONSTANT;
594 Status = AE_BAD_HEX_CONSTANT;
598 /* Base validated above */
606 /*******************************************************************************
608 * FUNCTION: AcpiUtStrupr
610 * PARAMETERS: SrcString - The source string to convert to
614 * DESCRIPTION: Convert string to uppercase
616 ******************************************************************************/
625 ACPI_FUNCTION_ENTRY ();
628 /* Walk entire string, uppercasing the letters */
630 for (String = SrcString; *String; )
632 *String = (char) ACPI_TOUPPER (*String);
640 /*******************************************************************************
642 * FUNCTION: AcpiUtMutexInitialize
648 * DESCRIPTION: Create the system mutex objects.
650 ******************************************************************************/
653 AcpiUtMutexInitialize (
660 ACPI_FUNCTION_TRACE ("UtMutexInitialize");
664 * Create each of the predefined mutex objects
666 for (i = 0; i < NUM_MUTEX; i++)
668 Status = AcpiUtCreateMutex (i);
669 if (ACPI_FAILURE (Status))
671 return_ACPI_STATUS (Status);
675 Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
676 return_ACPI_STATUS (Status);
680 /*******************************************************************************
682 * FUNCTION: AcpiUtMutexTerminate
688 * DESCRIPTION: Delete all of the system mutex objects.
690 ******************************************************************************/
693 AcpiUtMutexTerminate (
699 ACPI_FUNCTION_TRACE ("UtMutexTerminate");
703 * Delete each predefined mutex object
705 for (i = 0; i < NUM_MUTEX; i++)
707 (void) AcpiUtDeleteMutex (i);
710 AcpiOsDeleteLock (AcpiGbl_GpeLock);
715 /*******************************************************************************
717 * FUNCTION: AcpiUtCreateMutex
719 * PARAMETERS: MutexID - ID of the mutex to be created
723 * DESCRIPTION: Create a mutex object.
725 ******************************************************************************/
729 ACPI_MUTEX_HANDLE MutexId)
731 ACPI_STATUS Status = AE_OK;
734 ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId);
737 if (MutexId > MAX_MUTEX)
739 return_ACPI_STATUS (AE_BAD_PARAMETER);
742 if (!AcpiGbl_MutexInfo[MutexId].Mutex)
744 Status = AcpiOsCreateSemaphore (1, 1,
745 &AcpiGbl_MutexInfo[MutexId].Mutex);
746 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
747 AcpiGbl_MutexInfo[MutexId].UseCount = 0;
750 return_ACPI_STATUS (Status);
754 /*******************************************************************************
756 * FUNCTION: AcpiUtDeleteMutex
758 * PARAMETERS: MutexID - ID of the mutex to be deleted
762 * DESCRIPTION: Delete a mutex object.
764 ******************************************************************************/
768 ACPI_MUTEX_HANDLE MutexId)
773 ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId);
776 if (MutexId > MAX_MUTEX)
778 return_ACPI_STATUS (AE_BAD_PARAMETER);
781 Status = AcpiOsDeleteSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex);
783 AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
784 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
786 return_ACPI_STATUS (Status);
790 /*******************************************************************************
792 * FUNCTION: AcpiUtAcquireMutex
794 * PARAMETERS: MutexID - ID of the mutex to be acquired
798 * DESCRIPTION: Acquire a mutex object.
800 ******************************************************************************/
804 ACPI_MUTEX_HANDLE MutexId)
811 ACPI_FUNCTION_NAME ("UtAcquireMutex");
814 if (MutexId > MAX_MUTEX)
816 return (AE_BAD_PARAMETER);
819 ThisThreadId = AcpiOsGetThreadId ();
822 * Deadlock prevention. Check if this thread owns any mutexes of value
823 * greater than or equal to this one. If so, the thread has violated
824 * the mutex ordering rule. This indicates a coding error somewhere in
825 * the ACPI subsystem code.
827 for (i = MutexId; i < MAX_MUTEX; i++)
829 if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
833 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
834 "Mutex [%s] already acquired by this thread [%X]\n",
835 AcpiUtGetMutexName (MutexId), ThisThreadId));
837 return (AE_ALREADY_ACQUIRED);
840 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
841 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
842 ThisThreadId, AcpiUtGetMutexName (i),
843 AcpiUtGetMutexName (MutexId)));
845 return (AE_ACQUIRE_DEADLOCK);
849 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
850 "Thread %X attempting to acquire Mutex [%s]\n",
851 ThisThreadId, AcpiUtGetMutexName (MutexId)));
853 Status = AcpiOsWaitSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex,
854 1, ACPI_WAIT_FOREVER);
855 if (ACPI_SUCCESS (Status))
857 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
858 ThisThreadId, AcpiUtGetMutexName (MutexId)));
860 AcpiGbl_MutexInfo[MutexId].UseCount++;
861 AcpiGbl_MutexInfo[MutexId].OwnerId = ThisThreadId;
865 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n",
866 ThisThreadId, AcpiUtGetMutexName (MutexId),
867 AcpiFormatException (Status)));
874 /*******************************************************************************
876 * FUNCTION: AcpiUtReleaseMutex
878 * PARAMETERS: MutexID - ID of the mutex to be released
882 * DESCRIPTION: Release a mutex object.
884 ******************************************************************************/
888 ACPI_MUTEX_HANDLE MutexId)
895 ACPI_FUNCTION_NAME ("UtReleaseMutex");
898 ThisThreadId = AcpiOsGetThreadId ();
899 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
900 "Thread %X releasing Mutex [%s]\n", ThisThreadId,
901 AcpiUtGetMutexName (MutexId)));
903 if (MutexId > MAX_MUTEX)
905 return (AE_BAD_PARAMETER);
909 * Mutex must be acquired in order to release it!
911 if (AcpiGbl_MutexInfo[MutexId].OwnerId == ACPI_MUTEX_NOT_ACQUIRED)
913 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
914 "Mutex [%s] is not acquired, cannot release\n",
915 AcpiUtGetMutexName (MutexId)));
917 return (AE_NOT_ACQUIRED);
921 * Deadlock prevention. Check if this thread owns any mutexes of value
922 * greater than this one. If so, the thread has violated the mutex
923 * ordering rule. This indicates a coding error somewhere in
924 * the ACPI subsystem code.
926 for (i = MutexId; i < MAX_MUTEX; i++)
928 if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
935 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
936 "Invalid release order: owns [%s], releasing [%s]\n",
937 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
939 return (AE_RELEASE_DEADLOCK);
943 /* Mark unlocked FIRST */
945 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
947 Status = AcpiOsSignalSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex, 1);
949 if (ACPI_FAILURE (Status))
951 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n",
952 ThisThreadId, AcpiUtGetMutexName (MutexId),
953 AcpiFormatException (Status)));
957 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
958 ThisThreadId, AcpiUtGetMutexName (MutexId)));
965 /*******************************************************************************
967 * FUNCTION: AcpiUtCreateUpdateStateAndPush
969 * PARAMETERS: *Object - Object to be added to the new state
970 * Action - Increment/Decrement
971 * StateList - List the state will be added to
975 * DESCRIPTION: Create a new state and push it
977 ******************************************************************************/
980 AcpiUtCreateUpdateStateAndPush (
981 ACPI_OPERAND_OBJECT *Object,
983 ACPI_GENERIC_STATE **StateList)
985 ACPI_GENERIC_STATE *State;
988 ACPI_FUNCTION_ENTRY ();
991 /* Ignore null objects; these are expected */
998 State = AcpiUtCreateUpdateState (Object, Action);
1001 return (AE_NO_MEMORY);
1004 AcpiUtPushGenericState (StateList, State);
1009 /*******************************************************************************
1011 * FUNCTION: AcpiUtCreatePkgStateAndPush
1013 * PARAMETERS: *Object - Object to be added to the new state
1014 * Action - Increment/Decrement
1015 * StateList - List the state will be added to
1019 * DESCRIPTION: Create a new state and push it
1021 ******************************************************************************/
1024 AcpiUtCreatePkgStateAndPush (
1025 void *InternalObject,
1026 void *ExternalObject,
1028 ACPI_GENERIC_STATE **StateList)
1030 ACPI_GENERIC_STATE *State;
1033 ACPI_FUNCTION_ENTRY ();
1036 State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
1039 return (AE_NO_MEMORY);
1042 AcpiUtPushGenericState (StateList, State);
1047 /*******************************************************************************
1049 * FUNCTION: AcpiUtPushGenericState
1051 * PARAMETERS: ListHead - Head of the state stack
1052 * State - State object to push
1056 * DESCRIPTION: Push a state object onto a state stack
1058 ******************************************************************************/
1061 AcpiUtPushGenericState (
1062 ACPI_GENERIC_STATE **ListHead,
1063 ACPI_GENERIC_STATE *State)
1065 ACPI_FUNCTION_TRACE ("UtPushGenericState");
1068 /* Push the state object onto the front of the list (stack) */
1070 State->Common.Next = *ListHead;
1077 /*******************************************************************************
1079 * FUNCTION: AcpiUtPopGenericState
1081 * PARAMETERS: ListHead - Head of the state stack
1085 * DESCRIPTION: Pop a state object from a state stack
1087 ******************************************************************************/
1089 ACPI_GENERIC_STATE *
1090 AcpiUtPopGenericState (
1091 ACPI_GENERIC_STATE **ListHead)
1093 ACPI_GENERIC_STATE *State;
1096 ACPI_FUNCTION_TRACE ("UtPopGenericState");
1099 /* Remove the state object at the head of the list (stack) */
1104 /* Update the list head */
1106 *ListHead = State->Common.Next;
1113 /*******************************************************************************
1115 * FUNCTION: AcpiUtCreateGenericState
1121 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1122 * the global state cache; If none available, create a new one.
1124 ******************************************************************************/
1126 ACPI_GENERIC_STATE *
1127 AcpiUtCreateGenericState (void)
1129 ACPI_GENERIC_STATE *State;
1132 ACPI_FUNCTION_ENTRY ();
1135 State = AcpiUtAcquireFromCache (ACPI_MEM_LIST_STATE);
1141 State->Common.DataType = ACPI_DESC_TYPE_STATE;
1148 /*******************************************************************************
1150 * FUNCTION: AcpiUtCreateThreadState
1154 * RETURN: Thread State
1156 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1157 * to track per-thread info during method execution
1159 ******************************************************************************/
1162 AcpiUtCreateThreadState (
1165 ACPI_GENERIC_STATE *State;
1168 ACPI_FUNCTION_TRACE ("UtCreateThreadState");
1171 /* Create the generic state object */
1173 State = AcpiUtCreateGenericState ();
1179 /* Init fields specific to the update struct */
1181 State->Common.DataType = ACPI_DESC_TYPE_STATE_THREAD;
1182 State->Thread.ThreadId = AcpiOsGetThreadId ();
1184 return_PTR ((ACPI_THREAD_STATE *) State);
1188 /*******************************************************************************
1190 * FUNCTION: AcpiUtCreateUpdateState
1192 * PARAMETERS: Object - Initial Object to be installed in the
1194 * Action - Update action to be performed
1198 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1199 * to update reference counts and delete complex objects such
1202 ******************************************************************************/
1204 ACPI_GENERIC_STATE *
1205 AcpiUtCreateUpdateState (
1206 ACPI_OPERAND_OBJECT *Object,
1209 ACPI_GENERIC_STATE *State;
1212 ACPI_FUNCTION_TRACE_PTR ("UtCreateUpdateState", Object);
1215 /* Create the generic state object */
1217 State = AcpiUtCreateGenericState ();
1223 /* Init fields specific to the update struct */
1225 State->Common.DataType = ACPI_DESC_TYPE_STATE_UPDATE;
1226 State->Update.Object = Object;
1227 State->Update.Value = Action;
1233 /*******************************************************************************
1235 * FUNCTION: AcpiUtCreatePkgState
1237 * PARAMETERS: Object - Initial Object to be installed in the
1239 * Action - Update action to be performed
1243 * DESCRIPTION: Create a "Package State"
1245 ******************************************************************************/
1247 ACPI_GENERIC_STATE *
1248 AcpiUtCreatePkgState (
1249 void *InternalObject,
1250 void *ExternalObject,
1253 ACPI_GENERIC_STATE *State;
1256 ACPI_FUNCTION_TRACE_PTR ("UtCreatePkgState", InternalObject);
1259 /* Create the generic state object */
1261 State = AcpiUtCreateGenericState ();
1267 /* Init fields specific to the update struct */
1269 State->Common.DataType = ACPI_DESC_TYPE_STATE_PACKAGE;
1270 State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
1271 State->Pkg.DestObject = ExternalObject;
1272 State->Pkg.Index = Index;
1273 State->Pkg.NumPackages = 1;
1279 /*******************************************************************************
1281 * FUNCTION: AcpiUtCreateControlState
1287 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1288 * to support nested IF/WHILE constructs in the AML.
1290 ******************************************************************************/
1292 ACPI_GENERIC_STATE *
1293 AcpiUtCreateControlState (
1296 ACPI_GENERIC_STATE *State;
1299 ACPI_FUNCTION_TRACE ("UtCreateControlState");
1302 /* Create the generic state object */
1304 State = AcpiUtCreateGenericState ();
1310 /* Init fields specific to the control struct */
1312 State->Common.DataType = ACPI_DESC_TYPE_STATE_CONTROL;
1313 State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1319 /*******************************************************************************
1321 * FUNCTION: AcpiUtDeleteGenericState
1323 * PARAMETERS: State - The state object to be deleted
1327 * DESCRIPTION: Put a state object back into the global state cache. The object
1328 * is not actually freed at this time.
1330 ******************************************************************************/
1333 AcpiUtDeleteGenericState (
1334 ACPI_GENERIC_STATE *State)
1336 ACPI_FUNCTION_TRACE ("UtDeleteGenericState");
1339 AcpiUtReleaseToCache (ACPI_MEM_LIST_STATE, State);
1344 /*******************************************************************************
1346 * FUNCTION: AcpiUtDeleteGenericStateCache
1352 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1355 ******************************************************************************/
1358 AcpiUtDeleteGenericStateCache (
1361 ACPI_FUNCTION_TRACE ("UtDeleteGenericStateCache");
1364 AcpiUtDeleteGenericCache (ACPI_MEM_LIST_STATE);
1369 /*******************************************************************************
1371 * FUNCTION: AcpiUtWalkPackageTree
1373 * PARAMETERS: ObjDesc - The Package object on which to resolve refs
1377 * DESCRIPTION: Walk through a package
1379 ******************************************************************************/
1382 AcpiUtWalkPackageTree (
1383 ACPI_OPERAND_OBJECT *SourceObject,
1385 ACPI_PKG_CALLBACK WalkCallback,
1388 ACPI_STATUS Status = AE_OK;
1389 ACPI_GENERIC_STATE *StateList = NULL;
1390 ACPI_GENERIC_STATE *State;
1392 ACPI_OPERAND_OBJECT *ThisSourceObj;
1395 ACPI_FUNCTION_TRACE ("UtWalkPackageTree");
1398 State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1401 return_ACPI_STATUS (AE_NO_MEMORY);
1406 /* Get one element of the package */
1408 ThisIndex = State->Pkg.Index;
1409 ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1410 State->Pkg.SourceObject->Package.Elements[ThisIndex];
1414 * 1) An uninitialized package element. It is completely
1415 * legal to declare a package and leave it uninitialized
1416 * 2) Not an internal object - can be a namespace node instead
1417 * 3) Any type other than a package. Packages are handled in else
1420 if ((!ThisSourceObj) ||
1421 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1422 (ACPI_GET_OBJECT_TYPE (ThisSourceObj) != ACPI_TYPE_PACKAGE))
1424 Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1426 if (ACPI_FAILURE (Status))
1428 return_ACPI_STATUS (Status);
1432 while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1435 * We've handled all of the objects at this level, This means
1436 * that we have just completed a package. That package may
1437 * have contained one or more packages itself.
1439 * Delete this state and pop the previous state (package).
1441 AcpiUtDeleteGenericState (State);
1442 State = AcpiUtPopGenericState (&StateList);
1444 /* Finished when there are no more states */
1449 * We have handled all of the objects in the top level
1450 * package just add the length of the package objects
1453 return_ACPI_STATUS (AE_OK);
1457 * Go back up a level and move the index past the just
1458 * completed package object.
1465 /* This is a subobject of type package */
1467 Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1469 if (ACPI_FAILURE (Status))
1471 return_ACPI_STATUS (Status);
1475 * Push the current state and create a new one
1476 * The callback above returned a new target package object.
1478 AcpiUtPushGenericState (&StateList, State);
1479 State = AcpiUtCreatePkgState (ThisSourceObj,
1480 State->Pkg.ThisTargetObj, 0);
1483 return_ACPI_STATUS (AE_NO_MEMORY);
1488 /* We should never get here */
1490 return_ACPI_STATUS (AE_AML_INTERNAL);
1494 /*******************************************************************************
1496 * FUNCTION: AcpiUtGenerateChecksum
1498 * PARAMETERS: Buffer - Buffer to be scanned
1499 * Length - number of bytes to examine
1503 * DESCRIPTION: Generate a checksum on a raw buffer
1505 ******************************************************************************/
1508 AcpiUtGenerateChecksum (
1513 signed char Sum = 0;
1516 for (i = 0; i < Length; i++)
1518 Sum = (signed char) (Sum + Buffer[i]);
1521 return ((UINT8) (0 - Sum));
1525 /*******************************************************************************
1527 * FUNCTION: AcpiUtGetResourceEndTag
1529 * PARAMETERS: ObjDesc - The resource template buffer object
1531 * RETURN: Pointer to the end tag
1533 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1535 ******************************************************************************/
1539 AcpiUtGetResourceEndTag (
1540 ACPI_OPERAND_OBJECT *ObjDesc)
1547 Buffer = ObjDesc->Buffer.Pointer;
1548 EndBuffer = Buffer + ObjDesc->Buffer.Length;
1550 while (Buffer < EndBuffer)
1552 BufferByte = *Buffer;
1553 if (BufferByte & ACPI_RDESC_TYPE_MASK)
1555 /* Large Descriptor - Length is next 2 bytes */
1557 Buffer += ((*(Buffer+1) | (*(Buffer+2) << 8)) + 3);
1561 /* Small Descriptor. End Tag will be found here */
1563 if ((BufferByte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG)
1565 /* Found the end tag descriptor, all done. */
1570 /* Length is in the header */
1572 Buffer += ((BufferByte & 0x07) + 1);
1576 /* End tag not found */
1582 /*******************************************************************************
1584 * FUNCTION: AcpiUtReportError
1586 * PARAMETERS: ModuleName - Caller's module name (for error output)
1587 * LineNumber - Caller's line number (for error output)
1588 * ComponentId - Caller's component ID (for error output)
1589 * Message - Error message to use on failure
1593 * DESCRIPTION: Print error message
1595 ******************************************************************************/
1605 AcpiOsPrintf ("%8s-%04d: *** Error: ", ModuleName, LineNumber);
1609 /*******************************************************************************
1611 * FUNCTION: AcpiUtReportWarning
1613 * PARAMETERS: ModuleName - Caller's module name (for error output)
1614 * LineNumber - Caller's line number (for error output)
1615 * ComponentId - Caller's component ID (for error output)
1616 * Message - Error message to use on failure
1620 * DESCRIPTION: Print warning message
1622 ******************************************************************************/
1625 AcpiUtReportWarning (
1631 AcpiOsPrintf ("%8s-%04d: *** Warning: ", ModuleName, LineNumber);
1635 /*******************************************************************************
1637 * FUNCTION: AcpiUtReportInfo
1639 * PARAMETERS: ModuleName - Caller's module name (for error output)
1640 * LineNumber - Caller's line number (for error output)
1641 * ComponentId - Caller's component ID (for error output)
1642 * Message - Error message to use on failure
1646 * DESCRIPTION: Print information message
1648 ******************************************************************************/
1657 AcpiOsPrintf ("%8s-%04d: *** Info: ", ModuleName, LineNumber);