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