summaryrefslogtreecommitdiffstats
path: root/sys/contrib/dev/acpica/nsnames.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/dev/acpica/nsnames.c')
-rw-r--r--sys/contrib/dev/acpica/nsnames.c236
1 files changed, 106 insertions, 130 deletions
diff --git a/sys/contrib/dev/acpica/nsnames.c b/sys/contrib/dev/acpica/nsnames.c
index 644141c..19059c7 100644
--- a/sys/contrib/dev/acpica/nsnames.c
+++ b/sys/contrib/dev/acpica/nsnames.c
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Module Name: nsnames - Name manipulation and search
- * $Revision: 65 $
+ * $Revision: 74 $
*
******************************************************************************/
@@ -9,7 +9,7 @@
*
* 1. Copyright Notice
*
- * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
+ * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
* All rights reserved.
*
* 2. License
@@ -123,97 +123,127 @@
#define _COMPONENT ACPI_NAMESPACE
- MODULE_NAME ("nsnames")
+ ACPI_MODULE_NAME ("nsnames")
/*******************************************************************************
*
- * FUNCTION: AcpiNsGetTablePathname
+ * FUNCTION: AcpiNsBuildExternalPath
*
- * PARAMETERS: Node - Scope whose name is needed
+ * PARAMETERS: Node - NS node whose pathname is needed
+ * Size - Size of the pathname
+ * *NameBuffer - Where to return the pathname
*
- * RETURN: Pointer to storage containing the fully qualified name of
- * the scope, in Label format (all segments strung together
- * with no separators)
+ * RETURN: Places the pathname into the NameBuffer, in external format
+ * (name segments separated by path separators)
*
- * DESCRIPTION: Used for debug printing in AcpiNsSearchTable().
+ * DESCRIPTION: Generate a full pathaname
*
******************************************************************************/
-NATIVE_CHAR *
-AcpiNsGetTablePathname (
- ACPI_NAMESPACE_NODE *Node)
+void
+AcpiNsBuildExternalPath (
+ ACPI_NAMESPACE_NODE *Node,
+ ACPI_SIZE Size,
+ NATIVE_CHAR *NameBuffer)
{
- NATIVE_CHAR *NameBuffer;
- UINT32 Size;
- ACPI_NAME Name;
- ACPI_NAMESPACE_NODE *ChildNode;
+ UINT32 Index;
ACPI_NAMESPACE_NODE *ParentNode;
- FUNCTION_TRACE_PTR ("NsGetTablePathname", Node);
+ ACPI_FUNCTION_NAME ("NsBuildExternalPath");
- if (!AcpiGbl_RootNode || !Node)
+ /* Special case for root */
+
+ Index = Size - 1;
+ if (Index < ACPI_NAME_SIZE)
{
- /*
- * If the name space has not been initialized,
- * this function should not have been called.
- */
- return_PTR (NULL);
+ NameBuffer[0] = AML_ROOT_PREFIX;
+ NameBuffer[1] = 0;
+ return;
}
- ChildNode = Node->Child;
+ /* Store terminator byte, then build name backwards */
+ ParentNode = Node;
+ NameBuffer[Index] = 0;
- /* Calculate required buffer size based on depth below root */
-
- Size = 1;
- ParentNode = ChildNode;
- while (ParentNode)
+ while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode))
{
- ParentNode = AcpiNsGetParentObject (ParentNode);
- if (ParentNode)
- {
- Size += ACPI_NAME_SIZE;
- }
+ Index -= ACPI_NAME_SIZE;
+
+ /* Put the name into the buffer */
+
+ ACPI_MOVE_UNALIGNED32_TO_32 ((NameBuffer + Index), &ParentNode->Name);
+ ParentNode = AcpiNsGetParentNode (ParentNode);
+
+ /* Prefix name with the path separator */
+
+ Index--;
+ NameBuffer[Index] = PATH_SEPARATOR;
}
+ /* Overwrite final separator with the root prefix character */
- /* Allocate a buffer to be returned to caller */
+ NameBuffer[Index] = AML_ROOT_PREFIX;
- NameBuffer = ACPI_MEM_CALLOCATE (Size + 1);
- if (!NameBuffer)
+ if (Index != 0)
{
- REPORT_ERROR (("NsGetTablePathname: allocation failure\n"));
- return_PTR (NULL);
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
+ "Could not construct pathname; index=%X, size=%X, Path=%s\n",
+ Index, Size, &NameBuffer[Size]));
}
+ return;
+}
- /* Store terminator byte, then build name backwards */
- NameBuffer[Size] = '\0';
- while ((Size > ACPI_NAME_SIZE) &&
- AcpiNsGetParentObject (ChildNode))
- {
- Size -= ACPI_NAME_SIZE;
- Name = AcpiNsFindParentName (ChildNode);
+#ifdef ACPI_DEBUG
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiNsGetExternalPathname
+ *
+ * PARAMETERS: Node - NS node whose pathname is needed
+ *
+ * RETURN: Pointer to storage containing the fully qualified name of
+ * the node, In external format (name segments separated by path
+ * separators.)
+ *
+ * DESCRIPTION: Used for debug printing in AcpiNsSearchTable().
+ *
+ ******************************************************************************/
- /* Put the name into the buffer */
+NATIVE_CHAR *
+AcpiNsGetExternalPathname (
+ ACPI_NAMESPACE_NODE *Node)
+{
+ NATIVE_CHAR *NameBuffer;
+ ACPI_SIZE Size;
- MOVE_UNALIGNED32_TO_32 ((NameBuffer + Size), &Name);
- ChildNode = AcpiNsGetParentObject (ChildNode);
- }
- NameBuffer[--Size] = AML_ROOT_PREFIX;
+ ACPI_FUNCTION_TRACE_PTR ("NsGetExternalPathname", Node);
+
+
+ /* Calculate required buffer size based on depth below root */
- if (Size != 0)
+ Size = AcpiNsGetPathnameLength (Node);
+
+ /* Allocate a buffer to be returned to caller */
+
+ NameBuffer = ACPI_MEM_CALLOCATE (Size);
+ if (!NameBuffer)
{
- ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad pointer returned; size=%X\n", Size));
+ ACPI_REPORT_ERROR (("NsGetTablePathname: allocation failure\n"));
+ return_PTR (NULL);
}
+ /* Build the path in the allocated buffer */
+
+ AcpiNsBuildExternalPath (Node, Size, NameBuffer);
return_PTR (NameBuffer);
}
+#endif
/*******************************************************************************
@@ -228,26 +258,28 @@ AcpiNsGetTablePathname (
*
******************************************************************************/
-UINT32
+ACPI_SIZE
AcpiNsGetPathnameLength (
ACPI_NAMESPACE_NODE *Node)
{
- UINT32 Size;
+ ACPI_SIZE Size;
ACPI_NAMESPACE_NODE *NextNode;
- FUNCTION_ENTRY ();
+ ACPI_FUNCTION_ENTRY ();
/*
* Compute length of pathname as 5 * number of name segments.
* Go back up the parent tree to the root
*/
- for (Size = 0, NextNode = Node;
- AcpiNsGetParentObject (NextNode);
- NextNode = AcpiNsGetParentObject (NextNode))
+ Size = 0;
+ NextNode = Node;
+
+ while (NextNode != AcpiGbl_RootNode)
{
Size += PATH_SEGMENT_LENGTH;
+ NextNode = AcpiNsGetParentNode (NextNode);
}
return (Size + 1);
@@ -260,107 +292,51 @@ AcpiNsGetPathnameLength (
*
* PARAMETERS: TargetHandle - Handle of named object whose name is
* to be found
- * BufSize - Size of the buffer provided
- * UserBuffer - Where the pathname is returned
+ * Buffer - Where the pathname is returned
*
* RETURN: Status, Buffer is filled with pathname if status is AE_OK
*
* DESCRIPTION: Build and return a full namespace pathname
*
- * MUTEX: Locks Namespace
- *
******************************************************************************/
ACPI_STATUS
AcpiNsHandleToPathname (
ACPI_HANDLE TargetHandle,
- UINT32 *BufSize,
- NATIVE_CHAR *UserBuffer)
+ ACPI_BUFFER *Buffer)
{
- ACPI_STATUS Status = AE_OK;
+ ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
- UINT32 PathLength;
- UINT32 UserBufSize;
- ACPI_NAME Name;
- UINT32 Size;
+ ACPI_SIZE RequiredSize;
- FUNCTION_TRACE_PTR ("NsHandleToPathname", TargetHandle);
+ ACPI_FUNCTION_TRACE_PTR ("NsHandleToPathname", TargetHandle);
- if (!AcpiGbl_RootNode)
- {
- /*
- * If the name space has not been initialized,
- * this function should not have been called.
- */
- return_ACPI_STATUS (AE_NO_NAMESPACE);
- }
-
Node = AcpiNsMapHandleToNode (TargetHandle);
if (!Node)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
+ /* Determine size required for the caller buffer */
- /* Set return length to the required path length */
-
- PathLength = AcpiNsGetPathnameLength (Node);
- Size = PathLength - 1;
+ RequiredSize = AcpiNsGetPathnameLength (Node);
- UserBufSize = *BufSize;
- *BufSize = PathLength;
+ /* Validate/Allocate/Clear caller buffer */
- /* Check if the user buffer is sufficiently large */
-
- if (PathLength > UserBufSize)
- {
- Status = AE_BUFFER_OVERFLOW;
- goto Exit;
- }
-
- if (Size < ACPI_NAME_SIZE)
- {
- UserBuffer[0] = '\\';
- UserBuffer[1] = 0;
- goto Exit;
- }
-
- /* Store null terminator */
-
- UserBuffer[Size] = 0;
- Size -= ACPI_NAME_SIZE;
-
- /* Put the original ACPI name at the end of the path */
-
- MOVE_UNALIGNED32_TO_32 ((UserBuffer + Size),
- &Node->Name);
-
- UserBuffer[--Size] = PATH_SEPARATOR;
-
- /* Build name backwards, putting "." between segments */
-
- while ((Size > ACPI_NAME_SIZE) && Node)
+ Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
+ if (ACPI_FAILURE (Status))
{
- Size -= ACPI_NAME_SIZE;
- Name = AcpiNsFindParentName (Node);
- MOVE_UNALIGNED32_TO_32 ((UserBuffer + Size), &Name);
-
- UserBuffer[--Size] = PATH_SEPARATOR;
- Node = AcpiNsGetParentObject (Node);
+ return_ACPI_STATUS (Status);
}
- /*
- * Overlay the "." preceding the first segment with
- * the root name "\"
- */
- UserBuffer[Size] = '\\';
+ /* Build the path in the caller buffer */
- ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Len=%X, %s \n", PathLength, UserBuffer));
+ AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer);
-Exit:
- return_ACPI_STATUS (Status);
+ ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X] \n", (char *) Buffer->Pointer, RequiredSize));
+ return_ACPI_STATUS (AE_OK);
}
OpenPOWER on IntegriCloud