1 /******************************************************************************
3 * Module Name: dswload - Dispatcher namespace load callbacks
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, 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 "aslcompiler.h"
121 #include "acdispat.h"
122 #include "acnamesp.h"
124 #include "aslcompiler.y.h"
126 #define _COMPONENT ACPI_COMPILER
127 ACPI_MODULE_NAME ("aslload")
130 /*******************************************************************************
132 * FUNCTION: LdLoadNamespace
138 * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
139 * named ASL/AML objects into the namespace. The namespace is
140 * constructed in order to resolve named references and references
141 * to named fields within resource templates/descriptors.
143 ******************************************************************************/
147 ACPI_PARSE_OBJECT *RootOp)
149 ACPI_WALK_STATE *WalkState;
152 DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n");
154 /* Create a new walk state */
156 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
162 /* Perform the walk of the parse tree */
164 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
165 LdNamespace1End, WalkState);
167 /* Dump the namespace if debug is enabled */
169 AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
174 /*******************************************************************************
176 * FUNCTION: LdLoadFieldElements
178 * PARAMETERS: Op - Parent node (Field)
179 * WalkState - Current walk state
183 * DESCRIPTION: Enter the named elements of the field (children of the parent)
184 * into the namespace.
186 ******************************************************************************/
189 LdLoadFieldElements (
190 ACPI_PARSE_OBJECT *Op,
191 ACPI_WALK_STATE *WalkState)
193 ACPI_PARSE_OBJECT *Child = NULL;
194 ACPI_NAMESPACE_NODE *Node;
198 /* Get the first named field element */
200 switch (Op->Asl.AmlOpcode)
202 case AML_BANK_FIELD_OP:
204 Child = UtGetArg (Op, 6);
207 case AML_INDEX_FIELD_OP:
209 Child = UtGetArg (Op, 5);
214 Child = UtGetArg (Op, 4);
218 /* No other opcodes should arrive here */
219 return (AE_BAD_PARAMETER);
222 /* Enter all elements into the namespace */
226 switch (Child->Asl.AmlOpcode)
228 case AML_INT_RESERVEDFIELD_OP:
229 case AML_INT_ACCESSFIELD_OP:
235 Status = AcpiNsLookup (WalkState->ScopeInfo, Child->Asl.Value.String,
236 ACPI_TYPE_LOCAL_REGION_FIELD, ACPI_IMODE_LOAD_PASS1,
237 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
239 if (ACPI_FAILURE (Status))
241 if (Status != AE_ALREADY_EXISTS)
247 * The name already exists in this scope
248 * But continue processing the elements
250 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child, Child->Asl.Value.String);
254 Child->Asl.Node = Node;
255 Node->Object = (ACPI_OPERAND_OBJECT *) Child;
259 Child = Child->Asl.Next;
265 /*******************************************************************************
267 * FUNCTION: LdLoadResourceElements
269 * PARAMETERS: Op - Parent node (Resource Descriptor)
270 * WalkState - Current walk state
274 * DESCRIPTION: Enter the named elements of the resource descriptor (children
275 * of the parent) into the namespace.
277 * NOTE: In the real AML namespace, these named elements never exist. But
278 * we simply use the namespace here as a symbol table so we can look
279 * them up as they are referenced.
281 ******************************************************************************/
284 LdLoadResourceElements (
285 ACPI_PARSE_OBJECT *Op,
286 ACPI_WALK_STATE *WalkState)
288 ACPI_PARSE_OBJECT *InitializerOp = NULL;
289 ACPI_NAMESPACE_NODE *Node;
294 * Enter the resouce name into the namespace
297 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
298 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH,
300 if (ACPI_FAILURE (Status))
306 * Now enter the predefined fields, for easy lookup when referenced
309 InitializerOp = ASL_GET_CHILD_NODE (Op);
310 while (InitializerOp)
313 if (InitializerOp->Asl.ExternalName)
315 Status = AcpiNsLookup (WalkState->ScopeInfo,
316 InitializerOp->Asl.ExternalName,
317 ACPI_TYPE_LOCAL_RESOURCE_FIELD,
318 ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
320 if (ACPI_FAILURE (Status))
326 * Store the field offset in the namespace node so it
327 * can be used when the field is referenced
329 Node->OwnerId = (UINT16) InitializerOp->Asl.Value.Integer;
330 InitializerOp->Asl.Node = Node;
331 Node->Object = (ACPI_OPERAND_OBJECT *) InitializerOp;
333 /* Pass thru the field type (Bitfield or Bytefield) */
335 if (InitializerOp->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
337 Node->Flags |= ANOBJ_IS_BIT_OFFSET;
340 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
347 /*******************************************************************************
349 * FUNCTION: LdNamespace1Begin
351 * PARAMETERS: ASL_WALK_CALLBACK
355 * DESCRIPTION: Descending callback used during the parse tree walk. If this
356 * is a named AML opcode, enter into the namespace
358 ******************************************************************************/
362 ACPI_PARSE_OBJECT *Op,
366 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
367 ACPI_NAMESPACE_NODE *Node;
369 ACPI_OBJECT_TYPE ObjectType;
370 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY;
372 UINT32 Flags = ACPI_NS_NO_UPSEARCH;
373 ACPI_PARSE_OBJECT *Arg;
377 ACPI_FUNCTION_NAME ("LdNamespace1Begin");
378 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
379 Op, Op->Asl.ParseOpName));
383 * We are only interested in opcodes that have an associated name
384 * (or multiple names)
386 switch (Op->Asl.AmlOpcode)
388 case AML_BANK_FIELD_OP:
389 case AML_INDEX_FIELD_OP:
392 Status = LdLoadFieldElements (Op, WalkState);
397 /* All other opcodes go below */
401 /* Check if this object has already been installed in the namespace */
408 Path = Op->Asl.Namepath;
414 /* Map the raw opcode into an internal object type */
416 switch (Op->Asl.ParseOpcode)
420 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */
421 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */
423 /* Get the data type associated with the named object, not the name itself */
425 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
428 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
435 case PARSEOP_EXTERNAL:
438 * "External" simply enters a name and type into the namespace.
439 * We must be careful to not open a new scope, however, no matter
440 * what type the external name refers to (e.g., a method)
442 * first child is name, next child is ObjectType
444 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
445 ObjectType = ACPI_TYPE_ANY;
449 case PARSEOP_DEFAULT_ARG:
451 if(Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
453 Status = LdLoadResourceElements (Op, WalkState);
457 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
464 * The name referenced by Scope(Name) must already exist at this point.
465 * In other words, forward references for Scope() are not supported.
466 * The only real reason for this is that the MS interpreter cannot
467 * handle this case. Perhaps someday this case can go away.
469 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
470 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
471 if (ACPI_FAILURE (Status))
473 if (Status == AE_NOT_FOUND)
475 /* The name was not found, go ahead and create it */
477 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_LOCAL_SCOPE,
478 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
481 * However, this is an error -- primarily because the MS
482 * interpreter can't handle a forward reference from the
485 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, Op->Asl.ExternalName);
486 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op, Op->Asl.ExternalName);
490 AslCoreSubsystemError (Op, Status, "Failure from lookup\n", FALSE);
494 /* We found a node with this name, now check the type */
498 case ACPI_TYPE_LOCAL_SCOPE:
499 case ACPI_TYPE_DEVICE:
500 case ACPI_TYPE_POWER:
501 case ACPI_TYPE_PROCESSOR:
502 case ACPI_TYPE_THERMAL:
504 /* These are acceptable types - they all open a new scope */
507 case ACPI_TYPE_INTEGER:
508 case ACPI_TYPE_STRING:
509 case ACPI_TYPE_BUFFER:
512 * These types we will allow, but we will change the type. This
513 * enables some existing code of the form:
516 * Scope (DEB) { ... }
518 * Which is used to workaround the fact that the MS interpreter
519 * does not allow Scope() forward references.
521 sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
522 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
523 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
526 * Switch the type to scope, open the new scope
528 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
529 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, WalkState);
530 if (ACPI_FAILURE (Status))
532 return_ACPI_STATUS (Status);
539 * All other types are an error
541 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
542 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
545 * However, switch the type to be an actual scope so
546 * that compilation can continue without generating a whole
547 * cascade of additional errors. Open the new scope.
549 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
550 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, WalkState);
551 if (ACPI_FAILURE (Status))
553 return_ACPI_STATUS (Status);
564 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
569 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
570 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
572 /* The name must not already exist */
574 Flags |= ACPI_NS_ERROR_IF_FOUND;
577 * Enter the named type into the internal namespace. We enter the name
578 * as we go downward in the parse tree. Any necessary subobjects that involve
579 * arguments to the opcode must be created as we go back up the parse tree later.
581 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
582 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
583 if (ACPI_FAILURE (Status))
585 if (Status == AE_ALREADY_EXISTS)
587 /* The name already exists in this scope */
589 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
591 Node->Type = (UINT8) ObjectType;
596 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, Op->Asl.ExternalName);
603 AslCoreSubsystemError (Op, Status, "Failure from lookup %s\n", FALSE);
611 * Point the parse node to the new namespace node, and point
612 * the Node back to the original Parse node
615 Node->Object = (ACPI_OPERAND_OBJECT *) Op;
617 /* Set the actual data type if appropriate (EXTERNAL term only) */
619 if (ActualObjectType != ACPI_TYPE_ANY)
621 Node->Type = (UINT8) ActualObjectType;
622 Node->OwnerId = ASL_EXTERNAL_METHOD;
625 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
628 * Get the method argument count from "Extra" and store
629 * it in the OwnerId field of the namespace node
631 Node->OwnerId = (UINT16) Op->Asl.Extra;
639 /*******************************************************************************
641 * FUNCTION: LdNamespace1End
643 * PARAMETERS: ASL_WALK_CALLBACK
647 * DESCRIPTION: Ascending callback used during the loading of the namespace,
648 * We only need to worry about managing the scope stack here.
650 ******************************************************************************/
654 ACPI_PARSE_OBJECT *Op,
658 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
659 ACPI_OBJECT_TYPE ObjectType;
662 ACPI_FUNCTION_NAME ("LdNamespace1End");
665 /* We are only interested in opcodes that have an associated name */
667 if (!Op->Asl.Namepath)
672 /* Get the type to determine if we should pop the scope */
674 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
675 (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
677 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
679 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
683 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
686 /* Pop the scope stack */
688 if (AcpiNsOpensScope (ObjectType))
691 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
692 "(%s): Popping scope for Op [%s] %p\n",
693 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
695 AcpiDsScopeStackPop (WalkState);