Sync ACPICA with Intel's version 20170224.
[dragonfly.git] / sys / contrib / dev / acpica / source / components / disassembler / dmdeferred.c
blob53fe2b2ce43a24ca06267bb76e1c227477f2a5f2
1 /******************************************************************************
3 * Module Name: dmdeferred - Disassembly of deferred AML opcodes
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2017, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdispat.h"
47 #include "amlcode.h"
48 #include "acdisasm.h"
49 #include "acparser.h"
51 #define _COMPONENT ACPI_CA_DISASSEMBLER
52 ACPI_MODULE_NAME ("dmdeferred")
55 /* Local prototypes */
57 static ACPI_STATUS
58 AcpiDmDeferredParse (
59 ACPI_PARSE_OBJECT *Op,
60 UINT8 *Aml,
61 UINT32 AmlLength);
64 /******************************************************************************
66 * FUNCTION: AcpiDmParseDeferredOps
68 * PARAMETERS: Root - Root of the parse tree
70 * RETURN: Status
72 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
74 *****************************************************************************/
76 ACPI_STATUS
77 AcpiDmParseDeferredOps (
78 ACPI_PARSE_OBJECT *Root)
80 const ACPI_OPCODE_INFO *OpInfo;
81 ACPI_PARSE_OBJECT *Op = Root;
82 ACPI_STATUS Status;
85 ACPI_FUNCTION_ENTRY ();
88 /* Traverse the entire parse tree */
90 while (Op)
92 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
93 if (!(OpInfo->Flags & AML_DEFER))
95 Op = AcpiPsGetDepthNext (Root, Op);
96 continue;
99 /* Now we know we have a deferred opcode */
101 switch (Op->Common.AmlOpcode)
103 case AML_METHOD_OP:
104 case AML_BUFFER_OP:
105 case AML_PACKAGE_OP:
106 case AML_VARIABLE_PACKAGE_OP:
108 Status = AcpiDmDeferredParse (
109 Op, Op->Named.Data, Op->Named.Length);
110 if (ACPI_FAILURE (Status))
112 return (Status);
114 break;
116 /* We don't need to do anything for these deferred opcodes */
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:
128 break;
130 default:
132 ACPI_ERROR ((AE_INFO, "Unhandled deferred AML opcode [0x%.4X]",
133 Op->Common.AmlOpcode));
134 break;
137 Op = AcpiPsGetDepthNext (Root, Op);
140 return (AE_OK);
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
152 * RETURN: Status
154 * DESCRIPTION: Parse one deferred opcode
155 * (Methods, operation regions, etc.)
157 *****************************************************************************/
159 static ACPI_STATUS
160 AcpiDmDeferredParse (
161 ACPI_PARSE_OBJECT *Op,
162 UINT8 *Aml,
163 UINT32 AmlLength)
165 ACPI_WALK_STATE *WalkState;
166 ACPI_STATUS Status;
167 ACPI_PARSE_OBJECT *SearchOp;
168 ACPI_PARSE_OBJECT *StartOp;
169 ACPI_PARSE_OBJECT *NewRootOp;
170 ACPI_PARSE_OBJECT *ExtraOp;
173 ACPI_FUNCTION_TRACE (DmDeferredParse);
176 if (!Aml || !AmlLength)
178 return_ACPI_STATUS (AE_OK);
181 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing deferred opcode %s [%4.4s]\n",
182 Op->Common.AmlOpName, (char *) &Op->Named.Name));
184 /* Need a new walk state to parse the AML */
186 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
187 if (!WalkState)
189 return_ACPI_STATUS (AE_NO_MEMORY);
192 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
193 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
194 if (ACPI_FAILURE (Status))
196 return_ACPI_STATUS (Status);
199 /* Parse the AML for this deferred opcode */
201 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
202 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
203 Status = AcpiPsParseAml (WalkState);
205 StartOp = (Op->Common.Value.Arg)->Common.Next;
206 SearchOp = StartOp;
207 while (SearchOp)
209 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
213 * For Buffer and Package opcodes, link the newly parsed subtree
214 * into the main parse tree
216 switch (Op->Common.AmlOpcode)
218 case AML_BUFFER_OP:
219 case AML_PACKAGE_OP:
220 case AML_VARIABLE_PACKAGE_OP:
222 switch (Op->Common.AmlOpcode)
224 case AML_PACKAGE_OP:
226 ExtraOp = Op->Common.Value.Arg;
227 NewRootOp = ExtraOp->Common.Next;
228 ACPI_FREE (ExtraOp);
229 break;
231 case AML_VARIABLE_PACKAGE_OP:
232 case AML_BUFFER_OP:
233 default:
235 NewRootOp = Op->Common.Value.Arg;
236 break;
239 Op->Common.Value.Arg = NewRootOp->Common.Value.Arg;
241 /* Must point all parents to the main tree */
243 StartOp = Op;
244 SearchOp = StartOp;
245 while (SearchOp)
247 if (SearchOp->Common.Parent == NewRootOp)
249 SearchOp->Common.Parent = Op;
252 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
255 ACPI_FREE (NewRootOp);
256 break;
258 default:
260 break;
263 return_ACPI_STATUS (AE_OK);