mkdep(1) seems to want the current directory on the include path,
[dragonfly.git] / sys / contrib / dev / acpica-unix-20031203 / interpreter / dispatcher / dswload.c
1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *              $Revision: 85 $
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
145 ACPI_STATUS
146 AcpiDsInitCallbacks (
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
195 ACPI_STATUS
196 AcpiDsLoad1BeginOp (
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]\n", 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         if (WalkState->DeferredNode)
334         {
335             /* This name is already in the namespace, get the node */
336
337             Node = WalkState->DeferredNode;
338             Status = AE_OK;
339             break;
340         }
341
342         Flags = ACPI_NS_NO_UPSEARCH;
343         if ((WalkState->Opcode != AML_SCOPE_OP) &&
344             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
345         {
346             Flags |= ACPI_NS_ERROR_IF_FOUND;
347             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
348                     AcpiUtGetTypeName (ObjectType)));
349         }
350         else
351         {
352             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n",
353                     AcpiUtGetTypeName (ObjectType)));
354         }
355
356         /*
357          * Enter the named type into the internal namespace.  We enter the name
358          * as we go downward in the parse tree.  Any necessary subobjects that involve
359          * arguments to the opcode must be created as we go back up the parse tree later.
360          */
361         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
362                         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
363         if (ACPI_FAILURE (Status))
364         {
365             ACPI_REPORT_NSERROR (Path, Status);
366             return (Status);
367         }
368         break;
369     }
370
371
372     /* Common exit */
373
374     if (!Op)
375     {
376         /* Create a new op */
377
378         Op = AcpiPsAllocOp (WalkState->Opcode);
379         if (!Op)
380         {
381             return (AE_NO_MEMORY);
382         }
383     }
384
385     /* Initialize */
386
387     Op->Named.Name = Node->Name.Integer;
388
389 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
390     Op->Named.Path = (UINT8 *) Path;
391 #endif
392
393
394     /*
395      * Put the Node in the "op" object that the parser uses, so we
396      * can get it again quickly when this scope is closed
397      */
398     Op->Common.Node = Node;
399     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
400
401     *OutOp = Op;
402     return (Status);
403 }
404
405
406 /*******************************************************************************
407  *
408  * FUNCTION:    AcpiDsLoad1EndOp
409  *
410  * PARAMETERS:  WalkState       - Current state of the parse tree walk
411  *              Op              - Op that has been just been completed in the
412  *                                walk;  Arguments have now been evaluated.
413  *
414  * RETURN:      Status
415  *
416  * DESCRIPTION: Ascending callback used during the loading of the namespace,
417  *              both control methods and everything else.
418  *
419  ******************************************************************************/
420
421 ACPI_STATUS
422 AcpiDsLoad1EndOp (
423     ACPI_WALK_STATE         *WalkState)
424 {
425     ACPI_PARSE_OBJECT       *Op;
426     ACPI_OBJECT_TYPE        ObjectType;
427     ACPI_STATUS             Status = AE_OK;
428
429
430     ACPI_FUNCTION_NAME ("DsLoad1EndOp");
431
432
433     Op = WalkState->Op;
434     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
435
436     /* We are only interested in opcodes that have an associated name */
437
438     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
439     {
440         return (AE_OK);
441     }
442
443     /* Get the object type to determine if we should pop the scope */
444
445     ObjectType = WalkState->OpInfo->ObjectType;
446
447 #ifndef ACPI_NO_METHOD_EXECUTION
448     if (WalkState->OpInfo->Flags & AML_FIELD)
449     {
450         if (WalkState->Opcode == AML_FIELD_OP          ||
451             WalkState->Opcode == AML_BANK_FIELD_OP     ||
452             WalkState->Opcode == AML_INDEX_FIELD_OP)
453         {
454             Status = AcpiDsInitFieldObjects (Op, WalkState);
455         }
456         return (Status);
457     }
458
459
460     if (Op->Common.AmlOpcode == AML_REGION_OP)
461     {
462         Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
463                          (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer), WalkState);
464         if (ACPI_FAILURE (Status))
465         {
466             return (Status);
467         }
468     }
469 #endif
470
471     if (Op->Common.AmlOpcode == AML_NAME_OP)
472     {
473         /* For Name opcode, get the object type from the argument */
474
475         if (Op->Common.Value.Arg)
476         {
477             ObjectType = (AcpiPsGetOpcodeInfo ((Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
478             Op->Common.Node->Type = (UINT8) ObjectType;
479         }
480     }
481
482     if (Op->Common.AmlOpcode == AML_METHOD_OP)
483     {
484         /*
485          * MethodOp PkgLength NameString MethodFlags TermList
486          *
487          * Note: We must create the method node/object pair as soon as we
488          * see the method declaration.  This allows later pass1 parsing
489          * of invocations of the method (need to know the number of
490          * arguments.)
491          */
492         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
493             "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
494             WalkState, Op, Op->Named.Node));
495
496         if (!AcpiNsGetAttachedObject (Op->Named.Node))
497         {
498             WalkState->Operands[0] = (void *) Op->Named.Node;
499             WalkState->NumOperands = 1;
500
501             Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
502             if (ACPI_SUCCESS (Status))
503             {
504                 Status = AcpiExCreateMethod (Op->Named.Data,
505                                     Op->Named.Length, WalkState);
506             }
507             WalkState->Operands[0] = NULL;
508             WalkState->NumOperands = 0;
509
510             if (ACPI_FAILURE (Status))
511             {
512                 return (Status);
513             }
514         }
515     }
516
517     /* Pop the scope stack */
518
519     if (AcpiNsOpensScope (ObjectType))
520     {
521         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
522             AcpiUtGetTypeName (ObjectType), Op));
523
524         Status = AcpiDsScopeStackPop (WalkState);
525     }
526
527     return (Status);
528 }
529
530
531 /*******************************************************************************
532  *
533  * FUNCTION:    AcpiDsLoad2BeginOp
534  *
535  * PARAMETERS:  WalkState       - Current state of the parse tree walk
536  *              Op              - Op that has been just been reached in the
537  *                                walk;  Arguments have not been evaluated yet.
538  *
539  * RETURN:      Status
540  *
541  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
542  *
543  ******************************************************************************/
544
545 ACPI_STATUS
546 AcpiDsLoad2BeginOp (
547     ACPI_WALK_STATE         *WalkState,
548     ACPI_PARSE_OBJECT       **OutOp)
549 {
550     ACPI_PARSE_OBJECT       *Op;
551     ACPI_NAMESPACE_NODE     *Node;
552     ACPI_STATUS             Status;
553     ACPI_OBJECT_TYPE        ObjectType;
554     char                    *BufferPtr;
555
556
557     ACPI_FUNCTION_TRACE ("DsLoad2BeginOp");
558
559
560     Op = WalkState->Op;
561     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
562
563     if (Op)
564     {
565         /* We only care about Namespace opcodes here */
566
567         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE) && (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
568             (!(WalkState->OpInfo->Flags & AML_NAMED)))
569         {
570             return_ACPI_STATUS (AE_OK);
571         }
572
573         /*
574          * Get the name we are going to enter or lookup in the namespace
575          */
576         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
577         {
578             /* For Namepath op, get the path string */
579
580             BufferPtr = Op->Common.Value.String;
581             if (!BufferPtr)
582             {
583                 /* No name, just exit */
584
585                 return_ACPI_STATUS (AE_OK);
586             }
587         }
588         else
589         {
590             /* Get name from the op */
591
592             BufferPtr = (char *) &Op->Named.Name;
593         }
594     }
595     else
596     {
597         /* Get the namestring from the raw AML */
598
599         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
600     }
601
602     /* Map the opcode into an internal object type */
603
604     ObjectType = WalkState->OpInfo->ObjectType;
605
606     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
607         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
608
609
610     switch (WalkState->Opcode)
611     {
612     case AML_FIELD_OP:
613     case AML_BANK_FIELD_OP:
614     case AML_INDEX_FIELD_OP:
615
616         Node = NULL;
617         Status = AE_OK;
618         break;
619
620     case AML_INT_NAMEPATH_OP:
621
622         /*
623          * The NamePath 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         break;
629
630     case AML_SCOPE_OP:
631
632         /*
633          * The Path is an object reference to an existing object.  Don't enter the
634          * name into the namespace, but look it up for use later
635          */
636         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
637                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
638         if (ACPI_FAILURE (Status))
639         {
640             ACPI_REPORT_NSERROR (BufferPtr, Status);
641             return_ACPI_STATUS (Status);
642         }
643         /*
644          * We must check to make sure that the target is
645          * one of the opcodes that actually opens a scope
646          */
647         switch (Node->Type)
648         {
649         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
650         case ACPI_TYPE_DEVICE:
651         case ACPI_TYPE_POWER:
652         case ACPI_TYPE_PROCESSOR:
653         case ACPI_TYPE_THERMAL:
654
655             /* These are acceptable types */
656             break;
657
658         case ACPI_TYPE_INTEGER:
659         case ACPI_TYPE_STRING:
660         case ACPI_TYPE_BUFFER:
661
662             /*
663              * These types we will allow, but we will change the type.  This
664              * enables some existing code of the form:
665              *
666              *  Name (DEB, 0)
667              *  Scope (DEB) { ... }
668              */
669
670             ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
671                 BufferPtr, AcpiUtGetTypeName (Node->Type)));
672
673             Node->Type = ACPI_TYPE_ANY;
674             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
675             break;
676
677         default:
678
679             /* All other types are an error */
680
681             ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n",
682                 AcpiUtGetTypeName (Node->Type), BufferPtr));
683
684             return (AE_AML_OPERAND_TYPE);
685         }
686         break;
687
688     default:
689
690         /* All other opcodes */
691
692         if (Op && Op->Common.Node)
693         {
694             /* This op/node was previously entered into the namespace */
695
696             Node = Op->Common.Node;
697
698             if (AcpiNsOpensScope (ObjectType))
699             {
700                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
701                 if (ACPI_FAILURE (Status))
702                 {
703                     return_ACPI_STATUS (Status);
704                 }
705
706             }
707             return_ACPI_STATUS (AE_OK);
708         }
709
710         /*
711          * Enter the named type into the internal namespace.  We enter the name
712          * as we go downward in the parse tree.  Any necessary subobjects that involve
713          * arguments to the opcode must be created as we go back up the parse tree later.
714          *
715          * Note: Name may already exist if we are executing a deferred opcode.
716          */
717         if (WalkState->DeferredNode)
718         {
719             /* This name is already in the namespace, get the node */
720
721             Node = WalkState->DeferredNode;
722             Status = AE_OK;
723             break;
724         }
725
726         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
727                         ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, WalkState, &(Node));
728         break;
729     }
730
731     if (ACPI_FAILURE (Status))
732     {
733         ACPI_REPORT_NSERROR (BufferPtr, Status);
734         return_ACPI_STATUS (Status);
735     }
736
737
738     if (!Op)
739     {
740         /* Create a new op */
741
742         Op = AcpiPsAllocOp (WalkState->Opcode);
743         if (!Op)
744         {
745             return_ACPI_STATUS (AE_NO_MEMORY);
746         }
747
748         /* Initialize the new op */
749
750         if (Node)
751         {
752             Op->Named.Name = Node->Name.Integer;
753         }
754         if (OutOp)
755         {
756             *OutOp = Op;
757         }
758     }
759
760     /*
761      * Put the Node in the "op" object that the parser uses, so we
762      * can get it again quickly when this scope is closed
763      */
764     Op->Common.Node = Node;
765
766     return_ACPI_STATUS (Status);
767 }
768
769
770 /*******************************************************************************
771  *
772  * FUNCTION:    AcpiDsLoad2EndOp
773  *
774  * PARAMETERS:  WalkState       - Current state of the parse tree walk
775  *              Op              - Op that has been just been completed in the
776  *                                walk;  Arguments have now been evaluated.
777  *
778  * RETURN:      Status
779  *
780  * DESCRIPTION: Ascending callback used during the loading of the namespace,
781  *              both control methods and everything else.
782  *
783  ******************************************************************************/
784
785 ACPI_STATUS
786 AcpiDsLoad2EndOp (
787     ACPI_WALK_STATE         *WalkState)
788 {
789     ACPI_PARSE_OBJECT       *Op;
790     ACPI_STATUS             Status = AE_OK;
791     ACPI_OBJECT_TYPE        ObjectType;
792     ACPI_NAMESPACE_NODE     *Node;
793     ACPI_PARSE_OBJECT       *Arg;
794     ACPI_NAMESPACE_NODE     *NewNode;
795 #ifndef ACPI_NO_METHOD_EXECUTION
796     UINT32                  i;
797 #endif
798
799
800     ACPI_FUNCTION_TRACE ("DsLoad2EndOp");
801
802     Op = WalkState->Op;
803     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
804             WalkState->OpInfo->Name, Op, WalkState));
805
806     /* Only interested in opcodes that have namespace objects */
807
808     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
809     {
810         return_ACPI_STATUS (AE_OK);
811     }
812
813     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
814     {
815         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
816             "Ending scope Op=%p State=%p\n", Op, WalkState));
817     }
818
819
820     ObjectType = WalkState->OpInfo->ObjectType;
821
822     /*
823      * Get the Node/name from the earlier lookup
824      * (It was saved in the *op structure)
825      */
826     Node = Op->Common.Node;
827
828     /*
829      * Put the Node on the object stack (Contains the ACPI Name of
830      * this object)
831      */
832     WalkState->Operands[0] = (void *) Node;
833     WalkState->NumOperands = 1;
834
835     /* Pop the scope stack */
836
837     if (AcpiNsOpensScope (ObjectType) && (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
838     {
839         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
840             AcpiUtGetTypeName (ObjectType), Op));
841
842         Status = AcpiDsScopeStackPop (WalkState);
843         if (ACPI_FAILURE (Status))
844         {
845             goto Cleanup;
846         }
847     }
848
849     /*
850      * Named operations are as follows:
851      *
852      * AML_ALIAS
853      * AML_BANKFIELD
854      * AML_CREATEBITFIELD
855      * AML_CREATEBYTEFIELD
856      * AML_CREATEDWORDFIELD
857      * AML_CREATEFIELD
858      * AML_CREATEQWORDFIELD
859      * AML_CREATEWORDFIELD
860      * AML_DATA_REGION
861      * AML_DEVICE
862      * AML_EVENT
863      * AML_FIELD
864      * AML_INDEXFIELD
865      * AML_METHOD
866      * AML_METHODCALL
867      * AML_MUTEX
868      * AML_NAME
869      * AML_NAMEDFIELD
870      * AML_OPREGION
871      * AML_POWERRES
872      * AML_PROCESSOR
873      * AML_SCOPE
874      * AML_THERMALZONE
875      */
876
877     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
878         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
879         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
880
881     /* Decode the opcode */
882
883     Arg = Op->Common.Value.Arg;
884
885     switch (WalkState->OpInfo->Type)
886     {
887 #ifndef ACPI_NO_METHOD_EXECUTION
888
889     case AML_TYPE_CREATE_FIELD:
890
891         /*
892          * Create the field object, but the field buffer and index must
893          * be evaluated later during the execution phase
894          */
895         Status = AcpiDsCreateBufferField (Op, WalkState);
896         break;
897
898
899      case AML_TYPE_NAMED_FIELD:
900
901         switch (Op->Common.AmlOpcode)
902         {
903         case AML_INDEX_FIELD_OP:
904
905             Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
906                                             WalkState);
907             break;
908
909         case AML_BANK_FIELD_OP:
910
911             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
912             break;
913
914         case AML_FIELD_OP:
915
916             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
917             break;
918
919         default:
920             /* All NAMED_FIELD opcodes must be handled above */
921             break;
922         }
923         break;
924
925
926      case AML_TYPE_NAMED_SIMPLE:
927
928         Status = AcpiDsCreateOperands (WalkState, Arg);
929         if (ACPI_FAILURE (Status))
930         {
931             goto Cleanup;
932         }
933
934         switch (Op->Common.AmlOpcode)
935         {
936         case AML_PROCESSOR_OP:
937
938             Status = AcpiExCreateProcessor (WalkState);
939             break;
940
941         case AML_POWER_RES_OP:
942
943             Status = AcpiExCreatePowerResource (WalkState);
944             break;
945
946         case AML_MUTEX_OP:
947
948             Status = AcpiExCreateMutex (WalkState);
949             break;
950
951         case AML_EVENT_OP:
952
953             Status = AcpiExCreateEvent (WalkState);
954             break;
955
956         case AML_DATA_REGION_OP:
957
958             Status = AcpiExCreateTableRegion (WalkState);
959             break;
960
961         case AML_ALIAS_OP:
962
963             Status = AcpiExCreateAlias (WalkState);
964             break;
965
966         default:
967             /* Unknown opcode */
968
969             Status = AE_OK;
970             goto Cleanup;
971         }
972
973         /* Delete operands */
974
975         for (i = 1; i < WalkState->NumOperands; i++)
976         {
977             AcpiUtRemoveReference (WalkState->Operands[i]);
978             WalkState->Operands[i] = NULL;
979         }
980
981         break;
982 #endif /* ACPI_NO_METHOD_EXECUTION */
983
984     case AML_TYPE_NAMED_COMPLEX:
985
986         switch (Op->Common.AmlOpcode)
987         {
988 #ifndef ACPI_NO_METHOD_EXECUTION
989         case AML_REGION_OP:
990             /*
991              * The OpRegion is not fully parsed at this time.  Only valid argument is the SpaceId.
992              * (We must save the address of the AML of the address and length operands)
993              */
994             /*
995              * If we have a valid region, initialize it
996              * Namespace is NOT locked at this point.
997              */
998             Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node), FALSE);
999             if (ACPI_FAILURE (Status))
1000             {
1001                 /*
1002                  *  If AE_NOT_EXIST is returned, it is not fatal
1003                  *  because many regions get created before a handler
1004                  *  is installed for said region.
1005                  */
1006                 if (AE_NOT_EXIST == Status)
1007                 {
1008                     Status = AE_OK;
1009                 }
1010             }
1011             break;
1012
1013
1014         case AML_NAME_OP:
1015
1016             Status = AcpiDsCreateNode (WalkState, Node, Op);
1017             break;
1018 #endif /* ACPI_NO_METHOD_EXECUTION */
1019
1020
1021         default:
1022             /* All NAMED_COMPLEX opcodes must be handled above */
1023             /* Note: Method objects were already created in Pass 1 */
1024             break;
1025         }
1026         break;
1027
1028
1029     case AML_CLASS_INTERNAL:
1030
1031         /* case AML_INT_NAMEPATH_OP: */
1032         break;
1033
1034
1035     case AML_CLASS_METHOD_CALL:
1036
1037         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1038             "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
1039             WalkState, Op, Node));
1040
1041         /*
1042          * Lookup the method name and save the Node
1043          */
1044         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
1045                         ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
1046                         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1047                         WalkState, &(NewNode));
1048         if (ACPI_SUCCESS (Status))
1049         {
1050             /*
1051              * Make sure that what we found is indeed a method
1052              * We didn't search for a method on purpose, to see if the name would resolve
1053              */
1054             if (NewNode->Type != ACPI_TYPE_METHOD)
1055             {
1056                 Status = AE_AML_OPERAND_TYPE;
1057             }
1058
1059             /* We could put the returned object (Node) on the object stack for later, but
1060              * for now, we will put it in the "op" object that the parser uses, so we
1061              * can get it again at the end of this scope
1062              */
1063             Op->Common.Node = NewNode;
1064         }
1065         else
1066         {
1067             ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
1068         }
1069         break;
1070
1071
1072     default:
1073         break;
1074     }
1075
1076 Cleanup:
1077
1078     /* Remove the Node pushed at the very beginning */
1079
1080     WalkState->Operands[0] = NULL;
1081     WalkState->NumOperands = 0;
1082     return_ACPI_STATUS (Status);
1083 }
1084
1085