]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/dev/acpica/compiler/aslload.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / dev / acpica / compiler / aslload.c
1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *              $Revision: 1.77 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2007, 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 __ASLLOAD_C__
118
119 #include <contrib/dev/acpica/compiler/aslcompiler.h>
120 #include <contrib/dev/acpica/amlcode.h>
121 #include <contrib/dev/acpica/acdispat.h>
122 #include <contrib/dev/acpica/acnamesp.h>
123
124 #include "aslcompiler.y.h"
125
126 #define _COMPONENT          ACPI_COMPILER
127         ACPI_MODULE_NAME    ("aslload")
128
129 /* Local prototypes */
130
131 static ACPI_STATUS
132 LdLoadFieldElements (
133     ACPI_PARSE_OBJECT       *Op,
134     ACPI_WALK_STATE         *WalkState);
135
136 static ACPI_STATUS
137 LdLoadResourceElements (
138     ACPI_PARSE_OBJECT       *Op,
139     ACPI_WALK_STATE         *WalkState);
140
141 static ACPI_STATUS
142 LdNamespace1Begin (
143     ACPI_PARSE_OBJECT       *Op,
144     UINT32                  Level,
145     void                    *Context);
146
147 static ACPI_STATUS
148 LdNamespace1End (
149     ACPI_PARSE_OBJECT       *Op,
150     UINT32                  Level,
151     void                    *Context);
152
153
154 /*******************************************************************************
155  *
156  * FUNCTION:    LdLoadNamespace
157  *
158  * PARAMETERS:  RootOp      - Root of the parse tree
159  *
160  * RETURN:      Status
161  *
162  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
163  *              named ASL/AML objects into the namespace.  The namespace is
164  *              constructed in order to resolve named references and references
165  *              to named fields within resource templates/descriptors.
166  *
167  ******************************************************************************/
168
169 ACPI_STATUS
170 LdLoadNamespace (
171     ACPI_PARSE_OBJECT       *RootOp)
172 {
173     ACPI_WALK_STATE         *WalkState;
174
175
176     DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n");
177
178     /* Create a new walk state */
179
180     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
181     if (!WalkState)
182     {
183         return AE_NO_MEMORY;
184     }
185
186     /* Perform the walk of the parse tree */
187
188     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
189         LdNamespace1End, WalkState);
190
191     /* Dump the namespace if debug is enabled */
192
193     AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
194     return AE_OK;
195 }
196
197
198 /*******************************************************************************
199  *
200  * FUNCTION:    LdLoadFieldElements
201  *
202  * PARAMETERS:  Op              - Parent node (Field)
203  *              WalkState       - Current walk state
204  *
205  * RETURN:      Status
206  *
207  * DESCRIPTION: Enter the named elements of the field (children of the parent)
208  *              into the namespace.
209  *
210  ******************************************************************************/
211
212 static ACPI_STATUS
213 LdLoadFieldElements (
214     ACPI_PARSE_OBJECT       *Op,
215     ACPI_WALK_STATE         *WalkState)
216 {
217     ACPI_PARSE_OBJECT       *Child = NULL;
218     ACPI_NAMESPACE_NODE     *Node;
219     ACPI_STATUS             Status;
220
221
222     /* Get the first named field element */
223
224     switch (Op->Asl.AmlOpcode)
225     {
226     case AML_BANK_FIELD_OP:
227
228         Child = UtGetArg (Op, 6);
229         break;
230
231     case AML_INDEX_FIELD_OP:
232
233         Child = UtGetArg (Op, 5);
234         break;
235
236     case AML_FIELD_OP:
237
238         Child = UtGetArg (Op, 4);
239         break;
240
241     default:
242         /* No other opcodes should arrive here */
243         return (AE_BAD_PARAMETER);
244     }
245
246     /* Enter all elements into the namespace */
247
248     while (Child)
249     {
250         switch (Child->Asl.AmlOpcode)
251         {
252         case AML_INT_RESERVEDFIELD_OP:
253         case AML_INT_ACCESSFIELD_OP:
254
255             break;
256
257         default:
258
259             Status = AcpiNsLookup (WalkState->ScopeInfo,
260                         Child->Asl.Value.String,
261                         ACPI_TYPE_LOCAL_REGION_FIELD,
262                         ACPI_IMODE_LOAD_PASS1,
263                         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
264                             ACPI_NS_ERROR_IF_FOUND,
265                         NULL, &Node);
266             if (ACPI_FAILURE (Status))
267             {
268                 if (Status != AE_ALREADY_EXISTS)
269                 {
270                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
271                         Child->Asl.Value.String);
272                     return (Status);
273                 }
274
275                 /*
276                  * The name already exists in this scope
277                  * But continue processing the elements
278                  */
279                 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
280                     Child->Asl.Value.String);
281             }
282             else
283             {
284                 Child->Asl.Node = Node;
285                 Node->Op = Child;
286             }
287             break;
288         }
289         Child = Child->Asl.Next;
290     }
291     return (AE_OK);
292 }
293
294
295 /*******************************************************************************
296  *
297  * FUNCTION:    LdLoadResourceElements
298  *
299  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
300  *              WalkState       - Current walk state
301  *
302  * RETURN:      Status
303  *
304  * DESCRIPTION: Enter the named elements of the resource descriptor (children
305  *              of the parent) into the namespace.
306  *
307  * NOTE: In the real AML namespace, these named elements never exist.  But
308  *       we simply use the namespace here as a symbol table so we can look
309  *       them up as they are referenced.
310  *
311  ******************************************************************************/
312
313 static ACPI_STATUS
314 LdLoadResourceElements (
315     ACPI_PARSE_OBJECT       *Op,
316     ACPI_WALK_STATE         *WalkState)
317 {
318     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
319     ACPI_NAMESPACE_NODE     *Node;
320     ACPI_STATUS             Status;
321
322
323     /*
324      * Enter the resource name into the namespace. Name must not already exist.
325      * This opens a scope, so later field names are guaranteed to be new/unique.
326      */
327     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
328                 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
329                 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
330                 WalkState, &Node);
331     if (ACPI_FAILURE (Status))
332     {
333         if (Status == AE_ALREADY_EXISTS)
334         {
335             /* Actual node causing the error was saved in ParentMethod */
336
337             AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
338                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath);
339             return (AE_OK);
340         }
341         return (Status);
342     }
343
344     Node->Value = (UINT32) Op->Asl.Value.Integer;
345     Node->Op = Op;
346
347     /*
348      * Now enter the predefined fields, for easy lookup when referenced
349      * by the source ASL
350      */
351     InitializerOp = ASL_GET_CHILD_NODE (Op);
352     while (InitializerOp)
353     {
354
355         if (InitializerOp->Asl.ExternalName)
356         {
357             Status = AcpiNsLookup (WalkState->ScopeInfo,
358                         InitializerOp->Asl.ExternalName,
359                         ACPI_TYPE_LOCAL_RESOURCE_FIELD,
360                         ACPI_IMODE_LOAD_PASS1,
361                         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
362                         NULL, &Node);
363             if (ACPI_FAILURE (Status))
364             {
365                 return (Status);
366             }
367
368             /*
369              * Store the field offset in the namespace node so it
370              * can be used when the field is referenced
371              */
372             Node->Value = (UINT32) InitializerOp->Asl.Value.Integer;
373             InitializerOp->Asl.Node = Node;
374             Node->Op = InitializerOp;
375
376             /* Pass thru the field type (Bitfield or Bytefield) */
377
378             if (InitializerOp->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
379             {
380                 Node->Flags |= ANOBJ_IS_BIT_OFFSET;
381             }
382         }
383         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
384     }
385
386     return (AE_OK);
387 }
388
389
390 /*******************************************************************************
391  *
392  * FUNCTION:    LdNamespace1Begin
393  *
394  * PARAMETERS:  ASL_WALK_CALLBACK
395  *
396  * RETURN:      Status
397  *
398  * DESCRIPTION: Descending callback used during the parse tree walk.  If this
399  *              is a named AML opcode, enter into the namespace
400  *
401  ******************************************************************************/
402
403 static ACPI_STATUS
404 LdNamespace1Begin (
405     ACPI_PARSE_OBJECT       *Op,
406     UINT32                  Level,
407     void                    *Context)
408 {
409     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
410     ACPI_NAMESPACE_NODE     *Node;
411     ACPI_STATUS             Status;
412     ACPI_OBJECT_TYPE        ObjectType;
413     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
414     char                    *Path;
415     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
416     ACPI_PARSE_OBJECT       *Arg;
417     UINT32                  i;
418     BOOLEAN                 ForceNewScope = FALSE;
419
420
421     ACPI_FUNCTION_NAME (LdNamespace1Begin);
422     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
423         Op, Op->Asl.ParseOpName));
424
425
426     /*
427      * We are only interested in opcodes that have an associated name
428      * (or multiple names)
429      */
430     switch (Op->Asl.AmlOpcode)
431     {
432     case AML_BANK_FIELD_OP:
433     case AML_INDEX_FIELD_OP:
434     case AML_FIELD_OP:
435
436         Status = LdLoadFieldElements (Op, WalkState);
437         return (Status);
438
439     default:
440
441         /* All other opcodes go below */
442         break;
443     }
444
445     /* Check if this object has already been installed in the namespace */
446
447     if (Op->Asl.Node)
448     {
449         return (AE_OK);
450     }
451
452     Path = Op->Asl.Namepath;
453     if (!Path)
454     {
455         return (AE_OK);
456     }
457
458     /* Map the raw opcode into an internal object type */
459
460     switch (Op->Asl.ParseOpcode)
461     {
462     case PARSEOP_NAME:
463
464         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
465         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
466
467         /*
468          * If this name refers to a ResourceTemplate, we will need to open
469          * a new scope so that the resource subfield names can be entered into
470          * the namespace underneath this name
471          */
472         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
473         {
474             ForceNewScope = TRUE;
475         }
476
477         /* Get the data type associated with the named object, not the name itself */
478
479         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
480
481         ObjectType = 1;
482         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
483         {
484             ObjectType++;
485         }
486         break;
487
488
489     case PARSEOP_EXTERNAL:
490
491         /*
492          * "External" simply enters a name and type into the namespace.
493          * We must be careful to not open a new scope, however, no matter
494          * what type the external name refers to (e.g., a method)
495          *
496          * first child is name, next child is ObjectType
497          */
498         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
499         ObjectType = ACPI_TYPE_ANY;
500
501         /*
502          * We will mark every new node along the path as "External". This
503          * allows some or all of the nodes to be created later in the ASL
504          * code. Handles cases like this:
505          *
506          *   External (\_SB_.PCI0.ABCD, IntObj)
507          *   Scope (_SB_)
508          *   {
509          *       Device (PCI0)
510          *       {
511          *       }
512          *   }
513          *   Method (X)
514          *   {
515          *       Store (\_SB_.PCI0.ABCD, Local0)
516          *   }
517          */
518         Flags |= ACPI_NS_EXTERNAL;
519         break;
520
521     case PARSEOP_DEFAULT_ARG:
522
523         if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
524         {
525             Status = LdLoadResourceElements (Op, WalkState);
526             goto Exit;
527         }
528
529         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
530         break;
531
532
533     case PARSEOP_SCOPE:
534
535         /*
536          * The name referenced by Scope(Name) must already exist at this point.
537          * In other words, forward references for Scope() are not supported.
538          * The only real reason for this is that the MS interpreter cannot
539          * handle this case.  Perhaps someday this case can go away.
540          */
541         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
542                     ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
543                     WalkState, &(Node));
544         if (ACPI_FAILURE (Status))
545         {
546             if (Status == AE_NOT_FOUND)
547             {
548                 /* The name was not found, go ahead and create it */
549
550                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
551                             ACPI_TYPE_LOCAL_SCOPE,
552                             ACPI_IMODE_LOAD_PASS1, Flags,
553                             WalkState, &(Node));
554
555                 /*
556                  * However, this is an error -- primarily because the MS
557                  * interpreter can't handle a forward reference from the
558                  * Scope() operator.
559                  */
560                 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
561                     Op->Asl.ExternalName);
562                 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op,
563                     Op->Asl.ExternalName);
564                 goto FinishNode;
565             }
566
567             AslCoreSubsystemError (Op, Status, "Failure from lookup\n", FALSE);
568             goto Exit;
569         }
570
571         /* We found a node with this name, now check the type */
572
573         switch (Node->Type)
574         {
575         case ACPI_TYPE_LOCAL_SCOPE:
576         case ACPI_TYPE_DEVICE:
577         case ACPI_TYPE_POWER:
578         case ACPI_TYPE_PROCESSOR:
579         case ACPI_TYPE_THERMAL:
580
581             /* These are acceptable types - they all open a new scope */
582             break;
583
584         case ACPI_TYPE_INTEGER:
585         case ACPI_TYPE_STRING:
586         case ACPI_TYPE_BUFFER:
587
588             /*
589              * These types we will allow, but we will change the type.
590              * This enables some existing code of the form:
591              *
592              *  Name (DEB, 0)
593              *  Scope (DEB) { ... }
594              *
595              * Which is used to workaround the fact that the MS interpreter
596              * does not allow Scope() forward references.
597              */
598             sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
599                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
600             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
601
602             /* Switch the type to scope, open the new scope */
603
604             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
605             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
606                         WalkState);
607             if (ACPI_FAILURE (Status))
608             {
609                 return_ACPI_STATUS (Status);
610             }
611             break;
612
613         default:
614
615             /* All other types are an error */
616
617             sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
618                 AcpiUtGetTypeName (Node->Type));
619             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
620
621             /*
622              * However, switch the type to be an actual scope so
623              * that compilation can continue without generating a whole
624              * cascade of additional errors.  Open the new scope.
625              */
626             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
627             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
628                         WalkState);
629             if (ACPI_FAILURE (Status))
630             {
631                 return_ACPI_STATUS (Status);
632             }
633             break;
634         }
635
636         Status = AE_OK;
637         goto FinishNode;
638
639
640     default:
641
642         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
643         break;
644     }
645
646
647     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
648             Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
649
650     /* The name must not already exist */
651
652     Flags |= ACPI_NS_ERROR_IF_FOUND;
653
654     /*
655      * Enter the named type into the internal namespace.  We enter the name
656      * as we go downward in the parse tree.  Any necessary subobjects that
657      * involve arguments to the opcode must be created as we go back up the
658      * parse tree later.
659      */
660     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
661                     ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
662     if (ACPI_FAILURE (Status))
663     {
664         if (Status == AE_ALREADY_EXISTS)
665         {
666             /* The name already exists in this scope */
667
668             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
669             {
670                 /* Allow multiple references to the same scope */
671
672                 Node->Type = (UINT8) ObjectType;
673                 Status = AE_OK;
674             }
675             else if (Node->Flags & ANOBJ_IS_EXTERNAL)
676             {
677                 /*
678                  * Allow one create on an object or segment that was
679                  * previously declared External
680                  */
681                 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
682                 Node->Type = (UINT8) ObjectType;
683
684                 /* Just retyped a node, probably will need to open a scope */
685
686                 if (AcpiNsOpensScope (ObjectType))
687                 {
688                     Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
689                     if (ACPI_FAILURE (Status))
690                     {
691                         return_ACPI_STATUS (Status);
692                     }
693                 }
694                 Status = AE_OK;
695             }
696             else
697             {
698                 /* Valid error, object already exists */
699
700                 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
701                     Op->Asl.ExternalName);
702                 Status = AE_OK;
703                 goto Exit;
704             }
705         }
706         else
707         {
708             AslCoreSubsystemError (Op, Status,
709                 "Failure from lookup %s\n", FALSE);
710             goto Exit;
711         }
712     }
713
714     if (ForceNewScope)
715     {
716         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
717         if (ACPI_FAILURE (Status))
718         {
719             return_ACPI_STATUS (Status);
720         }
721     }
722
723 FinishNode:
724     /*
725      * Point the parse node to the new namespace node, and point
726      * the Node back to the original Parse node
727      */
728     Op->Asl.Node = Node;
729     Node->Op = Op;
730
731     /* Set the actual data type if appropriate (EXTERNAL term only) */
732
733     if (ActualObjectType != ACPI_TYPE_ANY)
734     {
735         Node->Type = (UINT8) ActualObjectType;
736         Node->Value = ASL_EXTERNAL_METHOD;
737     }
738
739     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
740     {
741         /*
742          * Get the method argument count from "Extra" and save
743          * it in the namespace node
744          */
745         Node->Value = (UINT32) Op->Asl.Extra;
746     }
747
748 Exit:
749     return (Status);
750 }
751
752
753 /*******************************************************************************
754  *
755  * FUNCTION:    LdNamespace1End
756  *
757  * PARAMETERS:  ASL_WALK_CALLBACK
758  *
759  * RETURN:      Status
760  *
761  * DESCRIPTION: Ascending callback used during the loading of the namespace,
762  *              We only need to worry about managing the scope stack here.
763  *
764  ******************************************************************************/
765
766 static ACPI_STATUS
767 LdNamespace1End (
768     ACPI_PARSE_OBJECT       *Op,
769     UINT32                  Level,
770     void                    *Context)
771 {
772     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
773     ACPI_OBJECT_TYPE        ObjectType;
774     BOOLEAN                 ForceNewScope = FALSE;
775
776
777     ACPI_FUNCTION_NAME (LdNamespace1End);
778
779
780     /* We are only interested in opcodes that have an associated name */
781
782     if (!Op->Asl.Namepath)
783     {
784         return (AE_OK);
785     }
786
787     /* Get the type to determine if we should pop the scope */
788
789     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
790         (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
791     {
792         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
793
794         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
795     }
796     else
797     {
798         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
799     }
800
801     /* Pop scope that was pushed for Resource Templates */
802
803     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
804     {
805         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
806         {
807             ForceNewScope = TRUE;
808         }
809     }
810
811     /* Pop the scope stack */
812
813     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
814     {
815
816         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
817             "(%s): Popping scope for Op [%s] %p\n",
818             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
819
820         (void) AcpiDsScopeStackPop (WalkState);
821     }
822
823     return (AE_OK);
824 }
825
826