xref: /titanic_44/usr/src/uts/intel/io/acpica/disassembler/dmdeferred.c (revision cb56572868bfc488bbd3ab847b09db2a25554d44)
1*cb565728SJerry Jelinek /******************************************************************************
2*cb565728SJerry Jelinek  *
3*cb565728SJerry Jelinek  * Module Name: dmdeferred - Disassembly of deferred AML opcodes
4*cb565728SJerry Jelinek  *
5*cb565728SJerry Jelinek  *****************************************************************************/
6*cb565728SJerry Jelinek 
7*cb565728SJerry Jelinek /*
8*cb565728SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9*cb565728SJerry Jelinek  * All rights reserved.
10*cb565728SJerry Jelinek  *
11*cb565728SJerry Jelinek  * Redistribution and use in source and binary forms, with or without
12*cb565728SJerry Jelinek  * modification, are permitted provided that the following conditions
13*cb565728SJerry Jelinek  * are met:
14*cb565728SJerry Jelinek  * 1. Redistributions of source code must retain the above copyright
15*cb565728SJerry Jelinek  *    notice, this list of conditions, and the following disclaimer,
16*cb565728SJerry Jelinek  *    without modification.
17*cb565728SJerry Jelinek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*cb565728SJerry Jelinek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*cb565728SJerry Jelinek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*cb565728SJerry Jelinek  *    including a substantially similar Disclaimer requirement for further
21*cb565728SJerry Jelinek  *    binary redistribution.
22*cb565728SJerry Jelinek  * 3. Neither the names of the above-listed copyright holders nor the names
23*cb565728SJerry Jelinek  *    of any contributors may be used to endorse or promote products derived
24*cb565728SJerry Jelinek  *    from this software without specific prior written permission.
25*cb565728SJerry Jelinek  *
26*cb565728SJerry Jelinek  * Alternatively, this software may be distributed under the terms of the
27*cb565728SJerry Jelinek  * GNU General Public License ("GPL") version 2 as published by the Free
28*cb565728SJerry Jelinek  * Software Foundation.
29*cb565728SJerry Jelinek  *
30*cb565728SJerry Jelinek  * NO WARRANTY
31*cb565728SJerry Jelinek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*cb565728SJerry Jelinek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*cb565728SJerry Jelinek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*cb565728SJerry Jelinek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*cb565728SJerry Jelinek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*cb565728SJerry Jelinek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*cb565728SJerry Jelinek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*cb565728SJerry Jelinek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*cb565728SJerry Jelinek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*cb565728SJerry Jelinek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*cb565728SJerry Jelinek  * POSSIBILITY OF SUCH DAMAGES.
42*cb565728SJerry Jelinek  */
43*cb565728SJerry Jelinek 
44*cb565728SJerry Jelinek #include "acpi.h"
45*cb565728SJerry Jelinek #include "accommon.h"
46*cb565728SJerry Jelinek #include "acdispat.h"
47*cb565728SJerry Jelinek #include "amlcode.h"
48*cb565728SJerry Jelinek #include "acdisasm.h"
49*cb565728SJerry Jelinek #include "acparser.h"
50*cb565728SJerry Jelinek 
51*cb565728SJerry Jelinek #define _COMPONENT          ACPI_CA_DISASSEMBLER
52*cb565728SJerry Jelinek         ACPI_MODULE_NAME    ("dmdeferred")
53*cb565728SJerry Jelinek 
54*cb565728SJerry Jelinek 
55*cb565728SJerry Jelinek /* Local prototypes */
56*cb565728SJerry Jelinek 
57*cb565728SJerry Jelinek static ACPI_STATUS
58*cb565728SJerry Jelinek AcpiDmDeferredParse (
59*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *Op,
60*cb565728SJerry Jelinek     UINT8                   *Aml,
61*cb565728SJerry Jelinek     UINT32                  AmlLength);
62*cb565728SJerry Jelinek 
63*cb565728SJerry Jelinek 
64*cb565728SJerry Jelinek /******************************************************************************
65*cb565728SJerry Jelinek  *
66*cb565728SJerry Jelinek  * FUNCTION:    AcpiDmParseDeferredOps
67*cb565728SJerry Jelinek  *
68*cb565728SJerry Jelinek  * PARAMETERS:  Root                - Root of the parse tree
69*cb565728SJerry Jelinek  *
70*cb565728SJerry Jelinek  * RETURN:      Status
71*cb565728SJerry Jelinek  *
72*cb565728SJerry Jelinek  * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
73*cb565728SJerry Jelinek  *
74*cb565728SJerry Jelinek  *****************************************************************************/
75*cb565728SJerry Jelinek 
76*cb565728SJerry Jelinek ACPI_STATUS
AcpiDmParseDeferredOps(ACPI_PARSE_OBJECT * Root)77*cb565728SJerry Jelinek AcpiDmParseDeferredOps (
78*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *Root)
79*cb565728SJerry Jelinek {
80*cb565728SJerry Jelinek     const ACPI_OPCODE_INFO  *OpInfo;
81*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *Op = Root;
82*cb565728SJerry Jelinek     ACPI_STATUS             Status;
83*cb565728SJerry Jelinek 
84*cb565728SJerry Jelinek 
85*cb565728SJerry Jelinek     ACPI_FUNCTION_ENTRY ();
86*cb565728SJerry Jelinek 
87*cb565728SJerry Jelinek 
88*cb565728SJerry Jelinek     /* Traverse the entire parse tree */
89*cb565728SJerry Jelinek 
90*cb565728SJerry Jelinek     while (Op)
91*cb565728SJerry Jelinek     {
92*cb565728SJerry Jelinek         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
93*cb565728SJerry Jelinek         if (!(OpInfo->Flags & AML_DEFER))
94*cb565728SJerry Jelinek         {
95*cb565728SJerry Jelinek             Op = AcpiPsGetDepthNext (Root, Op);
96*cb565728SJerry Jelinek             continue;
97*cb565728SJerry Jelinek         }
98*cb565728SJerry Jelinek 
99*cb565728SJerry Jelinek         /* Now we know we have a deferred opcode */
100*cb565728SJerry Jelinek 
101*cb565728SJerry Jelinek         switch (Op->Common.AmlOpcode)
102*cb565728SJerry Jelinek         {
103*cb565728SJerry Jelinek         case AML_METHOD_OP:
104*cb565728SJerry Jelinek         case AML_BUFFER_OP:
105*cb565728SJerry Jelinek         case AML_PACKAGE_OP:
106*cb565728SJerry Jelinek         case AML_VAR_PACKAGE_OP:
107*cb565728SJerry Jelinek 
108*cb565728SJerry Jelinek             Status = AcpiDmDeferredParse (
109*cb565728SJerry Jelinek                 Op, Op->Named.Data, Op->Named.Length);
110*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
111*cb565728SJerry Jelinek             {
112*cb565728SJerry Jelinek                 return (Status);
113*cb565728SJerry Jelinek             }
114*cb565728SJerry Jelinek             break;
115*cb565728SJerry Jelinek 
116*cb565728SJerry Jelinek         /* We don't need to do anything for these deferred opcodes */
117*cb565728SJerry Jelinek 
118*cb565728SJerry Jelinek         case AML_REGION_OP:
119*cb565728SJerry Jelinek         case AML_DATA_REGION_OP:
120*cb565728SJerry Jelinek         case AML_CREATE_QWORD_FIELD_OP:
121*cb565728SJerry Jelinek         case AML_CREATE_DWORD_FIELD_OP:
122*cb565728SJerry Jelinek         case AML_CREATE_WORD_FIELD_OP:
123*cb565728SJerry Jelinek         case AML_CREATE_BYTE_FIELD_OP:
124*cb565728SJerry Jelinek         case AML_CREATE_BIT_FIELD_OP:
125*cb565728SJerry Jelinek         case AML_CREATE_FIELD_OP:
126*cb565728SJerry Jelinek         case AML_BANK_FIELD_OP:
127*cb565728SJerry Jelinek 
128*cb565728SJerry Jelinek             break;
129*cb565728SJerry Jelinek 
130*cb565728SJerry Jelinek         default:
131*cb565728SJerry Jelinek 
132*cb565728SJerry Jelinek             ACPI_ERROR ((AE_INFO, "Unhandled deferred AML opcode [0x%.4X]",
133*cb565728SJerry Jelinek                  Op->Common.AmlOpcode));
134*cb565728SJerry Jelinek             break;
135*cb565728SJerry Jelinek         }
136*cb565728SJerry Jelinek 
137*cb565728SJerry Jelinek         Op = AcpiPsGetDepthNext (Root, Op);
138*cb565728SJerry Jelinek     }
139*cb565728SJerry Jelinek 
140*cb565728SJerry Jelinek     return (AE_OK);
141*cb565728SJerry Jelinek }
142*cb565728SJerry Jelinek 
143*cb565728SJerry Jelinek 
144*cb565728SJerry Jelinek /******************************************************************************
145*cb565728SJerry Jelinek  *
146*cb565728SJerry Jelinek  * FUNCTION:    AcpiDmDeferredParse
147*cb565728SJerry Jelinek  *
148*cb565728SJerry Jelinek  * PARAMETERS:  Op                  - Root Op of the deferred opcode
149*cb565728SJerry Jelinek  *              Aml                 - Pointer to the raw AML
150*cb565728SJerry Jelinek  *              AmlLength           - Length of the AML
151*cb565728SJerry Jelinek  *
152*cb565728SJerry Jelinek  * RETURN:      Status
153*cb565728SJerry Jelinek  *
154*cb565728SJerry Jelinek  * DESCRIPTION: Parse one deferred opcode
155*cb565728SJerry Jelinek  *              (Methods, operation regions, etc.)
156*cb565728SJerry Jelinek  *
157*cb565728SJerry Jelinek  *****************************************************************************/
158*cb565728SJerry Jelinek 
159*cb565728SJerry Jelinek static ACPI_STATUS
AcpiDmDeferredParse(ACPI_PARSE_OBJECT * Op,UINT8 * Aml,UINT32 AmlLength)160*cb565728SJerry Jelinek AcpiDmDeferredParse (
161*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *Op,
162*cb565728SJerry Jelinek     UINT8                   *Aml,
163*cb565728SJerry Jelinek     UINT32                  AmlLength)
164*cb565728SJerry Jelinek {
165*cb565728SJerry Jelinek     ACPI_WALK_STATE         *WalkState;
166*cb565728SJerry Jelinek     ACPI_STATUS             Status;
167*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *SearchOp;
168*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *StartOp;
169*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *NewRootOp;
170*cb565728SJerry Jelinek     ACPI_PARSE_OBJECT       *ExtraOp;
171*cb565728SJerry Jelinek 
172*cb565728SJerry Jelinek 
173*cb565728SJerry Jelinek     ACPI_FUNCTION_TRACE (DmDeferredParse);
174*cb565728SJerry Jelinek 
175*cb565728SJerry Jelinek 
176*cb565728SJerry Jelinek     if (!Aml || !AmlLength)
177*cb565728SJerry Jelinek     {
178*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_OK);
179*cb565728SJerry Jelinek     }
180*cb565728SJerry Jelinek 
181*cb565728SJerry Jelinek     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing deferred opcode %s [%4.4s]\n",
182*cb565728SJerry Jelinek         Op->Common.AmlOpName, (char *) &Op->Named.Name));
183*cb565728SJerry Jelinek 
184*cb565728SJerry Jelinek     /* Need a new walk state to parse the AML */
185*cb565728SJerry Jelinek 
186*cb565728SJerry Jelinek     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
187*cb565728SJerry Jelinek     if (!WalkState)
188*cb565728SJerry Jelinek     {
189*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_NO_MEMORY);
190*cb565728SJerry Jelinek     }
191*cb565728SJerry Jelinek 
192*cb565728SJerry Jelinek     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
193*cb565728SJerry Jelinek         AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
194*cb565728SJerry Jelinek     if (ACPI_FAILURE (Status))
195*cb565728SJerry Jelinek     {
196*cb565728SJerry Jelinek         return_ACPI_STATUS (Status);
197*cb565728SJerry Jelinek     }
198*cb565728SJerry Jelinek 
199*cb565728SJerry Jelinek     /* Parse the AML for this deferred opcode */
200*cb565728SJerry Jelinek 
201*cb565728SJerry Jelinek     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
202*cb565728SJerry Jelinek     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
203*cb565728SJerry Jelinek     Status = AcpiPsParseAml (WalkState);
204*cb565728SJerry Jelinek 
205*cb565728SJerry Jelinek     StartOp = (Op->Common.Value.Arg)->Common.Next;
206*cb565728SJerry Jelinek     SearchOp = StartOp;
207*cb565728SJerry Jelinek     while (SearchOp)
208*cb565728SJerry Jelinek     {
209*cb565728SJerry Jelinek         SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
210*cb565728SJerry Jelinek     }
211*cb565728SJerry Jelinek 
212*cb565728SJerry Jelinek     /*
213*cb565728SJerry Jelinek      * For Buffer and Package opcodes, link the newly parsed subtree
214*cb565728SJerry Jelinek      * into the main parse tree
215*cb565728SJerry Jelinek      */
216*cb565728SJerry Jelinek     switch (Op->Common.AmlOpcode)
217*cb565728SJerry Jelinek     {
218*cb565728SJerry Jelinek     case AML_BUFFER_OP:
219*cb565728SJerry Jelinek     case AML_PACKAGE_OP:
220*cb565728SJerry Jelinek     case AML_VAR_PACKAGE_OP:
221*cb565728SJerry Jelinek 
222*cb565728SJerry Jelinek         switch (Op->Common.AmlOpcode)
223*cb565728SJerry Jelinek         {
224*cb565728SJerry Jelinek         case AML_PACKAGE_OP:
225*cb565728SJerry Jelinek 
226*cb565728SJerry Jelinek             ExtraOp = Op->Common.Value.Arg;
227*cb565728SJerry Jelinek             NewRootOp = ExtraOp->Common.Next;
228*cb565728SJerry Jelinek             ACPI_FREE (ExtraOp);
229*cb565728SJerry Jelinek             break;
230*cb565728SJerry Jelinek 
231*cb565728SJerry Jelinek         case AML_VAR_PACKAGE_OP:
232*cb565728SJerry Jelinek         case AML_BUFFER_OP:
233*cb565728SJerry Jelinek         default:
234*cb565728SJerry Jelinek 
235*cb565728SJerry Jelinek             NewRootOp = Op->Common.Value.Arg;
236*cb565728SJerry Jelinek             break;
237*cb565728SJerry Jelinek         }
238*cb565728SJerry Jelinek 
239*cb565728SJerry Jelinek         Op->Common.Value.Arg = NewRootOp->Common.Value.Arg;
240*cb565728SJerry Jelinek 
241*cb565728SJerry Jelinek         /* Must point all parents to the main tree */
242*cb565728SJerry Jelinek 
243*cb565728SJerry Jelinek         StartOp = Op;
244*cb565728SJerry Jelinek         SearchOp = StartOp;
245*cb565728SJerry Jelinek         while (SearchOp)
246*cb565728SJerry Jelinek         {
247*cb565728SJerry Jelinek             if (SearchOp->Common.Parent == NewRootOp)
248*cb565728SJerry Jelinek             {
249*cb565728SJerry Jelinek                 SearchOp->Common.Parent = Op;
250*cb565728SJerry Jelinek             }
251*cb565728SJerry Jelinek 
252*cb565728SJerry Jelinek             SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
253*cb565728SJerry Jelinek         }
254*cb565728SJerry Jelinek 
255*cb565728SJerry Jelinek         ACPI_FREE (NewRootOp);
256*cb565728SJerry Jelinek         break;
257*cb565728SJerry Jelinek 
258*cb565728SJerry Jelinek     default:
259*cb565728SJerry Jelinek 
260*cb565728SJerry Jelinek         break;
261*cb565728SJerry Jelinek     }
262*cb565728SJerry Jelinek 
263*cb565728SJerry Jelinek     return_ACPI_STATUS (AE_OK);
264*cb565728SJerry Jelinek }
265