dswload.c revision 114237
1/******************************************************************************
2 *
3 * Module Name: dswload - Dispatcher namespace load callbacks
4 *              $Revision: 83 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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
128#define _COMPONENT          ACPI_DISPATCHER
129        ACPI_MODULE_NAME    ("dswload")
130
131
132/*******************************************************************************
133 *
134 * FUNCTION:    AcpiDsInitCallbacks
135 *
136 * PARAMETERS:  WalkState       - Current state of the parse tree walk
137 *              PassNumber      - 1, 2, or 3
138 *
139 * RETURN:      Status
140 *
141 * DESCRIPTION: Init walk state callbacks
142 *
143 ******************************************************************************/
144
145ACPI_STATUS
146AcpiDsInitCallbacks (
147    ACPI_WALK_STATE         *WalkState,
148    UINT32                  PassNumber)
149{
150
151    switch (PassNumber)
152    {
153    case 1:
154        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE;
155        WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
156        WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
157        break;
158
159    case 2:
160        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE;
161        WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
162        WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
163        break;
164
165    case 3:
166#ifndef ACPI_NO_METHOD_EXECUTION
167        WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  | ACPI_PARSE_DELETE_TREE;
168        WalkState->DescendingCallback = AcpiDsExecBeginOp;
169        WalkState->AscendingCallback  = AcpiDsExecEndOp;
170#endif
171        break;
172
173    default:
174        return (AE_BAD_PARAMETER);
175    }
176
177    return (AE_OK);
178}
179
180
181/*******************************************************************************
182 *
183 * FUNCTION:    AcpiDsLoad1BeginOp
184 *
185 * PARAMETERS:  WalkState       - Current state of the parse tree walk
186 *              Op              - Op that has been just been reached in the
187 *                                walk;  Arguments have not been evaluated yet.
188 *
189 * RETURN:      Status
190 *
191 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
192 *
193 ******************************************************************************/
194
195ACPI_STATUS
196AcpiDsLoad1BeginOp (
197    ACPI_WALK_STATE         *WalkState,
198    ACPI_PARSE_OBJECT       **OutOp)
199{
200    ACPI_PARSE_OBJECT       *Op;
201    ACPI_NAMESPACE_NODE     *Node;
202    ACPI_STATUS             Status;
203    ACPI_OBJECT_TYPE        ObjectType;
204    char                    *Path;
205    UINT32                  Flags;
206
207
208    ACPI_FUNCTION_NAME ("DsLoad1BeginOp");
209
210
211    Op = WalkState->Op;
212    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
213
214    /* We are only interested in opcodes that have an associated name */
215
216    if (Op)
217    {
218        if (!(WalkState->OpInfo->Flags & AML_NAMED))
219        {
220#if 0
221            if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
222                (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
223            {
224                AcpiOsPrintf ("\n\n***EXECUTABLE OPCODE %s***\n\n", WalkState->OpInfo->Name);
225                *OutOp = Op;
226                return (AE_CTRL_SKIP);
227            }
228#endif
229            *OutOp = Op;
230            return (AE_OK);
231        }
232
233        /* Check if this object has already been installed in the namespace */
234
235        if (Op->Common.Node)
236        {
237            *OutOp = Op;
238            return (AE_OK);
239        }
240    }
241
242    Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
243
244    /* Map the raw opcode into an internal object type */
245
246    ObjectType = WalkState->OpInfo->ObjectType;
247
248    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
249        "State=%p Op=%p [%s] ", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
250
251    switch (WalkState->Opcode)
252    {
253    case AML_SCOPE_OP:
254
255        /*
256         * The target name of the Scope() operator must exist at this point so
257         * that we can actually open the scope to enter new names underneath it.
258         * Allow search-to-root for single namesegs.
259         */
260        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
261                        ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
262        if (ACPI_FAILURE (Status))
263        {
264            ACPI_REPORT_NSERROR (Path, Status);
265            return (Status);
266        }
267
268        /*
269         * Check to make sure that the target is
270         * one of the opcodes that actually opens a scope
271         */
272        switch (Node->Type)
273        {
274        case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
275        case ACPI_TYPE_DEVICE:
276        case ACPI_TYPE_POWER:
277        case ACPI_TYPE_PROCESSOR:
278        case ACPI_TYPE_THERMAL:
279
280            /* These are acceptable types */
281            break;
282
283        case ACPI_TYPE_INTEGER:
284        case ACPI_TYPE_STRING:
285        case ACPI_TYPE_BUFFER:
286
287            /*
288             * These types we will allow, but we will change the type.  This
289             * enables some existing code of the form:
290             *
291             *  Name (DEB, 0)
292             *  Scope (DEB) { ... }
293             *
294             * Note: silently change the type here.  On the second pass, we will report a warning
295             */
296
297            ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
298                Path, AcpiUtGetTypeName (Node->Type)));
299
300            Node->Type = ACPI_TYPE_ANY;
301            WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
302            break;
303
304        default:
305
306            /* All other types are an error */
307
308            ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n",
309                AcpiUtGetTypeName (Node->Type), Path));
310
311            return (AE_AML_OPERAND_TYPE);
312        }
313        break;
314
315
316    default:
317
318        /*
319         * For all other named opcodes, we will enter the name into the namespace.
320         *
321         * Setup the search flags.
322         * Since we are entering a name into the namespace, we do not want to
323         * enable the search-to-root upsearch.
324         *
325         * There are only two conditions where it is acceptable that the name
326         * already exists:
327         *    1) the Scope() operator can reopen a scoping object that was
328         *       previously defined (Scope, Method, Device, etc.)
329         *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
330         *       BufferField, or Package), the name of the object is already
331         *       in the namespace.
332         */
333        Flags = ACPI_NS_NO_UPSEARCH;
334        if ((WalkState->Opcode != AML_SCOPE_OP) &&
335            (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
336        {
337            Flags |= ACPI_NS_ERROR_IF_FOUND;
338            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "Cannot already exist\n"));
339        }
340        else
341        {
342            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "Both Find or Create allowed\n"));
343        }
344
345        /*
346         * Enter the named type into the internal namespace.  We enter the name
347         * as we go downward in the parse tree.  Any necessary subobjects that involve
348         * arguments to the opcode must be created as we go back up the parse tree later.
349         */
350        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
351                        ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
352        if (ACPI_FAILURE (Status))
353        {
354            ACPI_REPORT_NSERROR (Path, Status);
355            return (Status);
356        }
357        break;
358    }
359
360
361    /* Common exit */
362
363    if (!Op)
364    {
365        /* Create a new op */
366
367        Op = AcpiPsAllocOp (WalkState->Opcode);
368        if (!Op)
369        {
370            return (AE_NO_MEMORY);
371        }
372    }
373
374    /* Initialize */
375
376    Op->Named.Name = Node->Name.Integer;
377
378#if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
379    Op->Named.Path = (UINT8 *) Path;
380#endif
381
382
383    /*
384     * Put the Node in the "op" object that the parser uses, so we
385     * can get it again quickly when this scope is closed
386     */
387    Op->Common.Node = Node;
388    AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
389
390    *OutOp = Op;
391    return (Status);
392}
393
394
395/*******************************************************************************
396 *
397 * FUNCTION:    AcpiDsLoad1EndOp
398 *
399 * PARAMETERS:  WalkState       - Current state of the parse tree walk
400 *              Op              - Op that has been just been completed in the
401 *                                walk;  Arguments have now been evaluated.
402 *
403 * RETURN:      Status
404 *
405 * DESCRIPTION: Ascending callback used during the loading of the namespace,
406 *              both control methods and everything else.
407 *
408 ******************************************************************************/
409
410ACPI_STATUS
411AcpiDsLoad1EndOp (
412    ACPI_WALK_STATE         *WalkState)
413{
414    ACPI_PARSE_OBJECT       *Op;
415    ACPI_OBJECT_TYPE        ObjectType;
416    ACPI_STATUS             Status = AE_OK;
417
418
419    ACPI_FUNCTION_NAME ("DsLoad1EndOp");
420
421
422    Op = WalkState->Op;
423    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
424
425    /* We are only interested in opcodes that have an associated name */
426
427    if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
428    {
429        return (AE_OK);
430    }
431
432    /* Get the object type to determine if we should pop the scope */
433
434    ObjectType = WalkState->OpInfo->ObjectType;
435
436#ifndef ACPI_NO_METHOD_EXECUTION
437    if (WalkState->OpInfo->Flags & AML_FIELD)
438    {
439        if (WalkState->Opcode == AML_FIELD_OP          ||
440            WalkState->Opcode == AML_BANK_FIELD_OP     ||
441            WalkState->Opcode == AML_INDEX_FIELD_OP)
442        {
443            Status = AcpiDsInitFieldObjects (Op, WalkState);
444        }
445        return (Status);
446    }
447
448
449    if (Op->Common.AmlOpcode == AML_REGION_OP)
450    {
451        Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
452                         (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer), WalkState);
453        if (ACPI_FAILURE (Status))
454        {
455            return (Status);
456        }
457    }
458#endif
459
460    if (Op->Common.AmlOpcode == AML_NAME_OP)
461    {
462        /* For Name opcode, get the object type from the argument */
463
464        if (Op->Common.Value.Arg)
465        {
466            ObjectType = (AcpiPsGetOpcodeInfo ((Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
467            Op->Common.Node->Type = (UINT8) ObjectType;
468        }
469    }
470
471    if (Op->Common.AmlOpcode == AML_METHOD_OP)
472    {
473        /*
474         * MethodOp PkgLength NameString MethodFlags TermList
475         *
476         * Note: We must create the method node/object pair as soon as we
477         * see the method declaration.  This allows later pass1 parsing
478         * of invocations of the method (need to know the number of
479         * arguments.)
480         */
481        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
482            "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
483            WalkState, Op, Op->Named.Node));
484
485        if (!AcpiNsGetAttachedObject (Op->Named.Node))
486        {
487            WalkState->Operands[0] = (void *) Op->Named.Node;
488            WalkState->NumOperands = 1;
489
490            Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
491            if (ACPI_SUCCESS (Status))
492            {
493                Status = AcpiExCreateMethod (Op->Named.Data,
494                                    Op->Named.Length, WalkState);
495            }
496            WalkState->Operands[0] = NULL;
497            WalkState->NumOperands = 0;
498
499            if (ACPI_FAILURE (Status))
500            {
501                return (Status);
502            }
503        }
504    }
505
506    /* Pop the scope stack */
507
508    if (AcpiNsOpensScope (ObjectType))
509    {
510        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
511            AcpiUtGetTypeName (ObjectType), Op));
512
513        Status = AcpiDsScopeStackPop (WalkState);
514    }
515
516    return (Status);
517}
518
519
520/*******************************************************************************
521 *
522 * FUNCTION:    AcpiDsLoad2BeginOp
523 *
524 * PARAMETERS:  WalkState       - Current state of the parse tree walk
525 *              Op              - Op that has been just been reached in the
526 *                                walk;  Arguments have not been evaluated yet.
527 *
528 * RETURN:      Status
529 *
530 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
531 *
532 ******************************************************************************/
533
534ACPI_STATUS
535AcpiDsLoad2BeginOp (
536    ACPI_WALK_STATE         *WalkState,
537    ACPI_PARSE_OBJECT       **OutOp)
538{
539    ACPI_PARSE_OBJECT       *Op;
540    ACPI_NAMESPACE_NODE     *Node;
541    ACPI_STATUS             Status;
542    ACPI_OBJECT_TYPE        ObjectType;
543    char                    *BufferPtr;
544
545
546    ACPI_FUNCTION_TRACE ("DsLoad2BeginOp");
547
548
549    Op = WalkState->Op;
550    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
551
552    if (Op)
553    {
554        /* We only care about Namespace opcodes here */
555
556        if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE) && (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
557            (!(WalkState->OpInfo->Flags & AML_NAMED)))
558        {
559            return_ACPI_STATUS (AE_OK);
560        }
561
562        /*
563         * Get the name we are going to enter or lookup in the namespace
564         */
565        if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
566        {
567            /* For Namepath op, get the path string */
568
569            BufferPtr = Op->Common.Value.String;
570            if (!BufferPtr)
571            {
572                /* No name, just exit */
573
574                return_ACPI_STATUS (AE_OK);
575            }
576        }
577        else
578        {
579            /* Get name from the op */
580
581            BufferPtr = (char *) &Op->Named.Name;
582        }
583    }
584    else
585    {
586        /* Get the namestring from the raw AML */
587
588        BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
589    }
590
591    /* Map the opcode into an internal object type */
592
593    ObjectType = WalkState->OpInfo->ObjectType;
594
595    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
596        "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
597
598
599    switch (WalkState->Opcode)
600    {
601    case AML_FIELD_OP:
602    case AML_BANK_FIELD_OP:
603    case AML_INDEX_FIELD_OP:
604
605        Node = NULL;
606        Status = AE_OK;
607        break;
608
609    case AML_INT_NAMEPATH_OP:
610
611        /*
612         * The NamePath is an object reference to an existing object.  Don't enter the
613         * name into the namespace, but look it up for use later
614         */
615        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
616                        ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
617        break;
618
619    case AML_SCOPE_OP:
620
621        /*
622         * The Path is an object reference to an existing object.  Don't enter the
623         * name into the namespace, but look it up for use later
624         */
625        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
626                        ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
627        if (ACPI_FAILURE (Status))
628        {
629            ACPI_REPORT_NSERROR (BufferPtr, Status);
630            return_ACPI_STATUS (Status);
631        }
632        /*
633         * We must check to make sure that the target is
634         * one of the opcodes that actually opens a scope
635         */
636        switch (Node->Type)
637        {
638        case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
639        case ACPI_TYPE_DEVICE:
640        case ACPI_TYPE_POWER:
641        case ACPI_TYPE_PROCESSOR:
642        case ACPI_TYPE_THERMAL:
643
644            /* These are acceptable types */
645            break;
646
647        case ACPI_TYPE_INTEGER:
648        case ACPI_TYPE_STRING:
649        case ACPI_TYPE_BUFFER:
650
651            /*
652             * These types we will allow, but we will change the type.  This
653             * enables some existing code of the form:
654             *
655             *  Name (DEB, 0)
656             *  Scope (DEB) { ... }
657             */
658
659            ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
660                BufferPtr, AcpiUtGetTypeName (Node->Type)));
661
662            Node->Type = ACPI_TYPE_ANY;
663            WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
664            break;
665
666        default:
667
668            /* All other types are an error */
669
670            ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n",
671                AcpiUtGetTypeName (Node->Type), BufferPtr));
672
673            return (AE_AML_OPERAND_TYPE);
674        }
675        break;
676
677    default:
678
679        /* All other opcodes */
680
681        if (Op && Op->Common.Node)
682        {
683            /* This op/node was previously entered into the namespace */
684
685            Node = Op->Common.Node;
686
687            if (AcpiNsOpensScope (ObjectType))
688            {
689                Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
690                if (ACPI_FAILURE (Status))
691                {
692                    return_ACPI_STATUS (Status);
693                }
694
695            }
696            return_ACPI_STATUS (AE_OK);
697        }
698
699        /*
700         * Enter the named type into the internal namespace.  We enter the name
701         * as we go downward in the parse tree.  Any necessary subobjects that involve
702         * arguments to the opcode must be created as we go back up the parse tree later.
703         */
704        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
705                        ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, WalkState, &(Node));
706        break;
707    }
708
709    if (ACPI_FAILURE (Status))
710    {
711        ACPI_REPORT_NSERROR (BufferPtr, Status);
712        return_ACPI_STATUS (Status);
713    }
714
715
716    if (!Op)
717    {
718        /* Create a new op */
719
720        Op = AcpiPsAllocOp (WalkState->Opcode);
721        if (!Op)
722        {
723            return_ACPI_STATUS (AE_NO_MEMORY);
724        }
725
726        /* Initialize the new op */
727
728        if (Node)
729        {
730            Op->Named.Name = Node->Name.Integer;
731        }
732        if (OutOp)
733        {
734            *OutOp = Op;
735        }
736    }
737
738    /*
739     * Put the Node in the "op" object that the parser uses, so we
740     * can get it again quickly when this scope is closed
741     */
742    Op->Common.Node = Node;
743
744    return_ACPI_STATUS (Status);
745}
746
747
748/*******************************************************************************
749 *
750 * FUNCTION:    AcpiDsLoad2EndOp
751 *
752 * PARAMETERS:  WalkState       - Current state of the parse tree walk
753 *              Op              - Op that has been just been completed in the
754 *                                walk;  Arguments have now been evaluated.
755 *
756 * RETURN:      Status
757 *
758 * DESCRIPTION: Ascending callback used during the loading of the namespace,
759 *              both control methods and everything else.
760 *
761 ******************************************************************************/
762
763ACPI_STATUS
764AcpiDsLoad2EndOp (
765    ACPI_WALK_STATE         *WalkState)
766{
767    ACPI_PARSE_OBJECT       *Op;
768    ACPI_STATUS             Status = AE_OK;
769    ACPI_OBJECT_TYPE        ObjectType;
770    ACPI_NAMESPACE_NODE     *Node;
771    ACPI_PARSE_OBJECT       *Arg;
772    ACPI_NAMESPACE_NODE     *NewNode;
773#ifndef ACPI_NO_METHOD_EXECUTION
774    UINT32                  i;
775#endif
776
777
778    ACPI_FUNCTION_TRACE ("DsLoad2EndOp");
779
780    Op = WalkState->Op;
781    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
782            WalkState->OpInfo->Name, Op, WalkState));
783
784    /* Only interested in opcodes that have namespace objects */
785
786    if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
787    {
788        return_ACPI_STATUS (AE_OK);
789    }
790
791    if (Op->Common.AmlOpcode == AML_SCOPE_OP)
792    {
793        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
794            "Ending scope Op=%p State=%p\n", Op, WalkState));
795    }
796
797
798    ObjectType = WalkState->OpInfo->ObjectType;
799
800    /*
801     * Get the Node/name from the earlier lookup
802     * (It was saved in the *op structure)
803     */
804    Node = Op->Common.Node;
805
806    /*
807     * Put the Node on the object stack (Contains the ACPI Name of
808     * this object)
809     */
810    WalkState->Operands[0] = (void *) Node;
811    WalkState->NumOperands = 1;
812
813    /* Pop the scope stack */
814
815    if (AcpiNsOpensScope (ObjectType) && (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
816    {
817        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
818            AcpiUtGetTypeName (ObjectType), Op));
819
820        Status = AcpiDsScopeStackPop (WalkState);
821        if (ACPI_FAILURE (Status))
822        {
823            goto Cleanup;
824        }
825    }
826
827    /*
828     * Named operations are as follows:
829     *
830     * AML_ALIAS
831     * AML_BANKFIELD
832     * AML_CREATEBITFIELD
833     * AML_CREATEBYTEFIELD
834     * AML_CREATEDWORDFIELD
835     * AML_CREATEFIELD
836     * AML_CREATEQWORDFIELD
837     * AML_CREATEWORDFIELD
838     * AML_DATA_REGION
839     * AML_DEVICE
840     * AML_EVENT
841     * AML_FIELD
842     * AML_INDEXFIELD
843     * AML_METHOD
844     * AML_METHODCALL
845     * AML_MUTEX
846     * AML_NAME
847     * AML_NAMEDFIELD
848     * AML_OPREGION
849     * AML_POWERRES
850     * AML_PROCESSOR
851     * AML_SCOPE
852     * AML_THERMALZONE
853     */
854
855    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
856        "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
857        AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
858
859    /* Decode the opcode */
860
861    Arg = Op->Common.Value.Arg;
862
863    switch (WalkState->OpInfo->Type)
864    {
865#ifndef ACPI_NO_METHOD_EXECUTION
866
867    case AML_TYPE_CREATE_FIELD:
868
869        /*
870         * Create the field object, but the field buffer and index must
871         * be evaluated later during the execution phase
872         */
873        Status = AcpiDsCreateBufferField (Op, WalkState);
874        break;
875
876
877     case AML_TYPE_NAMED_FIELD:
878
879        switch (Op->Common.AmlOpcode)
880        {
881        case AML_INDEX_FIELD_OP:
882
883            Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
884                                            WalkState);
885            break;
886
887        case AML_BANK_FIELD_OP:
888
889            Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
890            break;
891
892        case AML_FIELD_OP:
893
894            Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
895            break;
896
897        default:
898            /* All NAMED_FIELD opcodes must be handled above */
899            break;
900        }
901        break;
902
903
904     case AML_TYPE_NAMED_SIMPLE:
905
906        Status = AcpiDsCreateOperands (WalkState, Arg);
907        if (ACPI_FAILURE (Status))
908        {
909            goto Cleanup;
910        }
911
912        switch (Op->Common.AmlOpcode)
913        {
914        case AML_PROCESSOR_OP:
915
916            Status = AcpiExCreateProcessor (WalkState);
917            break;
918
919        case AML_POWER_RES_OP:
920
921            Status = AcpiExCreatePowerResource (WalkState);
922            break;
923
924        case AML_MUTEX_OP:
925
926            Status = AcpiExCreateMutex (WalkState);
927            break;
928
929        case AML_EVENT_OP:
930
931            Status = AcpiExCreateEvent (WalkState);
932            break;
933
934        case AML_DATA_REGION_OP:
935
936            Status = AcpiExCreateTableRegion (WalkState);
937            break;
938
939        case AML_ALIAS_OP:
940
941            Status = AcpiExCreateAlias (WalkState);
942            break;
943
944        default:
945            /* Unknown opcode */
946
947            Status = AE_OK;
948            goto Cleanup;
949        }
950
951        /* Delete operands */
952
953        for (i = 1; i < WalkState->NumOperands; i++)
954        {
955            AcpiUtRemoveReference (WalkState->Operands[i]);
956            WalkState->Operands[i] = NULL;
957        }
958
959        break;
960#endif /* ACPI_NO_METHOD_EXECUTION */
961
962    case AML_TYPE_NAMED_COMPLEX:
963
964        switch (Op->Common.AmlOpcode)
965        {
966#ifndef ACPI_NO_METHOD_EXECUTION
967        case AML_REGION_OP:
968            /*
969             * The OpRegion is not fully parsed at this time.  Only valid argument is the SpaceId.
970             * (We must save the address of the AML of the address and length operands)
971             */
972            /*
973             * If we have a valid region, initialize it
974             * Namespace is NOT locked at this point.
975             */
976            Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node), FALSE);
977            if (ACPI_FAILURE (Status))
978            {
979                /*
980                 *  If AE_NOT_EXIST is returned, it is not fatal
981                 *  because many regions get created before a handler
982                 *  is installed for said region.
983                 */
984                if (AE_NOT_EXIST == Status)
985                {
986                    Status = AE_OK;
987                }
988            }
989            break;
990
991
992        case AML_NAME_OP:
993
994            Status = AcpiDsCreateNode (WalkState, Node, Op);
995            break;
996#endif /* ACPI_NO_METHOD_EXECUTION */
997
998
999        default:
1000            /* All NAMED_COMPLEX opcodes must be handled above */
1001            /* Note: Method objects were already created in Pass 1 */
1002            break;
1003        }
1004        break;
1005
1006
1007    case AML_CLASS_INTERNAL:
1008
1009        /* case AML_INT_NAMEPATH_OP: */
1010        break;
1011
1012
1013    case AML_CLASS_METHOD_CALL:
1014
1015        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1016            "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
1017            WalkState, Op, Node));
1018
1019        /*
1020         * Lookup the method name and save the Node
1021         */
1022        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
1023                        ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
1024                        ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1025                        WalkState, &(NewNode));
1026        if (ACPI_SUCCESS (Status))
1027        {
1028            /*
1029             * Make sure that what we found is indeed a method
1030             * We didn't search for a method on purpose, to see if the name would resolve
1031             */
1032            if (NewNode->Type != ACPI_TYPE_METHOD)
1033            {
1034                Status = AE_AML_OPERAND_TYPE;
1035            }
1036
1037            /* We could put the returned object (Node) on the object stack for later, but
1038             * for now, we will put it in the "op" object that the parser uses, so we
1039             * can get it again at the end of this scope
1040             */
1041            Op->Common.Node = NewNode;
1042        }
1043        else
1044        {
1045            ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
1046        }
1047        break;
1048
1049
1050    default:
1051        break;
1052    }
1053
1054Cleanup:
1055
1056    /* Remove the Node pushed at the very beginning */
1057
1058    WalkState->Operands[0] = NULL;
1059    WalkState->NumOperands = 0;
1060    return_ACPI_STATUS (Status);
1061}
1062
1063
1064