sprofalyze fixes
[minix.git] / drivers / acpi / dispatcher / dswload.c
blob1a02f9f1c868640f9c1d12f8694b08adbab6bd7e
1 /******************************************************************************
3 * Module Name: dswload - Dispatcher namespace load callbacks
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
14 * 2. License
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
19 * property rights.
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
38 * conditions are met:
40 * 3. Conditions
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
64 * make.
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
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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
88 * PARTICULAR PURPOSE.
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
97 * LIMITED REMEDY.
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 __DSWLOAD_C__
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acparser.h"
121 #include "amlcode.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
125 #include "acevents.h"
127 #ifdef ACPI_ASL_COMPILER
128 #include "acdisasm.h"
129 #endif
131 #define _COMPONENT ACPI_DISPATCHER
132 ACPI_MODULE_NAME ("dswload")
135 /*******************************************************************************
137 * FUNCTION: AcpiDsInitCallbacks
139 * PARAMETERS: WalkState - Current state of the parse tree walk
140 * PassNumber - 1, 2, or 3
142 * RETURN: Status
144 * DESCRIPTION: Init walk state callbacks
146 ******************************************************************************/
148 ACPI_STATUS
149 AcpiDsInitCallbacks (
150 ACPI_WALK_STATE *WalkState,
151 UINT32 PassNumber)
154 switch (PassNumber)
156 case 1:
157 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
158 ACPI_PARSE_DELETE_TREE;
159 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
160 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
161 break;
163 case 2:
164 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
165 ACPI_PARSE_DELETE_TREE;
166 WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
167 WalkState->AscendingCallback = AcpiDsLoad2EndOp;
168 break;
170 case 3:
171 #ifndef ACPI_NO_METHOD_EXECUTION
172 WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
173 ACPI_PARSE_DELETE_TREE;
174 WalkState->DescendingCallback = AcpiDsExecBeginOp;
175 WalkState->AscendingCallback = AcpiDsExecEndOp;
176 #endif
177 break;
179 default:
180 return (AE_BAD_PARAMETER);
183 return (AE_OK);
187 /*******************************************************************************
189 * FUNCTION: AcpiDsLoad1BeginOp
191 * PARAMETERS: WalkState - Current state of the parse tree walk
192 * OutOp - Where to return op if a new one is created
194 * RETURN: Status
196 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
198 ******************************************************************************/
200 ACPI_STATUS
201 AcpiDsLoad1BeginOp (
202 ACPI_WALK_STATE *WalkState,
203 ACPI_PARSE_OBJECT **OutOp)
205 ACPI_PARSE_OBJECT *Op;
206 ACPI_NAMESPACE_NODE *Node;
207 ACPI_STATUS Status;
208 ACPI_OBJECT_TYPE ObjectType;
209 char *Path;
210 UINT32 Flags;
213 ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
216 Op = WalkState->Op;
217 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
219 /* We are only interested in opcodes that have an associated name */
221 if (Op)
223 if (!(WalkState->OpInfo->Flags & AML_NAMED))
225 *OutOp = Op;
226 return_ACPI_STATUS (AE_OK);
229 /* Check if this object has already been installed in the namespace */
231 if (Op->Common.Node)
233 *OutOp = Op;
234 return_ACPI_STATUS (AE_OK);
238 Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
240 /* Map the raw opcode into an internal object type */
242 ObjectType = WalkState->OpInfo->ObjectType;
244 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
245 "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
247 switch (WalkState->Opcode)
249 case AML_SCOPE_OP:
252 * The target name of the Scope() operator must exist at this point so
253 * that we can actually open the scope to enter new names underneath it.
254 * Allow search-to-root for single namesegs.
256 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
257 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
258 #ifdef ACPI_ASL_COMPILER
259 if (Status == AE_NOT_FOUND)
262 * Table disassembly:
263 * Target of Scope() not found. Generate an External for it, and
264 * insert the name into the namespace.
266 AcpiDmAddToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0);
267 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
268 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
269 WalkState, &Node);
271 #endif
272 if (ACPI_FAILURE (Status))
274 ACPI_ERROR_NAMESPACE (Path, Status);
275 return_ACPI_STATUS (Status);
279 * Check to make sure that the target is
280 * one of the opcodes that actually opens a scope
282 switch (Node->Type)
284 case ACPI_TYPE_ANY:
285 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
286 case ACPI_TYPE_DEVICE:
287 case ACPI_TYPE_POWER:
288 case ACPI_TYPE_PROCESSOR:
289 case ACPI_TYPE_THERMAL:
291 /* These are acceptable types */
292 break;
294 case ACPI_TYPE_INTEGER:
295 case ACPI_TYPE_STRING:
296 case ACPI_TYPE_BUFFER:
299 * These types we will allow, but we will change the type.
300 * This enables some existing code of the form:
302 * Name (DEB, 0)
303 * Scope (DEB) { ... }
305 * Note: silently change the type here. On the second pass,
306 * we will report a warning
308 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
309 "Type override - [%4.4s] had invalid type (%s) "
310 "for Scope operator, changed to type ANY\n",
311 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
313 Node->Type = ACPI_TYPE_ANY;
314 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
315 break;
317 default:
319 /* All other types are an error */
321 ACPI_ERROR ((AE_INFO,
322 "Invalid type (%s) for target of "
323 "Scope operator [%4.4s] (Cannot override)",
324 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
326 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
328 break;
331 default:
333 * For all other named opcodes, we will enter the name into
334 * the namespace.
336 * Setup the search flags.
337 * Since we are entering a name into the namespace, we do not want to
338 * enable the search-to-root upsearch.
340 * There are only two conditions where it is acceptable that the name
341 * already exists:
342 * 1) the Scope() operator can reopen a scoping object that was
343 * previously defined (Scope, Method, Device, etc.)
344 * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
345 * BufferField, or Package), the name of the object is already
346 * in the namespace.
348 if (WalkState->DeferredNode)
350 /* This name is already in the namespace, get the node */
352 Node = WalkState->DeferredNode;
353 Status = AE_OK;
354 break;
358 * If we are executing a method, do not create any namespace objects
359 * during the load phase, only during execution.
361 if (WalkState->MethodNode)
363 Node = NULL;
364 Status = AE_OK;
365 break;
368 Flags = ACPI_NS_NO_UPSEARCH;
369 if ((WalkState->Opcode != AML_SCOPE_OP) &&
370 (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
372 Flags |= ACPI_NS_ERROR_IF_FOUND;
373 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
374 AcpiUtGetTypeName (ObjectType)));
376 else
378 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
379 "[%s] Both Find or Create allowed\n",
380 AcpiUtGetTypeName (ObjectType)));
384 * Enter the named type into the internal namespace. We enter the name
385 * as we go downward in the parse tree. Any necessary subobjects that
386 * involve arguments to the opcode must be created as we go back up the
387 * parse tree later.
389 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
390 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
391 if (ACPI_FAILURE (Status))
393 if (Status == AE_ALREADY_EXISTS)
395 /* The name already exists in this scope */
397 if (Node->Flags & ANOBJ_IS_EXTERNAL)
400 * Allow one create on an object or segment that was
401 * previously declared External
403 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
404 Node->Type = (UINT8) ObjectType;
406 /* Just retyped a node, probably will need to open a scope */
408 if (AcpiNsOpensScope (ObjectType))
410 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
411 if (ACPI_FAILURE (Status))
413 return_ACPI_STATUS (Status);
417 Status = AE_OK;
421 if (ACPI_FAILURE (Status))
423 ACPI_ERROR_NAMESPACE (Path, Status);
424 return_ACPI_STATUS (Status);
427 break;
430 /* Common exit */
432 if (!Op)
434 /* Create a new op */
436 Op = AcpiPsAllocOp (WalkState->Opcode);
437 if (!Op)
439 return_ACPI_STATUS (AE_NO_MEMORY);
443 /* Initialize the op */
445 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
446 Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
447 #endif
449 if (Node)
452 * Put the Node in the "op" object that the parser uses, so we
453 * can get it again quickly when this scope is closed
455 Op->Common.Node = Node;
456 Op->Named.Name = Node->Name.Integer;
459 AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
460 *OutOp = Op;
461 return_ACPI_STATUS (Status);
465 /*******************************************************************************
467 * FUNCTION: AcpiDsLoad1EndOp
469 * PARAMETERS: WalkState - Current state of the parse tree walk
471 * RETURN: Status
473 * DESCRIPTION: Ascending callback used during the loading of the namespace,
474 * both control methods and everything else.
476 ******************************************************************************/
478 ACPI_STATUS
479 AcpiDsLoad1EndOp (
480 ACPI_WALK_STATE *WalkState)
482 ACPI_PARSE_OBJECT *Op;
483 ACPI_OBJECT_TYPE ObjectType;
484 ACPI_STATUS Status = AE_OK;
487 ACPI_FUNCTION_TRACE (DsLoad1EndOp);
490 Op = WalkState->Op;
491 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
493 /* We are only interested in opcodes that have an associated name */
495 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
497 return_ACPI_STATUS (AE_OK);
500 /* Get the object type to determine if we should pop the scope */
502 ObjectType = WalkState->OpInfo->ObjectType;
504 #ifndef ACPI_NO_METHOD_EXECUTION
505 if (WalkState->OpInfo->Flags & AML_FIELD)
508 * If we are executing a method, do not create any namespace objects
509 * during the load phase, only during execution.
511 if (!WalkState->MethodNode)
513 if (WalkState->Opcode == AML_FIELD_OP ||
514 WalkState->Opcode == AML_BANK_FIELD_OP ||
515 WalkState->Opcode == AML_INDEX_FIELD_OP)
517 Status = AcpiDsInitFieldObjects (Op, WalkState);
520 return_ACPI_STATUS (Status);
524 * If we are executing a method, do not create any namespace objects
525 * during the load phase, only during execution.
527 if (!WalkState->MethodNode)
529 if (Op->Common.AmlOpcode == AML_REGION_OP)
531 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
532 (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
533 WalkState);
534 if (ACPI_FAILURE (Status))
536 return_ACPI_STATUS (Status);
539 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
541 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
542 REGION_DATA_TABLE, WalkState);
543 if (ACPI_FAILURE (Status))
545 return_ACPI_STATUS (Status);
549 #endif
551 if (Op->Common.AmlOpcode == AML_NAME_OP)
553 /* For Name opcode, get the object type from the argument */
555 if (Op->Common.Value.Arg)
557 ObjectType = (AcpiPsGetOpcodeInfo (
558 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
560 /* Set node type if we have a namespace node */
562 if (Op->Common.Node)
564 Op->Common.Node->Type = (UINT8) ObjectType;
570 * If we are executing a method, do not create any namespace objects
571 * during the load phase, only during execution.
573 if (!WalkState->MethodNode)
575 if (Op->Common.AmlOpcode == AML_METHOD_OP)
578 * MethodOp PkgLength NameString MethodFlags TermList
580 * Note: We must create the method node/object pair as soon as we
581 * see the method declaration. This allows later pass1 parsing
582 * of invocations of the method (need to know the number of
583 * arguments.)
585 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
586 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
587 WalkState, Op, Op->Named.Node));
589 if (!AcpiNsGetAttachedObject (Op->Named.Node))
591 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
592 WalkState->NumOperands = 1;
594 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
595 if (ACPI_SUCCESS (Status))
597 Status = AcpiExCreateMethod (Op->Named.Data,
598 Op->Named.Length, WalkState);
601 WalkState->Operands[0] = NULL;
602 WalkState->NumOperands = 0;
604 if (ACPI_FAILURE (Status))
606 return_ACPI_STATUS (Status);
612 /* Pop the scope stack (only if loading a table) */
614 if (!WalkState->MethodNode &&
615 AcpiNsOpensScope (ObjectType))
617 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
618 AcpiUtGetTypeName (ObjectType), Op));
620 Status = AcpiDsScopeStackPop (WalkState);
623 return_ACPI_STATUS (Status);
627 /*******************************************************************************
629 * FUNCTION: AcpiDsLoad2BeginOp
631 * PARAMETERS: WalkState - Current state of the parse tree walk
632 * OutOp - Wher to return op if a new one is created
634 * RETURN: Status
636 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
638 ******************************************************************************/
640 ACPI_STATUS
641 AcpiDsLoad2BeginOp (
642 ACPI_WALK_STATE *WalkState,
643 ACPI_PARSE_OBJECT **OutOp)
645 ACPI_PARSE_OBJECT *Op;
646 ACPI_NAMESPACE_NODE *Node;
647 ACPI_STATUS Status;
648 ACPI_OBJECT_TYPE ObjectType;
649 char *BufferPtr;
650 UINT32 Flags;
653 ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
656 Op = WalkState->Op;
657 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
659 if (Op)
661 if ((WalkState->ControlState) &&
662 (WalkState->ControlState->Common.State ==
663 ACPI_CONTROL_CONDITIONAL_EXECUTING))
665 /* We are executing a while loop outside of a method */
667 Status = AcpiDsExecBeginOp (WalkState, OutOp);
668 return_ACPI_STATUS (Status);
671 /* We only care about Namespace opcodes here */
673 if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE) &&
674 (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
675 (!(WalkState->OpInfo->Flags & AML_NAMED)))
677 return_ACPI_STATUS (AE_OK);
680 /* Get the name we are going to enter or lookup in the namespace */
682 if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
684 /* For Namepath op, get the path string */
686 BufferPtr = Op->Common.Value.String;
687 if (!BufferPtr)
689 /* No name, just exit */
691 return_ACPI_STATUS (AE_OK);
694 else
696 /* Get name from the op */
698 BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
701 else
703 /* Get the namestring from the raw AML */
705 BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
708 /* Map the opcode into an internal object type */
710 ObjectType = WalkState->OpInfo->ObjectType;
712 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
713 "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
715 switch (WalkState->Opcode)
717 case AML_FIELD_OP:
718 case AML_BANK_FIELD_OP:
719 case AML_INDEX_FIELD_OP:
721 Node = NULL;
722 Status = AE_OK;
723 break;
725 case AML_INT_NAMEPATH_OP:
727 * The NamePath is an object reference to an existing object.
728 * Don't enter the name into the namespace, but look it up
729 * for use later.
731 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
732 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
733 WalkState, &(Node));
734 break;
736 case AML_SCOPE_OP:
738 /* Special case for Scope(\) -> refers to the Root node */
740 if (Op && (Op->Named.Node == AcpiGbl_RootNode))
742 Node = Op->Named.Node;
744 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
745 if (ACPI_FAILURE (Status))
747 return_ACPI_STATUS (Status);
750 else
753 * The Path is an object reference to an existing object.
754 * Don't enter the name into the namespace, but look it up
755 * for use later.
757 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
758 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
759 WalkState, &(Node));
760 if (ACPI_FAILURE (Status))
762 #ifdef ACPI_ASL_COMPILER
763 if (Status == AE_NOT_FOUND)
765 Status = AE_OK;
767 else
769 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
771 #else
772 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
773 #endif
774 return_ACPI_STATUS (Status);
779 * We must check to make sure that the target is
780 * one of the opcodes that actually opens a scope
782 switch (Node->Type)
784 case ACPI_TYPE_ANY:
785 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
786 case ACPI_TYPE_DEVICE:
787 case ACPI_TYPE_POWER:
788 case ACPI_TYPE_PROCESSOR:
789 case ACPI_TYPE_THERMAL:
791 /* These are acceptable types */
792 break;
794 case ACPI_TYPE_INTEGER:
795 case ACPI_TYPE_STRING:
796 case ACPI_TYPE_BUFFER:
799 * These types we will allow, but we will change the type.
800 * This enables some existing code of the form:
802 * Name (DEB, 0)
803 * Scope (DEB) { ... }
805 ACPI_WARNING ((AE_INFO,
806 "Type override - [%4.4s] had invalid type (%s) "
807 "for Scope operator, changed to type ANY\n",
808 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
810 Node->Type = ACPI_TYPE_ANY;
811 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
812 break;
814 default:
816 /* All other types are an error */
818 ACPI_ERROR ((AE_INFO,
819 "Invalid type (%s) for target of "
820 "Scope operator [%4.4s] (Cannot override)",
821 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
823 return (AE_AML_OPERAND_TYPE);
825 break;
827 default:
829 /* All other opcodes */
831 if (Op && Op->Common.Node)
833 /* This op/node was previously entered into the namespace */
835 Node = Op->Common.Node;
837 if (AcpiNsOpensScope (ObjectType))
839 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
840 if (ACPI_FAILURE (Status))
842 return_ACPI_STATUS (Status);
846 return_ACPI_STATUS (AE_OK);
850 * Enter the named type into the internal namespace. We enter the name
851 * as we go downward in the parse tree. Any necessary subobjects that
852 * involve arguments to the opcode must be created as we go back up the
853 * parse tree later.
855 * Note: Name may already exist if we are executing a deferred opcode.
857 if (WalkState->DeferredNode)
859 /* This name is already in the namespace, get the node */
861 Node = WalkState->DeferredNode;
862 Status = AE_OK;
863 break;
866 Flags = ACPI_NS_NO_UPSEARCH;
867 if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
869 /* Execution mode, node cannot already exist, node is temporary */
871 Flags |= ACPI_NS_ERROR_IF_FOUND;
873 if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
875 Flags |= ACPI_NS_TEMPORARY;
879 /* Add new entry or lookup existing entry */
881 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
882 ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
884 if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
886 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
887 "***New Node [%4.4s] %p is temporary\n",
888 AcpiUtGetNodeName (Node), Node));
890 break;
893 if (ACPI_FAILURE (Status))
895 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
896 return_ACPI_STATUS (Status);
899 if (!Op)
901 /* Create a new op */
903 Op = AcpiPsAllocOp (WalkState->Opcode);
904 if (!Op)
906 return_ACPI_STATUS (AE_NO_MEMORY);
909 /* Initialize the new op */
911 if (Node)
913 Op->Named.Name = Node->Name.Integer;
915 *OutOp = Op;
919 * Put the Node in the "op" object that the parser uses, so we
920 * can get it again quickly when this scope is closed
922 Op->Common.Node = Node;
923 return_ACPI_STATUS (Status);
927 /*******************************************************************************
929 * FUNCTION: AcpiDsLoad2EndOp
931 * PARAMETERS: WalkState - Current state of the parse tree walk
933 * RETURN: Status
935 * DESCRIPTION: Ascending callback used during the loading of the namespace,
936 * both control methods and everything else.
938 ******************************************************************************/
940 ACPI_STATUS
941 AcpiDsLoad2EndOp (
942 ACPI_WALK_STATE *WalkState)
944 ACPI_PARSE_OBJECT *Op;
945 ACPI_STATUS Status = AE_OK;
946 ACPI_OBJECT_TYPE ObjectType;
947 ACPI_NAMESPACE_NODE *Node;
948 ACPI_PARSE_OBJECT *Arg;
949 ACPI_NAMESPACE_NODE *NewNode;
950 #ifndef ACPI_NO_METHOD_EXECUTION
951 UINT32 i;
952 UINT8 RegionSpace;
953 #endif
956 ACPI_FUNCTION_TRACE (DsLoad2EndOp);
958 Op = WalkState->Op;
959 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
960 WalkState->OpInfo->Name, Op, WalkState));
962 /* Check if opcode had an associated namespace object */
964 if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
966 return_ACPI_STATUS (AE_OK);
969 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
971 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
972 "Ending scope Op=%p State=%p\n", Op, WalkState));
975 ObjectType = WalkState->OpInfo->ObjectType;
978 * Get the Node/name from the earlier lookup
979 * (It was saved in the *op structure)
981 Node = Op->Common.Node;
984 * Put the Node on the object stack (Contains the ACPI Name of
985 * this object)
987 WalkState->Operands[0] = (void *) Node;
988 WalkState->NumOperands = 1;
990 /* Pop the scope stack */
992 if (AcpiNsOpensScope (ObjectType) &&
993 (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
995 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
996 AcpiUtGetTypeName (ObjectType), Op));
998 Status = AcpiDsScopeStackPop (WalkState);
999 if (ACPI_FAILURE (Status))
1001 goto Cleanup;
1006 * Named operations are as follows:
1008 * AML_ALIAS
1009 * AML_BANKFIELD
1010 * AML_CREATEBITFIELD
1011 * AML_CREATEBYTEFIELD
1012 * AML_CREATEDWORDFIELD
1013 * AML_CREATEFIELD
1014 * AML_CREATEQWORDFIELD
1015 * AML_CREATEWORDFIELD
1016 * AML_DATA_REGION
1017 * AML_DEVICE
1018 * AML_EVENT
1019 * AML_FIELD
1020 * AML_INDEXFIELD
1021 * AML_METHOD
1022 * AML_METHODCALL
1023 * AML_MUTEX
1024 * AML_NAME
1025 * AML_NAMEDFIELD
1026 * AML_OPREGION
1027 * AML_POWERRES
1028 * AML_PROCESSOR
1029 * AML_SCOPE
1030 * AML_THERMALZONE
1033 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1034 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
1035 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
1037 /* Decode the opcode */
1039 Arg = Op->Common.Value.Arg;
1041 switch (WalkState->OpInfo->Type)
1043 #ifndef ACPI_NO_METHOD_EXECUTION
1045 case AML_TYPE_CREATE_FIELD:
1047 * Create the field object, but the field buffer and index must
1048 * be evaluated later during the execution phase
1050 Status = AcpiDsCreateBufferField (Op, WalkState);
1051 break;
1054 case AML_TYPE_NAMED_FIELD:
1056 * If we are executing a method, initialize the field
1058 if (WalkState->MethodNode)
1060 Status = AcpiDsInitFieldObjects (Op, WalkState);
1063 switch (Op->Common.AmlOpcode)
1065 case AML_INDEX_FIELD_OP:
1067 Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
1068 WalkState);
1069 break;
1071 case AML_BANK_FIELD_OP:
1073 Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
1074 break;
1076 case AML_FIELD_OP:
1078 Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
1079 break;
1081 default:
1082 /* All NAMED_FIELD opcodes must be handled above */
1083 break;
1085 break;
1088 case AML_TYPE_NAMED_SIMPLE:
1090 Status = AcpiDsCreateOperands (WalkState, Arg);
1091 if (ACPI_FAILURE (Status))
1093 goto Cleanup;
1096 switch (Op->Common.AmlOpcode)
1098 case AML_PROCESSOR_OP:
1100 Status = AcpiExCreateProcessor (WalkState);
1101 break;
1103 case AML_POWER_RES_OP:
1105 Status = AcpiExCreatePowerResource (WalkState);
1106 break;
1108 case AML_MUTEX_OP:
1110 Status = AcpiExCreateMutex (WalkState);
1111 break;
1113 case AML_EVENT_OP:
1115 Status = AcpiExCreateEvent (WalkState);
1116 break;
1119 case AML_ALIAS_OP:
1121 Status = AcpiExCreateAlias (WalkState);
1122 break;
1124 default:
1125 /* Unknown opcode */
1127 Status = AE_OK;
1128 goto Cleanup;
1131 /* Delete operands */
1133 for (i = 1; i < WalkState->NumOperands; i++)
1135 AcpiUtRemoveReference (WalkState->Operands[i]);
1136 WalkState->Operands[i] = NULL;
1139 break;
1140 #endif /* ACPI_NO_METHOD_EXECUTION */
1142 case AML_TYPE_NAMED_COMPLEX:
1144 switch (Op->Common.AmlOpcode)
1146 #ifndef ACPI_NO_METHOD_EXECUTION
1147 case AML_REGION_OP:
1148 case AML_DATA_REGION_OP:
1150 if (Op->Common.AmlOpcode == AML_REGION_OP)
1152 RegionSpace = (ACPI_ADR_SPACE_TYPE)
1153 ((Op->Common.Value.Arg)->Common.Value.Integer);
1155 else
1157 RegionSpace = REGION_DATA_TABLE;
1161 * The OpRegion is not fully parsed at this time. The only valid
1162 * argument is the SpaceId. (We must save the address of the
1163 * AML of the address and length operands)
1165 * If we have a valid region, initialize it. The namespace is
1166 * unlocked at this point.
1168 * Need to unlock interpreter if it is locked (if we are running
1169 * a control method), in order to allow _REG methods to be run
1170 * during AcpiEvInitializeRegion.
1172 if (WalkState->MethodNode)
1175 * Executing a method: initialize the region and unlock
1176 * the interpreter
1178 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
1179 RegionSpace, WalkState);
1180 if (ACPI_FAILURE (Status))
1182 return (Status);
1185 AcpiExExitInterpreter ();
1188 Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
1189 FALSE);
1190 if (WalkState->MethodNode)
1192 AcpiExEnterInterpreter ();
1195 if (ACPI_FAILURE (Status))
1198 * If AE_NOT_EXIST is returned, it is not fatal
1199 * because many regions get created before a handler
1200 * is installed for said region.
1202 if (AE_NOT_EXIST == Status)
1204 Status = AE_OK;
1207 break;
1210 case AML_NAME_OP:
1212 Status = AcpiDsCreateNode (WalkState, Node, Op);
1213 break;
1216 case AML_METHOD_OP:
1218 * MethodOp PkgLength NameString MethodFlags TermList
1220 * Note: We must create the method node/object pair as soon as we
1221 * see the method declaration. This allows later pass1 parsing
1222 * of invocations of the method (need to know the number of
1223 * arguments.)
1225 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1226 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
1227 WalkState, Op, Op->Named.Node));
1229 if (!AcpiNsGetAttachedObject (Op->Named.Node))
1231 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
1232 WalkState->NumOperands = 1;
1234 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1235 if (ACPI_SUCCESS (Status))
1237 Status = AcpiExCreateMethod (Op->Named.Data,
1238 Op->Named.Length, WalkState);
1240 WalkState->Operands[0] = NULL;
1241 WalkState->NumOperands = 0;
1243 if (ACPI_FAILURE (Status))
1245 return_ACPI_STATUS (Status);
1248 break;
1250 #endif /* ACPI_NO_METHOD_EXECUTION */
1252 default:
1253 /* All NAMED_COMPLEX opcodes must be handled above */
1254 break;
1256 break;
1259 case AML_CLASS_INTERNAL:
1261 /* case AML_INT_NAMEPATH_OP: */
1262 break;
1265 case AML_CLASS_METHOD_CALL:
1267 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1268 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
1269 WalkState, Op, Node));
1272 * Lookup the method name and save the Node
1274 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
1275 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
1276 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1277 WalkState, &(NewNode));
1278 if (ACPI_SUCCESS (Status))
1281 * Make sure that what we found is indeed a method
1282 * We didn't search for a method on purpose, to see if the name
1283 * would resolve
1285 if (NewNode->Type != ACPI_TYPE_METHOD)
1287 Status = AE_AML_OPERAND_TYPE;
1290 /* We could put the returned object (Node) on the object stack for
1291 * later, but for now, we will put it in the "op" object that the
1292 * parser uses, so we can get it again at the end of this scope
1294 Op->Common.Node = NewNode;
1296 else
1298 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
1300 break;
1303 default:
1304 break;
1307 Cleanup:
1309 /* Remove the Node pushed at the very beginning */
1311 WalkState->Operands[0] = NULL;
1312 WalkState->NumOperands = 0;
1313 return_ACPI_STATUS (Status);