xref: /freebsd/sys/contrib/dev/acpica/components/dispatcher/dswload2.c (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
1 /******************************************************************************
2  *
3  * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2022, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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.
65  *
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.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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.
89  *
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.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acdispat.h>
157 #include <contrib/dev/acpica/include/acinterp.h>
158 #include <contrib/dev/acpica/include/acnamesp.h>
159 #include <contrib/dev/acpica/include/acevents.h>
160 #if !defined(ACPI_DB_APP) && defined(ACPI_EXEC_APP)
161 #include "aecommon.h"
162 #endif
163 
164 #define _COMPONENT          ACPI_DISPATCHER
165         ACPI_MODULE_NAME    ("dswload2")
166 
167 
168 /*******************************************************************************
169  *
170  * FUNCTION:    AcpiDsLoad2BeginOp
171  *
172  * PARAMETERS:  WalkState       - Current state of the parse tree walk
173  *              OutOp           - Where to return op if a new one is created
174  *
175  * RETURN:      Status
176  *
177  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
178  *
179  ******************************************************************************/
180 
181 ACPI_STATUS
182 AcpiDsLoad2BeginOp (
183     ACPI_WALK_STATE         *WalkState,
184     ACPI_PARSE_OBJECT       **OutOp)
185 {
186     ACPI_PARSE_OBJECT       *Op;
187     ACPI_NAMESPACE_NODE     *Node;
188     ACPI_STATUS             Status;
189     ACPI_OBJECT_TYPE        ObjectType;
190     char                    *BufferPtr;
191     UINT32                  Flags;
192 
193 
194     ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
195 
196 
197     Op = WalkState->Op;
198     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
199 
200     if (Op)
201     {
202         if ((WalkState->ControlState) &&
203             (WalkState->ControlState->Common.State ==
204                 ACPI_CONTROL_CONDITIONAL_EXECUTING))
205         {
206             /* We are executing a while loop outside of a method */
207 
208             Status = AcpiDsExecBeginOp (WalkState, OutOp);
209             return_ACPI_STATUS (Status);
210         }
211 
212         /* We only care about Namespace opcodes here */
213 
214         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
215               (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
216             (!(WalkState->OpInfo->Flags & AML_NAMED)))
217         {
218             return_ACPI_STATUS (AE_OK);
219         }
220 
221         /* Get the name we are going to enter or lookup in the namespace */
222 
223         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
224         {
225             /* For Namepath op, get the path string */
226 
227             BufferPtr = Op->Common.Value.String;
228             if (!BufferPtr)
229             {
230                 /* No name, just exit */
231 
232                 return_ACPI_STATUS (AE_OK);
233             }
234         }
235         else
236         {
237             /* Get name from the op */
238 
239             BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
240         }
241     }
242     else
243     {
244         /* Get the namestring from the raw AML */
245 
246         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
247     }
248 
249     /* Map the opcode into an internal object type */
250 
251     ObjectType = WalkState->OpInfo->ObjectType;
252 
253     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
254         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
255 
256     switch (WalkState->Opcode)
257     {
258     case AML_FIELD_OP:
259     case AML_BANK_FIELD_OP:
260     case AML_INDEX_FIELD_OP:
261 
262         Node = NULL;
263         Status = AE_OK;
264         break;
265 
266     case AML_INT_NAMEPATH_OP:
267         /*
268          * The NamePath is an object reference to an existing object.
269          * Don't enter the name into the namespace, but look it up
270          * for use later.
271          */
272         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
273             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
274             WalkState, &(Node));
275         break;
276 
277     case AML_SCOPE_OP:
278 
279         /* Special case for Scope(\) -> refers to the Root node */
280 
281         if (Op && (Op->Named.Node == AcpiGbl_RootNode))
282         {
283             Node = Op->Named.Node;
284 
285             Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
286             if (ACPI_FAILURE (Status))
287             {
288                 return_ACPI_STATUS (Status);
289             }
290         }
291         else
292         {
293             /*
294              * The Path is an object reference to an existing object.
295              * Don't enter the name into the namespace, but look it up
296              * for use later.
297              */
298             Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
299                 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
300                 WalkState, &(Node));
301             if (ACPI_FAILURE (Status))
302             {
303 #ifdef ACPI_ASL_COMPILER
304                 if (Status == AE_NOT_FOUND)
305                 {
306                     Status = AE_OK;
307                 }
308                 else
309                 {
310                     ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
311                         BufferPtr, Status);
312                 }
313 #else
314                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
315                     BufferPtr, Status);
316 #endif
317                 return_ACPI_STATUS (Status);
318             }
319         }
320 
321         /*
322          * We must check to make sure that the target is
323          * one of the opcodes that actually opens a scope
324          */
325         switch (Node->Type)
326         {
327         case ACPI_TYPE_ANY:
328         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
329         case ACPI_TYPE_DEVICE:
330         case ACPI_TYPE_POWER:
331         case ACPI_TYPE_PROCESSOR:
332         case ACPI_TYPE_THERMAL:
333 
334             /* These are acceptable types */
335             break;
336 
337         case ACPI_TYPE_INTEGER:
338         case ACPI_TYPE_STRING:
339         case ACPI_TYPE_BUFFER:
340 
341             /*
342              * These types we will allow, but we will change the type.
343              * This enables some existing code of the form:
344              *
345              *  Name (DEB, 0)
346              *  Scope (DEB) { ... }
347              */
348             ACPI_WARNING ((AE_INFO,
349                 "Type override - [%4.4s] had invalid type (%s) "
350                 "for Scope operator, changed to type ANY",
351                 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
352 
353             Node->Type = ACPI_TYPE_ANY;
354             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
355             break;
356 
357         case ACPI_TYPE_METHOD:
358 
359             /*
360              * Allow scope change to root during execution of module-level
361              * code. Root is typed METHOD during this time.
362              */
363             if ((Node == AcpiGbl_RootNode) &&
364                 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
365             {
366                 break;
367             }
368 
369             ACPI_FALLTHROUGH;
370 
371         default:
372 
373             /* All other types are an error */
374 
375             ACPI_ERROR ((AE_INFO,
376                 "Invalid type (%s) for target of "
377                 "Scope operator [%4.4s] (Cannot override)",
378                 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
379 
380             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
381         }
382         break;
383 
384     default:
385 
386         /* All other opcodes */
387 
388         if (Op && Op->Common.Node)
389         {
390             /* This op/node was previously entered into the namespace */
391 
392             Node = Op->Common.Node;
393 
394             if (AcpiNsOpensScope (ObjectType))
395             {
396                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
397                 if (ACPI_FAILURE (Status))
398                 {
399                     return_ACPI_STATUS (Status);
400                 }
401             }
402 
403             return_ACPI_STATUS (AE_OK);
404         }
405 
406         /*
407          * Enter the named type into the internal namespace. We enter the name
408          * as we go downward in the parse tree. Any necessary subobjects that
409          * involve arguments to the opcode must be created as we go back up the
410          * parse tree later.
411          *
412          * Note: Name may already exist if we are executing a deferred opcode.
413          */
414         if (WalkState->DeferredNode)
415         {
416             /* This name is already in the namespace, get the node */
417 
418             Node = WalkState->DeferredNode;
419             Status = AE_OK;
420             break;
421         }
422 
423         Flags = ACPI_NS_NO_UPSEARCH;
424         if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
425         {
426             /* Execution mode, node cannot already exist, node is temporary */
427 
428             Flags |= ACPI_NS_ERROR_IF_FOUND;
429 
430             if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
431             {
432                 Flags |= ACPI_NS_TEMPORARY;
433             }
434         }
435 
436 #ifdef ACPI_ASL_COMPILER
437 
438         /*
439          * Do not open a scope for AML_EXTERNAL_OP
440          * AcpiNsLookup can open a new scope based on the object type
441          * of this op. AML_EXTERNAL_OP is a declaration rather than a
442          * definition. In the case that this external is a method object,
443          * AcpiNsLookup will open a new scope. However, an AML_EXTERNAL_OP
444          * associated with the ACPI_TYPE_METHOD is a declaration, rather than
445          * a definition. Flags is set to avoid opening a scope for any
446          * AML_EXTERNAL_OP.
447          */
448         if (WalkState->Opcode == AML_EXTERNAL_OP)
449         {
450             Flags |= ACPI_NS_DONT_OPEN_SCOPE;
451         }
452 #endif
453 
454         /*
455          * For name creation opcodes, the full namepath prefix must
456          * exist, except for the final (new) nameseg.
457          */
458         if (WalkState->OpInfo->Flags & AML_NAMED)
459         {
460             Flags |= ACPI_NS_PREFIX_MUST_EXIST;
461         }
462 
463         /* Add new entry or lookup existing entry */
464 
465         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
466             ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
467 
468         if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
469         {
470             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
471                 "***New Node [%4.4s] %p is temporary\n",
472                 AcpiUtGetNodeName (Node), Node));
473         }
474         break;
475     }
476 
477     if (ACPI_FAILURE (Status))
478     {
479         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
480             BufferPtr, Status);
481         return_ACPI_STATUS (Status);
482     }
483 
484     if (!Op)
485     {
486         /* Create a new op */
487 
488         Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
489         if (!Op)
490         {
491             return_ACPI_STATUS (AE_NO_MEMORY);
492         }
493 
494         /* Initialize the new op */
495 
496         if (Node)
497         {
498             Op->Named.Name = Node->Name.Integer;
499         }
500         *OutOp = Op;
501     }
502 
503     /*
504      * Put the Node in the "op" object that the parser uses, so we
505      * can get it again quickly when this scope is closed
506      */
507     Op->Common.Node = Node;
508     return_ACPI_STATUS (Status);
509 }
510 
511 
512 /*******************************************************************************
513  *
514  * FUNCTION:    AcpiDsLoad2EndOp
515  *
516  * PARAMETERS:  WalkState       - Current state of the parse tree walk
517  *
518  * RETURN:      Status
519  *
520  * DESCRIPTION: Ascending callback used during the loading of the namespace,
521  *              both control methods and everything else.
522  *
523  ******************************************************************************/
524 
525 ACPI_STATUS
526 AcpiDsLoad2EndOp (
527     ACPI_WALK_STATE         *WalkState)
528 {
529     ACPI_PARSE_OBJECT       *Op;
530     ACPI_STATUS             Status = AE_OK;
531     ACPI_OBJECT_TYPE        ObjectType;
532     ACPI_NAMESPACE_NODE     *Node;
533     ACPI_PARSE_OBJECT       *Arg;
534     ACPI_NAMESPACE_NODE     *NewNode;
535     UINT32                  i;
536     UINT8                   RegionSpace;
537 #if !defined(ACPI_DB_APP) && defined(ACPI_EXEC_APP)
538     ACPI_OPERAND_OBJECT     *ObjDesc;
539     char                    *Namepath;
540 #endif
541 
542 
543     ACPI_FUNCTION_TRACE (DsLoad2EndOp);
544 
545     Op = WalkState->Op;
546     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
547         WalkState->OpInfo->Name, Op, WalkState));
548 
549     /* Check if opcode had an associated namespace object */
550 
551     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
552     {
553         return_ACPI_STATUS (AE_OK);
554     }
555 
556     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
557     {
558         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
559             "Ending scope Op=%p State=%p\n", Op, WalkState));
560     }
561 
562     ObjectType = WalkState->OpInfo->ObjectType;
563 
564     /*
565      * Get the Node/name from the earlier lookup
566      * (It was saved in the *op structure)
567      */
568     Node = Op->Common.Node;
569 
570     /*
571      * Put the Node on the object stack (Contains the ACPI Name of
572      * this object)
573      */
574     WalkState->Operands[0] = (void *) Node;
575     WalkState->NumOperands = 1;
576 
577     /* Pop the scope stack */
578 
579     if (AcpiNsOpensScope (ObjectType) &&
580        (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
581     {
582         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
583             AcpiUtGetTypeName (ObjectType), Op));
584 
585         Status = AcpiDsScopeStackPop (WalkState);
586         if (ACPI_FAILURE (Status))
587         {
588             goto Cleanup;
589         }
590     }
591 
592     /*
593      * Named operations are as follows:
594      *
595      * AML_ALIAS
596      * AML_BANKFIELD
597      * AML_CREATEBITFIELD
598      * AML_CREATEBYTEFIELD
599      * AML_CREATEDWORDFIELD
600      * AML_CREATEFIELD
601      * AML_CREATEQWORDFIELD
602      * AML_CREATEWORDFIELD
603      * AML_DATA_REGION
604      * AML_DEVICE
605      * AML_EVENT
606      * AML_FIELD
607      * AML_INDEXFIELD
608      * AML_METHOD
609      * AML_METHODCALL
610      * AML_MUTEX
611      * AML_NAME
612      * AML_NAMEDFIELD
613      * AML_OPREGION
614      * AML_POWERRES
615      * AML_PROCESSOR
616      * AML_SCOPE
617      * AML_THERMALZONE
618      */
619 
620     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
621         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
622         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
623 
624     /* Decode the opcode */
625 
626     Arg = Op->Common.Value.Arg;
627 
628     switch (WalkState->OpInfo->Type)
629     {
630 
631     case AML_TYPE_CREATE_FIELD:
632         /*
633          * Create the field object, but the field buffer and index must
634          * be evaluated later during the execution phase
635          */
636         Status = AcpiDsCreateBufferField (Op, WalkState);
637         if ACPI_FAILURE (Status)
638         {
639             ACPI_EXCEPTION ((AE_INFO, Status, "CreateBufferField failure"));
640             goto Cleanup;
641         }
642         break;
643 
644      case AML_TYPE_NAMED_FIELD:
645         /*
646          * If we are executing a method, initialize the field
647          */
648         if (WalkState->MethodNode)
649         {
650             Status = AcpiDsInitFieldObjects (Op, WalkState);
651         }
652 
653         switch (Op->Common.AmlOpcode)
654         {
655         case AML_INDEX_FIELD_OP:
656 
657             Status = AcpiDsCreateIndexField (
658                 Op, (ACPI_HANDLE) Arg->Common.Node, WalkState);
659             break;
660 
661         case AML_BANK_FIELD_OP:
662 
663             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
664             break;
665 
666         case AML_FIELD_OP:
667 
668             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
669             break;
670 
671         default:
672 
673             /* All NAMED_FIELD opcodes must be handled above */
674             break;
675         }
676         break;
677 
678      case AML_TYPE_NAMED_SIMPLE:
679 
680         Status = AcpiDsCreateOperands (WalkState, Arg);
681         if (ACPI_FAILURE (Status))
682         {
683             goto Cleanup;
684         }
685 
686         switch (Op->Common.AmlOpcode)
687         {
688         case AML_PROCESSOR_OP:
689 
690             Status = AcpiExCreateProcessor (WalkState);
691             break;
692 
693         case AML_POWER_RESOURCE_OP:
694 
695             Status = AcpiExCreatePowerResource (WalkState);
696             break;
697 
698         case AML_MUTEX_OP:
699 
700             Status = AcpiExCreateMutex (WalkState);
701             break;
702 
703         case AML_EVENT_OP:
704 
705             Status = AcpiExCreateEvent (WalkState);
706             break;
707 
708         case AML_ALIAS_OP:
709 
710             Status = AcpiExCreateAlias (WalkState);
711             break;
712 
713         default:
714 
715             /* Unknown opcode */
716 
717             Status = AE_OK;
718             goto Cleanup;
719         }
720 
721         /* Delete operands */
722 
723         for (i = 1; i < WalkState->NumOperands; i++)
724         {
725             AcpiUtRemoveReference (WalkState->Operands[i]);
726             WalkState->Operands[i] = NULL;
727         }
728 
729         break;
730 
731     case AML_TYPE_NAMED_COMPLEX:
732 
733         switch (Op->Common.AmlOpcode)
734         {
735         case AML_REGION_OP:
736         case AML_DATA_REGION_OP:
737 
738             if (Op->Common.AmlOpcode == AML_REGION_OP)
739             {
740                 RegionSpace = (ACPI_ADR_SPACE_TYPE)
741                     ((Op->Common.Value.Arg)->Common.Value.Integer);
742             }
743             else
744             {
745                 RegionSpace = ACPI_ADR_SPACE_DATA_TABLE;
746             }
747 
748             /*
749              * The OpRegion is not fully parsed at this time. The only valid
750              * argument is the SpaceId. (We must save the address of the
751              * AML of the address and length operands)
752              *
753              * If we have a valid region, initialize it. The namespace is
754              * unlocked at this point.
755              *
756              * Need to unlock interpreter if it is locked (if we are running
757              * a control method), in order to allow _REG methods to be run
758              * during AcpiEvInitializeRegion.
759              */
760             if (WalkState->MethodNode)
761             {
762                 /*
763                  * Executing a method: initialize the region and unlock
764                  * the interpreter
765                  */
766                 Status = AcpiExCreateRegion (Op->Named.Data,
767                     Op->Named.Length, RegionSpace, WalkState);
768                 if (ACPI_FAILURE (Status))
769                 {
770                     return_ACPI_STATUS (Status);
771                 }
772             }
773 
774             Status = AcpiEvInitializeRegion (
775                 AcpiNsGetAttachedObject (Node));
776             break;
777 
778         case AML_NAME_OP:
779 
780             Status = AcpiDsCreateNode (WalkState, Node, Op);
781             if (ACPI_FAILURE (Status))
782             {
783                 goto Cleanup;
784             }
785 
786 #if !defined(ACPI_DB_APP) && defined(ACPI_EXEC_APP)
787             /*
788              * AcpiExec support for namespace initialization file (initialize
789              * Name opcodes in this code.)
790              */
791             Namepath = AcpiNsGetExternalPathname (Node);
792             Status = AeLookupInitFileEntry (Namepath, &ObjDesc);
793             if (ACPI_SUCCESS (Status))
794             {
795                 /* Detach any existing object, attach new object */
796 
797                 if (Node->Object)
798                 {
799                     AcpiNsDetachObject (Node);
800                 }
801                 AcpiNsAttachObject (Node, ObjDesc, ObjDesc->Common.Type);
802             }
803             ACPI_FREE (Namepath);
804             Status = AE_OK;
805 #endif
806             break;
807 
808         case AML_METHOD_OP:
809             /*
810              * MethodOp PkgLength NameString MethodFlags TermList
811              *
812              * Note: We must create the method node/object pair as soon as we
813              * see the method declaration. This allows later pass1 parsing
814              * of invocations of the method (need to know the number of
815              * arguments.)
816              */
817             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
818                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
819                 WalkState, Op, Op->Named.Node));
820 
821             if (!AcpiNsGetAttachedObject (Op->Named.Node))
822             {
823                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
824                 WalkState->NumOperands = 1;
825 
826                 Status = AcpiDsCreateOperands (
827                     WalkState, Op->Common.Value.Arg);
828                 if (ACPI_SUCCESS (Status))
829                 {
830                     Status = AcpiExCreateMethod (
831                         Op->Named.Data, Op->Named.Length, WalkState);
832                 }
833 
834                 WalkState->Operands[0] = NULL;
835                 WalkState->NumOperands = 0;
836 
837                 if (ACPI_FAILURE (Status))
838                 {
839                     return_ACPI_STATUS (Status);
840                 }
841             }
842             break;
843 
844 
845         default:
846 
847             /* All NAMED_COMPLEX opcodes must be handled above */
848             break;
849         }
850         break;
851 
852     case AML_CLASS_INTERNAL:
853 
854         /* case AML_INT_NAMEPATH_OP: */
855         break;
856 
857     case AML_CLASS_METHOD_CALL:
858 
859         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
860             "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
861             WalkState, Op, Node));
862 
863         /*
864          * Lookup the method name and save the Node
865          */
866         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
867             ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
868             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
869             WalkState, &(NewNode));
870         if (ACPI_SUCCESS (Status))
871         {
872             /*
873              * Make sure that what we found is indeed a method
874              * We didn't search for a method on purpose, to see if the name
875              * would resolve
876              */
877             if (NewNode->Type != ACPI_TYPE_METHOD)
878             {
879                 Status = AE_AML_OPERAND_TYPE;
880             }
881 
882             /* We could put the returned object (Node) on the object stack for
883              * later, but for now, we will put it in the "op" object that the
884              * parser uses, so we can get it again at the end of this scope
885              */
886             Op->Common.Node = NewNode;
887         }
888         else
889         {
890             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
891                 Arg->Common.Value.String, Status);
892         }
893         break;
894 
895 
896     default:
897 
898         break;
899     }
900 
901 Cleanup:
902 
903     /* Remove the Node pushed at the very beginning */
904 
905     WalkState->Operands[0] = NULL;
906     WalkState->NumOperands = 0;
907     return_ACPI_STATUS (Status);
908 }
909