xref: /titanic_50/usr/src/uts/intel/io/acpica/namespace/nsparse.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: nsparse - namespace interface to AML parser
4ae115bc7Smrj  *
5ae115bc7Smrj  *****************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj  * All rights reserved.
10ae115bc7Smrj  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25ae115bc7Smrj  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29ae115bc7Smrj  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43ae115bc7Smrj 
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acnamesp.h"
47ae115bc7Smrj #include "acparser.h"
48ae115bc7Smrj #include "acdispat.h"
49db2bae30SDana Myers #include "actables.h"
50ae115bc7Smrj 
51ae115bc7Smrj 
52ae115bc7Smrj #define _COMPONENT          ACPI_NAMESPACE
53ae115bc7Smrj         ACPI_MODULE_NAME    ("nsparse")
54ae115bc7Smrj 
55ae115bc7Smrj 
56ae115bc7Smrj /*******************************************************************************
57ae115bc7Smrj  *
58ae115bc7Smrj  * FUNCTION:    NsOneCompleteParse
59ae115bc7Smrj  *
60ae115bc7Smrj  * PARAMETERS:  PassNumber              - 1 or 2
61ae115bc7Smrj  *              TableDesc               - The table to be parsed.
62ae115bc7Smrj  *
63ae115bc7Smrj  * RETURN:      Status
64ae115bc7Smrj  *
65ae115bc7Smrj  * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
66ae115bc7Smrj  *
67ae115bc7Smrj  ******************************************************************************/
68ae115bc7Smrj 
69ae115bc7Smrj ACPI_STATUS
AcpiNsOneCompleteParse(UINT32 PassNumber,UINT32 TableIndex,ACPI_NAMESPACE_NODE * StartNode)70ae115bc7Smrj AcpiNsOneCompleteParse (
71db2bae30SDana Myers     UINT32                  PassNumber,
72db2bae30SDana Myers     UINT32                  TableIndex,
73db2bae30SDana Myers     ACPI_NAMESPACE_NODE     *StartNode)
74ae115bc7Smrj {
75ae115bc7Smrj     ACPI_PARSE_OBJECT       *ParseRoot;
76ae115bc7Smrj     ACPI_STATUS             Status;
77db2bae30SDana Myers     UINT32                  AmlLength;
78db2bae30SDana Myers     UINT8                   *AmlStart;
79ae115bc7Smrj     ACPI_WALK_STATE         *WalkState;
80db2bae30SDana Myers     ACPI_TABLE_HEADER       *Table;
81db2bae30SDana Myers     ACPI_OWNER_ID           OwnerId;
82ae115bc7Smrj 
83ae115bc7Smrj 
84ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsOneCompleteParse);
85ae115bc7Smrj 
86ae115bc7Smrj 
87*385cc6b4SJerry Jelinek     Status = AcpiGetTableByIndex (TableIndex, &Table);
88*385cc6b4SJerry Jelinek     if (ACPI_FAILURE (Status))
89*385cc6b4SJerry Jelinek     {
90*385cc6b4SJerry Jelinek         return_ACPI_STATUS (Status);
91*385cc6b4SJerry Jelinek     }
92*385cc6b4SJerry Jelinek 
93*385cc6b4SJerry Jelinek     /* Table must consist of at least a complete header */
94*385cc6b4SJerry Jelinek 
95*385cc6b4SJerry Jelinek     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
96*385cc6b4SJerry Jelinek     {
97*385cc6b4SJerry Jelinek         return_ACPI_STATUS (AE_BAD_HEADER);
98*385cc6b4SJerry Jelinek     }
99*385cc6b4SJerry Jelinek 
100*385cc6b4SJerry Jelinek     AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
101*385cc6b4SJerry Jelinek     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
102*385cc6b4SJerry Jelinek 
103db2bae30SDana Myers     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
104db2bae30SDana Myers     if (ACPI_FAILURE (Status))
105db2bae30SDana Myers     {
106db2bae30SDana Myers         return_ACPI_STATUS (Status);
107db2bae30SDana Myers     }
108db2bae30SDana Myers 
109ae115bc7Smrj     /* Create and init a Root Node */
110ae115bc7Smrj 
111*385cc6b4SJerry Jelinek     ParseRoot = AcpiPsCreateScopeOp (AmlStart);
112ae115bc7Smrj     if (!ParseRoot)
113ae115bc7Smrj     {
114ae115bc7Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
115ae115bc7Smrj     }
116ae115bc7Smrj 
117ae115bc7Smrj     /* Create and initialize a new walk state */
118ae115bc7Smrj 
119db2bae30SDana Myers     WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
120ae115bc7Smrj     if (!WalkState)
121ae115bc7Smrj     {
122ae115bc7Smrj         AcpiPsFreeOp (ParseRoot);
123ae115bc7Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
124ae115bc7Smrj     }
125ae115bc7Smrj 
126db2bae30SDana Myers     Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
127db2bae30SDana Myers         AmlStart, AmlLength, NULL, (UINT8) PassNumber);
128db2bae30SDana Myers     if (ACPI_FAILURE (Status))
129db2bae30SDana Myers     {
130db2bae30SDana Myers         AcpiDsDeleteWalkState (WalkState);
131db2bae30SDana Myers         goto Cleanup;
132db2bae30SDana Myers     }
133db2bae30SDana Myers 
134*385cc6b4SJerry Jelinek     /* Found OSDT table, enable the namespace override feature */
135*385cc6b4SJerry Jelinek 
136*385cc6b4SJerry Jelinek     if (ACPI_COMPARE_NAME(Table->Signature, ACPI_SIG_OSDT) &&
137*385cc6b4SJerry Jelinek         PassNumber == ACPI_IMODE_LOAD_PASS1)
138*385cc6b4SJerry Jelinek     {
139*385cc6b4SJerry Jelinek         WalkState->NamespaceOverride = TRUE;
140*385cc6b4SJerry Jelinek     }
141*385cc6b4SJerry Jelinek 
142db2bae30SDana Myers     /* StartNode is the default location to load the table  */
143db2bae30SDana Myers 
144db2bae30SDana Myers     if (StartNode && StartNode != AcpiGbl_RootNode)
145db2bae30SDana Myers     {
146*385cc6b4SJerry Jelinek         Status = AcpiDsScopeStackPush (
147*385cc6b4SJerry Jelinek             StartNode, ACPI_TYPE_METHOD, WalkState);
148db2bae30SDana Myers         if (ACPI_FAILURE (Status))
149db2bae30SDana Myers         {
150db2bae30SDana Myers             AcpiDsDeleteWalkState (WalkState);
151db2bae30SDana Myers             goto Cleanup;
152db2bae30SDana Myers         }
153db2bae30SDana Myers     }
154db2bae30SDana Myers 
155ae115bc7Smrj     /* Parse the AML */
156ae115bc7Smrj 
157*385cc6b4SJerry Jelinek     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
158*385cc6b4SJerry Jelinek         "*PARSE* pass %u parse\n", PassNumber));
159ae115bc7Smrj     Status = AcpiPsParseAml (WalkState);
160ae115bc7Smrj 
161db2bae30SDana Myers Cleanup:
162ae115bc7Smrj     AcpiPsDeleteParseTree (ParseRoot);
163ae115bc7Smrj     return_ACPI_STATUS (Status);
164ae115bc7Smrj }
165ae115bc7Smrj 
166ae115bc7Smrj 
167ae115bc7Smrj /*******************************************************************************
168ae115bc7Smrj  *
169ae115bc7Smrj  * FUNCTION:    AcpiNsParseTable
170ae115bc7Smrj  *
171ae115bc7Smrj  * PARAMETERS:  TableDesc       - An ACPI table descriptor for table to parse
172ae115bc7Smrj  *              StartNode       - Where to enter the table into the namespace
173ae115bc7Smrj  *
174ae115bc7Smrj  * RETURN:      Status
175ae115bc7Smrj  *
176ae115bc7Smrj  * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
177ae115bc7Smrj  *
178ae115bc7Smrj  ******************************************************************************/
179ae115bc7Smrj 
180ae115bc7Smrj ACPI_STATUS
AcpiNsParseTable(UINT32 TableIndex,ACPI_NAMESPACE_NODE * StartNode)181ae115bc7Smrj AcpiNsParseTable (
182db2bae30SDana Myers     UINT32                  TableIndex,
183ae115bc7Smrj     ACPI_NAMESPACE_NODE     *StartNode)
184ae115bc7Smrj {
185ae115bc7Smrj     ACPI_STATUS             Status;
186ae115bc7Smrj 
187ae115bc7Smrj 
188ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsParseTable);
189ae115bc7Smrj 
190ae115bc7Smrj 
191ae115bc7Smrj     /*
192ae115bc7Smrj      * AML Parse, pass 1
193ae115bc7Smrj      *
194ae115bc7Smrj      * In this pass, we load most of the namespace. Control methods
195ae115bc7Smrj      * are not parsed until later. A parse tree is not created. Instead,
196ae115bc7Smrj      * each Parser Op subtree is deleted when it is finished. This saves
197ae115bc7Smrj      * a great deal of memory, and allows a small cache of parse objects
198ae115bc7Smrj      * to service the entire parse. The second pass of the parse then
199db2bae30SDana Myers      * performs another complete parse of the AML.
200ae115bc7Smrj      */
201ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
202*385cc6b4SJerry Jelinek 
203aa2aa9a6SDana Myers     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
204aa2aa9a6SDana Myers         TableIndex, StartNode);
205ae115bc7Smrj     if (ACPI_FAILURE (Status))
206ae115bc7Smrj     {
207ae115bc7Smrj         return_ACPI_STATUS (Status);
208ae115bc7Smrj     }
209ae115bc7Smrj 
210ae115bc7Smrj     /*
211ae115bc7Smrj      * AML Parse, pass 2
212ae115bc7Smrj      *
213ae115bc7Smrj      * In this pass, we resolve forward references and other things
214ae115bc7Smrj      * that could not be completed during the first pass.
215ae115bc7Smrj      * Another complete parse of the AML is performed, but the
216ae115bc7Smrj      * overhead of this is compensated for by the fact that the
217ae115bc7Smrj      * parse objects are all cached.
218ae115bc7Smrj      */
219ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
220aa2aa9a6SDana Myers     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
221aa2aa9a6SDana Myers         TableIndex, StartNode);
222ae115bc7Smrj     if (ACPI_FAILURE (Status))
223ae115bc7Smrj     {
224ae115bc7Smrj         return_ACPI_STATUS (Status);
225ae115bc7Smrj     }
226ae115bc7Smrj 
227ae115bc7Smrj     return_ACPI_STATUS (Status);
228ae115bc7Smrj }
229