diff options
Diffstat (limited to 'sys/contrib/dev/acpica/nsutils.c')
-rw-r--r-- | sys/contrib/dev/acpica/nsutils.c | 315 |
1 files changed, 183 insertions, 132 deletions
diff --git a/sys/contrib/dev/acpica/nsutils.c b/sys/contrib/dev/acpica/nsutils.c index 936843c..56dd713 100644 --- a/sys/contrib/dev/acpica/nsutils.c +++ b/sys/contrib/dev/acpica/nsutils.c @@ -2,7 +2,7 @@ * * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing * parents and siblings and Scope manipulation - * $Revision: 77 $ + * $Revision: 83 $ * *****************************************************************************/ @@ -123,11 +123,11 @@ #include "amlcode.h" #include "actables.h" -#define _COMPONENT NAMESPACE +#define _COMPONENT ACPI_NAMESPACE MODULE_NAME ("nsutils") -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsValidRootPrefix * @@ -137,7 +137,7 @@ * * DESCRIPTION: Check if a character is a valid ACPI Root prefix * - ***************************************************************************/ + ******************************************************************************/ BOOLEAN AcpiNsValidRootPrefix ( @@ -148,7 +148,7 @@ AcpiNsValidRootPrefix ( } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsValidPathSeparator * @@ -158,7 +158,7 @@ AcpiNsValidRootPrefix ( * * DESCRIPTION: Check if a character is a valid ACPI path separator * - ***************************************************************************/ + ******************************************************************************/ BOOLEAN AcpiNsValidPathSeparator ( @@ -169,7 +169,7 @@ AcpiNsValidPathSeparator ( } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsGetType * @@ -177,26 +177,26 @@ AcpiNsValidPathSeparator ( * * RETURN: Type field from Node whose handle is passed * - ***************************************************************************/ + ******************************************************************************/ -OBJECT_TYPE_INTERNAL +ACPI_OBJECT_TYPE8 AcpiNsGetType ( - ACPI_HANDLE handle) + ACPI_NAMESPACE_NODE *Node) { FUNCTION_TRACE ("NsGetType"); - if (!handle) + if (!Node) { - REPORT_WARNING (("NsGetType: Null handle\n")); + REPORT_WARNING (("NsGetType: Null Node ptr")); return_VALUE (ACPI_TYPE_ANY); } - return_VALUE (((ACPI_NAMESPACE_NODE *) handle)->Type); + return_VALUE (Node->Type); } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsLocal * @@ -205,16 +205,16 @@ AcpiNsGetType ( * RETURN: LOCAL if names must be found locally in objects of the * passed type, 0 if enclosing scopes should be searched * - ***************************************************************************/ + ******************************************************************************/ UINT32 AcpiNsLocal ( - OBJECT_TYPE_INTERNAL Type) + ACPI_OBJECT_TYPE8 Type) { FUNCTION_TRACE ("NsLocal"); - if (!AcpiCmValidObjectType (Type)) + if (!AcpiUtValidObjectType (Type)) { /* Type code out of range */ @@ -226,45 +226,33 @@ AcpiNsLocal ( } -/**************************************************************************** +/******************************************************************************* * - * FUNCTION: AcpiNsInternalizeName + * FUNCTION: AcpiNsGetInternalNameLength * - * PARAMETERS: *ExternalName - External representation of name - * **Converted Name - Where to return the resulting - * internal represention of the name + * PARAMETERS: Info - Info struct initialized with the + * external name pointer. * * RETURN: Status * - * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0") - * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) + * DESCRIPTION: Calculate the length of the internal (AML) namestring + * corresponding to the external (ASL) namestring. * - ****************************************************************************/ + ******************************************************************************/ ACPI_STATUS -AcpiNsInternalizeName ( - NATIVE_CHAR *ExternalName, - NATIVE_CHAR **ConvertedName) +AcpiNsGetInternalNameLength ( + ACPI_NAMESTRING_INFO *Info) { - NATIVE_CHAR *Result = NULL; - NATIVE_CHAR *InternalName; - UINT32 NumSegments = 0; - BOOLEAN FullyQualified = FALSE; + NATIVE_CHAR *NextExternalChar; UINT32 i; - UINT32 NumCarats = 0; - - - FUNCTION_TRACE ("NsInternalizeName"); - - - if ((!ExternalName) || - (*ExternalName == 0) || - (!ConvertedName)) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } + NextExternalChar = Info->ExternalName; + Info->NumCarats = 0; + Info->NumSegments = 0; + Info->FullyQualified = FALSE; + /* * For the internal name, the required length is 4 bytes * per segment, plus 1 each for RootPrefix, MultiNamePrefixOp, @@ -274,11 +262,10 @@ AcpiNsInternalizeName ( * strlen() + 1 covers the first NameSeg, which has no * path separator */ - - if (AcpiNsValidRootPrefix (ExternalName[0])) + if (AcpiNsValidRootPrefix (NextExternalChar[0])) { - FullyQualified = TRUE; - ExternalName++; + Info->FullyQualified = TRUE; + NextExternalChar++; } else @@ -287,10 +274,10 @@ AcpiNsInternalizeName ( * Handle Carat prefixes */ - while (*ExternalName == '^') + while (*NextExternalChar == '^') { - NumCarats++; - ExternalName++; + Info->NumCarats++; + NextExternalChar++; } } @@ -300,32 +287,57 @@ AcpiNsInternalizeName ( * with one segment since the segment count is (# separators) * + 1, and zero separators is ok. */ - - if (*ExternalName) + if (*NextExternalChar) { - NumSegments = 1; - for (i = 0; ExternalName[i]; i++) + Info->NumSegments = 1; + for (i = 0; NextExternalChar[i]; i++) { - if (AcpiNsValidPathSeparator (ExternalName[i])) + if (AcpiNsValidPathSeparator (NextExternalChar[i])) { - NumSegments++; + Info->NumSegments++; } } } + Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) + + 4 + Info->NumCarats; - /* We need a segment to store the internal version of the name */ + Info->NextExternalChar = NextExternalChar; + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiNsBuildInternalName + * + * PARAMETERS: Info - Info struct fully initialized + * + * RETURN: Status + * + * DESCRIPTION: Construct the internal (AML) namestring + * corresponding to the external (ASL) namestring. + * + ******************************************************************************/ + +ACPI_STATUS +AcpiNsBuildInternalName ( + ACPI_NAMESTRING_INFO *Info) +{ + UINT32 NumSegments = Info->NumSegments; + NATIVE_CHAR *InternalName = Info->InternalName; + NATIVE_CHAR *ExternalName = Info->NextExternalChar; + NATIVE_CHAR *Result = NULL; + UINT32 i; - InternalName = AcpiCmCallocate ((ACPI_NAME_SIZE * NumSegments) + 4 + NumCarats); - if (!InternalName) - { - return_ACPI_STATUS (AE_NO_MEMORY); - } + FUNCTION_TRACE ("AcpiNsBuildInternalName"); + /* Setup the correct prefixes, counts, and pointers */ - if (FullyQualified) + if (Info->FullyQualified) { InternalName[0] = '\\'; @@ -344,7 +356,6 @@ AcpiNsInternalizeName ( InternalName[2] = (char) NumSegments; Result = &InternalName[3]; } - } else @@ -353,11 +364,10 @@ AcpiNsInternalizeName ( * Not fully qualified. * Handle Carats first, then append the name segments */ - i = 0; - if (NumCarats) + if (Info->NumCarats) { - for (i = 0; i < NumCarats; i++) + for (i = 0; i < Info->NumCarats; i++) { InternalName[i] = '^'; } @@ -392,22 +402,18 @@ AcpiNsInternalizeName ( if (AcpiNsValidPathSeparator (*ExternalName) || (*ExternalName == 0)) { - /* - * Pad the segment with underscore(s) if - * segment is short - */ + /* Pad the segment with underscore(s) if segment is short */ Result[i] = '_'; } else { - /* Convert INT8 to uppercase and save it */ + /* Convert the character to uppercase and save it */ Result[i] = (char) TOUPPER (*ExternalName); ExternalName++; } - } /* Now we must have a path separator, or the pathname is bad */ @@ -415,7 +421,6 @@ AcpiNsInternalizeName ( if (!AcpiNsValidPathSeparator (*ExternalName) && (*ExternalName != 0)) { - AcpiCmFree (InternalName); return_ACPI_STATUS (AE_BAD_PARAMETER); } @@ -426,23 +431,18 @@ AcpiNsInternalizeName ( } - /* Return the completed name */ + /* Terminate the string */ - /* Terminate the string! */ *Result = 0; - *ConvertedName = InternalName; - - if (FullyQualified) + if (Info->FullyQualified) { - DEBUG_PRINT (TRACE_EXEC, - ("NsInternalizeName: returning [%p] (abs) \"\\%s\"\n", + DEBUG_PRINTP (TRACE_EXEC, ("returning [%p] (abs) \"\\%s\"\n", InternalName, &InternalName[0])); } else { - DEBUG_PRINT (TRACE_EXEC, - ("NsInternalizeName: returning [%p] (rel) \"%s\"\n", + DEBUG_PRINTP (TRACE_EXEC, ("returning [%p] (rel) \"%s\"\n", InternalName, &InternalName[2])); } @@ -450,20 +450,84 @@ AcpiNsInternalizeName ( } -/**************************************************************************** +/******************************************************************************* + * + * FUNCTION: AcpiNsInternalizeName + * + * PARAMETERS: *ExternalName - External representation of name + * **Converted Name - Where to return the resulting + * internal represention of the name + * + * RETURN: Status + * + * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0") + * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) + * + *******************************************************************************/ + +ACPI_STATUS +AcpiNsInternalizeName ( + NATIVE_CHAR *ExternalName, + NATIVE_CHAR **ConvertedName) +{ + NATIVE_CHAR *InternalName; + ACPI_NAMESTRING_INFO Info; + ACPI_STATUS Status; + + + FUNCTION_TRACE ("NsInternalizeName"); + + + if ((!ExternalName) || + (*ExternalName == 0) || + (!ConvertedName)) + { + return_ACPI_STATUS (AE_BAD_PARAMETER); + } + + + /* Get the length of the new internal name */ + + Info.ExternalName = ExternalName; + AcpiNsGetInternalNameLength (&Info); + + /* We need a segment to store the internal name */ + + InternalName = AcpiUtCallocate (Info.Length); + if (!InternalName) + { + return_ACPI_STATUS (AE_NO_MEMORY); + } + + /* Build the name */ + + Info.InternalName = InternalName; + Status = AcpiNsBuildInternalName (&Info); + if (ACPI_FAILURE (Status)) + { + AcpiUtFree (InternalName); + return_ACPI_STATUS (Status); + } + + *ConvertedName = InternalName; + return_ACPI_STATUS (AE_OK); +} + + +/******************************************************************************* * * FUNCTION: AcpiNsExternalizeName * * PARAMETERS: *InternalName - Internal representation of name * **ConvertedName - Where to return the resulting - * external representation of name + * external representation of name * * RETURN: Status * * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) * to its external form (e.g. "\_PR_.CPU0") * - ****************************************************************************/ + ******************************************************************************/ ACPI_STATUS AcpiNsExternalizeName ( @@ -581,7 +645,7 @@ AcpiNsExternalizeName ( * Build ConvertedName... */ - (*ConvertedName) = AcpiCmCallocate (*ConvertedNameLength); + (*ConvertedName) = AcpiUtCallocate (*ConvertedNameLength); if (!(*ConvertedName)) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -614,7 +678,7 @@ AcpiNsExternalizeName ( } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsConvertHandleToEntry * @@ -624,7 +688,7 @@ AcpiNsExternalizeName ( * * DESCRIPTION: Convert a namespace handle to a real Node * - ****************************************************************************/ + ******************************************************************************/ ACPI_NAMESPACE_NODE * AcpiNsConvertHandleToEntry ( @@ -636,7 +700,6 @@ AcpiNsConvertHandleToEntry ( * TBD: [Future] Real integer handles allow for more verification * and keep all pointers within this subsystem! */ - if (!Handle) { return (NULL); @@ -659,7 +722,7 @@ AcpiNsConvertHandleToEntry ( } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsConvertEntryToHandle * @@ -669,7 +732,7 @@ AcpiNsConvertHandleToEntry ( * * DESCRIPTION: Convert a real Node to a namespace handle * - ****************************************************************************/ + ******************************************************************************/ ACPI_HANDLE AcpiNsConvertEntryToHandle ( @@ -682,7 +745,6 @@ AcpiNsConvertEntryToHandle ( * TBD: [Future] Real integer handles allow for more verification * and keep all pointers within this subsystem! */ - return ((ACPI_HANDLE) Node); @@ -704,7 +766,7 @@ AcpiNsConvertEntryToHandle ( } -/****************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsTerminate * @@ -730,12 +792,10 @@ AcpiNsTerminate (void) /* * 1) Free the entire namespace -- all objects, tables, and stacks - */ - /* + * * Delete all objects linked to the root * (additional table descriptors) */ - AcpiNsDeleteNamespaceSubtree (ThisNode); /* Detach any object(s) attached to the root */ @@ -744,27 +804,24 @@ AcpiNsTerminate (void) if (ObjDesc) { AcpiNsDetachObject (ThisNode); - AcpiCmRemoveReference (ObjDesc); + AcpiUtRemoveReference (ObjDesc); } AcpiNsDeleteChildren (ThisNode); - - DEBUG_PRINT (ACPI_INFO, ("NsTerminate: Namespace freed\n")); + DEBUG_PRINTP (ACPI_INFO, ("Namespace freed\n")); /* * 2) Now we can delete the ACPI tables */ - AcpiTbDeleteAcpiTables (); - - DEBUG_PRINT (ACPI_INFO, ("NsTerminate: ACPI Tables freed\n")); + DEBUG_PRINTP (ACPI_INFO, ("ACPI Tables freed\n")); return_VOID; } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsOpensScope * @@ -773,16 +830,16 @@ AcpiNsTerminate (void) * RETURN: NEWSCOPE if the passed type "opens a name scope" according * to the ACPI specification, else 0 * - ***************************************************************************/ + ******************************************************************************/ UINT32 AcpiNsOpensScope ( - OBJECT_TYPE_INTERNAL Type) + ACPI_OBJECT_TYPE8 Type) { FUNCTION_TRACE_U32 ("NsOpensScope", Type); - if (!AcpiCmValidObjectType (Type)) + if (!AcpiUtValidObjectType (Type)) { /* type code out of range */ @@ -794,7 +851,7 @@ AcpiNsOpensScope ( } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsGetNode * @@ -812,7 +869,7 @@ AcpiNsOpensScope ( * * MUTEX: Locks namespace * - ***************************************************************************/ + ******************************************************************************/ ACPI_STATUS AcpiNsGetNode ( @@ -850,7 +907,7 @@ AcpiNsGetNode ( } - AcpiCmAcquireMutex (ACPI_MTX_NAMESPACE); + AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); /* Setup lookup scope (search starting point) */ @@ -865,22 +922,21 @@ AcpiNsGetNode ( if (ACPI_FAILURE (Status)) { - DEBUG_PRINT (ACPI_INFO, ("NsGetNode: %s, %s\n", - InternalPath, AcpiCmFormatException (Status))); + DEBUG_PRINTP (ACPI_INFO, ("%s, %s\n", + InternalPath, AcpiUtFormatException (Status))); } - AcpiCmReleaseMutex (ACPI_MTX_NAMESPACE); + AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); /* Cleanup */ - AcpiCmFree (InternalPath); - + AcpiUtFree (InternalPath); return_ACPI_STATUS (Status); } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsFindParentName * @@ -892,7 +948,7 @@ AcpiNsGetNode ( * name segment, or "????" if the parent name can't be found * (which "should not happen"). * - ***************************************************************************/ + ******************************************************************************/ ACPI_NAME AcpiNsFindParentName ( @@ -911,10 +967,8 @@ AcpiNsFindParentName ( ParentNode = AcpiNsGetParentObject (ChildNode); if (ParentNode) { - DEBUG_PRINT (TRACE_EXEC, - ("Parent of %p [%4.4s] is %p [%4.4s]\n", - ChildNode, &ChildNode->Name, ParentNode, - &ParentNode->Name)); + DEBUG_PRINTP (TRACE_EXEC, ("Parent of %p [%4.4s] is %p [%4.4s]\n", + ChildNode, &ChildNode->Name, ParentNode, &ParentNode->Name)); if (ParentNode->Name) { @@ -922,19 +976,17 @@ AcpiNsFindParentName ( } } - DEBUG_PRINT (TRACE_EXEC, - ("FindParentName: unable to find parent of %p (%4.4s)\n", + DEBUG_PRINTP (TRACE_EXEC, ("unable to find parent of %p (%4.4s)\n", ChildNode, &ChildNode->Name)); } - return_VALUE (ACPI_UNKNOWN_NAME); } #if defined(ACPI_DEBUG) || defined(ENABLE_DEBUGGER) -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsExistDownstreamSibling * @@ -948,7 +1000,7 @@ AcpiNsFindParentName ( * line drawing character to use when displaying namespace * trees. * - ***************************************************************************/ + ******************************************************************************/ BOOLEAN AcpiNsExistDownstreamSibling ( @@ -971,7 +1023,7 @@ AcpiNsExistDownstreamSibling ( #endif /* ACPI_DEBUG */ -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsGetParentObject * @@ -981,7 +1033,7 @@ AcpiNsExistDownstreamSibling ( * * DESCRIPTION: Obtain the parent entry for a given entry in the namespace. * - ***************************************************************************/ + ******************************************************************************/ ACPI_NAMESPACE_NODE * @@ -1002,7 +1054,6 @@ AcpiNsGetParentObject ( * This saves putting a parent back pointer in each and * every named object! */ - while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST)) { Node = Node->Peer; @@ -1013,7 +1064,7 @@ AcpiNsGetParentObject ( } -/**************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiNsGetNextValidObject * @@ -1025,7 +1076,7 @@ AcpiNsGetParentObject ( * DESCRIPTION: Find the next valid object within a name table. * Useful for implementing NULL-end-of-list loops. * - ***************************************************************************/ + ******************************************************************************/ ACPI_NAMESPACE_NODE * |