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