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 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/utmisc.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
122 #include "acnamesp.h"
125 #define _COMPONENT ACPI_UTILITIES
126 ACPI_MODULE_NAME ("utmisc")
129 /*******************************************************************************
131 * FUNCTION: AcpiUtPrintString
133 * PARAMETERS: String - Null terminated ASCII string
137 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
140 ******************************************************************************/
152 AcpiOsPrintf ("<\"NULL STRING PTR\">");
157 for (i = 0; String[i] && (i < MaxLength); i++)
159 /* Escape sequences */
164 AcpiOsPrintf ("\\a"); /* BELL */
168 AcpiOsPrintf ("\\b"); /* BACKSPACE */
172 AcpiOsPrintf ("\\f"); /* FORMFEED */
176 AcpiOsPrintf ("\\n"); /* LINEFEED */
180 AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
184 AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
188 AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
191 case '\'': /* Single Quote */
192 case '\"': /* Double Quote */
193 case '\\': /* Backslash */
194 AcpiOsPrintf ("\\%c", (int) String[i]);
199 /* Check for printable character or hex escape */
201 if (ACPI_IS_PRINT (String[i]))
203 /* This is a normal character */
205 AcpiOsPrintf ("%c", (int) String[i]);
209 /* All others will be Hex escapes */
211 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
218 if (i == MaxLength && String[i])
220 AcpiOsPrintf ("...");
225 /*******************************************************************************
227 * FUNCTION: AcpiUtDwordByteSwap
229 * PARAMETERS: Value - Value to be converted
231 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
233 ******************************************************************************/
236 AcpiUtDwordByteSwap (
252 ACPI_FUNCTION_ENTRY ();
257 Out.Bytes[0] = In.Bytes[3];
258 Out.Bytes[1] = In.Bytes[2];
259 Out.Bytes[2] = In.Bytes[1];
260 Out.Bytes[3] = In.Bytes[0];
266 /*******************************************************************************
268 * FUNCTION: AcpiUtSetIntegerWidth
270 * PARAMETERS: Revision From DSDT header
274 * DESCRIPTION: Set the global integer bit width based upon the revision
275 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
276 * For Revision 2 and above, Integers are 64 bits. Yes, this
277 * makes a difference.
279 ******************************************************************************/
282 AcpiUtSetIntegerWidth (
288 AcpiGbl_IntegerBitWidth = 32;
289 AcpiGbl_IntegerByteWidth = 4;
293 AcpiGbl_IntegerBitWidth = 64;
294 AcpiGbl_IntegerByteWidth = 8;
299 #ifdef ACPI_DEBUG_OUTPUT
300 /*******************************************************************************
302 * FUNCTION: AcpiUtDisplayInitPathname
304 * PARAMETERS: ObjHandle - Handle whose pathname will be displayed
305 * Path - Additional path string to be appended.
306 * (NULL if no extra path)
308 * RETURN: ACPI_STATUS
310 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
312 ******************************************************************************/
315 AcpiUtDisplayInitPathname (
317 ACPI_NAMESPACE_NODE *ObjHandle,
324 ACPI_FUNCTION_ENTRY ();
327 /* Only print the path if the appropriate debug level is enabled */
329 if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
334 /* Get the full pathname to the node */
336 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
337 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
338 if (ACPI_FAILURE (Status))
343 /* Print what we're doing */
347 case ACPI_TYPE_METHOD:
348 AcpiOsPrintf ("Executing ");
352 AcpiOsPrintf ("Initializing ");
356 /* Print the object type and pathname */
358 AcpiOsPrintf ("%-12s %s", AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
360 /* Extra path is used to append names like _STA, _INI, etc. */
364 AcpiOsPrintf (".%s", Path);
368 ACPI_MEM_FREE (Buffer.Pointer);
373 /*******************************************************************************
375 * FUNCTION: AcpiUtValidAcpiName
377 * PARAMETERS: Character - The character to be examined
379 * RETURN: 1 if Character may appear in a name, else 0
381 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
382 * 1) Upper case alpha
386 ******************************************************************************/
389 AcpiUtValidAcpiName (
392 char *NamePtr = (char *) &Name;
396 ACPI_FUNCTION_ENTRY ();
399 for (i = 0; i < ACPI_NAME_SIZE; i++)
401 if (!((NamePtr[i] == '_') ||
402 (NamePtr[i] >= 'A' && NamePtr[i] <= 'Z') ||
403 (NamePtr[i] >= '0' && NamePtr[i] <= '9')))
413 /*******************************************************************************
415 * FUNCTION: AcpiUtValidAcpiCharacter
417 * PARAMETERS: Character - The character to be examined
419 * RETURN: 1 if Character may appear in a name, else 0
421 * DESCRIPTION: Check for a printable character
423 ******************************************************************************/
426 AcpiUtValidAcpiCharacter (
430 ACPI_FUNCTION_ENTRY ();
432 return ((BOOLEAN) ((Character == '_') ||
433 (Character >= 'A' && Character <= 'Z') ||
434 (Character >= '0' && Character <= '9')));
438 /*******************************************************************************
440 * FUNCTION: AcpiUtStrtoul64
442 * PARAMETERS: String - Null terminated string
443 * Terminater - Where a pointer to the terminating byte is returned
444 * Base - Radix of the string
446 * RETURN: Converted value
448 * DESCRIPTION: Convert a string into an unsigned value.
450 ******************************************************************************/
458 ACPI_INTEGER *RetInteger)
461 ACPI_INTEGER ReturnValue = 0;
462 ACPI_STATUS Status = AE_OK;
463 ACPI_INTEGER Dividend;
464 ACPI_INTEGER Quotient;
479 * The specified Base parameter is not in the domain of
482 return (AE_BAD_PARAMETER);
486 * skip over any white space in the buffer:
488 while (ACPI_IS_SPACE (*String) || *String == '\t')
494 * If the input parameter Base is zero, then we need to
495 * determine if it is octal, decimal, or hexadecimal:
501 if (ACPI_TOLOWER (*(++String)) == 'x')
518 * For octal and hexadecimal bases, skip over the leading
519 * 0 or 0x, if they are present.
521 if (Base == 8 && *String == '0')
528 ACPI_TOLOWER (*(++String)) == 'x')
533 /* Main loop: convert the string to an unsigned long */
537 if (ACPI_IS_DIGIT (*String))
539 Index = ((UINT8) *String) - '0';
543 Index = (UINT8) ACPI_TOUPPER (*String);
544 if (ACPI_IS_UPPER ((char) Index))
546 Index = Index - 'A' + 10;
559 /* Check to see if value is out of range: */
561 Dividend = ACPI_INTEGER_MAX - (ACPI_INTEGER) Index;
562 (void) AcpiUtShortDivide (&Dividend, Base, &Quotient, NULL);
563 if (ReturnValue > Quotient)
569 ReturnValue += Index;
573 *RetInteger = ReturnValue;
581 Status = AE_BAD_OCTAL_CONSTANT;
585 Status = AE_BAD_DECIMAL_CONSTANT;
589 Status = AE_BAD_HEX_CONSTANT;
593 /* Base validated above */
601 /*******************************************************************************
603 * FUNCTION: AcpiUtStrupr
605 * PARAMETERS: SrcString - The source string to convert to
609 * DESCRIPTION: Convert string to uppercase
611 ******************************************************************************/
620 ACPI_FUNCTION_ENTRY ();
623 /* Walk entire string, uppercasing the letters */
625 for (String = SrcString; *String; )
627 *String = (char) ACPI_TOUPPER (*String);
634 /*******************************************************************************
636 * FUNCTION: AcpiUtMutexInitialize
642 * DESCRIPTION: Create the system mutex objects.
644 ******************************************************************************/
647 AcpiUtMutexInitialize (
654 ACPI_FUNCTION_TRACE ("UtMutexInitialize");
658 * Create each of the predefined mutex objects
660 for (i = 0; i < NUM_MTX; i++)
662 Status = AcpiUtCreateMutex (i);
663 if (ACPI_FAILURE (Status))
665 return_ACPI_STATUS (Status);
669 return_ACPI_STATUS (AE_OK);
673 /*******************************************************************************
675 * FUNCTION: AcpiUtMutexTerminate
681 * DESCRIPTION: Delete all of the system mutex objects.
683 ******************************************************************************/
686 AcpiUtMutexTerminate (
692 ACPI_FUNCTION_TRACE ("UtMutexTerminate");
696 * Delete each predefined mutex object
698 for (i = 0; i < NUM_MTX; i++)
700 (void) AcpiUtDeleteMutex (i);
707 /*******************************************************************************
709 * FUNCTION: AcpiUtCreateMutex
711 * PARAMETERS: MutexID - ID of the mutex to be created
715 * DESCRIPTION: Create a mutex object.
717 ******************************************************************************/
721 ACPI_MUTEX_HANDLE MutexId)
723 ACPI_STATUS Status = AE_OK;
726 ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId);
729 if (MutexId > MAX_MTX)
731 return_ACPI_STATUS (AE_BAD_PARAMETER);
734 if (!AcpiGbl_AcpiMutexInfo[MutexId].Mutex)
736 Status = AcpiOsCreateSemaphore (1, 1,
737 &AcpiGbl_AcpiMutexInfo[MutexId].Mutex);
738 AcpiGbl_AcpiMutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
739 AcpiGbl_AcpiMutexInfo[MutexId].UseCount = 0;
742 return_ACPI_STATUS (Status);
746 /*******************************************************************************
748 * FUNCTION: AcpiUtDeleteMutex
750 * PARAMETERS: MutexID - ID of the mutex to be deleted
754 * DESCRIPTION: Delete a mutex object.
756 ******************************************************************************/
760 ACPI_MUTEX_HANDLE MutexId)
765 ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId);
768 if (MutexId > MAX_MTX)
770 return_ACPI_STATUS (AE_BAD_PARAMETER);
773 Status = AcpiOsDeleteSemaphore (AcpiGbl_AcpiMutexInfo[MutexId].Mutex);
775 AcpiGbl_AcpiMutexInfo[MutexId].Mutex = NULL;
776 AcpiGbl_AcpiMutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
778 return_ACPI_STATUS (Status);
782 /*******************************************************************************
784 * FUNCTION: AcpiUtAcquireMutex
786 * PARAMETERS: MutexID - ID of the mutex to be acquired
790 * DESCRIPTION: Acquire a mutex object.
792 ******************************************************************************/
796 ACPI_MUTEX_HANDLE MutexId)
803 ACPI_FUNCTION_NAME ("UtAcquireMutex");
806 if (MutexId > MAX_MTX)
808 return (AE_BAD_PARAMETER);
811 ThisThreadId = AcpiOsGetThreadId ();
814 * Deadlock prevention. Check if this thread owns any mutexes of value
815 * greater than or equal to this one. If so, the thread has violated
816 * the mutex ordering rule. This indicates a coding error somewhere in
817 * the ACPI subsystem code.
819 for (i = MutexId; i < MAX_MTX; i++)
821 if (AcpiGbl_AcpiMutexInfo[i].OwnerId == ThisThreadId)
825 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
826 "Mutex [%s] already acquired by this thread [%X]\n",
827 AcpiUtGetMutexName (MutexId), ThisThreadId));
829 return (AE_ALREADY_ACQUIRED);
832 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
833 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
834 ThisThreadId, AcpiUtGetMutexName (i),
835 AcpiUtGetMutexName (MutexId)));
837 return (AE_ACQUIRE_DEADLOCK);
841 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
842 "Thread %X attempting to acquire Mutex [%s]\n",
843 ThisThreadId, AcpiUtGetMutexName (MutexId)));
845 Status = AcpiOsWaitSemaphore (AcpiGbl_AcpiMutexInfo[MutexId].Mutex,
846 1, ACPI_WAIT_FOREVER);
847 if (ACPI_SUCCESS (Status))
849 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
850 ThisThreadId, AcpiUtGetMutexName (MutexId)));
852 AcpiGbl_AcpiMutexInfo[MutexId].UseCount++;
853 AcpiGbl_AcpiMutexInfo[MutexId].OwnerId = ThisThreadId;
857 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n",
858 ThisThreadId, AcpiUtGetMutexName (MutexId),
859 AcpiFormatException (Status)));
866 /*******************************************************************************
868 * FUNCTION: AcpiUtReleaseMutex
870 * PARAMETERS: MutexID - ID of the mutex to be released
874 * DESCRIPTION: Release a mutex object.
876 ******************************************************************************/
880 ACPI_MUTEX_HANDLE MutexId)
887 ACPI_FUNCTION_NAME ("UtReleaseMutex");
890 ThisThreadId = AcpiOsGetThreadId ();
891 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
892 "Thread %X releasing Mutex [%s]\n", ThisThreadId,
893 AcpiUtGetMutexName (MutexId)));
895 if (MutexId > MAX_MTX)
897 return (AE_BAD_PARAMETER);
901 * Mutex must be acquired in order to release it!
903 if (AcpiGbl_AcpiMutexInfo[MutexId].OwnerId == ACPI_MUTEX_NOT_ACQUIRED)
905 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
906 "Mutex [%s] is not acquired, cannot release\n",
907 AcpiUtGetMutexName (MutexId)));
909 return (AE_NOT_ACQUIRED);
913 * Deadlock prevention. Check if this thread owns any mutexes of value
914 * greater than this one. If so, the thread has violated the mutex
915 * ordering rule. This indicates a coding error somewhere in
916 * the ACPI subsystem code.
918 for (i = MutexId; i < MAX_MTX; i++)
920 if (AcpiGbl_AcpiMutexInfo[i].OwnerId == ThisThreadId)
927 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
928 "Invalid release order: owns [%s], releasing [%s]\n",
929 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
931 return (AE_RELEASE_DEADLOCK);
935 /* Mark unlocked FIRST */
937 AcpiGbl_AcpiMutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
939 Status = AcpiOsSignalSemaphore (AcpiGbl_AcpiMutexInfo[MutexId].Mutex, 1);
941 if (ACPI_FAILURE (Status))
943 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n",
944 ThisThreadId, AcpiUtGetMutexName (MutexId),
945 AcpiFormatException (Status)));
949 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
950 ThisThreadId, AcpiUtGetMutexName (MutexId)));
957 /*******************************************************************************
959 * FUNCTION: AcpiUtCreateUpdateStateAndPush
961 * PARAMETERS: *Object - Object to be added to the new state
962 * Action - Increment/Decrement
963 * StateList - List the state will be added to
967 * DESCRIPTION: Create a new state and push it
969 ******************************************************************************/
972 AcpiUtCreateUpdateStateAndPush (
973 ACPI_OPERAND_OBJECT *Object,
975 ACPI_GENERIC_STATE **StateList)
977 ACPI_GENERIC_STATE *State;
980 ACPI_FUNCTION_ENTRY ();
983 /* Ignore null objects; these are expected */
990 State = AcpiUtCreateUpdateState (Object, Action);
993 return (AE_NO_MEMORY);
996 AcpiUtPushGenericState (StateList, State);
1001 /*******************************************************************************
1003 * FUNCTION: AcpiUtCreatePkgStateAndPush
1005 * PARAMETERS: *Object - Object to be added to the new state
1006 * Action - Increment/Decrement
1007 * StateList - List the state will be added to
1011 * DESCRIPTION: Create a new state and push it
1013 ******************************************************************************/
1016 AcpiUtCreatePkgStateAndPush (
1017 void *InternalObject,
1018 void *ExternalObject,
1020 ACPI_GENERIC_STATE **StateList)
1022 ACPI_GENERIC_STATE *State;
1025 ACPI_FUNCTION_ENTRY ();
1028 State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
1031 return (AE_NO_MEMORY);
1034 AcpiUtPushGenericState (StateList, State);
1039 /*******************************************************************************
1041 * FUNCTION: AcpiUtPushGenericState
1043 * PARAMETERS: ListHead - Head of the state stack
1044 * State - State object to push
1048 * DESCRIPTION: Push a state object onto a state stack
1050 ******************************************************************************/
1053 AcpiUtPushGenericState (
1054 ACPI_GENERIC_STATE **ListHead,
1055 ACPI_GENERIC_STATE *State)
1057 ACPI_FUNCTION_TRACE ("UtPushGenericState");
1060 /* Push the state object onto the front of the list (stack) */
1062 State->Common.Next = *ListHead;
1069 /*******************************************************************************
1071 * FUNCTION: AcpiUtPopGenericState
1073 * PARAMETERS: ListHead - Head of the state stack
1077 * DESCRIPTION: Pop a state object from a state stack
1079 ******************************************************************************/
1081 ACPI_GENERIC_STATE *
1082 AcpiUtPopGenericState (
1083 ACPI_GENERIC_STATE **ListHead)
1085 ACPI_GENERIC_STATE *State;
1088 ACPI_FUNCTION_TRACE ("UtPopGenericState");
1091 /* Remove the state object at the head of the list (stack) */
1096 /* Update the list head */
1098 *ListHead = State->Common.Next;
1105 /*******************************************************************************
1107 * FUNCTION: AcpiUtCreateGenericState
1113 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1114 * the global state cache; If none available, create a new one.
1116 ******************************************************************************/
1118 ACPI_GENERIC_STATE *
1119 AcpiUtCreateGenericState (void)
1121 ACPI_GENERIC_STATE *State;
1124 ACPI_FUNCTION_ENTRY ();
1127 State = AcpiUtAcquireFromCache (ACPI_MEM_LIST_STATE);
1133 State->Common.DataType = ACPI_DESC_TYPE_STATE;
1140 /*******************************************************************************
1142 * FUNCTION: AcpiUtCreateThreadState
1146 * RETURN: Thread State
1148 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1149 * to track per-thread info during method execution
1151 ******************************************************************************/
1154 AcpiUtCreateThreadState (
1157 ACPI_GENERIC_STATE *State;
1160 ACPI_FUNCTION_TRACE ("UtCreateThreadState");
1163 /* Create the generic state object */
1165 State = AcpiUtCreateGenericState ();
1171 /* Init fields specific to the update struct */
1173 State->Common.DataType = ACPI_DESC_TYPE_STATE_THREAD;
1174 State->Thread.ThreadId = AcpiOsGetThreadId ();
1176 return_PTR ((ACPI_THREAD_STATE *) State);
1180 /*******************************************************************************
1182 * FUNCTION: AcpiUtCreateUpdateState
1184 * PARAMETERS: Object - Initial Object to be installed in the
1186 * Action - Update action to be performed
1190 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1191 * to update reference counts and delete complex objects such
1194 ******************************************************************************/
1196 ACPI_GENERIC_STATE *
1197 AcpiUtCreateUpdateState (
1198 ACPI_OPERAND_OBJECT *Object,
1201 ACPI_GENERIC_STATE *State;
1204 ACPI_FUNCTION_TRACE_PTR ("UtCreateUpdateState", Object);
1207 /* Create the generic state object */
1209 State = AcpiUtCreateGenericState ();
1215 /* Init fields specific to the update struct */
1217 State->Common.DataType = ACPI_DESC_TYPE_STATE_UPDATE;
1218 State->Update.Object = Object;
1219 State->Update.Value = Action;
1225 /*******************************************************************************
1227 * FUNCTION: AcpiUtCreatePkgState
1229 * PARAMETERS: Object - Initial Object to be installed in the
1231 * Action - Update action to be performed
1235 * DESCRIPTION: Create a "Package State"
1237 ******************************************************************************/
1239 ACPI_GENERIC_STATE *
1240 AcpiUtCreatePkgState (
1241 void *InternalObject,
1242 void *ExternalObject,
1245 ACPI_GENERIC_STATE *State;
1248 ACPI_FUNCTION_TRACE_PTR ("UtCreatePkgState", InternalObject);
1251 /* Create the generic state object */
1253 State = AcpiUtCreateGenericState ();
1259 /* Init fields specific to the update struct */
1261 State->Common.DataType = ACPI_DESC_TYPE_STATE_PACKAGE;
1262 State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
1263 State->Pkg.DestObject = ExternalObject;
1264 State->Pkg.Index = Index;
1265 State->Pkg.NumPackages = 1;
1271 /*******************************************************************************
1273 * FUNCTION: AcpiUtCreateControlState
1279 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1280 * to support nested IF/WHILE constructs in the AML.
1282 ******************************************************************************/
1284 ACPI_GENERIC_STATE *
1285 AcpiUtCreateControlState (
1288 ACPI_GENERIC_STATE *State;
1291 ACPI_FUNCTION_TRACE ("UtCreateControlState");
1294 /* Create the generic state object */
1296 State = AcpiUtCreateGenericState ();
1302 /* Init fields specific to the control struct */
1304 State->Common.DataType = ACPI_DESC_TYPE_STATE_CONTROL;
1305 State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1311 /*******************************************************************************
1313 * FUNCTION: AcpiUtDeleteGenericState
1315 * PARAMETERS: State - The state object to be deleted
1319 * DESCRIPTION: Put a state object back into the global state cache. The object
1320 * is not actually freed at this time.
1322 ******************************************************************************/
1325 AcpiUtDeleteGenericState (
1326 ACPI_GENERIC_STATE *State)
1328 ACPI_FUNCTION_TRACE ("UtDeleteGenericState");
1331 AcpiUtReleaseToCache (ACPI_MEM_LIST_STATE, State);
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);
1361 /*******************************************************************************
1363 * FUNCTION: AcpiUtWalkPackageTree
1365 * PARAMETERS: ObjDesc - The Package object on which to resolve refs
1369 * DESCRIPTION: Walk through a package
1371 ******************************************************************************/
1374 AcpiUtWalkPackageTree (
1375 ACPI_OPERAND_OBJECT *SourceObject,
1377 ACPI_PKG_CALLBACK WalkCallback,
1380 ACPI_STATUS Status = AE_OK;
1381 ACPI_GENERIC_STATE *StateList = NULL;
1382 ACPI_GENERIC_STATE *State;
1384 ACPI_OPERAND_OBJECT *ThisSourceObj;
1387 ACPI_FUNCTION_TRACE ("UtWalkPackageTree");
1390 State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1393 return_ACPI_STATUS (AE_NO_MEMORY);
1398 /* Get one element of the package */
1400 ThisIndex = State->Pkg.Index;
1401 ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1402 State->Pkg.SourceObject->Package.Elements[ThisIndex];
1406 * 1) An uninitialized package element. It is completely
1407 * legal to declare a package and leave it uninitialized
1408 * 2) Not an internal object - can be a namespace node instead
1409 * 3) Any type other than a package. Packages are handled in else
1412 if ((!ThisSourceObj) ||
1413 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1414 (ACPI_GET_OBJECT_TYPE (ThisSourceObj) != ACPI_TYPE_PACKAGE))
1416 Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1418 if (ACPI_FAILURE (Status))
1420 return_ACPI_STATUS (Status);
1424 while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1427 * We've handled all of the objects at this level, This means
1428 * that we have just completed a package. That package may
1429 * have contained one or more packages itself.
1431 * Delete this state and pop the previous state (package).
1433 AcpiUtDeleteGenericState (State);
1434 State = AcpiUtPopGenericState (&StateList);
1436 /* Finished when there are no more states */
1441 * We have handled all of the objects in the top level
1442 * package just add the length of the package objects
1445 return_ACPI_STATUS (AE_OK);
1449 * Go back up a level and move the index past the just
1450 * completed package object.
1457 /* This is a subobject of type package */
1459 Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1461 if (ACPI_FAILURE (Status))
1463 return_ACPI_STATUS (Status);
1467 * Push the current state and create a new one
1468 * The callback above returned a new target package object.
1470 AcpiUtPushGenericState (&StateList, State);
1471 State = AcpiUtCreatePkgState (ThisSourceObj,
1472 State->Pkg.ThisTargetObj, 0);
1475 return_ACPI_STATUS (AE_NO_MEMORY);
1480 /* We should never get here */
1482 return_ACPI_STATUS (AE_AML_INTERNAL);
1486 /*******************************************************************************
1488 * FUNCTION: AcpiUtGenerateChecksum
1490 * PARAMETERS: Buffer - Buffer to be scanned
1491 * Length - number of bytes to examine
1495 * DESCRIPTION: Generate a checksum on a raw buffer
1497 ******************************************************************************/
1500 AcpiUtGenerateChecksum (
1505 signed char Sum = 0;
1508 for (i = 0; i < Length; i++)
1510 Sum = (signed char) (Sum + Buffer[i]);
1513 return ((UINT8) (0 - Sum));
1517 /*******************************************************************************
1519 * FUNCTION: AcpiUtGetResourceEndTag
1521 * PARAMETERS: ObjDesc - The resource template buffer object
1523 * RETURN: Pointer to the end tag
1525 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1527 ******************************************************************************/
1531 AcpiUtGetResourceEndTag (
1532 ACPI_OPERAND_OBJECT *ObjDesc)
1539 Buffer = ObjDesc->Buffer.Pointer;
1540 EndBuffer = Buffer + ObjDesc->Buffer.Length;
1542 while (Buffer < EndBuffer)
1544 BufferByte = *Buffer;
1545 if (BufferByte & ACPI_RDESC_TYPE_MASK)
1547 /* Large Descriptor - Length is next 2 bytes */
1549 Buffer += ((*(Buffer+1) | (*(Buffer+2) << 8)) + 3);
1553 /* Small Descriptor. End Tag will be found here */
1555 if ((BufferByte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG)
1557 /* Found the end tag descriptor, all done. */
1562 /* Length is in the header */
1564 Buffer += ((BufferByte & 0x07) + 1);
1568 /* End tag not found */
1574 /*******************************************************************************
1576 * FUNCTION: AcpiUtReportError
1578 * PARAMETERS: ModuleName - Caller's module name (for error output)
1579 * LineNumber - Caller's line number (for error output)
1580 * ComponentId - Caller's component ID (for error output)
1581 * Message - Error message to use on failure
1585 * DESCRIPTION: Print error message
1587 ******************************************************************************/
1597 AcpiOsPrintf ("%8s-%04d: *** Error: ", ModuleName, LineNumber);
1601 /*******************************************************************************
1603 * FUNCTION: AcpiUtReportWarning
1605 * PARAMETERS: ModuleName - Caller's module name (for error output)
1606 * LineNumber - Caller's line number (for error output)
1607 * ComponentId - Caller's component ID (for error output)
1608 * Message - Error message to use on failure
1612 * DESCRIPTION: Print warning message
1614 ******************************************************************************/
1617 AcpiUtReportWarning (
1623 AcpiOsPrintf ("%8s-%04d: *** Warning: ", ModuleName, LineNumber);
1627 /*******************************************************************************
1629 * FUNCTION: AcpiUtReportInfo
1631 * PARAMETERS: ModuleName - Caller's module name (for error output)
1632 * LineNumber - Caller's line number (for error output)
1633 * ComponentId - Caller's component ID (for error output)
1634 * Message - Error message to use on failure
1638 * DESCRIPTION: Print information message
1640 ******************************************************************************/
1649 AcpiOsPrintf ("%8s-%04d: *** Info: ", ModuleName, LineNumber);