1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, 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 ACPI_FUNCTION_ENTRY ();
106 Size
= AcpiNsBuildNormalizedPath (Node
, NULL
, 0, FALSE
);
111 /*******************************************************************************
113 * FUNCTION: AcpiNsHandleToPathname
115 * PARAMETERS: TargetHandle - Handle of named object whose name is
117 * Buffer - Where the pathname is returned
118 * NoTrailing - Remove trailing '_' for each name
121 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
123 * DESCRIPTION: Build and return a full namespace pathname
125 ******************************************************************************/
128 AcpiNsHandleToPathname (
129 ACPI_HANDLE TargetHandle
,
134 ACPI_NAMESPACE_NODE
*Node
;
135 ACPI_SIZE RequiredSize
;
138 ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname
, TargetHandle
);
141 Node
= AcpiNsValidateHandle (TargetHandle
);
144 return_ACPI_STATUS (AE_BAD_PARAMETER
);
147 /* Determine size required for the caller buffer */
149 RequiredSize
= AcpiNsBuildNormalizedPath (Node
, NULL
, 0, NoTrailing
);
152 return_ACPI_STATUS (AE_BAD_PARAMETER
);
155 /* Validate/Allocate/Clear caller buffer */
157 Status
= AcpiUtInitializeBuffer (Buffer
, RequiredSize
);
158 if (ACPI_FAILURE (Status
))
160 return_ACPI_STATUS (Status
);
163 /* Build the path in the caller buffer */
165 (void) AcpiNsBuildNormalizedPath (Node
, Buffer
->Pointer
,
166 RequiredSize
, NoTrailing
);
167 if (ACPI_FAILURE (Status
))
169 return_ACPI_STATUS (Status
);
172 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%s [%X]\n",
173 (char *) Buffer
->Pointer
, (UINT32
) RequiredSize
));
174 return_ACPI_STATUS (AE_OK
);
178 /*******************************************************************************
180 * FUNCTION: AcpiNsBuildNormalizedPath
182 * PARAMETERS: Node - Namespace node
183 * FullPath - Where the path name is returned
184 * PathSize - Size of returned path name buffer
185 * NoTrailing - Remove trailing '_' from each name segment
187 * RETURN: Return 1 if the AML path is empty, otherwise returning (length
188 * of pathname + 1) which means the 'FullPath' contains a trailing
191 * DESCRIPTION: Build and return a full namespace pathname.
192 * Note that if the size of 'FullPath' isn't large enough to
193 * contain the namespace node's path name, the actual required
194 * buffer length is returned, and it should be greater than
195 * 'PathSize'. So callers are able to check the returning value
196 * to determine the buffer size of 'FullPath'.
198 ******************************************************************************/
201 AcpiNsBuildNormalizedPath (
202 ACPI_NAMESPACE_NODE
*Node
,
207 UINT32 Length
= 0, i
;
208 char Name
[ACPI_NAME_SIZE
];
209 BOOLEAN DoNoTrailing
;
210 char c
, *Left
, *Right
;
211 ACPI_NAMESPACE_NODE
*NextNode
;
214 ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath
, Node
);
217 #define ACPI_PATH_PUT8(Path, Size, Byte, Length) \
219 if ((Length) < (Size)) \
221 (Path)[(Length)] = (Byte); \
227 * Make sure the PathSize is correct, so that we don't need to
228 * validate both FullPath and PathSize.
237 goto BuildTrailingNull
;
241 while (NextNode
&& NextNode
!= AcpiGbl_RootNode
)
243 if (NextNode
!= Node
)
245 ACPI_PATH_PUT8(FullPath
, PathSize
, AML_DUAL_NAME_PREFIX
, Length
);
248 ACPI_MOVE_32_TO_32 (Name
, &NextNode
->Name
);
249 DoNoTrailing
= NoTrailing
;
250 for (i
= 0; i
< 4; i
++)
253 if (DoNoTrailing
&& c
!= '_')
255 DoNoTrailing
= FALSE
;
259 ACPI_PATH_PUT8(FullPath
, PathSize
, c
, Length
);
263 NextNode
= NextNode
->Parent
;
266 ACPI_PATH_PUT8(FullPath
, PathSize
, AML_ROOT_PREFIX
, Length
);
268 /* Reverse the path string */
270 if (Length
<= PathSize
)
273 Right
= FullPath
+Length
- 1;
283 /* Append the trailing null */
286 ACPI_PATH_PUT8 (FullPath
, PathSize
, '\0', Length
);
288 #undef ACPI_PATH_PUT8
290 return_UINT32 (Length
);
294 /*******************************************************************************
296 * FUNCTION: AcpiNsGetNormalizedPathname
298 * PARAMETERS: Node - Namespace node whose pathname is needed
299 * NoTrailing - Remove trailing '_' from each name segment
301 * RETURN: Pointer to storage containing the fully qualified name of
302 * the node, In external format (name segments separated by path
305 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
306 * for error and debug statements. All trailing '_' will be
307 * removed from the full pathname if 'NoTrailing' is specified..
309 ******************************************************************************/
312 AcpiNsGetNormalizedPathname (
313 ACPI_NAMESPACE_NODE
*Node
,
320 ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname
, Node
);
323 /* Calculate required buffer size based on depth below root */
325 Size
= AcpiNsBuildNormalizedPath (Node
, NULL
, 0, NoTrailing
);
331 /* Allocate a buffer to be returned to caller */
333 NameBuffer
= ACPI_ALLOCATE_ZEROED (Size
);
336 ACPI_ERROR ((AE_INFO
,
337 "Could not allocate %u bytes", (UINT32
) Size
));
341 /* Build the path in the allocated buffer */
343 (void) AcpiNsBuildNormalizedPath (Node
, NameBuffer
, Size
, NoTrailing
);
345 return_PTR (NameBuffer
);