1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2017, 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
);
80 return_PTR (NameBuffer
);
84 /*******************************************************************************
86 * FUNCTION: AcpiNsGetPathnameLength
88 * PARAMETERS: Node - Namespace node
90 * RETURN: Length of path, including prefix
92 * DESCRIPTION: Get the length of the pathname string for this node
94 ******************************************************************************/
97 AcpiNsGetPathnameLength (
98 ACPI_NAMESPACE_NODE
*Node
)
103 /* Validate the Node */
105 if (ACPI_GET_DESCRIPTOR_TYPE (Node
) != ACPI_DESC_TYPE_NAMED
)
107 ACPI_ERROR ((AE_INFO
,
108 "Invalid/cached reference target node: %p, descriptor type %d",
109 Node
, ACPI_GET_DESCRIPTOR_TYPE (Node
)));
113 Size
= AcpiNsBuildNormalizedPath (Node
, NULL
, 0, FALSE
);
118 /*******************************************************************************
120 * FUNCTION: AcpiNsHandleToName
122 * PARAMETERS: TargetHandle - Handle of named object whose name is
124 * Buffer - Where the name is returned
126 * RETURN: Status, Buffer is filled with name if status is AE_OK
128 * DESCRIPTION: Build and return a full namespace name
130 ******************************************************************************/
134 ACPI_HANDLE TargetHandle
,
138 ACPI_NAMESPACE_NODE
*Node
;
139 const char *NodeName
;
142 ACPI_FUNCTION_TRACE_PTR (NsHandleToName
, TargetHandle
);
145 Node
= AcpiNsValidateHandle (TargetHandle
);
148 return_ACPI_STATUS (AE_BAD_PARAMETER
);
151 /* Validate/Allocate/Clear caller buffer */
153 Status
= AcpiUtInitializeBuffer (Buffer
, ACPI_PATH_SEGMENT_LENGTH
);
154 if (ACPI_FAILURE (Status
))
156 return_ACPI_STATUS (Status
);
159 /* Just copy the ACPI name from the Node and zero terminate it */
161 NodeName
= AcpiUtGetNodeName (Node
);
162 ACPI_MOVE_NAME (Buffer
->Pointer
, NodeName
);
163 ((char *) Buffer
->Pointer
) [ACPI_NAME_SIZE
] = 0;
165 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%4.4s\n", (char *) Buffer
->Pointer
));
166 return_ACPI_STATUS (AE_OK
);
170 /*******************************************************************************
172 * FUNCTION: AcpiNsHandleToPathname
174 * PARAMETERS: TargetHandle - Handle of named object whose name is
176 * Buffer - Where the pathname is returned
177 * NoTrailing - Remove trailing '_' for each name
180 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
182 * DESCRIPTION: Build and return a full namespace pathname
184 ******************************************************************************/
187 AcpiNsHandleToPathname (
188 ACPI_HANDLE TargetHandle
,
193 ACPI_NAMESPACE_NODE
*Node
;
194 ACPI_SIZE RequiredSize
;
197 ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname
, TargetHandle
);
200 Node
= AcpiNsValidateHandle (TargetHandle
);
203 return_ACPI_STATUS (AE_BAD_PARAMETER
);
206 /* Determine size required for the caller buffer */
208 RequiredSize
= AcpiNsBuildNormalizedPath (Node
, NULL
, 0, NoTrailing
);
211 return_ACPI_STATUS (AE_BAD_PARAMETER
);
214 /* Validate/Allocate/Clear caller buffer */
216 Status
= AcpiUtInitializeBuffer (Buffer
, RequiredSize
);
217 if (ACPI_FAILURE (Status
))
219 return_ACPI_STATUS (Status
);
222 /* Build the path in the caller buffer */
224 (void) AcpiNsBuildNormalizedPath (Node
, Buffer
->Pointer
,
225 RequiredSize
, NoTrailing
);
227 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%s [%X]\n",
228 (char *) Buffer
->Pointer
, (UINT32
) RequiredSize
));
229 return_ACPI_STATUS (AE_OK
);
233 /*******************************************************************************
235 * FUNCTION: AcpiNsBuildNormalizedPath
237 * PARAMETERS: Node - Namespace node
238 * FullPath - Where the path name is returned
239 * PathSize - Size of returned path name buffer
240 * NoTrailing - Remove trailing '_' from each name segment
242 * RETURN: Return 1 if the AML path is empty, otherwise returning (length
243 * of pathname + 1) which means the 'FullPath' contains a trailing
246 * DESCRIPTION: Build and return a full namespace pathname.
247 * Note that if the size of 'FullPath' isn't large enough to
248 * contain the namespace node's path name, the actual required
249 * buffer length is returned, and it should be greater than
250 * 'PathSize'. So callers are able to check the returning value
251 * to determine the buffer size of 'FullPath'.
253 ******************************************************************************/
256 AcpiNsBuildNormalizedPath (
257 ACPI_NAMESPACE_NODE
*Node
,
262 UINT32 Length
= 0, i
;
263 char Name
[ACPI_NAME_SIZE
];
264 BOOLEAN DoNoTrailing
;
265 char c
, *Left
, *Right
;
266 ACPI_NAMESPACE_NODE
*NextNode
;
269 ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath
, Node
);
272 #define ACPI_PATH_PUT8(Path, Size, Byte, Length) \
274 if ((Length) < (Size)) \
276 (Path)[(Length)] = (Byte); \
282 * Make sure the PathSize is correct, so that we don't need to
283 * validate both FullPath and PathSize.
292 goto BuildTrailingNull
;
296 while (NextNode
&& NextNode
!= AcpiGbl_RootNode
)
298 if (NextNode
!= Node
)
300 ACPI_PATH_PUT8(FullPath
, PathSize
, AML_DUAL_NAME_PREFIX
, Length
);
303 ACPI_MOVE_32_TO_32 (Name
, &NextNode
->Name
);
304 DoNoTrailing
= NoTrailing
;
305 for (i
= 0; i
< 4; i
++)
308 if (DoNoTrailing
&& c
!= '_')
310 DoNoTrailing
= FALSE
;
314 ACPI_PATH_PUT8(FullPath
, PathSize
, c
, Length
);
318 NextNode
= NextNode
->Parent
;
321 ACPI_PATH_PUT8(FullPath
, PathSize
, AML_ROOT_PREFIX
, Length
);
323 /* Reverse the path string */
325 if (Length
<= PathSize
)
328 Right
= FullPath
+Length
- 1;
338 /* Append the trailing null */
341 ACPI_PATH_PUT8 (FullPath
, PathSize
, '\0', Length
);
343 #undef ACPI_PATH_PUT8
345 return_UINT32 (Length
);
349 /*******************************************************************************
351 * FUNCTION: AcpiNsGetNormalizedPathname
353 * PARAMETERS: Node - Namespace node whose pathname is needed
354 * NoTrailing - Remove trailing '_' from each name segment
356 * RETURN: Pointer to storage containing the fully qualified name of
357 * the node, In external format (name segments separated by path
360 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
361 * for error and debug statements. All trailing '_' will be
362 * removed from the full pathname if 'NoTrailing' is specified..
364 ******************************************************************************/
367 AcpiNsGetNormalizedPathname (
368 ACPI_NAMESPACE_NODE
*Node
,
375 ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname
, Node
);
378 /* Calculate required buffer size based on depth below root */
380 Size
= AcpiNsBuildNormalizedPath (Node
, NULL
, 0, NoTrailing
);
386 /* Allocate a buffer to be returned to caller */
388 NameBuffer
= ACPI_ALLOCATE_ZEROED (Size
);
391 ACPI_ERROR ((AE_INFO
,
392 "Could not allocate %u bytes", (UINT32
) Size
));
396 /* Build the path in the allocated buffer */
398 (void) AcpiNsBuildNormalizedPath (Node
, NameBuffer
, Size
, NoTrailing
);
400 return_PTR (NameBuffer
);