1 /******************************************************************************
3 * Module Name: dswload - Dispatcher first pass namespace load callbacks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acdispat.h>
157 #include <contrib/dev/acpica/include/acinterp.h>
158 #include <contrib/dev/acpica/include/acnamesp.h>
160 #ifdef ACPI_ASL_COMPILER
161 #include <contrib/dev/acpica/include/acdisasm.h>
164 #define _COMPONENT ACPI_DISPATCHER
165 ACPI_MODULE_NAME ("dswload")
168 /*******************************************************************************
170 * FUNCTION: AcpiDsInitCallbacks
172 * PARAMETERS: WalkState - Current state of the parse tree walk
173 * PassNumber - 1, 2, or 3
177 * DESCRIPTION: Init walk state callbacks
179 ******************************************************************************/
182 AcpiDsInitCallbacks (
183 ACPI_WALK_STATE *WalkState,
191 /* Parse only - caller will setup callbacks */
193 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
194 ACPI_PARSE_DELETE_TREE |
195 ACPI_PARSE_DISASSEMBLE;
196 WalkState->DescendingCallback = NULL;
197 WalkState->AscendingCallback = NULL;
204 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
205 ACPI_PARSE_DELETE_TREE;
206 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
207 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
214 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
215 ACPI_PARSE_DELETE_TREE;
216 WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
217 WalkState->AscendingCallback = AcpiDsLoad2EndOp;
224 #ifndef ACPI_NO_METHOD_EXECUTION
225 WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
226 ACPI_PARSE_DELETE_TREE;
227 WalkState->DescendingCallback = AcpiDsExecBeginOp;
228 WalkState->AscendingCallback = AcpiDsExecEndOp;
234 return (AE_BAD_PARAMETER);
241 /*******************************************************************************
243 * FUNCTION: AcpiDsLoad1BeginOp
245 * PARAMETERS: WalkState - Current state of the parse tree walk
246 * OutOp - Where to return op if a new one is created
250 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
252 ******************************************************************************/
256 ACPI_WALK_STATE *WalkState,
257 ACPI_PARSE_OBJECT **OutOp)
259 ACPI_PARSE_OBJECT *Op;
260 ACPI_NAMESPACE_NODE *Node;
262 ACPI_OBJECT_TYPE ObjectType;
267 ACPI_FUNCTION_TRACE_PTR (DsLoad1BeginOp, WalkState->Op);
271 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
273 /* We are only interested in opcodes that have an associated name */
277 if (!(WalkState->OpInfo->Flags & AML_NAMED))
280 return_ACPI_STATUS (AE_OK);
283 /* Check if this object has already been installed in the namespace */
288 return_ACPI_STATUS (AE_OK);
292 Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
294 /* Map the raw opcode into an internal object type */
296 ObjectType = WalkState->OpInfo->ObjectType;
298 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
299 "State=%p Op=%p [%s]\n", WalkState, Op,
300 AcpiUtGetTypeName (ObjectType)));
302 switch (WalkState->Opcode)
306 * The target name of the Scope() operator must exist at this point so
307 * that we can actually open the scope to enter new names underneath it.
308 * Allow search-to-root for single namesegs.
310 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
311 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
312 #ifdef ACPI_ASL_COMPILER
313 if (Status == AE_NOT_FOUND)
317 * Target of Scope() not found. Generate an External for it, and
318 * insert the name into the namespace.
320 AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
321 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
322 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
326 if (ACPI_FAILURE (Status))
328 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
329 return_ACPI_STATUS (Status);
333 * Check to make sure that the target is
334 * one of the opcodes that actually opens a scope
339 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
340 case ACPI_TYPE_DEVICE:
341 case ACPI_TYPE_POWER:
342 case ACPI_TYPE_PROCESSOR:
343 case ACPI_TYPE_THERMAL:
345 /* These are acceptable types */
348 case ACPI_TYPE_INTEGER:
349 case ACPI_TYPE_STRING:
350 case ACPI_TYPE_BUFFER:
352 * These types we will allow, but we will change the type.
353 * This enables some existing code of the form:
356 * Scope (DEB) { ... }
358 * Note: silently change the type here. On the second pass,
359 * we will report a warning
361 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
362 "Type override - [%4.4s] had invalid type (%s) "
363 "for Scope operator, changed to type ANY\n",
364 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
366 Node->Type = ACPI_TYPE_ANY;
367 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
370 case ACPI_TYPE_METHOD:
372 * Allow scope change to root during execution of module-level
373 * code. Root is typed METHOD during this time.
375 if ((Node == AcpiGbl_RootNode) &&
376 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
381 /*lint -fallthrough */
385 /* All other types are an error */
387 ACPI_ERROR ((AE_INFO,
388 "Invalid type (%s) for target of "
389 "Scope operator [%4.4s] (Cannot override)",
390 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
392 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
398 * For all other named opcodes, we will enter the name into
401 * Setup the search flags.
402 * Since we are entering a name into the namespace, we do not want to
403 * enable the search-to-root upsearch.
405 * There are only two conditions where it is acceptable that the name
407 * 1) the Scope() operator can reopen a scoping object that was
408 * previously defined (Scope, Method, Device, etc.)
409 * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
410 * BufferField, or Package), the name of the object is already
413 if (WalkState->DeferredNode)
415 /* This name is already in the namespace, get the node */
417 Node = WalkState->DeferredNode;
423 * If we are executing a method, do not create any namespace objects
424 * during the load phase, only during execution.
426 if (WalkState->MethodNode)
433 Flags = ACPI_NS_NO_UPSEARCH;
434 if ((WalkState->Opcode != AML_SCOPE_OP) &&
435 (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
437 if (WalkState->NamespaceOverride)
439 Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
440 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Override allowed\n",
441 AcpiUtGetTypeName (ObjectType)));
445 Flags |= ACPI_NS_ERROR_IF_FOUND;
446 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
447 AcpiUtGetTypeName (ObjectType)));
452 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
453 "[%s] Both Find or Create allowed\n",
454 AcpiUtGetTypeName (ObjectType)));
458 * Enter the named type into the internal namespace. We enter the name
459 * as we go downward in the parse tree. Any necessary subobjects that
460 * involve arguments to the opcode must be created as we go back up the
463 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
464 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
465 if (ACPI_FAILURE (Status))
467 if (Status == AE_ALREADY_EXISTS)
469 /* The name already exists in this scope */
471 if (Node->Flags & ANOBJ_IS_EXTERNAL)
474 * Allow one create on an object or segment that was
475 * previously declared External
477 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
478 Node->Type = (UINT8) ObjectType;
480 /* Just retyped a node, probably will need to open a scope */
482 if (AcpiNsOpensScope (ObjectType))
484 Status = AcpiDsScopeStackPush (
485 Node, ObjectType, WalkState);
486 if (ACPI_FAILURE (Status))
488 return_ACPI_STATUS (Status);
496 if (ACPI_FAILURE (Status))
498 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
499 return_ACPI_STATUS (Status);
509 /* Create a new op */
511 Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
514 return_ACPI_STATUS (AE_NO_MEMORY);
518 /* Initialize the op */
520 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
521 Op->Named.Path = Path;
527 * Put the Node in the "op" object that the parser uses, so we
528 * can get it again quickly when this scope is closed
530 Op->Common.Node = Node;
531 Op->Named.Name = Node->Name.Integer;
534 AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
536 return_ACPI_STATUS (Status);
540 /*******************************************************************************
542 * FUNCTION: AcpiDsLoad1EndOp
544 * PARAMETERS: WalkState - Current state of the parse tree walk
548 * DESCRIPTION: Ascending callback used during the loading of the namespace,
549 * both control methods and everything else.
551 ******************************************************************************/
555 ACPI_WALK_STATE *WalkState)
557 ACPI_PARSE_OBJECT *Op;
558 ACPI_OBJECT_TYPE ObjectType;
559 ACPI_STATUS Status = AE_OK;
561 #ifdef ACPI_ASL_COMPILER
566 ACPI_FUNCTION_TRACE (DsLoad1EndOp);
570 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
572 /* We are only interested in opcodes that have an associated name */
574 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
576 return_ACPI_STATUS (AE_OK);
579 /* Get the object type to determine if we should pop the scope */
581 ObjectType = WalkState->OpInfo->ObjectType;
583 #ifndef ACPI_NO_METHOD_EXECUTION
584 if (WalkState->OpInfo->Flags & AML_FIELD)
587 * If we are executing a method, do not create any namespace objects
588 * during the load phase, only during execution.
590 if (!WalkState->MethodNode)
592 if (WalkState->Opcode == AML_FIELD_OP ||
593 WalkState->Opcode == AML_BANK_FIELD_OP ||
594 WalkState->Opcode == AML_INDEX_FIELD_OP)
596 Status = AcpiDsInitFieldObjects (Op, WalkState);
599 return_ACPI_STATUS (Status);
603 * If we are executing a method, do not create any namespace objects
604 * during the load phase, only during execution.
606 if (!WalkState->MethodNode)
608 if (Op->Common.AmlOpcode == AML_REGION_OP)
610 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
611 (ACPI_ADR_SPACE_TYPE)
612 ((Op->Common.Value.Arg)->Common.Value.Integer),
614 if (ACPI_FAILURE (Status))
616 return_ACPI_STATUS (Status);
619 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
621 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
622 ACPI_ADR_SPACE_DATA_TABLE, WalkState);
623 if (ACPI_FAILURE (Status))
625 return_ACPI_STATUS (Status);
631 if (Op->Common.AmlOpcode == AML_NAME_OP)
633 /* For Name opcode, get the object type from the argument */
635 if (Op->Common.Value.Arg)
637 ObjectType = (AcpiPsGetOpcodeInfo (
638 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
640 /* Set node type if we have a namespace node */
644 Op->Common.Node->Type = (UINT8) ObjectType;
649 #ifdef ACPI_ASL_COMPILER
651 * For external opcode, get the object type from the argument and
652 * get the parameter count from the argument's next.
654 if (AcpiGbl_DisasmFlag &&
656 Op->Common.AmlOpcode == AML_EXTERNAL_OP)
659 * Note, if this external is not a method
660 * Op->Common.Value.Arg->Common.Next->Common.Value.Integer == 0
661 * Therefore, ParamCount will be 0.
663 ParamCount = (UINT8) Op->Common.Value.Arg->Common.Next->Common.Value.Integer;
664 ObjectType = (UINT8) Op->Common.Value.Arg->Common.Value.Integer;
665 Op->Common.Node->Flags |= ANOBJ_IS_EXTERNAL;
666 Op->Common.Node->Type = (UINT8) ObjectType;
668 AcpiDmCreateSubobjectForExternal ((UINT8)ObjectType,
669 &Op->Common.Node, ParamCount);
672 * Add the external to the external list because we may be
673 * emitting code based off of the items within the external list.
675 AcpiDmAddOpToExternalList (Op, Op->Named.Path, (UINT8)ObjectType, ParamCount,
676 ACPI_EXT_ORIGIN_FROM_OPCODE | ACPI_EXT_RESOLVED_REFERENCE);
681 * If we are executing a method, do not create any namespace objects
682 * during the load phase, only during execution.
684 if (!WalkState->MethodNode)
686 if (Op->Common.AmlOpcode == AML_METHOD_OP)
689 * MethodOp PkgLength NameString MethodFlags TermList
691 * Note: We must create the method node/object pair as soon as we
692 * see the method declaration. This allows later pass1 parsing
693 * of invocations of the method (need to know the number of
696 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
697 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
698 WalkState, Op, Op->Named.Node));
700 if (!AcpiNsGetAttachedObject (Op->Named.Node))
702 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
703 WalkState->NumOperands = 1;
705 Status = AcpiDsCreateOperands (
706 WalkState, Op->Common.Value.Arg);
707 if (ACPI_SUCCESS (Status))
709 Status = AcpiExCreateMethod (Op->Named.Data,
710 Op->Named.Length, WalkState);
713 WalkState->Operands[0] = NULL;
714 WalkState->NumOperands = 0;
716 if (ACPI_FAILURE (Status))
718 return_ACPI_STATUS (Status);
724 /* Pop the scope stack (only if loading a table) */
726 if (!WalkState->MethodNode &&
727 Op->Common.AmlOpcode != AML_EXTERNAL_OP &&
728 AcpiNsOpensScope (ObjectType))
730 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
731 AcpiUtGetTypeName (ObjectType), Op));
733 Status = AcpiDsScopeStackPop (WalkState);
736 return_ACPI_STATUS (Status);