1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nsnames")
56 /*******************************************************************************
58 * FUNCTION: AcpiNsBuildExternalPath
60 * PARAMETERS: Node - NS node whose pathname is needed
61 * Size - Size of the pathname
62 * *NameBuffer - Where to return the pathname
65 * Places the pathname into the NameBuffer, in external format
66 * (name segments separated by path separators)
68 * DESCRIPTION: Generate a full pathaname
70 ******************************************************************************/
73 AcpiNsBuildExternalPath (
74 ACPI_NAMESPACE_NODE
*Node
,
79 ACPI_NAMESPACE_NODE
*ParentNode
;
82 ACPI_FUNCTION_ENTRY ();
85 /* Special case for root */
88 if (Index
< ACPI_NAME_SIZE
)
90 NameBuffer
[0] = AML_ROOT_PREFIX
;
95 /* Store terminator byte, then build name backwards */
98 NameBuffer
[Index
] = 0;
100 while ((Index
> ACPI_NAME_SIZE
) && (ParentNode
!= AcpiGbl_RootNode
))
102 Index
-= ACPI_NAME_SIZE
;
104 /* Put the name into the buffer */
106 ACPI_MOVE_32_TO_32 ((NameBuffer
+ Index
), &ParentNode
->Name
);
107 ParentNode
= ParentNode
->Parent
;
109 /* Prefix name with the path separator */
112 NameBuffer
[Index
] = ACPI_PATH_SEPARATOR
;
115 /* Overwrite final separator with the root prefix character */
117 NameBuffer
[Index
] = AML_ROOT_PREFIX
;
121 ACPI_ERROR ((AE_INFO
,
122 "Could not construct external pathname; index=%u, size=%u, Path=%s",
123 (UINT32
) Index
, (UINT32
) Size
, &NameBuffer
[Size
]));
125 return (AE_BAD_PARAMETER
);
132 /*******************************************************************************
134 * FUNCTION: AcpiNsGetExternalPathname
136 * PARAMETERS: Node - Namespace node whose pathname is needed
138 * RETURN: Pointer to storage containing the fully qualified name of
139 * the node, In external format (name segments separated by path
142 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
143 * for error and debug statements.
145 ******************************************************************************/
148 AcpiNsGetExternalPathname (
149 ACPI_NAMESPACE_NODE
*Node
)
156 ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname
, Node
);
159 /* Calculate required buffer size based on depth below root */
161 Size
= AcpiNsGetPathnameLength (Node
);
167 /* Allocate a buffer to be returned to caller */
169 NameBuffer
= ACPI_ALLOCATE_ZEROED (Size
);
172 ACPI_ERROR ((AE_INFO
, "Could not allocate %u bytes", (UINT32
) Size
));
176 /* Build the path in the allocated buffer */
178 Status
= AcpiNsBuildExternalPath (Node
, Size
, NameBuffer
);
179 if (ACPI_FAILURE (Status
))
181 ACPI_FREE (NameBuffer
);
185 return_PTR (NameBuffer
);
189 /*******************************************************************************
191 * FUNCTION: AcpiNsGetPathnameLength
193 * PARAMETERS: Node - Namespace node
195 * RETURN: Length of path, including prefix
197 * DESCRIPTION: Get the length of the pathname string for this node
199 ******************************************************************************/
202 AcpiNsGetPathnameLength (
203 ACPI_NAMESPACE_NODE
*Node
)
206 ACPI_NAMESPACE_NODE
*NextNode
;
209 ACPI_FUNCTION_ENTRY ();
213 * Compute length of pathname as 5 * number of name segments.
214 * Go back up the parent tree to the root
219 while (NextNode
&& (NextNode
!= AcpiGbl_RootNode
))
221 if (ACPI_GET_DESCRIPTOR_TYPE (NextNode
) != ACPI_DESC_TYPE_NAMED
)
223 ACPI_ERROR ((AE_INFO
,
224 "Invalid Namespace Node (%p) while traversing namespace",
228 Size
+= ACPI_PATH_SEGMENT_LENGTH
;
229 NextNode
= NextNode
->Parent
;
234 Size
= 1; /* Root node case */
237 return (Size
+ 1); /* +1 for null string terminator */
241 /*******************************************************************************
243 * FUNCTION: AcpiNsHandleToPathname
245 * PARAMETERS: TargetHandle - Handle of named object whose name is
247 * Buffer - Where the pathname is returned
249 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
251 * DESCRIPTION: Build and return a full namespace pathname
253 ******************************************************************************/
256 AcpiNsHandleToPathname (
257 ACPI_HANDLE TargetHandle
,
261 ACPI_NAMESPACE_NODE
*Node
;
262 ACPI_SIZE RequiredSize
;
265 ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname
, TargetHandle
);
268 Node
= AcpiNsValidateHandle (TargetHandle
);
271 return_ACPI_STATUS (AE_BAD_PARAMETER
);
274 /* Determine size required for the caller buffer */
276 RequiredSize
= AcpiNsGetPathnameLength (Node
);
279 return_ACPI_STATUS (AE_BAD_PARAMETER
);
282 /* Validate/Allocate/Clear caller buffer */
284 Status
= AcpiUtInitializeBuffer (Buffer
, RequiredSize
);
285 if (ACPI_FAILURE (Status
))
287 return_ACPI_STATUS (Status
);
290 /* Build the path in the caller buffer */
292 Status
= AcpiNsBuildExternalPath (Node
, RequiredSize
, Buffer
->Pointer
);
293 if (ACPI_FAILURE (Status
))
295 return_ACPI_STATUS (Status
);
298 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%s [%X]\n",
299 (char *) Buffer
->Pointer
, (UINT32
) RequiredSize
));
300 return_ACPI_STATUS (AE_OK
);