1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
45 #include <acpi/acpi.h>
46 #include <acpi/amlcode.h>
47 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsnames")
53 /* Local prototypes */
56 acpi_ns_build_external_path (
57 struct acpi_namespace_node
*node
,
62 /*******************************************************************************
64 * FUNCTION: acpi_ns_build_external_path
66 * PARAMETERS: Node - NS node whose pathname is needed
67 * Size - Size of the pathname
68 * *name_buffer - Where to return the pathname
70 * RETURN: Places the pathname into the name_buffer, in external format
71 * (name segments separated by path separators)
73 * DESCRIPTION: Generate a full pathaname
75 ******************************************************************************/
78 acpi_ns_build_external_path (
79 struct acpi_namespace_node
*node
,
84 struct acpi_namespace_node
*parent_node
;
87 ACPI_FUNCTION_NAME ("ns_build_external_path");
90 /* Special case for root */
93 if (index
< ACPI_NAME_SIZE
) {
94 name_buffer
[0] = AML_ROOT_PREFIX
;
99 /* Store terminator byte, then build name backwards */
102 name_buffer
[index
] = 0;
104 while ((index
> ACPI_NAME_SIZE
) && (parent_node
!= acpi_gbl_root_node
)) {
105 index
-= ACPI_NAME_SIZE
;
107 /* Put the name into the buffer */
109 ACPI_MOVE_32_TO_32 ((name_buffer
+ index
), &parent_node
->name
);
110 parent_node
= acpi_ns_get_parent_node (parent_node
);
112 /* Prefix name with the path separator */
115 name_buffer
[index
] = ACPI_PATH_SEPARATOR
;
118 /* Overwrite final separator with the root prefix character */
120 name_buffer
[index
] = AML_ROOT_PREFIX
;
123 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
124 "Could not construct pathname; index=%X, size=%X, Path=%s\n",
125 (u32
) index
, (u32
) size
, &name_buffer
[size
]));
132 #ifdef ACPI_DEBUG_OUTPUT
133 /*******************************************************************************
135 * FUNCTION: acpi_ns_get_external_pathname
137 * PARAMETERS: Node - Namespace node whose pathname is needed
139 * RETURN: Pointer to storage containing the fully qualified name of
140 * the node, In external format (name segments separated by path
143 * DESCRIPTION: Used for debug printing in acpi_ns_search_table().
145 ******************************************************************************/
148 acpi_ns_get_external_pathname (
149 struct acpi_namespace_node
*node
)
155 ACPI_FUNCTION_TRACE_PTR ("ns_get_external_pathname", node
);
158 /* Calculate required buffer size based on depth below root */
160 size
= acpi_ns_get_pathname_length (node
);
162 /* Allocate a buffer to be returned to caller */
164 name_buffer
= ACPI_MEM_CALLOCATE (size
);
166 ACPI_REPORT_ERROR (("ns_get_table_pathname: allocation failure\n"));
170 /* Build the path in the allocated buffer */
172 acpi_ns_build_external_path (node
, size
, name_buffer
);
173 return_PTR (name_buffer
);
178 /*******************************************************************************
180 * FUNCTION: acpi_ns_get_pathname_length
182 * PARAMETERS: Node - Namespace node
184 * RETURN: Length of path, including prefix
186 * DESCRIPTION: Get the length of the pathname string for this node
188 ******************************************************************************/
191 acpi_ns_get_pathname_length (
192 struct acpi_namespace_node
*node
)
195 struct acpi_namespace_node
*next_node
;
198 ACPI_FUNCTION_ENTRY ();
202 * Compute length of pathname as 5 * number of name segments.
203 * Go back up the parent tree to the root
208 while (next_node
&& (next_node
!= acpi_gbl_root_node
)) {
209 size
+= ACPI_PATH_SEGMENT_LENGTH
;
210 next_node
= acpi_ns_get_parent_node (next_node
);
214 size
= 1; /* Root node case */
217 return (size
+ 1); /* +1 for null string terminator */
221 /*******************************************************************************
223 * FUNCTION: acpi_ns_handle_to_pathname
225 * PARAMETERS: target_handle - Handle of named object whose name is
227 * Buffer - Where the pathname is returned
229 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
231 * DESCRIPTION: Build and return a full namespace pathname
233 ******************************************************************************/
236 acpi_ns_handle_to_pathname (
237 acpi_handle target_handle
,
238 struct acpi_buffer
*buffer
)
241 struct acpi_namespace_node
*node
;
242 acpi_size required_size
;
245 ACPI_FUNCTION_TRACE_PTR ("ns_handle_to_pathname", target_handle
);
248 node
= acpi_ns_map_handle_to_node (target_handle
);
250 return_ACPI_STATUS (AE_BAD_PARAMETER
);
253 /* Determine size required for the caller buffer */
255 required_size
= acpi_ns_get_pathname_length (node
);
257 /* Validate/Allocate/Clear caller buffer */
259 status
= acpi_ut_initialize_buffer (buffer
, required_size
);
260 if (ACPI_FAILURE (status
)) {
261 return_ACPI_STATUS (status
);
264 /* Build the path in the caller buffer */
266 acpi_ns_build_external_path (node
, required_size
, buffer
->pointer
);
268 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%s [%X] \n",
269 (char *) buffer
->pointer
, (u32
) required_size
));
270 return_ACPI_STATUS (AE_OK
);