xref: /freebsd/sys/contrib/dev/acpica/components/dispatcher/dswload.c (revision d6eb98610fa65663bf0df4574b7cb2c5c4ffda71)
1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher first pass namespace load callbacks
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2019, 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 
160 #ifdef ACPI_ASL_COMPILER
161 #include <contrib/dev/acpica/include/acdisasm.h>
162 #endif
163 
164 #define _COMPONENT          ACPI_DISPATCHER
165         ACPI_MODULE_NAME    ("dswload")
166 
167 
168 /*******************************************************************************
169  *
170  * FUNCTION:    AcpiDsInitCallbacks
171  *
172  * PARAMETERS:  WalkState       - Current state of the parse tree walk
173  *              PassNumber      - 1, 2, or 3
174  *
175  * RETURN:      Status
176  *
177  * DESCRIPTION: Init walk state callbacks
178  *
179  ******************************************************************************/
180 
181 ACPI_STATUS
182 AcpiDsInitCallbacks (
183     ACPI_WALK_STATE         *WalkState,
184     UINT32                  PassNumber)
185 {
186 
187     switch (PassNumber)
188     {
189     case 0:
190 
191         /* Parse only - caller will setup callbacks */
192 
193         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
194                                         ACPI_PARSE_DELETE_TREE |
195                                         ACPI_PARSE_DISASSEMBLE;
196         WalkState->DescendingCallback = NULL;
197         WalkState->AscendingCallback  = NULL;
198         break;
199 
200     case 1:
201 
202         /* Load pass 1 */
203 
204         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
205                                         ACPI_PARSE_DELETE_TREE;
206         WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
207         WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
208         break;
209 
210     case 2:
211 
212         /* Load pass 2 */
213 
214         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
215                                         ACPI_PARSE_DELETE_TREE;
216         WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
217         WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
218         break;
219 
220     case 3:
221 
222         /* Execution pass */
223 
224         WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
225                                         ACPI_PARSE_DELETE_TREE;
226         WalkState->DescendingCallback = AcpiDsExecBeginOp;
227         WalkState->AscendingCallback  = AcpiDsExecEndOp;
228         break;
229 
230     default:
231 
232         return (AE_BAD_PARAMETER);
233     }
234 
235     return (AE_OK);
236 }
237 
238 
239 /*******************************************************************************
240  *
241  * FUNCTION:    AcpiDsLoad1BeginOp
242  *
243  * PARAMETERS:  WalkState       - Current state of the parse tree walk
244  *              OutOp           - Where to return op if a new one is created
245  *
246  * RETURN:      Status
247  *
248  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
249  *
250  ******************************************************************************/
251 
252 ACPI_STATUS
253 AcpiDsLoad1BeginOp (
254     ACPI_WALK_STATE         *WalkState,
255     ACPI_PARSE_OBJECT       **OutOp)
256 {
257     ACPI_PARSE_OBJECT       *Op;
258     ACPI_NAMESPACE_NODE     *Node;
259     ACPI_STATUS             Status;
260     ACPI_OBJECT_TYPE        ObjectType;
261     char                    *Path;
262     UINT32                  Flags;
263 
264 
265     ACPI_FUNCTION_TRACE_PTR (DsLoad1BeginOp, WalkState->Op);
266 
267 
268     Op = WalkState->Op;
269     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
270 
271     /* We are only interested in opcodes that have an associated name */
272 
273     if (Op)
274     {
275         if (!(WalkState->OpInfo->Flags & AML_NAMED))
276         {
277             *OutOp = Op;
278             return_ACPI_STATUS (AE_OK);
279         }
280 
281         /* Check if this object has already been installed in the namespace */
282 
283         if (Op->Common.Node)
284         {
285             *OutOp = Op;
286             return_ACPI_STATUS (AE_OK);
287         }
288     }
289 
290     Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
291 
292     /* Map the raw opcode into an internal object type */
293 
294     ObjectType = WalkState->OpInfo->ObjectType;
295 
296     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
297         "State=%p Op=%p [%s]\n", WalkState, Op,
298         AcpiUtGetTypeName (ObjectType)));
299 
300     switch (WalkState->Opcode)
301     {
302     case AML_SCOPE_OP:
303         /*
304          * The target name of the Scope() operator must exist at this point so
305          * that we can actually open the scope to enter new names underneath it.
306          * Allow search-to-root for single namesegs.
307          */
308         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
309             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
310 #ifdef ACPI_ASL_COMPILER
311         if (Status == AE_NOT_FOUND)
312         {
313             /*
314              * Table disassembly:
315              * Target of Scope() not found. Generate an External for it, and
316              * insert the name into the namespace.
317              */
318             AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
319             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
320                ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
321                WalkState, &Node);
322         }
323 #endif
324         if (ACPI_FAILURE (Status))
325         {
326             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
327             return_ACPI_STATUS (Status);
328         }
329 
330         /*
331          * Check to make sure that the target is
332          * one of the opcodes that actually opens a scope
333          */
334         switch (Node->Type)
335         {
336         case ACPI_TYPE_ANY:
337         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
338         case ACPI_TYPE_DEVICE:
339         case ACPI_TYPE_POWER:
340         case ACPI_TYPE_PROCESSOR:
341         case ACPI_TYPE_THERMAL:
342 
343             /* These are acceptable types */
344             break;
345 
346         case ACPI_TYPE_INTEGER:
347         case ACPI_TYPE_STRING:
348         case ACPI_TYPE_BUFFER:
349             /*
350              * These types we will allow, but we will change the type.
351              * This enables some existing code of the form:
352              *
353              *  Name (DEB, 0)
354              *  Scope (DEB) { ... }
355              *
356              * Note: silently change the type here. On the second pass,
357              * we will report a warning
358              */
359             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
360                 "Type override - [%4.4s] had invalid type (%s) "
361                 "for Scope operator, changed to type ANY\n",
362                 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
363 
364             Node->Type = ACPI_TYPE_ANY;
365             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
366             break;
367 
368         case ACPI_TYPE_METHOD:
369             /*
370              * Allow scope change to root during execution of module-level
371              * code. Root is typed METHOD during this time.
372              */
373             if ((Node == AcpiGbl_RootNode) &&
374                 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
375             {
376                 break;
377             }
378 
379             /*lint -fallthrough */
380 
381         default:
382 
383             /* All other types are an error */
384 
385             ACPI_ERROR ((AE_INFO,
386                 "Invalid type (%s) for target of "
387                 "Scope operator [%4.4s] (Cannot override)",
388                 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
389 
390             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
391         }
392         break;
393 
394     default:
395         /*
396          * For all other named opcodes, we will enter the name into
397          * the namespace.
398          *
399          * Setup the search flags.
400          * Since we are entering a name into the namespace, we do not want to
401          * enable the search-to-root upsearch.
402          *
403          * There are only two conditions where it is acceptable that the name
404          * already exists:
405          *    1) the Scope() operator can reopen a scoping object that was
406          *       previously defined (Scope, Method, Device, etc.)
407          *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
408          *       BufferField, or Package), the name of the object is already
409          *       in the namespace.
410          */
411         if (WalkState->DeferredNode)
412         {
413             /* This name is already in the namespace, get the node */
414 
415             Node = WalkState->DeferredNode;
416             Status = AE_OK;
417             break;
418         }
419 
420         /*
421          * If we are executing a method, do not create any namespace objects
422          * during the load phase, only during execution.
423          */
424         if (WalkState->MethodNode)
425         {
426             Node = NULL;
427             Status = AE_OK;
428             break;
429         }
430 
431         Flags = ACPI_NS_NO_UPSEARCH;
432         if ((WalkState->Opcode != AML_SCOPE_OP) &&
433             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
434         {
435             if (WalkState->NamespaceOverride)
436             {
437                 Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
438                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Override allowed\n",
439                     AcpiUtGetTypeName (ObjectType)));
440             }
441             else
442             {
443                 Flags |= ACPI_NS_ERROR_IF_FOUND;
444                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
445                     AcpiUtGetTypeName (ObjectType)));
446             }
447         }
448         else
449         {
450             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
451                 "[%s] Both Find or Create allowed\n",
452                 AcpiUtGetTypeName (ObjectType)));
453         }
454 
455         /*
456          * Enter the named type into the internal namespace. We enter the name
457          * as we go downward in the parse tree. Any necessary subobjects that
458          * involve arguments to the opcode must be created as we go back up the
459          * parse tree later.
460          */
461         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
462             ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
463         if (ACPI_FAILURE (Status))
464         {
465             if (Status == AE_ALREADY_EXISTS)
466             {
467                 /* The name already exists in this scope */
468 
469                 if (Node->Flags & ANOBJ_IS_EXTERNAL)
470                 {
471                     /*
472                      * Allow one create on an object or segment that was
473                      * previously declared External
474                      */
475                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
476                     Node->Type = (UINT8) ObjectType;
477 
478                     /* Just retyped a node, probably will need to open a scope */
479 
480                     if (AcpiNsOpensScope (ObjectType))
481                     {
482                         Status = AcpiDsScopeStackPush (
483                             Node, ObjectType, WalkState);
484                         if (ACPI_FAILURE (Status))
485                         {
486                             return_ACPI_STATUS (Status);
487                         }
488                     }
489 
490                     Status = AE_OK;
491                 }
492             }
493 
494             if (ACPI_FAILURE (Status))
495             {
496                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
497                 return_ACPI_STATUS (Status);
498             }
499         }
500         break;
501     }
502 
503     /* Common exit */
504 
505     if (!Op)
506     {
507         /* Create a new op */
508 
509         Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
510         if (!Op)
511         {
512             return_ACPI_STATUS (AE_NO_MEMORY);
513         }
514     }
515 
516     /* Initialize the op */
517 
518 #ifdef ACPI_CONSTANT_EVAL_ONLY
519     Op->Named.Path = Path;
520 #endif
521 
522     if (Node)
523     {
524         /*
525          * Put the Node in the "op" object that the parser uses, so we
526          * can get it again quickly when this scope is closed
527          */
528         Op->Common.Node = Node;
529         Op->Named.Name = Node->Name.Integer;
530     }
531 
532     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
533     *OutOp = Op;
534     return_ACPI_STATUS (Status);
535 }
536 
537 
538 /*******************************************************************************
539  *
540  * FUNCTION:    AcpiDsLoad1EndOp
541  *
542  * PARAMETERS:  WalkState       - Current state of the parse tree walk
543  *
544  * RETURN:      Status
545  *
546  * DESCRIPTION: Ascending callback used during the loading of the namespace,
547  *              both control methods and everything else.
548  *
549  ******************************************************************************/
550 
551 ACPI_STATUS
552 AcpiDsLoad1EndOp (
553     ACPI_WALK_STATE         *WalkState)
554 {
555     ACPI_PARSE_OBJECT       *Op;
556     ACPI_OBJECT_TYPE        ObjectType;
557     ACPI_STATUS             Status = AE_OK;
558 
559 #ifdef ACPI_ASL_COMPILER
560     UINT8                   ParamCount;
561 #endif
562 
563 
564     ACPI_FUNCTION_TRACE (DsLoad1EndOp);
565 
566 
567     Op = WalkState->Op;
568     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
569 
570     /* We are only interested in opcodes that have an associated name */
571 
572     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
573     {
574         return_ACPI_STATUS (AE_OK);
575     }
576 
577     /* Get the object type to determine if we should pop the scope */
578 
579     ObjectType = WalkState->OpInfo->ObjectType;
580 
581     if (WalkState->OpInfo->Flags & AML_FIELD)
582     {
583         /*
584          * If we are executing a method, do not create any namespace objects
585          * during the load phase, only during execution.
586          */
587         if (!WalkState->MethodNode)
588         {
589             if (WalkState->Opcode == AML_FIELD_OP          ||
590                 WalkState->Opcode == AML_BANK_FIELD_OP     ||
591                 WalkState->Opcode == AML_INDEX_FIELD_OP)
592             {
593                 Status = AcpiDsInitFieldObjects (Op, WalkState);
594             }
595         }
596         return_ACPI_STATUS (Status);
597     }
598 
599     /*
600      * If we are executing a method, do not create any namespace objects
601      * during the load phase, only during execution.
602      */
603     if (!WalkState->MethodNode)
604     {
605         if (Op->Common.AmlOpcode == AML_REGION_OP)
606         {
607             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
608                 (ACPI_ADR_SPACE_TYPE)
609                     ((Op->Common.Value.Arg)->Common.Value.Integer),
610                 WalkState);
611             if (ACPI_FAILURE (Status))
612             {
613                 return_ACPI_STATUS (Status);
614             }
615         }
616         else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
617         {
618             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
619                 ACPI_ADR_SPACE_DATA_TABLE, WalkState);
620             if (ACPI_FAILURE (Status))
621             {
622                 return_ACPI_STATUS (Status);
623             }
624         }
625     }
626 
627     if (Op->Common.AmlOpcode == AML_NAME_OP)
628     {
629         /* For Name opcode, get the object type from the argument */
630 
631         if (Op->Common.Value.Arg)
632         {
633             ObjectType = (AcpiPsGetOpcodeInfo (
634                 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
635 
636             /* Set node type if we have a namespace node */
637 
638             if (Op->Common.Node)
639             {
640                 Op->Common.Node->Type = (UINT8) ObjectType;
641             }
642         }
643     }
644 
645 #ifdef ACPI_ASL_COMPILER
646     /*
647      * For external opcode, get the object type from the argument and
648      * get the parameter count from the argument's next.
649      */
650     if (AcpiGbl_DisasmFlag &&
651         Op->Common.Node &&
652         Op->Common.AmlOpcode == AML_EXTERNAL_OP)
653     {
654         /*
655          * Note, if this external is not a method
656          * Op->Common.Value.Arg->Common.Next->Common.Value.Integer == 0
657          * Therefore, ParamCount will be 0.
658          */
659         ParamCount = (UINT8) Op->Common.Value.Arg->Common.Next->Common.Value.Integer;
660         ObjectType = (UINT8) Op->Common.Value.Arg->Common.Value.Integer;
661         Op->Common.Node->Flags |= ANOBJ_IS_EXTERNAL;
662         Op->Common.Node->Type = (UINT8) ObjectType;
663 
664         AcpiDmCreateSubobjectForExternal ((UINT8)ObjectType,
665             &Op->Common.Node, ParamCount);
666 
667         /*
668          * Add the external to the external list because we may be
669          * emitting code based off of the items within the external list.
670          */
671         AcpiDmAddOpToExternalList (Op, Op->Named.Path, (UINT8)ObjectType, ParamCount,
672            ACPI_EXT_ORIGIN_FROM_OPCODE | ACPI_EXT_RESOLVED_REFERENCE);
673     }
674 #endif
675 
676     /*
677      * If we are executing a method, do not create any namespace objects
678      * during the load phase, only during execution.
679      */
680     if (!WalkState->MethodNode)
681     {
682         if (Op->Common.AmlOpcode == AML_METHOD_OP)
683         {
684             /*
685              * MethodOp PkgLength NameString MethodFlags TermList
686              *
687              * Note: We must create the method node/object pair as soon as we
688              * see the method declaration. This allows later pass1 parsing
689              * of invocations of the method (need to know the number of
690              * arguments.)
691              */
692             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
693                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
694                 WalkState, Op, Op->Named.Node));
695 
696             if (!AcpiNsGetAttachedObject (Op->Named.Node))
697             {
698                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
699                 WalkState->NumOperands = 1;
700 
701                 Status = AcpiDsCreateOperands (
702                     WalkState, Op->Common.Value.Arg);
703                 if (ACPI_SUCCESS (Status))
704                 {
705                     Status = AcpiExCreateMethod (Op->Named.Data,
706                         Op->Named.Length, WalkState);
707                 }
708 
709                 WalkState->Operands[0] = NULL;
710                 WalkState->NumOperands = 0;
711 
712                 if (ACPI_FAILURE (Status))
713                 {
714                     return_ACPI_STATUS (Status);
715                 }
716             }
717         }
718     }
719 
720     /* Pop the scope stack (only if loading a table) */
721 
722     if (!WalkState->MethodNode &&
723         Op->Common.AmlOpcode != AML_EXTERNAL_OP &&
724         AcpiNsOpensScope (ObjectType))
725     {
726         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
727             AcpiUtGetTypeName (ObjectType), Op));
728 
729         Status = AcpiDsScopeStackPop (WalkState);
730     }
731 
732     return_ACPI_STATUS (Status);
733 }
734