1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, 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: AcpiNsGetExternalPathname
58 * PARAMETERS: Node - Namespace node whose pathname is needed
60 * RETURN: Pointer to storage containing the fully qualified name of
61 * the node, In external format (name segments separated by path
64 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
65 * for error and debug statements.
67 ******************************************************************************/
70 AcpiNsGetExternalPathname (
71 ACPI_NAMESPACE_NODE *Node)
76 ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
79 NameBuffer = AcpiNsGetNormalizedPathname (Node, FALSE);
81 return_PTR (NameBuffer);
85 /*******************************************************************************
87 * FUNCTION: AcpiNsGetPathnameLength
89 * PARAMETERS: Node - Namespace node
91 * RETURN: Length of path, including prefix
93 * DESCRIPTION: Get the length of the pathname string for this node
95 ******************************************************************************/
98 AcpiNsGetPathnameLength (
99 ACPI_NAMESPACE_NODE *Node)
104 ACPI_FUNCTION_ENTRY ();
107 Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, FALSE);
113 /*******************************************************************************
115 * FUNCTION: AcpiNsHandleToPathname
117 * PARAMETERS: TargetHandle - Handle of named object whose name is
119 * Buffer - Where the pathname is returned
120 * NoTrailing - Remove trailing '_' for each name
123 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
125 * DESCRIPTION: Build and return a full namespace pathname
127 ******************************************************************************/
130 AcpiNsHandleToPathname (
131 ACPI_HANDLE TargetHandle,
136 ACPI_NAMESPACE_NODE *Node;
137 ACPI_SIZE RequiredSize;
140 ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
143 Node = AcpiNsValidateHandle (TargetHandle);
146 return_ACPI_STATUS (AE_BAD_PARAMETER);
149 /* Determine size required for the caller buffer */
151 RequiredSize = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
154 return_ACPI_STATUS (AE_BAD_PARAMETER);
157 /* Validate/Allocate/Clear caller buffer */
159 Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
160 if (ACPI_FAILURE (Status))
162 return_ACPI_STATUS (Status);
165 /* Build the path in the caller buffer */
167 (void) AcpiNsBuildNormalizedPath (Node, Buffer->Pointer,
168 RequiredSize, NoTrailing);
169 if (ACPI_FAILURE (Status))
171 return_ACPI_STATUS (Status);
174 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
175 (char *) Buffer->Pointer, (UINT32) RequiredSize));
176 return_ACPI_STATUS (AE_OK);
180 /*******************************************************************************
182 * FUNCTION: AcpiNsBuildNormalizedPath
184 * PARAMETERS: Node - Namespace node
185 * FullPath - Where the path name is returned
186 * PathSize - Size of returned path name buffer
187 * NoTrailing - Remove trailing '_' from each name segment
189 * RETURN: Return 1 if the AML path is empty, otherwise returning (length
190 * of pathname + 1) which means the 'FullPath' contains a trailing
193 * DESCRIPTION: Build and return a full namespace pathname.
194 * Note that if the size of 'FullPath' isn't large enough to
195 * contain the namespace node's path name, the actual required
196 * buffer length is returned, and it should be greater than
197 * 'PathSize'. So callers are able to check the returning value
198 * to determine the buffer size of 'FullPath'.
200 ******************************************************************************/
203 AcpiNsBuildNormalizedPath (
204 ACPI_NAMESPACE_NODE *Node,
209 UINT32 Length = 0, i;
210 char Name[ACPI_NAME_SIZE];
211 BOOLEAN DoNoTrailing;
212 char c, *Left, *Right;
213 ACPI_NAMESPACE_NODE *NextNode;
216 ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath, Node);
219 #define ACPI_PATH_PUT8(Path, Size, Byte, Length) \
221 if ((Length) < (Size)) \
223 (Path)[(Length)] = (Byte); \
229 * Make sure the PathSize is correct, so that we don't need to
230 * validate both FullPath and PathSize.
239 goto BuildTrailingNull;
243 while (NextNode && NextNode != AcpiGbl_RootNode)
245 if (NextNode != Node)
247 ACPI_PATH_PUT8(FullPath, PathSize, AML_DUAL_NAME_PREFIX, Length);
249 ACPI_MOVE_32_TO_32 (Name, &NextNode->Name);
250 DoNoTrailing = NoTrailing;
251 for (i = 0; i < 4; i++)
254 if (DoNoTrailing && c != '_')
256 DoNoTrailing = FALSE;
260 ACPI_PATH_PUT8(FullPath, PathSize, c, Length);
263 NextNode = NextNode->Parent;
265 ACPI_PATH_PUT8(FullPath, PathSize, AML_ROOT_PREFIX, Length);
267 /* Reverse the path string */
269 if (Length <= PathSize)
272 Right = FullPath+Length-1;
281 /* Append the trailing null */
284 ACPI_PATH_PUT8(FullPath, PathSize, '\0', Length);
286 #undef ACPI_PATH_PUT8
288 return_UINT32 (Length);
292 /*******************************************************************************
294 * FUNCTION: AcpiNsGetNormalizedPathname
296 * PARAMETERS: Node - Namespace node whose pathname is needed
297 * NoTrailing - Remove trailing '_' from each name segment
299 * RETURN: Pointer to storage containing the fully qualified name of
300 * the node, In external format (name segments separated by path
303 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
304 * for error and debug statements. All trailing '_' will be
305 * removed from the full pathname if 'NoTrailing' is specified..
307 ******************************************************************************/
310 AcpiNsGetNormalizedPathname (
311 ACPI_NAMESPACE_NODE *Node,
318 ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname, Node);
321 /* Calculate required buffer size based on depth below root */
323 Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
329 /* Allocate a buffer to be returned to caller */
331 NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
334 ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
338 /* Build the path in the allocated buffer */
340 (void) AcpiNsBuildNormalizedPath (Node, NameBuffer, Size, NoTrailing);
342 return_PTR (NameBuffer);