1 /******************************************************************************
3 * Module Name: dswload - Dispatcher first pass namespace load callbacks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
52 #ifdef ACPI_ASL_COMPILER
56 #define _COMPONENT ACPI_DISPATCHER
57 ACPI_MODULE_NAME ("dswload")
60 /*******************************************************************************
62 * FUNCTION: AcpiDsInitCallbacks
64 * PARAMETERS: WalkState - Current state of the parse tree walk
65 * PassNumber - 1, 2, or 3
69 * DESCRIPTION: Init walk state callbacks
71 ******************************************************************************/
75 ACPI_WALK_STATE *WalkState,
83 /* Parse only - caller will setup callbacks */
85 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
86 ACPI_PARSE_DELETE_TREE |
87 ACPI_PARSE_DISASSEMBLE;
88 WalkState->DescendingCallback = NULL;
89 WalkState->AscendingCallback = NULL;
96 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
97 ACPI_PARSE_DELETE_TREE;
98 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
99 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
106 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
107 ACPI_PARSE_DELETE_TREE;
108 WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
109 WalkState->AscendingCallback = AcpiDsLoad2EndOp;
116 #ifndef ACPI_NO_METHOD_EXECUTION
117 WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
118 ACPI_PARSE_DELETE_TREE;
119 WalkState->DescendingCallback = AcpiDsExecBeginOp;
120 WalkState->AscendingCallback = AcpiDsExecEndOp;
126 return (AE_BAD_PARAMETER);
133 /*******************************************************************************
135 * FUNCTION: AcpiDsLoad1BeginOp
137 * PARAMETERS: WalkState - Current state of the parse tree walk
138 * OutOp - Where to return op if a new one is created
142 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
144 ******************************************************************************/
148 ACPI_WALK_STATE *WalkState,
149 ACPI_PARSE_OBJECT **OutOp)
151 ACPI_PARSE_OBJECT *Op;
152 ACPI_NAMESPACE_NODE *Node;
154 ACPI_OBJECT_TYPE ObjectType;
159 ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
163 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
165 /* We are only interested in opcodes that have an associated name */
169 if (!(WalkState->OpInfo->Flags & AML_NAMED))
172 return_ACPI_STATUS (AE_OK);
175 /* Check if this object has already been installed in the namespace */
180 return_ACPI_STATUS (AE_OK);
184 Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
186 /* Map the raw opcode into an internal object type */
188 ObjectType = WalkState->OpInfo->ObjectType;
190 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
191 "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
193 switch (WalkState->Opcode)
197 * The target name of the Scope() operator must exist at this point so
198 * that we can actually open the scope to enter new names underneath it.
199 * Allow search-to-root for single namesegs.
201 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
202 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
203 #ifdef ACPI_ASL_COMPILER
204 if (Status == AE_NOT_FOUND)
208 * Target of Scope() not found. Generate an External for it, and
209 * insert the name into the namespace.
211 AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
212 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
213 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
217 if (ACPI_FAILURE (Status))
219 ACPI_ERROR_NAMESPACE (Path, Status);
220 return_ACPI_STATUS (Status);
224 * Check to make sure that the target is
225 * one of the opcodes that actually opens a scope
230 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
231 case ACPI_TYPE_DEVICE:
232 case ACPI_TYPE_POWER:
233 case ACPI_TYPE_PROCESSOR:
234 case ACPI_TYPE_THERMAL:
236 /* These are acceptable types */
239 case ACPI_TYPE_INTEGER:
240 case ACPI_TYPE_STRING:
241 case ACPI_TYPE_BUFFER:
243 * These types we will allow, but we will change the type.
244 * This enables some existing code of the form:
247 * Scope (DEB) { ... }
249 * Note: silently change the type here. On the second pass,
250 * we will report a warning
252 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
253 "Type override - [%4.4s] had invalid type (%s) "
254 "for Scope operator, changed to type ANY\n",
255 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
257 Node->Type = ACPI_TYPE_ANY;
258 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
261 case ACPI_TYPE_METHOD:
263 * Allow scope change to root during execution of module-level
264 * code. Root is typed METHOD during this time.
266 if ((Node == AcpiGbl_RootNode) &&
267 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
272 /*lint -fallthrough */
276 /* All other types are an error */
278 ACPI_ERROR ((AE_INFO,
279 "Invalid type (%s) for target of "
280 "Scope operator [%4.4s] (Cannot override)",
281 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
283 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
289 * For all other named opcodes, we will enter the name into
292 * Setup the search flags.
293 * Since we are entering a name into the namespace, we do not want to
294 * enable the search-to-root upsearch.
296 * There are only two conditions where it is acceptable that the name
298 * 1) the Scope() operator can reopen a scoping object that was
299 * previously defined (Scope, Method, Device, etc.)
300 * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
301 * BufferField, or Package), the name of the object is already
304 if (WalkState->DeferredNode)
306 /* This name is already in the namespace, get the node */
308 Node = WalkState->DeferredNode;
314 * If we are executing a method, do not create any namespace objects
315 * during the load phase, only during execution.
317 if (WalkState->MethodNode)
324 Flags = ACPI_NS_NO_UPSEARCH;
325 if ((WalkState->Opcode != AML_SCOPE_OP) &&
326 (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
328 if (WalkState->NamespaceOverride)
330 Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
331 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Override allowed\n",
332 AcpiUtGetTypeName (ObjectType)));
336 Flags |= ACPI_NS_ERROR_IF_FOUND;
337 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
338 AcpiUtGetTypeName (ObjectType)));
343 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
344 "[%s] Both Find or Create allowed\n",
345 AcpiUtGetTypeName (ObjectType)));
349 * Enter the named type into the internal namespace. We enter the name
350 * as we go downward in the parse tree. Any necessary subobjects that
351 * involve arguments to the opcode must be created as we go back up the
354 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
355 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
356 if (ACPI_FAILURE (Status))
358 if (Status == AE_ALREADY_EXISTS)
360 /* The name already exists in this scope */
362 if (Node->Flags & ANOBJ_IS_EXTERNAL)
365 * Allow one create on an object or segment that was
366 * previously declared External
368 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
369 Node->Type = (UINT8) ObjectType;
371 /* Just retyped a node, probably will need to open a scope */
373 if (AcpiNsOpensScope (ObjectType))
375 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
376 if (ACPI_FAILURE (Status))
378 return_ACPI_STATUS (Status);
386 if (ACPI_FAILURE (Status))
388 ACPI_ERROR_NAMESPACE (Path, Status);
389 return_ACPI_STATUS (Status);
399 /* Create a new op */
401 Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
404 return_ACPI_STATUS (AE_NO_MEMORY);
408 /* Initialize the op */
410 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
411 Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
417 * Put the Node in the "op" object that the parser uses, so we
418 * can get it again quickly when this scope is closed
420 Op->Common.Node = Node;
421 Op->Named.Name = Node->Name.Integer;
424 AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
426 return_ACPI_STATUS (Status);
430 /*******************************************************************************
432 * FUNCTION: AcpiDsLoad1EndOp
434 * PARAMETERS: WalkState - Current state of the parse tree walk
438 * DESCRIPTION: Ascending callback used during the loading of the namespace,
439 * both control methods and everything else.
441 ******************************************************************************/
445 ACPI_WALK_STATE *WalkState)
447 ACPI_PARSE_OBJECT *Op;
448 ACPI_OBJECT_TYPE ObjectType;
449 ACPI_STATUS Status = AE_OK;
452 ACPI_FUNCTION_TRACE (DsLoad1EndOp);
456 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
458 /* We are only interested in opcodes that have an associated name */
460 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
462 return_ACPI_STATUS (AE_OK);
465 /* Get the object type to determine if we should pop the scope */
467 ObjectType = WalkState->OpInfo->ObjectType;
469 #ifndef ACPI_NO_METHOD_EXECUTION
470 if (WalkState->OpInfo->Flags & AML_FIELD)
473 * If we are executing a method, do not create any namespace objects
474 * during the load phase, only during execution.
476 if (!WalkState->MethodNode)
478 if (WalkState->Opcode == AML_FIELD_OP ||
479 WalkState->Opcode == AML_BANK_FIELD_OP ||
480 WalkState->Opcode == AML_INDEX_FIELD_OP)
482 Status = AcpiDsInitFieldObjects (Op, WalkState);
485 return_ACPI_STATUS (Status);
489 * If we are executing a method, do not create any namespace objects
490 * during the load phase, only during execution.
492 if (!WalkState->MethodNode)
494 if (Op->Common.AmlOpcode == AML_REGION_OP)
496 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
497 (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
499 if (ACPI_FAILURE (Status))
501 return_ACPI_STATUS (Status);
504 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
506 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
507 ACPI_ADR_SPACE_DATA_TABLE, WalkState);
508 if (ACPI_FAILURE (Status))
510 return_ACPI_STATUS (Status);
516 if (Op->Common.AmlOpcode == AML_NAME_OP)
518 /* For Name opcode, get the object type from the argument */
520 if (Op->Common.Value.Arg)
522 ObjectType = (AcpiPsGetOpcodeInfo (
523 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
525 /* Set node type if we have a namespace node */
529 Op->Common.Node->Type = (UINT8) ObjectType;
535 * If we are executing a method, do not create any namespace objects
536 * during the load phase, only during execution.
538 if (!WalkState->MethodNode)
540 if (Op->Common.AmlOpcode == AML_METHOD_OP)
543 * MethodOp PkgLength NameString MethodFlags TermList
545 * Note: We must create the method node/object pair as soon as we
546 * see the method declaration. This allows later pass1 parsing
547 * of invocations of the method (need to know the number of
550 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
551 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
552 WalkState, Op, Op->Named.Node));
554 if (!AcpiNsGetAttachedObject (Op->Named.Node))
556 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
557 WalkState->NumOperands = 1;
559 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
560 if (ACPI_SUCCESS (Status))
562 Status = AcpiExCreateMethod (Op->Named.Data,
563 Op->Named.Length, WalkState);
566 WalkState->Operands[0] = NULL;
567 WalkState->NumOperands = 0;
569 if (ACPI_FAILURE (Status))
571 return_ACPI_STATUS (Status);
577 /* Pop the scope stack (only if loading a table) */
579 if (!WalkState->MethodNode &&
580 AcpiNsOpensScope (ObjectType))
582 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
583 AcpiUtGetTypeName (ObjectType), Op));
585 Status = AcpiDsScopeStackPop (WalkState);
588 return_ACPI_STATUS (Status);