OSDN Git Service

klibc基本機能実装. ACPICAの準備
[vaneos/DivergeMirror.git] / drivers / acpi / compiler / aslload.c
1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116 #include "aslcompiler.h"
117 #include "amlcode.h"
118 #include "acdispat.h"
119 #include "acnamesp.h"
120
121 #include "aslcompiler.y.h"
122
123 #define _COMPONENT          ACPI_COMPILER
124         ACPI_MODULE_NAME    ("aslload")
125
126 /* Local prototypes */
127
128 static ACPI_STATUS
129 LdLoadFieldElements (
130     ACPI_PARSE_OBJECT       *Op,
131     ACPI_WALK_STATE         *WalkState);
132
133 static ACPI_STATUS
134 LdLoadResourceElements (
135     ACPI_PARSE_OBJECT       *Op,
136     ACPI_WALK_STATE         *WalkState);
137
138 static ACPI_STATUS
139 LdNamespace1Begin (
140     ACPI_PARSE_OBJECT       *Op,
141     UINT32                  Level,
142     void                    *Context);
143
144 static ACPI_STATUS
145 LdNamespace2Begin (
146     ACPI_PARSE_OBJECT       *Op,
147     UINT32                  Level,
148     void                    *Context);
149
150 static ACPI_STATUS
151 LdCommonNamespaceEnd (
152     ACPI_PARSE_OBJECT       *Op,
153     UINT32                  Level,
154     void                    *Context);
155
156
157 /*******************************************************************************
158  *
159  * FUNCTION:    LdLoadNamespace
160  *
161  * PARAMETERS:  RootOp      - Root of the parse tree
162  *
163  * RETURN:      Status
164  *
165  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
166  *              named ASL/AML objects into the namespace. The namespace is
167  *              constructed in order to resolve named references and references
168  *              to named fields within resource templates/descriptors.
169  *
170  ******************************************************************************/
171
172 ACPI_STATUS
173 LdLoadNamespace (
174     ACPI_PARSE_OBJECT       *RootOp)
175 {
176     ACPI_WALK_STATE         *WalkState;
177
178
179     DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n");
180
181     /* Create a new walk state */
182
183     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
184     if (!WalkState)
185     {
186         return (AE_NO_MEMORY);
187     }
188
189     /* Walk the entire parse tree, first pass */
190
191     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
192         LdCommonNamespaceEnd, WalkState);
193
194     /* Second pass to handle forward references */
195
196     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
197         LdCommonNamespaceEnd, WalkState);
198
199     /* Dump the namespace if debug is enabled */
200
201     AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
202     ACPI_FREE (WalkState);
203     return (AE_OK);
204 }
205
206
207 /*******************************************************************************
208  *
209  * FUNCTION:    LdLoadFieldElements
210  *
211  * PARAMETERS:  Op              - Parent node (Field)
212  *              WalkState       - Current walk state
213  *
214  * RETURN:      Status
215  *
216  * DESCRIPTION: Enter the named elements of the field (children of the parent)
217  *              into the namespace.
218  *
219  ******************************************************************************/
220
221 static ACPI_STATUS
222 LdLoadFieldElements (
223     ACPI_PARSE_OBJECT       *Op,
224     ACPI_WALK_STATE         *WalkState)
225 {
226     ACPI_PARSE_OBJECT       *Child = NULL;
227     ACPI_NAMESPACE_NODE     *Node;
228     ACPI_STATUS             Status;
229
230
231     /* Get the first named field element */
232
233     switch (Op->Asl.AmlOpcode)
234     {
235     case AML_BANK_FIELD_OP:
236
237         Child = UtGetArg (Op, 6);
238         break;
239
240     case AML_INDEX_FIELD_OP:
241
242         Child = UtGetArg (Op, 5);
243         break;
244
245     case AML_FIELD_OP:
246
247         Child = UtGetArg (Op, 4);
248         break;
249
250     default:
251
252         /* No other opcodes should arrive here */
253
254         return (AE_BAD_PARAMETER);
255     }
256
257     /* Enter all elements into the namespace */
258
259     while (Child)
260     {
261         switch (Child->Asl.AmlOpcode)
262         {
263         case AML_INT_RESERVEDFIELD_OP:
264         case AML_INT_ACCESSFIELD_OP:
265         case AML_INT_CONNECTION_OP:
266             break;
267
268         default:
269
270             Status = AcpiNsLookup (WalkState->ScopeInfo,
271                         Child->Asl.Value.String,
272                         ACPI_TYPE_LOCAL_REGION_FIELD,
273                         ACPI_IMODE_LOAD_PASS1,
274                         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
275                             ACPI_NS_ERROR_IF_FOUND,
276                         NULL, &Node);
277             if (ACPI_FAILURE (Status))
278             {
279                 if (Status != AE_ALREADY_EXISTS)
280                 {
281                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
282                         Child->Asl.Value.String);
283                     return (Status);
284                 }
285
286                 /*
287                  * The name already exists in this scope
288                  * But continue processing the elements
289                  */
290                 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
291                     Child->Asl.Value.String);
292             }
293             else
294             {
295                 Child->Asl.Node = Node;
296                 Node->Op = Child;
297             }
298             break;
299         }
300
301         Child = Child->Asl.Next;
302     }
303
304     return (AE_OK);
305 }
306
307
308 /*******************************************************************************
309  *
310  * FUNCTION:    LdLoadResourceElements
311  *
312  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
313  *              WalkState       - Current walk state
314  *
315  * RETURN:      Status
316  *
317  * DESCRIPTION: Enter the named elements of the resource descriptor (children
318  *              of the parent) into the namespace.
319  *
320  * NOTE: In the real AML namespace, these named elements never exist. But
321  *       we simply use the namespace here as a symbol table so we can look
322  *       them up as they are referenced.
323  *
324  ******************************************************************************/
325
326 static ACPI_STATUS
327 LdLoadResourceElements (
328     ACPI_PARSE_OBJECT       *Op,
329     ACPI_WALK_STATE         *WalkState)
330 {
331     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
332     ACPI_NAMESPACE_NODE     *Node;
333     ACPI_STATUS             Status;
334
335
336     /*
337      * Enter the resource name into the namespace. Name must not already exist.
338      * This opens a scope, so later field names are guaranteed to be new/unique.
339      */
340     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
341                 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
342                 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
343                 WalkState, &Node);
344     if (ACPI_FAILURE (Status))
345     {
346         if (Status == AE_ALREADY_EXISTS)
347         {
348             /* Actual node causing the error was saved in ParentMethod */
349
350             AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
351                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath);
352             return (AE_OK);
353         }
354         return (Status);
355     }
356
357     Node->Value = (UINT32) Op->Asl.Value.Integer;
358     Node->Op = Op;
359     Op->Asl.Node = Node;
360
361     /*
362      * Now enter the predefined fields, for easy lookup when referenced
363      * by the source ASL
364      */
365     InitializerOp = ASL_GET_CHILD_NODE (Op);
366     while (InitializerOp)
367     {
368         if (InitializerOp->Asl.ExternalName)
369         {
370             Status = AcpiNsLookup (WalkState->ScopeInfo,
371                         InitializerOp->Asl.ExternalName,
372                         ACPI_TYPE_LOCAL_RESOURCE_FIELD,
373                         ACPI_IMODE_LOAD_PASS1,
374                         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
375                         NULL, &Node);
376             if (ACPI_FAILURE (Status))
377             {
378                 return (Status);
379             }
380
381             /*
382              * Store the field offset and length in the namespace node
383              * so it can be used when the field is referenced
384              */
385             Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
386             Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
387             InitializerOp->Asl.Node = Node;
388             Node->Op = InitializerOp;
389         }
390
391         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
392     }
393
394     return (AE_OK);
395 }
396
397
398 /*******************************************************************************
399  *
400  * FUNCTION:    LdNamespace1Begin
401  *
402  * PARAMETERS:  ASL_WALK_CALLBACK
403  *
404  * RETURN:      Status
405  *
406  * DESCRIPTION: Descending callback used during the parse tree walk. If this
407  *              is a named AML opcode, enter into the namespace
408  *
409  ******************************************************************************/
410
411 static ACPI_STATUS
412 LdNamespace1Begin (
413     ACPI_PARSE_OBJECT       *Op,
414     UINT32                  Level,
415     void                    *Context)
416 {
417     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
418     ACPI_NAMESPACE_NODE     *Node;
419     ACPI_STATUS             Status;
420     ACPI_OBJECT_TYPE        ObjectType;
421     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
422     char                    *Path;
423     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
424     ACPI_PARSE_OBJECT       *Arg;
425     UINT32                  i;
426     BOOLEAN                 ForceNewScope = FALSE;
427
428
429     ACPI_FUNCTION_NAME (LdNamespace1Begin);
430     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
431         Op, Op->Asl.ParseOpName));
432
433     /*
434      * We are only interested in opcodes that have an associated name
435      * (or multiple names)
436      */
437     switch (Op->Asl.AmlOpcode)
438     {
439     case AML_BANK_FIELD_OP:
440     case AML_INDEX_FIELD_OP:
441     case AML_FIELD_OP:
442
443         Status = LdLoadFieldElements (Op, WalkState);
444         return (Status);
445
446     case AML_INT_CONNECTION_OP:
447
448
449         if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
450         {
451             break;
452         }
453         Arg = Op->Asl.Child;
454
455         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
456             ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
457             WalkState, &Node);
458         if (ACPI_FAILURE (Status))
459         {
460             break;
461         }
462
463         if (Node->Type == ACPI_TYPE_BUFFER)
464         {
465             Arg->Asl.Node = Node;
466
467             Arg = Node->Op->Asl.Child;  /* Get namepath */
468             Arg = Arg->Asl.Next;        /* Get actual buffer */
469             Arg = Arg->Asl.Child;       /* Buffer length */
470             Arg = Arg->Asl.Next;        /* RAW_DATA buffer */
471         }
472         break;
473
474     default:
475
476         /* All other opcodes go below */
477
478         break;
479     }
480
481     /* Check if this object has already been installed in the namespace */
482
483     if (Op->Asl.Node)
484     {
485         return (AE_OK);
486     }
487
488     Path = Op->Asl.Namepath;
489     if (!Path)
490     {
491         return (AE_OK);
492     }
493
494     /* Map the raw opcode into an internal object type */
495
496     switch (Op->Asl.ParseOpcode)
497     {
498     case PARSEOP_NAME:
499
500         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
501         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
502
503         /*
504          * If this name refers to a ResourceTemplate, we will need to open
505          * a new scope so that the resource subfield names can be entered into
506          * the namespace underneath this name
507          */
508         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
509         {
510             ForceNewScope = TRUE;
511         }
512
513         /* Get the data type associated with the named object, not the name itself */
514
515         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
516
517         ObjectType = 1;
518         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
519         {
520             ObjectType++;
521         }
522         break;
523
524
525     case PARSEOP_EXTERNAL:
526         /*
527          * "External" simply enters a name and type into the namespace.
528          * We must be careful to not open a new scope, however, no matter
529          * what type the external name refers to (e.g., a method)
530          *
531          * first child is name, next child is ObjectType
532          */
533         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
534         ObjectType = ACPI_TYPE_ANY;
535
536         /*
537          * We will mark every new node along the path as "External". This
538          * allows some or all of the nodes to be created later in the ASL
539          * code. Handles cases like this:
540          *
541          *   External (\_SB_.PCI0.ABCD, IntObj)
542          *   Scope (_SB_)
543          *   {
544          *       Device (PCI0)
545          *       {
546          *       }
547          *   }
548          *   Method (X)
549          *   {
550          *       Store (\_SB_.PCI0.ABCD, Local0)
551          *   }
552          */
553         Flags |= ACPI_NS_EXTERNAL;
554         break;
555
556     case PARSEOP_DEFAULT_ARG:
557
558         if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
559         {
560             Status = LdLoadResourceElements (Op, WalkState);
561             return_ACPI_STATUS (Status);
562         }
563
564         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
565         break;
566
567     case PARSEOP_SCOPE:
568         /*
569          * The name referenced by Scope(Name) must already exist at this point.
570          * In other words, forward references for Scope() are not supported.
571          * The only real reason for this is that the MS interpreter cannot
572          * handle this case. Perhaps someday this case can go away.
573          */
574         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
575                     ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
576                     WalkState, &(Node));
577         if (ACPI_FAILURE (Status))
578         {
579             if (Status == AE_NOT_FOUND)
580             {
581                 /* The name was not found, go ahead and create it */
582
583                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
584                             ACPI_TYPE_LOCAL_SCOPE,
585                             ACPI_IMODE_LOAD_PASS1, Flags,
586                             WalkState, &(Node));
587                 if (ACPI_FAILURE (Status))
588                 {
589                     return_ACPI_STATUS (Status);
590                 }
591
592                 /*
593                  * However, this is an error -- primarily because the MS
594                  * interpreter can't handle a forward reference from the
595                  * Scope() operator.
596                  */
597                 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
598                     Op->Asl.ExternalName);
599                 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op,
600                     Op->Asl.ExternalName);
601                 goto FinishNode;
602             }
603
604             AslCoreSubsystemError (Op, Status,
605                 "Failure from namespace lookup", FALSE);
606
607             return_ACPI_STATUS (Status);
608         }
609
610         /* We found a node with this name, now check the type */
611
612         switch (Node->Type)
613         {
614         case ACPI_TYPE_LOCAL_SCOPE:
615         case ACPI_TYPE_DEVICE:
616         case ACPI_TYPE_POWER:
617         case ACPI_TYPE_PROCESSOR:
618         case ACPI_TYPE_THERMAL:
619
620             /* These are acceptable types - they all open a new scope */
621             break;
622
623         case ACPI_TYPE_INTEGER:
624         case ACPI_TYPE_STRING:
625         case ACPI_TYPE_BUFFER:
626             /*
627              * These types we will allow, but we will change the type.
628              * This enables some existing code of the form:
629              *
630              *  Name (DEB, 0)
631              *  Scope (DEB) { ... }
632              *
633              * Which is used to workaround the fact that the MS interpreter
634              * does not allow Scope() forward references.
635              */
636             sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
637                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
638             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
639
640             /* Switch the type to scope, open the new scope */
641
642             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
643             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
644                         WalkState);
645             if (ACPI_FAILURE (Status))
646             {
647                 return_ACPI_STATUS (Status);
648             }
649             break;
650
651         default:
652
653             /* All other types are an error */
654
655             sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
656                 AcpiUtGetTypeName (Node->Type));
657             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
658
659             /*
660              * However, switch the type to be an actual scope so
661              * that compilation can continue without generating a whole
662              * cascade of additional errors. Open the new scope.
663              */
664             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
665             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
666                         WalkState);
667             if (ACPI_FAILURE (Status))
668             {
669                 return_ACPI_STATUS (Status);
670             }
671             break;
672         }
673
674         Status = AE_OK;
675         goto FinishNode;
676
677
678     default:
679
680         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
681         break;
682     }
683
684
685     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
686             Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
687
688     /* The name must not already exist */
689
690     Flags |= ACPI_NS_ERROR_IF_FOUND;
691
692     /*
693      * Enter the named type into the internal namespace. We enter the name
694      * as we go downward in the parse tree. Any necessary subobjects that
695      * involve arguments to the opcode must be created as we go back up the
696      * parse tree later.
697      */
698     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
699                     ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
700     if (ACPI_FAILURE (Status))
701     {
702         if (Status == AE_ALREADY_EXISTS)
703         {
704             /* The name already exists in this scope */
705
706             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
707             {
708                 /* Allow multiple references to the same scope */
709
710                 Node->Type = (UINT8) ObjectType;
711                 Status = AE_OK;
712             }
713             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
714                      (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
715             {
716                 /*
717                  * Allow one create on an object or segment that was
718                  * previously declared External
719                  */
720                 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
721                 Node->Type = (UINT8) ObjectType;
722
723                 /* Just retyped a node, probably will need to open a scope */
724
725                 if (AcpiNsOpensScope (ObjectType))
726                 {
727                     Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
728                     if (ACPI_FAILURE (Status))
729                     {
730                         return_ACPI_STATUS (Status);
731                     }
732                 }
733                 Status = AE_OK;
734             }
735             else
736             {
737                 /* Valid error, object already exists */
738
739                 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
740                     Op->Asl.ExternalName);
741                 return_ACPI_STATUS (AE_OK);
742             }
743         }
744         else
745         {
746             AslCoreSubsystemError (Op, Status,
747                 "Failure from namespace lookup", FALSE);
748             return_ACPI_STATUS (Status);
749         }
750     }
751
752     if (ForceNewScope)
753     {
754         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
755         if (ACPI_FAILURE (Status))
756         {
757             return_ACPI_STATUS (Status);
758         }
759     }
760
761 FinishNode:
762     /*
763      * Point the parse node to the new namespace node, and point
764      * the Node back to the original Parse node
765      */
766     Op->Asl.Node = Node;
767     Node->Op = Op;
768
769     /* Set the actual data type if appropriate (EXTERNAL term only) */
770
771     if (ActualObjectType != ACPI_TYPE_ANY)
772     {
773         Node->Type = (UINT8) ActualObjectType;
774         Node->Value = ASL_EXTERNAL_METHOD;
775     }
776
777     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
778     {
779         /*
780          * Get the method argument count from "Extra" and save
781          * it in the namespace node
782          */
783         Node->Value = (UINT32) Op->Asl.Extra;
784     }
785
786     return_ACPI_STATUS (Status);
787 }
788
789
790 /*******************************************************************************
791  *
792  * FUNCTION:    LdNamespace2Begin
793  *
794  * PARAMETERS:  ASL_WALK_CALLBACK
795  *
796  * RETURN:      Status
797  *
798  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
799  *              Second pass resolves some forward references.
800  *
801  * Notes:
802  * Currently only needs to handle the Alias operator.
803  * Could be used to allow forward references from the Scope() operator, but
804  * the MS interpreter does not allow this, so this compiler does not either.
805  *
806  ******************************************************************************/
807
808 static ACPI_STATUS
809 LdNamespace2Begin (
810     ACPI_PARSE_OBJECT       *Op,
811     UINT32                  Level,
812     void                    *Context)
813 {
814     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
815     ACPI_STATUS             Status;
816     ACPI_NAMESPACE_NODE     *Node;
817     ACPI_OBJECT_TYPE        ObjectType;
818     BOOLEAN                 ForceNewScope = FALSE;
819     ACPI_PARSE_OBJECT       *Arg;
820     char                    *Path;
821     ACPI_NAMESPACE_NODE     *TargetNode;
822
823
824     ACPI_FUNCTION_NAME (LdNamespace2Begin);
825     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
826         Op, Op->Asl.ParseOpName));
827
828
829     /* Ignore Ops with no namespace node */
830
831     Node = Op->Asl.Node;
832     if (!Node)
833     {
834         return (AE_OK);
835     }
836
837     /* Get the type to determine if we should push the scope */
838
839     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
840         (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
841     {
842         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
843     }
844     else
845     {
846         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
847     }
848
849     /* Push scope for Resource Templates */
850
851     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
852     {
853         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
854         {
855             ForceNewScope = TRUE;
856         }
857     }
858
859     /* Push the scope stack */
860
861     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
862     {
863         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
864         if (ACPI_FAILURE (Status))
865         {
866             return_ACPI_STATUS (Status);
867         }
868     }
869
870     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
871     {
872         /* Complete the alias node by getting and saving the target node */
873
874         /* First child is the alias target */
875
876         Arg = Op->Asl.Child;
877
878         /* Get the target pathname */
879
880         Path = Arg->Asl.Namepath;
881         if (!Path)
882         {
883             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
884             if (ACPI_FAILURE (Status))
885             {
886                 return (Status);
887             }
888         }
889
890         /* Get the NS node associated with the target. It must exist. */
891
892         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
893                     ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
894                     WalkState, &TargetNode);
895         if (ACPI_FAILURE (Status))
896         {
897             if (Status == AE_NOT_FOUND)
898             {
899                 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
900                     Op->Asl.ExternalName);
901
902                 /*
903                  * The name was not found, go ahead and create it.
904                  * This prevents more errors later.
905                  */
906                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
907                             ACPI_TYPE_ANY,
908                             ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH,
909                             WalkState, &(Node));
910                 return (AE_OK);
911             }
912
913             AslCoreSubsystemError (Op, Status,
914                 "Failure from namespace lookup", FALSE);
915             return (AE_OK);
916         }
917
918         /* Save the target node within the alias node */
919
920         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
921     }
922
923     return (AE_OK);
924 }
925
926
927 /*******************************************************************************
928  *
929  * FUNCTION:    LdCommonNamespaceEnd
930  *
931  * PARAMETERS:  ASL_WALK_CALLBACK
932  *
933  * RETURN:      Status
934  *
935  * DESCRIPTION: Ascending callback used during the loading of the namespace,
936  *              We only need to worry about managing the scope stack here.
937  *
938  ******************************************************************************/
939
940 static ACPI_STATUS
941 LdCommonNamespaceEnd (
942     ACPI_PARSE_OBJECT       *Op,
943     UINT32                  Level,
944     void                    *Context)
945 {
946     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
947     ACPI_OBJECT_TYPE        ObjectType;
948     BOOLEAN                 ForceNewScope = FALSE;
949
950
951     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
952
953
954     /* We are only interested in opcodes that have an associated name */
955
956     if (!Op->Asl.Namepath)
957     {
958         return (AE_OK);
959     }
960
961     /* Get the type to determine if we should pop the scope */
962
963     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
964         (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
965     {
966         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
967
968         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
969     }
970     else
971     {
972         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
973     }
974
975     /* Pop scope that was pushed for Resource Templates */
976
977     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
978     {
979         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
980         {
981             ForceNewScope = TRUE;
982         }
983     }
984
985     /* Pop the scope stack */
986
987     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
988     {
989         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
990             "(%s): Popping scope for Op [%s] %p\n",
991             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
992
993         (void) AcpiDsScopeStackPop (WalkState);
994     }
995
996     return (AE_OK);
997 }