17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate *
37c478bd9Sstevel@tonic-gate * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
47c478bd9Sstevel@tonic-gate * parents and siblings and Scope manipulation
57c478bd9Sstevel@tonic-gate *
67c478bd9Sstevel@tonic-gate *****************************************************************************/
77c478bd9Sstevel@tonic-gate
8*35786f68SRobert Mustacchi /******************************************************************************
9*35786f68SRobert Mustacchi *
10*35786f68SRobert Mustacchi * 1. Copyright Notice
11*35786f68SRobert Mustacchi *
12*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
137c478bd9Sstevel@tonic-gate * All rights reserved.
147c478bd9Sstevel@tonic-gate *
15*35786f68SRobert Mustacchi * 2. License
16*35786f68SRobert Mustacchi *
17*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
18*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
19*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
20*35786f68SRobert Mustacchi * property rights.
21*35786f68SRobert Mustacchi *
22*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
24*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
26*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
27*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
28*35786f68SRobert Mustacchi *
29*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
31*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
32*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
33*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
34*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
35*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
36*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
37*35786f68SRobert Mustacchi *
38*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
39*35786f68SRobert Mustacchi * conditions are met:
40*35786f68SRobert Mustacchi *
41*35786f68SRobert Mustacchi * 3. Conditions
42*35786f68SRobert Mustacchi *
43*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
45*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
46*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
47*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
48*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
49*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
50*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
51*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
52*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
53*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
54*35786f68SRobert Mustacchi *
55*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
57*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
58*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
59*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
60*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
61*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
62*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
63*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
64*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
65*35786f68SRobert Mustacchi * make.
66*35786f68SRobert Mustacchi *
67*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
68*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
69*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
70*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
71*35786f68SRobert Mustacchi * distribution.
72*35786f68SRobert Mustacchi *
73*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
74*35786f68SRobert Mustacchi * Intel Code.
75*35786f68SRobert Mustacchi *
76*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
78*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
79*35786f68SRobert Mustacchi * without prior written authorization from Intel.
80*35786f68SRobert Mustacchi *
81*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
82*35786f68SRobert Mustacchi *
83*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
90*35786f68SRobert Mustacchi *
91*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98*35786f68SRobert Mustacchi * LIMITED REMEDY.
99*35786f68SRobert Mustacchi *
100*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
101*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
102*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
103*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
104*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
105*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
106*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
107*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
108*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
110*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
111*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
112*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
113*35786f68SRobert Mustacchi * such license, approval or letter.
114*35786f68SRobert Mustacchi *
115*35786f68SRobert Mustacchi *****************************************************************************
116*35786f68SRobert Mustacchi *
117*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
118*35786f68SRobert Mustacchi * following license:
119*35786f68SRobert Mustacchi *
12026f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
12126f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
12226f3cdf0SGordon Ross * are met:
12326f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
12426f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
12526f3cdf0SGordon Ross * without modification.
12626f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12726f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
12826f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
12926f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
13026f3cdf0SGordon Ross * binary redistribution.
13126f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
13226f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
13326f3cdf0SGordon Ross * from this software without specific prior written permission.
13426f3cdf0SGordon Ross *
13526f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13626f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13826f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146*35786f68SRobert Mustacchi *
147*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
148*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
149*35786f68SRobert Mustacchi * Software Foundation.
150*35786f68SRobert Mustacchi *
151*35786f68SRobert Mustacchi *****************************************************************************/
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate #include "acpi.h"
154aa2aa9a6SDana Myers #include "accommon.h"
1557c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1567c478bd9Sstevel@tonic-gate #include "amlcode.h"
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate #define _COMPONENT ACPI_NAMESPACE
1597c478bd9Sstevel@tonic-gate ACPI_MODULE_NAME ("nsutils")
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate /* Local prototypes */
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate #ifdef ACPI_OBSOLETE_FUNCTIONS
1647c478bd9Sstevel@tonic-gate ACPI_NAME
1657c478bd9Sstevel@tonic-gate AcpiNsFindParentName (
1667c478bd9Sstevel@tonic-gate ACPI_NAMESPACE_NODE *NodeToSearch);
1677c478bd9Sstevel@tonic-gate #endif
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate /*******************************************************************************
1717c478bd9Sstevel@tonic-gate *
1727c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsPrintNodePathname
1737c478bd9Sstevel@tonic-gate *
1747c478bd9Sstevel@tonic-gate * PARAMETERS: Node - Object
1757c478bd9Sstevel@tonic-gate * Message - Prefix message
1767c478bd9Sstevel@tonic-gate *
1777c478bd9Sstevel@tonic-gate * DESCRIPTION: Print an object's full namespace pathname
1787c478bd9Sstevel@tonic-gate * Manages allocation/freeing of a pathname buffer
1797c478bd9Sstevel@tonic-gate *
1807c478bd9Sstevel@tonic-gate ******************************************************************************/
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate void
AcpiNsPrintNodePathname(ACPI_NAMESPACE_NODE * Node,const char * Message)1837c478bd9Sstevel@tonic-gate AcpiNsPrintNodePathname (
1847c478bd9Sstevel@tonic-gate ACPI_NAMESPACE_NODE *Node,
185db2bae30SDana Myers const char *Message)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate ACPI_BUFFER Buffer;
1887c478bd9Sstevel@tonic-gate ACPI_STATUS Status;
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate if (!Node)
1927c478bd9Sstevel@tonic-gate {
1937c478bd9Sstevel@tonic-gate AcpiOsPrintf ("[NULL NAME]");
1947c478bd9Sstevel@tonic-gate return;
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate /* Convert handle to full pathname and print it (with supplied message) */
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
2007c478bd9Sstevel@tonic-gate
2017b1019a6SJerry Jelinek Status = AcpiNsHandleToPathname (Node, &Buffer, TRUE);
2027c478bd9Sstevel@tonic-gate if (ACPI_SUCCESS (Status))
2037c478bd9Sstevel@tonic-gate {
2047c478bd9Sstevel@tonic-gate if (Message)
2057c478bd9Sstevel@tonic-gate {
2067c478bd9Sstevel@tonic-gate AcpiOsPrintf ("%s ", Message);
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate
209*35786f68SRobert Mustacchi AcpiOsPrintf ("%s", (char *) Buffer.Pointer);
21027f7c583Smyers ACPI_FREE (Buffer.Pointer);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate /*******************************************************************************
2167c478bd9Sstevel@tonic-gate *
2177c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsGetType
2187c478bd9Sstevel@tonic-gate *
2197c478bd9Sstevel@tonic-gate * PARAMETERS: Node - Parent Node to be examined
2207c478bd9Sstevel@tonic-gate *
2217c478bd9Sstevel@tonic-gate * RETURN: Type field from Node whose handle is passed
2227c478bd9Sstevel@tonic-gate *
2237c478bd9Sstevel@tonic-gate * DESCRIPTION: Return the type of a Namespace node
2247c478bd9Sstevel@tonic-gate *
2257c478bd9Sstevel@tonic-gate ******************************************************************************/
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate ACPI_OBJECT_TYPE
AcpiNsGetType(ACPI_NAMESPACE_NODE * Node)2287c478bd9Sstevel@tonic-gate AcpiNsGetType (
2297c478bd9Sstevel@tonic-gate ACPI_NAMESPACE_NODE *Node)
2307c478bd9Sstevel@tonic-gate {
23127f7c583Smyers ACPI_FUNCTION_TRACE (NsGetType);
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate if (!Node)
2357c478bd9Sstevel@tonic-gate {
23630082d0cSmyers ACPI_WARNING ((AE_INFO, "Null Node parameter"));
2377b1019a6SJerry Jelinek return_UINT8 (ACPI_TYPE_ANY);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407b1019a6SJerry Jelinek return_UINT8 (Node->Type);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate /*******************************************************************************
2457c478bd9Sstevel@tonic-gate *
2467c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsLocal
2477c478bd9Sstevel@tonic-gate *
2487c478bd9Sstevel@tonic-gate * PARAMETERS: Type - A namespace object type
2497c478bd9Sstevel@tonic-gate *
2507c478bd9Sstevel@tonic-gate * RETURN: LOCAL if names must be found locally in objects of the
2517c478bd9Sstevel@tonic-gate * passed type, 0 if enclosing scopes should be searched
2527c478bd9Sstevel@tonic-gate *
2537c478bd9Sstevel@tonic-gate * DESCRIPTION: Returns scope rule for the given object type.
2547c478bd9Sstevel@tonic-gate *
2557c478bd9Sstevel@tonic-gate ******************************************************************************/
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate UINT32
AcpiNsLocal(ACPI_OBJECT_TYPE Type)2587c478bd9Sstevel@tonic-gate AcpiNsLocal (
2597c478bd9Sstevel@tonic-gate ACPI_OBJECT_TYPE Type)
2607c478bd9Sstevel@tonic-gate {
26127f7c583Smyers ACPI_FUNCTION_TRACE (NsLocal);
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (!AcpiUtValidObjectType (Type))
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate /* Type code out of range */
2677c478bd9Sstevel@tonic-gate
26826f3cdf0SGordon Ross ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
269186507a7Smyers return_UINT32 (ACPI_NS_NORMAL);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727b1019a6SJerry Jelinek return_UINT32 (AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /*******************************************************************************
2777c478bd9Sstevel@tonic-gate *
2787c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsGetInternalNameLength
2797c478bd9Sstevel@tonic-gate *
2807c478bd9Sstevel@tonic-gate * PARAMETERS: Info - Info struct initialized with the
2817c478bd9Sstevel@tonic-gate * external name pointer.
2827c478bd9Sstevel@tonic-gate *
2837c478bd9Sstevel@tonic-gate * RETURN: None
2847c478bd9Sstevel@tonic-gate *
2857c478bd9Sstevel@tonic-gate * DESCRIPTION: Calculate the length of the internal (AML) namestring
2867c478bd9Sstevel@tonic-gate * corresponding to the external (ASL) namestring.
2877c478bd9Sstevel@tonic-gate *
2887c478bd9Sstevel@tonic-gate ******************************************************************************/
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate void
AcpiNsGetInternalNameLength(ACPI_NAMESTRING_INFO * Info)2917c478bd9Sstevel@tonic-gate AcpiNsGetInternalNameLength (
2927c478bd9Sstevel@tonic-gate ACPI_NAMESTRING_INFO *Info)
2937c478bd9Sstevel@tonic-gate {
294db2bae30SDana Myers const char *NextExternalChar;
2957c478bd9Sstevel@tonic-gate UINT32 i;
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate ACPI_FUNCTION_ENTRY ();
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate NextExternalChar = Info->ExternalName;
3027c478bd9Sstevel@tonic-gate Info->NumCarats = 0;
3037c478bd9Sstevel@tonic-gate Info->NumSegments = 0;
3047c478bd9Sstevel@tonic-gate Info->FullyQualified = FALSE;
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate /*
3077b1019a6SJerry Jelinek * For the internal name, the required length is 4 bytes per segment,
3087b1019a6SJerry Jelinek * plus 1 each for RootPrefix, MultiNamePrefixOp, segment count,
3097b1019a6SJerry Jelinek * trailing null (which is not really needed, but no there's harm in
3107b1019a6SJerry Jelinek * putting it there)
3117c478bd9Sstevel@tonic-gate *
3127c478bd9Sstevel@tonic-gate * strlen() + 1 covers the first NameSeg, which has no path separator
3137c478bd9Sstevel@tonic-gate */
3147b1019a6SJerry Jelinek if (ACPI_IS_ROOT_PREFIX (*NextExternalChar))
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate Info->FullyQualified = TRUE;
3177c478bd9Sstevel@tonic-gate NextExternalChar++;
318aa2aa9a6SDana Myers
319aa2aa9a6SDana Myers /* Skip redundant RootPrefix, like \\_SB.PCI0.SBRG.EC0 */
320aa2aa9a6SDana Myers
3217b1019a6SJerry Jelinek while (ACPI_IS_ROOT_PREFIX (*NextExternalChar))
322aa2aa9a6SDana Myers {
323aa2aa9a6SDana Myers NextExternalChar++;
324aa2aa9a6SDana Myers }
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate else
3277c478bd9Sstevel@tonic-gate {
328aa2aa9a6SDana Myers /* Handle Carat prefixes */
329aa2aa9a6SDana Myers
3307b1019a6SJerry Jelinek while (ACPI_IS_PARENT_PREFIX (*NextExternalChar))
3317c478bd9Sstevel@tonic-gate {
3327c478bd9Sstevel@tonic-gate Info->NumCarats++;
3337c478bd9Sstevel@tonic-gate NextExternalChar++;
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate * Determine the number of ACPI name "segments" by counting the number of
3397c478bd9Sstevel@tonic-gate * path separators within the string. Start with one segment since the
3407c478bd9Sstevel@tonic-gate * segment count is [(# separators) + 1], and zero separators is ok.
3417c478bd9Sstevel@tonic-gate */
3427c478bd9Sstevel@tonic-gate if (*NextExternalChar)
3437c478bd9Sstevel@tonic-gate {
3447c478bd9Sstevel@tonic-gate Info->NumSegments = 1;
3457c478bd9Sstevel@tonic-gate for (i = 0; NextExternalChar[i]; i++)
3467c478bd9Sstevel@tonic-gate {
3477b1019a6SJerry Jelinek if (ACPI_IS_PATH_SEPARATOR (NextExternalChar[i]))
3487c478bd9Sstevel@tonic-gate {
3497c478bd9Sstevel@tonic-gate Info->NumSegments++;
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
3557b1019a6SJerry Jelinek 4 + Info->NumCarats;
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate Info->NextExternalChar = NextExternalChar;
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate /*******************************************************************************
3627c478bd9Sstevel@tonic-gate *
3637c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsBuildInternalName
3647c478bd9Sstevel@tonic-gate *
3657c478bd9Sstevel@tonic-gate * PARAMETERS: Info - Info struct fully initialized
3667c478bd9Sstevel@tonic-gate *
3677c478bd9Sstevel@tonic-gate * RETURN: Status
3687c478bd9Sstevel@tonic-gate *
3697c478bd9Sstevel@tonic-gate * DESCRIPTION: Construct the internal (AML) namestring
3707c478bd9Sstevel@tonic-gate * corresponding to the external (ASL) namestring.
3717c478bd9Sstevel@tonic-gate *
3727c478bd9Sstevel@tonic-gate ******************************************************************************/
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiNsBuildInternalName(ACPI_NAMESTRING_INFO * Info)3757c478bd9Sstevel@tonic-gate AcpiNsBuildInternalName (
3767c478bd9Sstevel@tonic-gate ACPI_NAMESTRING_INFO *Info)
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate UINT32 NumSegments = Info->NumSegments;
3797c478bd9Sstevel@tonic-gate char *InternalName = Info->InternalName;
380db2bae30SDana Myers const char *ExternalName = Info->NextExternalChar;
3817c478bd9Sstevel@tonic-gate char *Result = NULL;
382db2bae30SDana Myers UINT32 i;
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate
38527f7c583Smyers ACPI_FUNCTION_TRACE (NsBuildInternalName);
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /* Setup the correct prefixes, counts, and pointers */
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate if (Info->FullyQualified)
3917c478bd9Sstevel@tonic-gate {
3927b1019a6SJerry Jelinek InternalName[0] = AML_ROOT_PREFIX;
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate if (NumSegments <= 1)
3957c478bd9Sstevel@tonic-gate {
3967c478bd9Sstevel@tonic-gate Result = &InternalName[1];
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate else if (NumSegments == 2)
3997c478bd9Sstevel@tonic-gate {
4007c478bd9Sstevel@tonic-gate InternalName[1] = AML_DUAL_NAME_PREFIX;
4017c478bd9Sstevel@tonic-gate Result = &InternalName[2];
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate else
4047c478bd9Sstevel@tonic-gate {
405*35786f68SRobert Mustacchi InternalName[1] = AML_MULTI_NAME_PREFIX;
4067c478bd9Sstevel@tonic-gate InternalName[2] = (char) NumSegments;
4077c478bd9Sstevel@tonic-gate Result = &InternalName[3];
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate else
4117c478bd9Sstevel@tonic-gate {
4127c478bd9Sstevel@tonic-gate /*
4137c478bd9Sstevel@tonic-gate * Not fully qualified.
4147c478bd9Sstevel@tonic-gate * Handle Carats first, then append the name segments
4157c478bd9Sstevel@tonic-gate */
4167c478bd9Sstevel@tonic-gate i = 0;
4177c478bd9Sstevel@tonic-gate if (Info->NumCarats)
4187c478bd9Sstevel@tonic-gate {
4197c478bd9Sstevel@tonic-gate for (i = 0; i < Info->NumCarats; i++)
4207c478bd9Sstevel@tonic-gate {
4217b1019a6SJerry Jelinek InternalName[i] = AML_PARENT_PREFIX;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate if (NumSegments <= 1)
4267c478bd9Sstevel@tonic-gate {
4277c478bd9Sstevel@tonic-gate Result = &InternalName[i];
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate else if (NumSegments == 2)
4307c478bd9Sstevel@tonic-gate {
4317c478bd9Sstevel@tonic-gate InternalName[i] = AML_DUAL_NAME_PREFIX;
432db2bae30SDana Myers Result = &InternalName[(ACPI_SIZE) i+1];
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate else
4357c478bd9Sstevel@tonic-gate {
436*35786f68SRobert Mustacchi InternalName[i] = AML_MULTI_NAME_PREFIX;
437db2bae30SDana Myers InternalName[(ACPI_SIZE) i+1] = (char) NumSegments;
438db2bae30SDana Myers Result = &InternalName[(ACPI_SIZE) i+2];
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate /* Build the name (minus path separators) */
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate for (; NumSegments; NumSegments--)
4457c478bd9Sstevel@tonic-gate {
4467c478bd9Sstevel@tonic-gate for (i = 0; i < ACPI_NAME_SIZE; i++)
4477c478bd9Sstevel@tonic-gate {
4487b1019a6SJerry Jelinek if (ACPI_IS_PATH_SEPARATOR (*ExternalName) ||
4497c478bd9Sstevel@tonic-gate (*ExternalName == 0))
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate /* Pad the segment with underscore(s) if segment is short */
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate Result[i] = '_';
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate else
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate /* Convert the character to uppercase and save it */
4587c478bd9Sstevel@tonic-gate
4597b1019a6SJerry Jelinek Result[i] = (char) toupper ((int) *ExternalName);
4607c478bd9Sstevel@tonic-gate ExternalName++;
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate /* Now we must have a path separator, or the pathname is bad */
4657c478bd9Sstevel@tonic-gate
4667b1019a6SJerry Jelinek if (!ACPI_IS_PATH_SEPARATOR (*ExternalName) &&
4677c478bd9Sstevel@tonic-gate (*ExternalName != 0))
4687c478bd9Sstevel@tonic-gate {
4697b1019a6SJerry Jelinek return_ACPI_STATUS (AE_BAD_PATHNAME);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate /* Move on the next segment */
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate ExternalName++;
4757c478bd9Sstevel@tonic-gate Result += ACPI_NAME_SIZE;
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate /* Terminate the string */
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate *Result = 0;
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate if (Info->FullyQualified)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
4857c478bd9Sstevel@tonic-gate InternalName, InternalName));
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate else
4887c478bd9Sstevel@tonic-gate {
4897c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
4907c478bd9Sstevel@tonic-gate InternalName, InternalName));
4917c478bd9Sstevel@tonic-gate }
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_OK);
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate /*******************************************************************************
4987c478bd9Sstevel@tonic-gate *
4997c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsInternalizeName
5007c478bd9Sstevel@tonic-gate *
5017c478bd9Sstevel@tonic-gate * PARAMETERS: *ExternalName - External representation of name
5027c478bd9Sstevel@tonic-gate * **Converted Name - Where to return the resulting
5037c478bd9Sstevel@tonic-gate * internal represention of the name
5047c478bd9Sstevel@tonic-gate *
5057c478bd9Sstevel@tonic-gate * RETURN: Status
5067c478bd9Sstevel@tonic-gate *
5077c478bd9Sstevel@tonic-gate * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
5087c478bd9Sstevel@tonic-gate * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
5097c478bd9Sstevel@tonic-gate *
5107c478bd9Sstevel@tonic-gate *******************************************************************************/
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiNsInternalizeName(const char * ExternalName,char ** ConvertedName)5137c478bd9Sstevel@tonic-gate AcpiNsInternalizeName (
514db2bae30SDana Myers const char *ExternalName,
5157c478bd9Sstevel@tonic-gate char **ConvertedName)
5167c478bd9Sstevel@tonic-gate {
5177c478bd9Sstevel@tonic-gate char *InternalName;
5187c478bd9Sstevel@tonic-gate ACPI_NAMESTRING_INFO Info;
5197c478bd9Sstevel@tonic-gate ACPI_STATUS Status;
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate
52227f7c583Smyers ACPI_FUNCTION_TRACE (NsInternalizeName);
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate if ((!ExternalName) ||
5267c478bd9Sstevel@tonic-gate (*ExternalName == 0) ||
5277c478bd9Sstevel@tonic-gate (!ConvertedName))
5287c478bd9Sstevel@tonic-gate {
5297c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_BAD_PARAMETER);
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /* Get the length of the new internal name */
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate Info.ExternalName = ExternalName;
5357c478bd9Sstevel@tonic-gate AcpiNsGetInternalNameLength (&Info);
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate /* We need a segment to store the internal name */
5387c478bd9Sstevel@tonic-gate
53927f7c583Smyers InternalName = ACPI_ALLOCATE_ZEROED (Info.Length);
5407c478bd9Sstevel@tonic-gate if (!InternalName)
5417c478bd9Sstevel@tonic-gate {
5427c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_NO_MEMORY);
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate /* Build the name */
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate Info.InternalName = InternalName;
5487c478bd9Sstevel@tonic-gate Status = AcpiNsBuildInternalName (&Info);
5497c478bd9Sstevel@tonic-gate if (ACPI_FAILURE (Status))
5507c478bd9Sstevel@tonic-gate {
55127f7c583Smyers ACPI_FREE (InternalName);
5527c478bd9Sstevel@tonic-gate return_ACPI_STATUS (Status);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate *ConvertedName = InternalName;
5567c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_OK);
5577c478bd9Sstevel@tonic-gate }
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate /*******************************************************************************
5617c478bd9Sstevel@tonic-gate *
5627c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsExternalizeName
5637c478bd9Sstevel@tonic-gate *
5647c478bd9Sstevel@tonic-gate * PARAMETERS: InternalNameLength - Lenth of the internal name below
5657c478bd9Sstevel@tonic-gate * InternalName - Internal representation of name
5667c478bd9Sstevel@tonic-gate * ConvertedNameLength - Where the length is returned
5677c478bd9Sstevel@tonic-gate * ConvertedName - Where the resulting external name
5687c478bd9Sstevel@tonic-gate * is returned
5697c478bd9Sstevel@tonic-gate *
5707c478bd9Sstevel@tonic-gate * RETURN: Status
5717c478bd9Sstevel@tonic-gate *
5727c478bd9Sstevel@tonic-gate * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
5737c478bd9Sstevel@tonic-gate * to its external (printable) form (e.g. "\_PR_.CPU0")
5747c478bd9Sstevel@tonic-gate *
5757c478bd9Sstevel@tonic-gate ******************************************************************************/
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiNsExternalizeName(UINT32 InternalNameLength,const char * InternalName,UINT32 * ConvertedNameLength,char ** ConvertedName)5787c478bd9Sstevel@tonic-gate AcpiNsExternalizeName (
5797c478bd9Sstevel@tonic-gate UINT32 InternalNameLength,
580db2bae30SDana Myers const char *InternalName,
5817c478bd9Sstevel@tonic-gate UINT32 *ConvertedNameLength,
5827c478bd9Sstevel@tonic-gate char **ConvertedName)
5837c478bd9Sstevel@tonic-gate {
584db2bae30SDana Myers UINT32 NamesIndex = 0;
585db2bae30SDana Myers UINT32 NumSegments = 0;
586db2bae30SDana Myers UINT32 RequiredLength;
587db2bae30SDana Myers UINT32 PrefixLength = 0;
588db2bae30SDana Myers UINT32 i = 0;
589db2bae30SDana Myers UINT32 j = 0;
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate
59227f7c583Smyers ACPI_FUNCTION_TRACE (NsExternalizeName);
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate if (!InternalNameLength ||
5967c478bd9Sstevel@tonic-gate !InternalName ||
5977c478bd9Sstevel@tonic-gate !ConvertedName)
5987c478bd9Sstevel@tonic-gate {
5997c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_BAD_PARAMETER);
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate
602aa2aa9a6SDana Myers /* Check for a prefix (one '\' | one or more '^') */
603aa2aa9a6SDana Myers
6047c478bd9Sstevel@tonic-gate switch (InternalName[0])
6057c478bd9Sstevel@tonic-gate {
6067b1019a6SJerry Jelinek case AML_ROOT_PREFIX:
6077b1019a6SJerry Jelinek
6087c478bd9Sstevel@tonic-gate PrefixLength = 1;
6097c478bd9Sstevel@tonic-gate break;
6107c478bd9Sstevel@tonic-gate
6117b1019a6SJerry Jelinek case AML_PARENT_PREFIX:
6127b1019a6SJerry Jelinek
6137c478bd9Sstevel@tonic-gate for (i = 0; i < InternalNameLength; i++)
6147c478bd9Sstevel@tonic-gate {
6157b1019a6SJerry Jelinek if (ACPI_IS_PARENT_PREFIX (InternalName[i]))
6167c478bd9Sstevel@tonic-gate {
6177c478bd9Sstevel@tonic-gate PrefixLength = i + 1;
6187c478bd9Sstevel@tonic-gate }
6197c478bd9Sstevel@tonic-gate else
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate break;
6227c478bd9Sstevel@tonic-gate }
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate
6257c478bd9Sstevel@tonic-gate if (i == InternalNameLength)
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate PrefixLength = i;
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate break;
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate default:
6337b1019a6SJerry Jelinek
6347c478bd9Sstevel@tonic-gate break;
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate /*
638aa2aa9a6SDana Myers * Check for object names. Note that there could be 0-255 of these
6397c478bd9Sstevel@tonic-gate * 4-byte elements.
6407c478bd9Sstevel@tonic-gate */
6417c478bd9Sstevel@tonic-gate if (PrefixLength < InternalNameLength)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate switch (InternalName[PrefixLength])
6447c478bd9Sstevel@tonic-gate {
645*35786f68SRobert Mustacchi case AML_MULTI_NAME_PREFIX:
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate /* <count> 4-byte names */
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate NamesIndex = PrefixLength + 2;
650db2bae30SDana Myers NumSegments = (UINT8)
651db2bae30SDana Myers InternalName[(ACPI_SIZE) PrefixLength + 1];
6527c478bd9Sstevel@tonic-gate break;
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate case AML_DUAL_NAME_PREFIX:
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate /* Two 4-byte names */
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate NamesIndex = PrefixLength + 1;
6597c478bd9Sstevel@tonic-gate NumSegments = 2;
6607c478bd9Sstevel@tonic-gate break;
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate case 0:
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate /* NullName */
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate NamesIndex = 0;
6677c478bd9Sstevel@tonic-gate NumSegments = 0;
6687c478bd9Sstevel@tonic-gate break;
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate default:
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate /* one 4-byte name */
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate NamesIndex = PrefixLength;
6757c478bd9Sstevel@tonic-gate NumSegments = 1;
6767c478bd9Sstevel@tonic-gate break;
6777c478bd9Sstevel@tonic-gate }
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate
6807c478bd9Sstevel@tonic-gate /*
6817c478bd9Sstevel@tonic-gate * Calculate the length of ConvertedName, which equals the length
6827c478bd9Sstevel@tonic-gate * of the prefix, length of all object names, length of any required
6837c478bd9Sstevel@tonic-gate * punctuation ('.') between object names, plus the NULL terminator.
6847c478bd9Sstevel@tonic-gate */
6857c478bd9Sstevel@tonic-gate RequiredLength = PrefixLength + (4 * NumSegments) +
6867b1019a6SJerry Jelinek ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
6877c478bd9Sstevel@tonic-gate
6887c478bd9Sstevel@tonic-gate /*
6897b1019a6SJerry Jelinek * Check to see if we're still in bounds. If not, there's a problem
6907c478bd9Sstevel@tonic-gate * with InternalName (invalid format).
6917c478bd9Sstevel@tonic-gate */
6927c478bd9Sstevel@tonic-gate if (RequiredLength > InternalNameLength)
6937c478bd9Sstevel@tonic-gate {
69430082d0cSmyers ACPI_ERROR ((AE_INFO, "Invalid internal name"));
6957c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_BAD_PATHNAME);
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate
698aa2aa9a6SDana Myers /* Build the ConvertedName */
699aa2aa9a6SDana Myers
70027f7c583Smyers *ConvertedName = ACPI_ALLOCATE_ZEROED (RequiredLength);
7017c478bd9Sstevel@tonic-gate if (!(*ConvertedName))
7027c478bd9Sstevel@tonic-gate {
7037c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_NO_MEMORY);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate j = 0;
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate for (i = 0; i < PrefixLength; i++)
7097c478bd9Sstevel@tonic-gate {
7107c478bd9Sstevel@tonic-gate (*ConvertedName)[j++] = InternalName[i];
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate if (NumSegments > 0)
7147c478bd9Sstevel@tonic-gate {
7157c478bd9Sstevel@tonic-gate for (i = 0; i < NumSegments; i++)
7167c478bd9Sstevel@tonic-gate {
7177c478bd9Sstevel@tonic-gate if (i > 0)
7187c478bd9Sstevel@tonic-gate {
7197c478bd9Sstevel@tonic-gate (*ConvertedName)[j++] = '.';
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate
7227b1019a6SJerry Jelinek /* Copy and validate the 4-char name segment */
7237b1019a6SJerry Jelinek
7247b1019a6SJerry Jelinek ACPI_MOVE_NAME (&(*ConvertedName)[j],
7257b1019a6SJerry Jelinek &InternalName[NamesIndex]);
7267b1019a6SJerry Jelinek AcpiUtRepairName (&(*ConvertedName)[j]);
7277b1019a6SJerry Jelinek
7287b1019a6SJerry Jelinek j += ACPI_NAME_SIZE;
7297b1019a6SJerry Jelinek NamesIndex += ACPI_NAME_SIZE;
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate
7337c478bd9Sstevel@tonic-gate if (ConvertedNameLength)
7347c478bd9Sstevel@tonic-gate {
7357c478bd9Sstevel@tonic-gate *ConvertedNameLength = (UINT32) RequiredLength;
7367c478bd9Sstevel@tonic-gate }
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_OK);
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate /*******************************************************************************
7437c478bd9Sstevel@tonic-gate *
74426f3cdf0SGordon Ross * FUNCTION: AcpiNsValidateHandle
7457c478bd9Sstevel@tonic-gate *
74626f3cdf0SGordon Ross * PARAMETERS: Handle - Handle to be validated and typecast to a
74726f3cdf0SGordon Ross * namespace node.
7487c478bd9Sstevel@tonic-gate *
74926f3cdf0SGordon Ross * RETURN: A pointer to a namespace node
7507c478bd9Sstevel@tonic-gate *
75126f3cdf0SGordon Ross * DESCRIPTION: Convert a namespace handle to a namespace node. Handles special
75226f3cdf0SGordon Ross * cases for the root node.
7537c478bd9Sstevel@tonic-gate *
75426f3cdf0SGordon Ross * NOTE: Real integer handles would allow for more verification
7557c478bd9Sstevel@tonic-gate * and keep all pointers within this subsystem - however this introduces
75626f3cdf0SGordon Ross * more overhead and has not been necessary to this point. Drivers
75726f3cdf0SGordon Ross * holding handles are typically notified before a node becomes invalid
75826f3cdf0SGordon Ross * due to a table unload.
759aa2aa9a6SDana Myers *
7607c478bd9Sstevel@tonic-gate ******************************************************************************/
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate ACPI_NAMESPACE_NODE *
AcpiNsValidateHandle(ACPI_HANDLE Handle)76326f3cdf0SGordon Ross AcpiNsValidateHandle (
7647c478bd9Sstevel@tonic-gate ACPI_HANDLE Handle)
7657c478bd9Sstevel@tonic-gate {
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate ACPI_FUNCTION_ENTRY ();
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate
770aa2aa9a6SDana Myers /* Parameter validation */
771aa2aa9a6SDana Myers
77227f7c583Smyers if ((!Handle) || (Handle == ACPI_ROOT_OBJECT))
7737c478bd9Sstevel@tonic-gate {
7747c478bd9Sstevel@tonic-gate return (AcpiGbl_RootNode);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate /* We can at least attempt to verify the handle */
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
7807c478bd9Sstevel@tonic-gate {
7817c478bd9Sstevel@tonic-gate return (NULL);
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate
78427f7c583Smyers return (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle));
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate
7887c478bd9Sstevel@tonic-gate /*******************************************************************************
7897c478bd9Sstevel@tonic-gate *
7907c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsTerminate
7917c478bd9Sstevel@tonic-gate *
7927c478bd9Sstevel@tonic-gate * PARAMETERS: none
7937c478bd9Sstevel@tonic-gate *
7947c478bd9Sstevel@tonic-gate * RETURN: none
7957c478bd9Sstevel@tonic-gate *
7967c478bd9Sstevel@tonic-gate * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
7977c478bd9Sstevel@tonic-gate *
7987c478bd9Sstevel@tonic-gate ******************************************************************************/
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate void
AcpiNsTerminate(void)8017c478bd9Sstevel@tonic-gate AcpiNsTerminate (
8027c478bd9Sstevel@tonic-gate void)
8037c478bd9Sstevel@tonic-gate {
8047b1019a6SJerry Jelinek ACPI_STATUS Status;
805*35786f68SRobert Mustacchi ACPI_OPERAND_OBJECT *Prev;
806*35786f68SRobert Mustacchi ACPI_OPERAND_OBJECT *Next;
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate
80927f7c583Smyers ACPI_FUNCTION_TRACE (NsTerminate);
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate
812*35786f68SRobert Mustacchi /* Delete any module-level code blocks */
8137b1019a6SJerry Jelinek
814*35786f68SRobert Mustacchi Next = AcpiGbl_ModuleCodeList;
815*35786f68SRobert Mustacchi while (Next)
816*35786f68SRobert Mustacchi {
817*35786f68SRobert Mustacchi Prev = Next;
818*35786f68SRobert Mustacchi Next = Next->Method.Mutex;
819*35786f68SRobert Mustacchi Prev->Method.Mutex = NULL; /* Clear the Mutex (cheated) field */
820*35786f68SRobert Mustacchi AcpiUtRemoveReference (Prev);
8217b1019a6SJerry Jelinek }
8227b1019a6SJerry Jelinek
8237c478bd9Sstevel@tonic-gate /*
8247b1019a6SJerry Jelinek * Free the entire namespace -- all nodes and all objects
8257b1019a6SJerry Jelinek * attached to the nodes
8267c478bd9Sstevel@tonic-gate */
8277c478bd9Sstevel@tonic-gate AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
8287c478bd9Sstevel@tonic-gate
8297b1019a6SJerry Jelinek /* Delete any objects attached to the root node */
8307c478bd9Sstevel@tonic-gate
8317b1019a6SJerry Jelinek Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
8327b1019a6SJerry Jelinek if (ACPI_FAILURE (Status))
8337c478bd9Sstevel@tonic-gate {
8347b1019a6SJerry Jelinek return_VOID;
8357c478bd9Sstevel@tonic-gate }
8367c478bd9Sstevel@tonic-gate
8377b1019a6SJerry Jelinek AcpiNsDeleteNode (AcpiGbl_RootNode);
8387b1019a6SJerry Jelinek (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
8397b1019a6SJerry Jelinek
8407c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
8417c478bd9Sstevel@tonic-gate return_VOID;
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate
8457c478bd9Sstevel@tonic-gate /*******************************************************************************
8467c478bd9Sstevel@tonic-gate *
8477c478bd9Sstevel@tonic-gate * FUNCTION: AcpiNsOpensScope
8487c478bd9Sstevel@tonic-gate *
8497c478bd9Sstevel@tonic-gate * PARAMETERS: Type - A valid namespace type
8507c478bd9Sstevel@tonic-gate *
8517c478bd9Sstevel@tonic-gate * RETURN: NEWSCOPE if the passed type "opens a name scope" according
8527c478bd9Sstevel@tonic-gate * to the ACPI specification, else 0
8537c478bd9Sstevel@tonic-gate *
8547c478bd9Sstevel@tonic-gate ******************************************************************************/
8557c478bd9Sstevel@tonic-gate
8567c478bd9Sstevel@tonic-gate UINT32
AcpiNsOpensScope(ACPI_OBJECT_TYPE Type)8577c478bd9Sstevel@tonic-gate AcpiNsOpensScope (
8587c478bd9Sstevel@tonic-gate ACPI_OBJECT_TYPE Type)
8597c478bd9Sstevel@tonic-gate {
8607b1019a6SJerry Jelinek ACPI_FUNCTION_ENTRY ();
8617c478bd9Sstevel@tonic-gate
8627c478bd9Sstevel@tonic-gate
8637b1019a6SJerry Jelinek if (Type > ACPI_TYPE_LOCAL_MAX)
8647c478bd9Sstevel@tonic-gate {
8657c478bd9Sstevel@tonic-gate /* type code out of range */
8667c478bd9Sstevel@tonic-gate
86726f3cdf0SGordon Ross ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
8687b1019a6SJerry Jelinek return (ACPI_NS_NORMAL);
8697c478bd9Sstevel@tonic-gate }
8707c478bd9Sstevel@tonic-gate
8717b1019a6SJerry Jelinek return (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate /*******************************************************************************
8767c478bd9Sstevel@tonic-gate *
877*35786f68SRobert Mustacchi * FUNCTION: AcpiNsGetNodeUnlocked
8787c478bd9Sstevel@tonic-gate *
8797c478bd9Sstevel@tonic-gate * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
8807c478bd9Sstevel@tonic-gate * \ (backslash) and ^ (carat) prefixes, and the
8817c478bd9Sstevel@tonic-gate * . (period) to separate segments are supported.
88227f7c583Smyers * PrefixNode - Root of subtree to be searched, or NS_ALL for the
8837b1019a6SJerry Jelinek * root of the name space. If Name is fully
8847c478bd9Sstevel@tonic-gate * qualified (first INT8 is '\'), the passed value
8857c478bd9Sstevel@tonic-gate * of Scope will not be accessed.
8867c478bd9Sstevel@tonic-gate * Flags - Used to indicate whether to perform upsearch or
8877c478bd9Sstevel@tonic-gate * not.
8887c478bd9Sstevel@tonic-gate * ReturnNode - Where the Node is returned
8897c478bd9Sstevel@tonic-gate *
8907c478bd9Sstevel@tonic-gate * DESCRIPTION: Look up a name relative to a given scope and return the
8917b1019a6SJerry Jelinek * corresponding Node. NOTE: Scope can be null.
8927c478bd9Sstevel@tonic-gate *
893*35786f68SRobert Mustacchi * MUTEX: Doesn't locks namespace
8947c478bd9Sstevel@tonic-gate *
8957c478bd9Sstevel@tonic-gate ******************************************************************************/
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiNsGetNodeUnlocked(ACPI_NAMESPACE_NODE * PrefixNode,const char * Pathname,UINT32 Flags,ACPI_NAMESPACE_NODE ** ReturnNode)898*35786f68SRobert Mustacchi AcpiNsGetNodeUnlocked (
89927f7c583Smyers ACPI_NAMESPACE_NODE *PrefixNode,
900db2bae30SDana Myers const char *Pathname,
9017c478bd9Sstevel@tonic-gate UINT32 Flags,
9027c478bd9Sstevel@tonic-gate ACPI_NAMESPACE_NODE **ReturnNode)
9037c478bd9Sstevel@tonic-gate {
9047c478bd9Sstevel@tonic-gate ACPI_GENERIC_STATE ScopeInfo;
9057c478bd9Sstevel@tonic-gate ACPI_STATUS Status;
90627f7c583Smyers char *InternalPath;
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate
909*35786f68SRobert Mustacchi ACPI_FUNCTION_TRACE_PTR (NsGetNodeUnlocked, ACPI_CAST_PTR (char, Pathname));
9107c478bd9Sstevel@tonic-gate
9117c478bd9Sstevel@tonic-gate
9127b1019a6SJerry Jelinek /* Simplest case is a null pathname */
9137b1019a6SJerry Jelinek
91427f7c583Smyers if (!Pathname)
9157c478bd9Sstevel@tonic-gate {
91627f7c583Smyers *ReturnNode = PrefixNode;
91727f7c583Smyers if (!PrefixNode)
9187c478bd9Sstevel@tonic-gate {
91927f7c583Smyers *ReturnNode = AcpiGbl_RootNode;
9207c478bd9Sstevel@tonic-gate }
9217b1019a6SJerry Jelinek
9227b1019a6SJerry Jelinek return_ACPI_STATUS (AE_OK);
9237b1019a6SJerry Jelinek }
9247b1019a6SJerry Jelinek
9257b1019a6SJerry Jelinek /* Quick check for a reference to the root */
9267b1019a6SJerry Jelinek
9277b1019a6SJerry Jelinek if (ACPI_IS_ROOT_PREFIX (Pathname[0]) && (!Pathname[1]))
9287b1019a6SJerry Jelinek {
9297b1019a6SJerry Jelinek *ReturnNode = AcpiGbl_RootNode;
93027f7c583Smyers return_ACPI_STATUS (AE_OK);
93127f7c583Smyers }
93227f7c583Smyers
93327f7c583Smyers /* Convert path to internal representation */
93427f7c583Smyers
93527f7c583Smyers Status = AcpiNsInternalizeName (Pathname, &InternalPath);
93627f7c583Smyers if (ACPI_FAILURE (Status))
93727f7c583Smyers {
93827f7c583Smyers return_ACPI_STATUS (Status);
9397c478bd9Sstevel@tonic-gate }
9407c478bd9Sstevel@tonic-gate
9417c478bd9Sstevel@tonic-gate /* Setup lookup scope (search starting point) */
9427c478bd9Sstevel@tonic-gate
94327f7c583Smyers ScopeInfo.Scope.Node = PrefixNode;
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate /* Lookup the name in the namespace */
9467c478bd9Sstevel@tonic-gate
94727f7c583Smyers Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
9487b1019a6SJerry Jelinek ACPI_IMODE_EXECUTE, (Flags | ACPI_NS_DONT_OPEN_SCOPE),
9497b1019a6SJerry Jelinek NULL, ReturnNode);
9507c478bd9Sstevel@tonic-gate if (ACPI_FAILURE (Status))
9517c478bd9Sstevel@tonic-gate {
952aa2aa9a6SDana Myers ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s, %s\n",
9537b1019a6SJerry Jelinek Pathname, AcpiFormatException (Status)));
9547c478bd9Sstevel@tonic-gate }
9557c478bd9Sstevel@tonic-gate
95627f7c583Smyers ACPI_FREE (InternalPath);
9577c478bd9Sstevel@tonic-gate return_ACPI_STATUS (Status);
9587c478bd9Sstevel@tonic-gate }
959*35786f68SRobert Mustacchi
960*35786f68SRobert Mustacchi
961*35786f68SRobert Mustacchi /*******************************************************************************
962*35786f68SRobert Mustacchi *
963*35786f68SRobert Mustacchi * FUNCTION: AcpiNsGetNode
964*35786f68SRobert Mustacchi *
965*35786f68SRobert Mustacchi * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
966*35786f68SRobert Mustacchi * \ (backslash) and ^ (carat) prefixes, and the
967*35786f68SRobert Mustacchi * . (period) to separate segments are supported.
968*35786f68SRobert Mustacchi * PrefixNode - Root of subtree to be searched, or NS_ALL for the
969*35786f68SRobert Mustacchi * root of the name space. If Name is fully
970*35786f68SRobert Mustacchi * qualified (first INT8 is '\'), the passed value
971*35786f68SRobert Mustacchi * of Scope will not be accessed.
972*35786f68SRobert Mustacchi * Flags - Used to indicate whether to perform upsearch or
973*35786f68SRobert Mustacchi * not.
974*35786f68SRobert Mustacchi * ReturnNode - Where the Node is returned
975*35786f68SRobert Mustacchi *
976*35786f68SRobert Mustacchi * DESCRIPTION: Look up a name relative to a given scope and return the
977*35786f68SRobert Mustacchi * corresponding Node. NOTE: Scope can be null.
978*35786f68SRobert Mustacchi *
979*35786f68SRobert Mustacchi * MUTEX: Locks namespace
980*35786f68SRobert Mustacchi *
981*35786f68SRobert Mustacchi ******************************************************************************/
982*35786f68SRobert Mustacchi
983*35786f68SRobert Mustacchi ACPI_STATUS
AcpiNsGetNode(ACPI_NAMESPACE_NODE * PrefixNode,const char * Pathname,UINT32 Flags,ACPI_NAMESPACE_NODE ** ReturnNode)984*35786f68SRobert Mustacchi AcpiNsGetNode (
985*35786f68SRobert Mustacchi ACPI_NAMESPACE_NODE *PrefixNode,
986*35786f68SRobert Mustacchi const char *Pathname,
987*35786f68SRobert Mustacchi UINT32 Flags,
988*35786f68SRobert Mustacchi ACPI_NAMESPACE_NODE **ReturnNode)
989*35786f68SRobert Mustacchi {
990*35786f68SRobert Mustacchi ACPI_STATUS Status;
991*35786f68SRobert Mustacchi
992*35786f68SRobert Mustacchi
993*35786f68SRobert Mustacchi ACPI_FUNCTION_TRACE_PTR (NsGetNode, ACPI_CAST_PTR (char, Pathname));
994*35786f68SRobert Mustacchi
995*35786f68SRobert Mustacchi
996*35786f68SRobert Mustacchi Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
997*35786f68SRobert Mustacchi if (ACPI_FAILURE (Status))
998*35786f68SRobert Mustacchi {
999*35786f68SRobert Mustacchi return_ACPI_STATUS (Status);
1000*35786f68SRobert Mustacchi }
1001*35786f68SRobert Mustacchi
1002*35786f68SRobert Mustacchi Status = AcpiNsGetNodeUnlocked (PrefixNode, Pathname,
1003*35786f68SRobert Mustacchi Flags, ReturnNode);
1004*35786f68SRobert Mustacchi
1005*35786f68SRobert Mustacchi (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1006*35786f68SRobert Mustacchi return_ACPI_STATUS (Status);
1007*35786f68SRobert Mustacchi }
1008