1 /******************************************************************************
3 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __DSWLOAD2_C__
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acparser.h>
49 #include <contrib/dev/acpica/include/amlcode.h>
50 #include <contrib/dev/acpica/include/acdispat.h>
51 #include <contrib/dev/acpica/include/acinterp.h>
52 #include <contrib/dev/acpica/include/acnamesp.h>
53 #include <contrib/dev/acpica/include/acevents.h>
55 #define _COMPONENT ACPI_DISPATCHER
56 ACPI_MODULE_NAME ("dswload2")
59 /*******************************************************************************
61 * FUNCTION: AcpiDsLoad2BeginOp
63 * PARAMETERS: WalkState - Current state of the parse tree walk
64 * OutOp - Wher to return op if a new one is created
68 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
70 ******************************************************************************/
74 ACPI_WALK_STATE *WalkState,
75 ACPI_PARSE_OBJECT **OutOp)
77 ACPI_PARSE_OBJECT *Op;
78 ACPI_NAMESPACE_NODE *Node;
80 ACPI_OBJECT_TYPE ObjectType;
85 ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
89 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
93 if ((WalkState->ControlState) &&
94 (WalkState->ControlState->Common.State ==
95 ACPI_CONTROL_CONDITIONAL_EXECUTING))
97 /* We are executing a while loop outside of a method */
99 Status = AcpiDsExecBeginOp (WalkState, OutOp);
100 return_ACPI_STATUS (Status);
103 /* We only care about Namespace opcodes here */
105 if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE) &&
106 (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
107 (!(WalkState->OpInfo->Flags & AML_NAMED)))
109 return_ACPI_STATUS (AE_OK);
112 /* Get the name we are going to enter or lookup in the namespace */
114 if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
116 /* For Namepath op, get the path string */
118 BufferPtr = Op->Common.Value.String;
121 /* No name, just exit */
123 return_ACPI_STATUS (AE_OK);
128 /* Get name from the op */
130 BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
135 /* Get the namestring from the raw AML */
137 BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
140 /* Map the opcode into an internal object type */
142 ObjectType = WalkState->OpInfo->ObjectType;
144 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
145 "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
147 switch (WalkState->Opcode)
150 case AML_BANK_FIELD_OP:
151 case AML_INDEX_FIELD_OP:
157 case AML_INT_NAMEPATH_OP:
159 * The NamePath is an object reference to an existing object.
160 * Don't enter the name into the namespace, but look it up
163 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
164 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
170 /* Special case for Scope(\) -> refers to the Root node */
172 if (Op && (Op->Named.Node == AcpiGbl_RootNode))
174 Node = Op->Named.Node;
176 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
177 if (ACPI_FAILURE (Status))
179 return_ACPI_STATUS (Status);
185 * The Path is an object reference to an existing object.
186 * Don't enter the name into the namespace, but look it up
189 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
190 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
192 if (ACPI_FAILURE (Status))
194 #ifdef ACPI_ASL_COMPILER
195 if (Status == AE_NOT_FOUND)
201 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
204 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
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 /* Add new entry or lookup existing entry */
327 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
328 ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
330 if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
332 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
333 "***New Node [%4.4s] %p is temporary\n",
334 AcpiUtGetNodeName (Node), Node));
339 if (ACPI_FAILURE (Status))
341 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
342 return_ACPI_STATUS (Status);
347 /* Create a new op */
349 Op = AcpiPsAllocOp (WalkState->Opcode);
352 return_ACPI_STATUS (AE_NO_MEMORY);
355 /* Initialize the new op */
359 Op->Named.Name = Node->Name.Integer;
365 * Put the Node in the "op" object that the parser uses, so we
366 * can get it again quickly when this scope is closed
368 Op->Common.Node = Node;
369 return_ACPI_STATUS (Status);
373 /*******************************************************************************
375 * FUNCTION: AcpiDsLoad2EndOp
377 * PARAMETERS: WalkState - Current state of the parse tree walk
381 * DESCRIPTION: Ascending callback used during the loading of the namespace,
382 * both control methods and everything else.
384 ******************************************************************************/
388 ACPI_WALK_STATE *WalkState)
390 ACPI_PARSE_OBJECT *Op;
391 ACPI_STATUS Status = AE_OK;
392 ACPI_OBJECT_TYPE ObjectType;
393 ACPI_NAMESPACE_NODE *Node;
394 ACPI_PARSE_OBJECT *Arg;
395 ACPI_NAMESPACE_NODE *NewNode;
396 #ifndef ACPI_NO_METHOD_EXECUTION
402 ACPI_FUNCTION_TRACE (DsLoad2EndOp);
405 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
406 WalkState->OpInfo->Name, Op, WalkState));
408 /* Check if opcode had an associated namespace object */
410 if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
412 return_ACPI_STATUS (AE_OK);
415 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
417 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
418 "Ending scope Op=%p State=%p\n", Op, WalkState));
421 ObjectType = WalkState->OpInfo->ObjectType;
424 * Get the Node/name from the earlier lookup
425 * (It was saved in the *op structure)
427 Node = Op->Common.Node;
430 * Put the Node on the object stack (Contains the ACPI Name of
433 WalkState->Operands[0] = (void *) Node;
434 WalkState->NumOperands = 1;
436 /* Pop the scope stack */
438 if (AcpiNsOpensScope (ObjectType) &&
439 (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
441 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
442 AcpiUtGetTypeName (ObjectType), Op));
444 Status = AcpiDsScopeStackPop (WalkState);
445 if (ACPI_FAILURE (Status))
452 * Named operations are as follows:
457 * AML_CREATEBYTEFIELD
458 * AML_CREATEDWORDFIELD
460 * AML_CREATEQWORDFIELD
461 * AML_CREATEWORDFIELD
479 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
480 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
481 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
483 /* Decode the opcode */
485 Arg = Op->Common.Value.Arg;
487 switch (WalkState->OpInfo->Type)
489 #ifndef ACPI_NO_METHOD_EXECUTION
491 case AML_TYPE_CREATE_FIELD:
493 * Create the field object, but the field buffer and index must
494 * be evaluated later during the execution phase
496 Status = AcpiDsCreateBufferField (Op, WalkState);
500 case AML_TYPE_NAMED_FIELD:
502 * If we are executing a method, initialize the field
504 if (WalkState->MethodNode)
506 Status = AcpiDsInitFieldObjects (Op, WalkState);
509 switch (Op->Common.AmlOpcode)
511 case AML_INDEX_FIELD_OP:
513 Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
517 case AML_BANK_FIELD_OP:
519 Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
524 Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
528 /* All NAMED_FIELD opcodes must be handled above */
534 case AML_TYPE_NAMED_SIMPLE:
536 Status = AcpiDsCreateOperands (WalkState, Arg);
537 if (ACPI_FAILURE (Status))
542 switch (Op->Common.AmlOpcode)
544 case AML_PROCESSOR_OP:
546 Status = AcpiExCreateProcessor (WalkState);
549 case AML_POWER_RES_OP:
551 Status = AcpiExCreatePowerResource (WalkState);
556 Status = AcpiExCreateMutex (WalkState);
561 Status = AcpiExCreateEvent (WalkState);
567 Status = AcpiExCreateAlias (WalkState);
577 /* Delete operands */
579 for (i = 1; i < WalkState->NumOperands; i++)
581 AcpiUtRemoveReference (WalkState->Operands[i]);
582 WalkState->Operands[i] = NULL;
586 #endif /* ACPI_NO_METHOD_EXECUTION */
588 case AML_TYPE_NAMED_COMPLEX:
590 switch (Op->Common.AmlOpcode)
592 #ifndef ACPI_NO_METHOD_EXECUTION
594 case AML_DATA_REGION_OP:
596 if (Op->Common.AmlOpcode == AML_REGION_OP)
598 RegionSpace = (ACPI_ADR_SPACE_TYPE)
599 ((Op->Common.Value.Arg)->Common.Value.Integer);
603 RegionSpace = ACPI_ADR_SPACE_DATA_TABLE;
607 * The OpRegion is not fully parsed at this time. The only valid
608 * argument is the SpaceId. (We must save the address of the
609 * AML of the address and length operands)
611 * If we have a valid region, initialize it. The namespace is
612 * unlocked at this point.
614 * Need to unlock interpreter if it is locked (if we are running
615 * a control method), in order to allow _REG methods to be run
616 * during AcpiEvInitializeRegion.
618 if (WalkState->MethodNode)
621 * Executing a method: initialize the region and unlock
624 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
625 RegionSpace, WalkState);
626 if (ACPI_FAILURE (Status))
628 return_ACPI_STATUS (Status);
631 AcpiExExitInterpreter ();
634 Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
636 if (WalkState->MethodNode)
638 AcpiExEnterInterpreter ();
641 if (ACPI_FAILURE (Status))
644 * If AE_NOT_EXIST is returned, it is not fatal
645 * because many regions get created before a handler
646 * is installed for said region.
648 if (AE_NOT_EXIST == Status)
658 Status = AcpiDsCreateNode (WalkState, Node, Op);
664 * MethodOp PkgLength NameString MethodFlags TermList
666 * Note: We must create the method node/object pair as soon as we
667 * see the method declaration. This allows later pass1 parsing
668 * of invocations of the method (need to know the number of
671 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
672 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
673 WalkState, Op, Op->Named.Node));
675 if (!AcpiNsGetAttachedObject (Op->Named.Node))
677 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
678 WalkState->NumOperands = 1;
680 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
681 if (ACPI_SUCCESS (Status))
683 Status = AcpiExCreateMethod (Op->Named.Data,
684 Op->Named.Length, WalkState);
686 WalkState->Operands[0] = NULL;
687 WalkState->NumOperands = 0;
689 if (ACPI_FAILURE (Status))
691 return_ACPI_STATUS (Status);
696 #endif /* ACPI_NO_METHOD_EXECUTION */
699 /* All NAMED_COMPLEX opcodes must be handled above */
705 case AML_CLASS_INTERNAL:
707 /* case AML_INT_NAMEPATH_OP: */
711 case AML_CLASS_METHOD_CALL:
713 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
714 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
715 WalkState, Op, Node));
718 * Lookup the method name and save the Node
720 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
721 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
722 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
723 WalkState, &(NewNode));
724 if (ACPI_SUCCESS (Status))
727 * Make sure that what we found is indeed a method
728 * We didn't search for a method on purpose, to see if the name
731 if (NewNode->Type != ACPI_TYPE_METHOD)
733 Status = AE_AML_OPERAND_TYPE;
736 /* We could put the returned object (Node) on the object stack for
737 * later, but for now, we will put it in the "op" object that the
738 * parser uses, so we can get it again at the end of this scope
740 Op->Common.Node = NewNode;
744 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
755 /* Remove the Node pushed at the very beginning */
757 WalkState->Operands[0] = NULL;
758 WalkState->NumOperands = 0;
759 return_ACPI_STATUS (Status);