aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/namespace/nssearch.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/namespace/nssearch.c')
-rw-r--r--drivers/acpi/namespace/nssearch.c148
1 files changed, 88 insertions, 60 deletions
diff --git a/drivers/acpi/namespace/nssearch.c b/drivers/acpi/namespace/nssearch.c
index d64b78952f24..500e2bbcfaf7 100644
--- a/drivers/acpi/namespace/nssearch.c
+++ b/drivers/acpi/namespace/nssearch.c
@@ -56,16 +56,16 @@ acpi_ns_search_parent_tree(u32 target_name,
56 56
57/******************************************************************************* 57/*******************************************************************************
58 * 58 *
59 * FUNCTION: acpi_ns_search_node 59 * FUNCTION: acpi_ns_search_one_scope
60 * 60 *
61 * PARAMETERS: target_name - Ascii ACPI name to search for 61 * PARAMETERS: target_name - Ascii ACPI name to search for
62 * Node - Starting node where search will begin 62 * parent_node - Starting node where search will begin
63 * Type - Object type to match 63 * Type - Object type to match
64 * return_node - Where the matched Named obj is returned 64 * return_node - Where the matched Named obj is returned
65 * 65 *
66 * RETURN: Status 66 * RETURN: Status
67 * 67 *
68 * DESCRIPTION: Search a single level of the namespace. Performs a 68 * DESCRIPTION: Search a single level of the namespace. Performs a
69 * simple search of the specified level, and does not add 69 * simple search of the specified level, and does not add
70 * entries or search parents. 70 * entries or search parents.
71 * 71 *
@@ -75,35 +75,40 @@ acpi_ns_search_parent_tree(u32 target_name,
75 * 75 *
76 * All namespace searching is linear in this implementation, but 76 * All namespace searching is linear in this implementation, but
77 * could be easily modified to support any improved search 77 * could be easily modified to support any improved search
78 * algorithm. However, the linear search was chosen for simplicity 78 * algorithm. However, the linear search was chosen for simplicity
79 * and because the trees are small and the other interpreter 79 * and because the trees are small and the other interpreter
80 * execution overhead is relatively high. 80 * execution overhead is relatively high.
81 * 81 *
82 * Note: CPU execution analysis has shown that the AML interpreter spends
83 * a very small percentage of its time searching the namespace. Therefore,
84 * the linear search seems to be sufficient, as there would seem to be
85 * little value in improving the search.
86 *
82 ******************************************************************************/ 87 ******************************************************************************/
83 88
84acpi_status 89acpi_status
85acpi_ns_search_node(u32 target_name, 90acpi_ns_search_one_scope(u32 target_name,
86 struct acpi_namespace_node *node, 91 struct acpi_namespace_node *parent_node,
87 acpi_object_type type, 92 acpi_object_type type,
88 struct acpi_namespace_node **return_node) 93 struct acpi_namespace_node **return_node)
89{ 94{
90 struct acpi_namespace_node *next_node; 95 struct acpi_namespace_node *node;
91 96
92 ACPI_FUNCTION_TRACE("ns_search_node"); 97 ACPI_FUNCTION_TRACE(ns_search_one_scope);
93 98
94#ifdef ACPI_DEBUG_OUTPUT 99#ifdef ACPI_DEBUG_OUTPUT
95 if (ACPI_LV_NAMES & acpi_dbg_level) { 100 if (ACPI_LV_NAMES & acpi_dbg_level) {
96 char *scope_name; 101 char *scope_name;
97 102
98 scope_name = acpi_ns_get_external_pathname(node); 103 scope_name = acpi_ns_get_external_pathname(parent_node);
99 if (scope_name) { 104 if (scope_name) {
100 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 105 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
101 "Searching %s (%p) For [%4.4s] (%s)\n", 106 "Searching %s (%p) For [%4.4s] (%s)\n",
102 scope_name, node, ACPI_CAST_PTR(char, 107 scope_name, parent_node,
103 &target_name), 108 ACPI_CAST_PTR(char, &target_name),
104 acpi_ut_get_type_name(type))); 109 acpi_ut_get_type_name(type)));
105 110
106 ACPI_MEM_FREE(scope_name); 111 ACPI_FREE(scope_name);
107 } 112 }
108 } 113 }
109#endif 114#endif
@@ -112,32 +117,33 @@ acpi_ns_search_node(u32 target_name,
112 * Search for name at this namespace level, which is to say that we 117 * Search for name at this namespace level, which is to say that we
113 * must search for the name among the children of this object 118 * must search for the name among the children of this object
114 */ 119 */
115 next_node = node->child; 120 node = parent_node->child;
116 while (next_node) { 121 while (node) {
122
117 /* Check for match against the name */ 123 /* Check for match against the name */
118 124
119 if (next_node->name.integer == target_name) { 125 if (node->name.integer == target_name) {
126
120 /* Resolve a control method alias if any */ 127 /* Resolve a control method alias if any */
121 128
122 if (acpi_ns_get_type(next_node) == 129 if (acpi_ns_get_type(node) ==
123 ACPI_TYPE_LOCAL_METHOD_ALIAS) { 130 ACPI_TYPE_LOCAL_METHOD_ALIAS) {
124 next_node = 131 node =
125 ACPI_CAST_PTR(struct acpi_namespace_node, 132 ACPI_CAST_PTR(struct acpi_namespace_node,
126 next_node->object); 133 node->object);
127 } 134 }
128 135
129 /* 136 /* Found matching entry */
130 * Found matching entry. 137
131 */
132 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 138 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
133 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n", 139 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n",
134 ACPI_CAST_PTR(char, &target_name), 140 ACPI_CAST_PTR(char, &target_name),
135 acpi_ut_get_type_name(next_node-> 141 acpi_ut_get_type_name(node->type),
136 type), 142 node,
137 next_node, 143 acpi_ut_get_node_name(parent_node),
138 acpi_ut_get_node_name(node), node)); 144 parent_node));
139 145
140 *return_node = next_node; 146 *return_node = node;
141 return_ACPI_STATUS(AE_OK); 147 return_ACPI_STATUS(AE_OK);
142 } 148 }
143 149
@@ -145,7 +151,8 @@ acpi_ns_search_node(u32 target_name,
145 * The last entry in the list points back to the parent, 151 * The last entry in the list points back to the parent,
146 * so a flag is used to indicate the end-of-list 152 * so a flag is used to indicate the end-of-list
147 */ 153 */
148 if (next_node->flags & ANOBJ_END_OF_PEER_LIST) { 154 if (node->flags & ANOBJ_END_OF_PEER_LIST) {
155
149 /* Searched entire list, we are done */ 156 /* Searched entire list, we are done */
150 157
151 break; 158 break;
@@ -153,7 +160,7 @@ acpi_ns_search_node(u32 target_name,
153 160
154 /* Didn't match name, move on to the next peer object */ 161 /* Didn't match name, move on to the next peer object */
155 162
156 next_node = next_node->peer; 163 node = node->peer;
157 } 164 }
158 165
159 /* Searched entire namespace level, not found */ 166 /* Searched entire namespace level, not found */
@@ -162,7 +169,8 @@ acpi_ns_search_node(u32 target_name,
162 "Name [%4.4s] (%s) not found in search in scope [%4.4s] %p first child %p\n", 169 "Name [%4.4s] (%s) not found in search in scope [%4.4s] %p first child %p\n",
163 ACPI_CAST_PTR(char, &target_name), 170 ACPI_CAST_PTR(char, &target_name),
164 acpi_ut_get_type_name(type), 171 acpi_ut_get_type_name(type),
165 acpi_ut_get_node_name(node), node, node->child)); 172 acpi_ut_get_node_name(parent_node), parent_node,
173 parent_node->child));
166 174
167 return_ACPI_STATUS(AE_NOT_FOUND); 175 return_ACPI_STATUS(AE_NOT_FOUND);
168} 176}
@@ -179,14 +187,14 @@ acpi_ns_search_node(u32 target_name,
179 * RETURN: Status 187 * RETURN: Status
180 * 188 *
181 * DESCRIPTION: Called when a name has not been found in the current namespace 189 * DESCRIPTION: Called when a name has not been found in the current namespace
182 * level. Before adding it or giving up, ACPI scope rules require 190 * level. Before adding it or giving up, ACPI scope rules require
183 * searching enclosing scopes in cases identified by acpi_ns_local(). 191 * searching enclosing scopes in cases identified by acpi_ns_local().
184 * 192 *
185 * "A name is located by finding the matching name in the current 193 * "A name is located by finding the matching name in the current
186 * name space, and then in the parent name space. If the parent 194 * name space, and then in the parent name space. If the parent
187 * name space does not contain the name, the search continues 195 * name space does not contain the name, the search continues
188 * recursively until either the name is found or the name space 196 * recursively until either the name is found or the name space
189 * does not have a parent (the root of the name space). This 197 * does not have a parent (the root of the name space). This
190 * indicates that the name is not found" (From ACPI Specification, 198 * indicates that the name is not found" (From ACPI Specification,
191 * section 5.3) 199 * section 5.3)
192 * 200 *
@@ -201,7 +209,7 @@ acpi_ns_search_parent_tree(u32 target_name,
201 acpi_status status; 209 acpi_status status;
202 struct acpi_namespace_node *parent_node; 210 struct acpi_namespace_node *parent_node;
203 211
204 ACPI_FUNCTION_TRACE("ns_search_parent_tree"); 212 ACPI_FUNCTION_TRACE(ns_search_parent_tree);
205 213
206 parent_node = acpi_ns_get_parent_node(node); 214 parent_node = acpi_ns_get_parent_node(node);
207 215
@@ -235,20 +243,19 @@ acpi_ns_search_parent_tree(u32 target_name,
235 */ 243 */
236 while (parent_node) { 244 while (parent_node) {
237 /* 245 /*
238 * Search parent scope. Use TYPE_ANY because we don't care about the 246 * Search parent scope. Use TYPE_ANY because we don't care about the
239 * object type at this point, we only care about the existence of 247 * object type at this point, we only care about the existence of
240 * the actual name we are searching for. Typechecking comes later. 248 * the actual name we are searching for. Typechecking comes later.
241 */ 249 */
242 status = acpi_ns_search_node(target_name, parent_node, 250 status =
251 acpi_ns_search_one_scope(target_name, parent_node,
243 ACPI_TYPE_ANY, return_node); 252 ACPI_TYPE_ANY, return_node);
244 if (ACPI_SUCCESS(status)) { 253 if (ACPI_SUCCESS(status)) {
245 return_ACPI_STATUS(status); 254 return_ACPI_STATUS(status);
246 } 255 }
247 256
248 /* 257 /* Not found here, go up another level (until we reach the root) */
249 * Not found here, go up another level 258
250 * (until we reach the root)
251 */
252 parent_node = acpi_ns_get_parent_node(parent_node); 259 parent_node = acpi_ns_get_parent_node(parent_node);
253 } 260 }
254 261
@@ -273,7 +280,7 @@ acpi_ns_search_parent_tree(u32 target_name,
273 * RETURN: Status 280 * RETURN: Status
274 * 281 *
275 * DESCRIPTION: Search for a name segment in a single namespace level, 282 * DESCRIPTION: Search for a name segment in a single namespace level,
276 * optionally adding it if it is not found. If the passed 283 * optionally adding it if it is not found. If the passed
277 * Type is not Any and the type previously stored in the 284 * Type is not Any and the type previously stored in the
278 * entry was Any (i.e. unknown), update the stored type. 285 * entry was Any (i.e. unknown), update the stored type.
279 * 286 *
@@ -293,29 +300,46 @@ acpi_ns_search_and_enter(u32 target_name,
293 acpi_status status; 300 acpi_status status;
294 struct acpi_namespace_node *new_node; 301 struct acpi_namespace_node *new_node;
295 302
296 ACPI_FUNCTION_TRACE("ns_search_and_enter"); 303 ACPI_FUNCTION_TRACE(ns_search_and_enter);
297 304
298 /* Parameter validation */ 305 /* Parameter validation */
299 306
300 if (!node || !target_name || !return_node) { 307 if (!node || !target_name || !return_node) {
301 ACPI_ERROR((AE_INFO, 308 ACPI_ERROR((AE_INFO,
302 "Null param: Node %p Name %X return_node %p", 309 "Null parameter: Node %p Name %X ReturnNode %p",
303 node, target_name, return_node)); 310 node, target_name, return_node));
304 return_ACPI_STATUS(AE_BAD_PARAMETER); 311 return_ACPI_STATUS(AE_BAD_PARAMETER);
305 } 312 }
306 313
307 /* Name must consist of printable characters */ 314 /*
308 315 * Name must consist of valid ACPI characters. We will repair the name if
316 * necessary because we don't want to abort because of this, but we want
317 * all namespace names to be printable. A warning message is appropriate.
318 *
319 * This issue came up because there are in fact machines that exhibit
320 * this problem, and we want to be able to enable ACPI support for them,
321 * even though there are a few bad names.
322 */
309 if (!acpi_ut_valid_acpi_name(target_name)) { 323 if (!acpi_ut_valid_acpi_name(target_name)) {
310 ACPI_ERROR((AE_INFO, "Bad character in ACPI Name: %X", 324 target_name = acpi_ut_repair_name(target_name);
311 target_name)); 325
312 return_ACPI_STATUS(AE_BAD_CHARACTER); 326 /* Report warning only if in strict mode or debug mode */
327
328 if (!acpi_gbl_enable_interpreter_slack) {
329 ACPI_WARNING((AE_INFO,
330 "Found bad character(s) in name, repaired: [%4.4s]\n",
331 ACPI_CAST_PTR(char, &target_name)));
332 } else {
333 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
334 "Found bad character(s) in name, repaired: [%4.4s]\n",
335 ACPI_CAST_PTR(char, &target_name)));
336 }
313 } 337 }
314 338
315 /* Try to find the name in the namespace level specified by the caller */ 339 /* Try to find the name in the namespace level specified by the caller */
316 340
317 *return_node = ACPI_ENTRY_NOT_FOUND; 341 *return_node = ACPI_ENTRY_NOT_FOUND;
318 status = acpi_ns_search_node(target_name, node, type, return_node); 342 status = acpi_ns_search_one_scope(target_name, node, type, return_node);
319 if (status != AE_NOT_FOUND) { 343 if (status != AE_NOT_FOUND) {
320 /* 344 /*
321 * If we found it AND the request specifies that a find is an error, 345 * If we found it AND the request specifies that a find is an error,
@@ -325,18 +349,16 @@ acpi_ns_search_and_enter(u32 target_name,
325 status = AE_ALREADY_EXISTS; 349 status = AE_ALREADY_EXISTS;
326 } 350 }
327 351
328 /* 352 /* Either found it or there was an error: finished either way */
329 * Either found it or there was an error 353
330 * -- finished either way
331 */
332 return_ACPI_STATUS(status); 354 return_ACPI_STATUS(status);
333 } 355 }
334 356
335 /* 357 /*
336 * The name was not found. If we are NOT performing the first pass 358 * The name was not found. If we are NOT performing the first pass
337 * (name entry) of loading the namespace, search the parent tree (all the 359 * (name entry) of loading the namespace, search the parent tree (all the
338 * way to the root if necessary.) We don't want to perform the parent 360 * way to the root if necessary.) We don't want to perform the parent
339 * search when the namespace is actually being loaded. We want to perform 361 * search when the namespace is actually being loaded. We want to perform
340 * the search when namespace references are being resolved (load pass 2) 362 * the search when namespace references are being resolved (load pass 2)
341 * and during the execution phase. 363 * and during the execution phase.
342 */ 364 */
@@ -354,9 +376,8 @@ acpi_ns_search_and_enter(u32 target_name,
354 } 376 }
355 } 377 }
356 378
357 /* 379 /* In execute mode, just search, never add names. Exit now */
358 * In execute mode, just search, never add names. Exit now. 380
359 */
360 if (interpreter_mode == ACPI_IMODE_EXECUTE) { 381 if (interpreter_mode == ACPI_IMODE_EXECUTE) {
361 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 382 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
362 "%4.4s Not found in %p [Not adding]\n", 383 "%4.4s Not found in %p [Not adding]\n",
@@ -371,11 +392,18 @@ acpi_ns_search_and_enter(u32 target_name,
371 if (!new_node) { 392 if (!new_node) {
372 return_ACPI_STATUS(AE_NO_MEMORY); 393 return_ACPI_STATUS(AE_NO_MEMORY);
373 } 394 }
395#ifdef ACPI_ASL_COMPILER
396 /*
397 * Node is an object defined by an External() statement
398 */
399 if (flags & ACPI_NS_EXTERNAL) {
400 new_node->flags |= ANOBJ_IS_EXTERNAL;
401 }
402#endif
374 403
375 /* Install the new object into the parent's list of children */ 404 /* Install the new object into the parent's list of children */
376 405
377 acpi_ns_install_node(walk_state, node, new_node, type); 406 acpi_ns_install_node(walk_state, node, new_node, type);
378 *return_node = new_node; 407 *return_node = new_node;
379
380 return_ACPI_STATUS(AE_OK); 408 return_ACPI_STATUS(AE_OK);
381} 409}