1 /******************************************************************************
3 * Module Name: dmdeferred - Disassembly of deferred AML opcodes
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
52 #define _COMPONENT ACPI_CA_DISASSEMBLER
53 ACPI_MODULE_NAME ("dmdeferred")
56 /* Local prototypes */
60 ACPI_PARSE_OBJECT
*Op
,
65 /******************************************************************************
67 * FUNCTION: AcpiDmParseDeferredOps
69 * PARAMETERS: Root - Root of the parse tree
73 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
75 *****************************************************************************/
78 AcpiDmParseDeferredOps (
79 ACPI_PARSE_OBJECT
*Root
)
81 const ACPI_OPCODE_INFO
*OpInfo
;
82 ACPI_PARSE_OBJECT
*Op
= Root
;
86 ACPI_FUNCTION_ENTRY ();
89 /* Traverse the entire parse tree */
93 OpInfo
= AcpiPsGetOpcodeInfo (Op
->Common
.AmlOpcode
);
94 if (!(OpInfo
->Flags
& AML_DEFER
))
96 Op
= AcpiPsGetDepthNext (Root
, Op
);
100 /* Now we know we have a deferred opcode */
102 switch (Op
->Common
.AmlOpcode
)
107 case AML_VAR_PACKAGE_OP
:
109 Status
= AcpiDmDeferredParse (Op
, Op
->Named
.Data
, Op
->Named
.Length
);
110 if (ACPI_FAILURE (Status
))
116 /* We don't need to do anything for these deferred opcodes */
119 case AML_DATA_REGION_OP
:
120 case AML_CREATE_QWORD_FIELD_OP
:
121 case AML_CREATE_DWORD_FIELD_OP
:
122 case AML_CREATE_WORD_FIELD_OP
:
123 case AML_CREATE_BYTE_FIELD_OP
:
124 case AML_CREATE_BIT_FIELD_OP
:
125 case AML_CREATE_FIELD_OP
:
126 case AML_BANK_FIELD_OP
:
132 ACPI_ERROR ((AE_INFO
, "Unhandled deferred AML opcode [0x%.4X]",
133 Op
->Common
.AmlOpcode
));
137 Op
= AcpiPsGetDepthNext (Root
, Op
);
144 /******************************************************************************
146 * FUNCTION: AcpiDmDeferredParse
148 * PARAMETERS: Op - Root Op of the deferred opcode
149 * Aml - Pointer to the raw AML
150 * AmlLength - Length of the AML
154 * DESCRIPTION: Parse one deferred opcode
155 * (Methods, operation regions, etc.)
157 *****************************************************************************/
160 AcpiDmDeferredParse (
161 ACPI_PARSE_OBJECT
*Op
,
165 ACPI_WALK_STATE
*WalkState
;
167 ACPI_PARSE_OBJECT
*SearchOp
;
168 ACPI_PARSE_OBJECT
*StartOp
;
169 UINT32 BaseAmlOffset
;
170 ACPI_PARSE_OBJECT
*NewRootOp
;
171 ACPI_PARSE_OBJECT
*ExtraOp
;
174 ACPI_FUNCTION_TRACE (DmDeferredParse
);
177 if (!Aml
|| !AmlLength
)
179 return_ACPI_STATUS (AE_OK
);
182 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "Parsing deferred opcode %s [%4.4s]\n",
183 Op
->Common
.AmlOpName
, (char *) &Op
->Named
.Name
));
185 /* Need a new walk state to parse the AML */
187 WalkState
= AcpiDsCreateWalkState (0, Op
, NULL
, NULL
);
190 return_ACPI_STATUS (AE_NO_MEMORY
);
193 Status
= AcpiDsInitAmlWalk (WalkState
, Op
, NULL
, Aml
,
194 AmlLength
, NULL
, ACPI_IMODE_LOAD_PASS1
);
195 if (ACPI_FAILURE (Status
))
197 return_ACPI_STATUS (Status
);
200 /* Parse the AML for this deferred opcode */
202 WalkState
->ParseFlags
&= ~ACPI_PARSE_DELETE_TREE
;
203 WalkState
->ParseFlags
|= ACPI_PARSE_DISASSEMBLE
;
204 Status
= AcpiPsParseAml (WalkState
);
207 * We need to update all of the AML offsets, since the parser thought
208 * that the method began at offset zero. In reality, it began somewhere
209 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
210 * was just created and update the AmlOffset in each Op.
212 BaseAmlOffset
= (Op
->Common
.Value
.Arg
)->Common
.AmlOffset
+ 1;
213 StartOp
= (Op
->Common
.Value
.Arg
)->Common
.Next
;
218 SearchOp
->Common
.AmlOffset
+= BaseAmlOffset
;
219 SearchOp
= AcpiPsGetDepthNext (StartOp
, SearchOp
);
223 * For Buffer and Package opcodes, link the newly parsed subtree
224 * into the main parse tree
226 switch (Op
->Common
.AmlOpcode
)
230 case AML_VAR_PACKAGE_OP
:
232 switch (Op
->Common
.AmlOpcode
)
236 ExtraOp
= Op
->Common
.Value
.Arg
;
237 NewRootOp
= ExtraOp
->Common
.Next
;
241 case AML_VAR_PACKAGE_OP
:
245 NewRootOp
= Op
->Common
.Value
.Arg
;
249 Op
->Common
.Value
.Arg
= NewRootOp
->Common
.Value
.Arg
;
251 /* Must point all parents to the main tree */
257 if (SearchOp
->Common
.Parent
== NewRootOp
)
259 SearchOp
->Common
.Parent
= Op
;
262 SearchOp
= AcpiPsGetDepthNext (StartOp
, SearchOp
);
265 ACPI_FREE (NewRootOp
);
273 return_ACPI_STATUS (AE_OK
);