1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
121 #include "acnamesp.h"
124 #define _COMPONENT ACPI_UTILITIES
125 ACPI_MODULE_NAME ("utmisc")
128 /*******************************************************************************
130 * FUNCTION: AcpiUtPrintString
132 * PARAMETERS: String - Null terminated ASCII string
136 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
139 ******************************************************************************/
151 AcpiOsPrintf ("<\"NULL STRING PTR\">");
156 for (i
= 0; String
[i
] && (i
< MaxLength
); i
++)
158 /* Escape sequences */
163 AcpiOsPrintf ("\\a"); /* BELL */
167 AcpiOsPrintf ("\\b"); /* BACKSPACE */
171 AcpiOsPrintf ("\\f"); /* FORMFEED */
175 AcpiOsPrintf ("\\n"); /* LINEFEED */
179 AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
183 AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
187 AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
190 case '\'': /* Single Quote */
191 case '\"': /* Double Quote */
192 case '\\': /* Backslash */
193 AcpiOsPrintf ("\\%c", (int) String
[i
]);
198 /* Check for printable character or hex escape */
200 if (ACPI_IS_PRINT (String
[i
]))
202 /* This is a normal character */
204 AcpiOsPrintf ("%c", (int) String
[i
]);
208 /* All others will be Hex escapes */
210 AcpiOsPrintf ("\\x%2.2X", (INT32
) String
[i
]);
217 if (i
== MaxLength
&& String
[i
])
219 AcpiOsPrintf ("...");
224 /*******************************************************************************
226 * FUNCTION: AcpiUtDwordByteSwap
228 * PARAMETERS: Value - Value to be converted
230 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
232 ******************************************************************************/
235 AcpiUtDwordByteSwap (
251 ACPI_FUNCTION_ENTRY ();
256 Out
.Bytes
[0] = In
.Bytes
[3];
257 Out
.Bytes
[1] = In
.Bytes
[2];
258 Out
.Bytes
[2] = In
.Bytes
[1];
259 Out
.Bytes
[3] = In
.Bytes
[0];
265 /*******************************************************************************
267 * FUNCTION: AcpiUtSetIntegerWidth
269 * PARAMETERS: Revision From DSDT header
273 * DESCRIPTION: Set the global integer bit width based upon the revision
274 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
275 * For Revision 2 and above, Integers are 64 bits. Yes, this
276 * makes a difference.
278 ******************************************************************************/
281 AcpiUtSetIntegerWidth (
287 AcpiGbl_IntegerBitWidth
= 32;
288 AcpiGbl_IntegerNybbleWidth
= 8;
289 AcpiGbl_IntegerByteWidth
= 4;
293 AcpiGbl_IntegerBitWidth
= 64;
294 AcpiGbl_IntegerNybbleWidth
= 16;
295 AcpiGbl_IntegerByteWidth
= 8;
300 #ifdef ACPI_DEBUG_OUTPUT
301 /*******************************************************************************
303 * FUNCTION: AcpiUtDisplayInitPathname
305 * PARAMETERS: ObjHandle - Handle whose pathname will be displayed
306 * Path - Additional path string to be appended.
307 * (NULL if no extra path)
309 * RETURN: ACPI_STATUS
311 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
313 ******************************************************************************/
316 AcpiUtDisplayInitPathname (
318 ACPI_NAMESPACE_NODE
*ObjHandle
,
325 ACPI_FUNCTION_ENTRY ();
328 /* Only print the path if the appropriate debug level is enabled */
330 if (!(AcpiDbgLevel
& ACPI_LV_INIT_NAMES
))
335 /* Get the full pathname to the node */
337 Buffer
.Length
= ACPI_ALLOCATE_LOCAL_BUFFER
;
338 Status
= AcpiNsHandleToPathname (ObjHandle
, &Buffer
);
339 if (ACPI_FAILURE (Status
))
344 /* Print what we're doing */
348 case ACPI_TYPE_METHOD
:
349 AcpiOsPrintf ("Executing ");
353 AcpiOsPrintf ("Initializing ");
357 /* Print the object type and pathname */
359 AcpiOsPrintf ("%-12s %s", AcpiUtGetTypeName (Type
), (char *) Buffer
.Pointer
);
361 /* Extra path is used to append names like _STA, _INI, etc. */
365 AcpiOsPrintf (".%s", Path
);
369 ACPI_MEM_FREE (Buffer
.Pointer
);
374 /*******************************************************************************
376 * FUNCTION: AcpiUtValidAcpiName
378 * PARAMETERS: Character - The character to be examined
380 * RETURN: 1 if Character may appear in a name, else 0
382 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
383 * 1) Upper case alpha
387 ******************************************************************************/
390 AcpiUtValidAcpiName (
393 char *NamePtr
= (char *) &Name
;
398 ACPI_FUNCTION_ENTRY ();
401 for (i
= 0; i
< ACPI_NAME_SIZE
; i
++)
403 Character
= *NamePtr
;
406 if (!((Character
== '_') ||
407 (Character
>= 'A' && Character
<= 'Z') ||
408 (Character
>= '0' && Character
<= '9')))
418 /*******************************************************************************
420 * FUNCTION: AcpiUtValidAcpiCharacter
422 * PARAMETERS: Character - The character to be examined
424 * RETURN: 1 if Character may appear in a name, else 0
426 * DESCRIPTION: Check for a printable character
428 ******************************************************************************/
431 AcpiUtValidAcpiCharacter (
435 ACPI_FUNCTION_ENTRY ();
437 return ((BOOLEAN
) ((Character
== '_') ||
438 (Character
>= 'A' && Character
<= 'Z') ||
439 (Character
>= '0' && Character
<= '9')));
443 /*******************************************************************************
445 * FUNCTION: AcpiUtStrtoul64
447 * PARAMETERS: String - Null terminated string
448 * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE
449 * RetInteger - Where the converted integer is returned
451 * RETURN: Status and Converted value
453 * DESCRIPTION: Convert a string into an unsigned value.
454 * NOTE: Does not support Octal strings, not needed.
456 ******************************************************************************/
462 ACPI_INTEGER
*RetInteger
)
464 UINT32 ThisDigit
= 0;
465 ACPI_INTEGER ReturnValue
= 0;
466 ACPI_INTEGER Quotient
;
469 ACPI_FUNCTION_TRACE ("UtStroul64");
472 if ((!String
) || !(*String
))
486 return_ACPI_STATUS (AE_BAD_PARAMETER
);
489 /* Skip over any white space in the buffer */
491 while (ACPI_IS_SPACE (*String
) || *String
== '\t')
497 * If the input parameter Base is zero, then we need to
498 * determine if it is decimal or hexadecimal:
502 if ((*String
== '0') &&
503 (ACPI_TOLOWER (*(String
+ 1)) == 'x'))
515 * For hexadecimal base, skip over the leading
516 * 0 or 0x, if they are present.
520 (ACPI_TOLOWER (*(String
+ 1)) == 'x'))
525 /* Any string left? */
532 /* Main loop: convert the string to a 64-bit integer */
536 if (ACPI_IS_DIGIT (*String
))
538 /* Convert ASCII 0-9 to Decimal value */
540 ThisDigit
= ((UINT8
) *String
) - '0';
546 /* Digit is out of range */
551 ThisDigit
= (UINT8
) ACPI_TOUPPER (*String
);
552 if (ACPI_IS_XDIGIT ((char) ThisDigit
))
554 /* Convert ASCII Hex char to value */
556 ThisDigit
= ThisDigit
- 'A' + 10;
561 * We allow non-hex chars, just stop now, same as end-of-string.
562 * See ACPI spec, string-to-integer conversion.
568 /* Divide the digit into the correct position */
570 (void) AcpiUtShortDivide ((ACPI_INTEGER_MAX
- (ACPI_INTEGER
) ThisDigit
),
571 Base
, &Quotient
, NULL
);
572 if (ReturnValue
> Quotient
)
578 ReturnValue
+= ThisDigit
;
582 /* All done, normal exit */
584 *RetInteger
= ReturnValue
;
585 return_ACPI_STATUS (AE_OK
);
589 /* Base was set/validated above */
593 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT
);
597 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT
);
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
);
636 /*******************************************************************************
638 * FUNCTION: AcpiUtMutexInitialize
644 * DESCRIPTION: Create the system mutex objects.
646 ******************************************************************************/
649 AcpiUtMutexInitialize (
656 ACPI_FUNCTION_TRACE ("UtMutexInitialize");
660 * Create each of the predefined mutex objects
662 for (i
= 0; i
< NUM_MUTEX
; i
++)
664 Status
= AcpiUtCreateMutex (i
);
665 if (ACPI_FAILURE (Status
))
667 return_ACPI_STATUS (Status
);
671 Status
= AcpiOsCreateLock (&AcpiGbl_GpeLock
);
672 return_ACPI_STATUS (Status
);
676 /*******************************************************************************
678 * FUNCTION: AcpiUtMutexTerminate
684 * DESCRIPTION: Delete all of the system mutex objects.
686 ******************************************************************************/
689 AcpiUtMutexTerminate (
695 ACPI_FUNCTION_TRACE ("UtMutexTerminate");
699 * Delete each predefined mutex object
701 for (i
= 0; i
< NUM_MUTEX
; i
++)
703 (void) AcpiUtDeleteMutex (i
);
706 AcpiOsDeleteLock (AcpiGbl_GpeLock
);
711 /*******************************************************************************
713 * FUNCTION: AcpiUtCreateMutex
715 * PARAMETERS: MutexID - ID of the mutex to be created
719 * DESCRIPTION: Create a mutex object.
721 ******************************************************************************/
725 ACPI_MUTEX_HANDLE MutexId
)
727 ACPI_STATUS Status
= AE_OK
;
730 ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId
);
733 if (MutexId
> MAX_MUTEX
)
735 return_ACPI_STATUS (AE_BAD_PARAMETER
);
738 if (!AcpiGbl_MutexInfo
[MutexId
].Mutex
)
740 Status
= AcpiOsCreateSemaphore (1, 1,
741 &AcpiGbl_MutexInfo
[MutexId
].Mutex
);
742 AcpiGbl_MutexInfo
[MutexId
].OwnerId
= ACPI_MUTEX_NOT_ACQUIRED
;
743 AcpiGbl_MutexInfo
[MutexId
].UseCount
= 0;
746 return_ACPI_STATUS (Status
);
750 /*******************************************************************************
752 * FUNCTION: AcpiUtDeleteMutex
754 * PARAMETERS: MutexID - ID of the mutex to be deleted
758 * DESCRIPTION: Delete a mutex object.
760 ******************************************************************************/
764 ACPI_MUTEX_HANDLE MutexId
)
769 ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId
);
772 if (MutexId
> MAX_MUTEX
)
774 return_ACPI_STATUS (AE_BAD_PARAMETER
);
777 Status
= AcpiOsDeleteSemaphore (AcpiGbl_MutexInfo
[MutexId
].Mutex
);
779 AcpiGbl_MutexInfo
[MutexId
].Mutex
= NULL
;
780 AcpiGbl_MutexInfo
[MutexId
].OwnerId
= ACPI_MUTEX_NOT_ACQUIRED
;
782 return_ACPI_STATUS (Status
);
786 /*******************************************************************************
788 * FUNCTION: AcpiUtAcquireMutex
790 * PARAMETERS: MutexID - ID of the mutex to be acquired
794 * DESCRIPTION: Acquire a mutex object.
796 ******************************************************************************/
800 ACPI_MUTEX_HANDLE MutexId
)
806 ACPI_FUNCTION_NAME ("UtAcquireMutex");
809 if (MutexId
> MAX_MUTEX
)
811 return (AE_BAD_PARAMETER
);
814 ThisThreadId
= AcpiOsGetThreadId ();
816 #ifdef ACPI_MUTEX_DEBUG
820 * Mutex debug code, for internal debugging only.
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
);
851 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
,
852 "Thread %X attempting to acquire Mutex [%s]\n",
853 ThisThreadId
, AcpiUtGetMutexName (MutexId
)));
855 Status
= AcpiOsWaitSemaphore (AcpiGbl_MutexInfo
[MutexId
].Mutex
,
856 1, ACPI_WAIT_FOREVER
);
857 if (ACPI_SUCCESS (Status
))
859 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
, "Thread %X acquired Mutex [%s]\n",
860 ThisThreadId
, AcpiUtGetMutexName (MutexId
)));
862 AcpiGbl_MutexInfo
[MutexId
].UseCount
++;
863 AcpiGbl_MutexInfo
[MutexId
].OwnerId
= ThisThreadId
;
867 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Thread %X could not acquire Mutex [%s] %s\n",
868 ThisThreadId
, AcpiUtGetMutexName (MutexId
),
869 AcpiFormatException (Status
)));
876 /*******************************************************************************
878 * FUNCTION: AcpiUtReleaseMutex
880 * PARAMETERS: MutexID - ID of the mutex to be released
884 * DESCRIPTION: Release a mutex object.
886 ******************************************************************************/
890 ACPI_MUTEX_HANDLE MutexId
)
897 ACPI_FUNCTION_NAME ("UtReleaseMutex");
900 ThisThreadId
= AcpiOsGetThreadId ();
901 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
,
902 "Thread %X releasing Mutex [%s]\n", ThisThreadId
,
903 AcpiUtGetMutexName (MutexId
)));
905 if (MutexId
> MAX_MUTEX
)
907 return (AE_BAD_PARAMETER
);
911 * Mutex must be acquired in order to release it!
913 if (AcpiGbl_MutexInfo
[MutexId
].OwnerId
== ACPI_MUTEX_NOT_ACQUIRED
)
915 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
916 "Mutex [%s] is not acquired, cannot release\n",
917 AcpiUtGetMutexName (MutexId
)));
919 return (AE_NOT_ACQUIRED
);
923 * Deadlock prevention. Check if this thread owns any mutexes of value
924 * greater than this one. If so, the thread has violated the mutex
925 * ordering rule. This indicates a coding error somewhere in
926 * the ACPI subsystem code.
928 for (i
= MutexId
; i
< MAX_MUTEX
; i
++)
930 if (AcpiGbl_MutexInfo
[i
].OwnerId
== ThisThreadId
)
937 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
938 "Invalid release order: owns [%s], releasing [%s]\n",
939 AcpiUtGetMutexName (i
), AcpiUtGetMutexName (MutexId
)));
941 return (AE_RELEASE_DEADLOCK
);
945 /* Mark unlocked FIRST */
947 AcpiGbl_MutexInfo
[MutexId
].OwnerId
= ACPI_MUTEX_NOT_ACQUIRED
;
949 Status
= AcpiOsSignalSemaphore (AcpiGbl_MutexInfo
[MutexId
].Mutex
, 1);
951 if (ACPI_FAILURE (Status
))
953 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Thread %X could not release Mutex [%s] %s\n",
954 ThisThreadId
, AcpiUtGetMutexName (MutexId
),
955 AcpiFormatException (Status
)));
959 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX
, "Thread %X released Mutex [%s]\n",
960 ThisThreadId
, AcpiUtGetMutexName (MutexId
)));
967 /*******************************************************************************
969 * FUNCTION: AcpiUtCreateUpdateStateAndPush
971 * PARAMETERS: *Object - Object to be added to the new state
972 * Action - Increment/Decrement
973 * StateList - List the state will be added to
977 * DESCRIPTION: Create a new state and push it
979 ******************************************************************************/
982 AcpiUtCreateUpdateStateAndPush (
983 ACPI_OPERAND_OBJECT
*Object
,
985 ACPI_GENERIC_STATE
**StateList
)
987 ACPI_GENERIC_STATE
*State
;
990 ACPI_FUNCTION_ENTRY ();
993 /* Ignore null objects; these are expected */
1000 State
= AcpiUtCreateUpdateState (Object
, Action
);
1003 return (AE_NO_MEMORY
);
1006 AcpiUtPushGenericState (StateList
, State
);
1011 /*******************************************************************************
1013 * FUNCTION: AcpiUtCreatePkgStateAndPush
1015 * PARAMETERS: *Object - Object to be added to the new state
1016 * Action - Increment/Decrement
1017 * StateList - List the state will be added to
1021 * DESCRIPTION: Create a new state and push it
1023 ******************************************************************************/
1026 AcpiUtCreatePkgStateAndPush (
1027 void *InternalObject
,
1028 void *ExternalObject
,
1030 ACPI_GENERIC_STATE
**StateList
)
1032 ACPI_GENERIC_STATE
*State
;
1035 ACPI_FUNCTION_ENTRY ();
1038 State
= AcpiUtCreatePkgState (InternalObject
, ExternalObject
, Index
);
1041 return (AE_NO_MEMORY
);
1044 AcpiUtPushGenericState (StateList
, State
);
1049 /*******************************************************************************
1051 * FUNCTION: AcpiUtPushGenericState
1053 * PARAMETERS: ListHead - Head of the state stack
1054 * State - State object to push
1058 * DESCRIPTION: Push a state object onto a state stack
1060 ******************************************************************************/
1063 AcpiUtPushGenericState (
1064 ACPI_GENERIC_STATE
**ListHead
,
1065 ACPI_GENERIC_STATE
*State
)
1067 ACPI_FUNCTION_TRACE ("UtPushGenericState");
1070 /* Push the state object onto the front of the list (stack) */
1072 State
->Common
.Next
= *ListHead
;
1079 /*******************************************************************************
1081 * FUNCTION: AcpiUtPopGenericState
1083 * PARAMETERS: ListHead - Head of the state stack
1087 * DESCRIPTION: Pop a state object from a state stack
1089 ******************************************************************************/
1091 ACPI_GENERIC_STATE
*
1092 AcpiUtPopGenericState (
1093 ACPI_GENERIC_STATE
**ListHead
)
1095 ACPI_GENERIC_STATE
*State
;
1098 ACPI_FUNCTION_TRACE ("UtPopGenericState");
1101 /* Remove the state object at the head of the list (stack) */
1106 /* Update the list head */
1108 *ListHead
= State
->Common
.Next
;
1115 /*******************************************************************************
1117 * FUNCTION: AcpiUtCreateGenericState
1123 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1124 * the global state cache; If none available, create a new one.
1126 ******************************************************************************/
1128 ACPI_GENERIC_STATE
*
1129 AcpiUtCreateGenericState (void)
1131 ACPI_GENERIC_STATE
*State
;
1134 ACPI_FUNCTION_ENTRY ();
1137 State
= AcpiUtAcquireFromCache (ACPI_MEM_LIST_STATE
);
1143 State
->Common
.DataType
= ACPI_DESC_TYPE_STATE
;
1150 /*******************************************************************************
1152 * FUNCTION: AcpiUtCreateThreadState
1156 * RETURN: Thread State
1158 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1159 * to track per-thread info during method execution
1161 ******************************************************************************/
1164 AcpiUtCreateThreadState (
1167 ACPI_GENERIC_STATE
*State
;
1170 ACPI_FUNCTION_TRACE ("UtCreateThreadState");
1173 /* Create the generic state object */
1175 State
= AcpiUtCreateGenericState ();
1181 /* Init fields specific to the update struct */
1183 State
->Common
.DataType
= ACPI_DESC_TYPE_STATE_THREAD
;
1184 State
->Thread
.ThreadId
= AcpiOsGetThreadId ();
1186 return_PTR ((ACPI_THREAD_STATE
*) State
);
1190 /*******************************************************************************
1192 * FUNCTION: AcpiUtCreateUpdateState
1194 * PARAMETERS: Object - Initial Object to be installed in the
1196 * Action - Update action to be performed
1200 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1201 * to update reference counts and delete complex objects such
1204 ******************************************************************************/
1206 ACPI_GENERIC_STATE
*
1207 AcpiUtCreateUpdateState (
1208 ACPI_OPERAND_OBJECT
*Object
,
1211 ACPI_GENERIC_STATE
*State
;
1214 ACPI_FUNCTION_TRACE_PTR ("UtCreateUpdateState", Object
);
1217 /* Create the generic state object */
1219 State
= AcpiUtCreateGenericState ();
1225 /* Init fields specific to the update struct */
1227 State
->Common
.DataType
= ACPI_DESC_TYPE_STATE_UPDATE
;
1228 State
->Update
.Object
= Object
;
1229 State
->Update
.Value
= Action
;
1235 /*******************************************************************************
1237 * FUNCTION: AcpiUtCreatePkgState
1239 * PARAMETERS: Object - Initial Object to be installed in the
1241 * Action - Update action to be performed
1245 * DESCRIPTION: Create a "Package State"
1247 ******************************************************************************/
1249 ACPI_GENERIC_STATE
*
1250 AcpiUtCreatePkgState (
1251 void *InternalObject
,
1252 void *ExternalObject
,
1255 ACPI_GENERIC_STATE
*State
;
1258 ACPI_FUNCTION_TRACE_PTR ("UtCreatePkgState", InternalObject
);
1261 /* Create the generic state object */
1263 State
= AcpiUtCreateGenericState ();
1269 /* Init fields specific to the update struct */
1271 State
->Common
.DataType
= ACPI_DESC_TYPE_STATE_PACKAGE
;
1272 State
->Pkg
.SourceObject
= (ACPI_OPERAND_OBJECT
*) InternalObject
;
1273 State
->Pkg
.DestObject
= ExternalObject
;
1274 State
->Pkg
.Index
= Index
;
1275 State
->Pkg
.NumPackages
= 1;
1281 /*******************************************************************************
1283 * FUNCTION: AcpiUtCreateControlState
1289 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1290 * to support nested IF/WHILE constructs in the AML.
1292 ******************************************************************************/
1294 ACPI_GENERIC_STATE
*
1295 AcpiUtCreateControlState (
1298 ACPI_GENERIC_STATE
*State
;
1301 ACPI_FUNCTION_TRACE ("UtCreateControlState");
1304 /* Create the generic state object */
1306 State
= AcpiUtCreateGenericState ();
1312 /* Init fields specific to the control struct */
1314 State
->Common
.DataType
= ACPI_DESC_TYPE_STATE_CONTROL
;
1315 State
->Common
.State
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
1321 /*******************************************************************************
1323 * FUNCTION: AcpiUtDeleteGenericState
1325 * PARAMETERS: State - The state object to be deleted
1329 * DESCRIPTION: Put a state object back into the global state cache. The object
1330 * is not actually freed at this time.
1332 ******************************************************************************/
1335 AcpiUtDeleteGenericState (
1336 ACPI_GENERIC_STATE
*State
)
1338 ACPI_FUNCTION_TRACE ("UtDeleteGenericState");
1341 AcpiUtReleaseToCache (ACPI_MEM_LIST_STATE
, State
);
1346 #ifdef ACPI_ENABLE_OBJECT_CACHE
1347 /*******************************************************************************
1349 * FUNCTION: AcpiUtDeleteGenericStateCache
1355 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1358 ******************************************************************************/
1361 AcpiUtDeleteGenericStateCache (
1364 ACPI_FUNCTION_TRACE ("UtDeleteGenericStateCache");
1367 AcpiUtDeleteGenericCache (ACPI_MEM_LIST_STATE
);
1373 /*******************************************************************************
1375 * FUNCTION: AcpiUtWalkPackageTree
1377 * PARAMETERS: ObjDesc - The Package object on which to resolve refs
1381 * DESCRIPTION: Walk through a package
1383 ******************************************************************************/
1386 AcpiUtWalkPackageTree (
1387 ACPI_OPERAND_OBJECT
*SourceObject
,
1389 ACPI_PKG_CALLBACK WalkCallback
,
1392 ACPI_STATUS Status
= AE_OK
;
1393 ACPI_GENERIC_STATE
*StateList
= NULL
;
1394 ACPI_GENERIC_STATE
*State
;
1396 ACPI_OPERAND_OBJECT
*ThisSourceObj
;
1399 ACPI_FUNCTION_TRACE ("UtWalkPackageTree");
1402 State
= AcpiUtCreatePkgState (SourceObject
, TargetObject
, 0);
1405 return_ACPI_STATUS (AE_NO_MEMORY
);
1410 /* Get one element of the package */
1412 ThisIndex
= State
->Pkg
.Index
;
1413 ThisSourceObj
= (ACPI_OPERAND_OBJECT
*)
1414 State
->Pkg
.SourceObject
->Package
.Elements
[ThisIndex
];
1418 * 1) An uninitialized package element. It is completely
1419 * legal to declare a package and leave it uninitialized
1420 * 2) Not an internal object - can be a namespace node instead
1421 * 3) Any type other than a package. Packages are handled in else
1424 if ((!ThisSourceObj
) ||
1425 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj
) != ACPI_DESC_TYPE_OPERAND
) ||
1426 (ACPI_GET_OBJECT_TYPE (ThisSourceObj
) != ACPI_TYPE_PACKAGE
))
1428 Status
= WalkCallback (ACPI_COPY_TYPE_SIMPLE
, ThisSourceObj
,
1430 if (ACPI_FAILURE (Status
))
1432 return_ACPI_STATUS (Status
);
1436 while (State
->Pkg
.Index
>= State
->Pkg
.SourceObject
->Package
.Count
)
1439 * We've handled all of the objects at this level, This means
1440 * that we have just completed a package. That package may
1441 * have contained one or more packages itself.
1443 * Delete this state and pop the previous state (package).
1445 AcpiUtDeleteGenericState (State
);
1446 State
= AcpiUtPopGenericState (&StateList
);
1448 /* Finished when there are no more states */
1453 * We have handled all of the objects in the top level
1454 * package just add the length of the package objects
1457 return_ACPI_STATUS (AE_OK
);
1461 * Go back up a level and move the index past the just
1462 * completed package object.
1469 /* This is a subobject of type package */
1471 Status
= WalkCallback (ACPI_COPY_TYPE_PACKAGE
, ThisSourceObj
,
1473 if (ACPI_FAILURE (Status
))
1475 return_ACPI_STATUS (Status
);
1479 * Push the current state and create a new one
1480 * The callback above returned a new target package object.
1482 AcpiUtPushGenericState (&StateList
, State
);
1483 State
= AcpiUtCreatePkgState (ThisSourceObj
,
1484 State
->Pkg
.ThisTargetObj
, 0);
1487 return_ACPI_STATUS (AE_NO_MEMORY
);
1492 /* We should never get here */
1494 return_ACPI_STATUS (AE_AML_INTERNAL
);
1498 /*******************************************************************************
1500 * FUNCTION: AcpiUtGenerateChecksum
1502 * PARAMETERS: Buffer - Buffer to be scanned
1503 * Length - number of bytes to examine
1507 * DESCRIPTION: Generate a checksum on a raw buffer
1509 ******************************************************************************/
1512 AcpiUtGenerateChecksum (
1517 signed char Sum
= 0;
1520 for (i
= 0; i
< Length
; i
++)
1522 Sum
= (signed char) (Sum
+ Buffer
[i
]);
1525 return ((UINT8
) (0 - Sum
));
1529 /*******************************************************************************
1531 * FUNCTION: AcpiUtGetResourceEndTag
1533 * PARAMETERS: ObjDesc - The resource template buffer object
1535 * RETURN: Pointer to the end tag
1537 * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
1539 ******************************************************************************/
1543 AcpiUtGetResourceEndTag (
1544 ACPI_OPERAND_OBJECT
*ObjDesc
)
1551 Buffer
= ObjDesc
->Buffer
.Pointer
;
1552 EndBuffer
= Buffer
+ ObjDesc
->Buffer
.Length
;
1554 while (Buffer
< EndBuffer
)
1556 BufferByte
= *Buffer
;
1557 if (BufferByte
& ACPI_RDESC_TYPE_MASK
)
1559 /* Large Descriptor - Length is next 2 bytes */
1561 Buffer
+= ((*(Buffer
+1) | (*(Buffer
+2) << 8)) + 3);
1565 /* Small Descriptor. End Tag will be found here */
1567 if ((BufferByte
& ACPI_RDESC_SMALL_MASK
) == ACPI_RDESC_TYPE_END_TAG
)
1569 /* Found the end tag descriptor, all done. */
1574 /* Length is in the header */
1576 Buffer
+= ((BufferByte
& 0x07) + 1);
1580 /* End tag not found */
1586 /*******************************************************************************
1588 * FUNCTION: AcpiUtReportError
1590 * PARAMETERS: ModuleName - Caller's module name (for error output)
1591 * LineNumber - Caller's line number (for error output)
1592 * ComponentId - Caller's component ID (for error output)
1593 * Message - Error message to use on failure
1597 * DESCRIPTION: Print error message
1599 ******************************************************************************/
1609 AcpiOsPrintf ("%8s-%04d: *** Error: ", ModuleName
, LineNumber
);
1613 /*******************************************************************************
1615 * FUNCTION: AcpiUtReportWarning
1617 * PARAMETERS: ModuleName - Caller's module name (for error output)
1618 * LineNumber - Caller's line number (for error output)
1619 * ComponentId - Caller's component ID (for error output)
1620 * Message - Error message to use on failure
1624 * DESCRIPTION: Print warning message
1626 ******************************************************************************/
1629 AcpiUtReportWarning (
1635 AcpiOsPrintf ("%8s-%04d: *** Warning: ", ModuleName
, LineNumber
);
1639 /*******************************************************************************
1641 * FUNCTION: AcpiUtReportInfo
1643 * PARAMETERS: ModuleName - Caller's module name (for error output)
1644 * LineNumber - Caller's line number (for error output)
1645 * ComponentId - Caller's component ID (for error output)
1646 * Message - Error message to use on failure
1650 * DESCRIPTION: Print information message
1652 ******************************************************************************/
1661 AcpiOsPrintf ("%8s-%04d: *** Info: ", ModuleName
, LineNumber
);