1 /******************************************************************************
3 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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\n",
240 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
242 Node->Type = ACPI_TYPE_ANY;
243 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
248 /* All other types are an error */
250 ACPI_ERROR ((AE_INFO,
251 "Invalid type (%s) for target of "
252 "Scope operator [%4.4s] (Cannot override)",
253 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
255 return (AE_AML_OPERAND_TYPE);
261 /* All other opcodes */
263 if (Op && Op->Common.Node)
265 /* This op/node was previously entered into the namespace */
267 Node = Op->Common.Node;
269 if (AcpiNsOpensScope (ObjectType))
271 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
272 if (ACPI_FAILURE (Status))
274 return_ACPI_STATUS (Status);
278 return_ACPI_STATUS (AE_OK);
282 * Enter the named type into the internal namespace. We enter the name
283 * as we go downward in the parse tree. Any necessary subobjects that
284 * involve arguments to the opcode must be created as we go back up the
287 * Note: Name may already exist if we are executing a deferred opcode.
289 if (WalkState->DeferredNode)
291 /* This name is already in the namespace, get the node */
293 Node = WalkState->DeferredNode;
298 Flags = ACPI_NS_NO_UPSEARCH;
299 if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
301 /* Execution mode, node cannot already exist, node is temporary */
303 Flags |= ACPI_NS_ERROR_IF_FOUND;
305 if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
307 Flags |= ACPI_NS_TEMPORARY;
311 /* Add new entry or lookup existing entry */
313 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
314 ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
316 if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
318 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
319 "***New Node [%4.4s] %p is temporary\n",
320 AcpiUtGetNodeName (Node), Node));
325 if (ACPI_FAILURE (Status))
327 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
328 return_ACPI_STATUS (Status);
333 /* Create a new op */
335 Op = AcpiPsAllocOp (WalkState->Opcode);
338 return_ACPI_STATUS (AE_NO_MEMORY);
341 /* Initialize the new op */
345 Op->Named.Name = Node->Name.Integer;
351 * Put the Node in the "op" object that the parser uses, so we
352 * can get it again quickly when this scope is closed
354 Op->Common.Node = Node;
355 return_ACPI_STATUS (Status);
359 /*******************************************************************************
361 * FUNCTION: AcpiDsLoad2EndOp
363 * PARAMETERS: WalkState - Current state of the parse tree walk
367 * DESCRIPTION: Ascending callback used during the loading of the namespace,
368 * both control methods and everything else.
370 ******************************************************************************/
374 ACPI_WALK_STATE *WalkState)
376 ACPI_PARSE_OBJECT *Op;
377 ACPI_STATUS Status = AE_OK;
378 ACPI_OBJECT_TYPE ObjectType;
379 ACPI_NAMESPACE_NODE *Node;
380 ACPI_PARSE_OBJECT *Arg;
381 ACPI_NAMESPACE_NODE *NewNode;
382 #ifndef ACPI_NO_METHOD_EXECUTION
388 ACPI_FUNCTION_TRACE (DsLoad2EndOp);
391 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
392 WalkState->OpInfo->Name, Op, WalkState));
394 /* Check if opcode had an associated namespace object */
396 if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
398 return_ACPI_STATUS (AE_OK);
401 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
403 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
404 "Ending scope Op=%p State=%p\n", Op, WalkState));
407 ObjectType = WalkState->OpInfo->ObjectType;
410 * Get the Node/name from the earlier lookup
411 * (It was saved in the *op structure)
413 Node = Op->Common.Node;
416 * Put the Node on the object stack (Contains the ACPI Name of
419 WalkState->Operands[0] = (void *) Node;
420 WalkState->NumOperands = 1;
422 /* Pop the scope stack */
424 if (AcpiNsOpensScope (ObjectType) &&
425 (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
427 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
428 AcpiUtGetTypeName (ObjectType), Op));
430 Status = AcpiDsScopeStackPop (WalkState);
431 if (ACPI_FAILURE (Status))
438 * Named operations are as follows:
443 * AML_CREATEBYTEFIELD
444 * AML_CREATEDWORDFIELD
446 * AML_CREATEQWORDFIELD
447 * AML_CREATEWORDFIELD
465 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
466 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
467 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
469 /* Decode the opcode */
471 Arg = Op->Common.Value.Arg;
473 switch (WalkState->OpInfo->Type)
475 #ifndef ACPI_NO_METHOD_EXECUTION
477 case AML_TYPE_CREATE_FIELD:
479 * Create the field object, but the field buffer and index must
480 * be evaluated later during the execution phase
482 Status = AcpiDsCreateBufferField (Op, WalkState);
486 case AML_TYPE_NAMED_FIELD:
488 * If we are executing a method, initialize the field
490 if (WalkState->MethodNode)
492 Status = AcpiDsInitFieldObjects (Op, WalkState);
495 switch (Op->Common.AmlOpcode)
497 case AML_INDEX_FIELD_OP:
499 Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
503 case AML_BANK_FIELD_OP:
505 Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
510 Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
514 /* All NAMED_FIELD opcodes must be handled above */
520 case AML_TYPE_NAMED_SIMPLE:
522 Status = AcpiDsCreateOperands (WalkState, Arg);
523 if (ACPI_FAILURE (Status))
528 switch (Op->Common.AmlOpcode)
530 case AML_PROCESSOR_OP:
532 Status = AcpiExCreateProcessor (WalkState);
535 case AML_POWER_RES_OP:
537 Status = AcpiExCreatePowerResource (WalkState);
542 Status = AcpiExCreateMutex (WalkState);
547 Status = AcpiExCreateEvent (WalkState);
553 Status = AcpiExCreateAlias (WalkState);
563 /* Delete operands */
565 for (i = 1; i < WalkState->NumOperands; i++)
567 AcpiUtRemoveReference (WalkState->Operands[i]);
568 WalkState->Operands[i] = NULL;
572 #endif /* ACPI_NO_METHOD_EXECUTION */
574 case AML_TYPE_NAMED_COMPLEX:
576 switch (Op->Common.AmlOpcode)
578 #ifndef ACPI_NO_METHOD_EXECUTION
580 case AML_DATA_REGION_OP:
582 if (Op->Common.AmlOpcode == AML_REGION_OP)
584 RegionSpace = (ACPI_ADR_SPACE_TYPE)
585 ((Op->Common.Value.Arg)->Common.Value.Integer);
589 RegionSpace = ACPI_ADR_SPACE_DATA_TABLE;
593 * The OpRegion is not fully parsed at this time. The only valid
594 * argument is the SpaceId. (We must save the address of the
595 * AML of the address and length operands)
597 * If we have a valid region, initialize it. The namespace is
598 * unlocked at this point.
600 * Need to unlock interpreter if it is locked (if we are running
601 * a control method), in order to allow _REG methods to be run
602 * during AcpiEvInitializeRegion.
604 if (WalkState->MethodNode)
607 * Executing a method: initialize the region and unlock
610 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
611 RegionSpace, WalkState);
612 if (ACPI_FAILURE (Status))
617 AcpiExExitInterpreter ();
620 Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
622 if (WalkState->MethodNode)
624 AcpiExEnterInterpreter ();
627 if (ACPI_FAILURE (Status))
630 * If AE_NOT_EXIST is returned, it is not fatal
631 * because many regions get created before a handler
632 * is installed for said region.
634 if (AE_NOT_EXIST == Status)
644 Status = AcpiDsCreateNode (WalkState, Node, Op);
650 * MethodOp PkgLength NameString MethodFlags TermList
652 * Note: We must create the method node/object pair as soon as we
653 * see the method declaration. This allows later pass1 parsing
654 * of invocations of the method (need to know the number of
657 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
658 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
659 WalkState, Op, Op->Named.Node));
661 if (!AcpiNsGetAttachedObject (Op->Named.Node))
663 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
664 WalkState->NumOperands = 1;
666 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
667 if (ACPI_SUCCESS (Status))
669 Status = AcpiExCreateMethod (Op->Named.Data,
670 Op->Named.Length, WalkState);
672 WalkState->Operands[0] = NULL;
673 WalkState->NumOperands = 0;
675 if (ACPI_FAILURE (Status))
677 return_ACPI_STATUS (Status);
682 #endif /* ACPI_NO_METHOD_EXECUTION */
685 /* All NAMED_COMPLEX opcodes must be handled above */
691 case AML_CLASS_INTERNAL:
693 /* case AML_INT_NAMEPATH_OP: */
697 case AML_CLASS_METHOD_CALL:
699 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
700 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
701 WalkState, Op, Node));
704 * Lookup the method name and save the Node
706 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
707 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
708 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
709 WalkState, &(NewNode));
710 if (ACPI_SUCCESS (Status))
713 * Make sure that what we found is indeed a method
714 * We didn't search for a method on purpose, to see if the name
717 if (NewNode->Type != ACPI_TYPE_METHOD)
719 Status = AE_AML_OPERAND_TYPE;
722 /* We could put the returned object (Node) on the object stack for
723 * later, but for now, we will put it in the "op" object that the
724 * parser uses, so we can get it again at the end of this scope
726 Op->Common.Node = NewNode;
730 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
741 /* Remove the Node pushed at the very beginning */
743 WalkState->Operands[0] = NULL;
744 WalkState->NumOperands = 0;
745 return_ACPI_STATUS (Status);