1 /******************************************************************************
3 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME ("dswload2")
57 /*******************************************************************************
59 * FUNCTION: AcpiDsLoad2BeginOp
61 * PARAMETERS: WalkState - Current state of the parse tree walk
62 * OutOp - Wher to return op if a new one is created
66 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
68 ******************************************************************************/
72 ACPI_WALK_STATE
*WalkState
,
73 ACPI_PARSE_OBJECT
**OutOp
)
75 ACPI_PARSE_OBJECT
*Op
;
76 ACPI_NAMESPACE_NODE
*Node
;
78 ACPI_OBJECT_TYPE ObjectType
;
83 ACPI_FUNCTION_TRACE (DsLoad2BeginOp
);
87 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", Op
, WalkState
));
91 if ((WalkState
->ControlState
) &&
92 (WalkState
->ControlState
->Common
.State
==
93 ACPI_CONTROL_CONDITIONAL_EXECUTING
))
95 /* We are executing a while loop outside of a method */
97 Status
= AcpiDsExecBeginOp (WalkState
, OutOp
);
98 return_ACPI_STATUS (Status
);
101 /* We only care about Namespace opcodes here */
103 if ((!(WalkState
->OpInfo
->Flags
& AML_NSOPCODE
) &&
104 (WalkState
->Opcode
!= AML_INT_NAMEPATH_OP
)) ||
105 (!(WalkState
->OpInfo
->Flags
& AML_NAMED
)))
107 return_ACPI_STATUS (AE_OK
);
110 /* Get the name we are going to enter or lookup in the namespace */
112 if (WalkState
->Opcode
== AML_INT_NAMEPATH_OP
)
114 /* For Namepath op, get the path string */
116 BufferPtr
= Op
->Common
.Value
.String
;
119 /* No name, just exit */
121 return_ACPI_STATUS (AE_OK
);
126 /* Get name from the op */
128 BufferPtr
= ACPI_CAST_PTR (char, &Op
->Named
.Name
);
133 /* Get the namestring from the raw AML */
135 BufferPtr
= AcpiPsGetNextNamestring (&WalkState
->ParserState
);
138 /* Map the opcode into an internal object type */
140 ObjectType
= WalkState
->OpInfo
->ObjectType
;
142 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
143 "State=%p Op=%p Type=%X\n", WalkState
, Op
, ObjectType
));
145 switch (WalkState
->Opcode
)
148 case AML_BANK_FIELD_OP
:
149 case AML_INDEX_FIELD_OP
:
155 case AML_INT_NAMEPATH_OP
:
157 * The NamePath is an object reference to an existing object.
158 * Don't enter the name into the namespace, but look it up
161 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, BufferPtr
, ObjectType
,
162 ACPI_IMODE_EXECUTE
, ACPI_NS_SEARCH_PARENT
,
168 /* Special case for Scope(\) -> refers to the Root node */
170 if (Op
&& (Op
->Named
.Node
== AcpiGbl_RootNode
))
172 Node
= Op
->Named
.Node
;
174 Status
= AcpiDsScopeStackPush (Node
, ObjectType
, WalkState
);
175 if (ACPI_FAILURE (Status
))
177 return_ACPI_STATUS (Status
);
183 * The Path is an object reference to an existing object.
184 * Don't enter the name into the namespace, but look it up
187 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, BufferPtr
, ObjectType
,
188 ACPI_IMODE_EXECUTE
, ACPI_NS_SEARCH_PARENT
,
190 if (ACPI_FAILURE (Status
))
192 #ifdef ACPI_ASL_COMPILER
193 if (Status
== AE_NOT_FOUND
)
199 ACPI_ERROR_NAMESPACE (WalkState
->ScopeInfo
,
203 ACPI_ERROR_NAMESPACE (WalkState
->ScopeInfo
,
206 return_ACPI_STATUS (Status
);
211 * We must check to make sure that the target is
212 * one of the opcodes that actually opens a scope
217 case ACPI_TYPE_LOCAL_SCOPE
: /* Scope */
218 case ACPI_TYPE_DEVICE
:
219 case ACPI_TYPE_POWER
:
220 case ACPI_TYPE_PROCESSOR
:
221 case ACPI_TYPE_THERMAL
:
223 /* These are acceptable types */
226 case ACPI_TYPE_INTEGER
:
227 case ACPI_TYPE_STRING
:
228 case ACPI_TYPE_BUFFER
:
231 * These types we will allow, but we will change the type.
232 * This enables some existing code of the form:
235 * Scope (DEB) { ... }
237 ACPI_WARNING ((AE_INFO
,
238 "Type override - [%4.4s] had invalid type (%s) "
239 "for Scope operator, changed to type ANY",
240 AcpiUtGetNodeName (Node
), AcpiUtGetTypeName (Node
->Type
)));
242 Node
->Type
= ACPI_TYPE_ANY
;
243 WalkState
->ScopeInfo
->Common
.Value
= ACPI_TYPE_ANY
;
246 case ACPI_TYPE_METHOD
:
249 * Allow scope change to root during execution of module-level
250 * code. Root is typed METHOD during this time.
252 if ((Node
== AcpiGbl_RootNode
) &&
253 (WalkState
->ParseFlags
& ACPI_PARSE_MODULE_LEVEL
))
258 /*lint -fallthrough */
262 /* All other types are an error */
264 ACPI_ERROR ((AE_INFO
,
265 "Invalid type (%s) for target of "
266 "Scope operator [%4.4s] (Cannot override)",
267 AcpiUtGetTypeName (Node
->Type
), AcpiUtGetNodeName (Node
)));
269 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
275 /* All other opcodes */
277 if (Op
&& Op
->Common
.Node
)
279 /* This op/node was previously entered into the namespace */
281 Node
= Op
->Common
.Node
;
283 if (AcpiNsOpensScope (ObjectType
))
285 Status
= AcpiDsScopeStackPush (Node
, ObjectType
, WalkState
);
286 if (ACPI_FAILURE (Status
))
288 return_ACPI_STATUS (Status
);
292 return_ACPI_STATUS (AE_OK
);
296 * Enter the named type into the internal namespace. We enter the name
297 * as we go downward in the parse tree. Any necessary subobjects that
298 * involve arguments to the opcode must be created as we go back up the
301 * Note: Name may already exist if we are executing a deferred opcode.
303 if (WalkState
->DeferredNode
)
305 /* This name is already in the namespace, get the node */
307 Node
= WalkState
->DeferredNode
;
312 Flags
= ACPI_NS_NO_UPSEARCH
;
313 if (WalkState
->PassNumber
== ACPI_IMODE_EXECUTE
)
315 /* Execution mode, node cannot already exist, node is temporary */
317 Flags
|= ACPI_NS_ERROR_IF_FOUND
;
319 if (!(WalkState
->ParseFlags
& ACPI_PARSE_MODULE_LEVEL
))
321 Flags
|= ACPI_NS_TEMPORARY
;
325 #ifdef ACPI_ASL_COMPILER
328 * Do not open a scope for AML_EXTERNAL_OP
329 * AcpiNsLookup can open a new scope based on the object type
330 * of this op. AML_EXTERNAL_OP is a declaration rather than a
331 * definition. In the case that this external is a method object,
332 * AcpiNsLookup will open a new scope. However, an AML_EXTERNAL_OP
333 * associated with the ACPI_TYPE_METHOD is a declaration, rather than
334 * a definition. Flags is set to avoid opening a scope for any
337 if (WalkState
->Opcode
== AML_EXTERNAL_OP
)
339 Flags
|= ACPI_NS_DONT_OPEN_SCOPE
;
344 * For name creation opcodes, the full namepath prefix must
345 * exist, except for the final (new) nameseg.
347 if (WalkState
->OpInfo
->Flags
& AML_NAMED
)
349 Flags
|= ACPI_NS_PREFIX_MUST_EXIST
;
352 /* Add new entry or lookup existing entry */
354 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, BufferPtr
, ObjectType
,
355 ACPI_IMODE_LOAD_PASS2
, Flags
, WalkState
, &Node
);
357 if (ACPI_SUCCESS (Status
) && (Flags
& ACPI_NS_TEMPORARY
))
359 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
360 "***New Node [%4.4s] %p is temporary\n",
361 AcpiUtGetNodeName (Node
), Node
));
366 if (ACPI_FAILURE (Status
))
368 ACPI_ERROR_NAMESPACE (WalkState
->ScopeInfo
,
370 return_ACPI_STATUS (Status
);
375 /* Create a new op */
377 Op
= AcpiPsAllocOp (WalkState
->Opcode
, WalkState
->Aml
);
380 return_ACPI_STATUS (AE_NO_MEMORY
);
383 /* Initialize the new op */
387 Op
->Named
.Name
= Node
->Name
.Integer
;
393 * Put the Node in the "op" object that the parser uses, so we
394 * can get it again quickly when this scope is closed
396 Op
->Common
.Node
= Node
;
397 return_ACPI_STATUS (Status
);
401 /*******************************************************************************
403 * FUNCTION: AcpiDsLoad2EndOp
405 * PARAMETERS: WalkState - Current state of the parse tree walk
409 * DESCRIPTION: Ascending callback used during the loading of the namespace,
410 * both control methods and everything else.
412 ******************************************************************************/
416 ACPI_WALK_STATE
*WalkState
)
418 ACPI_PARSE_OBJECT
*Op
;
419 ACPI_STATUS Status
= AE_OK
;
420 ACPI_OBJECT_TYPE ObjectType
;
421 ACPI_NAMESPACE_NODE
*Node
;
422 ACPI_PARSE_OBJECT
*Arg
;
423 ACPI_NAMESPACE_NODE
*NewNode
;
428 ACPI_FUNCTION_TRACE (DsLoad2EndOp
);
431 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Opcode [%s] Op %p State %p\n",
432 WalkState
->OpInfo
->Name
, Op
, WalkState
));
434 /* Check if opcode had an associated namespace object */
436 if (!(WalkState
->OpInfo
->Flags
& AML_NSOBJECT
))
438 return_ACPI_STATUS (AE_OK
);
441 if (Op
->Common
.AmlOpcode
== AML_SCOPE_OP
)
443 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
444 "Ending scope Op=%p State=%p\n", Op
, WalkState
));
447 ObjectType
= WalkState
->OpInfo
->ObjectType
;
450 * Get the Node/name from the earlier lookup
451 * (It was saved in the *op structure)
453 Node
= Op
->Common
.Node
;
456 * Put the Node on the object stack (Contains the ACPI Name of
459 WalkState
->Operands
[0] = (void *) Node
;
460 WalkState
->NumOperands
= 1;
462 /* Pop the scope stack */
464 if (AcpiNsOpensScope (ObjectType
) &&
465 (Op
->Common
.AmlOpcode
!= AML_INT_METHODCALL_OP
))
467 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "(%s) Popping scope for Op %p\n",
468 AcpiUtGetTypeName (ObjectType
), Op
));
470 Status
= AcpiDsScopeStackPop (WalkState
);
471 if (ACPI_FAILURE (Status
))
478 * Named operations are as follows:
483 * AML_CREATEBYTEFIELD
484 * AML_CREATEDWORDFIELD
486 * AML_CREATEQWORDFIELD
487 * AML_CREATEWORDFIELD
505 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
506 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
507 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
), WalkState
, Op
, Node
));
509 /* Decode the opcode */
511 Arg
= Op
->Common
.Value
.Arg
;
513 switch (WalkState
->OpInfo
->Type
)
516 case AML_TYPE_CREATE_FIELD
:
518 * Create the field object, but the field buffer and index must
519 * be evaluated later during the execution phase
521 Status
= AcpiDsCreateBufferField (Op
, WalkState
);
524 case AML_TYPE_NAMED_FIELD
:
526 * If we are executing a method, initialize the field
528 if (WalkState
->MethodNode
)
530 Status
= AcpiDsInitFieldObjects (Op
, WalkState
);
533 switch (Op
->Common
.AmlOpcode
)
535 case AML_INDEX_FIELD_OP
:
537 Status
= AcpiDsCreateIndexField (
538 Op
, (ACPI_HANDLE
) Arg
->Common
.Node
, WalkState
);
541 case AML_BANK_FIELD_OP
:
543 Status
= AcpiDsCreateBankField (Op
, Arg
->Common
.Node
, WalkState
);
548 Status
= AcpiDsCreateField (Op
, Arg
->Common
.Node
, WalkState
);
553 /* All NAMED_FIELD opcodes must be handled above */
558 case AML_TYPE_NAMED_SIMPLE
:
560 Status
= AcpiDsCreateOperands (WalkState
, Arg
);
561 if (ACPI_FAILURE (Status
))
566 switch (Op
->Common
.AmlOpcode
)
568 case AML_PROCESSOR_OP
:
570 Status
= AcpiExCreateProcessor (WalkState
);
573 case AML_POWER_RESOURCE_OP
:
575 Status
= AcpiExCreatePowerResource (WalkState
);
580 Status
= AcpiExCreateMutex (WalkState
);
585 Status
= AcpiExCreateEvent (WalkState
);
590 Status
= AcpiExCreateAlias (WalkState
);
601 /* Delete operands */
603 for (i
= 1; i
< WalkState
->NumOperands
; i
++)
605 AcpiUtRemoveReference (WalkState
->Operands
[i
]);
606 WalkState
->Operands
[i
] = NULL
;
611 case AML_TYPE_NAMED_COMPLEX
:
613 switch (Op
->Common
.AmlOpcode
)
616 case AML_DATA_REGION_OP
:
618 if (Op
->Common
.AmlOpcode
== AML_REGION_OP
)
620 RegionSpace
= (ACPI_ADR_SPACE_TYPE
)
621 ((Op
->Common
.Value
.Arg
)->Common
.Value
.Integer
);
625 RegionSpace
= ACPI_ADR_SPACE_DATA_TABLE
;
629 * The OpRegion is not fully parsed at this time. The only valid
630 * argument is the SpaceId. (We must save the address of the
631 * AML of the address and length operands)
633 * If we have a valid region, initialize it. The namespace is
634 * unlocked at this point.
636 * Need to unlock interpreter if it is locked (if we are running
637 * a control method), in order to allow _REG methods to be run
638 * during AcpiEvInitializeRegion.
640 if (WalkState
->MethodNode
)
643 * Executing a method: initialize the region and unlock
646 Status
= AcpiExCreateRegion (Op
->Named
.Data
,
647 Op
->Named
.Length
, RegionSpace
, WalkState
);
648 if (ACPI_FAILURE (Status
))
650 return_ACPI_STATUS (Status
);
654 Status
= AcpiEvInitializeRegion (
655 AcpiNsGetAttachedObject (Node
));
660 Status
= AcpiDsCreateNode (WalkState
, Node
, Op
);
665 * MethodOp PkgLength NameString MethodFlags TermList
667 * Note: We must create the method node/object pair as soon as we
668 * see the method declaration. This allows later pass1 parsing
669 * of invocations of the method (need to know the number of
672 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
673 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
674 WalkState
, Op
, Op
->Named
.Node
));
676 if (!AcpiNsGetAttachedObject (Op
->Named
.Node
))
678 WalkState
->Operands
[0] = ACPI_CAST_PTR (void, Op
->Named
.Node
);
679 WalkState
->NumOperands
= 1;
681 Status
= AcpiDsCreateOperands (
682 WalkState
, Op
->Common
.Value
.Arg
);
683 if (ACPI_SUCCESS (Status
))
685 Status
= AcpiExCreateMethod (
686 Op
->Named
.Data
, Op
->Named
.Length
, WalkState
);
689 WalkState
->Operands
[0] = NULL
;
690 WalkState
->NumOperands
= 0;
692 if (ACPI_FAILURE (Status
))
694 return_ACPI_STATUS (Status
);
702 /* All NAMED_COMPLEX opcodes must be handled above */
707 case AML_CLASS_INTERNAL
:
709 /* case AML_INT_NAMEPATH_OP: */
712 case AML_CLASS_METHOD_CALL
:
714 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
715 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
716 WalkState
, Op
, Node
));
719 * Lookup the method name and save the Node
721 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.String
,
722 ACPI_TYPE_ANY
, ACPI_IMODE_LOAD_PASS2
,
723 ACPI_NS_SEARCH_PARENT
| ACPI_NS_DONT_OPEN_SCOPE
,
724 WalkState
, &(NewNode
));
725 if (ACPI_SUCCESS (Status
))
728 * Make sure that what we found is indeed a method
729 * We didn't search for a method on purpose, to see if the name
732 if (NewNode
->Type
!= ACPI_TYPE_METHOD
)
734 Status
= AE_AML_OPERAND_TYPE
;
737 /* We could put the returned object (Node) on the object stack for
738 * later, but for now, we will put it in the "op" object that the
739 * parser uses, so we can get it again at the end of this scope
741 Op
->Common
.Node
= NewNode
;
745 ACPI_ERROR_NAMESPACE (WalkState
->ScopeInfo
,
746 Arg
->Common
.Value
.String
, Status
);
758 /* Remove the Node pushed at the very beginning */
760 WalkState
->Operands
[0] = NULL
;
761 WalkState
->NumOperands
= 0;
762 return_ACPI_STATUS (Status
);