1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2004, 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")
54 /*******************************************************************************
56 * FUNCTION: acpi_ns_build_external_path
58 * PARAMETERS: Node - NS node whose pathname is needed
59 * Size - Size of the pathname
60 * *name_buffer - Where to return the pathname
62 * RETURN: Places the pathname into the name_buffer, in external format
63 * (name segments separated by path separators)
65 * DESCRIPTION: Generate a full pathaname
67 ******************************************************************************/
70 acpi_ns_build_external_path (
71 struct acpi_namespace_node *node,
76 struct acpi_namespace_node *parent_node;
79 ACPI_FUNCTION_NAME ("ns_build_external_path");
82 /* Special case for root */
85 if (index < ACPI_NAME_SIZE) {
86 name_buffer[0] = AML_ROOT_PREFIX;
91 /* Store terminator byte, then build name backwards */
94 name_buffer[index] = 0;
96 while ((index > ACPI_NAME_SIZE) && (parent_node != acpi_gbl_root_node)) {
97 index -= ACPI_NAME_SIZE;
99 /* Put the name into the buffer */
101 ACPI_MOVE_32_TO_32 ((name_buffer + index), &parent_node->name);
102 parent_node = acpi_ns_get_parent_node (parent_node);
104 /* Prefix name with the path separator */
107 name_buffer[index] = ACPI_PATH_SEPARATOR;
110 /* Overwrite final separator with the root prefix character */
112 name_buffer[index] = AML_ROOT_PREFIX;
115 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
116 "Could not construct pathname; index=%X, size=%X, Path=%s\n",
117 (u32) index, (u32) size, &name_buffer[size]));
124 #ifdef ACPI_DEBUG_OUTPUT
125 /*******************************************************************************
127 * FUNCTION: acpi_ns_get_external_pathname
129 * PARAMETERS: Node - NS node whose pathname is needed
131 * RETURN: Pointer to storage containing the fully qualified name of
132 * the node, In external format (name segments separated by path
135 * DESCRIPTION: Used for debug printing in acpi_ns_search_table().
137 ******************************************************************************/
140 acpi_ns_get_external_pathname (
141 struct acpi_namespace_node *node)
147 ACPI_FUNCTION_TRACE_PTR ("ns_get_external_pathname", node);
150 /* Calculate required buffer size based on depth below root */
152 size = acpi_ns_get_pathname_length (node);
154 /* Allocate a buffer to be returned to caller */
156 name_buffer = ACPI_MEM_CALLOCATE (size);
158 ACPI_REPORT_ERROR (("ns_get_table_pathname: allocation failure\n"));
162 /* Build the path in the allocated buffer */
164 acpi_ns_build_external_path (node, size, name_buffer);
165 return_PTR (name_buffer);
170 /*******************************************************************************
172 * FUNCTION: acpi_ns_get_pathname_length
174 * PARAMETERS: Node - Namespace node
176 * RETURN: Length of path, including prefix
178 * DESCRIPTION: Get the length of the pathname string for this node
180 ******************************************************************************/
183 acpi_ns_get_pathname_length (
184 struct acpi_namespace_node *node)
187 struct acpi_namespace_node *next_node;
190 ACPI_FUNCTION_ENTRY ();
194 * Compute length of pathname as 5 * number of name segments.
195 * Go back up the parent tree to the root
200 while (next_node && (next_node != acpi_gbl_root_node)) {
201 size += ACPI_PATH_SEGMENT_LENGTH;
202 next_node = acpi_ns_get_parent_node (next_node);
209 /*******************************************************************************
211 * FUNCTION: acpi_ns_handle_to_pathname
213 * PARAMETERS: target_handle - Handle of named object whose name is
215 * Buffer - Where the pathname is returned
217 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
219 * DESCRIPTION: Build and return a full namespace pathname
221 ******************************************************************************/
224 acpi_ns_handle_to_pathname (
225 acpi_handle target_handle,
226 struct acpi_buffer *buffer)
229 struct acpi_namespace_node *node;
230 acpi_size required_size;
233 ACPI_FUNCTION_TRACE_PTR ("ns_handle_to_pathname", target_handle);
236 node = acpi_ns_map_handle_to_node (target_handle);
238 return_ACPI_STATUS (AE_BAD_PARAMETER);
241 /* Determine size required for the caller buffer */
243 required_size = acpi_ns_get_pathname_length (node);
245 /* Validate/Allocate/Clear caller buffer */
247 status = acpi_ut_initialize_buffer (buffer, required_size);
248 if (ACPI_FAILURE (status)) {
249 return_ACPI_STATUS (status);
252 /* Build the path in the caller buffer */
254 acpi_ns_build_external_path (node, required_size, buffer->pointer);
256 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X] \n", (char *) buffer->pointer, (u32) required_size));
257 return_ACPI_STATUS (AE_OK);