initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / namespace / nsutils.c
blobbf49ce29651344c30262d24c7c1361d31995ae79
1 /******************************************************************************
3 * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
4 * parents and siblings and Scope manipulation
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2004, R. Byron Moore
10 * All rights reserved.
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.
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.
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.
46 #include <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
48 #include <acpi/amlcode.h>
49 #include <acpi/actables.h>
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsutils")
55 /*******************************************************************************
57 * FUNCTION: acpi_ns_report_error
59 * PARAMETERS: module_name - Caller's module name (for error output)
60 * line_number - Caller's line number (for error output)
61 * component_id - Caller's component ID (for error output)
62 * Message - Error message to use on failure
64 * RETURN: None
66 * DESCRIPTION: Print warning message with full pathname
68 ******************************************************************************/
70 void
71 acpi_ns_report_error (
72 char *module_name,
73 u32 line_number,
74 u32 component_id,
75 char *internal_name,
76 acpi_status lookup_status)
78 acpi_status status;
79 char *name = NULL;
82 acpi_os_printf ("%8s-%04d: *** Error: Looking up ",
83 module_name, line_number);
85 if (lookup_status == AE_BAD_CHARACTER) {
86 /* There is a non-ascii character in the name */
88 acpi_os_printf ("[0x%4.4X] (NON-ASCII)\n", *(ACPI_CAST_PTR (u32, internal_name)));
90 else {
91 /* Convert path to external format */
93 status = acpi_ns_externalize_name (ACPI_UINT32_MAX, internal_name, NULL, &name);
95 /* Print target name */
97 if (ACPI_SUCCESS (status)) {
98 acpi_os_printf ("[%s]", name);
100 else {
101 acpi_os_printf ("[COULD NOT EXTERNALIZE NAME]");
104 if (name) {
105 ACPI_MEM_FREE (name);
109 acpi_os_printf (" in namespace, %s\n",
110 acpi_format_exception (lookup_status));
114 /*******************************************************************************
116 * FUNCTION: acpi_ns_report_method_error
118 * PARAMETERS: module_name - Caller's module name (for error output)
119 * line_number - Caller's line number (for error output)
120 * component_id - Caller's component ID (for error output)
121 * Message - Error message to use on failure
123 * RETURN: None
125 * DESCRIPTION: Print warning message with full pathname
127 ******************************************************************************/
129 void
130 acpi_ns_report_method_error (
131 char *module_name,
132 u32 line_number,
133 u32 component_id,
134 char *message,
135 struct acpi_namespace_node *prefix_node,
136 char *path,
137 acpi_status method_status)
139 acpi_status status;
140 struct acpi_namespace_node *node = prefix_node;
143 if (path) {
144 status = acpi_ns_get_node_by_path (path, prefix_node, ACPI_NS_NO_UPSEARCH, &node);
145 if (ACPI_FAILURE (status)) {
146 acpi_os_printf ("report_method_error: Could not get node\n");
147 return;
151 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
152 acpi_ns_print_node_pathname (node, message);
153 acpi_os_printf (", %s\n", acpi_format_exception (method_status));
157 /*******************************************************************************
159 * FUNCTION: acpi_ns_print_node_pathname
161 * PARAMETERS: Node - Object
162 * Msg - Prefix message
164 * DESCRIPTION: Print an object's full namespace pathname
165 * Manages allocation/freeing of a pathname buffer
167 ******************************************************************************/
169 void
170 acpi_ns_print_node_pathname (
171 struct acpi_namespace_node *node,
172 char *msg)
174 struct acpi_buffer buffer;
175 acpi_status status;
178 if (!node) {
179 acpi_os_printf ("[NULL NAME]");
180 return;
183 /* Convert handle to a full pathname and print it (with supplied message) */
185 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
187 status = acpi_ns_handle_to_pathname (node, &buffer);
188 if (ACPI_SUCCESS (status)) {
189 if (msg) {
190 acpi_os_printf ("%s ", msg);
193 acpi_os_printf ("[%s] (Node %p)", (char *) buffer.pointer, node);
194 ACPI_MEM_FREE (buffer.pointer);
199 /*******************************************************************************
201 * FUNCTION: acpi_ns_valid_root_prefix
203 * PARAMETERS: Prefix - Character to be checked
205 * RETURN: TRUE if a valid prefix
207 * DESCRIPTION: Check if a character is a valid ACPI Root prefix
209 ******************************************************************************/
212 acpi_ns_valid_root_prefix (
213 char prefix)
216 return ((u8) (prefix == '\\'));
220 /*******************************************************************************
222 * FUNCTION: acpi_ns_valid_path_separator
224 * PARAMETERS: Sep - Character to be checked
226 * RETURN: TRUE if a valid path separator
228 * DESCRIPTION: Check if a character is a valid ACPI path separator
230 ******************************************************************************/
233 acpi_ns_valid_path_separator (
234 char sep)
237 return ((u8) (sep == '.'));
241 /*******************************************************************************
243 * FUNCTION: acpi_ns_get_type
245 * PARAMETERS: Handle - Parent Node to be examined
247 * RETURN: Type field from Node whose handle is passed
249 ******************************************************************************/
251 acpi_object_type
252 acpi_ns_get_type (
253 struct acpi_namespace_node *node)
255 ACPI_FUNCTION_TRACE ("ns_get_type");
258 if (!node) {
259 ACPI_REPORT_WARNING (("ns_get_type: Null Node input pointer\n"));
260 return_VALUE (ACPI_TYPE_ANY);
263 return_VALUE ((acpi_object_type) node->type);
267 /*******************************************************************************
269 * FUNCTION: acpi_ns_local
271 * PARAMETERS: Type - A namespace object type
273 * RETURN: LOCAL if names must be found locally in objects of the
274 * passed type, 0 if enclosing scopes should be searched
276 ******************************************************************************/
279 acpi_ns_local (
280 acpi_object_type type)
282 ACPI_FUNCTION_TRACE ("ns_local");
285 if (!acpi_ut_valid_object_type (type)) {
286 /* Type code out of range */
288 ACPI_REPORT_WARNING (("ns_local: Invalid Object Type\n"));
289 return_VALUE (ACPI_NS_NORMAL);
292 return_VALUE ((u32) acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL);
296 /*******************************************************************************
298 * FUNCTION: acpi_ns_get_internal_name_length
300 * PARAMETERS: Info - Info struct initialized with the
301 * external name pointer.
303 * RETURN: Status
305 * DESCRIPTION: Calculate the length of the internal (AML) namestring
306 * corresponding to the external (ASL) namestring.
308 ******************************************************************************/
310 void
311 acpi_ns_get_internal_name_length (
312 struct acpi_namestring_info *info)
314 char *next_external_char;
315 u32 i;
318 ACPI_FUNCTION_ENTRY ();
321 next_external_char = info->external_name;
322 info->num_carats = 0;
323 info->num_segments = 0;
324 info->fully_qualified = FALSE;
327 * For the internal name, the required length is 4 bytes
328 * per segment, plus 1 each for root_prefix, multi_name_prefix_op,
329 * segment count, trailing null (which is not really needed,
330 * but no there's harm in putting it there)
332 * strlen() + 1 covers the first name_seg, which has no
333 * path separator
335 if (acpi_ns_valid_root_prefix (next_external_char[0])) {
336 info->fully_qualified = TRUE;
337 next_external_char++;
339 else {
341 * Handle Carat prefixes
343 while (*next_external_char == '^') {
344 info->num_carats++;
345 next_external_char++;
350 * Determine the number of ACPI name "segments" by counting
351 * the number of path separators within the string. Start
352 * with one segment since the segment count is (# separators)
353 * + 1, and zero separators is ok.
355 if (*next_external_char) {
356 info->num_segments = 1;
357 for (i = 0; next_external_char[i]; i++) {
358 if (acpi_ns_valid_path_separator (next_external_char[i])) {
359 info->num_segments++;
364 info->length = (ACPI_NAME_SIZE * info->num_segments) +
365 4 + info->num_carats;
367 info->next_external_char = next_external_char;
371 /*******************************************************************************
373 * FUNCTION: acpi_ns_build_internal_name
375 * PARAMETERS: Info - Info struct fully initialized
377 * RETURN: Status
379 * DESCRIPTION: Construct the internal (AML) namestring
380 * corresponding to the external (ASL) namestring.
382 ******************************************************************************/
384 acpi_status
385 acpi_ns_build_internal_name (
386 struct acpi_namestring_info *info)
388 u32 num_segments = info->num_segments;
389 char *internal_name = info->internal_name;
390 char *external_name = info->next_external_char;
391 char *result = NULL;
392 acpi_native_uint i;
395 ACPI_FUNCTION_TRACE ("ns_build_internal_name");
398 /* Setup the correct prefixes, counts, and pointers */
400 if (info->fully_qualified) {
401 internal_name[0] = '\\';
403 if (num_segments <= 1) {
404 result = &internal_name[1];
406 else if (num_segments == 2) {
407 internal_name[1] = AML_DUAL_NAME_PREFIX;
408 result = &internal_name[2];
410 else {
411 internal_name[1] = AML_MULTI_NAME_PREFIX_OP;
412 internal_name[2] = (char) num_segments;
413 result = &internal_name[3];
416 else {
418 * Not fully qualified.
419 * Handle Carats first, then append the name segments
421 i = 0;
422 if (info->num_carats) {
423 for (i = 0; i < info->num_carats; i++) {
424 internal_name[i] = '^';
428 if (num_segments <= 1) {
429 result = &internal_name[i];
431 else if (num_segments == 2) {
432 internal_name[i] = AML_DUAL_NAME_PREFIX;
433 result = &internal_name[(acpi_native_uint) (i+1)];
435 else {
436 internal_name[i] = AML_MULTI_NAME_PREFIX_OP;
437 internal_name[(acpi_native_uint) (i+1)] = (char) num_segments;
438 result = &internal_name[(acpi_native_uint) (i+2)];
442 /* Build the name (minus path separators) */
444 for (; num_segments; num_segments--) {
445 for (i = 0; i < ACPI_NAME_SIZE; i++) {
446 if (acpi_ns_valid_path_separator (*external_name) ||
447 (*external_name == 0)) {
448 /* Pad the segment with underscore(s) if segment is short */
450 result[i] = '_';
452 else {
453 /* Convert the character to uppercase and save it */
455 result[i] = (char) ACPI_TOUPPER ((int) *external_name);
456 external_name++;
460 /* Now we must have a path separator, or the pathname is bad */
462 if (!acpi_ns_valid_path_separator (*external_name) &&
463 (*external_name != 0)) {
464 return_ACPI_STATUS (AE_BAD_PARAMETER);
467 /* Move on the next segment */
469 external_name++;
470 result += ACPI_NAME_SIZE;
473 /* Terminate the string */
475 *result = 0;
477 if (info->fully_qualified) {
478 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
479 internal_name, internal_name));
481 else {
482 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
483 internal_name, internal_name));
486 return_ACPI_STATUS (AE_OK);
490 /*******************************************************************************
492 * FUNCTION: acpi_ns_internalize_name
494 * PARAMETERS: *external_name - External representation of name
495 * **Converted Name - Where to return the resulting
496 * internal represention of the name
498 * RETURN: Status
500 * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
501 * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
503 *******************************************************************************/
505 acpi_status
506 acpi_ns_internalize_name (
507 char *external_name,
508 char **converted_name)
510 char *internal_name;
511 struct acpi_namestring_info info;
512 acpi_status status;
515 ACPI_FUNCTION_TRACE ("ns_internalize_name");
518 if ((!external_name) ||
519 (*external_name == 0) ||
520 (!converted_name)) {
521 return_ACPI_STATUS (AE_BAD_PARAMETER);
524 /* Get the length of the new internal name */
526 info.external_name = external_name;
527 acpi_ns_get_internal_name_length (&info);
529 /* We need a segment to store the internal name */
531 internal_name = ACPI_MEM_CALLOCATE (info.length);
532 if (!internal_name) {
533 return_ACPI_STATUS (AE_NO_MEMORY);
536 /* Build the name */
538 info.internal_name = internal_name;
539 status = acpi_ns_build_internal_name (&info);
540 if (ACPI_FAILURE (status)) {
541 ACPI_MEM_FREE (internal_name);
542 return_ACPI_STATUS (status);
545 *converted_name = internal_name;
546 return_ACPI_STATUS (AE_OK);
550 /*******************************************************************************
552 * FUNCTION: acpi_ns_externalize_name
554 * PARAMETERS: *internal_name - Internal representation of name
555 * **converted_name - Where to return the resulting
556 * external representation of name
558 * RETURN: Status
560 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
561 * to its external form (e.g. "\_PR_.CPU0")
563 ******************************************************************************/
565 acpi_status
566 acpi_ns_externalize_name (
567 u32 internal_name_length,
568 char *internal_name,
569 u32 *converted_name_length,
570 char **converted_name)
572 acpi_native_uint names_index = 0;
573 acpi_native_uint num_segments = 0;
574 acpi_native_uint required_length;
575 acpi_native_uint prefix_length = 0;
576 acpi_native_uint i = 0;
577 acpi_native_uint j = 0;
580 ACPI_FUNCTION_TRACE ("ns_externalize_name");
583 if (!internal_name_length ||
584 !internal_name ||
585 !converted_name) {
586 return_ACPI_STATUS (AE_BAD_PARAMETER);
590 * Check for a prefix (one '\' | one or more '^').
592 switch (internal_name[0]) {
593 case '\\':
594 prefix_length = 1;
595 break;
597 case '^':
598 for (i = 0; i < internal_name_length; i++) {
599 if (internal_name[i] == '^') {
600 prefix_length = i + 1;
602 else {
603 break;
607 if (i == internal_name_length) {
608 prefix_length = i;
611 break;
613 default:
614 break;
618 * Check for object names. Note that there could be 0-255 of these
619 * 4-byte elements.
621 if (prefix_length < internal_name_length) {
622 switch (internal_name[prefix_length]) {
623 case AML_MULTI_NAME_PREFIX_OP:
625 /* <count> 4-byte names */
627 names_index = prefix_length + 2;
628 num_segments = (acpi_native_uint) (u8) internal_name[(acpi_native_uint) (prefix_length + 1)];
629 break;
631 case AML_DUAL_NAME_PREFIX:
633 /* Two 4-byte names */
635 names_index = prefix_length + 1;
636 num_segments = 2;
637 break;
639 case 0:
641 /* null_name */
643 names_index = 0;
644 num_segments = 0;
645 break;
647 default:
649 /* one 4-byte name */
651 names_index = prefix_length;
652 num_segments = 1;
653 break;
658 * Calculate the length of converted_name, which equals the length
659 * of the prefix, length of all object names, length of any required
660 * punctuation ('.') between object names, plus the NULL terminator.
662 required_length = prefix_length + (4 * num_segments) +
663 ((num_segments > 0) ? (num_segments - 1) : 0) + 1;
666 * Check to see if we're still in bounds. If not, there's a problem
667 * with internal_name (invalid format).
669 if (required_length > internal_name_length) {
670 ACPI_REPORT_ERROR (("ns_externalize_name: Invalid internal name\n"));
671 return_ACPI_STATUS (AE_BAD_PATHNAME);
675 * Build converted_name...
677 *converted_name = ACPI_MEM_CALLOCATE (required_length);
678 if (!(*converted_name)) {
679 return_ACPI_STATUS (AE_NO_MEMORY);
682 j = 0;
684 for (i = 0; i < prefix_length; i++) {
685 (*converted_name)[j++] = internal_name[i];
688 if (num_segments > 0) {
689 for (i = 0; i < num_segments; i++) {
690 if (i > 0) {
691 (*converted_name)[j++] = '.';
694 (*converted_name)[j++] = internal_name[names_index++];
695 (*converted_name)[j++] = internal_name[names_index++];
696 (*converted_name)[j++] = internal_name[names_index++];
697 (*converted_name)[j++] = internal_name[names_index++];
701 if (converted_name_length) {
702 *converted_name_length = (u32) required_length;
705 return_ACPI_STATUS (AE_OK);
709 /*******************************************************************************
711 * FUNCTION: acpi_ns_map_handle_to_node
713 * PARAMETERS: Handle - Handle to be converted to an Node
715 * RETURN: A Name table entry pointer
717 * DESCRIPTION: Convert a namespace handle to a real Node
719 * Note: Real integer handles allow for more verification
720 * and keep all pointers within this subsystem.
722 ******************************************************************************/
724 struct acpi_namespace_node *
725 acpi_ns_map_handle_to_node (
726 acpi_handle handle)
729 ACPI_FUNCTION_ENTRY ();
733 * Simple implementation.
735 if (!handle) {
736 return (NULL);
739 if (handle == ACPI_ROOT_OBJECT) {
740 return (acpi_gbl_root_node);
743 /* We can at least attempt to verify the handle */
745 if (ACPI_GET_DESCRIPTOR_TYPE (handle) != ACPI_DESC_TYPE_NAMED) {
746 return (NULL);
749 return ((struct acpi_namespace_node *) handle);
753 /*******************************************************************************
755 * FUNCTION: acpi_ns_convert_entry_to_handle
757 * PARAMETERS: Node - Node to be converted to a Handle
759 * RETURN: An USER acpi_handle
761 * DESCRIPTION: Convert a real Node to a namespace handle
763 ******************************************************************************/
765 acpi_handle
766 acpi_ns_convert_entry_to_handle (
767 struct acpi_namespace_node *node)
772 * Simple implementation for now;
774 return ((acpi_handle) node);
777 /* ---------------------------------------------------
779 if (!Node)
781 return (NULL);
784 if (Node == acpi_gbl_root_node)
786 return (ACPI_ROOT_OBJECT);
790 return ((acpi_handle) Node);
791 ------------------------------------------------------*/
795 /*******************************************************************************
797 * FUNCTION: acpi_ns_terminate
799 * PARAMETERS: none
801 * RETURN: none
803 * DESCRIPTION: free memory allocated for table storage.
805 ******************************************************************************/
807 void
808 acpi_ns_terminate (void)
810 union acpi_operand_object *obj_desc;
813 ACPI_FUNCTION_TRACE ("ns_terminate");
817 * 1) Free the entire namespace -- all nodes and objects
819 * Delete all object descriptors attached to namepsace nodes
821 acpi_ns_delete_namespace_subtree (acpi_gbl_root_node);
823 /* Detach any objects attached to the root */
825 obj_desc = acpi_ns_get_attached_object (acpi_gbl_root_node);
826 if (obj_desc) {
827 acpi_ns_detach_object (acpi_gbl_root_node);
830 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
833 * 2) Now we can delete the ACPI tables
835 acpi_tb_delete_all_tables ();
836 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
838 return_VOID;
842 /*******************************************************************************
844 * FUNCTION: acpi_ns_opens_scope
846 * PARAMETERS: Type - A valid namespace type
848 * RETURN: NEWSCOPE if the passed type "opens a name scope" according
849 * to the ACPI specification, else 0
851 ******************************************************************************/
854 acpi_ns_opens_scope (
855 acpi_object_type type)
857 ACPI_FUNCTION_TRACE_STR ("ns_opens_scope", acpi_ut_get_type_name (type));
860 if (!acpi_ut_valid_object_type (type)) {
861 /* type code out of range */
863 ACPI_REPORT_WARNING (("ns_opens_scope: Invalid Object Type %X\n", type));
864 return_VALUE (ACPI_NS_NORMAL);
867 return_VALUE (((u32) acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE);
871 /*******************************************************************************
873 * FUNCTION: acpi_ns_get_node_by_path
875 * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
876 * \ (backslash) and ^ (carat) prefixes, and the
877 * . (period) to separate segments are supported.
878 * start_node - Root of subtree to be searched, or NS_ALL for the
879 * root of the name space. If Name is fully
880 * qualified (first s8 is '\'), the passed value
881 * of Scope will not be accessed.
882 * Flags - Used to indicate whether to perform upsearch or
883 * not.
884 * return_node - Where the Node is returned
886 * DESCRIPTION: Look up a name relative to a given scope and return the
887 * corresponding Node. NOTE: Scope can be null.
889 * MUTEX: Locks namespace
891 ******************************************************************************/
893 acpi_status
894 acpi_ns_get_node_by_path (
895 char *pathname,
896 struct acpi_namespace_node *start_node,
897 u32 flags,
898 struct acpi_namespace_node **return_node)
900 union acpi_generic_state scope_info;
901 acpi_status status;
902 char *internal_path = NULL;
905 ACPI_FUNCTION_TRACE_PTR ("ns_get_node_by_path", pathname);
908 if (pathname) {
909 /* Convert path to internal representation */
911 status = acpi_ns_internalize_name (pathname, &internal_path);
912 if (ACPI_FAILURE (status)) {
913 return_ACPI_STATUS (status);
917 /* Must lock namespace during lookup */
919 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
920 if (ACPI_FAILURE (status)) {
921 goto cleanup;
924 /* Setup lookup scope (search starting point) */
926 scope_info.scope.node = start_node;
928 /* Lookup the name in the namespace */
930 status = acpi_ns_lookup (&scope_info, internal_path,
931 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
932 (flags | ACPI_NS_DONT_OPEN_SCOPE),
933 NULL, return_node);
934 if (ACPI_FAILURE (status)) {
935 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
936 internal_path, acpi_format_exception (status)));
939 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
941 cleanup:
942 /* Cleanup */
943 if (internal_path) {
944 ACPI_MEM_FREE (internal_path);
946 return_ACPI_STATUS (status);
950 /*******************************************************************************
952 * FUNCTION: acpi_ns_find_parent_name
954 * PARAMETERS: *child_node - Named Obj whose name is to be found
956 * RETURN: The ACPI name
958 * DESCRIPTION: Search for the given obj in its parent scope and return the
959 * name segment, or "????" if the parent name can't be found
960 * (which "should not happen").
962 ******************************************************************************/
964 acpi_name
965 acpi_ns_find_parent_name (
966 struct acpi_namespace_node *child_node)
968 struct acpi_namespace_node *parent_node;
971 ACPI_FUNCTION_TRACE ("ns_find_parent_name");
974 if (child_node) {
975 /* Valid entry. Get the parent Node */
977 parent_node = acpi_ns_get_parent_node (child_node);
978 if (parent_node) {
979 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Parent of %p [%4.4s] is %p [%4.4s]\n",
980 child_node, acpi_ut_get_node_name (child_node),
981 parent_node, acpi_ut_get_node_name (parent_node)));
983 if (parent_node->name.integer) {
984 return_VALUE ((acpi_name) parent_node->name.integer);
988 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "unable to find parent of %p (%4.4s)\n",
989 child_node, acpi_ut_get_node_name (child_node)));
992 return_VALUE (ACPI_UNKNOWN_NAME);
996 /*******************************************************************************
998 * FUNCTION: acpi_ns_get_parent_node
1000 * PARAMETERS: Node - Current table entry
1002 * RETURN: Parent entry of the given entry
1004 * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
1006 ******************************************************************************/
1009 struct acpi_namespace_node *
1010 acpi_ns_get_parent_node (
1011 struct acpi_namespace_node *node)
1013 ACPI_FUNCTION_ENTRY ();
1016 if (!node) {
1017 return (NULL);
1021 * Walk to the end of this peer list.
1022 * The last entry is marked with a flag and the peer
1023 * pointer is really a pointer back to the parent.
1024 * This saves putting a parent back pointer in each and
1025 * every named object!
1027 while (!(node->flags & ANOBJ_END_OF_PEER_LIST)) {
1028 node = node->peer;
1032 return (node->peer);
1036 /*******************************************************************************
1038 * FUNCTION: acpi_ns_get_next_valid_node
1040 * PARAMETERS: Node - Current table entry
1042 * RETURN: Next valid Node in the linked node list. NULL if no more valid
1043 * nodess
1045 * DESCRIPTION: Find the next valid node within a name table.
1046 * Useful for implementing NULL-end-of-list loops.
1048 ******************************************************************************/
1051 struct acpi_namespace_node *
1052 acpi_ns_get_next_valid_node (
1053 struct acpi_namespace_node *node)
1056 /* If we are at the end of this peer list, return NULL */
1058 if (node->flags & ANOBJ_END_OF_PEER_LIST) {
1059 return NULL;
1062 /* Otherwise just return the next peer */
1064 return (node->peer);