Deleted Added
full compact
dsopcode.c (131440) dsopcode.c (151600)
1/******************************************************************************
2 *
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
4 * "control" opcodes
5 * $Revision: 95 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#define __DSOPCODE_C__
119
1/******************************************************************************
2 *
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
4 * "control" opcodes
5 * $Revision: 95 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#define __DSOPCODE_C__
119
120#include "acpi.h"
121#include "acparser.h"
122#include "amlcode.h"
123#include "acdispat.h"
124#include "acinterp.h"
125#include "acnamesp.h"
126#include "acevents.h"
120#include <contrib/dev/acpica/acpi.h>
121#include <contrib/dev/acpica/acparser.h>
122#include <contrib/dev/acpica/amlcode.h>
123#include <contrib/dev/acpica/acdispat.h>
124#include <contrib/dev/acpica/acinterp.h>
125#include <contrib/dev/acpica/acnamesp.h>
126#include <contrib/dev/acpica/acevents.h>
127
128#define _COMPONENT ACPI_DISPATCHER
129 ACPI_MODULE_NAME ("dsopcode")
130
131
132/*****************************************************************************
133 *
134 * FUNCTION: AcpiDsExecuteArguments
135 *
136 * PARAMETERS: Node - Parent NS node
137 * AmlLength - Length of executable AML
138 * AmlStart - Pointer to the AML
139 *
140 * RETURN: Status.
141 *
142 * DESCRIPTION: Late (deferred) execution of region or field arguments
143 *
144 ****************************************************************************/
145
146ACPI_STATUS
147AcpiDsExecuteArguments (
148 ACPI_NAMESPACE_NODE *Node,
149 ACPI_NAMESPACE_NODE *ScopeNode,
150 UINT32 AmlLength,
151 UINT8 *AmlStart)
152{
153 ACPI_STATUS Status;
154 ACPI_PARSE_OBJECT *Op;
155 ACPI_WALK_STATE *WalkState;
156
157
158 ACPI_FUNCTION_TRACE ("DsExecuteArguments");
159
160
161 /*
162 * Allocate a new parser op to be the root of the parsed tree
163 */
164 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
165 if (!Op)
166 {
167 return_ACPI_STATUS (AE_NO_MEMORY);
168 }
169
170 /* Save the Node for use in AcpiPsParseAml */
171
172 Op->Common.Node = ScopeNode;
173
174 /* Create and initialize a new parser state */
175
176 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
177 if (!WalkState)
178 {
179 return_ACPI_STATUS (AE_NO_MEMORY);
180 }
181
182 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
183 AmlLength, NULL, 1);
184 if (ACPI_FAILURE (Status))
185 {
186 AcpiDsDeleteWalkState (WalkState);
187 return_ACPI_STATUS (Status);
188 }
189
190 /* Mark this parse as a deferred opcode */
191
192 WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
193 WalkState->DeferredNode = Node;
194
195 /* Pass1: Parse the entire declaration */
196
197 Status = AcpiPsParseAml (WalkState);
198 if (ACPI_FAILURE (Status))
199 {
200 AcpiPsDeleteParseTree (Op);
201 return_ACPI_STATUS (Status);
202 }
203
204 /* Get and init the Op created above */
205
206 Op->Common.Node = Node;
207 AcpiPsDeleteParseTree (Op);
208
209 /* Evaluate the deferred arguments */
210
211 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
212 if (!Op)
213 {
214 return_ACPI_STATUS (AE_NO_MEMORY);
215 }
216
217 Op->Common.Node = ScopeNode;
218
219 /* Create and initialize a new parser state */
220
221 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
222 if (!WalkState)
223 {
224 return_ACPI_STATUS (AE_NO_MEMORY);
225 }
226
227 /* Execute the opcode and arguments */
228
229 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
230 AmlLength, NULL, 3);
231 if (ACPI_FAILURE (Status))
232 {
233 AcpiDsDeleteWalkState (WalkState);
234 return_ACPI_STATUS (Status);
235 }
236
237 /* Mark this execution as a deferred opcode */
238
239 WalkState->DeferredNode = Node;
240 Status = AcpiPsParseAml (WalkState);
241 AcpiPsDeleteParseTree (Op);
242 return_ACPI_STATUS (Status);
243}
244
245
246/*****************************************************************************
247 *
248 * FUNCTION: AcpiDsGetBufferFieldArguments
249 *
250 * PARAMETERS: ObjDesc - A valid BufferField object
251 *
252 * RETURN: Status.
253 *
254 * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
255 * evaluation of these field attributes.
256 *
257 ****************************************************************************/
258
259ACPI_STATUS
260AcpiDsGetBufferFieldArguments (
261 ACPI_OPERAND_OBJECT *ObjDesc)
262{
263 ACPI_OPERAND_OBJECT *ExtraDesc;
264 ACPI_NAMESPACE_NODE *Node;
265 ACPI_STATUS Status;
266
267
268 ACPI_FUNCTION_TRACE_PTR ("DsGetBufferFieldArguments", ObjDesc);
269
270
271 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
272 {
273 return_ACPI_STATUS (AE_OK);
274 }
275
276 /* Get the AML pointer (method object) and BufferField node */
277
278 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
279 Node = ObjDesc->BufferField.Node;
280
281 ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_BUFFER_FIELD, Node, NULL));
282 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
283 AcpiUtGetNodeName (Node)));
284
285 /* Execute the AML code for the TermArg arguments */
286
287 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
288 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
289 return_ACPI_STATUS (Status);
290}
291
292
293/*****************************************************************************
294 *
295 * FUNCTION: AcpiDsGetBufferArguments
296 *
297 * PARAMETERS: ObjDesc - A valid Buffer object
298 *
299 * RETURN: Status.
300 *
301 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
302 * the late evaluation of these attributes.
303 *
304 ****************************************************************************/
305
306ACPI_STATUS
307AcpiDsGetBufferArguments (
308 ACPI_OPERAND_OBJECT *ObjDesc)
309{
310 ACPI_NAMESPACE_NODE *Node;
311 ACPI_STATUS Status;
312
313
314 ACPI_FUNCTION_TRACE_PTR ("DsGetBufferArguments", ObjDesc);
315
316
317 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
318 {
319 return_ACPI_STATUS (AE_OK);
320 }
321
322 /* Get the Buffer node */
323
324 Node = ObjDesc->Buffer.Node;
325 if (!Node)
326 {
327 ACPI_REPORT_ERROR ((
328 "No pointer back to NS node in buffer obj %p\n", ObjDesc));
329 return_ACPI_STATUS (AE_AML_INTERNAL);
330 }
331
332 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
333
334 /* Execute the AML code for the TermArg arguments */
335
336 Status = AcpiDsExecuteArguments (Node, Node,
337 ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
338 return_ACPI_STATUS (Status);
339}
340
341
342/*****************************************************************************
343 *
344 * FUNCTION: AcpiDsGetPackageArguments
345 *
346 * PARAMETERS: ObjDesc - A valid Package object
347 *
348 * RETURN: Status.
349 *
350 * DESCRIPTION: Get Package length and initializer byte list. This implements
351 * the late evaluation of these attributes.
352 *
353 ****************************************************************************/
354
355ACPI_STATUS
356AcpiDsGetPackageArguments (
357 ACPI_OPERAND_OBJECT *ObjDesc)
358{
359 ACPI_NAMESPACE_NODE *Node;
360 ACPI_STATUS Status;
361
362
363 ACPI_FUNCTION_TRACE_PTR ("DsGetPackageArguments", ObjDesc);
364
365
366 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
367 {
368 return_ACPI_STATUS (AE_OK);
369 }
370
371 /* Get the Package node */
372
373 Node = ObjDesc->Package.Node;
374 if (!Node)
375 {
376 ACPI_REPORT_ERROR ((
377 "No pointer back to NS node in package %p\n", ObjDesc));
378 return_ACPI_STATUS (AE_AML_INTERNAL);
379 }
380
381 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
382
383 /* Execute the AML code for the TermArg arguments */
384
385 Status = AcpiDsExecuteArguments (Node, Node,
386 ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
387 return_ACPI_STATUS (Status);
388}
389
390
391/*****************************************************************************
392 *
393 * FUNCTION: AcpiDsGetRegionArguments
394 *
395 * PARAMETERS: ObjDesc - A valid region object
396 *
397 * RETURN: Status.
398 *
399 * DESCRIPTION: Get region address and length. This implements the late
400 * evaluation of these region attributes.
401 *
402 ****************************************************************************/
403
404ACPI_STATUS
405AcpiDsGetRegionArguments (
406 ACPI_OPERAND_OBJECT *ObjDesc)
407{
408 ACPI_NAMESPACE_NODE *Node;
409 ACPI_STATUS Status;
410 ACPI_OPERAND_OBJECT *ExtraDesc;
411
412
413 ACPI_FUNCTION_TRACE_PTR ("DsGetRegionArguments", ObjDesc);
414
415
416 if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
417 {
418 return_ACPI_STATUS (AE_OK);
419 }
420
421 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
422 if (!ExtraDesc)
423 {
424 return_ACPI_STATUS (AE_NOT_EXIST);
425 }
426
427 /* Get the Region node */
428
429 Node = ObjDesc->Region.Node;
430
431 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (ACPI_TYPE_REGION, Node, NULL));
432
433 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
434 AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
435
436 /* Execute the argument AML */
437
438 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
439 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
440 return_ACPI_STATUS (Status);
441}
442
443
444/*****************************************************************************
445 *
446 * FUNCTION: AcpiDsInitializeRegion
447 *
448 * PARAMETERS: Op - A valid region Op object
449 *
450 * RETURN: Status
451 *
452 * DESCRIPTION: Front end to EvInitializeRegion
453 *
454 ****************************************************************************/
455
456ACPI_STATUS
457AcpiDsInitializeRegion (
458 ACPI_HANDLE ObjHandle)
459{
460 ACPI_OPERAND_OBJECT *ObjDesc;
461 ACPI_STATUS Status;
462
463
464 ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
465
466 /* Namespace is NOT locked */
467
468 Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
469 return (Status);
470}
471
472
473/*****************************************************************************
474 *
475 * FUNCTION: AcpiDsInitBufferField
476 *
477 * PARAMETERS: AmlOpcode - CreateXxxField
478 * ObjDesc - BufferField object
479 * BufferDesc - Host Buffer
480 * OffsetDesc - Offset into buffer
481 * Length - Length of field (CREATE_FIELD_OP only)
482 * Result - Where to store the result
483 *
484 * RETURN: Status
485 *
486 * DESCRIPTION: Perform actual initialization of a buffer field
487 *
488 ****************************************************************************/
489
490ACPI_STATUS
491AcpiDsInitBufferField (
492 UINT16 AmlOpcode,
493 ACPI_OPERAND_OBJECT *ObjDesc,
494 ACPI_OPERAND_OBJECT *BufferDesc,
495 ACPI_OPERAND_OBJECT *OffsetDesc,
496 ACPI_OPERAND_OBJECT *LengthDesc,
497 ACPI_OPERAND_OBJECT *ResultDesc)
498{
499 UINT32 Offset;
500 UINT32 BitOffset;
501 UINT32 BitCount;
502 UINT8 FieldFlags;
503 ACPI_STATUS Status;
504
505
506 ACPI_FUNCTION_TRACE_PTR ("DsInitBufferField", ObjDesc);
507
508
509 /* Host object must be a Buffer */
510
511 if (ACPI_GET_OBJECT_TYPE (BufferDesc) != ACPI_TYPE_BUFFER)
512 {
513 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
514 "Target of Create Field is not a Buffer object - %s\n",
515 AcpiUtGetObjectTypeName (BufferDesc)));
516
517 Status = AE_AML_OPERAND_TYPE;
518 goto Cleanup;
519 }
520
521 /*
522 * The last parameter to all of these opcodes (ResultDesc) started
523 * out as a NameString, and should therefore now be a NS node
524 * after resolution in AcpiExResolveOperands().
525 */
526 if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
527 {
528 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n",
529 AcpiPsGetOpcodeName (AmlOpcode), AcpiUtGetDescriptorName (ResultDesc)));
530
531 Status = AE_AML_OPERAND_TYPE;
532 goto Cleanup;
533 }
534
535 Offset = (UINT32) OffsetDesc->Integer.Value;
536
537 /*
538 * Setup the Bit offsets and counts, according to the opcode
539 */
540 switch (AmlOpcode)
541 {
542 case AML_CREATE_FIELD_OP:
543
544 /* Offset is in bits, count is in bits */
545
546 BitOffset = Offset;
547 BitCount = (UINT32) LengthDesc->Integer.Value;
548 FieldFlags = AML_FIELD_ACCESS_BYTE;
549 break;
550
551 case AML_CREATE_BIT_FIELD_OP:
552
553 /* Offset is in bits, Field is one bit */
554
555 BitOffset = Offset;
556 BitCount = 1;
557 FieldFlags = AML_FIELD_ACCESS_BYTE;
558 break;
559
560 case AML_CREATE_BYTE_FIELD_OP:
561
562 /* Offset is in bytes, field is one byte */
563
564 BitOffset = 8 * Offset;
565 BitCount = 8;
566 FieldFlags = AML_FIELD_ACCESS_BYTE;
567 break;
568
569 case AML_CREATE_WORD_FIELD_OP:
570
571 /* Offset is in bytes, field is one word */
572
573 BitOffset = 8 * Offset;
574 BitCount = 16;
575 FieldFlags = AML_FIELD_ACCESS_WORD;
576 break;
577
578 case AML_CREATE_DWORD_FIELD_OP:
579
580 /* Offset is in bytes, field is one dword */
581
582 BitOffset = 8 * Offset;
583 BitCount = 32;
584 FieldFlags = AML_FIELD_ACCESS_DWORD;
585 break;
586
587 case AML_CREATE_QWORD_FIELD_OP:
588
589 /* Offset is in bytes, field is one qword */
590
591 BitOffset = 8 * Offset;
592 BitCount = 64;
593 FieldFlags = AML_FIELD_ACCESS_QWORD;
594 break;
595
596 default:
597
598 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
599 "Unknown field creation opcode %02x\n",
600 AmlOpcode));
601 Status = AE_AML_BAD_OPCODE;
602 goto Cleanup;
603 }
604
605 /* Entire field must fit within the current length of the buffer */
606
607 if ((BitOffset + BitCount) >
608 (8 * (UINT32) BufferDesc->Buffer.Length))
609 {
610 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
611 "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
612 AcpiUtGetNodeName (ResultDesc),
613 BitOffset + BitCount,
614 AcpiUtGetNodeName (BufferDesc->Buffer.Node),
615 8 * (UINT32) BufferDesc->Buffer.Length));
616 Status = AE_AML_BUFFER_LIMIT;
617 goto Cleanup;
618 }
619
620 /*
621 * Initialize areas of the field object that are common to all fields
622 * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
623 */
624 Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags, 0,
625 BitOffset, BitCount);
626 if (ACPI_FAILURE (Status))
627 {
628 goto Cleanup;
629 }
630
631 ObjDesc->BufferField.BufferObj = BufferDesc;
632
633 /* Reference count for BufferDesc inherits ObjDesc count */
634
635 BufferDesc->Common.ReferenceCount = (UINT16) (BufferDesc->Common.ReferenceCount +
636 ObjDesc->Common.ReferenceCount);
637
638
639Cleanup:
640
641 /* Always delete the operands */
642
643 AcpiUtRemoveReference (OffsetDesc);
644 AcpiUtRemoveReference (BufferDesc);
645
646 if (AmlOpcode == AML_CREATE_FIELD_OP)
647 {
648 AcpiUtRemoveReference (LengthDesc);
649 }
650
651 /* On failure, delete the result descriptor */
652
653 if (ACPI_FAILURE (Status))
654 {
655 AcpiUtRemoveReference (ResultDesc); /* Result descriptor */
656 }
657 else
658 {
659 /* Now the address and length are valid for this BufferField */
660
661 ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
662 }
663
664 return_ACPI_STATUS (Status);
665}
666
667
668/*****************************************************************************
669 *
670 * FUNCTION: AcpiDsEvalBufferFieldOperands
671 *
672 * PARAMETERS: WalkState - Current walk
673 * Op - A valid BufferField Op object
674 *
675 * RETURN: Status
676 *
677 * DESCRIPTION: Get BufferField Buffer and Index
678 * Called from AcpiDsExecEndOp during BufferField parse tree walk
679 *
680 ****************************************************************************/
681
682ACPI_STATUS
683AcpiDsEvalBufferFieldOperands (
684 ACPI_WALK_STATE *WalkState,
685 ACPI_PARSE_OBJECT *Op)
686{
687 ACPI_STATUS Status;
688 ACPI_OPERAND_OBJECT *ObjDesc;
689 ACPI_NAMESPACE_NODE *Node;
690 ACPI_PARSE_OBJECT *NextOp;
691
692
693 ACPI_FUNCTION_TRACE_PTR ("DsEvalBufferFieldOperands", Op);
694
695
696 /*
697 * This is where we evaluate the address and length fields of the
698 * CreateXxxField declaration
699 */
700 Node = Op->Common.Node;
701
702 /* NextOp points to the op that holds the Buffer */
703
704 NextOp = Op->Common.Value.Arg;
705
706 /* Evaluate/create the address and length operands */
707
708 Status = AcpiDsCreateOperands (WalkState, NextOp);
709 if (ACPI_FAILURE (Status))
710 {
711 return_ACPI_STATUS (Status);
712 }
713
714 ObjDesc = AcpiNsGetAttachedObject (Node);
715 if (!ObjDesc)
716 {
717 return_ACPI_STATUS (AE_NOT_EXIST);
718 }
719
720 /* Resolve the operands */
721
722 Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
723 ACPI_WALK_OPERANDS, WalkState);
724
725 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
726 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
727 WalkState->NumOperands, "after AcpiExResolveOperands");
728
729 if (ACPI_FAILURE (Status))
730 {
731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
732 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
733
734 return_ACPI_STATUS (Status);
735 }
736
737 /* Initialize the Buffer Field */
738
739 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
740 {
741 /* NOTE: Slightly different operands for this opcode */
742
743 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
744 WalkState->Operands[0], WalkState->Operands[1],
745 WalkState->Operands[2], WalkState->Operands[3]);
746 }
747 else
748 {
749 /* All other, CreateXxxField opcodes */
750
751 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
752 WalkState->Operands[0], WalkState->Operands[1],
753 NULL, WalkState->Operands[2]);
754 }
755
756 return_ACPI_STATUS (Status);
757}
758
759
760/*****************************************************************************
761 *
762 * FUNCTION: AcpiDsEvalRegionOperands
763 *
764 * PARAMETERS: WalkState - Current walk
765 * Op - A valid region Op object
766 *
767 * RETURN: Status
768 *
769 * DESCRIPTION: Get region address and length
770 * Called from AcpiDsExecEndOp during OpRegion parse tree walk
771 *
772 ****************************************************************************/
773
774ACPI_STATUS
775AcpiDsEvalRegionOperands (
776 ACPI_WALK_STATE *WalkState,
777 ACPI_PARSE_OBJECT *Op)
778{
779 ACPI_STATUS Status;
780 ACPI_OPERAND_OBJECT *ObjDesc;
781 ACPI_OPERAND_OBJECT *OperandDesc;
782 ACPI_NAMESPACE_NODE *Node;
783 ACPI_PARSE_OBJECT *NextOp;
784
785
786 ACPI_FUNCTION_TRACE_PTR ("DsEvalRegionOperands", Op);
787
788
789 /*
790 * This is where we evaluate the address and length fields of the OpRegion declaration
791 */
792 Node = Op->Common.Node;
793
794 /* NextOp points to the op that holds the SpaceID */
795
796 NextOp = Op->Common.Value.Arg;
797
798 /* NextOp points to address op */
799
800 NextOp = NextOp->Common.Next;
801
802 /* Evaluate/create the address and length operands */
803
804 Status = AcpiDsCreateOperands (WalkState, NextOp);
805 if (ACPI_FAILURE (Status))
806 {
807 return_ACPI_STATUS (Status);
808 }
809
810 /* Resolve the length and address operands to numbers */
811
812 Status = AcpiExResolveOperands (Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
813 if (ACPI_FAILURE (Status))
814 {
815 return_ACPI_STATUS (Status);
816 }
817
818 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
819 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
820 1, "after AcpiExResolveOperands");
821
822 ObjDesc = AcpiNsGetAttachedObject (Node);
823 if (!ObjDesc)
824 {
825 return_ACPI_STATUS (AE_NOT_EXIST);
826 }
827
828 /*
829 * Get the length operand and save it
830 * (at Top of stack)
831 */
832 OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
833
834 ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
835 AcpiUtRemoveReference (OperandDesc);
836
837 /*
838 * Get the address and save it
839 * (at top of stack - 1)
840 */
841 OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
842
843 ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS) OperandDesc->Integer.Value;
844 AcpiUtRemoveReference (OperandDesc);
845
846 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
847 ObjDesc,
848 ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
849 ObjDesc->Region.Length));
850
851 /* Now the address and length are valid for this opregion */
852
853 ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
854
855 return_ACPI_STATUS (Status);
856}
857
858
859/*****************************************************************************
860 *
861 * FUNCTION: AcpiDsEvalDataObjectOperands
862 *
863 * PARAMETERS: WalkState - Current walk
864 * Op - A valid DataObject Op object
865 * ObjDesc - DataObject
866 *
867 * RETURN: Status
868 *
869 * DESCRIPTION: Get the operands and complete the following data objec types:
870 * Buffer
871 * Package
872 *
873 ****************************************************************************/
874
875ACPI_STATUS
876AcpiDsEvalDataObjectOperands (
877 ACPI_WALK_STATE *WalkState,
878 ACPI_PARSE_OBJECT *Op,
879 ACPI_OPERAND_OBJECT *ObjDesc)
880{
881 ACPI_STATUS Status;
882 ACPI_OPERAND_OBJECT *ArgDesc;
883 UINT32 Length;
884
885
886 ACPI_FUNCTION_TRACE ("DsEvalDataObjectOperands");
887
888
889 /* The first operand (for all of these data objects) is the length */
890
891 Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
892 if (ACPI_FAILURE (Status))
893 {
894 return_ACPI_STATUS (Status);
895 }
896
897 Status = AcpiExResolveOperands (WalkState->Opcode,
898 &(WalkState->Operands [WalkState->NumOperands -1]),
899 WalkState);
900 if (ACPI_FAILURE (Status))
901 {
902 return_ACPI_STATUS (Status);
903 }
904
905 /* Extract length operand */
906
907 ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
908 Length = (UINT32) ArgDesc->Integer.Value;
909
910 /* Cleanup for length operand */
911
912 Status = AcpiDsObjStackPop (1, WalkState);
913 if (ACPI_FAILURE (Status))
914 {
915 return_ACPI_STATUS (Status);
916 }
917
918 AcpiUtRemoveReference (ArgDesc);
919
920 /*
921 * Create the actual data object
922 */
923 switch (Op->Common.AmlOpcode)
924 {
925 case AML_BUFFER_OP:
926
927 Status = AcpiDsBuildInternalBufferObj (WalkState, Op, Length, &ObjDesc);
928 break;
929
930 case AML_PACKAGE_OP:
931 case AML_VAR_PACKAGE_OP:
932
933 Status = AcpiDsBuildInternalPackageObj (WalkState, Op, Length, &ObjDesc);
934 break;
935
936 default:
937 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
938 }
939
940 if (ACPI_SUCCESS (Status))
941 {
942 /*
943 * Return the object in the WalkState, unless the parent is a package --
944 * in this case, the return object will be stored in the parse tree
945 * for the package.
946 */
947 if ((!Op->Common.Parent) ||
948 ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
949 (Op->Common.Parent->Common.AmlOpcode != AML_VAR_PACKAGE_OP) &&
950 (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
951 {
952 WalkState->ResultObj = ObjDesc;
953 }
954 }
955
956 return_ACPI_STATUS (Status);
957}
958
959
960/*******************************************************************************
961 *
962 * FUNCTION: AcpiDsExecBeginControlOp
963 *
964 * PARAMETERS: WalkList - The list that owns the walk stack
965 * Op - The control Op
966 *
967 * RETURN: Status
968 *
969 * DESCRIPTION: Handles all control ops encountered during control method
970 * execution.
971 *
972 ******************************************************************************/
973
974ACPI_STATUS
975AcpiDsExecBeginControlOp (
976 ACPI_WALK_STATE *WalkState,
977 ACPI_PARSE_OBJECT *Op)
978{
979 ACPI_STATUS Status = AE_OK;
980 ACPI_GENERIC_STATE *ControlState;
981
982
983 ACPI_FUNCTION_NAME ("DsExecBeginControlOp");
984
985
986 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", Op,
987 Op->Common.AmlOpcode, WalkState));
988
989 switch (Op->Common.AmlOpcode)
990 {
991 case AML_IF_OP:
992 case AML_WHILE_OP:
993
994 /*
995 * IF/WHILE: Create a new control state to manage these
996 * constructs. We need to manage these as a stack, in order
997 * to handle nesting.
998 */
999 ControlState = AcpiUtCreateControlState ();
1000 if (!ControlState)
1001 {
1002 Status = AE_NO_MEMORY;
1003 break;
1004 }
1005 /*
1006 * Save a pointer to the predicate for multiple executions
1007 * of a loop
1008 */
1009 ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
1010 ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
1011 ControlState->Control.Opcode = Op->Common.AmlOpcode;
1012
1013
1014 /* Push the control state on this walk's control stack */
1015
1016 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
1017 break;
1018
1019 case AML_ELSE_OP:
1020
1021 /* Predicate is in the state object */
1022 /* If predicate is true, the IF was executed, ignore ELSE part */
1023
1024 if (WalkState->LastPredicate)
1025 {
1026 Status = AE_CTRL_TRUE;
1027 }
1028
1029 break;
1030
1031 case AML_RETURN_OP:
1032
1033 break;
1034
1035 default:
1036 break;
1037 }
1038
1039 return (Status);
1040}
1041
1042
1043/*******************************************************************************
1044 *
1045 * FUNCTION: AcpiDsExecEndControlOp
1046 *
1047 * PARAMETERS: WalkList - The list that owns the walk stack
1048 * Op - The control Op
1049 *
1050 * RETURN: Status
1051 *
1052 * DESCRIPTION: Handles all control ops encountered during control method
1053 * execution.
1054 *
1055 ******************************************************************************/
1056
1057ACPI_STATUS
1058AcpiDsExecEndControlOp (
1059 ACPI_WALK_STATE *WalkState,
1060 ACPI_PARSE_OBJECT *Op)
1061{
1062 ACPI_STATUS Status = AE_OK;
1063 ACPI_GENERIC_STATE *ControlState;
1064
1065
1066 ACPI_FUNCTION_NAME ("DsExecEndControlOp");
1067
1068
1069 switch (Op->Common.AmlOpcode)
1070 {
1071 case AML_IF_OP:
1072
1073 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
1074
1075 /*
1076 * Save the result of the predicate in case there is an
1077 * ELSE to come
1078 */
1079 WalkState->LastPredicate =
1080 (BOOLEAN) WalkState->ControlState->Common.Value;
1081
1082 /*
1083 * Pop the control state that was created at the start
1084 * of the IF and free it
1085 */
1086 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1087 AcpiUtDeleteGenericState (ControlState);
1088 break;
1089
1090
1091 case AML_ELSE_OP:
1092
1093 break;
1094
1095
1096 case AML_WHILE_OP:
1097
1098 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
1099
1100 if (WalkState->ControlState->Common.Value)
1101 {
1102 /* Predicate was true, go back and evaluate it again! */
1103
1104 Status = AE_CTRL_PENDING;
1105 }
1106
1107 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", Op));
1108
1109 /* Pop this control state and free it */
1110
1111 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1112
1113 WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
1114 AcpiUtDeleteGenericState (ControlState);
1115 break;
1116
1117
1118 case AML_RETURN_OP:
1119
1120 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1121 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
1122
1123 /*
1124 * One optional operand -- the return value
1125 * It can be either an immediate operand or a result that
1126 * has been bubbled up the tree
1127 */
1128 if (Op->Common.Value.Arg)
1129 {
1130 /* Return statement has an immediate operand */
1131
1132 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1133 if (ACPI_FAILURE (Status))
1134 {
1135 return (Status);
1136 }
1137
1138 /*
1139 * If value being returned is a Reference (such as
1140 * an arg or local), resolve it now because it may
1141 * cease to exist at the end of the method.
1142 */
1143 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
1144 if (ACPI_FAILURE (Status))
1145 {
1146 return (Status);
1147 }
1148
1149 /*
1150 * Get the return value and save as the last result
1151 * value. This is the only place where WalkState->ReturnDesc
1152 * is set to anything other than zero!
1153 */
1154 WalkState->ReturnDesc = WalkState->Operands[0];
1155 }
1156 else if ((WalkState->Results) &&
1157 (WalkState->Results->Results.NumResults > 0))
1158 {
1159 /*
1160 * The return value has come from a previous calculation.
1161 *
1162 * If value being returned is a Reference (such as
1163 * an arg or local), resolve it now because it may
1164 * cease to exist at the end of the method.
1165 *
1166 * Allow references created by the Index operator to return unchanged.
1167 */
1168 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1169 (ACPI_GET_OBJECT_TYPE (WalkState->Results->Results.ObjDesc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1170 ((WalkState->Results->Results.ObjDesc [0])->Reference.Opcode != AML_INDEX_OP))
1171 {
1172 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
1173 if (ACPI_FAILURE (Status))
1174 {
1175 return (Status);
1176 }
1177 }
1178
1179 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
1180 }
1181 else
1182 {
1183 /* No return operand */
1184
1185 if (WalkState->NumOperands)
1186 {
1187 AcpiUtRemoveReference (WalkState->Operands [0]);
1188 }
1189
1190 WalkState->Operands [0] = NULL;
1191 WalkState->NumOperands = 0;
1192 WalkState->ReturnDesc = NULL;
1193 }
1194
1195
1196 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1197 "Completed RETURN_OP State=%p, RetVal=%p\n",
1198 WalkState, WalkState->ReturnDesc));
1199
1200 /* End the control method execution right now */
1201
1202 Status = AE_CTRL_TERMINATE;
1203 break;
1204
1205
1206 case AML_NOOP_OP:
1207
1208 /* Just do nothing! */
1209 break;
1210
1211
1212 case AML_BREAK_POINT_OP:
1213
1214 /* Call up to the OS service layer to handle this */
1215
1216 Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1217
1218 /* If and when it returns, all done. */
1219
1220 break;
1221
1222
1223 case AML_BREAK_OP:
1224 case AML_CONTINUE_OP: /* ACPI 2.0 */
1225
1226
1227 /* Pop and delete control states until we find a while */
1228
1229 while (WalkState->ControlState &&
1230 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
1231 {
1232 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1233 AcpiUtDeleteGenericState (ControlState);
1234 }
1235
1236 /* No while found? */
1237
1238 if (!WalkState->ControlState)
1239 {
1240 return (AE_AML_NO_WHILE);
1241 }
1242
1243 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
1244
1245 WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
1246
1247 /* Return status depending on opcode */
1248
1249 if (Op->Common.AmlOpcode == AML_BREAK_OP)
1250 {
1251 Status = AE_CTRL_BREAK;
1252 }
1253 else
1254 {
1255 Status = AE_CTRL_CONTINUE;
1256 }
1257 break;
1258
1259
1260 default:
1261
1262 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
1263 Op->Common.AmlOpcode, Op));
1264
1265 Status = AE_AML_BAD_OPCODE;
1266 break;
1267 }
1268
1269 return (Status);
1270}
1271
127
128#define _COMPONENT ACPI_DISPATCHER
129 ACPI_MODULE_NAME ("dsopcode")
130
131
132/*****************************************************************************
133 *
134 * FUNCTION: AcpiDsExecuteArguments
135 *
136 * PARAMETERS: Node - Parent NS node
137 * AmlLength - Length of executable AML
138 * AmlStart - Pointer to the AML
139 *
140 * RETURN: Status.
141 *
142 * DESCRIPTION: Late (deferred) execution of region or field arguments
143 *
144 ****************************************************************************/
145
146ACPI_STATUS
147AcpiDsExecuteArguments (
148 ACPI_NAMESPACE_NODE *Node,
149 ACPI_NAMESPACE_NODE *ScopeNode,
150 UINT32 AmlLength,
151 UINT8 *AmlStart)
152{
153 ACPI_STATUS Status;
154 ACPI_PARSE_OBJECT *Op;
155 ACPI_WALK_STATE *WalkState;
156
157
158 ACPI_FUNCTION_TRACE ("DsExecuteArguments");
159
160
161 /*
162 * Allocate a new parser op to be the root of the parsed tree
163 */
164 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
165 if (!Op)
166 {
167 return_ACPI_STATUS (AE_NO_MEMORY);
168 }
169
170 /* Save the Node for use in AcpiPsParseAml */
171
172 Op->Common.Node = ScopeNode;
173
174 /* Create and initialize a new parser state */
175
176 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
177 if (!WalkState)
178 {
179 return_ACPI_STATUS (AE_NO_MEMORY);
180 }
181
182 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
183 AmlLength, NULL, 1);
184 if (ACPI_FAILURE (Status))
185 {
186 AcpiDsDeleteWalkState (WalkState);
187 return_ACPI_STATUS (Status);
188 }
189
190 /* Mark this parse as a deferred opcode */
191
192 WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
193 WalkState->DeferredNode = Node;
194
195 /* Pass1: Parse the entire declaration */
196
197 Status = AcpiPsParseAml (WalkState);
198 if (ACPI_FAILURE (Status))
199 {
200 AcpiPsDeleteParseTree (Op);
201 return_ACPI_STATUS (Status);
202 }
203
204 /* Get and init the Op created above */
205
206 Op->Common.Node = Node;
207 AcpiPsDeleteParseTree (Op);
208
209 /* Evaluate the deferred arguments */
210
211 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
212 if (!Op)
213 {
214 return_ACPI_STATUS (AE_NO_MEMORY);
215 }
216
217 Op->Common.Node = ScopeNode;
218
219 /* Create and initialize a new parser state */
220
221 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
222 if (!WalkState)
223 {
224 return_ACPI_STATUS (AE_NO_MEMORY);
225 }
226
227 /* Execute the opcode and arguments */
228
229 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
230 AmlLength, NULL, 3);
231 if (ACPI_FAILURE (Status))
232 {
233 AcpiDsDeleteWalkState (WalkState);
234 return_ACPI_STATUS (Status);
235 }
236
237 /* Mark this execution as a deferred opcode */
238
239 WalkState->DeferredNode = Node;
240 Status = AcpiPsParseAml (WalkState);
241 AcpiPsDeleteParseTree (Op);
242 return_ACPI_STATUS (Status);
243}
244
245
246/*****************************************************************************
247 *
248 * FUNCTION: AcpiDsGetBufferFieldArguments
249 *
250 * PARAMETERS: ObjDesc - A valid BufferField object
251 *
252 * RETURN: Status.
253 *
254 * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
255 * evaluation of these field attributes.
256 *
257 ****************************************************************************/
258
259ACPI_STATUS
260AcpiDsGetBufferFieldArguments (
261 ACPI_OPERAND_OBJECT *ObjDesc)
262{
263 ACPI_OPERAND_OBJECT *ExtraDesc;
264 ACPI_NAMESPACE_NODE *Node;
265 ACPI_STATUS Status;
266
267
268 ACPI_FUNCTION_TRACE_PTR ("DsGetBufferFieldArguments", ObjDesc);
269
270
271 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
272 {
273 return_ACPI_STATUS (AE_OK);
274 }
275
276 /* Get the AML pointer (method object) and BufferField node */
277
278 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
279 Node = ObjDesc->BufferField.Node;
280
281 ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_BUFFER_FIELD, Node, NULL));
282 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
283 AcpiUtGetNodeName (Node)));
284
285 /* Execute the AML code for the TermArg arguments */
286
287 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
288 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
289 return_ACPI_STATUS (Status);
290}
291
292
293/*****************************************************************************
294 *
295 * FUNCTION: AcpiDsGetBufferArguments
296 *
297 * PARAMETERS: ObjDesc - A valid Buffer object
298 *
299 * RETURN: Status.
300 *
301 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
302 * the late evaluation of these attributes.
303 *
304 ****************************************************************************/
305
306ACPI_STATUS
307AcpiDsGetBufferArguments (
308 ACPI_OPERAND_OBJECT *ObjDesc)
309{
310 ACPI_NAMESPACE_NODE *Node;
311 ACPI_STATUS Status;
312
313
314 ACPI_FUNCTION_TRACE_PTR ("DsGetBufferArguments", ObjDesc);
315
316
317 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
318 {
319 return_ACPI_STATUS (AE_OK);
320 }
321
322 /* Get the Buffer node */
323
324 Node = ObjDesc->Buffer.Node;
325 if (!Node)
326 {
327 ACPI_REPORT_ERROR ((
328 "No pointer back to NS node in buffer obj %p\n", ObjDesc));
329 return_ACPI_STATUS (AE_AML_INTERNAL);
330 }
331
332 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
333
334 /* Execute the AML code for the TermArg arguments */
335
336 Status = AcpiDsExecuteArguments (Node, Node,
337 ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
338 return_ACPI_STATUS (Status);
339}
340
341
342/*****************************************************************************
343 *
344 * FUNCTION: AcpiDsGetPackageArguments
345 *
346 * PARAMETERS: ObjDesc - A valid Package object
347 *
348 * RETURN: Status.
349 *
350 * DESCRIPTION: Get Package length and initializer byte list. This implements
351 * the late evaluation of these attributes.
352 *
353 ****************************************************************************/
354
355ACPI_STATUS
356AcpiDsGetPackageArguments (
357 ACPI_OPERAND_OBJECT *ObjDesc)
358{
359 ACPI_NAMESPACE_NODE *Node;
360 ACPI_STATUS Status;
361
362
363 ACPI_FUNCTION_TRACE_PTR ("DsGetPackageArguments", ObjDesc);
364
365
366 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
367 {
368 return_ACPI_STATUS (AE_OK);
369 }
370
371 /* Get the Package node */
372
373 Node = ObjDesc->Package.Node;
374 if (!Node)
375 {
376 ACPI_REPORT_ERROR ((
377 "No pointer back to NS node in package %p\n", ObjDesc));
378 return_ACPI_STATUS (AE_AML_INTERNAL);
379 }
380
381 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
382
383 /* Execute the AML code for the TermArg arguments */
384
385 Status = AcpiDsExecuteArguments (Node, Node,
386 ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
387 return_ACPI_STATUS (Status);
388}
389
390
391/*****************************************************************************
392 *
393 * FUNCTION: AcpiDsGetRegionArguments
394 *
395 * PARAMETERS: ObjDesc - A valid region object
396 *
397 * RETURN: Status.
398 *
399 * DESCRIPTION: Get region address and length. This implements the late
400 * evaluation of these region attributes.
401 *
402 ****************************************************************************/
403
404ACPI_STATUS
405AcpiDsGetRegionArguments (
406 ACPI_OPERAND_OBJECT *ObjDesc)
407{
408 ACPI_NAMESPACE_NODE *Node;
409 ACPI_STATUS Status;
410 ACPI_OPERAND_OBJECT *ExtraDesc;
411
412
413 ACPI_FUNCTION_TRACE_PTR ("DsGetRegionArguments", ObjDesc);
414
415
416 if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
417 {
418 return_ACPI_STATUS (AE_OK);
419 }
420
421 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
422 if (!ExtraDesc)
423 {
424 return_ACPI_STATUS (AE_NOT_EXIST);
425 }
426
427 /* Get the Region node */
428
429 Node = ObjDesc->Region.Node;
430
431 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (ACPI_TYPE_REGION, Node, NULL));
432
433 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
434 AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
435
436 /* Execute the argument AML */
437
438 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
439 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
440 return_ACPI_STATUS (Status);
441}
442
443
444/*****************************************************************************
445 *
446 * FUNCTION: AcpiDsInitializeRegion
447 *
448 * PARAMETERS: Op - A valid region Op object
449 *
450 * RETURN: Status
451 *
452 * DESCRIPTION: Front end to EvInitializeRegion
453 *
454 ****************************************************************************/
455
456ACPI_STATUS
457AcpiDsInitializeRegion (
458 ACPI_HANDLE ObjHandle)
459{
460 ACPI_OPERAND_OBJECT *ObjDesc;
461 ACPI_STATUS Status;
462
463
464 ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
465
466 /* Namespace is NOT locked */
467
468 Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
469 return (Status);
470}
471
472
473/*****************************************************************************
474 *
475 * FUNCTION: AcpiDsInitBufferField
476 *
477 * PARAMETERS: AmlOpcode - CreateXxxField
478 * ObjDesc - BufferField object
479 * BufferDesc - Host Buffer
480 * OffsetDesc - Offset into buffer
481 * Length - Length of field (CREATE_FIELD_OP only)
482 * Result - Where to store the result
483 *
484 * RETURN: Status
485 *
486 * DESCRIPTION: Perform actual initialization of a buffer field
487 *
488 ****************************************************************************/
489
490ACPI_STATUS
491AcpiDsInitBufferField (
492 UINT16 AmlOpcode,
493 ACPI_OPERAND_OBJECT *ObjDesc,
494 ACPI_OPERAND_OBJECT *BufferDesc,
495 ACPI_OPERAND_OBJECT *OffsetDesc,
496 ACPI_OPERAND_OBJECT *LengthDesc,
497 ACPI_OPERAND_OBJECT *ResultDesc)
498{
499 UINT32 Offset;
500 UINT32 BitOffset;
501 UINT32 BitCount;
502 UINT8 FieldFlags;
503 ACPI_STATUS Status;
504
505
506 ACPI_FUNCTION_TRACE_PTR ("DsInitBufferField", ObjDesc);
507
508
509 /* Host object must be a Buffer */
510
511 if (ACPI_GET_OBJECT_TYPE (BufferDesc) != ACPI_TYPE_BUFFER)
512 {
513 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
514 "Target of Create Field is not a Buffer object - %s\n",
515 AcpiUtGetObjectTypeName (BufferDesc)));
516
517 Status = AE_AML_OPERAND_TYPE;
518 goto Cleanup;
519 }
520
521 /*
522 * The last parameter to all of these opcodes (ResultDesc) started
523 * out as a NameString, and should therefore now be a NS node
524 * after resolution in AcpiExResolveOperands().
525 */
526 if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
527 {
528 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n",
529 AcpiPsGetOpcodeName (AmlOpcode), AcpiUtGetDescriptorName (ResultDesc)));
530
531 Status = AE_AML_OPERAND_TYPE;
532 goto Cleanup;
533 }
534
535 Offset = (UINT32) OffsetDesc->Integer.Value;
536
537 /*
538 * Setup the Bit offsets and counts, according to the opcode
539 */
540 switch (AmlOpcode)
541 {
542 case AML_CREATE_FIELD_OP:
543
544 /* Offset is in bits, count is in bits */
545
546 BitOffset = Offset;
547 BitCount = (UINT32) LengthDesc->Integer.Value;
548 FieldFlags = AML_FIELD_ACCESS_BYTE;
549 break;
550
551 case AML_CREATE_BIT_FIELD_OP:
552
553 /* Offset is in bits, Field is one bit */
554
555 BitOffset = Offset;
556 BitCount = 1;
557 FieldFlags = AML_FIELD_ACCESS_BYTE;
558 break;
559
560 case AML_CREATE_BYTE_FIELD_OP:
561
562 /* Offset is in bytes, field is one byte */
563
564 BitOffset = 8 * Offset;
565 BitCount = 8;
566 FieldFlags = AML_FIELD_ACCESS_BYTE;
567 break;
568
569 case AML_CREATE_WORD_FIELD_OP:
570
571 /* Offset is in bytes, field is one word */
572
573 BitOffset = 8 * Offset;
574 BitCount = 16;
575 FieldFlags = AML_FIELD_ACCESS_WORD;
576 break;
577
578 case AML_CREATE_DWORD_FIELD_OP:
579
580 /* Offset is in bytes, field is one dword */
581
582 BitOffset = 8 * Offset;
583 BitCount = 32;
584 FieldFlags = AML_FIELD_ACCESS_DWORD;
585 break;
586
587 case AML_CREATE_QWORD_FIELD_OP:
588
589 /* Offset is in bytes, field is one qword */
590
591 BitOffset = 8 * Offset;
592 BitCount = 64;
593 FieldFlags = AML_FIELD_ACCESS_QWORD;
594 break;
595
596 default:
597
598 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
599 "Unknown field creation opcode %02x\n",
600 AmlOpcode));
601 Status = AE_AML_BAD_OPCODE;
602 goto Cleanup;
603 }
604
605 /* Entire field must fit within the current length of the buffer */
606
607 if ((BitOffset + BitCount) >
608 (8 * (UINT32) BufferDesc->Buffer.Length))
609 {
610 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
611 "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
612 AcpiUtGetNodeName (ResultDesc),
613 BitOffset + BitCount,
614 AcpiUtGetNodeName (BufferDesc->Buffer.Node),
615 8 * (UINT32) BufferDesc->Buffer.Length));
616 Status = AE_AML_BUFFER_LIMIT;
617 goto Cleanup;
618 }
619
620 /*
621 * Initialize areas of the field object that are common to all fields
622 * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
623 */
624 Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags, 0,
625 BitOffset, BitCount);
626 if (ACPI_FAILURE (Status))
627 {
628 goto Cleanup;
629 }
630
631 ObjDesc->BufferField.BufferObj = BufferDesc;
632
633 /* Reference count for BufferDesc inherits ObjDesc count */
634
635 BufferDesc->Common.ReferenceCount = (UINT16) (BufferDesc->Common.ReferenceCount +
636 ObjDesc->Common.ReferenceCount);
637
638
639Cleanup:
640
641 /* Always delete the operands */
642
643 AcpiUtRemoveReference (OffsetDesc);
644 AcpiUtRemoveReference (BufferDesc);
645
646 if (AmlOpcode == AML_CREATE_FIELD_OP)
647 {
648 AcpiUtRemoveReference (LengthDesc);
649 }
650
651 /* On failure, delete the result descriptor */
652
653 if (ACPI_FAILURE (Status))
654 {
655 AcpiUtRemoveReference (ResultDesc); /* Result descriptor */
656 }
657 else
658 {
659 /* Now the address and length are valid for this BufferField */
660
661 ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
662 }
663
664 return_ACPI_STATUS (Status);
665}
666
667
668/*****************************************************************************
669 *
670 * FUNCTION: AcpiDsEvalBufferFieldOperands
671 *
672 * PARAMETERS: WalkState - Current walk
673 * Op - A valid BufferField Op object
674 *
675 * RETURN: Status
676 *
677 * DESCRIPTION: Get BufferField Buffer and Index
678 * Called from AcpiDsExecEndOp during BufferField parse tree walk
679 *
680 ****************************************************************************/
681
682ACPI_STATUS
683AcpiDsEvalBufferFieldOperands (
684 ACPI_WALK_STATE *WalkState,
685 ACPI_PARSE_OBJECT *Op)
686{
687 ACPI_STATUS Status;
688 ACPI_OPERAND_OBJECT *ObjDesc;
689 ACPI_NAMESPACE_NODE *Node;
690 ACPI_PARSE_OBJECT *NextOp;
691
692
693 ACPI_FUNCTION_TRACE_PTR ("DsEvalBufferFieldOperands", Op);
694
695
696 /*
697 * This is where we evaluate the address and length fields of the
698 * CreateXxxField declaration
699 */
700 Node = Op->Common.Node;
701
702 /* NextOp points to the op that holds the Buffer */
703
704 NextOp = Op->Common.Value.Arg;
705
706 /* Evaluate/create the address and length operands */
707
708 Status = AcpiDsCreateOperands (WalkState, NextOp);
709 if (ACPI_FAILURE (Status))
710 {
711 return_ACPI_STATUS (Status);
712 }
713
714 ObjDesc = AcpiNsGetAttachedObject (Node);
715 if (!ObjDesc)
716 {
717 return_ACPI_STATUS (AE_NOT_EXIST);
718 }
719
720 /* Resolve the operands */
721
722 Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
723 ACPI_WALK_OPERANDS, WalkState);
724
725 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
726 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
727 WalkState->NumOperands, "after AcpiExResolveOperands");
728
729 if (ACPI_FAILURE (Status))
730 {
731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
732 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
733
734 return_ACPI_STATUS (Status);
735 }
736
737 /* Initialize the Buffer Field */
738
739 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
740 {
741 /* NOTE: Slightly different operands for this opcode */
742
743 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
744 WalkState->Operands[0], WalkState->Operands[1],
745 WalkState->Operands[2], WalkState->Operands[3]);
746 }
747 else
748 {
749 /* All other, CreateXxxField opcodes */
750
751 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
752 WalkState->Operands[0], WalkState->Operands[1],
753 NULL, WalkState->Operands[2]);
754 }
755
756 return_ACPI_STATUS (Status);
757}
758
759
760/*****************************************************************************
761 *
762 * FUNCTION: AcpiDsEvalRegionOperands
763 *
764 * PARAMETERS: WalkState - Current walk
765 * Op - A valid region Op object
766 *
767 * RETURN: Status
768 *
769 * DESCRIPTION: Get region address and length
770 * Called from AcpiDsExecEndOp during OpRegion parse tree walk
771 *
772 ****************************************************************************/
773
774ACPI_STATUS
775AcpiDsEvalRegionOperands (
776 ACPI_WALK_STATE *WalkState,
777 ACPI_PARSE_OBJECT *Op)
778{
779 ACPI_STATUS Status;
780 ACPI_OPERAND_OBJECT *ObjDesc;
781 ACPI_OPERAND_OBJECT *OperandDesc;
782 ACPI_NAMESPACE_NODE *Node;
783 ACPI_PARSE_OBJECT *NextOp;
784
785
786 ACPI_FUNCTION_TRACE_PTR ("DsEvalRegionOperands", Op);
787
788
789 /*
790 * This is where we evaluate the address and length fields of the OpRegion declaration
791 */
792 Node = Op->Common.Node;
793
794 /* NextOp points to the op that holds the SpaceID */
795
796 NextOp = Op->Common.Value.Arg;
797
798 /* NextOp points to address op */
799
800 NextOp = NextOp->Common.Next;
801
802 /* Evaluate/create the address and length operands */
803
804 Status = AcpiDsCreateOperands (WalkState, NextOp);
805 if (ACPI_FAILURE (Status))
806 {
807 return_ACPI_STATUS (Status);
808 }
809
810 /* Resolve the length and address operands to numbers */
811
812 Status = AcpiExResolveOperands (Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
813 if (ACPI_FAILURE (Status))
814 {
815 return_ACPI_STATUS (Status);
816 }
817
818 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
819 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
820 1, "after AcpiExResolveOperands");
821
822 ObjDesc = AcpiNsGetAttachedObject (Node);
823 if (!ObjDesc)
824 {
825 return_ACPI_STATUS (AE_NOT_EXIST);
826 }
827
828 /*
829 * Get the length operand and save it
830 * (at Top of stack)
831 */
832 OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
833
834 ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
835 AcpiUtRemoveReference (OperandDesc);
836
837 /*
838 * Get the address and save it
839 * (at top of stack - 1)
840 */
841 OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
842
843 ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS) OperandDesc->Integer.Value;
844 AcpiUtRemoveReference (OperandDesc);
845
846 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
847 ObjDesc,
848 ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
849 ObjDesc->Region.Length));
850
851 /* Now the address and length are valid for this opregion */
852
853 ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
854
855 return_ACPI_STATUS (Status);
856}
857
858
859/*****************************************************************************
860 *
861 * FUNCTION: AcpiDsEvalDataObjectOperands
862 *
863 * PARAMETERS: WalkState - Current walk
864 * Op - A valid DataObject Op object
865 * ObjDesc - DataObject
866 *
867 * RETURN: Status
868 *
869 * DESCRIPTION: Get the operands and complete the following data objec types:
870 * Buffer
871 * Package
872 *
873 ****************************************************************************/
874
875ACPI_STATUS
876AcpiDsEvalDataObjectOperands (
877 ACPI_WALK_STATE *WalkState,
878 ACPI_PARSE_OBJECT *Op,
879 ACPI_OPERAND_OBJECT *ObjDesc)
880{
881 ACPI_STATUS Status;
882 ACPI_OPERAND_OBJECT *ArgDesc;
883 UINT32 Length;
884
885
886 ACPI_FUNCTION_TRACE ("DsEvalDataObjectOperands");
887
888
889 /* The first operand (for all of these data objects) is the length */
890
891 Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
892 if (ACPI_FAILURE (Status))
893 {
894 return_ACPI_STATUS (Status);
895 }
896
897 Status = AcpiExResolveOperands (WalkState->Opcode,
898 &(WalkState->Operands [WalkState->NumOperands -1]),
899 WalkState);
900 if (ACPI_FAILURE (Status))
901 {
902 return_ACPI_STATUS (Status);
903 }
904
905 /* Extract length operand */
906
907 ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
908 Length = (UINT32) ArgDesc->Integer.Value;
909
910 /* Cleanup for length operand */
911
912 Status = AcpiDsObjStackPop (1, WalkState);
913 if (ACPI_FAILURE (Status))
914 {
915 return_ACPI_STATUS (Status);
916 }
917
918 AcpiUtRemoveReference (ArgDesc);
919
920 /*
921 * Create the actual data object
922 */
923 switch (Op->Common.AmlOpcode)
924 {
925 case AML_BUFFER_OP:
926
927 Status = AcpiDsBuildInternalBufferObj (WalkState, Op, Length, &ObjDesc);
928 break;
929
930 case AML_PACKAGE_OP:
931 case AML_VAR_PACKAGE_OP:
932
933 Status = AcpiDsBuildInternalPackageObj (WalkState, Op, Length, &ObjDesc);
934 break;
935
936 default:
937 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
938 }
939
940 if (ACPI_SUCCESS (Status))
941 {
942 /*
943 * Return the object in the WalkState, unless the parent is a package --
944 * in this case, the return object will be stored in the parse tree
945 * for the package.
946 */
947 if ((!Op->Common.Parent) ||
948 ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
949 (Op->Common.Parent->Common.AmlOpcode != AML_VAR_PACKAGE_OP) &&
950 (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
951 {
952 WalkState->ResultObj = ObjDesc;
953 }
954 }
955
956 return_ACPI_STATUS (Status);
957}
958
959
960/*******************************************************************************
961 *
962 * FUNCTION: AcpiDsExecBeginControlOp
963 *
964 * PARAMETERS: WalkList - The list that owns the walk stack
965 * Op - The control Op
966 *
967 * RETURN: Status
968 *
969 * DESCRIPTION: Handles all control ops encountered during control method
970 * execution.
971 *
972 ******************************************************************************/
973
974ACPI_STATUS
975AcpiDsExecBeginControlOp (
976 ACPI_WALK_STATE *WalkState,
977 ACPI_PARSE_OBJECT *Op)
978{
979 ACPI_STATUS Status = AE_OK;
980 ACPI_GENERIC_STATE *ControlState;
981
982
983 ACPI_FUNCTION_NAME ("DsExecBeginControlOp");
984
985
986 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", Op,
987 Op->Common.AmlOpcode, WalkState));
988
989 switch (Op->Common.AmlOpcode)
990 {
991 case AML_IF_OP:
992 case AML_WHILE_OP:
993
994 /*
995 * IF/WHILE: Create a new control state to manage these
996 * constructs. We need to manage these as a stack, in order
997 * to handle nesting.
998 */
999 ControlState = AcpiUtCreateControlState ();
1000 if (!ControlState)
1001 {
1002 Status = AE_NO_MEMORY;
1003 break;
1004 }
1005 /*
1006 * Save a pointer to the predicate for multiple executions
1007 * of a loop
1008 */
1009 ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
1010 ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
1011 ControlState->Control.Opcode = Op->Common.AmlOpcode;
1012
1013
1014 /* Push the control state on this walk's control stack */
1015
1016 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
1017 break;
1018
1019 case AML_ELSE_OP:
1020
1021 /* Predicate is in the state object */
1022 /* If predicate is true, the IF was executed, ignore ELSE part */
1023
1024 if (WalkState->LastPredicate)
1025 {
1026 Status = AE_CTRL_TRUE;
1027 }
1028
1029 break;
1030
1031 case AML_RETURN_OP:
1032
1033 break;
1034
1035 default:
1036 break;
1037 }
1038
1039 return (Status);
1040}
1041
1042
1043/*******************************************************************************
1044 *
1045 * FUNCTION: AcpiDsExecEndControlOp
1046 *
1047 * PARAMETERS: WalkList - The list that owns the walk stack
1048 * Op - The control Op
1049 *
1050 * RETURN: Status
1051 *
1052 * DESCRIPTION: Handles all control ops encountered during control method
1053 * execution.
1054 *
1055 ******************************************************************************/
1056
1057ACPI_STATUS
1058AcpiDsExecEndControlOp (
1059 ACPI_WALK_STATE *WalkState,
1060 ACPI_PARSE_OBJECT *Op)
1061{
1062 ACPI_STATUS Status = AE_OK;
1063 ACPI_GENERIC_STATE *ControlState;
1064
1065
1066 ACPI_FUNCTION_NAME ("DsExecEndControlOp");
1067
1068
1069 switch (Op->Common.AmlOpcode)
1070 {
1071 case AML_IF_OP:
1072
1073 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
1074
1075 /*
1076 * Save the result of the predicate in case there is an
1077 * ELSE to come
1078 */
1079 WalkState->LastPredicate =
1080 (BOOLEAN) WalkState->ControlState->Common.Value;
1081
1082 /*
1083 * Pop the control state that was created at the start
1084 * of the IF and free it
1085 */
1086 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1087 AcpiUtDeleteGenericState (ControlState);
1088 break;
1089
1090
1091 case AML_ELSE_OP:
1092
1093 break;
1094
1095
1096 case AML_WHILE_OP:
1097
1098 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
1099
1100 if (WalkState->ControlState->Common.Value)
1101 {
1102 /* Predicate was true, go back and evaluate it again! */
1103
1104 Status = AE_CTRL_PENDING;
1105 }
1106
1107 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", Op));
1108
1109 /* Pop this control state and free it */
1110
1111 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1112
1113 WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
1114 AcpiUtDeleteGenericState (ControlState);
1115 break;
1116
1117
1118 case AML_RETURN_OP:
1119
1120 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1121 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
1122
1123 /*
1124 * One optional operand -- the return value
1125 * It can be either an immediate operand or a result that
1126 * has been bubbled up the tree
1127 */
1128 if (Op->Common.Value.Arg)
1129 {
1130 /* Return statement has an immediate operand */
1131
1132 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1133 if (ACPI_FAILURE (Status))
1134 {
1135 return (Status);
1136 }
1137
1138 /*
1139 * If value being returned is a Reference (such as
1140 * an arg or local), resolve it now because it may
1141 * cease to exist at the end of the method.
1142 */
1143 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
1144 if (ACPI_FAILURE (Status))
1145 {
1146 return (Status);
1147 }
1148
1149 /*
1150 * Get the return value and save as the last result
1151 * value. This is the only place where WalkState->ReturnDesc
1152 * is set to anything other than zero!
1153 */
1154 WalkState->ReturnDesc = WalkState->Operands[0];
1155 }
1156 else if ((WalkState->Results) &&
1157 (WalkState->Results->Results.NumResults > 0))
1158 {
1159 /*
1160 * The return value has come from a previous calculation.
1161 *
1162 * If value being returned is a Reference (such as
1163 * an arg or local), resolve it now because it may
1164 * cease to exist at the end of the method.
1165 *
1166 * Allow references created by the Index operator to return unchanged.
1167 */
1168 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1169 (ACPI_GET_OBJECT_TYPE (WalkState->Results->Results.ObjDesc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1170 ((WalkState->Results->Results.ObjDesc [0])->Reference.Opcode != AML_INDEX_OP))
1171 {
1172 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
1173 if (ACPI_FAILURE (Status))
1174 {
1175 return (Status);
1176 }
1177 }
1178
1179 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
1180 }
1181 else
1182 {
1183 /* No return operand */
1184
1185 if (WalkState->NumOperands)
1186 {
1187 AcpiUtRemoveReference (WalkState->Operands [0]);
1188 }
1189
1190 WalkState->Operands [0] = NULL;
1191 WalkState->NumOperands = 0;
1192 WalkState->ReturnDesc = NULL;
1193 }
1194
1195
1196 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1197 "Completed RETURN_OP State=%p, RetVal=%p\n",
1198 WalkState, WalkState->ReturnDesc));
1199
1200 /* End the control method execution right now */
1201
1202 Status = AE_CTRL_TERMINATE;
1203 break;
1204
1205
1206 case AML_NOOP_OP:
1207
1208 /* Just do nothing! */
1209 break;
1210
1211
1212 case AML_BREAK_POINT_OP:
1213
1214 /* Call up to the OS service layer to handle this */
1215
1216 Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1217
1218 /* If and when it returns, all done. */
1219
1220 break;
1221
1222
1223 case AML_BREAK_OP:
1224 case AML_CONTINUE_OP: /* ACPI 2.0 */
1225
1226
1227 /* Pop and delete control states until we find a while */
1228
1229 while (WalkState->ControlState &&
1230 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
1231 {
1232 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1233 AcpiUtDeleteGenericState (ControlState);
1234 }
1235
1236 /* No while found? */
1237
1238 if (!WalkState->ControlState)
1239 {
1240 return (AE_AML_NO_WHILE);
1241 }
1242
1243 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
1244
1245 WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
1246
1247 /* Return status depending on opcode */
1248
1249 if (Op->Common.AmlOpcode == AML_BREAK_OP)
1250 {
1251 Status = AE_CTRL_BREAK;
1252 }
1253 else
1254 {
1255 Status = AE_CTRL_CONTINUE;
1256 }
1257 break;
1258
1259
1260 default:
1261
1262 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
1263 Op->Common.AmlOpcode, Op));
1264
1265 Status = AE_AML_BAD_OPCODE;
1266 break;
1267 }
1268
1269 return (Status);
1270}
1271