[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / acpi / namespace / nsnames.c
blobb6f8f910eff06a209a3f53b14f5891165414e0dc
1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 ******************************************************************************/
69 void
70 acpi_ns_build_external_path (
71 struct acpi_namespace_node *node,
72 acpi_size size,
73 char *name_buffer)
75 acpi_size index;
76 struct acpi_namespace_node *parent_node;
79 ACPI_FUNCTION_NAME ("ns_build_external_path");
82 /* Special case for root */
84 index = size - 1;
85 if (index < ACPI_NAME_SIZE) {
86 name_buffer[0] = AML_ROOT_PREFIX;
87 name_buffer[1] = 0;
88 return;
91 /* Store terminator byte, then build name backwards */
93 parent_node = node;
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 */
106 index--;
107 name_buffer[index] = ACPI_PATH_SEPARATOR;
110 /* Overwrite final separator with the root prefix character */
112 name_buffer[index] = AML_ROOT_PREFIX;
114 if (index != 0) {
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]));
120 return;
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
133 * separators.)
135 * DESCRIPTION: Used for debug printing in acpi_ns_search_table().
137 ******************************************************************************/
139 char *
140 acpi_ns_get_external_pathname (
141 struct acpi_namespace_node *node)
143 char *name_buffer;
144 acpi_size size;
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);
157 if (!name_buffer) {
158 ACPI_REPORT_ERROR (("ns_get_table_pathname: allocation failure\n"));
159 return_PTR (NULL);
162 /* Build the path in the allocated buffer */
164 acpi_ns_build_external_path (node, size, name_buffer);
165 return_PTR (name_buffer);
167 #endif
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 ******************************************************************************/
182 acpi_size
183 acpi_ns_get_pathname_length (
184 struct acpi_namespace_node *node)
186 acpi_size size;
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
197 size = 0;
198 next_node = node;
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);
205 if (!size) {
206 size = 1; /* Root node case */
209 return (size + 1); /* +1 for null string terminator */
213 /*******************************************************************************
215 * FUNCTION: acpi_ns_handle_to_pathname
217 * PARAMETERS: target_handle - Handle of named object whose name is
218 * to be found
219 * Buffer - Where the pathname is returned
221 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
223 * DESCRIPTION: Build and return a full namespace pathname
225 ******************************************************************************/
227 acpi_status
228 acpi_ns_handle_to_pathname (
229 acpi_handle target_handle,
230 struct acpi_buffer *buffer)
232 acpi_status status;
233 struct acpi_namespace_node *node;
234 acpi_size required_size;
237 ACPI_FUNCTION_TRACE_PTR ("ns_handle_to_pathname", target_handle);
240 node = acpi_ns_map_handle_to_node (target_handle);
241 if (!node) {
242 return_ACPI_STATUS (AE_BAD_PARAMETER);
245 /* Determine size required for the caller buffer */
247 required_size = acpi_ns_get_pathname_length (node);
249 /* Validate/Allocate/Clear caller buffer */
251 status = acpi_ut_initialize_buffer (buffer, required_size);
252 if (ACPI_FAILURE (status)) {
253 return_ACPI_STATUS (status);
256 /* Build the path in the caller buffer */
258 acpi_ns_build_external_path (node, required_size, buffer->pointer);
260 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X] \n",
261 (char *) buffer->pointer, (u32) required_size));
262 return_ACPI_STATUS (AE_OK);