nsutils.c revision 99679
1/******************************************************************************
2 *
3 * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
4 *                        parents and siblings and Scope manipulation
5 *              $Revision: 110 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights.  You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code.  No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision.  In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change.  Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee.  Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution.  In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government.  In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#define __NSUTILS_C__
119
120#include "acpi.h"
121#include "acnamesp.h"
122#include "amlcode.h"
123#include "actables.h"
124
125#define _COMPONENT          ACPI_NAMESPACE
126        ACPI_MODULE_NAME    ("nsutils")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION:    AcpiNsValidRootPrefix
132 *
133 * PARAMETERS:  Prefix          - Character to be checked
134 *
135 * RETURN:      TRUE if a valid prefix
136 *
137 * DESCRIPTION: Check if a character is a valid ACPI Root prefix
138 *
139 ******************************************************************************/
140
141BOOLEAN
142AcpiNsValidRootPrefix (
143    NATIVE_CHAR             Prefix)
144{
145
146    return ((BOOLEAN) (Prefix == '\\'));
147}
148
149
150/*******************************************************************************
151 *
152 * FUNCTION:    AcpiNsValidPathSeparator
153 *
154 * PARAMETERS:  Sep              - Character to be checked
155 *
156 * RETURN:      TRUE if a valid path separator
157 *
158 * DESCRIPTION: Check if a character is a valid ACPI path separator
159 *
160 ******************************************************************************/
161
162BOOLEAN
163AcpiNsValidPathSeparator (
164    NATIVE_CHAR             Sep)
165{
166
167    return ((BOOLEAN) (Sep == '.'));
168}
169
170
171/*******************************************************************************
172 *
173 * FUNCTION:    AcpiNsGetType
174 *
175 * PARAMETERS:  Handle              - Parent Node to be examined
176 *
177 * RETURN:      Type field from Node whose handle is passed
178 *
179 ******************************************************************************/
180
181ACPI_OBJECT_TYPE
182AcpiNsGetType (
183    ACPI_NAMESPACE_NODE     *Node)
184{
185    ACPI_FUNCTION_TRACE ("NsGetType");
186
187
188    if (!Node)
189    {
190        ACPI_REPORT_WARNING (("NsGetType: Null Node ptr"));
191        return_VALUE (ACPI_TYPE_ANY);
192    }
193
194    return_VALUE ((ACPI_OBJECT_TYPE) Node->Type);
195}
196
197
198/*******************************************************************************
199 *
200 * FUNCTION:    AcpiNsLocal
201 *
202 * PARAMETERS:  Type            - A namespace object type
203 *
204 * RETURN:      LOCAL if names must be found locally in objects of the
205 *              passed type, 0 if enclosing scopes should be searched
206 *
207 ******************************************************************************/
208
209UINT32
210AcpiNsLocal (
211    ACPI_OBJECT_TYPE        Type)
212{
213    ACPI_FUNCTION_TRACE ("NsLocal");
214
215
216    if (!AcpiUtValidObjectType (Type))
217    {
218        /* Type code out of range  */
219
220        ACPI_REPORT_WARNING (("NsLocal: Invalid Object Type\n"));
221        return_VALUE (ACPI_NS_NORMAL);
222    }
223
224    return_VALUE ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
225}
226
227
228/*******************************************************************************
229 *
230 * FUNCTION:    AcpiNsGetInternalNameLength
231 *
232 * PARAMETERS:  Info            - Info struct initialized with the
233 *                                external name pointer.
234 *
235 * RETURN:      Status
236 *
237 * DESCRIPTION: Calculate the length of the internal (AML) namestring
238 *              corresponding to the external (ASL) namestring.
239 *
240 ******************************************************************************/
241
242void
243AcpiNsGetInternalNameLength (
244    ACPI_NAMESTRING_INFO    *Info)
245{
246    NATIVE_CHAR             *NextExternalChar;
247    UINT32                  i;
248
249
250    ACPI_FUNCTION_ENTRY ();
251
252
253    NextExternalChar = Info->ExternalName;
254    Info->NumCarats = 0;
255    Info->NumSegments = 0;
256    Info->FullyQualified = FALSE;
257
258    /*
259     * For the internal name, the required length is 4 bytes
260     * per segment, plus 1 each for RootPrefix, MultiNamePrefixOp,
261     * segment count, trailing null (which is not really needed,
262     * but no there's harm in putting it there)
263     *
264     * strlen() + 1 covers the first NameSeg, which has no
265     * path separator
266     */
267    if (AcpiNsValidRootPrefix (NextExternalChar[0]))
268    {
269        Info->FullyQualified = TRUE;
270        NextExternalChar++;
271    }
272    else
273    {
274        /*
275         * Handle Carat prefixes
276         */
277        while (*NextExternalChar == '^')
278        {
279            Info->NumCarats++;
280            NextExternalChar++;
281        }
282    }
283
284    /*
285     * Determine the number of ACPI name "segments" by counting
286     * the number of path separators within the string.  Start
287     * with one segment since the segment count is (# separators)
288     * + 1, and zero separators is ok.
289     */
290    if (*NextExternalChar)
291    {
292        Info->NumSegments = 1;
293        for (i = 0; NextExternalChar[i]; i++)
294        {
295            if (AcpiNsValidPathSeparator (NextExternalChar[i]))
296            {
297                Info->NumSegments++;
298            }
299        }
300    }
301
302    Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
303                    4 + Info->NumCarats;
304
305    Info->NextExternalChar = NextExternalChar;
306}
307
308
309/*******************************************************************************
310 *
311 * FUNCTION:    AcpiNsBuildInternalName
312 *
313 * PARAMETERS:  Info            - Info struct fully initialized
314 *
315 * RETURN:      Status
316 *
317 * DESCRIPTION: Construct the internal (AML) namestring
318 *              corresponding to the external (ASL) namestring.
319 *
320 ******************************************************************************/
321
322ACPI_STATUS
323AcpiNsBuildInternalName (
324    ACPI_NAMESTRING_INFO    *Info)
325{
326    UINT32                  NumSegments = Info->NumSegments;
327    NATIVE_CHAR             *InternalName = Info->InternalName;
328    NATIVE_CHAR             *ExternalName = Info->NextExternalChar;
329    NATIVE_CHAR             *Result = NULL;
330    NATIVE_UINT             i;
331
332
333    ACPI_FUNCTION_TRACE ("NsBuildInternalName");
334
335
336    /* Setup the correct prefixes, counts, and pointers */
337
338    if (Info->FullyQualified)
339    {
340        InternalName[0] = '\\';
341
342        if (NumSegments <= 1)
343        {
344            Result = &InternalName[1];
345        }
346        else if (NumSegments == 2)
347        {
348            InternalName[1] = AML_DUAL_NAME_PREFIX;
349            Result = &InternalName[2];
350        }
351        else
352        {
353            InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
354            InternalName[2] = (char) NumSegments;
355            Result = &InternalName[3];
356        }
357    }
358    else
359    {
360        /*
361         * Not fully qualified.
362         * Handle Carats first, then append the name segments
363         */
364        i = 0;
365        if (Info->NumCarats)
366        {
367            for (i = 0; i < Info->NumCarats; i++)
368            {
369                InternalName[i] = '^';
370            }
371        }
372
373        if (NumSegments <= 1)
374        {
375            Result = &InternalName[i];
376        }
377        else if (NumSegments == 2)
378        {
379            InternalName[i] = AML_DUAL_NAME_PREFIX;
380            Result = &InternalName[i+1];
381        }
382        else
383        {
384            InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
385            InternalName[i+1] = (char) NumSegments;
386            Result = &InternalName[i+2];
387        }
388    }
389
390    /* Build the name (minus path separators) */
391
392    for (; NumSegments; NumSegments--)
393    {
394        for (i = 0; i < ACPI_NAME_SIZE; i++)
395        {
396            if (AcpiNsValidPathSeparator (*ExternalName) ||
397               (*ExternalName == 0))
398            {
399                /* Pad the segment with underscore(s) if segment is short */
400
401                Result[i] = '_';
402            }
403            else
404            {
405                /* Convert the character to uppercase and save it */
406
407                Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
408                ExternalName++;
409            }
410        }
411
412        /* Now we must have a path separator, or the pathname is bad */
413
414        if (!AcpiNsValidPathSeparator (*ExternalName) &&
415            (*ExternalName != 0))
416        {
417            return_ACPI_STATUS (AE_BAD_PARAMETER);
418        }
419
420        /* Move on the next segment */
421
422        ExternalName++;
423        Result += ACPI_NAME_SIZE;
424    }
425
426    /* Terminate the string */
427
428    *Result = 0;
429
430    if (Info->FullyQualified)
431    {
432        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (abs) \"\\%s\"\n",
433            InternalName, InternalName));
434    }
435    else
436    {
437        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (rel) \"%s\"\n",
438            InternalName, InternalName));
439    }
440
441    return_ACPI_STATUS (AE_OK);
442}
443
444
445/*******************************************************************************
446 *
447 * FUNCTION:    AcpiNsInternalizeName
448 *
449 * PARAMETERS:  *ExternalName           - External representation of name
450 *              **Converted Name        - Where to return the resulting
451 *                                        internal represention of the name
452 *
453 * RETURN:      Status
454 *
455 * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
456 *              to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
457 *
458 *******************************************************************************/
459
460ACPI_STATUS
461AcpiNsInternalizeName (
462    NATIVE_CHAR             *ExternalName,
463    NATIVE_CHAR             **ConvertedName)
464{
465    NATIVE_CHAR             *InternalName;
466    ACPI_NAMESTRING_INFO    Info;
467    ACPI_STATUS             Status;
468
469
470    ACPI_FUNCTION_TRACE ("NsInternalizeName");
471
472
473    if ((!ExternalName)      ||
474        (*ExternalName == 0) ||
475        (!ConvertedName))
476    {
477        return_ACPI_STATUS (AE_BAD_PARAMETER);
478    }
479
480    /* Get the length of the new internal name */
481
482    Info.ExternalName = ExternalName;
483    AcpiNsGetInternalNameLength (&Info);
484
485    /* We need a segment to store the internal  name */
486
487    InternalName = ACPI_MEM_CALLOCATE (Info.Length);
488    if (!InternalName)
489    {
490        return_ACPI_STATUS (AE_NO_MEMORY);
491    }
492
493    /* Build the name */
494
495    Info.InternalName = InternalName;
496    Status = AcpiNsBuildInternalName (&Info);
497    if (ACPI_FAILURE (Status))
498    {
499        ACPI_MEM_FREE (InternalName);
500        return_ACPI_STATUS (Status);
501    }
502
503    *ConvertedName = InternalName;
504    return_ACPI_STATUS (AE_OK);
505}
506
507
508/*******************************************************************************
509 *
510 * FUNCTION:    AcpiNsExternalizeName
511 *
512 * PARAMETERS:  *InternalName          - Internal representation of name
513 *              **ConvertedName        - Where to return the resulting
514 *                                       external representation of name
515 *
516 * RETURN:      Status
517 *
518 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
519 *              to its external form (e.g. "\_PR_.CPU0")
520 *
521 ******************************************************************************/
522
523ACPI_STATUS
524AcpiNsExternalizeName (
525    UINT32                  InternalNameLength,
526    char                    *InternalName,
527    UINT32                  *ConvertedNameLength,
528    char                    **ConvertedName)
529{
530    NATIVE_UINT_MIN32       PrefixLength = 0;
531    NATIVE_UINT_MIN32       NamesIndex = 0;
532    NATIVE_UINT_MIN32       NumSegments = 0;
533    NATIVE_UINT_MIN32       i = 0;
534    NATIVE_UINT_MIN32       j = 0;
535    NATIVE_UINT_MIN32       RequiredLength;
536
537
538    ACPI_FUNCTION_TRACE ("NsExternalizeName");
539
540
541    if (!InternalNameLength     ||
542        !InternalName           ||
543        !ConvertedName)
544    {
545        return_ACPI_STATUS (AE_BAD_PARAMETER);
546    }
547
548    /*
549     * Check for a prefix (one '\' | one or more '^').
550     */
551    switch (InternalName[0])
552    {
553    case '\\':
554        PrefixLength = 1;
555        break;
556
557    case '^':
558        for (i = 0; i < InternalNameLength; i++)
559        {
560            if (InternalName[i] != '^')
561            {
562                PrefixLength = i + 1;
563            }
564        }
565
566        if (i == InternalNameLength)
567        {
568            PrefixLength = i;
569        }
570
571        break;
572
573    default:
574        break;
575    }
576
577    /*
578     * Check for object names.  Note that there could be 0-255 of these
579     * 4-byte elements.
580     */
581    if (PrefixLength < InternalNameLength)
582    {
583        switch (InternalName[PrefixLength])
584        {
585        case AML_MULTI_NAME_PREFIX_OP:
586
587            /* <count> 4-byte names */
588
589            NamesIndex = PrefixLength + 2;
590            NumSegments = (UINT32) (UINT8) InternalName[PrefixLength + 1];
591            break;
592
593        case AML_DUAL_NAME_PREFIX:
594
595            /* Two 4-byte names */
596
597            NamesIndex = PrefixLength + 1;
598            NumSegments = 2;
599            break;
600
601        case 0:
602
603            /* NullName */
604
605            NamesIndex = 0;
606            NumSegments = 0;
607            break;
608
609        default:
610
611            /* one 4-byte name */
612
613            NamesIndex = PrefixLength;
614            NumSegments = 1;
615            break;
616        }
617    }
618
619    /*
620     * Calculate the length of ConvertedName, which equals the length
621     * of the prefix, length of all object names, length of any required
622     * punctuation ('.') between object names, plus the NULL terminator.
623     */
624    RequiredLength = PrefixLength + (4 * NumSegments) +
625                        ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
626
627    /*
628     * Check to see if we're still in bounds.  If not, there's a problem
629     * with InternalName (invalid format).
630     */
631    if (RequiredLength > InternalNameLength)
632    {
633        ACPI_REPORT_ERROR (("NsExternalizeName: Invalid internal name\n"));
634        return_ACPI_STATUS (AE_BAD_PATHNAME);
635    }
636
637    /*
638     * Build ConvertedName...
639     */
640    *ConvertedName = ACPI_MEM_CALLOCATE (RequiredLength);
641    if (!(*ConvertedName))
642    {
643        return_ACPI_STATUS (AE_NO_MEMORY);
644    }
645
646    j = 0;
647
648    for (i = 0; i < PrefixLength; i++)
649    {
650        (*ConvertedName)[j++] = InternalName[i];
651    }
652
653    if (NumSegments > 0)
654    {
655        for (i = 0; i < NumSegments; i++)
656        {
657            if (i > 0)
658            {
659                (*ConvertedName)[j++] = '.';
660            }
661
662            (*ConvertedName)[j++] = InternalName[NamesIndex++];
663            (*ConvertedName)[j++] = InternalName[NamesIndex++];
664            (*ConvertedName)[j++] = InternalName[NamesIndex++];
665            (*ConvertedName)[j++] = InternalName[NamesIndex++];
666        }
667    }
668
669    if (ConvertedNameLength)
670    {
671        *ConvertedNameLength = (UINT32) RequiredLength;
672    }
673
674    return_ACPI_STATUS (AE_OK);
675}
676
677
678/*******************************************************************************
679 *
680 * FUNCTION:    AcpiNsMapHandleToNode
681 *
682 * PARAMETERS:  Handle          - Handle to be converted to an Node
683 *
684 * RETURN:      A Name table entry pointer
685 *
686 * DESCRIPTION: Convert a namespace handle to a real Node
687 *
688 * Note: Real integer handles allow for more verification
689 *       and keep all pointers within this subsystem.
690 *
691 ******************************************************************************/
692
693ACPI_NAMESPACE_NODE *
694AcpiNsMapHandleToNode (
695    ACPI_HANDLE             Handle)
696{
697
698    ACPI_FUNCTION_ENTRY ();
699
700
701    /*
702     * Simple implementation.
703     */
704    if (!Handle)
705    {
706        return (NULL);
707    }
708
709    if (Handle == ACPI_ROOT_OBJECT)
710    {
711        return (AcpiGbl_RootNode);
712    }
713
714    /* We can at least attempt to verify the handle */
715
716    if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
717    {
718        return (NULL);
719    }
720
721    return ((ACPI_NAMESPACE_NODE *) Handle);
722}
723
724
725/*******************************************************************************
726 *
727 * FUNCTION:    AcpiNsConvertEntryToHandle
728 *
729 * PARAMETERS:  Node          - Node to be converted to a Handle
730 *
731 * RETURN:      An USER ACPI_HANDLE
732 *
733 * DESCRIPTION: Convert a real Node to a namespace handle
734 *
735 ******************************************************************************/
736
737ACPI_HANDLE
738AcpiNsConvertEntryToHandle (
739    ACPI_NAMESPACE_NODE         *Node)
740{
741
742
743    /*
744     * Simple implementation for now;
745     */
746    return ((ACPI_HANDLE) Node);
747
748
749/* ---------------------------------------------------
750
751    if (!Node)
752    {
753        return (NULL);
754    }
755
756    if (Node == AcpiGbl_RootNode)
757    {
758        return (ACPI_ROOT_OBJECT);
759    }
760
761
762    return ((ACPI_HANDLE) Node);
763------------------------------------------------------*/
764}
765
766
767/*******************************************************************************
768 *
769 * FUNCTION:    AcpiNsTerminate
770 *
771 * PARAMETERS:  none
772 *
773 * RETURN:      none
774 *
775 * DESCRIPTION: free memory allocated for table storage.
776 *
777 ******************************************************************************/
778
779void
780AcpiNsTerminate (void)
781{
782    ACPI_OPERAND_OBJECT     *ObjDesc;
783    ACPI_NAMESPACE_NODE     *ThisNode;
784
785
786    ACPI_FUNCTION_TRACE ("NsTerminate");
787
788
789    ThisNode = AcpiGbl_RootNode;
790
791    /*
792     * 1) Free the entire namespace -- all objects, tables, and stacks
793     *
794     * Delete all objects linked to the root
795     * (additional table descriptors)
796     */
797    AcpiNsDeleteNamespaceSubtree (ThisNode);
798
799    /* Detach any object(s) attached to the root */
800
801    ObjDesc = AcpiNsGetAttachedObject (ThisNode);
802    if (ObjDesc)
803    {
804        AcpiNsDetachObject (ThisNode);
805        AcpiUtRemoveReference (ObjDesc);
806    }
807
808    AcpiNsDeleteChildren (ThisNode);
809    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
810
811
812    /*
813     * 2) Now we can delete the ACPI tables
814     */
815    AcpiTbDeleteAcpiTables ();
816    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
817
818    return_VOID;
819}
820
821
822/*******************************************************************************
823 *
824 * FUNCTION:    AcpiNsOpensScope
825 *
826 * PARAMETERS:  Type        - A valid namespace type
827 *
828 * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
829 *              to the ACPI specification, else 0
830 *
831 ******************************************************************************/
832
833UINT32
834AcpiNsOpensScope (
835    ACPI_OBJECT_TYPE        Type)
836{
837    ACPI_FUNCTION_TRACE_U32 ("NsOpensScope", Type);
838
839
840    if (!AcpiUtValidObjectType (Type))
841    {
842        /* type code out of range  */
843
844        ACPI_REPORT_WARNING (("NsOpensScope: Invalid Object Type %X\n", Type));
845        return_VALUE (ACPI_NS_NORMAL);
846    }
847
848    return_VALUE (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
849}
850
851
852/*******************************************************************************
853 *
854 * FUNCTION:    AcpiNsGetNodeByPath
855 *
856 * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
857 *                            \ (backslash) and ^ (carat) prefixes, and the
858 *                            . (period) to separate segments are supported.
859 *              StartNode   - Root of subtree to be searched, or NS_ALL for the
860 *                            root of the name space.  If Name is fully
861 *                            qualified (first INT8 is '\'), the passed value
862 *                            of Scope will not be accessed.
863 *              Flags       - Used to indicate whether to perform upsearch or
864 *                            not.
865 *              ReturnNode  - Where the Node is returned
866 *
867 * DESCRIPTION: Look up a name relative to a given scope and return the
868 *              corresponding Node.  NOTE: Scope can be null.
869 *
870 * MUTEX:       Locks namespace
871 *
872 ******************************************************************************/
873
874ACPI_STATUS
875AcpiNsGetNodeByPath (
876    NATIVE_CHAR             *Pathname,
877    ACPI_NAMESPACE_NODE     *StartNode,
878    UINT32                  Flags,
879    ACPI_NAMESPACE_NODE     **ReturnNode)
880{
881    ACPI_GENERIC_STATE      ScopeInfo;
882    ACPI_STATUS             Status;
883    NATIVE_CHAR             *InternalPath = NULL;
884
885
886    ACPI_FUNCTION_TRACE_PTR ("NsGetNodeByPath", Pathname);
887
888
889    if (!Pathname)
890    {
891        return_ACPI_STATUS (AE_BAD_PARAMETER);
892    }
893
894    /* Convert path to internal representation */
895
896    Status = AcpiNsInternalizeName (Pathname, &InternalPath);
897    if (ACPI_FAILURE (Status))
898    {
899        return_ACPI_STATUS (Status);
900    }
901
902    /* Must lock namespace during lookup */
903
904    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
905    if (ACPI_FAILURE (Status))
906    {
907        return_ACPI_STATUS (Status);
908    }
909
910    /* Setup lookup scope (search starting point) */
911
912    ScopeInfo.Scope.Node = StartNode;
913
914    /* Lookup the name in the namespace */
915
916    Status = AcpiNsLookup (&ScopeInfo, InternalPath,
917                            ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
918                            (Flags | ACPI_NS_DONT_OPEN_SCOPE),
919                            NULL, ReturnNode);
920    if (ACPI_FAILURE (Status))
921    {
922        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
923                InternalPath, AcpiFormatException (Status)));
924    }
925
926    /* Cleanup */
927
928    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
929    ACPI_MEM_FREE (InternalPath);
930    return_ACPI_STATUS (Status);
931}
932
933
934/*******************************************************************************
935 *
936 * FUNCTION:    AcpiNsFindParentName
937 *
938 * PARAMETERS:  *ChildNode             - Named Obj whose name is to be found
939 *
940 * RETURN:      The ACPI name
941 *
942 * DESCRIPTION: Search for the given obj in its parent scope and return the
943 *              name segment, or "????" if the parent name can't be found
944 *              (which "should not happen").
945 *
946 ******************************************************************************/
947
948ACPI_NAME
949AcpiNsFindParentName (
950    ACPI_NAMESPACE_NODE     *ChildNode)
951{
952    ACPI_NAMESPACE_NODE     *ParentNode;
953
954
955    ACPI_FUNCTION_TRACE ("NsFindParentName");
956
957
958    if (ChildNode)
959    {
960        /* Valid entry.  Get the parent Node */
961
962        ParentNode = AcpiNsGetParentNode (ChildNode);
963        if (ParentNode)
964        {
965            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Parent of %p [%4.4s] is %p [%4.4s]\n",
966                ChildNode,  ChildNode->Name.Ascii,
967                ParentNode, ParentNode->Name.Ascii));
968
969            if (ParentNode->Name.Integer)
970            {
971                return_VALUE ((ACPI_NAME) ParentNode->Name.Integer);
972            }
973        }
974
975        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "unable to find parent of %p (%4.4s)\n",
976            ChildNode, ChildNode->Name.Ascii));
977    }
978
979    return_VALUE (ACPI_UNKNOWN_NAME);
980}
981
982
983#if defined(ACPI_DEBUG) || defined(ENABLE_DEBUGGER)
984
985/*******************************************************************************
986 *
987 * FUNCTION:    AcpiNsExistDownstreamSibling
988 *
989 * PARAMETERS:  *Node          - pointer to first Node to examine
990 *
991 * RETURN:      TRUE if sibling is found, FALSE otherwise
992 *
993 * DESCRIPTION: Searches remainder of scope being processed to determine
994 *              whether there is a downstream sibling to the current
995 *              object.  This function is used to determine what type of
996 *              line drawing character to use when displaying namespace
997 *              trees.
998 *
999 ******************************************************************************/
1000
1001BOOLEAN
1002AcpiNsExistDownstreamSibling (
1003    ACPI_NAMESPACE_NODE     *Node)
1004{
1005
1006    if (!Node)
1007    {
1008        return (FALSE);
1009    }
1010
1011    if (Node->Name.Integer)
1012    {
1013        return (TRUE);
1014    }
1015
1016    return (FALSE);
1017}
1018
1019#endif /* ACPI_DEBUG */
1020
1021
1022/*******************************************************************************
1023 *
1024 * FUNCTION:    AcpiNsGetParentNode
1025 *
1026 * PARAMETERS:  Node       - Current table entry
1027 *
1028 * RETURN:      Parent entry of the given entry
1029 *
1030 * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
1031 *
1032 ******************************************************************************/
1033
1034
1035ACPI_NAMESPACE_NODE *
1036AcpiNsGetParentNode (
1037    ACPI_NAMESPACE_NODE     *Node)
1038{
1039    ACPI_FUNCTION_ENTRY ();
1040
1041
1042    if (!Node)
1043    {
1044        return (NULL);
1045    }
1046
1047    /*
1048     * Walk to the end of this peer list.
1049     * The last entry is marked with a flag and the peer
1050     * pointer is really a pointer back to the parent.
1051     * This saves putting a parent back pointer in each and
1052     * every named object!
1053     */
1054    while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
1055    {
1056        Node = Node->Peer;
1057    }
1058
1059
1060    return (Node->Peer);
1061}
1062
1063
1064/*******************************************************************************
1065 *
1066 * FUNCTION:    AcpiNsGetNextValidNode
1067 *
1068 * PARAMETERS:  Node       - Current table entry
1069 *
1070 * RETURN:      Next valid Node in the linked node list.  NULL if no more valid
1071 *              nodess
1072 *
1073 * DESCRIPTION: Find the next valid node within a name table.
1074 *              Useful for implementing NULL-end-of-list loops.
1075 *
1076 ******************************************************************************/
1077
1078
1079ACPI_NAMESPACE_NODE *
1080AcpiNsGetNextValidNode (
1081    ACPI_NAMESPACE_NODE     *Node)
1082{
1083
1084    /* If we are at the end of this peer list, return NULL */
1085
1086    if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
1087    {
1088        return NULL;
1089    }
1090
1091    /* Otherwise just return the next peer */
1092
1093    return (Node->Peer);
1094}
1095
1096
1097