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