1 /******************************************************************************
3 * Module Name: dswload - Dispatcher namespace load callbacks
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
117 #define __ASLLOAD_C__
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>
124 #include "aslcompiler.y.h"
126 #define _COMPONENT ACPI_COMPILER
127 ACPI_MODULE_NAME ("aslload")
129 /* Local prototypes */
132 LdLoadFieldElements (
133 ACPI_PARSE_OBJECT *Op,
134 ACPI_WALK_STATE *WalkState);
137 LdLoadResourceElements (
138 ACPI_PARSE_OBJECT *Op,
139 ACPI_WALK_STATE *WalkState);
143 ACPI_PARSE_OBJECT *Op,
149 ACPI_PARSE_OBJECT *Op,
154 /*******************************************************************************
156 * FUNCTION: LdLoadNamespace
158 * PARAMETERS: RootOp - Root of the parse tree
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.
167 ******************************************************************************/
171 ACPI_PARSE_OBJECT *RootOp)
173 ACPI_WALK_STATE *WalkState;
176 DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n");
178 /* Create a new walk state */
180 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
186 /* Perform the walk of the parse tree */
188 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
189 LdNamespace1End, WalkState);
191 /* Dump the namespace if debug is enabled */
193 AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
198 /*******************************************************************************
200 * FUNCTION: LdLoadFieldElements
202 * PARAMETERS: Op - Parent node (Field)
203 * WalkState - Current walk state
207 * DESCRIPTION: Enter the named elements of the field (children of the parent)
208 * into the namespace.
210 ******************************************************************************/
213 LdLoadFieldElements (
214 ACPI_PARSE_OBJECT *Op,
215 ACPI_WALK_STATE *WalkState)
217 ACPI_PARSE_OBJECT *Child = NULL;
218 ACPI_NAMESPACE_NODE *Node;
222 /* Get the first named field element */
224 switch (Op->Asl.AmlOpcode)
226 case AML_BANK_FIELD_OP:
228 Child = UtGetArg (Op, 6);
231 case AML_INDEX_FIELD_OP:
233 Child = UtGetArg (Op, 5);
238 Child = UtGetArg (Op, 4);
242 /* No other opcodes should arrive here */
243 return (AE_BAD_PARAMETER);
246 /* Enter all elements into the namespace */
250 switch (Child->Asl.AmlOpcode)
252 case AML_INT_RESERVEDFIELD_OP:
253 case AML_INT_ACCESSFIELD_OP:
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,
266 if (ACPI_FAILURE (Status))
268 if (Status != AE_ALREADY_EXISTS)
270 AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
271 Child->Asl.Value.String);
276 * The name already exists in this scope
277 * But continue processing the elements
279 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
280 Child->Asl.Value.String);
284 Child->Asl.Node = Node;
289 Child = Child->Asl.Next;
295 /*******************************************************************************
297 * FUNCTION: LdLoadResourceElements
299 * PARAMETERS: Op - Parent node (Resource Descriptor)
300 * WalkState - Current walk state
304 * DESCRIPTION: Enter the named elements of the resource descriptor (children
305 * of the parent) into the namespace.
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.
311 ******************************************************************************/
314 LdLoadResourceElements (
315 ACPI_PARSE_OBJECT *Op,
316 ACPI_WALK_STATE *WalkState)
318 ACPI_PARSE_OBJECT *InitializerOp = NULL;
319 ACPI_NAMESPACE_NODE *Node;
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.
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,
331 if (ACPI_FAILURE (Status))
333 if (Status == AE_ALREADY_EXISTS)
335 /* Actual node causing the error was saved in ParentMethod */
337 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
338 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath);
344 Node->Value = (UINT32) Op->Asl.Value.Integer;
348 * Now enter the predefined fields, for easy lookup when referenced
351 InitializerOp = ASL_GET_CHILD_NODE (Op);
352 while (InitializerOp)
355 if (InitializerOp->Asl.ExternalName)
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,
363 if (ACPI_FAILURE (Status))
369 * Store the field offset in the namespace node so it
370 * can be used when the field is referenced
372 Node->Value = (UINT32) InitializerOp->Asl.Value.Integer;
373 InitializerOp->Asl.Node = Node;
374 Node->Op = InitializerOp;
376 /* Pass thru the field type (Bitfield or Bytefield) */
378 if (InitializerOp->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
380 Node->Flags |= ANOBJ_IS_BIT_OFFSET;
383 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
390 /*******************************************************************************
392 * FUNCTION: LdNamespace1Begin
394 * PARAMETERS: ASL_WALK_CALLBACK
398 * DESCRIPTION: Descending callback used during the parse tree walk. If this
399 * is a named AML opcode, enter into the namespace
401 ******************************************************************************/
405 ACPI_PARSE_OBJECT *Op,
409 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
410 ACPI_NAMESPACE_NODE *Node;
412 ACPI_OBJECT_TYPE ObjectType;
413 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY;
415 UINT32 Flags = ACPI_NS_NO_UPSEARCH;
416 ACPI_PARSE_OBJECT *Arg;
418 BOOLEAN ForceNewScope = FALSE;
421 ACPI_FUNCTION_NAME (LdNamespace1Begin);
422 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
423 Op, Op->Asl.ParseOpName));
427 * We are only interested in opcodes that have an associated name
428 * (or multiple names)
430 switch (Op->Asl.AmlOpcode)
432 case AML_BANK_FIELD_OP:
433 case AML_INDEX_FIELD_OP:
436 Status = LdLoadFieldElements (Op, WalkState);
441 /* All other opcodes go below */
445 /* Check if this object has already been installed in the namespace */
452 Path = Op->Asl.Namepath;
458 /* Map the raw opcode into an internal object type */
460 switch (Op->Asl.ParseOpcode)
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 */
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
472 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
474 ForceNewScope = TRUE;
477 /* Get the data type associated with the named object, not the name itself */
479 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
482 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
489 case PARSEOP_EXTERNAL:
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)
496 * first child is name, next child is ObjectType
498 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
499 ObjectType = ACPI_TYPE_ANY;
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:
506 * External (\_SB_.PCI0.ABCD, IntObj)
515 * Store (\_SB_.PCI0.ABCD, Local0)
518 Flags |= ACPI_NS_EXTERNAL;
521 case PARSEOP_DEFAULT_ARG:
523 if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
525 Status = LdLoadResourceElements (Op, WalkState);
529 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
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.
541 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
542 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
544 if (ACPI_FAILURE (Status))
546 if (Status == AE_NOT_FOUND)
548 /* The name was not found, go ahead and create it */
550 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
551 ACPI_TYPE_LOCAL_SCOPE,
552 ACPI_IMODE_LOAD_PASS1, Flags,
556 * However, this is an error -- primarily because the MS
557 * interpreter can't handle a forward reference from the
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);
567 AslCoreSubsystemError (Op, Status, "Failure from lookup\n", FALSE);
571 /* We found a node with this name, now check the type */
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:
581 /* These are acceptable types - they all open a new scope */
584 case ACPI_TYPE_INTEGER:
585 case ACPI_TYPE_STRING:
586 case ACPI_TYPE_BUFFER:
589 * These types we will allow, but we will change the type.
590 * This enables some existing code of the form:
593 * Scope (DEB) { ... }
595 * Which is used to workaround the fact that the MS interpreter
596 * does not allow Scope() forward references.
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);
602 /* Switch the type to scope, open the new scope */
604 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
605 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
607 if (ACPI_FAILURE (Status))
609 return_ACPI_STATUS (Status);
615 /* All other types are an error */
617 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
618 AcpiUtGetTypeName (Node->Type));
619 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
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.
626 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
627 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
629 if (ACPI_FAILURE (Status))
631 return_ACPI_STATUS (Status);
642 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
647 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
648 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
650 /* The name must not already exist */
652 Flags |= ACPI_NS_ERROR_IF_FOUND;
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
660 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
661 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
662 if (ACPI_FAILURE (Status))
664 if (Status == AE_ALREADY_EXISTS)
666 /* The name already exists in this scope */
668 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
670 /* Allow multiple references to the same scope */
672 Node->Type = (UINT8) ObjectType;
675 else if (Node->Flags & ANOBJ_IS_EXTERNAL)
678 * Allow one create on an object or segment that was
679 * previously declared External
681 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
682 Node->Type = (UINT8) ObjectType;
684 /* Just retyped a node, probably will need to open a scope */
686 if (AcpiNsOpensScope (ObjectType))
688 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
689 if (ACPI_FAILURE (Status))
691 return_ACPI_STATUS (Status);
698 /* Valid error, object already exists */
700 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
701 Op->Asl.ExternalName);
708 AslCoreSubsystemError (Op, Status,
709 "Failure from lookup %s\n", FALSE);
716 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
717 if (ACPI_FAILURE (Status))
719 return_ACPI_STATUS (Status);
725 * Point the parse node to the new namespace node, and point
726 * the Node back to the original Parse node
731 /* Set the actual data type if appropriate (EXTERNAL term only) */
733 if (ActualObjectType != ACPI_TYPE_ANY)
735 Node->Type = (UINT8) ActualObjectType;
736 Node->Value = ASL_EXTERNAL_METHOD;
739 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
742 * Get the method argument count from "Extra" and save
743 * it in the namespace node
745 Node->Value = (UINT32) Op->Asl.Extra;
753 /*******************************************************************************
755 * FUNCTION: LdNamespace1End
757 * PARAMETERS: ASL_WALK_CALLBACK
761 * DESCRIPTION: Ascending callback used during the loading of the namespace,
762 * We only need to worry about managing the scope stack here.
764 ******************************************************************************/
768 ACPI_PARSE_OBJECT *Op,
772 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
773 ACPI_OBJECT_TYPE ObjectType;
774 BOOLEAN ForceNewScope = FALSE;
777 ACPI_FUNCTION_NAME (LdNamespace1End);
780 /* We are only interested in opcodes that have an associated name */
782 if (!Op->Asl.Namepath)
787 /* Get the type to determine if we should pop the scope */
789 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
790 (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
792 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
794 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
798 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
801 /* Pop scope that was pushed for Resource Templates */
803 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
805 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
807 ForceNewScope = TRUE;
811 /* Pop the scope stack */
813 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
816 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
817 "(%s): Popping scope for Op [%s] %p\n",
818 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
820 (void) AcpiDsScopeStackPop (WalkState);