summaryrefslogtreecommitdiff
path: root/source/components/namespace
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2015-07-20 22:31:50 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2015-07-20 22:31:50 +0000
commit136eac2a0638d3c751b1987603f71a9ae26879fd (patch)
tree1e61df024e8a47b6bc4e25d07f455c9dcd7e2dc8 /source/components/namespace
parentf3bbb1ca6c1b2b877d015a8f5f0c67e48a7a57ae (diff)
Notes
Diffstat (limited to 'source/components/namespace')
-rw-r--r--source/components/namespace/nsnames.c308
-rw-r--r--source/components/namespace/nsparse.c44
-rw-r--r--source/components/namespace/nsutils.c2
-rw-r--r--source/components/namespace/nsxfname.c6
4 files changed, 201 insertions, 159 deletions
diff --git a/source/components/namespace/nsnames.c b/source/components/namespace/nsnames.c
index 22e697b592b7..ea10930d1e4b 100644
--- a/source/components/namespace/nsnames.c
+++ b/source/components/namespace/nsnames.c
@@ -53,82 +53,6 @@
/*******************************************************************************
*
- * FUNCTION: AcpiNsBuildExternalPath
- *
- * PARAMETERS: Node - NS node whose pathname is needed
- * Size - Size of the pathname
- * *NameBuffer - Where to return the pathname
- *
- * RETURN: Status
- * Places the pathname into the NameBuffer, in external format
- * (name segments separated by path separators)
- *
- * DESCRIPTION: Generate a full pathaname
- *
- ******************************************************************************/
-
-ACPI_STATUS
-AcpiNsBuildExternalPath (
- ACPI_NAMESPACE_NODE *Node,
- ACPI_SIZE Size,
- char *NameBuffer)
-{
- ACPI_SIZE Index;
- ACPI_NAMESPACE_NODE *ParentNode;
-
-
- ACPI_FUNCTION_ENTRY ();
-
-
- /* Special case for root */
-
- Index = Size - 1;
- if (Index < ACPI_NAME_SIZE)
- {
- NameBuffer[0] = AML_ROOT_PREFIX;
- NameBuffer[1] = 0;
- return (AE_OK);
- }
-
- /* Store terminator byte, then build name backwards */
-
- ParentNode = Node;
- NameBuffer[Index] = 0;
-
- while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode))
- {
- Index -= ACPI_NAME_SIZE;
-
- /* Put the name into the buffer */
-
- ACPI_MOVE_32_TO_32 ((NameBuffer + Index), &ParentNode->Name);
- ParentNode = ParentNode->Parent;
-
- /* Prefix name with the path separator */
-
- Index--;
- NameBuffer[Index] = ACPI_PATH_SEPARATOR;
- }
-
- /* Overwrite final separator with the root prefix character */
-
- NameBuffer[Index] = AML_ROOT_PREFIX;
-
- if (Index != 0)
- {
- ACPI_ERROR ((AE_INFO,
- "Could not construct external pathname; index=%u, size=%u, Path=%s",
- (UINT32) Index, (UINT32) Size, &NameBuffer[Size]));
-
- return (AE_BAD_PARAMETER);
- }
-
- return (AE_OK);
-}
-
-
-/*******************************************************************************
- *
* FUNCTION: AcpiNsGetExternalPathname
*
* PARAMETERS: Node - Namespace node whose pathname is needed
@@ -146,39 +70,13 @@ char *
AcpiNsGetExternalPathname (
ACPI_NAMESPACE_NODE *Node)
{
- ACPI_STATUS Status;
char *NameBuffer;
- ACPI_SIZE Size;
ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
- /* Calculate required buffer size based on depth below root */
-
- Size = AcpiNsGetPathnameLength (Node);
- if (!Size)
- {
- return_PTR (NULL);
- }
-
- /* Allocate a buffer to be returned to caller */
-
- NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
- if (!NameBuffer)
- {
- ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
- return_PTR (NULL);
- }
-
- /* Build the path in the allocated buffer */
-
- Status = AcpiNsBuildExternalPath (Node, Size, NameBuffer);
- if (ACPI_FAILURE (Status))
- {
- ACPI_FREE (NameBuffer);
- return_PTR (NULL);
- }
+ NameBuffer = AcpiNsGetNormalizedPathname (Node, FALSE);
return_PTR (NameBuffer);
}
@@ -201,38 +99,14 @@ AcpiNsGetPathnameLength (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_SIZE Size;
- ACPI_NAMESPACE_NODE *NextNode;
ACPI_FUNCTION_ENTRY ();
- /*
- * Compute length of pathname as 5 * number of name segments.
- * Go back up the parent tree to the root
- */
- Size = 0;
- NextNode = Node;
+ Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, FALSE);
- while (NextNode && (NextNode != AcpiGbl_RootNode))
- {
- if (ACPI_GET_DESCRIPTOR_TYPE (NextNode) != ACPI_DESC_TYPE_NAMED)
- {
- ACPI_ERROR ((AE_INFO,
- "Invalid Namespace Node (%p) while traversing namespace",
- NextNode));
- return (0);
- }
- Size += ACPI_PATH_SEGMENT_LENGTH;
- NextNode = NextNode->Parent;
- }
-
- if (!Size)
- {
- Size = 1; /* Root node case */
- }
-
- return (Size + 1); /* +1 for null string terminator */
+ return (Size);
}
@@ -243,6 +117,8 @@ AcpiNsGetPathnameLength (
* PARAMETERS: TargetHandle - Handle of named object whose name is
* to be found
* Buffer - Where the pathname is returned
+ * NoTrailing - Remove trailing '_' for each name
+ * segment
*
* RETURN: Status, Buffer is filled with pathname if status is AE_OK
*
@@ -253,7 +129,8 @@ AcpiNsGetPathnameLength (
ACPI_STATUS
AcpiNsHandleToPathname (
ACPI_HANDLE TargetHandle,
- ACPI_BUFFER *Buffer)
+ ACPI_BUFFER *Buffer,
+ BOOLEAN NoTrailing)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
@@ -271,7 +148,7 @@ AcpiNsHandleToPathname (
/* Determine size required for the caller buffer */
- RequiredSize = AcpiNsGetPathnameLength (Node);
+ RequiredSize = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
if (!RequiredSize)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
@@ -287,7 +164,8 @@ AcpiNsHandleToPathname (
/* Build the path in the caller buffer */
- Status = AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer);
+ (void) AcpiNsBuildNormalizedPath (Node, Buffer->Pointer,
+ RequiredSize, NoTrailing);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
@@ -297,3 +175,169 @@ AcpiNsHandleToPathname (
(char *) Buffer->Pointer, (UINT32) RequiredSize));
return_ACPI_STATUS (AE_OK);
}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiNsBuildNormalizedPath
+ *
+ * PARAMETERS: Node - Namespace node
+ * FullPath - Where the path name is returned
+ * PathSize - Size of returned path name buffer
+ * NoTrailing - Remove trailing '_' from each name segment
+ *
+ * RETURN: Return 1 if the AML path is empty, otherwise returning (length
+ * of pathname + 1) which means the 'FullPath' contains a trailing
+ * null.
+ *
+ * DESCRIPTION: Build and return a full namespace pathname.
+ * Note that if the size of 'FullPath' isn't large enough to
+ * contain the namespace node's path name, the actual required
+ * buffer length is returned, and it should be greater than
+ * 'PathSize'. So callers are able to check the returning value
+ * to determine the buffer size of 'FullPath'.
+ *
+ ******************************************************************************/
+
+UINT32
+AcpiNsBuildNormalizedPath (
+ ACPI_NAMESPACE_NODE *Node,
+ char *FullPath,
+ UINT32 PathSize,
+ BOOLEAN NoTrailing)
+{
+ UINT32 Length = 0, i;
+ char Name[ACPI_NAME_SIZE];
+ BOOLEAN DoNoTrailing;
+ char c, *Left, *Right;
+ ACPI_NAMESPACE_NODE *NextNode;
+
+
+ ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath, Node);
+
+
+#define ACPI_PATH_PUT8(Path, Size, Byte, Length) \
+ do { \
+ if ((Length) < (Size)) \
+ { \
+ (Path)[(Length)] = (Byte); \
+ } \
+ (Length)++; \
+ } while (0)
+
+ /*
+ * Make sure the PathSize is correct, so that we don't need to
+ * validate both FullPath and PathSize.
+ */
+ if (!FullPath)
+ {
+ PathSize = 0;
+ }
+
+ if (!Node)
+ {
+ goto BuildTrailingNull;
+ }
+
+ NextNode = Node;
+ while (NextNode && NextNode != AcpiGbl_RootNode)
+ {
+ if (NextNode != Node)
+ {
+ ACPI_PATH_PUT8(FullPath, PathSize, AML_DUAL_NAME_PREFIX, Length);
+ }
+ ACPI_MOVE_32_TO_32 (Name, &NextNode->Name);
+ DoNoTrailing = NoTrailing;
+ for (i = 0; i < 4; i++)
+ {
+ c = Name[4-i-1];
+ if (DoNoTrailing && c != '_')
+ {
+ DoNoTrailing = FALSE;
+ }
+ if (!DoNoTrailing)
+ {
+ ACPI_PATH_PUT8(FullPath, PathSize, c, Length);
+ }
+ }
+ NextNode = NextNode->Parent;
+ }
+ ACPI_PATH_PUT8(FullPath, PathSize, AML_ROOT_PREFIX, Length);
+
+ /* Reverse the path string */
+
+ if (Length <= PathSize)
+ {
+ Left = FullPath;
+ Right = FullPath+Length-1;
+ while (Left < Right)
+ {
+ c = *Left;
+ *Left++ = *Right;
+ *Right-- = c;
+ }
+ }
+
+ /* Append the trailing null */
+
+BuildTrailingNull:
+ ACPI_PATH_PUT8(FullPath, PathSize, '\0', Length);
+
+#undef ACPI_PATH_PUT8
+
+ return_UINT32 (Length);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiNsGetNormalizedPathname
+ *
+ * PARAMETERS: Node - Namespace node whose pathname is needed
+ * NoTrailing - Remove trailing '_' from each name segment
+ *
+ * RETURN: Pointer to storage containing the fully qualified name of
+ * the node, In external format (name segments separated by path
+ * separators.)
+ *
+ * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
+ * for error and debug statements. All trailing '_' will be
+ * removed from the full pathname if 'NoTrailing' is specified..
+ *
+ ******************************************************************************/
+
+char *
+AcpiNsGetNormalizedPathname (
+ ACPI_NAMESPACE_NODE *Node,
+ BOOLEAN NoTrailing)
+{
+ char *NameBuffer;
+ ACPI_SIZE Size;
+
+
+ ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname, Node);
+
+
+ /* Calculate required buffer size based on depth below root */
+
+ Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
+ if (!Size)
+ {
+ return_PTR (NULL);
+ }
+
+ /* Allocate a buffer to be returned to caller */
+
+ NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
+ if (!NameBuffer)
+ {
+ ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
+ return_PTR (NULL);
+ }
+
+ /* Build the path in the allocated buffer */
+
+ (void) AcpiNsBuildNormalizedPath (Node, NameBuffer, Size, NoTrailing);
+
+ return_PTR (NameBuffer);
+}
diff --git a/source/components/namespace/nsparse.c b/source/components/namespace/nsparse.c
index bfc5615ade68..996db01747fb 100644
--- a/source/components/namespace/nsparse.c
+++ b/source/components/namespace/nsparse.c
@@ -84,6 +84,22 @@ AcpiNsOneCompleteParse (
ACPI_FUNCTION_TRACE (NsOneCompleteParse);
+ Status = AcpiGetTableByIndex (TableIndex, &Table);
+ if (ACPI_FAILURE (Status))
+ {
+ return_ACPI_STATUS (Status);
+ }
+
+ /* Table must consist of at least a complete header */
+
+ if (Table->Length < sizeof (ACPI_TABLE_HEADER))
+ {
+ return_ACPI_STATUS (AE_BAD_HEADER);
+ }
+
+ AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
+ AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
+
Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
if (ACPI_FAILURE (Status))
{
@@ -92,7 +108,7 @@ AcpiNsOneCompleteParse (
/* Create and init a Root Node */
- ParseRoot = AcpiPsCreateScopeOp ();
+ ParseRoot = AcpiPsCreateScopeOp (AmlStart);
if (!ParseRoot)
{
return_ACPI_STATUS (AE_NO_MEMORY);
@@ -107,26 +123,12 @@ AcpiNsOneCompleteParse (
return_ACPI_STATUS (AE_NO_MEMORY);
}
- Status = AcpiGetTableByIndex (TableIndex, &Table);
+ Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
+ AmlStart, AmlLength, NULL, (UINT8) PassNumber);
if (ACPI_FAILURE (Status))
{
AcpiDsDeleteWalkState (WalkState);
- AcpiPsFreeOp (ParseRoot);
- return_ACPI_STATUS (Status);
- }
-
- /* Table must consist of at least a complete header */
-
- if (Table->Length < sizeof (ACPI_TABLE_HEADER))
- {
- Status = AE_BAD_HEADER;
- }
- else
- {
- AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
- AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
- Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
- AmlStart, AmlLength, NULL, (UINT8) PassNumber);
+ goto Cleanup;
}
/* Found OSDT table, enable the namespace override feature */
@@ -137,12 +139,6 @@ AcpiNsOneCompleteParse (
WalkState->NamespaceOverride = TRUE;
}
- if (ACPI_FAILURE (Status))
- {
- AcpiDsDeleteWalkState (WalkState);
- goto Cleanup;
- }
-
/* StartNode is the default location to load the table */
if (StartNode && StartNode != AcpiGbl_RootNode)
diff --git a/source/components/namespace/nsutils.c b/source/components/namespace/nsutils.c
index 5335810c6028..83d75d0207ed 100644
--- a/source/components/namespace/nsutils.c
+++ b/source/components/namespace/nsutils.c
@@ -90,7 +90,7 @@ AcpiNsPrintNodePathname (
Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
- Status = AcpiNsHandleToPathname (Node, &Buffer);
+ Status = AcpiNsHandleToPathname (Node, &Buffer, FALSE);
if (ACPI_SUCCESS (Status))
{
if (Message)
diff --git a/source/components/namespace/nsxfname.c b/source/components/namespace/nsxfname.c
index 7f92201843aa..311431b2de84 100644
--- a/source/components/namespace/nsxfname.c
+++ b/source/components/namespace/nsxfname.c
@@ -193,11 +193,13 @@ AcpiGetName (
return (Status);
}
- if (NameType == ACPI_FULL_PATHNAME)
+ if (NameType == ACPI_FULL_PATHNAME ||
+ NameType == ACPI_FULL_PATHNAME_NO_TRAILING)
{
/* Get the full pathname (From the namespace root) */
- Status = AcpiNsHandleToPathname (Handle, Buffer);
+ Status = AcpiNsHandleToPathname (Handle, Buffer,
+ NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE);
return (Status);
}