xref: /titanic_41/usr/src/uts/intel/io/acpica/dispatcher/dswload.c (revision e802abbda8c322f24d47835734f4a793ef15ddc8)
1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *              $Revision: 1.120 $
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 #define __DSWLOAD_C__
118 
119 #include "acpi.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"
126 
127 #ifdef ACPI_ASL_COMPILER
128 #include "acdisasm.h"
129 #endif
130 
131 #define _COMPONENT          ACPI_DISPATCHER
132         ACPI_MODULE_NAME    ("dswload")
133 
134 
135 /*******************************************************************************
136  *
137  * FUNCTION:    AcpiDsInitCallbacks
138  *
139  * PARAMETERS:  WalkState       - Current state of the parse tree walk
140  *              PassNumber      - 1, 2, or 3
141  *
142  * RETURN:      Status
143  *
144  * DESCRIPTION: Init walk state callbacks
145  *
146  ******************************************************************************/
147 
148 ACPI_STATUS
149 AcpiDsInitCallbacks (
150     ACPI_WALK_STATE         *WalkState,
151     UINT32                  PassNumber)
152 {
153 
154     switch (PassNumber)
155     {
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;
162 
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;
169 
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;
178 
179     default:
180         return (AE_BAD_PARAMETER);
181     }
182 
183     return (AE_OK);
184 }
185 
186 
187 /*******************************************************************************
188  *
189  * FUNCTION:    AcpiDsLoad1BeginOp
190  *
191  * PARAMETERS:  WalkState       - Current state of the parse tree walk
192  *              OutOp           - Where to return op if a new one is created
193  *
194  * RETURN:      Status
195  *
196  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
197  *
198  ******************************************************************************/
199 
200 ACPI_STATUS
201 AcpiDsLoad1BeginOp (
202     ACPI_WALK_STATE         *WalkState,
203     ACPI_PARSE_OBJECT       **OutOp)
204 {
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;
211 
212 
213     ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
214 
215 
216     Op = WalkState->Op;
217     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
218 
219     /* We are only interested in opcodes that have an associated name */
220 
221     if (Op)
222     {
223         if (!(WalkState->OpInfo->Flags & AML_NAMED))
224         {
225             *OutOp = Op;
226             return_ACPI_STATUS (AE_OK);
227         }
228 
229         /* Check if this object has already been installed in the namespace */
230 
231         if (Op->Common.Node)
232         {
233             *OutOp = Op;
234             return_ACPI_STATUS (AE_OK);
235         }
236     }
237 
238     Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
239 
240     /* Map the raw opcode into an internal object type */
241 
242     ObjectType = WalkState->OpInfo->ObjectType;
243 
244     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
245         "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
246 
247     switch (WalkState->Opcode)
248     {
249     case AML_SCOPE_OP:
250 
251         /*
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.
255          */
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)
260         {
261             /*
262              * Table disassembly:
263              * Target of Scope() not found. Generate an External for it, and
264              * insert the name into the namespace.
265              */
266             AcpiDmAddToExternalList (Path, ACPI_TYPE_DEVICE, 0);
267             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
268                        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
269                        WalkState, &Node);
270         }
271 #endif
272         if (ACPI_FAILURE (Status))
273         {
274             ACPI_ERROR_NAMESPACE (Path, Status);
275             return_ACPI_STATUS (Status);
276         }
277 
278         /*
279          * Check to make sure that the target is
280          * one of the opcodes that actually opens a scope
281          */
282         switch (Node->Type)
283         {
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:
290 
291             /* These are acceptable types */
292             break;
293 
294         case ACPI_TYPE_INTEGER:
295         case ACPI_TYPE_STRING:
296         case ACPI_TYPE_BUFFER:
297 
298             /*
299              * These types we will allow, but we will change the type. This
300              * enables some existing code of the form:
301              *
302              *  Name (DEB, 0)
303              *  Scope (DEB) { ... }
304              *
305              * Note: silently change the type here. On the second pass, we will report
306              * a warning
307              */
308             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
309                 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
310                 Path, AcpiUtGetTypeName (Node->Type)));
311 
312             Node->Type = ACPI_TYPE_ANY;
313             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
314             break;
315 
316         default:
317 
318             /* All other types are an error */
319 
320             ACPI_ERROR ((AE_INFO,
321                 "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)",
322                 AcpiUtGetTypeName (Node->Type), Path));
323 
324             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
325         }
326         break;
327 
328 
329     default:
330         /*
331          * For all other named opcodes, we will enter the name into
332          * the namespace.
333          *
334          * Setup the search flags.
335          * Since we are entering a name into the namespace, we do not want to
336          * enable the search-to-root upsearch.
337          *
338          * There are only two conditions where it is acceptable that the name
339          * already exists:
340          *    1) the Scope() operator can reopen a scoping object that was
341          *       previously defined (Scope, Method, Device, etc.)
342          *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
343          *       BufferField, or Package), the name of the object is already
344          *       in the namespace.
345          */
346         if (WalkState->DeferredNode)
347         {
348             /* This name is already in the namespace, get the node */
349 
350             Node = WalkState->DeferredNode;
351             Status = AE_OK;
352             break;
353         }
354 
355         /*
356          * If we are executing a method, do not create any namespace objects
357          * during the load phase, only during execution.
358          */
359         if (WalkState->MethodNode)
360         {
361             Node = NULL;
362             Status = AE_OK;
363             break;
364         }
365 
366         Flags = ACPI_NS_NO_UPSEARCH;
367         if ((WalkState->Opcode != AML_SCOPE_OP) &&
368             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
369         {
370             Flags |= ACPI_NS_ERROR_IF_FOUND;
371             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
372                     AcpiUtGetTypeName (ObjectType)));
373         }
374         else
375         {
376             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
377                 "[%s] Both Find or Create allowed\n",
378                     AcpiUtGetTypeName (ObjectType)));
379         }
380 
381         /*
382          * Enter the named type into the internal namespace. We enter the name
383          * as we go downward in the parse tree. Any necessary subobjects that
384          * involve arguments to the opcode must be created as we go back up the
385          * parse tree later.
386          */
387         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
388                         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
389         if (ACPI_FAILURE (Status))
390         {
391             if (Status == AE_ALREADY_EXISTS)
392             {
393                 /* The name already exists in this scope */
394 
395                 if (Node->Flags & ANOBJ_IS_EXTERNAL)
396                 {
397                     /*
398                      * Allow one create on an object or segment that was
399                      * previously declared External
400                      */
401                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
402                     Node->Type = (UINT8) ObjectType;
403 
404                     /* Just retyped a node, probably will need to open a scope */
405 
406                     if (AcpiNsOpensScope (ObjectType))
407                     {
408                         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
409                         if (ACPI_FAILURE (Status))
410                         {
411                             return_ACPI_STATUS (Status);
412                         }
413                     }
414 
415                     Status = AE_OK;
416                 }
417             }
418 
419             if (ACPI_FAILURE (Status))
420             {
421                 ACPI_ERROR_NAMESPACE (Path, Status);
422                 return_ACPI_STATUS (Status);
423             }
424         }
425         break;
426     }
427 
428     /* Common exit */
429 
430     if (!Op)
431     {
432         /* Create a new op */
433 
434         Op = AcpiPsAllocOp (WalkState->Opcode);
435         if (!Op)
436         {
437             return_ACPI_STATUS (AE_NO_MEMORY);
438         }
439     }
440 
441     /* Initialize the op */
442 
443 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
444     Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
445 #endif
446 
447     if (Node)
448     {
449         /*
450          * Put the Node in the "op" object that the parser uses, so we
451          * can get it again quickly when this scope is closed
452          */
453         Op->Common.Node = Node;
454         Op->Named.Name = Node->Name.Integer;
455     }
456 
457     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
458     *OutOp = Op;
459     return_ACPI_STATUS (Status);
460 }
461 
462 
463 /*******************************************************************************
464  *
465  * FUNCTION:    AcpiDsLoad1EndOp
466  *
467  * PARAMETERS:  WalkState       - Current state of the parse tree walk
468  *
469  * RETURN:      Status
470  *
471  * DESCRIPTION: Ascending callback used during the loading of the namespace,
472  *              both control methods and everything else.
473  *
474  ******************************************************************************/
475 
476 ACPI_STATUS
477 AcpiDsLoad1EndOp (
478     ACPI_WALK_STATE         *WalkState)
479 {
480     ACPI_PARSE_OBJECT       *Op;
481     ACPI_OBJECT_TYPE        ObjectType;
482     ACPI_STATUS             Status = AE_OK;
483 
484 
485     ACPI_FUNCTION_TRACE (DsLoad1EndOp);
486 
487 
488     Op = WalkState->Op;
489     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
490 
491     /* We are only interested in opcodes that have an associated name */
492 
493     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
494     {
495         return_ACPI_STATUS (AE_OK);
496     }
497 
498     /* Get the object type to determine if we should pop the scope */
499 
500     ObjectType = WalkState->OpInfo->ObjectType;
501 
502 #ifndef ACPI_NO_METHOD_EXECUTION
503     if (WalkState->OpInfo->Flags & AML_FIELD)
504     {
505         /*
506          * If we are executing a method, do not create any namespace objects
507          * during the load phase, only during execution.
508          */
509         if (!WalkState->MethodNode)
510         {
511             if (WalkState->Opcode == AML_FIELD_OP          ||
512                 WalkState->Opcode == AML_BANK_FIELD_OP     ||
513                 WalkState->Opcode == AML_INDEX_FIELD_OP)
514             {
515                 Status = AcpiDsInitFieldObjects (Op, WalkState);
516             }
517         }
518         return_ACPI_STATUS (Status);
519     }
520 
521     /*
522      * If we are executing a method, do not create any namespace objects
523      * during the load phase, only during execution.
524      */
525     if (!WalkState->MethodNode)
526     {
527         if (Op->Common.AmlOpcode == AML_REGION_OP)
528         {
529             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
530                         (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
531                         WalkState);
532             if (ACPI_FAILURE (Status))
533             {
534                 return_ACPI_STATUS (Status);
535             }
536         }
537         else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
538         {
539             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
540                         REGION_DATA_TABLE, WalkState);
541             if (ACPI_FAILURE (Status))
542             {
543                 return_ACPI_STATUS (Status);
544             }
545         }
546     }
547 #endif
548 
549     if (Op->Common.AmlOpcode == AML_NAME_OP)
550     {
551         /* For Name opcode, get the object type from the argument */
552 
553         if (Op->Common.Value.Arg)
554         {
555             ObjectType = (AcpiPsGetOpcodeInfo (
556                 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
557 
558             /* Set node type if we have a namespace node */
559 
560             if (Op->Common.Node)
561             {
562                 Op->Common.Node->Type = (UINT8) ObjectType;
563             }
564         }
565     }
566 
567     /*
568      * If we are executing a method, do not create any namespace objects
569      * during the load phase, only during execution.
570      */
571     if (!WalkState->MethodNode)
572     {
573         if (Op->Common.AmlOpcode == AML_METHOD_OP)
574         {
575             /*
576              * MethodOp PkgLength NameString MethodFlags TermList
577              *
578              * Note: We must create the method node/object pair as soon as we
579              * see the method declaration. This allows later pass1 parsing
580              * of invocations of the method (need to know the number of
581              * arguments.)
582              */
583             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
584                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
585                 WalkState, Op, Op->Named.Node));
586 
587             if (!AcpiNsGetAttachedObject (Op->Named.Node))
588             {
589                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
590                 WalkState->NumOperands = 1;
591 
592                 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
593                 if (ACPI_SUCCESS (Status))
594                 {
595                     Status = AcpiExCreateMethod (Op->Named.Data,
596                                         Op->Named.Length, WalkState);
597                 }
598 
599                 WalkState->Operands[0] = NULL;
600                 WalkState->NumOperands = 0;
601 
602                 if (ACPI_FAILURE (Status))
603                 {
604                     return_ACPI_STATUS (Status);
605                 }
606             }
607         }
608     }
609 
610     /* Pop the scope stack (only if loading a table) */
611 
612     if (!WalkState->MethodNode &&
613         AcpiNsOpensScope (ObjectType))
614     {
615         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
616             AcpiUtGetTypeName (ObjectType), Op));
617 
618         Status = AcpiDsScopeStackPop (WalkState);
619     }
620 
621     return_ACPI_STATUS (Status);
622 }
623 
624 
625 /*******************************************************************************
626  *
627  * FUNCTION:    AcpiDsLoad2BeginOp
628  *
629  * PARAMETERS:  WalkState       - Current state of the parse tree walk
630  *              OutOp           - Wher to return op if a new one is created
631  *
632  * RETURN:      Status
633  *
634  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
635  *
636  ******************************************************************************/
637 
638 ACPI_STATUS
639 AcpiDsLoad2BeginOp (
640     ACPI_WALK_STATE         *WalkState,
641     ACPI_PARSE_OBJECT       **OutOp)
642 {
643     ACPI_PARSE_OBJECT       *Op;
644     ACPI_NAMESPACE_NODE     *Node;
645     ACPI_STATUS             Status;
646     ACPI_OBJECT_TYPE        ObjectType;
647     char                    *BufferPtr;
648     UINT32                  Flags;
649 
650 
651     ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
652 
653 
654     Op = WalkState->Op;
655     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
656 
657     if (Op)
658     {
659         if ((WalkState->ControlState) &&
660             (WalkState->ControlState->Common.State ==
661                 ACPI_CONTROL_CONDITIONAL_EXECUTING))
662         {
663             /* We are executing a while loop outside of a method */
664 
665             Status = AcpiDsExecBeginOp (WalkState, OutOp);
666             return_ACPI_STATUS (Status);
667         }
668 
669         /* We only care about Namespace opcodes here */
670 
671         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
672               (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
673             (!(WalkState->OpInfo->Flags & AML_NAMED)))
674         {
675 #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
676             if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
677                 (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
678             {
679                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
680                     "Begin/EXEC: %s (fl %8.8X)\n", WalkState->OpInfo->Name,
681                     WalkState->OpInfo->Flags));
682 
683                 /* Executing a type1 or type2 opcode outside of a method */
684 
685                 Status = AcpiDsExecBeginOp (WalkState, OutOp);
686                 return_ACPI_STATUS (Status);
687             }
688 #endif
689             return_ACPI_STATUS (AE_OK);
690         }
691 
692         /* Get the name we are going to enter or lookup in the namespace */
693 
694         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
695         {
696             /* For Namepath op, get the path string */
697 
698             BufferPtr = Op->Common.Value.String;
699             if (!BufferPtr)
700             {
701                 /* No name, just exit */
702 
703                 return_ACPI_STATUS (AE_OK);
704             }
705         }
706         else
707         {
708             /* Get name from the op */
709 
710             BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
711         }
712     }
713     else
714     {
715         /* Get the namestring from the raw AML */
716 
717         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
718     }
719 
720     /* Map the opcode into an internal object type */
721 
722     ObjectType = WalkState->OpInfo->ObjectType;
723 
724     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
725         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
726 
727     switch (WalkState->Opcode)
728     {
729     case AML_FIELD_OP:
730     case AML_BANK_FIELD_OP:
731     case AML_INDEX_FIELD_OP:
732 
733         Node = NULL;
734         Status = AE_OK;
735         break;
736 
737     case AML_INT_NAMEPATH_OP:
738         /*
739          * The NamePath is an object reference to an existing object.
740          * Don't enter the name into the namespace, but look it up
741          * for use later.
742          */
743         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
744                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
745                         WalkState, &(Node));
746         break;
747 
748     case AML_SCOPE_OP:
749         /*
750          * The Path is an object reference to an existing object.
751          * Don't enter the name into the namespace, but look it up
752          * for use later.
753          */
754         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
755                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
756                         WalkState, &(Node));
757         if (ACPI_FAILURE (Status))
758         {
759 #ifdef ACPI_ASL_COMPILER
760             if (Status == AE_NOT_FOUND)
761             {
762                 Status = AE_OK;
763             }
764             else
765             {
766                 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
767             }
768 #else
769             ACPI_ERROR_NAMESPACE (BufferPtr, Status);
770 #endif
771             return_ACPI_STATUS (Status);
772         }
773 
774         /*
775          * We must check to make sure that the target is
776          * one of the opcodes that actually opens a scope
777          */
778         switch (Node->Type)
779         {
780         case ACPI_TYPE_ANY:
781         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
782         case ACPI_TYPE_DEVICE:
783         case ACPI_TYPE_POWER:
784         case ACPI_TYPE_PROCESSOR:
785         case ACPI_TYPE_THERMAL:
786 
787             /* These are acceptable types */
788             break;
789 
790         case ACPI_TYPE_INTEGER:
791         case ACPI_TYPE_STRING:
792         case ACPI_TYPE_BUFFER:
793 
794             /*
795              * These types we will allow, but we will change the type. This
796              * enables some existing code of the form:
797              *
798              *  Name (DEB, 0)
799              *  Scope (DEB) { ... }
800              */
801             ACPI_WARNING ((AE_INFO,
802                 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)",
803                 BufferPtr, AcpiUtGetTypeName (Node->Type)));
804 
805             Node->Type = ACPI_TYPE_ANY;
806             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
807             break;
808 
809         default:
810 
811             /* All other types are an error */
812 
813             ACPI_ERROR ((AE_INFO,
814                 "Invalid type (%s) for target of Scope operator [%4.4s]",
815                 AcpiUtGetTypeName (Node->Type), BufferPtr));
816 
817             return (AE_AML_OPERAND_TYPE);
818         }
819         break;
820 
821     default:
822 
823         /* All other opcodes */
824 
825         if (Op && Op->Common.Node)
826         {
827             /* This op/node was previously entered into the namespace */
828 
829             Node = Op->Common.Node;
830 
831             if (AcpiNsOpensScope (ObjectType))
832             {
833                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
834                 if (ACPI_FAILURE (Status))
835                 {
836                     return_ACPI_STATUS (Status);
837                 }
838             }
839 
840             return_ACPI_STATUS (AE_OK);
841         }
842 
843         /*
844          * Enter the named type into the internal namespace. We enter the name
845          * as we go downward in the parse tree. Any necessary subobjects that
846          * involve arguments to the opcode must be created as we go back up the
847          * parse tree later.
848          *
849          * Note: Name may already exist if we are executing a deferred opcode.
850          */
851         if (WalkState->DeferredNode)
852         {
853             /* This name is already in the namespace, get the node */
854 
855             Node = WalkState->DeferredNode;
856             Status = AE_OK;
857             break;
858         }
859 
860         Flags = ACPI_NS_NO_UPSEARCH;
861         if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
862         {
863             /* Execution mode, node cannot already exist, node is temporary */
864 
865             Flags |= (ACPI_NS_ERROR_IF_FOUND | ACPI_NS_TEMPORARY);
866         }
867 
868         /* Add new entry or lookup existing entry */
869 
870         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
871                     ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
872 
873         if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
874         {
875             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
876                 "***New Node [%4.4s] %p is temporary\n",
877                 AcpiUtGetNodeName (Node), Node));
878         }
879         break;
880     }
881 
882     if (ACPI_FAILURE (Status))
883     {
884         ACPI_ERROR_NAMESPACE (BufferPtr, Status);
885         return_ACPI_STATUS (Status);
886     }
887 
888     if (!Op)
889     {
890         /* Create a new op */
891 
892         Op = AcpiPsAllocOp (WalkState->Opcode);
893         if (!Op)
894         {
895             return_ACPI_STATUS (AE_NO_MEMORY);
896         }
897 
898         /* Initialize the new op */
899 
900         if (Node)
901         {
902             Op->Named.Name = Node->Name.Integer;
903         }
904         *OutOp = Op;
905     }
906 
907     /*
908      * Put the Node in the "op" object that the parser uses, so we
909      * can get it again quickly when this scope is closed
910      */
911     Op->Common.Node = Node;
912     return_ACPI_STATUS (Status);
913 }
914 
915 
916 /*******************************************************************************
917  *
918  * FUNCTION:    AcpiDsLoad2EndOp
919  *
920  * PARAMETERS:  WalkState       - Current state of the parse tree walk
921  *
922  * RETURN:      Status
923  *
924  * DESCRIPTION: Ascending callback used during the loading of the namespace,
925  *              both control methods and everything else.
926  *
927  ******************************************************************************/
928 
929 ACPI_STATUS
930 AcpiDsLoad2EndOp (
931     ACPI_WALK_STATE         *WalkState)
932 {
933     ACPI_PARSE_OBJECT       *Op;
934     ACPI_STATUS             Status = AE_OK;
935     ACPI_OBJECT_TYPE        ObjectType;
936     ACPI_NAMESPACE_NODE     *Node;
937     ACPI_PARSE_OBJECT       *Arg;
938     ACPI_NAMESPACE_NODE     *NewNode;
939 #ifndef ACPI_NO_METHOD_EXECUTION
940     UINT32                  i;
941     UINT8                   RegionSpace;
942 #endif
943 
944 
945     ACPI_FUNCTION_TRACE (DsLoad2EndOp);
946 
947     Op = WalkState->Op;
948     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
949             WalkState->OpInfo->Name, Op, WalkState));
950 
951     /* Check if opcode had an associated namespace object */
952 
953     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
954     {
955 #ifndef ACPI_NO_METHOD_EXECUTION
956 #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
957         /* No namespace object. Executable opcode? */
958 
959         if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
960             (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
961         {
962             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
963                 "End/EXEC:   %s (fl %8.8X)\n", WalkState->OpInfo->Name,
964                 WalkState->OpInfo->Flags));
965 
966             /* Executing a type1 or type2 opcode outside of a method */
967 
968             Status = AcpiDsExecEndOp (WalkState);
969             return_ACPI_STATUS (Status);
970         }
971 #endif
972 #endif
973         return_ACPI_STATUS (AE_OK);
974     }
975 
976     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
977     {
978         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
979             "Ending scope Op=%p State=%p\n", Op, WalkState));
980     }
981 
982     ObjectType = WalkState->OpInfo->ObjectType;
983 
984     /*
985      * Get the Node/name from the earlier lookup
986      * (It was saved in the *op structure)
987      */
988     Node = Op->Common.Node;
989 
990     /*
991      * Put the Node on the object stack (Contains the ACPI Name of
992      * this object)
993      */
994     WalkState->Operands[0] = (void *) Node;
995     WalkState->NumOperands = 1;
996 
997     /* Pop the scope stack */
998 
999     if (AcpiNsOpensScope (ObjectType) &&
1000        (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
1001     {
1002         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
1003             AcpiUtGetTypeName (ObjectType), Op));
1004 
1005         Status = AcpiDsScopeStackPop (WalkState);
1006         if (ACPI_FAILURE (Status))
1007         {
1008             goto Cleanup;
1009         }
1010     }
1011 
1012     /*
1013      * Named operations are as follows:
1014      *
1015      * AML_ALIAS
1016      * AML_BANKFIELD
1017      * AML_CREATEBITFIELD
1018      * AML_CREATEBYTEFIELD
1019      * AML_CREATEDWORDFIELD
1020      * AML_CREATEFIELD
1021      * AML_CREATEQWORDFIELD
1022      * AML_CREATEWORDFIELD
1023      * AML_DATA_REGION
1024      * AML_DEVICE
1025      * AML_EVENT
1026      * AML_FIELD
1027      * AML_INDEXFIELD
1028      * AML_METHOD
1029      * AML_METHODCALL
1030      * AML_MUTEX
1031      * AML_NAME
1032      * AML_NAMEDFIELD
1033      * AML_OPREGION
1034      * AML_POWERRES
1035      * AML_PROCESSOR
1036      * AML_SCOPE
1037      * AML_THERMALZONE
1038      */
1039 
1040     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1041         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
1042         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
1043 
1044     /* Decode the opcode */
1045 
1046     Arg = Op->Common.Value.Arg;
1047 
1048     switch (WalkState->OpInfo->Type)
1049     {
1050 #ifndef ACPI_NO_METHOD_EXECUTION
1051 
1052     case AML_TYPE_CREATE_FIELD:
1053         /*
1054          * Create the field object, but the field buffer and index must
1055          * be evaluated later during the execution phase
1056          */
1057         Status = AcpiDsCreateBufferField (Op, WalkState);
1058         break;
1059 
1060 
1061      case AML_TYPE_NAMED_FIELD:
1062         /*
1063          * If we are executing a method, initialize the field
1064          */
1065         if (WalkState->MethodNode)
1066         {
1067             Status = AcpiDsInitFieldObjects (Op, WalkState);
1068         }
1069 
1070         switch (Op->Common.AmlOpcode)
1071         {
1072         case AML_INDEX_FIELD_OP:
1073 
1074             Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
1075                         WalkState);
1076             break;
1077 
1078         case AML_BANK_FIELD_OP:
1079 
1080             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
1081             break;
1082 
1083         case AML_FIELD_OP:
1084 
1085             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
1086             break;
1087 
1088         default:
1089             /* All NAMED_FIELD opcodes must be handled above */
1090             break;
1091         }
1092         break;
1093 
1094 
1095      case AML_TYPE_NAMED_SIMPLE:
1096 
1097         Status = AcpiDsCreateOperands (WalkState, Arg);
1098         if (ACPI_FAILURE (Status))
1099         {
1100             goto Cleanup;
1101         }
1102 
1103         switch (Op->Common.AmlOpcode)
1104         {
1105         case AML_PROCESSOR_OP:
1106 
1107             Status = AcpiExCreateProcessor (WalkState);
1108             break;
1109 
1110         case AML_POWER_RES_OP:
1111 
1112             Status = AcpiExCreatePowerResource (WalkState);
1113             break;
1114 
1115         case AML_MUTEX_OP:
1116 
1117             Status = AcpiExCreateMutex (WalkState);
1118             break;
1119 
1120         case AML_EVENT_OP:
1121 
1122             Status = AcpiExCreateEvent (WalkState);
1123             break;
1124 
1125 
1126         case AML_ALIAS_OP:
1127 
1128             Status = AcpiExCreateAlias (WalkState);
1129             break;
1130 
1131         default:
1132             /* Unknown opcode */
1133 
1134             Status = AE_OK;
1135             goto Cleanup;
1136         }
1137 
1138         /* Delete operands */
1139 
1140         for (i = 1; i < WalkState->NumOperands; i++)
1141         {
1142             AcpiUtRemoveReference (WalkState->Operands[i]);
1143             WalkState->Operands[i] = NULL;
1144         }
1145 
1146         break;
1147 #endif /* ACPI_NO_METHOD_EXECUTION */
1148 
1149     case AML_TYPE_NAMED_COMPLEX:
1150 
1151         switch (Op->Common.AmlOpcode)
1152         {
1153 #ifndef ACPI_NO_METHOD_EXECUTION
1154         case AML_REGION_OP:
1155         case AML_DATA_REGION_OP:
1156 
1157             if (Op->Common.AmlOpcode == AML_REGION_OP)
1158             {
1159                 RegionSpace = (ACPI_ADR_SPACE_TYPE)
1160                       ((Op->Common.Value.Arg)->Common.Value.Integer);
1161             }
1162             else
1163             {
1164                 RegionSpace = REGION_DATA_TABLE;
1165             }
1166 
1167             /*
1168              * If we are executing a method, initialize the region
1169              */
1170             if (WalkState->MethodNode)
1171             {
1172                 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
1173                             RegionSpace, WalkState);
1174                 if (ACPI_FAILURE (Status))
1175                 {
1176                     return (Status);
1177                 }
1178             }
1179 
1180             /*
1181              * The OpRegion is not fully parsed at this time. Only valid
1182              * argument is the SpaceId. (We must save the address of the
1183              * AML of the address and length operands)
1184              */
1185 
1186             /*
1187              * If we have a valid region, initialize it
1188              * Namespace is NOT locked at this point.
1189              *
1190              * TBD: need to unlock interpreter if it is locked, in order
1191              * to allow _REG methods to be run.
1192              */
1193             Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
1194                         FALSE);
1195             if (ACPI_FAILURE (Status))
1196             {
1197                 /*
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.
1201                  */
1202                 if (AE_NOT_EXIST == Status)
1203                 {
1204                     Status = AE_OK;
1205                 }
1206             }
1207             break;
1208 
1209 
1210         case AML_NAME_OP:
1211 
1212             Status = AcpiDsCreateNode (WalkState, Node, Op);
1213             break;
1214 
1215 
1216         case AML_METHOD_OP:
1217             /*
1218              * MethodOp PkgLength NameString MethodFlags TermList
1219              *
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.)
1224              */
1225             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1226                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
1227                 WalkState, Op, Op->Named.Node));
1228 
1229             if (!AcpiNsGetAttachedObject (Op->Named.Node))
1230             {
1231                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
1232                 WalkState->NumOperands = 1;
1233 
1234                 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1235                 if (ACPI_SUCCESS (Status))
1236                 {
1237                     Status = AcpiExCreateMethod (Op->Named.Data,
1238                                         Op->Named.Length, WalkState);
1239                 }
1240                 WalkState->Operands[0] = NULL;
1241                 WalkState->NumOperands = 0;
1242 
1243                 if (ACPI_FAILURE (Status))
1244                 {
1245                     return_ACPI_STATUS (Status);
1246                 }
1247             }
1248             break;
1249 
1250 #endif /* ACPI_NO_METHOD_EXECUTION */
1251 
1252         default:
1253             /* All NAMED_COMPLEX opcodes must be handled above */
1254             break;
1255         }
1256         break;
1257 
1258 
1259     case AML_CLASS_INTERNAL:
1260 
1261         /* case AML_INT_NAMEPATH_OP: */
1262         break;
1263 
1264 
1265     case AML_CLASS_METHOD_CALL:
1266 
1267         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1268             "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
1269             WalkState, Op, Node));
1270 
1271         /*
1272          * Lookup the method name and save the Node
1273          */
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))
1279         {
1280             /*
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
1284              */
1285             if (NewNode->Type != ACPI_TYPE_METHOD)
1286             {
1287                 Status = AE_AML_OPERAND_TYPE;
1288             }
1289 
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
1293              */
1294             Op->Common.Node = NewNode;
1295         }
1296         else
1297         {
1298             ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
1299         }
1300         break;
1301 
1302 
1303     default:
1304         break;
1305     }
1306 
1307 Cleanup:
1308 
1309     /* Remove the Node pushed at the very beginning */
1310 
1311     WalkState->Operands[0] = NULL;
1312     WalkState->NumOperands = 0;
1313     return_ACPI_STATUS (Status);
1314 }
1315 
1316 
1317