1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsnames")
54 /*******************************************************************************
56 * FUNCTION: AcpiNsBuildExternalPath
58 * PARAMETERS: Node - NS node whose pathname is needed
59 * Size - Size of the pathname
60 * *NameBuffer - Where to return the pathname
63 * Places the pathname into the NameBuffer, in external format
64 * (name segments separated by path separators)
66 * DESCRIPTION: Generate a full pathaname
68 ******************************************************************************/
71 AcpiNsBuildExternalPath (
72 ACPI_NAMESPACE_NODE *Node,
77 ACPI_NAMESPACE_NODE *ParentNode;
80 ACPI_FUNCTION_ENTRY ();
83 /* Special case for root */
86 if (Index < ACPI_NAME_SIZE)
88 NameBuffer[0] = AML_ROOT_PREFIX;
93 /* Store terminator byte, then build name backwards */
96 NameBuffer[Index] = 0;
98 while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode))
100 Index -= ACPI_NAME_SIZE;
102 /* Put the name into the buffer */
104 ACPI_MOVE_32_TO_32 ((NameBuffer + Index), &ParentNode->Name);
105 ParentNode = ParentNode->Parent;
107 /* Prefix name with the path separator */
110 NameBuffer[Index] = ACPI_PATH_SEPARATOR;
113 /* Overwrite final separator with the root prefix character */
115 NameBuffer[Index] = AML_ROOT_PREFIX;
119 ACPI_ERROR ((AE_INFO,
120 "Could not construct external pathname; index=%u, size=%u, Path=%s",
121 (UINT32) Index, (UINT32) Size, &NameBuffer[Size]));
123 return (AE_BAD_PARAMETER);
130 /*******************************************************************************
132 * FUNCTION: AcpiNsGetExternalPathname
134 * PARAMETERS: Node - Namespace node whose pathname is needed
136 * RETURN: Pointer to storage containing the fully qualified name of
137 * the node, In external format (name segments separated by path
140 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
141 * for error and debug statements.
143 ******************************************************************************/
146 AcpiNsGetExternalPathname (
147 ACPI_NAMESPACE_NODE *Node)
154 ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
157 /* Calculate required buffer size based on depth below root */
159 Size = AcpiNsGetPathnameLength (Node);
165 /* Allocate a buffer to be returned to caller */
167 NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
170 ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
174 /* Build the path in the allocated buffer */
176 Status = AcpiNsBuildExternalPath (Node, Size, NameBuffer);
177 if (ACPI_FAILURE (Status))
179 ACPI_FREE (NameBuffer);
183 return_PTR (NameBuffer);
187 /*******************************************************************************
189 * FUNCTION: AcpiNsGetPathnameLength
191 * PARAMETERS: Node - Namespace node
193 * RETURN: Length of path, including prefix
195 * DESCRIPTION: Get the length of the pathname string for this node
197 ******************************************************************************/
200 AcpiNsGetPathnameLength (
201 ACPI_NAMESPACE_NODE *Node)
204 ACPI_NAMESPACE_NODE *NextNode;
207 ACPI_FUNCTION_ENTRY ();
211 * Compute length of pathname as 5 * number of name segments.
212 * Go back up the parent tree to the root
217 while (NextNode && (NextNode != AcpiGbl_RootNode))
219 if (ACPI_GET_DESCRIPTOR_TYPE (NextNode) != ACPI_DESC_TYPE_NAMED)
221 ACPI_ERROR ((AE_INFO,
222 "Invalid Namespace Node (%p) while traversing namespace",
226 Size += ACPI_PATH_SEGMENT_LENGTH;
227 NextNode = NextNode->Parent;
232 Size = 1; /* Root node case */
235 return (Size + 1); /* +1 for null string terminator */
239 /*******************************************************************************
241 * FUNCTION: AcpiNsHandleToPathname
243 * PARAMETERS: TargetHandle - Handle of named object whose name is
245 * Buffer - Where the pathname is returned
247 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
249 * DESCRIPTION: Build and return a full namespace pathname
251 ******************************************************************************/
254 AcpiNsHandleToPathname (
255 ACPI_HANDLE TargetHandle,
259 ACPI_NAMESPACE_NODE *Node;
260 ACPI_SIZE RequiredSize;
263 ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
266 Node = AcpiNsValidateHandle (TargetHandle);
269 return_ACPI_STATUS (AE_BAD_PARAMETER);
272 /* Determine size required for the caller buffer */
274 RequiredSize = AcpiNsGetPathnameLength (Node);
277 return_ACPI_STATUS (AE_BAD_PARAMETER);
280 /* Validate/Allocate/Clear caller buffer */
282 Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
283 if (ACPI_FAILURE (Status))
285 return_ACPI_STATUS (Status);
288 /* Build the path in the caller buffer */
290 Status = AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer);
291 if (ACPI_FAILURE (Status))
293 return_ACPI_STATUS (Status);
296 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
297 (char *) Buffer->Pointer, (UINT32) RequiredSize));
298 return_ACPI_STATUS (AE_OK);