xref: /titanic_52/usr/src/uts/intel/io/acpica/namespace/nsutils.c (revision 71269a2275bf5a143dad6461eee2710a344e7261)
1 /******************************************************************************
2  *
3  * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
4  *                        parents and siblings and Scope manipulation
5  *              $Revision: 1.157 $
6  *
7  *****************************************************************************/
8 
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2008, 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 
124 #define _COMPONENT          ACPI_NAMESPACE
125         ACPI_MODULE_NAME    ("nsutils")
126 
127 /* Local prototypes */
128 
129 static BOOLEAN
130 AcpiNsValidPathSeparator (
131     char                    Sep);
132 
133 #ifdef ACPI_OBSOLETE_FUNCTIONS
134 ACPI_NAME
135 AcpiNsFindParentName (
136     ACPI_NAMESPACE_NODE     *NodeToSearch);
137 #endif
138 
139 
140 /*******************************************************************************
141  *
142  * FUNCTION:    AcpiNsReportError
143  *
144  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
145  *              LineNumber          - Caller's line number (for error output)
146  *              InternalName        - Name or path of the namespace node
147  *              LookupStatus        - Exception code from NS lookup
148  *
149  * RETURN:      None
150  *
151  * DESCRIPTION: Print warning message with full pathname
152  *
153  ******************************************************************************/
154 
155 void
156 AcpiNsReportError (
157     const char              *ModuleName,
158     UINT32                  LineNumber,
159     const char              *InternalName,
160     ACPI_STATUS             LookupStatus)
161 {
162     ACPI_STATUS             Status;
163     UINT32                  BadName;
164     char                    *Name = NULL;
165 
166 
167     AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
168 
169     if (LookupStatus == AE_BAD_CHARACTER)
170     {
171         /* There is a non-ascii character in the name */
172 
173         ACPI_MOVE_32_TO_32 (&BadName, InternalName);
174         AcpiOsPrintf ("[0x%4.4X] (NON-ASCII)", BadName);
175     }
176     else
177     {
178         /* Convert path to external format */
179 
180         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
181                     InternalName, NULL, &Name);
182 
183         /* Print target name */
184 
185         if (ACPI_SUCCESS (Status))
186         {
187             AcpiOsPrintf ("[%s]", Name);
188         }
189         else
190         {
191             AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
192         }
193 
194         if (Name)
195         {
196             ACPI_FREE (Name);
197         }
198     }
199 
200     AcpiOsPrintf (" Namespace lookup failure, %s\n",
201         AcpiFormatException (LookupStatus));
202 }
203 
204 
205 /*******************************************************************************
206  *
207  * FUNCTION:    AcpiNsReportMethodError
208  *
209  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
210  *              LineNumber          - Caller's line number (for error output)
211  *              Message             - Error message to use on failure
212  *              PrefixNode          - Prefix relative to the path
213  *              Path                - Path to the node (optional)
214  *              MethodStatus        - Execution status
215  *
216  * RETURN:      None
217  *
218  * DESCRIPTION: Print warning message with full pathname
219  *
220  ******************************************************************************/
221 
222 void
223 AcpiNsReportMethodError (
224     const char              *ModuleName,
225     UINT32                  LineNumber,
226     const char              *Message,
227     ACPI_NAMESPACE_NODE     *PrefixNode,
228     const char              *Path,
229     ACPI_STATUS             MethodStatus)
230 {
231     ACPI_STATUS             Status;
232     ACPI_NAMESPACE_NODE     *Node = PrefixNode;
233 
234 
235     AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
236 
237     if (Path)
238     {
239         Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
240                     &Node);
241         if (ACPI_FAILURE (Status))
242         {
243             AcpiOsPrintf ("[Could not get node by pathname]");
244         }
245     }
246 
247     AcpiNsPrintNodePathname (Node, Message);
248     AcpiOsPrintf (", %s\n", AcpiFormatException (MethodStatus));
249 }
250 
251 
252 /*******************************************************************************
253  *
254  * FUNCTION:    AcpiNsPrintNodePathname
255  *
256  * PARAMETERS:  Node            - Object
257  *              Message         - Prefix message
258  *
259  * DESCRIPTION: Print an object's full namespace pathname
260  *              Manages allocation/freeing of a pathname buffer
261  *
262  ******************************************************************************/
263 
264 void
265 AcpiNsPrintNodePathname (
266     ACPI_NAMESPACE_NODE     *Node,
267     const char              *Message)
268 {
269     ACPI_BUFFER             Buffer;
270     ACPI_STATUS             Status;
271 
272 
273     if (!Node)
274     {
275         AcpiOsPrintf ("[NULL NAME]");
276         return;
277     }
278 
279     /* Convert handle to full pathname and print it (with supplied message) */
280 
281     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
282 
283     Status = AcpiNsHandleToPathname (Node, &Buffer);
284     if (ACPI_SUCCESS (Status))
285     {
286         if (Message)
287         {
288             AcpiOsPrintf ("%s ", Message);
289         }
290 
291         AcpiOsPrintf ("[%s] (Node %p)", (char *) Buffer.Pointer, Node);
292         ACPI_FREE (Buffer.Pointer);
293     }
294 }
295 
296 
297 /*******************************************************************************
298  *
299  * FUNCTION:    AcpiNsValidRootPrefix
300  *
301  * PARAMETERS:  Prefix          - Character to be checked
302  *
303  * RETURN:      TRUE if a valid prefix
304  *
305  * DESCRIPTION: Check if a character is a valid ACPI Root prefix
306  *
307  ******************************************************************************/
308 
309 BOOLEAN
310 AcpiNsValidRootPrefix (
311     char                    Prefix)
312 {
313 
314     return ((BOOLEAN) (Prefix == '\\'));
315 }
316 
317 
318 /*******************************************************************************
319  *
320  * FUNCTION:    AcpiNsValidPathSeparator
321  *
322  * PARAMETERS:  Sep         - Character to be checked
323  *
324  * RETURN:      TRUE if a valid path separator
325  *
326  * DESCRIPTION: Check if a character is a valid ACPI path separator
327  *
328  ******************************************************************************/
329 
330 static BOOLEAN
331 AcpiNsValidPathSeparator (
332     char                    Sep)
333 {
334 
335     return ((BOOLEAN) (Sep == '.'));
336 }
337 
338 
339 /*******************************************************************************
340  *
341  * FUNCTION:    AcpiNsGetType
342  *
343  * PARAMETERS:  Node        - Parent Node to be examined
344  *
345  * RETURN:      Type field from Node whose handle is passed
346  *
347  * DESCRIPTION: Return the type of a Namespace node
348  *
349  ******************************************************************************/
350 
351 ACPI_OBJECT_TYPE
352 AcpiNsGetType (
353     ACPI_NAMESPACE_NODE     *Node)
354 {
355     ACPI_FUNCTION_TRACE (NsGetType);
356 
357 
358     if (!Node)
359     {
360         ACPI_WARNING ((AE_INFO, "Null Node parameter"));
361         return_UINT32 (ACPI_TYPE_ANY);
362     }
363 
364     return_UINT32 ((ACPI_OBJECT_TYPE) Node->Type);
365 }
366 
367 
368 /*******************************************************************************
369  *
370  * FUNCTION:    AcpiNsLocal
371  *
372  * PARAMETERS:  Type        - A namespace object type
373  *
374  * RETURN:      LOCAL if names must be found locally in objects of the
375  *              passed type, 0 if enclosing scopes should be searched
376  *
377  * DESCRIPTION: Returns scope rule for the given object type.
378  *
379  ******************************************************************************/
380 
381 UINT32
382 AcpiNsLocal (
383     ACPI_OBJECT_TYPE        Type)
384 {
385     ACPI_FUNCTION_TRACE (NsLocal);
386 
387 
388     if (!AcpiUtValidObjectType (Type))
389     {
390         /* Type code out of range  */
391 
392         ACPI_WARNING ((AE_INFO, "Invalid Object Type %X", Type));
393         return_UINT32 (ACPI_NS_NORMAL);
394     }
395 
396     return_UINT32 ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
397 }
398 
399 
400 /*******************************************************************************
401  *
402  * FUNCTION:    AcpiNsGetInternalNameLength
403  *
404  * PARAMETERS:  Info            - Info struct initialized with the
405  *                                external name pointer.
406  *
407  * RETURN:      None
408  *
409  * DESCRIPTION: Calculate the length of the internal (AML) namestring
410  *              corresponding to the external (ASL) namestring.
411  *
412  ******************************************************************************/
413 
414 void
415 AcpiNsGetInternalNameLength (
416     ACPI_NAMESTRING_INFO    *Info)
417 {
418     const char              *NextExternalChar;
419     UINT32                  i;
420 
421 
422     ACPI_FUNCTION_ENTRY ();
423 
424 
425     NextExternalChar = Info->ExternalName;
426     Info->NumCarats = 0;
427     Info->NumSegments = 0;
428     Info->FullyQualified = FALSE;
429 
430     /*
431      * For the internal name, the required length is 4 bytes per segment, plus
432      * 1 each for RootPrefix, MultiNamePrefixOp, segment count, trailing null
433      * (which is not really needed, but no there's harm in putting it there)
434      *
435      * strlen() + 1 covers the first NameSeg, which has no path separator
436      */
437     if (AcpiNsValidRootPrefix (NextExternalChar[0]))
438     {
439         Info->FullyQualified = TRUE;
440         NextExternalChar++;
441     }
442     else
443     {
444         /*
445          * Handle Carat prefixes
446          */
447         while (*NextExternalChar == '^')
448         {
449             Info->NumCarats++;
450             NextExternalChar++;
451         }
452     }
453 
454     /*
455      * Determine the number of ACPI name "segments" by counting the number of
456      * path separators within the string. Start with one segment since the
457      * segment count is [(# separators) + 1], and zero separators is ok.
458      */
459     if (*NextExternalChar)
460     {
461         Info->NumSegments = 1;
462         for (i = 0; NextExternalChar[i]; i++)
463         {
464             if (AcpiNsValidPathSeparator (NextExternalChar[i]))
465             {
466                 Info->NumSegments++;
467             }
468         }
469     }
470 
471     Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
472                     4 + Info->NumCarats;
473 
474     Info->NextExternalChar = NextExternalChar;
475 }
476 
477 
478 /*******************************************************************************
479  *
480  * FUNCTION:    AcpiNsBuildInternalName
481  *
482  * PARAMETERS:  Info            - Info struct fully initialized
483  *
484  * RETURN:      Status
485  *
486  * DESCRIPTION: Construct the internal (AML) namestring
487  *              corresponding to the external (ASL) namestring.
488  *
489  ******************************************************************************/
490 
491 ACPI_STATUS
492 AcpiNsBuildInternalName (
493     ACPI_NAMESTRING_INFO    *Info)
494 {
495     UINT32                  NumSegments = Info->NumSegments;
496     char                    *InternalName = Info->InternalName;
497     const char              *ExternalName = Info->NextExternalChar;
498     char                    *Result = NULL;
499     UINT32                  i;
500 
501 
502     ACPI_FUNCTION_TRACE (NsBuildInternalName);
503 
504 
505     /* Setup the correct prefixes, counts, and pointers */
506 
507     if (Info->FullyQualified)
508     {
509         InternalName[0] = '\\';
510 
511         if (NumSegments <= 1)
512         {
513             Result = &InternalName[1];
514         }
515         else if (NumSegments == 2)
516         {
517             InternalName[1] = AML_DUAL_NAME_PREFIX;
518             Result = &InternalName[2];
519         }
520         else
521         {
522             InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
523             InternalName[2] = (char) NumSegments;
524             Result = &InternalName[3];
525         }
526     }
527     else
528     {
529         /*
530          * Not fully qualified.
531          * Handle Carats first, then append the name segments
532          */
533         i = 0;
534         if (Info->NumCarats)
535         {
536             for (i = 0; i < Info->NumCarats; i++)
537             {
538                 InternalName[i] = '^';
539             }
540         }
541 
542         if (NumSegments <= 1)
543         {
544             Result = &InternalName[i];
545         }
546         else if (NumSegments == 2)
547         {
548             InternalName[i] = AML_DUAL_NAME_PREFIX;
549             Result = &InternalName[(ACPI_SIZE) i+1];
550         }
551         else
552         {
553             InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
554             InternalName[(ACPI_SIZE) i+1] = (char) NumSegments;
555             Result = &InternalName[(ACPI_SIZE) i+2];
556         }
557     }
558 
559     /* Build the name (minus path separators) */
560 
561     for (; NumSegments; NumSegments--)
562     {
563         for (i = 0; i < ACPI_NAME_SIZE; i++)
564         {
565             if (AcpiNsValidPathSeparator (*ExternalName) ||
566                (*ExternalName == 0))
567             {
568                 /* Pad the segment with underscore(s) if segment is short */
569 
570                 Result[i] = '_';
571             }
572             else
573             {
574                 /* Convert the character to uppercase and save it */
575 
576                 Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
577                 ExternalName++;
578             }
579         }
580 
581         /* Now we must have a path separator, or the pathname is bad */
582 
583         if (!AcpiNsValidPathSeparator (*ExternalName) &&
584             (*ExternalName != 0))
585         {
586             return_ACPI_STATUS (AE_BAD_PARAMETER);
587         }
588 
589         /* Move on the next segment */
590 
591         ExternalName++;
592         Result += ACPI_NAME_SIZE;
593     }
594 
595     /* Terminate the string */
596 
597     *Result = 0;
598 
599     if (Info->FullyQualified)
600     {
601         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
602             InternalName, InternalName));
603     }
604     else
605     {
606         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
607             InternalName, InternalName));
608     }
609 
610     return_ACPI_STATUS (AE_OK);
611 }
612 
613 
614 /*******************************************************************************
615  *
616  * FUNCTION:    AcpiNsInternalizeName
617  *
618  * PARAMETERS:  *ExternalName           - External representation of name
619  *              **Converted Name        - Where to return the resulting
620  *                                        internal represention of the name
621  *
622  * RETURN:      Status
623  *
624  * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
625  *              to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
626  *
627  *******************************************************************************/
628 
629 ACPI_STATUS
630 AcpiNsInternalizeName (
631     const char              *ExternalName,
632     char                    **ConvertedName)
633 {
634     char                    *InternalName;
635     ACPI_NAMESTRING_INFO    Info;
636     ACPI_STATUS             Status;
637 
638 
639     ACPI_FUNCTION_TRACE (NsInternalizeName);
640 
641 
642     if ((!ExternalName)      ||
643         (*ExternalName == 0) ||
644         (!ConvertedName))
645     {
646         return_ACPI_STATUS (AE_BAD_PARAMETER);
647     }
648 
649     /* Get the length of the new internal name */
650 
651     Info.ExternalName = ExternalName;
652     AcpiNsGetInternalNameLength (&Info);
653 
654     /* We need a segment to store the internal  name */
655 
656     InternalName = ACPI_ALLOCATE_ZEROED (Info.Length);
657     if (!InternalName)
658     {
659         return_ACPI_STATUS (AE_NO_MEMORY);
660     }
661 
662     /* Build the name */
663 
664     Info.InternalName = InternalName;
665     Status = AcpiNsBuildInternalName (&Info);
666     if (ACPI_FAILURE (Status))
667     {
668         ACPI_FREE (InternalName);
669         return_ACPI_STATUS (Status);
670     }
671 
672     *ConvertedName = InternalName;
673     return_ACPI_STATUS (AE_OK);
674 }
675 
676 
677 /*******************************************************************************
678  *
679  * FUNCTION:    AcpiNsExternalizeName
680  *
681  * PARAMETERS:  InternalNameLength  - Lenth of the internal name below
682  *              InternalName        - Internal representation of name
683  *              ConvertedNameLength - Where the length is returned
684  *              ConvertedName       - Where the resulting external name
685  *                                    is returned
686  *
687  * RETURN:      Status
688  *
689  * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
690  *              to its external (printable) form (e.g. "\_PR_.CPU0")
691  *
692  ******************************************************************************/
693 
694 ACPI_STATUS
695 AcpiNsExternalizeName (
696     UINT32                  InternalNameLength,
697     const char              *InternalName,
698     UINT32                  *ConvertedNameLength,
699     char                    **ConvertedName)
700 {
701     UINT32                  NamesIndex = 0;
702     UINT32                  NumSegments = 0;
703     UINT32                  RequiredLength;
704     UINT32                  PrefixLength = 0;
705     UINT32                  i = 0;
706     UINT32                  j = 0;
707 
708 
709     ACPI_FUNCTION_TRACE (NsExternalizeName);
710 
711 
712     if (!InternalNameLength     ||
713         !InternalName           ||
714         !ConvertedName)
715     {
716         return_ACPI_STATUS (AE_BAD_PARAMETER);
717     }
718 
719     /*
720      * Check for a prefix (one '\' | one or more '^').
721      */
722     switch (InternalName[0])
723     {
724     case '\\':
725         PrefixLength = 1;
726         break;
727 
728     case '^':
729         for (i = 0; i < InternalNameLength; i++)
730         {
731             if (InternalName[i] == '^')
732             {
733                 PrefixLength = i + 1;
734             }
735             else
736             {
737                 break;
738             }
739         }
740 
741         if (i == InternalNameLength)
742         {
743             PrefixLength = i;
744         }
745 
746         break;
747 
748     default:
749         break;
750     }
751 
752     /*
753      * Check for object names.  Note that there could be 0-255 of these
754      * 4-byte elements.
755      */
756     if (PrefixLength < InternalNameLength)
757     {
758         switch (InternalName[PrefixLength])
759         {
760         case AML_MULTI_NAME_PREFIX_OP:
761 
762             /* <count> 4-byte names */
763 
764             NamesIndex = PrefixLength + 2;
765             NumSegments = (UINT8)
766                 InternalName[(ACPI_SIZE) PrefixLength + 1];
767             break;
768 
769         case AML_DUAL_NAME_PREFIX:
770 
771             /* Two 4-byte names */
772 
773             NamesIndex = PrefixLength + 1;
774             NumSegments = 2;
775             break;
776 
777         case 0:
778 
779             /* NullName */
780 
781             NamesIndex = 0;
782             NumSegments = 0;
783             break;
784 
785         default:
786 
787             /* one 4-byte name */
788 
789             NamesIndex = PrefixLength;
790             NumSegments = 1;
791             break;
792         }
793     }
794 
795     /*
796      * Calculate the length of ConvertedName, which equals the length
797      * of the prefix, length of all object names, length of any required
798      * punctuation ('.') between object names, plus the NULL terminator.
799      */
800     RequiredLength = PrefixLength + (4 * NumSegments) +
801                         ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
802 
803     /*
804      * Check to see if we're still in bounds.  If not, there's a problem
805      * with InternalName (invalid format).
806      */
807     if (RequiredLength > InternalNameLength)
808     {
809         ACPI_ERROR ((AE_INFO, "Invalid internal name"));
810         return_ACPI_STATUS (AE_BAD_PATHNAME);
811     }
812 
813     /*
814      * Build ConvertedName
815      */
816     *ConvertedName = ACPI_ALLOCATE_ZEROED (RequiredLength);
817     if (!(*ConvertedName))
818     {
819         return_ACPI_STATUS (AE_NO_MEMORY);
820     }
821 
822     j = 0;
823 
824     for (i = 0; i < PrefixLength; i++)
825     {
826         (*ConvertedName)[j++] = InternalName[i];
827     }
828 
829     if (NumSegments > 0)
830     {
831         for (i = 0; i < NumSegments; i++)
832         {
833             if (i > 0)
834             {
835                 (*ConvertedName)[j++] = '.';
836             }
837 
838             (*ConvertedName)[j++] = InternalName[NamesIndex++];
839             (*ConvertedName)[j++] = InternalName[NamesIndex++];
840             (*ConvertedName)[j++] = InternalName[NamesIndex++];
841             (*ConvertedName)[j++] = InternalName[NamesIndex++];
842         }
843     }
844 
845     if (ConvertedNameLength)
846     {
847         *ConvertedNameLength = (UINT32) RequiredLength;
848     }
849 
850     return_ACPI_STATUS (AE_OK);
851 }
852 
853 
854 /*******************************************************************************
855  *
856  * FUNCTION:    AcpiNsMapHandleToNode
857  *
858  * PARAMETERS:  Handle          - Handle to be converted to an Node
859  *
860  * RETURN:      A Name table entry pointer
861  *
862  * DESCRIPTION: Convert a namespace handle to a real Node
863  *
864  * Note: Real integer handles would allow for more verification
865  *       and keep all pointers within this subsystem - however this introduces
866  *       more (and perhaps unnecessary) overhead.
867  *
868  ******************************************************************************/
869 
870 ACPI_NAMESPACE_NODE *
871 AcpiNsMapHandleToNode (
872     ACPI_HANDLE             Handle)
873 {
874 
875     ACPI_FUNCTION_ENTRY ();
876 
877 
878     /*
879      * Simple implementation
880      */
881     if ((!Handle) || (Handle == ACPI_ROOT_OBJECT))
882     {
883         return (AcpiGbl_RootNode);
884     }
885 
886     /* We can at least attempt to verify the handle */
887 
888     if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
889     {
890         return (NULL);
891     }
892 
893     return (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle));
894 }
895 
896 
897 /*******************************************************************************
898  *
899  * FUNCTION:    AcpiNsConvertEntryToHandle
900  *
901  * PARAMETERS:  Node          - Node to be converted to a Handle
902  *
903  * RETURN:      A user handle
904  *
905  * DESCRIPTION: Convert a real Node to a namespace handle
906  *
907  ******************************************************************************/
908 
909 ACPI_HANDLE
910 AcpiNsConvertEntryToHandle (
911     ACPI_NAMESPACE_NODE         *Node)
912 {
913 
914 
915     /*
916      * Simple implementation for now;
917      */
918     return ((ACPI_HANDLE) Node);
919 
920 
921 /* Example future implementation ---------------------
922 
923     if (!Node)
924     {
925         return (NULL);
926     }
927 
928     if (Node == AcpiGbl_RootNode)
929     {
930         return (ACPI_ROOT_OBJECT);
931     }
932 
933 
934     return ((ACPI_HANDLE) Node);
935 ------------------------------------------------------*/
936 }
937 
938 
939 /*******************************************************************************
940  *
941  * FUNCTION:    AcpiNsTerminate
942  *
943  * PARAMETERS:  none
944  *
945  * RETURN:      none
946  *
947  * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
948  *
949  ******************************************************************************/
950 
951 void
952 AcpiNsTerminate (
953     void)
954 {
955     ACPI_OPERAND_OBJECT     *ObjDesc;
956 
957 
958     ACPI_FUNCTION_TRACE (NsTerminate);
959 
960 
961     /*
962      * 1) Free the entire namespace -- all nodes and objects
963      *
964      * Delete all object descriptors attached to namepsace nodes
965      */
966     AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
967 
968     /* Detach any objects attached to the root */
969 
970     ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
971     if (ObjDesc)
972     {
973         AcpiNsDetachObject (AcpiGbl_RootNode);
974     }
975 
976     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
977     return_VOID;
978 }
979 
980 
981 /*******************************************************************************
982  *
983  * FUNCTION:    AcpiNsOpensScope
984  *
985  * PARAMETERS:  Type        - A valid namespace type
986  *
987  * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
988  *              to the ACPI specification, else 0
989  *
990  ******************************************************************************/
991 
992 UINT32
993 AcpiNsOpensScope (
994     ACPI_OBJECT_TYPE        Type)
995 {
996     ACPI_FUNCTION_TRACE_STR (NsOpensScope, AcpiUtGetTypeName (Type));
997 
998 
999     if (!AcpiUtValidObjectType (Type))
1000     {
1001         /* type code out of range  */
1002 
1003         ACPI_WARNING ((AE_INFO, "Invalid Object Type %X", Type));
1004         return_UINT32 (ACPI_NS_NORMAL);
1005     }
1006 
1007     return_UINT32 (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
1008 }
1009 
1010 
1011 /*******************************************************************************
1012  *
1013  * FUNCTION:    AcpiNsGetNode
1014  *
1015  * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
1016  *                            \ (backslash) and ^ (carat) prefixes, and the
1017  *                            . (period) to separate segments are supported.
1018  *              PrefixNode   - Root of subtree to be searched, or NS_ALL for the
1019  *                            root of the name space.  If Name is fully
1020  *                            qualified (first INT8 is '\'), the passed value
1021  *                            of Scope will not be accessed.
1022  *              Flags       - Used to indicate whether to perform upsearch or
1023  *                            not.
1024  *              ReturnNode  - Where the Node is returned
1025  *
1026  * DESCRIPTION: Look up a name relative to a given scope and return the
1027  *              corresponding Node.  NOTE: Scope can be null.
1028  *
1029  * MUTEX:       Locks namespace
1030  *
1031  ******************************************************************************/
1032 
1033 ACPI_STATUS
1034 AcpiNsGetNode (
1035     ACPI_NAMESPACE_NODE     *PrefixNode,
1036     const char              *Pathname,
1037     UINT32                  Flags,
1038     ACPI_NAMESPACE_NODE     **ReturnNode)
1039 {
1040     ACPI_GENERIC_STATE      ScopeInfo;
1041     ACPI_STATUS             Status;
1042     char                    *InternalPath;
1043 
1044 
1045     ACPI_FUNCTION_TRACE_PTR (NsGetNode, Pathname);
1046 
1047 
1048     if (!Pathname)
1049     {
1050         *ReturnNode = PrefixNode;
1051         if (!PrefixNode)
1052         {
1053             *ReturnNode = AcpiGbl_RootNode;
1054         }
1055         return_ACPI_STATUS (AE_OK);
1056     }
1057 
1058     /* Convert path to internal representation */
1059 
1060     Status = AcpiNsInternalizeName (Pathname, &InternalPath);
1061     if (ACPI_FAILURE (Status))
1062     {
1063         return_ACPI_STATUS (Status);
1064     }
1065 
1066     /* Must lock namespace during lookup */
1067 
1068     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1069     if (ACPI_FAILURE (Status))
1070     {
1071         goto Cleanup;
1072     }
1073 
1074     /* Setup lookup scope (search starting point) */
1075 
1076     ScopeInfo.Scope.Node = PrefixNode;
1077 
1078     /* Lookup the name in the namespace */
1079 
1080     Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
1081                 ACPI_IMODE_EXECUTE, (Flags | ACPI_NS_DONT_OPEN_SCOPE),
1082                 NULL, ReturnNode);
1083     if (ACPI_FAILURE (Status))
1084     {
1085         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
1086                 Pathname, AcpiFormatException (Status)));
1087     }
1088 
1089     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1090 
1091 Cleanup:
1092     ACPI_FREE (InternalPath);
1093     return_ACPI_STATUS (Status);
1094 }
1095 
1096 
1097 /*******************************************************************************
1098  *
1099  * FUNCTION:    AcpiNsGetParentNode
1100  *
1101  * PARAMETERS:  Node       - Current table entry
1102  *
1103  * RETURN:      Parent entry of the given entry
1104  *
1105  * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
1106  *
1107  ******************************************************************************/
1108 
1109 ACPI_NAMESPACE_NODE *
1110 AcpiNsGetParentNode (
1111     ACPI_NAMESPACE_NODE     *Node)
1112 {
1113     ACPI_FUNCTION_ENTRY ();
1114 
1115 
1116     if (!Node)
1117     {
1118         return (NULL);
1119     }
1120 
1121     /*
1122      * Walk to the end of this peer list. The last entry is marked with a flag
1123      * and the peer pointer is really a pointer back to the parent. This saves
1124      * putting a parent back pointer in each and every named object!
1125      */
1126     while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
1127     {
1128         Node = Node->Peer;
1129     }
1130 
1131     return (Node->Peer);
1132 }
1133 
1134 
1135 /*******************************************************************************
1136  *
1137  * FUNCTION:    AcpiNsGetNextValidNode
1138  *
1139  * PARAMETERS:  Node       - Current table entry
1140  *
1141  * RETURN:      Next valid Node in the linked node list. NULL if no more valid
1142  *              nodes.
1143  *
1144  * DESCRIPTION: Find the next valid node within a name table.
1145  *              Useful for implementing NULL-end-of-list loops.
1146  *
1147  ******************************************************************************/
1148 
1149 ACPI_NAMESPACE_NODE *
1150 AcpiNsGetNextValidNode (
1151     ACPI_NAMESPACE_NODE     *Node)
1152 {
1153 
1154     /* If we are at the end of this peer list, return NULL */
1155 
1156     if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
1157     {
1158         return NULL;
1159     }
1160 
1161     /* Otherwise just return the next peer */
1162 
1163     return (Node->Peer);
1164 }
1165 
1166 
1167 #ifdef ACPI_OBSOLETE_FUNCTIONS
1168 /*******************************************************************************
1169  *
1170  * FUNCTION:    AcpiNsFindParentName
1171  *
1172  * PARAMETERS:  *ChildNode             - Named Obj whose name is to be found
1173  *
1174  * RETURN:      The ACPI name
1175  *
1176  * DESCRIPTION: Search for the given obj in its parent scope and return the
1177  *              name segment, or "????" if the parent name can't be found
1178  *              (which "should not happen").
1179  *
1180  ******************************************************************************/
1181 
1182 ACPI_NAME
1183 AcpiNsFindParentName (
1184     ACPI_NAMESPACE_NODE     *ChildNode)
1185 {
1186     ACPI_NAMESPACE_NODE     *ParentNode;
1187 
1188 
1189     ACPI_FUNCTION_TRACE (NsFindParentName);
1190 
1191 
1192     if (ChildNode)
1193     {
1194         /* Valid entry.  Get the parent Node */
1195 
1196         ParentNode = AcpiNsGetParentNode (ChildNode);
1197         if (ParentNode)
1198         {
1199             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
1200                 "Parent of %p [%4.4s] is %p [%4.4s]\n",
1201                 ChildNode,  AcpiUtGetNodeName (ChildNode),
1202                 ParentNode, AcpiUtGetNodeName (ParentNode)));
1203 
1204             if (ParentNode->Name.Integer)
1205             {
1206                 return_VALUE ((ACPI_NAME) ParentNode->Name.Integer);
1207             }
1208         }
1209 
1210         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
1211             "Unable to find parent of %p (%4.4s)\n",
1212             ChildNode, AcpiUtGetNodeName (ChildNode)));
1213     }
1214 
1215     return_VALUE (ACPI_UNKNOWN_NAME);
1216 }
1217 #endif
1218 
1219 
1220