Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing | |
4 | * parents and siblings and Scope manipulation | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
9 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
10 | * All rights reserved. | |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
15 | * 1. Redistributions of source code must retain the above copyright | |
16 | * notice, this list of conditions, and the following disclaimer, | |
17 | * without modification. | |
18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
19 | * substantially similar to the "NO WARRANTY" disclaimer below | |
20 | * ("Disclaimer") and any redistribution must be conditioned upon | |
21 | * including a substantially similar Disclaimer requirement for further | |
22 | * binary redistribution. | |
23 | * 3. Neither the names of the above-listed copyright holders nor the names | |
24 | * of any contributors may be used to endorse or promote products derived | |
25 | * from this software without specific prior written permission. | |
26 | * | |
27 | * Alternatively, this software may be distributed under the terms of the | |
28 | * GNU General Public License ("GPL") version 2 as published by the Free | |
29 | * Software Foundation. | |
30 | * | |
31 | * NO WARRANTY | |
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
42 | * POSSIBILITY OF SUCH DAMAGES. | |
43 | */ | |
44 | ||
1da177e4 LT |
45 | #include <acpi/acpi.h> |
46 | #include <acpi/acnamesp.h> | |
47 | #include <acpi/amlcode.h> | |
48 | #include <acpi/actables.h> | |
49 | ||
50 | #define _COMPONENT ACPI_NAMESPACE | |
4be44fcd | 51 | ACPI_MODULE_NAME("nsutils") |
1da177e4 | 52 | |
44f6c012 | 53 | /* Local prototypes */ |
4be44fcd | 54 | static u8 acpi_ns_valid_path_separator(char sep); |
44f6c012 RM |
55 | |
56 | #ifdef ACPI_OBSOLETE_FUNCTIONS | |
4be44fcd | 57 | acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search); |
44f6c012 RM |
58 | #endif |
59 | ||
1da177e4 LT |
60 | /******************************************************************************* |
61 | * | |
62 | * FUNCTION: acpi_ns_report_error | |
63 | * | |
64 | * PARAMETERS: module_name - Caller's module name (for error output) | |
65 | * line_number - Caller's line number (for error output) | |
66 | * component_id - Caller's component ID (for error output) | |
44f6c012 RM |
67 | * internal_name - Name or path of the namespace node |
68 | * lookup_status - Exception code from NS lookup | |
1da177e4 LT |
69 | * |
70 | * RETURN: None | |
71 | * | |
72 | * DESCRIPTION: Print warning message with full pathname | |
73 | * | |
74 | ******************************************************************************/ | |
75 | ||
76 | void | |
4be44fcd LB |
77 | acpi_ns_report_error(char *module_name, |
78 | u32 line_number, | |
79 | u32 component_id, | |
80 | char *internal_name, acpi_status lookup_status) | |
1da177e4 | 81 | { |
4be44fcd LB |
82 | acpi_status status; |
83 | char *name = NULL; | |
1da177e4 | 84 | |
4be44fcd LB |
85 | acpi_os_printf("%8s-%04d: *** Error: Looking up ", |
86 | module_name, line_number); | |
1da177e4 LT |
87 | |
88 | if (lookup_status == AE_BAD_CHARACTER) { | |
89 | /* There is a non-ascii character in the name */ | |
90 | ||
4be44fcd LB |
91 | acpi_os_printf("[0x%4.4X] (NON-ASCII)\n", |
92 | *(ACPI_CAST_PTR(u32, internal_name))); | |
93 | } else { | |
1da177e4 LT |
94 | /* Convert path to external format */ |
95 | ||
4be44fcd LB |
96 | status = acpi_ns_externalize_name(ACPI_UINT32_MAX, |
97 | internal_name, NULL, &name); | |
1da177e4 LT |
98 | |
99 | /* Print target name */ | |
100 | ||
4be44fcd LB |
101 | if (ACPI_SUCCESS(status)) { |
102 | acpi_os_printf("[%s]", name); | |
103 | } else { | |
104 | acpi_os_printf("[COULD NOT EXTERNALIZE NAME]"); | |
1da177e4 LT |
105 | } |
106 | ||
107 | if (name) { | |
4be44fcd | 108 | ACPI_MEM_FREE(name); |
1da177e4 LT |
109 | } |
110 | } | |
111 | ||
4be44fcd LB |
112 | acpi_os_printf(" in namespace, %s\n", |
113 | acpi_format_exception(lookup_status)); | |
1da177e4 LT |
114 | } |
115 | ||
1da177e4 LT |
116 | /******************************************************************************* |
117 | * | |
118 | * FUNCTION: acpi_ns_report_method_error | |
119 | * | |
120 | * PARAMETERS: module_name - Caller's module name (for error output) | |
121 | * line_number - Caller's line number (for error output) | |
122 | * component_id - Caller's component ID (for error output) | |
123 | * Message - Error message to use on failure | |
44f6c012 RM |
124 | * prefix_node - Prefix relative to the path |
125 | * Path - Path to the node | |
126 | * method_status - Execution status | |
1da177e4 LT |
127 | * |
128 | * RETURN: None | |
129 | * | |
130 | * DESCRIPTION: Print warning message with full pathname | |
131 | * | |
132 | ******************************************************************************/ | |
133 | ||
134 | void | |
4be44fcd LB |
135 | acpi_ns_report_method_error(char *module_name, |
136 | u32 line_number, | |
137 | u32 component_id, | |
138 | char *message, | |
139 | struct acpi_namespace_node *prefix_node, | |
140 | char *path, acpi_status method_status) | |
1da177e4 | 141 | { |
4be44fcd LB |
142 | acpi_status status; |
143 | struct acpi_namespace_node *node = prefix_node; | |
1da177e4 LT |
144 | |
145 | if (path) { | |
4be44fcd LB |
146 | status = acpi_ns_get_node_by_path(path, prefix_node, |
147 | ACPI_NS_NO_UPSEARCH, &node); | |
148 | if (ACPI_FAILURE(status)) { | |
149 | acpi_os_printf | |
150 | ("report_method_error: Could not get node\n"); | |
1da177e4 LT |
151 | return; |
152 | } | |
153 | } | |
154 | ||
4be44fcd LB |
155 | acpi_os_printf("%8s-%04d: *** Error: ", module_name, line_number); |
156 | acpi_ns_print_node_pathname(node, message); | |
157 | acpi_os_printf(", %s\n", acpi_format_exception(method_status)); | |
1da177e4 LT |
158 | } |
159 | ||
1da177e4 LT |
160 | /******************************************************************************* |
161 | * | |
162 | * FUNCTION: acpi_ns_print_node_pathname | |
163 | * | |
44f6c012 RM |
164 | * PARAMETERS: Node - Object |
165 | * Message - Prefix message | |
1da177e4 LT |
166 | * |
167 | * DESCRIPTION: Print an object's full namespace pathname | |
168 | * Manages allocation/freeing of a pathname buffer | |
169 | * | |
170 | ******************************************************************************/ | |
171 | ||
172 | void | |
4be44fcd | 173 | acpi_ns_print_node_pathname(struct acpi_namespace_node *node, char *message) |
1da177e4 | 174 | { |
4be44fcd LB |
175 | struct acpi_buffer buffer; |
176 | acpi_status status; | |
1da177e4 LT |
177 | |
178 | if (!node) { | |
4be44fcd | 179 | acpi_os_printf("[NULL NAME]"); |
1da177e4 LT |
180 | return; |
181 | } | |
182 | ||
183 | /* Convert handle to full pathname and print it (with supplied message) */ | |
184 | ||
185 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; | |
186 | ||
4be44fcd LB |
187 | status = acpi_ns_handle_to_pathname(node, &buffer); |
188 | if (ACPI_SUCCESS(status)) { | |
44f6c012 | 189 | if (message) { |
4be44fcd | 190 | acpi_os_printf("%s ", message); |
1da177e4 LT |
191 | } |
192 | ||
4be44fcd LB |
193 | acpi_os_printf("[%s] (Node %p)", (char *)buffer.pointer, node); |
194 | ACPI_MEM_FREE(buffer.pointer); | |
1da177e4 LT |
195 | } |
196 | } | |
197 | ||
1da177e4 LT |
198 | /******************************************************************************* |
199 | * | |
200 | * FUNCTION: acpi_ns_valid_root_prefix | |
201 | * | |
202 | * PARAMETERS: Prefix - Character to be checked | |
203 | * | |
204 | * RETURN: TRUE if a valid prefix | |
205 | * | |
206 | * DESCRIPTION: Check if a character is a valid ACPI Root prefix | |
207 | * | |
208 | ******************************************************************************/ | |
209 | ||
4be44fcd | 210 | u8 acpi_ns_valid_root_prefix(char prefix) |
1da177e4 LT |
211 | { |
212 | ||
213 | return ((u8) (prefix == '\\')); | |
214 | } | |
215 | ||
1da177e4 LT |
216 | /******************************************************************************* |
217 | * | |
218 | * FUNCTION: acpi_ns_valid_path_separator | |
219 | * | |
44f6c012 | 220 | * PARAMETERS: Sep - Character to be checked |
1da177e4 LT |
221 | * |
222 | * RETURN: TRUE if a valid path separator | |
223 | * | |
224 | * DESCRIPTION: Check if a character is a valid ACPI path separator | |
225 | * | |
226 | ******************************************************************************/ | |
227 | ||
4be44fcd | 228 | static u8 acpi_ns_valid_path_separator(char sep) |
1da177e4 LT |
229 | { |
230 | ||
231 | return ((u8) (sep == '.')); | |
232 | } | |
233 | ||
1da177e4 LT |
234 | /******************************************************************************* |
235 | * | |
236 | * FUNCTION: acpi_ns_get_type | |
237 | * | |
44f6c012 | 238 | * PARAMETERS: Node - Parent Node to be examined |
1da177e4 LT |
239 | * |
240 | * RETURN: Type field from Node whose handle is passed | |
241 | * | |
44f6c012 RM |
242 | * DESCRIPTION: Return the type of a Namespace node |
243 | * | |
1da177e4 LT |
244 | ******************************************************************************/ |
245 | ||
4be44fcd | 246 | acpi_object_type acpi_ns_get_type(struct acpi_namespace_node * node) |
1da177e4 | 247 | { |
4be44fcd | 248 | ACPI_FUNCTION_TRACE("ns_get_type"); |
1da177e4 LT |
249 | |
250 | if (!node) { | |
4be44fcd | 251 | ACPI_REPORT_WARNING(("ns_get_type: Null Node input pointer\n")); |
50eca3eb | 252 | return_UINT32(ACPI_TYPE_ANY); |
1da177e4 LT |
253 | } |
254 | ||
50eca3eb | 255 | return_UINT32((acpi_object_type) node->type); |
1da177e4 LT |
256 | } |
257 | ||
1da177e4 LT |
258 | /******************************************************************************* |
259 | * | |
260 | * FUNCTION: acpi_ns_local | |
261 | * | |
44f6c012 | 262 | * PARAMETERS: Type - A namespace object type |
1da177e4 LT |
263 | * |
264 | * RETURN: LOCAL if names must be found locally in objects of the | |
265 | * passed type, 0 if enclosing scopes should be searched | |
266 | * | |
44f6c012 RM |
267 | * DESCRIPTION: Returns scope rule for the given object type. |
268 | * | |
1da177e4 LT |
269 | ******************************************************************************/ |
270 | ||
4be44fcd | 271 | u32 acpi_ns_local(acpi_object_type type) |
1da177e4 | 272 | { |
4be44fcd | 273 | ACPI_FUNCTION_TRACE("ns_local"); |
1da177e4 | 274 | |
4be44fcd | 275 | if (!acpi_ut_valid_object_type(type)) { |
1da177e4 LT |
276 | /* Type code out of range */ |
277 | ||
4be44fcd | 278 | ACPI_REPORT_WARNING(("ns_local: Invalid Object Type\n")); |
50eca3eb | 279 | return_UINT32(ACPI_NS_NORMAL); |
1da177e4 LT |
280 | } |
281 | ||
50eca3eb | 282 | return_UINT32((u32) acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL); |
1da177e4 LT |
283 | } |
284 | ||
1da177e4 LT |
285 | /******************************************************************************* |
286 | * | |
287 | * FUNCTION: acpi_ns_get_internal_name_length | |
288 | * | |
289 | * PARAMETERS: Info - Info struct initialized with the | |
290 | * external name pointer. | |
291 | * | |
44f6c012 | 292 | * RETURN: None |
1da177e4 LT |
293 | * |
294 | * DESCRIPTION: Calculate the length of the internal (AML) namestring | |
295 | * corresponding to the external (ASL) namestring. | |
296 | * | |
297 | ******************************************************************************/ | |
298 | ||
4be44fcd | 299 | void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info) |
1da177e4 | 300 | { |
4be44fcd LB |
301 | char *next_external_char; |
302 | u32 i; | |
1da177e4 | 303 | |
4be44fcd | 304 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
305 | |
306 | next_external_char = info->external_name; | |
307 | info->num_carats = 0; | |
308 | info->num_segments = 0; | |
309 | info->fully_qualified = FALSE; | |
310 | ||
311 | /* | |
312 | * For the internal name, the required length is 4 bytes per segment, plus | |
313 | * 1 each for root_prefix, multi_name_prefix_op, segment count, trailing null | |
314 | * (which is not really needed, but no there's harm in putting it there) | |
315 | * | |
316 | * strlen() + 1 covers the first name_seg, which has no path separator | |
317 | */ | |
4be44fcd | 318 | if (acpi_ns_valid_root_prefix(next_external_char[0])) { |
1da177e4 LT |
319 | info->fully_qualified = TRUE; |
320 | next_external_char++; | |
4be44fcd | 321 | } else { |
1da177e4 LT |
322 | /* |
323 | * Handle Carat prefixes | |
324 | */ | |
325 | while (*next_external_char == '^') { | |
326 | info->num_carats++; | |
327 | next_external_char++; | |
328 | } | |
329 | } | |
330 | ||
331 | /* | |
332 | * Determine the number of ACPI name "segments" by counting the number of | |
333 | * path separators within the string. Start with one segment since the | |
334 | * segment count is [(# separators) + 1], and zero separators is ok. | |
335 | */ | |
336 | if (*next_external_char) { | |
337 | info->num_segments = 1; | |
338 | for (i = 0; next_external_char[i]; i++) { | |
4be44fcd | 339 | if (acpi_ns_valid_path_separator(next_external_char[i])) { |
1da177e4 LT |
340 | info->num_segments++; |
341 | } | |
342 | } | |
343 | } | |
344 | ||
345 | info->length = (ACPI_NAME_SIZE * info->num_segments) + | |
4be44fcd | 346 | 4 + info->num_carats; |
1da177e4 LT |
347 | |
348 | info->next_external_char = next_external_char; | |
349 | } | |
350 | ||
1da177e4 LT |
351 | /******************************************************************************* |
352 | * | |
353 | * FUNCTION: acpi_ns_build_internal_name | |
354 | * | |
355 | * PARAMETERS: Info - Info struct fully initialized | |
356 | * | |
357 | * RETURN: Status | |
358 | * | |
359 | * DESCRIPTION: Construct the internal (AML) namestring | |
360 | * corresponding to the external (ASL) namestring. | |
361 | * | |
362 | ******************************************************************************/ | |
363 | ||
4be44fcd | 364 | acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info) |
1da177e4 | 365 | { |
4be44fcd LB |
366 | u32 num_segments = info->num_segments; |
367 | char *internal_name = info->internal_name; | |
368 | char *external_name = info->next_external_char; | |
369 | char *result = NULL; | |
370 | acpi_native_uint i; | |
1da177e4 | 371 | |
4be44fcd | 372 | ACPI_FUNCTION_TRACE("ns_build_internal_name"); |
1da177e4 LT |
373 | |
374 | /* Setup the correct prefixes, counts, and pointers */ | |
375 | ||
376 | if (info->fully_qualified) { | |
377 | internal_name[0] = '\\'; | |
378 | ||
379 | if (num_segments <= 1) { | |
380 | result = &internal_name[1]; | |
4be44fcd | 381 | } else if (num_segments == 2) { |
1da177e4 LT |
382 | internal_name[1] = AML_DUAL_NAME_PREFIX; |
383 | result = &internal_name[2]; | |
4be44fcd | 384 | } else { |
1da177e4 | 385 | internal_name[1] = AML_MULTI_NAME_PREFIX_OP; |
4be44fcd | 386 | internal_name[2] = (char)num_segments; |
1da177e4 LT |
387 | result = &internal_name[3]; |
388 | } | |
4be44fcd | 389 | } else { |
1da177e4 LT |
390 | /* |
391 | * Not fully qualified. | |
392 | * Handle Carats first, then append the name segments | |
393 | */ | |
394 | i = 0; | |
395 | if (info->num_carats) { | |
396 | for (i = 0; i < info->num_carats; i++) { | |
397 | internal_name[i] = '^'; | |
398 | } | |
399 | } | |
400 | ||
401 | if (num_segments <= 1) { | |
402 | result = &internal_name[i]; | |
4be44fcd | 403 | } else if (num_segments == 2) { |
1da177e4 | 404 | internal_name[i] = AML_DUAL_NAME_PREFIX; |
4be44fcd LB |
405 | result = &internal_name[(acpi_native_uint) (i + 1)]; |
406 | } else { | |
1da177e4 | 407 | internal_name[i] = AML_MULTI_NAME_PREFIX_OP; |
4be44fcd LB |
408 | internal_name[(acpi_native_uint) (i + 1)] = |
409 | (char)num_segments; | |
410 | result = &internal_name[(acpi_native_uint) (i + 2)]; | |
1da177e4 LT |
411 | } |
412 | } | |
413 | ||
414 | /* Build the name (minus path separators) */ | |
415 | ||
416 | for (; num_segments; num_segments--) { | |
417 | for (i = 0; i < ACPI_NAME_SIZE; i++) { | |
4be44fcd LB |
418 | if (acpi_ns_valid_path_separator(*external_name) || |
419 | (*external_name == 0)) { | |
1da177e4 LT |
420 | /* Pad the segment with underscore(s) if segment is short */ |
421 | ||
422 | result[i] = '_'; | |
4be44fcd | 423 | } else { |
1da177e4 LT |
424 | /* Convert the character to uppercase and save it */ |
425 | ||
4be44fcd LB |
426 | result[i] = |
427 | (char)ACPI_TOUPPER((int)*external_name); | |
1da177e4 LT |
428 | external_name++; |
429 | } | |
430 | } | |
431 | ||
432 | /* Now we must have a path separator, or the pathname is bad */ | |
433 | ||
4be44fcd LB |
434 | if (!acpi_ns_valid_path_separator(*external_name) && |
435 | (*external_name != 0)) { | |
436 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
437 | } |
438 | ||
439 | /* Move on the next segment */ | |
440 | ||
441 | external_name++; | |
442 | result += ACPI_NAME_SIZE; | |
443 | } | |
444 | ||
445 | /* Terminate the string */ | |
446 | ||
447 | *result = 0; | |
448 | ||
449 | if (info->fully_qualified) { | |
4be44fcd LB |
450 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
451 | "Returning [%p] (abs) \"\\%s\"\n", | |
452 | internal_name, internal_name)); | |
453 | } else { | |
454 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n", | |
455 | internal_name, internal_name)); | |
1da177e4 LT |
456 | } |
457 | ||
4be44fcd | 458 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
459 | } |
460 | ||
1da177e4 LT |
461 | /******************************************************************************* |
462 | * | |
463 | * FUNCTION: acpi_ns_internalize_name | |
464 | * | |
465 | * PARAMETERS: *external_name - External representation of name | |
466 | * **Converted Name - Where to return the resulting | |
467 | * internal represention of the name | |
468 | * | |
469 | * RETURN: Status | |
470 | * | |
471 | * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0") | |
472 | * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) | |
473 | * | |
474 | *******************************************************************************/ | |
475 | ||
4be44fcd | 476 | acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name) |
1da177e4 | 477 | { |
4be44fcd LB |
478 | char *internal_name; |
479 | struct acpi_namestring_info info; | |
480 | acpi_status status; | |
1da177e4 | 481 | |
4be44fcd | 482 | ACPI_FUNCTION_TRACE("ns_internalize_name"); |
1da177e4 | 483 | |
4be44fcd LB |
484 | if ((!external_name) || (*external_name == 0) || (!converted_name)) { |
485 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
486 | } |
487 | ||
488 | /* Get the length of the new internal name */ | |
489 | ||
490 | info.external_name = external_name; | |
4be44fcd | 491 | acpi_ns_get_internal_name_length(&info); |
1da177e4 LT |
492 | |
493 | /* We need a segment to store the internal name */ | |
494 | ||
4be44fcd | 495 | internal_name = ACPI_MEM_CALLOCATE(info.length); |
1da177e4 | 496 | if (!internal_name) { |
4be44fcd | 497 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
498 | } |
499 | ||
500 | /* Build the name */ | |
501 | ||
502 | info.internal_name = internal_name; | |
4be44fcd LB |
503 | status = acpi_ns_build_internal_name(&info); |
504 | if (ACPI_FAILURE(status)) { | |
505 | ACPI_MEM_FREE(internal_name); | |
506 | return_ACPI_STATUS(status); | |
1da177e4 LT |
507 | } |
508 | ||
509 | *converted_name = internal_name; | |
4be44fcd | 510 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
511 | } |
512 | ||
1da177e4 LT |
513 | /******************************************************************************* |
514 | * | |
515 | * FUNCTION: acpi_ns_externalize_name | |
516 | * | |
44f6c012 RM |
517 | * PARAMETERS: internal_name_length - Lenth of the internal name below |
518 | * internal_name - Internal representation of name | |
519 | * converted_name_length - Where the length is returned | |
520 | * converted_name - Where the resulting external name | |
521 | * is returned | |
1da177e4 LT |
522 | * |
523 | * RETURN: Status | |
524 | * | |
525 | * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) | |
44f6c012 | 526 | * to its external (printable) form (e.g. "\_PR_.CPU0") |
1da177e4 LT |
527 | * |
528 | ******************************************************************************/ | |
529 | ||
530 | acpi_status | |
4be44fcd LB |
531 | acpi_ns_externalize_name(u32 internal_name_length, |
532 | char *internal_name, | |
533 | u32 * converted_name_length, char **converted_name) | |
1da177e4 | 534 | { |
4be44fcd LB |
535 | acpi_native_uint names_index = 0; |
536 | acpi_native_uint num_segments = 0; | |
537 | acpi_native_uint required_length; | |
538 | acpi_native_uint prefix_length = 0; | |
539 | acpi_native_uint i = 0; | |
540 | acpi_native_uint j = 0; | |
1da177e4 | 541 | |
4be44fcd | 542 | ACPI_FUNCTION_TRACE("ns_externalize_name"); |
1da177e4 | 543 | |
4be44fcd LB |
544 | if (!internal_name_length || !internal_name || !converted_name) { |
545 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
546 | } |
547 | ||
548 | /* | |
549 | * Check for a prefix (one '\' | one or more '^'). | |
550 | */ | |
551 | switch (internal_name[0]) { | |
552 | case '\\': | |
553 | prefix_length = 1; | |
554 | break; | |
555 | ||
556 | case '^': | |
557 | for (i = 0; i < internal_name_length; i++) { | |
558 | if (internal_name[i] == '^') { | |
559 | prefix_length = i + 1; | |
4be44fcd | 560 | } else { |
1da177e4 LT |
561 | break; |
562 | } | |
563 | } | |
564 | ||
565 | if (i == internal_name_length) { | |
566 | prefix_length = i; | |
567 | } | |
568 | ||
569 | break; | |
570 | ||
571 | default: | |
572 | break; | |
573 | } | |
574 | ||
575 | /* | |
576 | * Check for object names. Note that there could be 0-255 of these | |
577 | * 4-byte elements. | |
578 | */ | |
579 | if (prefix_length < internal_name_length) { | |
580 | switch (internal_name[prefix_length]) { | |
581 | case AML_MULTI_NAME_PREFIX_OP: | |
582 | ||
583 | /* <count> 4-byte names */ | |
584 | ||
585 | names_index = prefix_length + 2; | |
586 | num_segments = (acpi_native_uint) (u8) | |
4be44fcd LB |
587 | internal_name[(acpi_native_uint) |
588 | (prefix_length + 1)]; | |
1da177e4 LT |
589 | break; |
590 | ||
591 | case AML_DUAL_NAME_PREFIX: | |
592 | ||
593 | /* Two 4-byte names */ | |
594 | ||
595 | names_index = prefix_length + 1; | |
596 | num_segments = 2; | |
597 | break; | |
598 | ||
599 | case 0: | |
600 | ||
601 | /* null_name */ | |
602 | ||
603 | names_index = 0; | |
604 | num_segments = 0; | |
605 | break; | |
606 | ||
607 | default: | |
608 | ||
609 | /* one 4-byte name */ | |
610 | ||
611 | names_index = prefix_length; | |
612 | num_segments = 1; | |
613 | break; | |
614 | } | |
615 | } | |
616 | ||
617 | /* | |
618 | * Calculate the length of converted_name, which equals the length | |
619 | * of the prefix, length of all object names, length of any required | |
620 | * punctuation ('.') between object names, plus the NULL terminator. | |
621 | */ | |
622 | required_length = prefix_length + (4 * num_segments) + | |
4be44fcd | 623 | ((num_segments > 0) ? (num_segments - 1) : 0) + 1; |
1da177e4 LT |
624 | |
625 | /* | |
626 | * Check to see if we're still in bounds. If not, there's a problem | |
627 | * with internal_name (invalid format). | |
628 | */ | |
629 | if (required_length > internal_name_length) { | |
4be44fcd LB |
630 | ACPI_REPORT_ERROR(("ns_externalize_name: Invalid internal name\n")); |
631 | return_ACPI_STATUS(AE_BAD_PATHNAME); | |
1da177e4 LT |
632 | } |
633 | ||
634 | /* | |
635 | * Build converted_name | |
636 | */ | |
4be44fcd | 637 | *converted_name = ACPI_MEM_CALLOCATE(required_length); |
1da177e4 | 638 | if (!(*converted_name)) { |
4be44fcd | 639 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
640 | } |
641 | ||
642 | j = 0; | |
643 | ||
644 | for (i = 0; i < prefix_length; i++) { | |
645 | (*converted_name)[j++] = internal_name[i]; | |
646 | } | |
647 | ||
648 | if (num_segments > 0) { | |
649 | for (i = 0; i < num_segments; i++) { | |
650 | if (i > 0) { | |
651 | (*converted_name)[j++] = '.'; | |
652 | } | |
653 | ||
654 | (*converted_name)[j++] = internal_name[names_index++]; | |
655 | (*converted_name)[j++] = internal_name[names_index++]; | |
656 | (*converted_name)[j++] = internal_name[names_index++]; | |
657 | (*converted_name)[j++] = internal_name[names_index++]; | |
658 | } | |
659 | } | |
660 | ||
661 | if (converted_name_length) { | |
662 | *converted_name_length = (u32) required_length; | |
663 | } | |
664 | ||
4be44fcd | 665 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
666 | } |
667 | ||
1da177e4 LT |
668 | /******************************************************************************* |
669 | * | |
670 | * FUNCTION: acpi_ns_map_handle_to_node | |
671 | * | |
672 | * PARAMETERS: Handle - Handle to be converted to an Node | |
673 | * | |
674 | * RETURN: A Name table entry pointer | |
675 | * | |
676 | * DESCRIPTION: Convert a namespace handle to a real Node | |
677 | * | |
44f6c012 RM |
678 | * Note: Real integer handles would allow for more verification |
679 | * and keep all pointers within this subsystem - however this introduces | |
680 | * more (and perhaps unnecessary) overhead. | |
1da177e4 LT |
681 | * |
682 | ******************************************************************************/ | |
683 | ||
4be44fcd | 684 | struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle) |
1da177e4 LT |
685 | { |
686 | ||
4be44fcd | 687 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
688 | |
689 | /* | |
690 | * Simple implementation. | |
691 | */ | |
692 | if (!handle) { | |
693 | return (NULL); | |
694 | } | |
695 | ||
696 | if (handle == ACPI_ROOT_OBJECT) { | |
697 | return (acpi_gbl_root_node); | |
698 | } | |
699 | ||
700 | /* We can at least attempt to verify the handle */ | |
701 | ||
4be44fcd | 702 | if (ACPI_GET_DESCRIPTOR_TYPE(handle) != ACPI_DESC_TYPE_NAMED) { |
1da177e4 LT |
703 | return (NULL); |
704 | } | |
705 | ||
4be44fcd | 706 | return ((struct acpi_namespace_node *)handle); |
1da177e4 LT |
707 | } |
708 | ||
1da177e4 LT |
709 | /******************************************************************************* |
710 | * | |
711 | * FUNCTION: acpi_ns_convert_entry_to_handle | |
712 | * | |
713 | * PARAMETERS: Node - Node to be converted to a Handle | |
714 | * | |
715 | * RETURN: A user handle | |
716 | * | |
717 | * DESCRIPTION: Convert a real Node to a namespace handle | |
718 | * | |
719 | ******************************************************************************/ | |
720 | ||
4be44fcd | 721 | acpi_handle acpi_ns_convert_entry_to_handle(struct acpi_namespace_node *node) |
1da177e4 LT |
722 | { |
723 | ||
1da177e4 LT |
724 | /* |
725 | * Simple implementation for now; | |
726 | */ | |
727 | return ((acpi_handle) node); | |
728 | ||
44f6c012 | 729 | /* Example future implementation --------------------- |
1da177e4 LT |
730 | |
731 | if (!Node) | |
732 | { | |
733 | return (NULL); | |
734 | } | |
735 | ||
736 | if (Node == acpi_gbl_root_node) | |
737 | { | |
738 | return (ACPI_ROOT_OBJECT); | |
739 | } | |
740 | ||
1da177e4 LT |
741 | return ((acpi_handle) Node); |
742 | ------------------------------------------------------*/ | |
743 | } | |
744 | ||
1da177e4 LT |
745 | /******************************************************************************* |
746 | * | |
747 | * FUNCTION: acpi_ns_terminate | |
748 | * | |
749 | * PARAMETERS: none | |
750 | * | |
751 | * RETURN: none | |
752 | * | |
44f6c012 | 753 | * DESCRIPTION: free memory allocated for namespace and ACPI table storage. |
1da177e4 LT |
754 | * |
755 | ******************************************************************************/ | |
756 | ||
4be44fcd | 757 | void acpi_ns_terminate(void) |
1da177e4 | 758 | { |
4be44fcd | 759 | union acpi_operand_object *obj_desc; |
1da177e4 | 760 | |
4be44fcd | 761 | ACPI_FUNCTION_TRACE("ns_terminate"); |
1da177e4 LT |
762 | |
763 | /* | |
764 | * 1) Free the entire namespace -- all nodes and objects | |
765 | * | |
766 | * Delete all object descriptors attached to namepsace nodes | |
767 | */ | |
4be44fcd | 768 | acpi_ns_delete_namespace_subtree(acpi_gbl_root_node); |
1da177e4 LT |
769 | |
770 | /* Detach any objects attached to the root */ | |
771 | ||
4be44fcd | 772 | obj_desc = acpi_ns_get_attached_object(acpi_gbl_root_node); |
1da177e4 | 773 | if (obj_desc) { |
4be44fcd | 774 | acpi_ns_detach_object(acpi_gbl_root_node); |
1da177e4 LT |
775 | } |
776 | ||
4be44fcd | 777 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n")); |
1da177e4 LT |
778 | |
779 | /* | |
780 | * 2) Now we can delete the ACPI tables | |
781 | */ | |
4be44fcd LB |
782 | acpi_tb_delete_all_tables(); |
783 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n")); | |
1da177e4 LT |
784 | |
785 | return_VOID; | |
786 | } | |
787 | ||
1da177e4 LT |
788 | /******************************************************************************* |
789 | * | |
790 | * FUNCTION: acpi_ns_opens_scope | |
791 | * | |
792 | * PARAMETERS: Type - A valid namespace type | |
793 | * | |
794 | * RETURN: NEWSCOPE if the passed type "opens a name scope" according | |
795 | * to the ACPI specification, else 0 | |
796 | * | |
797 | ******************************************************************************/ | |
798 | ||
4be44fcd | 799 | u32 acpi_ns_opens_scope(acpi_object_type type) |
1da177e4 | 800 | { |
4be44fcd | 801 | ACPI_FUNCTION_TRACE_STR("ns_opens_scope", acpi_ut_get_type_name(type)); |
1da177e4 | 802 | |
4be44fcd | 803 | if (!acpi_ut_valid_object_type(type)) { |
1da177e4 LT |
804 | /* type code out of range */ |
805 | ||
4be44fcd LB |
806 | ACPI_REPORT_WARNING(("ns_opens_scope: Invalid Object Type %X\n", |
807 | type)); | |
50eca3eb | 808 | return_UINT32(ACPI_NS_NORMAL); |
1da177e4 LT |
809 | } |
810 | ||
50eca3eb | 811 | return_UINT32(((u32) acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE); |
1da177e4 LT |
812 | } |
813 | ||
1da177e4 LT |
814 | /******************************************************************************* |
815 | * | |
816 | * FUNCTION: acpi_ns_get_node_by_path | |
817 | * | |
818 | * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The | |
819 | * \ (backslash) and ^ (carat) prefixes, and the | |
820 | * . (period) to separate segments are supported. | |
821 | * start_node - Root of subtree to be searched, or NS_ALL for the | |
822 | * root of the name space. If Name is fully | |
823 | * qualified (first s8 is '\'), the passed value | |
824 | * of Scope will not be accessed. | |
825 | * Flags - Used to indicate whether to perform upsearch or | |
826 | * not. | |
827 | * return_node - Where the Node is returned | |
828 | * | |
829 | * DESCRIPTION: Look up a name relative to a given scope and return the | |
830 | * corresponding Node. NOTE: Scope can be null. | |
831 | * | |
832 | * MUTEX: Locks namespace | |
833 | * | |
834 | ******************************************************************************/ | |
835 | ||
836 | acpi_status | |
4be44fcd LB |
837 | acpi_ns_get_node_by_path(char *pathname, |
838 | struct acpi_namespace_node *start_node, | |
839 | u32 flags, struct acpi_namespace_node **return_node) | |
1da177e4 | 840 | { |
4be44fcd LB |
841 | union acpi_generic_state scope_info; |
842 | acpi_status status; | |
843 | char *internal_path = NULL; | |
1da177e4 | 844 | |
4be44fcd | 845 | ACPI_FUNCTION_TRACE_PTR("ns_get_node_by_path", pathname); |
1da177e4 LT |
846 | |
847 | if (pathname) { | |
848 | /* Convert path to internal representation */ | |
849 | ||
4be44fcd LB |
850 | status = acpi_ns_internalize_name(pathname, &internal_path); |
851 | if (ACPI_FAILURE(status)) { | |
852 | return_ACPI_STATUS(status); | |
1da177e4 LT |
853 | } |
854 | } | |
855 | ||
856 | /* Must lock namespace during lookup */ | |
857 | ||
4be44fcd LB |
858 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
859 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
860 | goto cleanup; |
861 | } | |
862 | ||
863 | /* Setup lookup scope (search starting point) */ | |
864 | ||
865 | scope_info.scope.node = start_node; | |
866 | ||
867 | /* Lookup the name in the namespace */ | |
868 | ||
4be44fcd LB |
869 | status = acpi_ns_lookup(&scope_info, internal_path, |
870 | ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, | |
871 | (flags | ACPI_NS_DONT_OPEN_SCOPE), | |
872 | NULL, return_node); | |
873 | if (ACPI_FAILURE(status)) { | |
874 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s, %s\n", | |
875 | internal_path, | |
876 | acpi_format_exception(status))); | |
1da177e4 LT |
877 | } |
878 | ||
4be44fcd | 879 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 | 880 | |
4be44fcd | 881 | cleanup: |
1da177e4 | 882 | if (internal_path) { |
4be44fcd | 883 | ACPI_MEM_FREE(internal_path); |
1da177e4 | 884 | } |
4be44fcd | 885 | return_ACPI_STATUS(status); |
1da177e4 LT |
886 | } |
887 | ||
1da177e4 LT |
888 | /******************************************************************************* |
889 | * | |
890 | * FUNCTION: acpi_ns_get_parent_node | |
891 | * | |
892 | * PARAMETERS: Node - Current table entry | |
893 | * | |
894 | * RETURN: Parent entry of the given entry | |
895 | * | |
896 | * DESCRIPTION: Obtain the parent entry for a given entry in the namespace. | |
897 | * | |
898 | ******************************************************************************/ | |
899 | ||
4be44fcd LB |
900 | struct acpi_namespace_node *acpi_ns_get_parent_node(struct acpi_namespace_node |
901 | *node) | |
1da177e4 | 902 | { |
4be44fcd | 903 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
904 | |
905 | if (!node) { | |
906 | return (NULL); | |
907 | } | |
908 | ||
909 | /* | |
910 | * Walk to the end of this peer list. The last entry is marked with a flag | |
911 | * and the peer pointer is really a pointer back to the parent. This saves | |
912 | * putting a parent back pointer in each and every named object! | |
913 | */ | |
914 | while (!(node->flags & ANOBJ_END_OF_PEER_LIST)) { | |
915 | node = node->peer; | |
916 | } | |
917 | ||
1da177e4 LT |
918 | return (node->peer); |
919 | } | |
920 | ||
1da177e4 LT |
921 | /******************************************************************************* |
922 | * | |
923 | * FUNCTION: acpi_ns_get_next_valid_node | |
924 | * | |
925 | * PARAMETERS: Node - Current table entry | |
926 | * | |
927 | * RETURN: Next valid Node in the linked node list. NULL if no more valid | |
928 | * nodes. | |
929 | * | |
930 | * DESCRIPTION: Find the next valid node within a name table. | |
931 | * Useful for implementing NULL-end-of-list loops. | |
932 | * | |
933 | ******************************************************************************/ | |
934 | ||
4be44fcd LB |
935 | struct acpi_namespace_node *acpi_ns_get_next_valid_node(struct |
936 | acpi_namespace_node | |
937 | *node) | |
1da177e4 LT |
938 | { |
939 | ||
940 | /* If we are at the end of this peer list, return NULL */ | |
941 | ||
942 | if (node->flags & ANOBJ_END_OF_PEER_LIST) { | |
943 | return NULL; | |
944 | } | |
945 | ||
946 | /* Otherwise just return the next peer */ | |
947 | ||
948 | return (node->peer); | |
949 | } | |
950 | ||
44f6c012 RM |
951 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
952 | /******************************************************************************* | |
953 | * | |
954 | * FUNCTION: acpi_ns_find_parent_name | |
955 | * | |
956 | * PARAMETERS: *child_node - Named Obj whose name is to be found | |
957 | * | |
958 | * RETURN: The ACPI name | |
959 | * | |
960 | * DESCRIPTION: Search for the given obj in its parent scope and return the | |
961 | * name segment, or "????" if the parent name can't be found | |
962 | * (which "should not happen"). | |
963 | * | |
964 | ******************************************************************************/ | |
965 | ||
4be44fcd | 966 | acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node * child_node) |
44f6c012 | 967 | { |
4be44fcd | 968 | struct acpi_namespace_node *parent_node; |
44f6c012 | 969 | |
4be44fcd | 970 | ACPI_FUNCTION_TRACE("ns_find_parent_name"); |
44f6c012 RM |
971 | |
972 | if (child_node) { | |
973 | /* Valid entry. Get the parent Node */ | |
974 | ||
4be44fcd | 975 | parent_node = acpi_ns_get_parent_node(child_node); |
44f6c012 | 976 | if (parent_node) { |
4be44fcd LB |
977 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
978 | "Parent of %p [%4.4s] is %p [%4.4s]\n", | |
979 | child_node, | |
980 | acpi_ut_get_node_name(child_node), | |
981 | parent_node, | |
982 | acpi_ut_get_node_name(parent_node))); | |
44f6c012 RM |
983 | |
984 | if (parent_node->name.integer) { | |
4be44fcd LB |
985 | return_VALUE((acpi_name) parent_node->name. |
986 | integer); | |
44f6c012 RM |
987 | } |
988 | } | |
989 | ||
4be44fcd LB |
990 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
991 | "Unable to find parent of %p (%4.4s)\n", | |
992 | child_node, | |
993 | acpi_ut_get_node_name(child_node))); | |
44f6c012 RM |
994 | } |
995 | ||
4be44fcd | 996 | return_VALUE(ACPI_UNKNOWN_NAME); |
44f6c012 RM |
997 | } |
998 | #endif |