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