Deleted Added
full compact
dmdeferred.c (243044) dmdeferred.c (243347)
1/******************************************************************************
2 *
3 * Module Name: dmdeferred - Disassembly of deferred AML opcodes
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44
1/******************************************************************************
2 *
3 * Module Name: dmdeferred - Disassembly of deferred AML opcodes
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44
45#include "acpi.h"
46#include "accommon.h"
47#include "acdispat.h"
48#include "amlcode.h"
49#include "acdisasm.h"
50#include "acparser.h"
45#include <contrib/dev/acpica/include/acpi.h>
46#include <contrib/dev/acpica/include/accommon.h>
47#include <contrib/dev/acpica/include/acdispat.h>
48#include <contrib/dev/acpica/include/amlcode.h>
49#include <contrib/dev/acpica/include/acdisasm.h>
50#include <contrib/dev/acpica/include/acparser.h>
51
52#define _COMPONENT ACPI_CA_DISASSEMBLER
53 ACPI_MODULE_NAME ("dmdeferred")
54
55
56/* Local prototypes */
57
58static ACPI_STATUS
59AcpiDmDeferredParse (
60 ACPI_PARSE_OBJECT *Op,
61 UINT8 *Aml,
62 UINT32 AmlLength);
63
64
65/******************************************************************************
66 *
67 * FUNCTION: AcpiDmParseDeferredOps
68 *
69 * PARAMETERS: Root - Root of the parse tree
70 *
71 * RETURN: Status
72 *
73 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
74 *
75 *****************************************************************************/
76
77ACPI_STATUS
78AcpiDmParseDeferredOps (
79 ACPI_PARSE_OBJECT *Root)
80{
81 const ACPI_OPCODE_INFO *OpInfo;
82 ACPI_PARSE_OBJECT *Op = Root;
83 ACPI_STATUS Status;
84
85
86 ACPI_FUNCTION_NAME (DmParseDeferredOps);
87
88
89 /* Traverse the entire parse tree */
90
91 while (Op)
92 {
93 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
94 if (!(OpInfo->Flags & AML_DEFER))
95 {
96 Op = AcpiPsGetDepthNext (Root, Op);
97 continue;
98 }
99
100 /* Now we know we have a deferred opcode */
101
102 switch (Op->Common.AmlOpcode)
103 {
104 case AML_METHOD_OP:
105 case AML_BUFFER_OP:
106 case AML_PACKAGE_OP:
107 case AML_VAR_PACKAGE_OP:
108
109 Status = AcpiDmDeferredParse (Op, Op->Named.Data, Op->Named.Length);
110 if (ACPI_FAILURE (Status))
111 {
112 return (Status);
113 }
114 break;
115
116 /* We don't need to do anything for these deferred opcodes */
117
118 case AML_REGION_OP:
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:
127
128 break;
129
130 default:
131 ACPI_ERROR ((AE_INFO, "Unhandled deferred AML opcode [0x%.4X]",
132 Op->Common.AmlOpcode));
133 break;
134 }
135
136 Op = AcpiPsGetDepthNext (Root, Op);
137 }
138
139 return (AE_OK);
140}
141
142
143/******************************************************************************
144 *
145 * FUNCTION: AcpiDmDeferredParse
146 *
147 * PARAMETERS: Op - Root Op of the deferred opcode
148 * Aml - Pointer to the raw AML
149 * AmlLength - Length of the AML
150 *
151 * RETURN: Status
152 *
153 * DESCRIPTION: Parse one deferred opcode
154 * (Methods, operation regions, etc.)
155 *
156 *****************************************************************************/
157
158static ACPI_STATUS
159AcpiDmDeferredParse (
160 ACPI_PARSE_OBJECT *Op,
161 UINT8 *Aml,
162 UINT32 AmlLength)
163{
164 ACPI_WALK_STATE *WalkState;
165 ACPI_STATUS Status;
166 ACPI_PARSE_OBJECT *SearchOp;
167 ACPI_PARSE_OBJECT *StartOp;
168 UINT32 BaseAmlOffset;
169 ACPI_PARSE_OBJECT *NewRootOp;
170 ACPI_PARSE_OBJECT *ExtraOp;
171
172
173 ACPI_FUNCTION_TRACE (DmDeferredParse);
174
175
176 if (!Aml || !AmlLength)
177 {
178 return_ACPI_STATUS (AE_OK);
179 }
180
181 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing deferred opcode %s [%4.4s]\n",
182 Op->Common.AmlOpName, (char *) &Op->Named.Name));
183
184 /* Need a new walk state to parse the AML */
185
186 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
187 if (!WalkState)
188 {
189 return_ACPI_STATUS (AE_NO_MEMORY);
190 }
191
192 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
193 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
194 if (ACPI_FAILURE (Status))
195 {
196 return_ACPI_STATUS (Status);
197 }
198
199 /* Parse the AML for this deferred opcode */
200
201 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
202 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
203 Status = AcpiPsParseAml (WalkState);
204
205 /*
206 * We need to update all of the AML offsets, since the parser thought
207 * that the method began at offset zero. In reality, it began somewhere
208 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
209 * was just created and update the AmlOffset in each Op.
210 */
211 BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
212 StartOp = (Op->Common.Value.Arg)->Common.Next;
213 SearchOp = StartOp;
214
215 while (SearchOp)
216 {
217 SearchOp->Common.AmlOffset += BaseAmlOffset;
218 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
219 }
220
221 /*
222 * For Buffer and Package opcodes, link the newly parsed subtree
223 * into the main parse tree
224 */
225 switch (Op->Common.AmlOpcode)
226 {
227 case AML_BUFFER_OP:
228 case AML_PACKAGE_OP:
229 case AML_VAR_PACKAGE_OP:
230
231 switch (Op->Common.AmlOpcode)
232 {
233 case AML_PACKAGE_OP:
234
235 ExtraOp = Op->Common.Value.Arg;
236 NewRootOp = ExtraOp->Common.Next;
237 ACPI_FREE (ExtraOp);
238 break;
239
240 case AML_VAR_PACKAGE_OP:
241 case AML_BUFFER_OP:
242 default:
243
244 NewRootOp = Op->Common.Value.Arg;
245 break;
246 }
247
248 Op->Common.Value.Arg = NewRootOp->Common.Value.Arg;
249
250 /* Must point all parents to the main tree */
251
252 StartOp = Op;
253 SearchOp = StartOp;
254 while (SearchOp)
255 {
256 if (SearchOp->Common.Parent == NewRootOp)
257 {
258 SearchOp->Common.Parent = Op;
259 }
260
261 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
262 }
263
264 ACPI_FREE (NewRootOp);
265 break;
266
267 default:
268 break;
269 }
270
271 return_ACPI_STATUS (AE_OK);
272}
51
52#define _COMPONENT ACPI_CA_DISASSEMBLER
53 ACPI_MODULE_NAME ("dmdeferred")
54
55
56/* Local prototypes */
57
58static ACPI_STATUS
59AcpiDmDeferredParse (
60 ACPI_PARSE_OBJECT *Op,
61 UINT8 *Aml,
62 UINT32 AmlLength);
63
64
65/******************************************************************************
66 *
67 * FUNCTION: AcpiDmParseDeferredOps
68 *
69 * PARAMETERS: Root - Root of the parse tree
70 *
71 * RETURN: Status
72 *
73 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
74 *
75 *****************************************************************************/
76
77ACPI_STATUS
78AcpiDmParseDeferredOps (
79 ACPI_PARSE_OBJECT *Root)
80{
81 const ACPI_OPCODE_INFO *OpInfo;
82 ACPI_PARSE_OBJECT *Op = Root;
83 ACPI_STATUS Status;
84
85
86 ACPI_FUNCTION_NAME (DmParseDeferredOps);
87
88
89 /* Traverse the entire parse tree */
90
91 while (Op)
92 {
93 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
94 if (!(OpInfo->Flags & AML_DEFER))
95 {
96 Op = AcpiPsGetDepthNext (Root, Op);
97 continue;
98 }
99
100 /* Now we know we have a deferred opcode */
101
102 switch (Op->Common.AmlOpcode)
103 {
104 case AML_METHOD_OP:
105 case AML_BUFFER_OP:
106 case AML_PACKAGE_OP:
107 case AML_VAR_PACKAGE_OP:
108
109 Status = AcpiDmDeferredParse (Op, Op->Named.Data, Op->Named.Length);
110 if (ACPI_FAILURE (Status))
111 {
112 return (Status);
113 }
114 break;
115
116 /* We don't need to do anything for these deferred opcodes */
117
118 case AML_REGION_OP:
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:
127
128 break;
129
130 default:
131 ACPI_ERROR ((AE_INFO, "Unhandled deferred AML opcode [0x%.4X]",
132 Op->Common.AmlOpcode));
133 break;
134 }
135
136 Op = AcpiPsGetDepthNext (Root, Op);
137 }
138
139 return (AE_OK);
140}
141
142
143/******************************************************************************
144 *
145 * FUNCTION: AcpiDmDeferredParse
146 *
147 * PARAMETERS: Op - Root Op of the deferred opcode
148 * Aml - Pointer to the raw AML
149 * AmlLength - Length of the AML
150 *
151 * RETURN: Status
152 *
153 * DESCRIPTION: Parse one deferred opcode
154 * (Methods, operation regions, etc.)
155 *
156 *****************************************************************************/
157
158static ACPI_STATUS
159AcpiDmDeferredParse (
160 ACPI_PARSE_OBJECT *Op,
161 UINT8 *Aml,
162 UINT32 AmlLength)
163{
164 ACPI_WALK_STATE *WalkState;
165 ACPI_STATUS Status;
166 ACPI_PARSE_OBJECT *SearchOp;
167 ACPI_PARSE_OBJECT *StartOp;
168 UINT32 BaseAmlOffset;
169 ACPI_PARSE_OBJECT *NewRootOp;
170 ACPI_PARSE_OBJECT *ExtraOp;
171
172
173 ACPI_FUNCTION_TRACE (DmDeferredParse);
174
175
176 if (!Aml || !AmlLength)
177 {
178 return_ACPI_STATUS (AE_OK);
179 }
180
181 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing deferred opcode %s [%4.4s]\n",
182 Op->Common.AmlOpName, (char *) &Op->Named.Name));
183
184 /* Need a new walk state to parse the AML */
185
186 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
187 if (!WalkState)
188 {
189 return_ACPI_STATUS (AE_NO_MEMORY);
190 }
191
192 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
193 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
194 if (ACPI_FAILURE (Status))
195 {
196 return_ACPI_STATUS (Status);
197 }
198
199 /* Parse the AML for this deferred opcode */
200
201 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
202 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
203 Status = AcpiPsParseAml (WalkState);
204
205 /*
206 * We need to update all of the AML offsets, since the parser thought
207 * that the method began at offset zero. In reality, it began somewhere
208 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
209 * was just created and update the AmlOffset in each Op.
210 */
211 BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
212 StartOp = (Op->Common.Value.Arg)->Common.Next;
213 SearchOp = StartOp;
214
215 while (SearchOp)
216 {
217 SearchOp->Common.AmlOffset += BaseAmlOffset;
218 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
219 }
220
221 /*
222 * For Buffer and Package opcodes, link the newly parsed subtree
223 * into the main parse tree
224 */
225 switch (Op->Common.AmlOpcode)
226 {
227 case AML_BUFFER_OP:
228 case AML_PACKAGE_OP:
229 case AML_VAR_PACKAGE_OP:
230
231 switch (Op->Common.AmlOpcode)
232 {
233 case AML_PACKAGE_OP:
234
235 ExtraOp = Op->Common.Value.Arg;
236 NewRootOp = ExtraOp->Common.Next;
237 ACPI_FREE (ExtraOp);
238 break;
239
240 case AML_VAR_PACKAGE_OP:
241 case AML_BUFFER_OP:
242 default:
243
244 NewRootOp = Op->Common.Value.Arg;
245 break;
246 }
247
248 Op->Common.Value.Arg = NewRootOp->Common.Value.Arg;
249
250 /* Must point all parents to the main tree */
251
252 StartOp = Op;
253 SearchOp = StartOp;
254 while (SearchOp)
255 {
256 if (SearchOp->Common.Parent == NewRootOp)
257 {
258 SearchOp->Common.Parent = Op;
259 }
260
261 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
262 }
263
264 ACPI_FREE (NewRootOp);
265 break;
266
267 default:
268 break;
269 }
270
271 return_ACPI_STATUS (AE_OK);
272}