1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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;
397 ACPI_FUNCTION_ENTRY ();
400 for (i = 0; i < ACPI_NAME_SIZE; i++)
402 if (!((NamePtr[i] == '_') ||
403 (NamePtr[i] >= 'A' && NamePtr[i] <= 'Z') ||
404 (NamePtr[i] >= '0' && NamePtr[i] <= '9')))
414 /*******************************************************************************
416 * FUNCTION: AcpiUtValidAcpiCharacter
418 * PARAMETERS: Character - The character to be examined
420 * RETURN: 1 if Character may appear in a name, else 0
422 * DESCRIPTION: Check for a printable character
424 ******************************************************************************/
427 AcpiUtValidAcpiCharacter (
431 ACPI_FUNCTION_ENTRY ();
433 return ((BOOLEAN) ((Character == '_') ||
434 (Character >= 'A' && Character <= 'Z') ||
435 (Character >= '0' && Character <= '9')));
439 /*******************************************************************************
441 * FUNCTION: AcpiUtStrtoul64
443 * PARAMETERS: String - Null terminated string
444 * Terminater - Where a pointer to the terminating byte is returned
445 * Base - Radix of the string
447 * RETURN: Converted value
449 * DESCRIPTION: Convert a string into an unsigned value.
451 ******************************************************************************/
459 ACPI_INTEGER *RetInteger)
462 ACPI_INTEGER ReturnValue = 0;
463 ACPI_STATUS Status = AE_OK;
464 ACPI_INTEGER Dividend;
465 ACPI_INTEGER Quotient;
480 * The specified Base parameter is not in the domain of
483 return (AE_BAD_PARAMETER);
487 * skip over any white space in the buffer:
489 while (ACPI_IS_SPACE (*String) || *String == '\t')
495 * If the input parameter Base is zero, then we need to
496 * determine if it is octal, decimal, or hexadecimal:
502 if (ACPI_TOLOWER (*(++String)) == 'x')
519 * For octal and hexadecimal bases, skip over the leading
520 * 0 or 0x, if they are present.
522 if (Base == 8 && *String == '0')
529 ACPI_TOLOWER (*(++String)) == 'x')
534 /* Main loop: convert the string to an unsigned long */
538 if (ACPI_IS_DIGIT (*String))
540 Index = ((UINT8) *String) - '0';
544 Index = (UINT8) ACPI_TOUPPER (*String);
545 if (ACPI_IS_UPPER ((char) Index))
547 Index = Index - 'A' + 10;
560 /* Check to see if value is out of range: */
562 Dividend = ACPI_INTEGER_MAX - (ACPI_INTEGER) Index;
563 (void) AcpiUtShortDivide (&Dividend, Base, &Quotient, NULL);
564 if (ReturnValue > Quotient)
570 ReturnValue += Index;
574 *RetInteger = ReturnValue;
582 Status = AE_BAD_OCTAL_CONSTANT;
586 Status = AE_BAD_DECIMAL_CONSTANT;
590 Status = AE_BAD_HEX_CONSTANT;
594 /* Base validated above */
602 /*******************************************************************************
604 * FUNCTION: AcpiUtStrupr
606 * PARAMETERS: SrcString - The source string to convert to
610 * DESCRIPTION: Convert string to uppercase
612 ******************************************************************************/
621 ACPI_FUNCTION_ENTRY ();
624 /* Walk entire string, uppercasing the letters */
626 for (String = SrcString; *String; )
628 *String = (char) ACPI_TOUPPER (*String);
635 /*******************************************************************************
637 * FUNCTION: AcpiUtMutexInitialize
643 * DESCRIPTION: Create the system mutex objects.
645 ******************************************************************************/
648 AcpiUtMutexInitialize (
655 ACPI_FUNCTION_TRACE ("UtMutexInitialize");
659 * Create each of the predefined mutex objects
661 for (i = 0; i < NUM_MUTEX; i++)
663 Status = AcpiUtCreateMutex (i);
664 if (ACPI_FAILURE (Status))
666 return_ACPI_STATUS (Status);
671 Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
673 return_ACPI_STATUS (AE_OK);
677 /*******************************************************************************
679 * FUNCTION: AcpiUtMutexTerminate
685 * DESCRIPTION: Delete all of the system mutex objects.
687 ******************************************************************************/
690 AcpiUtMutexTerminate (
696 ACPI_FUNCTION_TRACE ("UtMutexTerminate");
700 * Delete each predefined mutex object
702 for (i = 0; i < NUM_MUTEX; i++)
704 (void) AcpiUtDeleteMutex (i);
707 AcpiOsDeleteLock (AcpiGbl_GpeLock);
712 /*******************************************************************************
714 * FUNCTION: AcpiUtCreateMutex
716 * PARAMETERS: MutexID - ID of the mutex to be created
720 * DESCRIPTION: Create a mutex object.
722 ******************************************************************************/
726 ACPI_MUTEX_HANDLE MutexId)
728 ACPI_STATUS Status = AE_OK;
731 ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId);
734 if (MutexId > MAX_MUTEX)
736 return_ACPI_STATUS (AE_BAD_PARAMETER);
739 if (!AcpiGbl_MutexInfo[MutexId].Mutex)
741 Status = AcpiOsCreateSemaphore (1, 1,
742 &AcpiGbl_MutexInfo[MutexId].Mutex);
743 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
744 AcpiGbl_MutexInfo[MutexId].UseCount = 0;
747 return_ACPI_STATUS (Status);
751 /*******************************************************************************
753 * FUNCTION: AcpiUtDeleteMutex
755 * PARAMETERS: MutexID - ID of the mutex to be deleted
759 * DESCRIPTION: Delete a mutex object.
761 ******************************************************************************/
765 ACPI_MUTEX_HANDLE MutexId)
770 ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId);
773 if (MutexId > MAX_MUTEX)
775 return_ACPI_STATUS (AE_BAD_PARAMETER);
778 Status = AcpiOsDeleteSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex);
780 AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
781 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
783 return_ACPI_STATUS (Status);
787 /*******************************************************************************
789 * FUNCTION: AcpiUtAcquireMutex
791 * PARAMETERS: MutexID - ID of the mutex to be acquired
795 * DESCRIPTION: Acquire a mutex object.
797 ******************************************************************************/
801 ACPI_MUTEX_HANDLE MutexId)
808 ACPI_FUNCTION_NAME ("UtAcquireMutex");
811 if (MutexId > MAX_MUTEX)
813 return (AE_BAD_PARAMETER);
816 ThisThreadId = AcpiOsGetThreadId ();
819 * Deadlock prevention. Check if this thread owns any mutexes of value
820 * greater than or equal to this one. If so, the thread has violated
821 * the mutex ordering rule. This indicates a coding error somewhere in
822 * the ACPI subsystem code.
824 for (i = MutexId; i < MAX_MUTEX; i++)
826 if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
830 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
831 "Mutex [%s] already acquired by this thread [%X]\n",
832 AcpiUtGetMutexName (MutexId), ThisThreadId));
834 return (AE_ALREADY_ACQUIRED);
837 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
838 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
839 ThisThreadId, AcpiUtGetMutexName (i),
840 AcpiUtGetMutexName (MutexId)));
842 return (AE_ACQUIRE_DEADLOCK);
846 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
847 "Thread %X attempting to acquire Mutex [%s]\n",
848 ThisThreadId, AcpiUtGetMutexName (MutexId)));
850 Status = AcpiOsWaitSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex,
851 1, ACPI_WAIT_FOREVER);
852 if (ACPI_SUCCESS (Status))
854 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
855 ThisThreadId, AcpiUtGetMutexName (MutexId)));
857 AcpiGbl_MutexInfo[MutexId].UseCount++;
858 AcpiGbl_MutexInfo[MutexId].OwnerId = ThisThreadId;
862 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n",
863 ThisThreadId, AcpiUtGetMutexName (MutexId),
864 AcpiFormatException (Status)));
871 /*******************************************************************************
873 * FUNCTION: AcpiUtReleaseMutex
875 * PARAMETERS: MutexID - ID of the mutex to be released
879 * DESCRIPTION: Release a mutex object.
881 ******************************************************************************/
885 ACPI_MUTEX_HANDLE MutexId)
892 ACPI_FUNCTION_NAME ("UtReleaseMutex");
895 ThisThreadId = AcpiOsGetThreadId ();
896 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
897 "Thread %X releasing Mutex [%s]\n", ThisThreadId,
898 AcpiUtGetMutexName (MutexId)));
900 if (MutexId > MAX_MUTEX)
902 return (AE_BAD_PARAMETER);
906 * Mutex must be acquired in order to release it!
908 if (AcpiGbl_MutexInfo[MutexId].OwnerId == ACPI_MUTEX_NOT_ACQUIRED)
910 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
911 "Mutex [%s] is not acquired, cannot release\n",
912 AcpiUtGetMutexName (MutexId)));
914 return (AE_NOT_ACQUIRED);
918 * Deadlock prevention. Check if this thread owns any mutexes of value
919 * greater than this one. If so, the thread has violated the mutex
920 * ordering rule. This indicates a coding error somewhere in
921 * the ACPI subsystem code.
923 for (i = MutexId; i < MAX_MUTEX; i++)
925 if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
932 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
933 "Invalid release order: owns [%s], releasing [%s]\n",
934 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
936 return (AE_RELEASE_DEADLOCK);
940 /* Mark unlocked FIRST */
942 AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
944 Status = AcpiOsSignalSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex, 1);
946 if (ACPI_FAILURE (Status))
948 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n",
949 ThisThreadId, AcpiUtGetMutexName (MutexId),
950 AcpiFormatException (Status)));
954 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
955 ThisThreadId, AcpiUtGetMutexName (MutexId)));
962 /*******************************************************************************
964 * FUNCTION: AcpiUtCreateUpdateStateAndPush
966 * PARAMETERS: *Object - Object to be added to the new state
967 * Action - Increment/Decrement
968 * StateList - List the state will be added to
972 * DESCRIPTION: Create a new state and push it
974 ******************************************************************************/
977 AcpiUtCreateUpdateStateAndPush (
978 ACPI_OPERAND_OBJECT *Object,
980 ACPI_GENERIC_STATE **StateList)
982 ACPI_GENERIC_STATE *State;
985 ACPI_FUNCTION_ENTRY ();
988 /* Ignore null objects; these are expected */
995 State = AcpiUtCreateUpdateState (Object, Action);
998 return (AE_NO_MEMORY);
1001 AcpiUtPushGenericState (StateList, State);
1006 /*******************************************************************************
1008 * FUNCTION: AcpiUtCreatePkgStateAndPush
1010 * PARAMETERS: *Object - Object to be added to the new state
1011 * Action - Increment/Decrement
1012 * StateList - List the state will be added to
1016 * DESCRIPTION: Create a new state and push it
1018 ******************************************************************************/
1021 AcpiUtCreatePkgStateAndPush (
1022 void *InternalObject,
1023 void *ExternalObject,
1025 ACPI_GENERIC_STATE **StateList)
1027 ACPI_GENERIC_STATE *State;
1030 ACPI_FUNCTION_ENTRY ();
1033 State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
1036 return (AE_NO_MEMORY);
1039 AcpiUtPushGenericState (StateList, State);
1044 /*******************************************************************************
1046 * FUNCTION: AcpiUtPushGenericState
1048 * PARAMETERS: ListHead - Head of the state stack
1049 * State - State object to push
1053 * DESCRIPTION: Push a state object onto a state stack
1055 ******************************************************************************/
1058 AcpiUtPushGenericState (
1059 ACPI_GENERIC_STATE **ListHead,
1060 ACPI_GENERIC_STATE *State)
1062 ACPI_FUNCTION_TRACE ("UtPushGenericState");
1065 /* Push the state object onto the front of the list (stack) */
1067 State->Common.Next = *ListHead;
1074 /*******************************************************************************
1076 * FUNCTION: AcpiUtPopGenericState
1078 * PARAMETERS: ListHead - Head of the state stack
1082 * DESCRIPTION: Pop a state object from a state stack
1084 ******************************************************************************/
1086 ACPI_GENERIC_STATE *
1087 AcpiUtPopGenericState (
1088 ACPI_GENERIC_STATE **ListHead)
1090 ACPI_GENERIC_STATE *State;
1093 ACPI_FUNCTION_TRACE ("UtPopGenericState");
1096 /* Remove the state object at the head of the list (stack) */
1101 /* Update the list head */
1103 *ListHead = State->Common.Next;
1110 /*******************************************************************************
1112 * FUNCTION: AcpiUtCreateGenericState
1118 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1119 * the global state cache; If none available, create a new one.
1121 ******************************************************************************/
1123 ACPI_GENERIC_STATE *
1124 AcpiUtCreateGenericState (void)
1126 ACPI_GENERIC_STATE *State;
1129 ACPI_FUNCTION_ENTRY ();
1132 State = AcpiUtAcquireFromCache (ACPI_MEM_LIST_STATE);
1138 State->Common.DataType = ACPI_DESC_TYPE_STATE;
1145 /*******************************************************************************
1147 * FUNCTION: AcpiUtCreateThreadState
1151 * RETURN: Thread State
1153 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1154 * to track per-thread info during method execution
1156 ******************************************************************************/
1159 AcpiUtCreateThreadState (
1162 ACPI_GENERIC_STATE *State;
1165 ACPI_FUNCTION_TRACE ("UtCreateThreadState");
1168 /* Create the generic state object */
1170 State = AcpiUtCreateGenericState ();
1176 /* Init fields specific to the update struct */
1178 State->Common.DataType = ACPI_DESC_TYPE_STATE_THREAD;
1179 State->Thread.ThreadId = AcpiOsGetThreadId ();
1181 return_PTR ((ACPI_THREAD_STATE *) State);
1185 /*******************************************************************************
1187 * FUNCTION: AcpiUtCreateUpdateState
1189 * PARAMETERS: Object - Initial Object to be installed in the
1191 * Action - Update action to be performed
1195 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1196 * to update reference counts and delete complex objects such
1199 ******************************************************************************/
1201 ACPI_GENERIC_STATE *
1202 AcpiUtCreateUpdateState (
1203 ACPI_OPERAND_OBJECT *Object,
1206 ACPI_GENERIC_STATE *State;
1209 ACPI_FUNCTION_TRACE_PTR ("UtCreateUpdateState", Object);
1212 /* Create the generic state object */
1214 State = AcpiUtCreateGenericState ();
1220 /* Init fields specific to the update struct */
1222 State->Common.DataType = ACPI_DESC_TYPE_STATE_UPDATE;
1223 State->Update.Object = Object;
1224 State->Update.Value = Action;
1230 /*******************************************************************************
1232 * FUNCTION: AcpiUtCreatePkgState
1234 * PARAMETERS: Object - Initial Object to be installed in the
1236 * Action - Update action to be performed
1240 * DESCRIPTION: Create a "Package State"
1242 ******************************************************************************/
1244 ACPI_GENERIC_STATE *
1245 AcpiUtCreatePkgState (
1246 void *InternalObject,
1247 void *ExternalObject,
1250 ACPI_GENERIC_STATE *State;
1253 ACPI_FUNCTION_TRACE_PTR ("UtCreatePkgState", InternalObject);
1256 /* Create the generic state object */
1258 State = AcpiUtCreateGenericState ();
1264 /* Init fields specific to the update struct */
1266 State->Common.DataType = ACPI_DESC_TYPE_STATE_PACKAGE;
1267 State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
1268 State->Pkg.DestObject = ExternalObject;
1269 State->Pkg.Index = Index;
1270 State->Pkg.NumPackages = 1;
1276 /*******************************************************************************
1278 * FUNCTION: AcpiUtCreateControlState
1284 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1285 * to support nested IF/WHILE constructs in the AML.
1287 ******************************************************************************/
1289 ACPI_GENERIC_STATE *
1290 AcpiUtCreateControlState (
1293 ACPI_GENERIC_STATE *State;
1296 ACPI_FUNCTION_TRACE ("UtCreateControlState");
1299 /* Create the generic state object */
1301 State = AcpiUtCreateGenericState ();
1307 /* Init fields specific to the control struct */
1309 State->Common.DataType = ACPI_DESC_TYPE_STATE_CONTROL;
1310 State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1316 /*******************************************************************************
1318 * FUNCTION: AcpiUtDeleteGenericState
1320 * PARAMETERS: State - The state object to be deleted
1324 * DESCRIPTION: Put a state object back into the global state cache. The object
1325 * is not actually freed at this time.
1327 ******************************************************************************/
1330 AcpiUtDeleteGenericState (
1331 ACPI_GENERIC_STATE *State)
1333 ACPI_FUNCTION_TRACE ("UtDeleteGenericState");
1336 AcpiUtReleaseToCache (ACPI_MEM_LIST_STATE, State);
1341 /*******************************************************************************
1343 * FUNCTION: AcpiUtDeleteGenericStateCache
1349 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1352 ******************************************************************************/
1355 AcpiUtDeleteGenericStateCache (
1358 ACPI_FUNCTION_TRACE ("UtDeleteGenericStateCache");
1361 AcpiUtDeleteGenericCache (ACPI_MEM_LIST_STATE);
1366 /*******************************************************************************
1368 * FUNCTION: AcpiUtWalkPackageTree
1370 * PARAMETERS: ObjDesc - The Package object on which to resolve refs
1374 * DESCRIPTION: Walk through a package
1376 ******************************************************************************/
1379 AcpiUtWalkPackageTree (
1380 ACPI_OPERAND_OBJECT *SourceObject,
1382 ACPI_PKG_CALLBACK WalkCallback,
1385 ACPI_STATUS Status = AE_OK;
1386 ACPI_GENERIC_STATE *StateList = NULL;
1387 ACPI_GENERIC_STATE *State;
1389 ACPI_OPERAND_OBJECT *ThisSourceObj;
1392 ACPI_FUNCTION_TRACE ("UtWalkPackageTree");
1395 State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1398 return_ACPI_STATUS (AE_NO_MEMORY);
1403 /* Get one element of the package */
1405 ThisIndex = State->Pkg.Index;
1406 ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1407 State->Pkg.SourceObject->Package.Elements[ThisIndex];
1411 * 1) An uninitialized package element. It is completely
1412 * legal to declare a package and leave it uninitialized
1413 * 2) Not an internal object - can be a namespace node instead
1414 * 3) Any type other than a package. Packages are handled in else
1417 if ((!ThisSourceObj) ||
1418 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1419 (ACPI_GET_OBJECT_TYPE (ThisSourceObj) != ACPI_TYPE_PACKAGE))
1421 Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1423 if (ACPI_FAILURE (Status))
1425 return_ACPI_STATUS (Status);
1429 while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1432 * We've handled all of the objects at this level, This means
1433 * that we have just completed a package. That package may
1434 * have contained one or more packages itself.
1436 * Delete this state and pop the previous state (package).
1438 AcpiUtDeleteGenericState (State);
1439 State = AcpiUtPopGenericState (&StateList);
1441 /* Finished when there are no more states */
1446 * We have handled all of the objects in the top level
1447 * package just add the length of the package objects
1450 return_ACPI_STATUS (AE_OK);
1454 * Go back up a level and move the index past the just
1455 * completed package object.
1462 /* This is a subobject of type package */
1464 Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1466 if (ACPI_FAILURE (Status))
1468 return_ACPI_STATUS (Status);
1472 * Push the current state and create a new one
1473 * The callback above returned a new target package object.
1475 AcpiUtPushGenericState (&StateList, State);
1476 State = AcpiUtCreatePkgState (ThisSourceObj,
1477 State->Pkg.ThisTargetObj, 0);
1480 return_ACPI_STATUS (AE_NO_MEMORY);
1485 /* We should never get here */
1487 return_ACPI_STATUS (AE_AML_INTERNAL);
1491 /*******************************************************************************
1493 * FUNCTION: AcpiUtGenerateChecksum
1495 * PARAMETERS: Buffer - Buffer to be scanned
1496 * Length - number of bytes to examine
1500 * DESCRIPTION: Generate a checksum on a raw buffer
1502 ******************************************************************************/
1505 AcpiUtGenerateChecksum (
1510 signed char Sum = 0;
1513 for (i = 0; i < Length; i++)
1515 Sum = (signed char) (Sum + Buffer[i]);
1518 return ((UINT8) (0 - Sum));
1522 /*******************************************************************************
1524 * FUNCTION: AcpiUtGetResourceEndTag
1526 * PARAMETERS: ObjDesc - The resource template buffer object
1528 * RETURN: Pointer to the end tag
1530 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1532 ******************************************************************************/
1536 AcpiUtGetResourceEndTag (
1537 ACPI_OPERAND_OBJECT *ObjDesc)
1544 Buffer = ObjDesc->Buffer.Pointer;
1545 EndBuffer = Buffer + ObjDesc->Buffer.Length;
1547 while (Buffer < EndBuffer)
1549 BufferByte = *Buffer;
1550 if (BufferByte & ACPI_RDESC_TYPE_MASK)
1552 /* Large Descriptor - Length is next 2 bytes */
1554 Buffer += ((*(Buffer+1) | (*(Buffer+2) << 8)) + 3);
1558 /* Small Descriptor. End Tag will be found here */
1560 if ((BufferByte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG)
1562 /* Found the end tag descriptor, all done. */
1567 /* Length is in the header */
1569 Buffer += ((BufferByte & 0x07) + 1);
1573 /* End tag not found */
1579 /*******************************************************************************
1581 * FUNCTION: AcpiUtReportError
1583 * PARAMETERS: ModuleName - Caller's module name (for error output)
1584 * LineNumber - Caller's line number (for error output)
1585 * ComponentId - Caller's component ID (for error output)
1586 * Message - Error message to use on failure
1590 * DESCRIPTION: Print error message
1592 ******************************************************************************/
1602 AcpiOsPrintf ("%8s-%04d: *** Error: ", ModuleName, LineNumber);
1606 /*******************************************************************************
1608 * FUNCTION: AcpiUtReportWarning
1610 * PARAMETERS: ModuleName - Caller's module name (for error output)
1611 * LineNumber - Caller's line number (for error output)
1612 * ComponentId - Caller's component ID (for error output)
1613 * Message - Error message to use on failure
1617 * DESCRIPTION: Print warning message
1619 ******************************************************************************/
1622 AcpiUtReportWarning (
1628 AcpiOsPrintf ("%8s-%04d: *** Warning: ", ModuleName, LineNumber);
1632 /*******************************************************************************
1634 * FUNCTION: AcpiUtReportInfo
1636 * PARAMETERS: ModuleName - Caller's module name (for error output)
1637 * LineNumber - Caller's line number (for error output)
1638 * ComponentId - Caller's component ID (for error output)
1639 * Message - Error message to use on failure
1643 * DESCRIPTION: Print information message
1645 ******************************************************************************/
1654 AcpiOsPrintf ("%8s-%04d: *** Info: ", ModuleName, LineNumber);