1 /******************************************************************************
3 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __DSWLOAD2_C__
119 #include "accommon.h"
120 #include "acparser.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
125 #include "acevents.h"
127 #define _COMPONENT ACPI_DISPATCHER
128 ACPI_MODULE_NAME ("dswload2")
131 /*******************************************************************************
133 * FUNCTION: AcpiDsLoad2BeginOp
135 * PARAMETERS: WalkState - Current state of the parse tree walk
136 * OutOp - Wher to return op if a new one is created
140 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
142 ******************************************************************************/
146 ACPI_WALK_STATE
*WalkState
,
147 ACPI_PARSE_OBJECT
**OutOp
)
149 ACPI_PARSE_OBJECT
*Op
;
150 ACPI_NAMESPACE_NODE
*Node
;
152 ACPI_OBJECT_TYPE ObjectType
;
157 ACPI_FUNCTION_TRACE (DsLoad2BeginOp
);
161 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", Op
, WalkState
));
165 if ((WalkState
->ControlState
) &&
166 (WalkState
->ControlState
->Common
.State
==
167 ACPI_CONTROL_CONDITIONAL_EXECUTING
))
169 /* We are executing a while loop outside of a method */
171 Status
= AcpiDsExecBeginOp (WalkState
, OutOp
);
172 return_ACPI_STATUS (Status
);
175 /* We only care about Namespace opcodes here */
177 if ((!(WalkState
->OpInfo
->Flags
& AML_NSOPCODE
) &&
178 (WalkState
->Opcode
!= AML_INT_NAMEPATH_OP
)) ||
179 (!(WalkState
->OpInfo
->Flags
& AML_NAMED
)))
181 return_ACPI_STATUS (AE_OK
);
184 /* Get the name we are going to enter or lookup in the namespace */
186 if (WalkState
->Opcode
== AML_INT_NAMEPATH_OP
)
188 /* For Namepath op, get the path string */
190 BufferPtr
= Op
->Common
.Value
.String
;
193 /* No name, just exit */
195 return_ACPI_STATUS (AE_OK
);
200 /* Get name from the op */
202 BufferPtr
= ACPI_CAST_PTR (char, &Op
->Named
.Name
);
207 /* Get the namestring from the raw AML */
209 BufferPtr
= AcpiPsGetNextNamestring (&WalkState
->ParserState
);
212 /* Map the opcode into an internal object type */
214 ObjectType
= WalkState
->OpInfo
->ObjectType
;
216 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
217 "State=%p Op=%p Type=%X\n", WalkState
, Op
, ObjectType
));
219 switch (WalkState
->Opcode
)
222 case AML_BANK_FIELD_OP
:
223 case AML_INDEX_FIELD_OP
:
229 case AML_INT_NAMEPATH_OP
:
231 * The NamePath is an object reference to an existing object.
232 * Don't enter the name into the namespace, but look it up
235 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, BufferPtr
, ObjectType
,
236 ACPI_IMODE_EXECUTE
, ACPI_NS_SEARCH_PARENT
,
242 /* Special case for Scope(\) -> refers to the Root node */
244 if (Op
&& (Op
->Named
.Node
== AcpiGbl_RootNode
))
246 Node
= Op
->Named
.Node
;
248 Status
= AcpiDsScopeStackPush (Node
, ObjectType
, WalkState
);
249 if (ACPI_FAILURE (Status
))
251 return_ACPI_STATUS (Status
);
257 * The Path is an object reference to an existing object.
258 * Don't enter the name into the namespace, but look it up
261 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, BufferPtr
, ObjectType
,
262 ACPI_IMODE_EXECUTE
, ACPI_NS_SEARCH_PARENT
,
264 if (ACPI_FAILURE (Status
))
266 #ifdef ACPI_ASL_COMPILER
267 if (Status
== AE_NOT_FOUND
)
273 ACPI_ERROR_NAMESPACE (BufferPtr
, Status
);
276 ACPI_ERROR_NAMESPACE (BufferPtr
, Status
);
278 return_ACPI_STATUS (Status
);
283 * We must check to make sure that the target is
284 * one of the opcodes that actually opens a scope
289 case ACPI_TYPE_LOCAL_SCOPE
: /* Scope */
290 case ACPI_TYPE_DEVICE
:
291 case ACPI_TYPE_POWER
:
292 case ACPI_TYPE_PROCESSOR
:
293 case ACPI_TYPE_THERMAL
:
295 /* These are acceptable types */
298 case ACPI_TYPE_INTEGER
:
299 case ACPI_TYPE_STRING
:
300 case ACPI_TYPE_BUFFER
:
303 * These types we will allow, but we will change the type.
304 * This enables some existing code of the form:
307 * Scope (DEB) { ... }
309 ACPI_WARNING ((AE_INFO
,
310 "Type override - [%4.4s] had invalid type (%s) "
311 "for Scope operator, changed to type ANY",
312 AcpiUtGetNodeName (Node
), AcpiUtGetTypeName (Node
->Type
)));
314 Node
->Type
= ACPI_TYPE_ANY
;
315 WalkState
->ScopeInfo
->Common
.Value
= ACPI_TYPE_ANY
;
318 case ACPI_TYPE_METHOD
:
321 * Allow scope change to root during execution of module-level
322 * code. Root is typed METHOD during this time.
324 if ((Node
== AcpiGbl_RootNode
) &&
325 (WalkState
->ParseFlags
& ACPI_PARSE_MODULE_LEVEL
))
330 /*lint -fallthrough */
334 /* All other types are an error */
336 ACPI_ERROR ((AE_INFO
,
337 "Invalid type (%s) for target of "
338 "Scope operator [%4.4s] (Cannot override)",
339 AcpiUtGetTypeName (Node
->Type
), AcpiUtGetNodeName (Node
)));
341 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
347 /* All other opcodes */
349 if (Op
&& Op
->Common
.Node
)
351 /* This op/node was previously entered into the namespace */
353 Node
= Op
->Common
.Node
;
355 if (AcpiNsOpensScope (ObjectType
))
357 Status
= AcpiDsScopeStackPush (Node
, ObjectType
, WalkState
);
358 if (ACPI_FAILURE (Status
))
360 return_ACPI_STATUS (Status
);
364 return_ACPI_STATUS (AE_OK
);
368 * Enter the named type into the internal namespace. We enter the name
369 * as we go downward in the parse tree. Any necessary subobjects that
370 * involve arguments to the opcode must be created as we go back up the
373 * Note: Name may already exist if we are executing a deferred opcode.
375 if (WalkState
->DeferredNode
)
377 /* This name is already in the namespace, get the node */
379 Node
= WalkState
->DeferredNode
;
384 Flags
= ACPI_NS_NO_UPSEARCH
;
385 if (WalkState
->PassNumber
== ACPI_IMODE_EXECUTE
)
387 /* Execution mode, node cannot already exist, node is temporary */
389 Flags
|= ACPI_NS_ERROR_IF_FOUND
;
391 if (!(WalkState
->ParseFlags
& ACPI_PARSE_MODULE_LEVEL
))
393 Flags
|= ACPI_NS_TEMPORARY
;
397 /* Add new entry or lookup existing entry */
399 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, BufferPtr
, ObjectType
,
400 ACPI_IMODE_LOAD_PASS2
, Flags
, WalkState
, &Node
);
402 if (ACPI_SUCCESS (Status
) && (Flags
& ACPI_NS_TEMPORARY
))
404 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
405 "***New Node [%4.4s] %p is temporary\n",
406 AcpiUtGetNodeName (Node
), Node
));
411 if (ACPI_FAILURE (Status
))
413 ACPI_ERROR_NAMESPACE (BufferPtr
, Status
);
414 return_ACPI_STATUS (Status
);
419 /* Create a new op */
421 Op
= AcpiPsAllocOp (WalkState
->Opcode
);
424 return_ACPI_STATUS (AE_NO_MEMORY
);
427 /* Initialize the new op */
431 Op
->Named
.Name
= Node
->Name
.Integer
;
437 * Put the Node in the "op" object that the parser uses, so we
438 * can get it again quickly when this scope is closed
440 Op
->Common
.Node
= Node
;
441 return_ACPI_STATUS (Status
);
445 /*******************************************************************************
447 * FUNCTION: AcpiDsLoad2EndOp
449 * PARAMETERS: WalkState - Current state of the parse tree walk
453 * DESCRIPTION: Ascending callback used during the loading of the namespace,
454 * both control methods and everything else.
456 ******************************************************************************/
460 ACPI_WALK_STATE
*WalkState
)
462 ACPI_PARSE_OBJECT
*Op
;
463 ACPI_STATUS Status
= AE_OK
;
464 ACPI_OBJECT_TYPE ObjectType
;
465 ACPI_NAMESPACE_NODE
*Node
;
466 ACPI_PARSE_OBJECT
*Arg
;
467 ACPI_NAMESPACE_NODE
*NewNode
;
468 #ifndef ACPI_NO_METHOD_EXECUTION
474 ACPI_FUNCTION_TRACE (DsLoad2EndOp
);
477 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Opcode [%s] Op %p State %p\n",
478 WalkState
->OpInfo
->Name
, Op
, WalkState
));
480 /* Check if opcode had an associated namespace object */
482 if (!(WalkState
->OpInfo
->Flags
& AML_NSOBJECT
))
484 return_ACPI_STATUS (AE_OK
);
487 if (Op
->Common
.AmlOpcode
== AML_SCOPE_OP
)
489 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
490 "Ending scope Op=%p State=%p\n", Op
, WalkState
));
493 ObjectType
= WalkState
->OpInfo
->ObjectType
;
496 * Get the Node/name from the earlier lookup
497 * (It was saved in the *op structure)
499 Node
= Op
->Common
.Node
;
502 * Put the Node on the object stack (Contains the ACPI Name of
505 WalkState
->Operands
[0] = (void *) Node
;
506 WalkState
->NumOperands
= 1;
508 /* Pop the scope stack */
510 if (AcpiNsOpensScope (ObjectType
) &&
511 (Op
->Common
.AmlOpcode
!= AML_INT_METHODCALL_OP
))
513 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "(%s) Popping scope for Op %p\n",
514 AcpiUtGetTypeName (ObjectType
), Op
));
516 Status
= AcpiDsScopeStackPop (WalkState
);
517 if (ACPI_FAILURE (Status
))
524 * Named operations are as follows:
529 * AML_CREATEBYTEFIELD
530 * AML_CREATEDWORDFIELD
532 * AML_CREATEQWORDFIELD
533 * AML_CREATEWORDFIELD
551 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
552 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
553 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
), WalkState
, Op
, Node
));
555 /* Decode the opcode */
557 Arg
= Op
->Common
.Value
.Arg
;
559 switch (WalkState
->OpInfo
->Type
)
561 #ifndef ACPI_NO_METHOD_EXECUTION
563 case AML_TYPE_CREATE_FIELD
:
565 * Create the field object, but the field buffer and index must
566 * be evaluated later during the execution phase
568 Status
= AcpiDsCreateBufferField (Op
, WalkState
);
571 case AML_TYPE_NAMED_FIELD
:
573 * If we are executing a method, initialize the field
575 if (WalkState
->MethodNode
)
577 Status
= AcpiDsInitFieldObjects (Op
, WalkState
);
580 switch (Op
->Common
.AmlOpcode
)
582 case AML_INDEX_FIELD_OP
:
584 Status
= AcpiDsCreateIndexField (Op
, (ACPI_HANDLE
) Arg
->Common
.Node
,
588 case AML_BANK_FIELD_OP
:
590 Status
= AcpiDsCreateBankField (Op
, Arg
->Common
.Node
, WalkState
);
595 Status
= AcpiDsCreateField (Op
, Arg
->Common
.Node
, WalkState
);
600 /* All NAMED_FIELD opcodes must be handled above */
605 case AML_TYPE_NAMED_SIMPLE
:
607 Status
= AcpiDsCreateOperands (WalkState
, Arg
);
608 if (ACPI_FAILURE (Status
))
613 switch (Op
->Common
.AmlOpcode
)
615 case AML_PROCESSOR_OP
:
617 Status
= AcpiExCreateProcessor (WalkState
);
620 case AML_POWER_RES_OP
:
622 Status
= AcpiExCreatePowerResource (WalkState
);
627 Status
= AcpiExCreateMutex (WalkState
);
632 Status
= AcpiExCreateEvent (WalkState
);
637 Status
= AcpiExCreateAlias (WalkState
);
648 /* Delete operands */
650 for (i
= 1; i
< WalkState
->NumOperands
; i
++)
652 AcpiUtRemoveReference (WalkState
->Operands
[i
]);
653 WalkState
->Operands
[i
] = NULL
;
657 #endif /* ACPI_NO_METHOD_EXECUTION */
659 case AML_TYPE_NAMED_COMPLEX
:
661 switch (Op
->Common
.AmlOpcode
)
663 #ifndef ACPI_NO_METHOD_EXECUTION
665 case AML_DATA_REGION_OP
:
667 if (Op
->Common
.AmlOpcode
== AML_REGION_OP
)
669 RegionSpace
= (ACPI_ADR_SPACE_TYPE
)
670 ((Op
->Common
.Value
.Arg
)->Common
.Value
.Integer
);
674 RegionSpace
= ACPI_ADR_SPACE_DATA_TABLE
;
678 * The OpRegion is not fully parsed at this time. The only valid
679 * argument is the SpaceId. (We must save the address of the
680 * AML of the address and length operands)
682 * If we have a valid region, initialize it. The namespace is
683 * unlocked at this point.
685 * Need to unlock interpreter if it is locked (if we are running
686 * a control method), in order to allow _REG methods to be run
687 * during AcpiEvInitializeRegion.
689 if (WalkState
->MethodNode
)
692 * Executing a method: initialize the region and unlock
695 Status
= AcpiExCreateRegion (Op
->Named
.Data
, Op
->Named
.Length
,
696 RegionSpace
, WalkState
);
697 if (ACPI_FAILURE (Status
))
699 return_ACPI_STATUS (Status
);
702 AcpiExExitInterpreter ();
705 Status
= AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node
),
707 if (WalkState
->MethodNode
)
709 AcpiExEnterInterpreter ();
712 if (ACPI_FAILURE (Status
))
715 * If AE_NOT_EXIST is returned, it is not fatal
716 * because many regions get created before a handler
717 * is installed for said region.
719 if (AE_NOT_EXIST
== Status
)
728 Status
= AcpiDsCreateNode (WalkState
, Node
, Op
);
733 * MethodOp PkgLength NameString MethodFlags TermList
735 * Note: We must create the method node/object pair as soon as we
736 * see the method declaration. This allows later pass1 parsing
737 * of invocations of the method (need to know the number of
740 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
741 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
742 WalkState
, Op
, Op
->Named
.Node
));
744 if (!AcpiNsGetAttachedObject (Op
->Named
.Node
))
746 WalkState
->Operands
[0] = ACPI_CAST_PTR (void, Op
->Named
.Node
);
747 WalkState
->NumOperands
= 1;
749 Status
= AcpiDsCreateOperands (WalkState
, Op
->Common
.Value
.Arg
);
750 if (ACPI_SUCCESS (Status
))
752 Status
= AcpiExCreateMethod (Op
->Named
.Data
,
753 Op
->Named
.Length
, WalkState
);
755 WalkState
->Operands
[0] = NULL
;
756 WalkState
->NumOperands
= 0;
758 if (ACPI_FAILURE (Status
))
760 return_ACPI_STATUS (Status
);
765 #endif /* ACPI_NO_METHOD_EXECUTION */
769 /* All NAMED_COMPLEX opcodes must be handled above */
774 case AML_CLASS_INTERNAL
:
776 /* case AML_INT_NAMEPATH_OP: */
779 case AML_CLASS_METHOD_CALL
:
781 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
782 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
783 WalkState
, Op
, Node
));
786 * Lookup the method name and save the Node
788 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.String
,
789 ACPI_TYPE_ANY
, ACPI_IMODE_LOAD_PASS2
,
790 ACPI_NS_SEARCH_PARENT
| ACPI_NS_DONT_OPEN_SCOPE
,
791 WalkState
, &(NewNode
));
792 if (ACPI_SUCCESS (Status
))
795 * Make sure that what we found is indeed a method
796 * We didn't search for a method on purpose, to see if the name
799 if (NewNode
->Type
!= ACPI_TYPE_METHOD
)
801 Status
= AE_AML_OPERAND_TYPE
;
804 /* We could put the returned object (Node) on the object stack for
805 * later, but for now, we will put it in the "op" object that the
806 * parser uses, so we can get it again at the end of this scope
808 Op
->Common
.Node
= NewNode
;
812 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.String
, Status
);
824 /* Remove the Node pushed at the very beginning */
826 WalkState
->Operands
[0] = NULL
;
827 WalkState
->NumOperands
= 0;
828 return_ACPI_STATUS (Status
);