aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/dev/acpica/utmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/dev/acpica/utmisc.c')
-rw-r--r--sys/contrib/dev/acpica/utmisc.c1152
1 files changed, 375 insertions, 777 deletions
diff --git a/sys/contrib/dev/acpica/utmisc.c b/sys/contrib/dev/acpica/utmisc.c
index 0ebb3bce883e..81b75db05343 100644
--- a/sys/contrib/dev/acpica/utmisc.c
+++ b/sys/contrib/dev/acpica/utmisc.c
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Module Name: utmisc - common utility procedures
- * $Revision: 101 $
+ * $Revision: 1.125 $
*
******************************************************************************/
@@ -9,7 +9,7 @@
*
* 1. Copyright Notice
*
- * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
+ * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
* All rights reserved.
*
* 2. License
@@ -119,6 +119,7 @@
#include <contrib/dev/acpica/acpi.h>
#include <contrib/dev/acpica/acnamesp.h>
+#include <contrib/dev/acpica/amlresrc.h>
#define _COMPONENT ACPI_UTILITIES
@@ -127,9 +128,186 @@
/*******************************************************************************
*
+ * FUNCTION: AcpiUtAllocateOwnerId
+ *
+ * PARAMETERS: OwnerId - Where the new owner ID is returned
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
+ * track objects created by the table or method, to be deleted
+ * when the method exits or the table is unloaded.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtAllocateOwnerId (
+ ACPI_OWNER_ID *OwnerId)
+{
+ ACPI_NATIVE_UINT i;
+ ACPI_STATUS Status;
+
+
+ ACPI_FUNCTION_TRACE ("UtAllocateOwnerId");
+
+
+ /* Guard against multiple allocations of ID to the same location */
+
+ if (*OwnerId)
+ {
+ ACPI_REPORT_ERROR (("Owner ID [%2.2X] already exists\n", *OwnerId));
+ return_ACPI_STATUS (AE_ALREADY_EXISTS);
+ }
+
+ /* Mutex for the global ID mask */
+
+ Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
+ if (ACPI_FAILURE (Status))
+ {
+ return_ACPI_STATUS (Status);
+ }
+
+ /* Find a free owner ID */
+
+ for (i = 0; i < 32; i++)
+ {
+ if (!(AcpiGbl_OwnerIdMask & (1 << i)))
+ {
+ ACPI_DEBUG_PRINT ((ACPI_DB_VALUES,
+ "Current OwnerId mask: %8.8X New ID: %2.2X\n",
+ AcpiGbl_OwnerIdMask, (unsigned int) (i + 1)));
+
+ AcpiGbl_OwnerIdMask |= (1 << i);
+ *OwnerId = (ACPI_OWNER_ID) (i + 1);
+ goto Exit;
+ }
+ }
+
+ /*
+ * If we are here, all OwnerIds have been allocated. This probably should
+ * not happen since the IDs are reused after deallocation. The IDs are
+ * allocated upon table load (one per table) and method execution, and
+ * they are released when a table is unloaded or a method completes
+ * execution.
+ */
+ *OwnerId = 0;
+ Status = AE_OWNER_ID_LIMIT;
+ ACPI_REPORT_ERROR ((
+ "Could not allocate new OwnerId (32 max), AE_OWNER_ID_LIMIT\n"));
+
+Exit:
+ (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
+ return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtReleaseOwnerId
+ *
+ * PARAMETERS: OwnerIdPtr - Pointer to a previously allocated OwnerID
+ *
+ * RETURN: None. No error is returned because we are either exiting a
+ * control method or unloading a table. Either way, we would
+ * ignore any error anyway.
+ *
+ * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 32
+ *
+ ******************************************************************************/
+
+void
+AcpiUtReleaseOwnerId (
+ ACPI_OWNER_ID *OwnerIdPtr)
+{
+ ACPI_OWNER_ID OwnerId = *OwnerIdPtr;
+ ACPI_STATUS Status;
+
+
+ ACPI_FUNCTION_TRACE_U32 ("UtReleaseOwnerId", OwnerId);
+
+
+ /* Always clear the input OwnerId (zero is an invalid ID) */
+
+ *OwnerIdPtr = 0;
+
+ /* Zero is not a valid OwnerID */
+
+ if ((OwnerId == 0) || (OwnerId > 32))
+ {
+ ACPI_REPORT_ERROR (("Invalid OwnerId: %2.2X\n", OwnerId));
+ return_VOID;
+ }
+
+ /* Mutex for the global ID mask */
+
+ Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
+ if (ACPI_FAILURE (Status))
+ {
+ return_VOID;
+ }
+
+ /* Normalize the ID to zero */
+
+ OwnerId--;
+
+ /* Free the owner ID only if it is valid */
+
+ if (AcpiGbl_OwnerIdMask & (1 << OwnerId))
+ {
+ AcpiGbl_OwnerIdMask ^= (1 << OwnerId);
+ }
+
+ (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
+ return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtStrupr (strupr)
+ *
+ * PARAMETERS: SrcString - The source string to convert
+ *
+ * RETURN: None
+ *
+ * DESCRIPTION: Convert string to uppercase
+ *
+ * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
+ *
+ ******************************************************************************/
+
+void
+AcpiUtStrupr (
+ char *SrcString)
+{
+ char *String;
+
+
+ ACPI_FUNCTION_ENTRY ();
+
+
+ if (!SrcString)
+ {
+ return;
+ }
+
+ /* Walk entire string, uppercasing the letters */
+
+ for (String = SrcString; *String; String++)
+ {
+ *String = (char) ACPI_TOUPPER (*String);
+ }
+
+ return;
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: AcpiUtPrintString
*
* PARAMETERS: String - Null terminated ASCII string
+ * MaxLength - Maximum output length
*
* RETURN: None
*
@@ -227,6 +405,8 @@ AcpiUtPrintString (
*
* PARAMETERS: Value - Value to be converted
*
+ * RETURN: UINT32 integer with bytes swapped
+ *
* DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
*
******************************************************************************/
@@ -240,7 +420,6 @@ AcpiUtDwordByteSwap (
UINT32 Value;
UINT8 Bytes[4];
} Out;
-
union
{
UINT32 Value;
@@ -302,7 +481,8 @@ AcpiUtSetIntegerWidth (
*
* FUNCTION: AcpiUtDisplayInitPathname
*
- * PARAMETERS: ObjHandle - Handle whose pathname will be displayed
+ * PARAMETERS: Type - Object type of the node
+ * ObjHandle - Handle whose pathname will be displayed
* Path - Additional path string to be appended.
* (NULL if no extra path)
*
@@ -356,7 +536,8 @@ AcpiUtDisplayInitPathname (
/* Print the object type and pathname */
- AcpiOsPrintf ("%-12s %s", AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
+ AcpiOsPrintf ("%-12s %s",
+ AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
/* Extra path is used to append names like _STA, _INI, etc. */
@@ -375,9 +556,9 @@ AcpiUtDisplayInitPathname (
*
* FUNCTION: AcpiUtValidAcpiName
*
- * PARAMETERS: Character - The character to be examined
+ * PARAMETERS: Name - The name to be examined
*
- * RETURN: 1 if Character may appear in a name, else 0
+ * RETURN: TRUE if the name is valid, FALSE otherwise
*
* DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
* 1) Upper case alpha
@@ -461,7 +642,7 @@ AcpiUtStrtoul64 (
UINT32 Base,
ACPI_INTEGER *RetInteger)
{
- UINT32 ThisDigit;
+ UINT32 ThisDigit = 0;
ACPI_INTEGER ReturnValue = 0;
ACPI_INTEGER Quotient;
@@ -469,6 +650,11 @@ AcpiUtStrtoul64 (
ACPI_FUNCTION_TRACE ("UtStroul64");
+ if ((!String) || !(*String))
+ {
+ goto ErrorExit;
+ }
+
switch (Base)
{
case ACPI_ANY_BASE:
@@ -485,7 +671,7 @@ AcpiUtStrtoul64 (
while (ACPI_IS_SPACE (*String) || *String == '\t')
{
- ++String;
+ String++;
}
/*
@@ -495,10 +681,10 @@ AcpiUtStrtoul64 (
if (Base == 0)
{
if ((*String == '0') &&
- (ACPI_TOLOWER (*(++String)) == 'x'))
+ (ACPI_TOLOWER (*(String + 1)) == 'x'))
{
Base = 16;
- ++String;
+ String += 2;
}
else
{
@@ -510,11 +696,18 @@ AcpiUtStrtoul64 (
* For hexadecimal base, skip over the leading
* 0 or 0x, if they are present.
*/
- if (Base == 16 &&
- *String == '0' &&
- ACPI_TOLOWER (*(++String)) == 'x')
+ if ((Base == 16) &&
+ (*String == '0') &&
+ (ACPI_TOLOWER (*(String + 1)) == 'x'))
{
- String++;
+ String += 2;
+ }
+
+ /* Any string left? */
+
+ if (!(*String))
+ {
+ goto ErrorExit;
}
/* Main loop: convert the string to a 64-bit integer */
@@ -529,8 +722,15 @@ AcpiUtStrtoul64 (
}
else
{
+ if (Base == 10)
+ {
+ /* Digit is out of range */
+
+ goto ErrorExit;
+ }
+
ThisDigit = (UINT8) ACPI_TOUPPER (*String);
- if (ACPI_IS_UPPER ((char) ThisDigit))
+ if (ACPI_IS_XDIGIT ((char) ThisDigit))
{
/* Convert ASCII Hex char to value */
@@ -538,17 +738,14 @@ AcpiUtStrtoul64 (
}
else
{
- goto ErrorExit;
+ /*
+ * We allow non-hex chars, just stop now, same as end-of-string.
+ * See ACPI spec, string-to-integer conversion.
+ */
+ break;
}
}
- /* Check to see if digit is out of range */
-
- if (ThisDigit >= Base)
- {
- goto ErrorExit;
- }
-
/* Divide the digit into the correct position */
(void) AcpiUtShortDivide ((ACPI_INTEGER_MAX - (ACPI_INTEGER) ThisDigit),
@@ -560,9 +757,11 @@ AcpiUtStrtoul64 (
ReturnValue *= Base;
ReturnValue += ThisDigit;
- ++String;
+ String++;
}
+ /* All done, normal exit */
+
*RetInteger = ReturnValue;
return_ACPI_STATUS (AE_OK);
@@ -583,372 +782,13 @@ ErrorExit:
/*******************************************************************************
*
- * FUNCTION: AcpiUtStrupr
- *
- * PARAMETERS: SrcString - The source string to convert to
- *
- * RETURN: SrcString
- *
- * DESCRIPTION: Convert string to uppercase
- *
- ******************************************************************************/
-
-char *
-AcpiUtStrupr (
- char *SrcString)
-{
- char *String;
-
-
- ACPI_FUNCTION_ENTRY ();
-
-
- /* Walk entire string, uppercasing the letters */
-
- for (String = SrcString; *String; )
- {
- *String = (char) ACPI_TOUPPER (*String);
- String++;
- }
-
- return (SrcString);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtMutexInitialize
- *
- * PARAMETERS: None.
- *
- * RETURN: Status
- *
- * DESCRIPTION: Create the system mutex objects.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUtMutexInitialize (
- void)
-{
- UINT32 i;
- ACPI_STATUS Status;
-
-
- ACPI_FUNCTION_TRACE ("UtMutexInitialize");
-
-
- /*
- * Create each of the predefined mutex objects
- */
- for (i = 0; i < NUM_MUTEX; i++)
- {
- Status = AcpiUtCreateMutex (i);
- if (ACPI_FAILURE (Status))
- {
- return_ACPI_STATUS (Status);
- }
- }
-
- Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtMutexTerminate
- *
- * PARAMETERS: None.
- *
- * RETURN: None.
- *
- * DESCRIPTION: Delete all of the system mutex objects.
- *
- ******************************************************************************/
-
-void
-AcpiUtMutexTerminate (
- void)
-{
- UINT32 i;
-
-
- ACPI_FUNCTION_TRACE ("UtMutexTerminate");
-
-
- /*
- * Delete each predefined mutex object
- */
- for (i = 0; i < NUM_MUTEX; i++)
- {
- (void) AcpiUtDeleteMutex (i);
- }
-
- AcpiOsDeleteLock (AcpiGbl_GpeLock);
- return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtCreateMutex
- *
- * PARAMETERS: MutexID - ID of the mutex to be created
- *
- * RETURN: Status
- *
- * DESCRIPTION: Create a mutex object.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUtCreateMutex (
- ACPI_MUTEX_HANDLE MutexId)
-{
- ACPI_STATUS Status = AE_OK;
-
-
- ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId);
-
-
- if (MutexId > MAX_MUTEX)
- {
- return_ACPI_STATUS (AE_BAD_PARAMETER);
- }
-
- if (!AcpiGbl_MutexInfo[MutexId].Mutex)
- {
- Status = AcpiOsCreateSemaphore (1, 1,
- &AcpiGbl_MutexInfo[MutexId].Mutex);
- AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
- AcpiGbl_MutexInfo[MutexId].UseCount = 0;
- }
-
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtDeleteMutex
- *
- * PARAMETERS: MutexID - ID of the mutex to be deleted
- *
- * RETURN: Status
- *
- * DESCRIPTION: Delete a mutex object.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUtDeleteMutex (
- ACPI_MUTEX_HANDLE MutexId)
-{
- ACPI_STATUS Status;
-
-
- ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId);
-
-
- if (MutexId > MAX_MUTEX)
- {
- return_ACPI_STATUS (AE_BAD_PARAMETER);
- }
-
- Status = AcpiOsDeleteSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex);
-
- AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
- AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
-
- return_ACPI_STATUS (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtAcquireMutex
- *
- * PARAMETERS: MutexID - ID of the mutex to be acquired
- *
- * RETURN: Status
- *
- * DESCRIPTION: Acquire a mutex object.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUtAcquireMutex (
- ACPI_MUTEX_HANDLE MutexId)
-{
- ACPI_STATUS Status;
- UINT32 i;
- UINT32 ThisThreadId;
-
-
- ACPI_FUNCTION_NAME ("UtAcquireMutex");
-
-
- if (MutexId > MAX_MUTEX)
- {
- return (AE_BAD_PARAMETER);
- }
-
- ThisThreadId = AcpiOsGetThreadId ();
-
- /*
- * Deadlock prevention. Check if this thread owns any mutexes of value
- * greater than or equal to this one. If so, the thread has violated
- * the mutex ordering rule. This indicates a coding error somewhere in
- * the ACPI subsystem code.
- */
- for (i = MutexId; i < MAX_MUTEX; i++)
- {
- if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
- {
- if (i == MutexId)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
- "Mutex [%s] already acquired by this thread [%X]\n",
- AcpiUtGetMutexName (MutexId), ThisThreadId));
-
- return (AE_ALREADY_ACQUIRED);
- }
-
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
- "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
- ThisThreadId, AcpiUtGetMutexName (i),
- AcpiUtGetMutexName (MutexId)));
-
- return (AE_ACQUIRE_DEADLOCK);
- }
- }
-
- ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
- "Thread %X attempting to acquire Mutex [%s]\n",
- ThisThreadId, AcpiUtGetMutexName (MutexId)));
-
- Status = AcpiOsWaitSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex,
- 1, ACPI_WAIT_FOREVER);
- if (ACPI_SUCCESS (Status))
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
- ThisThreadId, AcpiUtGetMutexName (MutexId)));
-
- AcpiGbl_MutexInfo[MutexId].UseCount++;
- AcpiGbl_MutexInfo[MutexId].OwnerId = ThisThreadId;
- }
- else
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n",
- ThisThreadId, AcpiUtGetMutexName (MutexId),
- AcpiFormatException (Status)));
- }
-
- return (Status);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtReleaseMutex
- *
- * PARAMETERS: MutexID - ID of the mutex to be released
- *
- * RETURN: Status
- *
- * DESCRIPTION: Release a mutex object.
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUtReleaseMutex (
- ACPI_MUTEX_HANDLE MutexId)
-{
- ACPI_STATUS Status;
- UINT32 i;
- UINT32 ThisThreadId;
-
-
- ACPI_FUNCTION_NAME ("UtReleaseMutex");
-
-
- ThisThreadId = AcpiOsGetThreadId ();
- ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
- "Thread %X releasing Mutex [%s]\n", ThisThreadId,
- AcpiUtGetMutexName (MutexId)));
-
- if (MutexId > MAX_MUTEX)
- {
- return (AE_BAD_PARAMETER);
- }
-
- /*
- * Mutex must be acquired in order to release it!
- */
- if (AcpiGbl_MutexInfo[MutexId].OwnerId == ACPI_MUTEX_NOT_ACQUIRED)
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
- "Mutex [%s] is not acquired, cannot release\n",
- AcpiUtGetMutexName (MutexId)));
-
- return (AE_NOT_ACQUIRED);
- }
-
- /*
- * Deadlock prevention. Check if this thread owns any mutexes of value
- * greater than this one. If so, the thread has violated the mutex
- * ordering rule. This indicates a coding error somewhere in
- * the ACPI subsystem code.
- */
- for (i = MutexId; i < MAX_MUTEX; i++)
- {
- if (AcpiGbl_MutexInfo[i].OwnerId == ThisThreadId)
- {
- if (i == MutexId)
- {
- continue;
- }
-
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
- "Invalid release order: owns [%s], releasing [%s]\n",
- AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
-
- return (AE_RELEASE_DEADLOCK);
- }
- }
-
- /* Mark unlocked FIRST */
-
- AcpiGbl_MutexInfo[MutexId].OwnerId = ACPI_MUTEX_NOT_ACQUIRED;
-
- Status = AcpiOsSignalSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex, 1);
-
- if (ACPI_FAILURE (Status))
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n",
- ThisThreadId, AcpiUtGetMutexName (MutexId),
- AcpiFormatException (Status)));
- }
- else
- {
- ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
- ThisThreadId, AcpiUtGetMutexName (MutexId)));
- }
-
- return (Status);
-}
-
-
-/*******************************************************************************
- *
* FUNCTION: AcpiUtCreateUpdateStateAndPush
*
- * PARAMETERS: *Object - Object to be added to the new state
+ * PARAMETERS: Object - Object to be added to the new state
* Action - Increment/Decrement
* StateList - List the state will be added to
*
- * RETURN: None
+ * RETURN: Status
*
* DESCRIPTION: Create a new state and push it
*
@@ -986,369 +826,12 @@ AcpiUtCreateUpdateStateAndPush (
/*******************************************************************************
*
- * FUNCTION: AcpiUtCreatePkgStateAndPush
- *
- * PARAMETERS: *Object - Object to be added to the new state
- * Action - Increment/Decrement
- * StateList - List the state will be added to
- *
- * RETURN: None
- *
- * DESCRIPTION: Create a new state and push it
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiUtCreatePkgStateAndPush (
- void *InternalObject,
- void *ExternalObject,
- UINT16 Index,
- ACPI_GENERIC_STATE **StateList)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_ENTRY ();
-
-
- State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
- if (!State)
- {
- return (AE_NO_MEMORY);
- }
-
- AcpiUtPushGenericState (StateList, State);
- return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtPushGenericState
- *
- * PARAMETERS: ListHead - Head of the state stack
- * State - State object to push
- *
- * RETURN: Status
- *
- * DESCRIPTION: Push a state object onto a state stack
- *
- ******************************************************************************/
-
-void
-AcpiUtPushGenericState (
- ACPI_GENERIC_STATE **ListHead,
- ACPI_GENERIC_STATE *State)
-{
- ACPI_FUNCTION_TRACE ("UtPushGenericState");
-
-
- /* Push the state object onto the front of the list (stack) */
-
- State->Common.Next = *ListHead;
- *ListHead = State;
-
- return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtPopGenericState
- *
- * PARAMETERS: ListHead - Head of the state stack
- *
- * RETURN: Status
- *
- * DESCRIPTION: Pop a state object from a state stack
- *
- ******************************************************************************/
-
-ACPI_GENERIC_STATE *
-AcpiUtPopGenericState (
- ACPI_GENERIC_STATE **ListHead)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_TRACE ("UtPopGenericState");
-
-
- /* Remove the state object at the head of the list (stack) */
-
- State = *ListHead;
- if (State)
- {
- /* Update the list head */
-
- *ListHead = State->Common.Next;
- }
-
- return_PTR (State);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtCreateGenericState
- *
- * PARAMETERS: None
- *
- * RETURN: Status
- *
- * DESCRIPTION: Create a generic state object. Attempt to obtain one from
- * the global state cache; If none available, create a new one.
- *
- ******************************************************************************/
-
-ACPI_GENERIC_STATE *
-AcpiUtCreateGenericState (void)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_ENTRY ();
-
-
- State = AcpiUtAcquireFromCache (ACPI_MEM_LIST_STATE);
-
- /* Initialize */
-
- if (State)
- {
- State->Common.DataType = ACPI_DESC_TYPE_STATE;
- }
-
- return (State);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtCreateThreadState
- *
- * PARAMETERS: None
- *
- * RETURN: Thread State
- *
- * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
- * to track per-thread info during method execution
- *
- ******************************************************************************/
-
-ACPI_THREAD_STATE *
-AcpiUtCreateThreadState (
- void)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_TRACE ("UtCreateThreadState");
-
-
- /* Create the generic state object */
-
- State = AcpiUtCreateGenericState ();
- if (!State)
- {
- return_PTR (NULL);
- }
-
- /* Init fields specific to the update struct */
-
- State->Common.DataType = ACPI_DESC_TYPE_STATE_THREAD;
- State->Thread.ThreadId = AcpiOsGetThreadId ();
-
- return_PTR ((ACPI_THREAD_STATE *) State);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtCreateUpdateState
- *
- * PARAMETERS: Object - Initial Object to be installed in the
- * state
- * Action - Update action to be performed
- *
- * RETURN: Status
- *
- * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
- * to update reference counts and delete complex objects such
- * as packages.
- *
- ******************************************************************************/
-
-ACPI_GENERIC_STATE *
-AcpiUtCreateUpdateState (
- ACPI_OPERAND_OBJECT *Object,
- UINT16 Action)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_TRACE_PTR ("UtCreateUpdateState", Object);
-
-
- /* Create the generic state object */
-
- State = AcpiUtCreateGenericState ();
- if (!State)
- {
- return_PTR (NULL);
- }
-
- /* Init fields specific to the update struct */
-
- State->Common.DataType = ACPI_DESC_TYPE_STATE_UPDATE;
- State->Update.Object = Object;
- State->Update.Value = Action;
-
- return_PTR (State);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtCreatePkgState
- *
- * PARAMETERS: Object - Initial Object to be installed in the
- * state
- * Action - Update action to be performed
- *
- * RETURN: Status
- *
- * DESCRIPTION: Create a "Package State"
- *
- ******************************************************************************/
-
-ACPI_GENERIC_STATE *
-AcpiUtCreatePkgState (
- void *InternalObject,
- void *ExternalObject,
- UINT16 Index)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_TRACE_PTR ("UtCreatePkgState", InternalObject);
-
-
- /* Create the generic state object */
-
- State = AcpiUtCreateGenericState ();
- if (!State)
- {
- return_PTR (NULL);
- }
-
- /* Init fields specific to the update struct */
-
- State->Common.DataType = ACPI_DESC_TYPE_STATE_PACKAGE;
- State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
- State->Pkg.DestObject = ExternalObject;
- State->Pkg.Index = Index;
- State->Pkg.NumPackages = 1;
-
- return_PTR (State);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtCreateControlState
- *
- * PARAMETERS: None
- *
- * RETURN: Status
- *
- * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
- * to support nested IF/WHILE constructs in the AML.
- *
- ******************************************************************************/
-
-ACPI_GENERIC_STATE *
-AcpiUtCreateControlState (
- void)
-{
- ACPI_GENERIC_STATE *State;
-
-
- ACPI_FUNCTION_TRACE ("UtCreateControlState");
-
-
- /* Create the generic state object */
-
- State = AcpiUtCreateGenericState ();
- if (!State)
- {
- return_PTR (NULL);
- }
-
- /* Init fields specific to the control struct */
-
- State->Common.DataType = ACPI_DESC_TYPE_STATE_CONTROL;
- State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
-
- return_PTR (State);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtDeleteGenericState
- *
- * PARAMETERS: State - The state object to be deleted
- *
- * RETURN: Status
- *
- * DESCRIPTION: Put a state object back into the global state cache. The object
- * is not actually freed at this time.
- *
- ******************************************************************************/
-
-void
-AcpiUtDeleteGenericState (
- ACPI_GENERIC_STATE *State)
-{
- ACPI_FUNCTION_TRACE ("UtDeleteGenericState");
-
-
- AcpiUtReleaseToCache (ACPI_MEM_LIST_STATE, State);
- return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: AcpiUtDeleteGenericStateCache
- *
- * PARAMETERS: None
- *
- * RETURN: Status
- *
- * DESCRIPTION: Purge the global state object cache. Used during subsystem
- * termination.
- *
- ******************************************************************************/
-
-void
-AcpiUtDeleteGenericStateCache (
- void)
-{
- ACPI_FUNCTION_TRACE ("UtDeleteGenericStateCache");
-
-
- AcpiUtDeleteGenericCache (ACPI_MEM_LIST_STATE);
- return_VOID;
-}
-
-
-/*******************************************************************************
- *
* FUNCTION: AcpiUtWalkPackageTree
*
- * PARAMETERS: ObjDesc - The Package object on which to resolve refs
+ * PARAMETERS: SourceObject - The package to walk
+ * TargetObject - Target object (if package is being copied)
+ * WalkCallback - Called once for each package element
+ * Context - Passed to the callback function
*
* RETURN: Status
*
@@ -1476,7 +959,7 @@ AcpiUtWalkPackageTree (
* PARAMETERS: Buffer - Buffer to be scanned
* Length - number of bytes to examine
*
- * RETURN: checksum
+ * RETURN: The generated checksum
*
* DESCRIPTION: Generate a checksum on a raw buffer
*
@@ -1502,13 +985,143 @@ AcpiUtGenerateChecksum (
/*******************************************************************************
*
+ * FUNCTION: AcpiUtGetResourceType
+ *
+ * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
+ *
+ * RETURN: The Resource Type with no extraneous bits (except the
+ * Large/Small descriptor bit -- this is left alone)
+ *
+ * DESCRIPTION: Extract the Resource Type/Name from the first byte of
+ * a resource descriptor.
+ *
+ ******************************************************************************/
+
+UINT8
+AcpiUtGetResourceType (
+ void *Aml)
+{
+ ACPI_FUNCTION_ENTRY ();
+
+
+ /*
+ * Byte 0 contains the descriptor name (Resource Type)
+ * Determine if this is a small or large resource
+ */
+ if (*((UINT8 *) Aml) & ACPI_RESOURCE_NAME_LARGE)
+ {
+ /* Large Resource Type -- bits 6:0 contain the name */
+
+ return (*((UINT8 *) Aml));
+ }
+ else
+ {
+ /* Small Resource Type -- bits 6:3 contain the name */
+
+ return ((UINT8) (*((UINT8 *) Aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
+ }
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtGetResourceLength
+ *
+ * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
+ *
+ * RETURN: Byte Length
+ *
+ * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
+ * definition, this does not include the size of the descriptor
+ * header or the length field itself.
+ *
+ ******************************************************************************/
+
+UINT16
+AcpiUtGetResourceLength (
+ void *Aml)
+{
+ UINT16 ResourceLength;
+
+
+ ACPI_FUNCTION_ENTRY ();
+
+
+ /*
+ * Byte 0 contains the descriptor name (Resource Type)
+ * Determine if this is a small or large resource
+ */
+ if (*((UINT8 *) Aml) & ACPI_RESOURCE_NAME_LARGE)
+ {
+ /* Large Resource type -- bytes 1-2 contain the 16-bit length */
+
+ ACPI_MOVE_16_TO_16 (&ResourceLength, &((UINT8 *) Aml)[1]);
+
+ }
+ else
+ {
+ /* Small Resource type -- bits 2:0 of byte 0 contain the length */
+
+ ResourceLength = (UINT16) (*((UINT8 *) Aml) &
+ ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
+ }
+
+ return (ResourceLength);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtGetDescriptorLength
+ *
+ * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
+ *
+ * RETURN: Byte length
+ *
+ * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
+ * length of the descriptor header and the length field itself.
+ * Used to walk descriptor lists.
+ *
+ ******************************************************************************/
+
+UINT32
+AcpiUtGetDescriptorLength (
+ void *Aml)
+{
+ UINT32 DescriptorLength;
+
+
+ ACPI_FUNCTION_ENTRY ();
+
+
+ /* First get the Resource Length (Does not include header length) */
+
+ DescriptorLength = AcpiUtGetResourceLength (Aml);
+
+ /* Determine if this is a small or large resource */
+
+ if (*((UINT8 *) Aml) & ACPI_RESOURCE_NAME_LARGE)
+ {
+ DescriptorLength += sizeof (AML_RESOURCE_LARGE_HEADER);
+ }
+ else
+ {
+ DescriptorLength += sizeof (AML_RESOURCE_SMALL_HEADER);
+ }
+
+ return (DescriptorLength);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: AcpiUtGetResourceEndTag
*
* PARAMETERS: ObjDesc - The resource template buffer object
*
* RETURN: Pointer to the end tag
*
- * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
+ * DESCRIPTION: Find the END_TAG resource descriptor in an AML resource template
*
******************************************************************************/
@@ -1517,41 +1130,30 @@ UINT8 *
AcpiUtGetResourceEndTag (
ACPI_OPERAND_OBJECT *ObjDesc)
{
- UINT8 BufferByte;
- UINT8 *Buffer;
- UINT8 *EndBuffer;
+ UINT8 *Aml;
+ UINT8 *EndAml;
+
+ Aml = ObjDesc->Buffer.Pointer;
+ EndAml = Aml + ObjDesc->Buffer.Length;
- Buffer = ObjDesc->Buffer.Pointer;
- EndBuffer = Buffer + ObjDesc->Buffer.Length;
+ /* Walk the resource template, one descriptor per loop */
- while (Buffer < EndBuffer)
+ while (Aml < EndAml)
{
- BufferByte = *Buffer;
- if (BufferByte & ACPI_RDESC_TYPE_MASK)
+ if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)
{
- /* Large Descriptor - Length is next 2 bytes */
+ /* Found the end_tag descriptor, all done */
- Buffer += ((*(Buffer+1) | (*(Buffer+2) << 8)) + 3);
+ return (Aml);
}
- else
- {
- /* Small Descriptor. End Tag will be found here */
-
- if ((BufferByte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG)
- {
- /* Found the end tag descriptor, all done. */
-
- return (Buffer);
- }
- /* Length is in the header */
+ /* Point to the next resource descriptor */
- Buffer += ((BufferByte & 0x07) + 1);
- }
+ Aml += AcpiUtGetResourceLength (Aml);
}
- /* End tag not found */
+ /* End tag was not found */
return (NULL);
}
@@ -1564,7 +1166,6 @@ AcpiUtGetResourceEndTag (
* PARAMETERS: ModuleName - Caller's module name (for error output)
* LineNumber - Caller's line number (for error output)
* ComponentId - Caller's component ID (for error output)
- * Message - Error message to use on failure
*
* RETURN: None
*
@@ -1579,7 +1180,6 @@ AcpiUtReportError (
UINT32 ComponentId)
{
-
AcpiOsPrintf ("%8s-%04d: *** Error: ", ModuleName, LineNumber);
}
@@ -1591,7 +1191,6 @@ AcpiUtReportError (
* PARAMETERS: ModuleName - Caller's module name (for error output)
* LineNumber - Caller's line number (for error output)
* ComponentId - Caller's component ID (for error output)
- * Message - Error message to use on failure
*
* RETURN: None
*
@@ -1617,7 +1216,6 @@ AcpiUtReportWarning (
* PARAMETERS: ModuleName - Caller's module name (for error output)
* LineNumber - Caller's line number (for error output)
* ComponentId - Caller's component ID (for error output)
- * Message - Error message to use on failure
*
* RETURN: None
*