1 /******************************************************************************
3 * Module Name: dswload - Dispatcher first pass namespace load callbacks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
54 #ifdef ACPI_ASL_COMPILER
58 #define _COMPONENT ACPI_DISPATCHER
59 ACPI_MODULE_NAME ("dswload")
62 /*******************************************************************************
64 * FUNCTION: AcpiDsInitCallbacks
66 * PARAMETERS: WalkState - Current state of the parse tree walk
67 * PassNumber - 1, 2, or 3
71 * DESCRIPTION: Init walk state callbacks
73 ******************************************************************************/
77 ACPI_WALK_STATE *WalkState,
85 /* Parse only - caller will setup callbacks */
87 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
88 ACPI_PARSE_DELETE_TREE |
89 ACPI_PARSE_DISASSEMBLE;
90 WalkState->DescendingCallback = NULL;
91 WalkState->AscendingCallback = NULL;
98 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
99 ACPI_PARSE_DELETE_TREE;
100 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
101 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
108 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
109 ACPI_PARSE_DELETE_TREE;
110 WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
111 WalkState->AscendingCallback = AcpiDsLoad2EndOp;
118 #ifndef ACPI_NO_METHOD_EXECUTION
119 WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
120 ACPI_PARSE_DELETE_TREE;
121 WalkState->DescendingCallback = AcpiDsExecBeginOp;
122 WalkState->AscendingCallback = AcpiDsExecEndOp;
128 return (AE_BAD_PARAMETER);
135 /*******************************************************************************
137 * FUNCTION: AcpiDsLoad1BeginOp
139 * PARAMETERS: WalkState - Current state of the parse tree walk
140 * OutOp - Where to return op if a new one is created
144 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
146 ******************************************************************************/
150 ACPI_WALK_STATE *WalkState,
151 ACPI_PARSE_OBJECT **OutOp)
153 ACPI_PARSE_OBJECT *Op;
154 ACPI_NAMESPACE_NODE *Node;
156 ACPI_OBJECT_TYPE ObjectType;
161 ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
165 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
167 /* We are only interested in opcodes that have an associated name */
171 if (!(WalkState->OpInfo->Flags & AML_NAMED))
174 return_ACPI_STATUS (AE_OK);
177 /* Check if this object has already been installed in the namespace */
182 return_ACPI_STATUS (AE_OK);
186 Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
188 /* Map the raw opcode into an internal object type */
190 ObjectType = WalkState->OpInfo->ObjectType;
192 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
193 "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
195 switch (WalkState->Opcode)
199 * The target name of the Scope() operator must exist at this point so
200 * that we can actually open the scope to enter new names underneath it.
201 * Allow search-to-root for single namesegs.
203 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
204 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
205 #ifdef ACPI_ASL_COMPILER
206 if (Status == AE_NOT_FOUND)
210 * Target of Scope() not found. Generate an External for it, and
211 * insert the name into the namespace.
213 AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
214 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
215 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
219 if (ACPI_FAILURE (Status))
221 ACPI_ERROR_NAMESPACE (Path, Status);
222 return_ACPI_STATUS (Status);
226 * Check to make sure that the target is
227 * one of the opcodes that actually opens a scope
232 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
233 case ACPI_TYPE_DEVICE:
234 case ACPI_TYPE_POWER:
235 case ACPI_TYPE_PROCESSOR:
236 case ACPI_TYPE_THERMAL:
238 /* These are acceptable types */
241 case ACPI_TYPE_INTEGER:
242 case ACPI_TYPE_STRING:
243 case ACPI_TYPE_BUFFER:
245 * These types we will allow, but we will change the type.
246 * This enables some existing code of the form:
249 * Scope (DEB) { ... }
251 * Note: silently change the type here. On the second pass,
252 * we will report a warning
254 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
255 "Type override - [%4.4s] had invalid type (%s) "
256 "for Scope operator, changed to type ANY\n",
257 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
259 Node->Type = ACPI_TYPE_ANY;
260 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
263 case ACPI_TYPE_METHOD:
265 * Allow scope change to root during execution of module-level
266 * code. Root is typed METHOD during this time.
268 if ((Node == AcpiGbl_RootNode) &&
269 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
274 /*lint -fallthrough */
278 /* All other types are an error */
280 ACPI_ERROR ((AE_INFO,
281 "Invalid type (%s) for target of "
282 "Scope operator [%4.4s] (Cannot override)",
283 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
285 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
291 * For all other named opcodes, we will enter the name into
294 * Setup the search flags.
295 * Since we are entering a name into the namespace, we do not want to
296 * enable the search-to-root upsearch.
298 * There are only two conditions where it is acceptable that the name
300 * 1) the Scope() operator can reopen a scoping object that was
301 * previously defined (Scope, Method, Device, etc.)
302 * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
303 * BufferField, or Package), the name of the object is already
306 if (WalkState->DeferredNode)
308 /* This name is already in the namespace, get the node */
310 Node = WalkState->DeferredNode;
316 * If we are executing a method, do not create any namespace objects
317 * during the load phase, only during execution.
319 if (WalkState->MethodNode)
326 Flags = ACPI_NS_NO_UPSEARCH;
327 if ((WalkState->Opcode != AML_SCOPE_OP) &&
328 (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
330 Flags |= ACPI_NS_ERROR_IF_FOUND;
331 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
332 AcpiUtGetTypeName (ObjectType)));
336 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
337 "[%s] Both Find or Create allowed\n",
338 AcpiUtGetTypeName (ObjectType)));
342 * Enter the named type into the internal namespace. We enter the name
343 * as we go downward in the parse tree. Any necessary subobjects that
344 * involve arguments to the opcode must be created as we go back up the
347 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
348 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
349 if (ACPI_FAILURE (Status))
351 if (Status == AE_ALREADY_EXISTS)
353 /* The name already exists in this scope */
355 if (Node->Flags & ANOBJ_IS_EXTERNAL)
358 * Allow one create on an object or segment that was
359 * previously declared External
361 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
362 Node->Type = (UINT8) ObjectType;
364 /* Just retyped a node, probably will need to open a scope */
366 if (AcpiNsOpensScope (ObjectType))
368 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
369 if (ACPI_FAILURE (Status))
371 return_ACPI_STATUS (Status);
379 if (ACPI_FAILURE (Status))
381 ACPI_ERROR_NAMESPACE (Path, Status);
382 return_ACPI_STATUS (Status);
392 /* Create a new op */
394 Op = AcpiPsAllocOp (WalkState->Opcode);
397 return_ACPI_STATUS (AE_NO_MEMORY);
401 /* Initialize the op */
403 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
404 Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
410 * Put the Node in the "op" object that the parser uses, so we
411 * can get it again quickly when this scope is closed
413 Op->Common.Node = Node;
414 Op->Named.Name = Node->Name.Integer;
417 AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
419 return_ACPI_STATUS (Status);
423 /*******************************************************************************
425 * FUNCTION: AcpiDsLoad1EndOp
427 * PARAMETERS: WalkState - Current state of the parse tree walk
431 * DESCRIPTION: Ascending callback used during the loading of the namespace,
432 * both control methods and everything else.
434 ******************************************************************************/
438 ACPI_WALK_STATE *WalkState)
440 ACPI_PARSE_OBJECT *Op;
441 ACPI_OBJECT_TYPE ObjectType;
442 ACPI_STATUS Status = AE_OK;
445 ACPI_FUNCTION_TRACE (DsLoad1EndOp);
449 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
451 /* We are only interested in opcodes that have an associated name */
453 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
455 return_ACPI_STATUS (AE_OK);
458 /* Get the object type to determine if we should pop the scope */
460 ObjectType = WalkState->OpInfo->ObjectType;
462 #ifndef ACPI_NO_METHOD_EXECUTION
463 if (WalkState->OpInfo->Flags & AML_FIELD)
466 * If we are executing a method, do not create any namespace objects
467 * during the load phase, only during execution.
469 if (!WalkState->MethodNode)
471 if (WalkState->Opcode == AML_FIELD_OP ||
472 WalkState->Opcode == AML_BANK_FIELD_OP ||
473 WalkState->Opcode == AML_INDEX_FIELD_OP)
475 Status = AcpiDsInitFieldObjects (Op, WalkState);
478 return_ACPI_STATUS (Status);
482 * If we are executing a method, do not create any namespace objects
483 * during the load phase, only during execution.
485 if (!WalkState->MethodNode)
487 if (Op->Common.AmlOpcode == AML_REGION_OP)
489 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
490 (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
492 if (ACPI_FAILURE (Status))
494 return_ACPI_STATUS (Status);
497 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
499 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
500 ACPI_ADR_SPACE_DATA_TABLE, WalkState);
501 if (ACPI_FAILURE (Status))
503 return_ACPI_STATUS (Status);
509 if (Op->Common.AmlOpcode == AML_NAME_OP)
511 /* For Name opcode, get the object type from the argument */
513 if (Op->Common.Value.Arg)
515 ObjectType = (AcpiPsGetOpcodeInfo (
516 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
518 /* Set node type if we have a namespace node */
522 Op->Common.Node->Type = (UINT8) ObjectType;
528 * If we are executing a method, do not create any namespace objects
529 * during the load phase, only during execution.
531 if (!WalkState->MethodNode)
533 if (Op->Common.AmlOpcode == AML_METHOD_OP)
536 * MethodOp PkgLength NameString MethodFlags TermList
538 * Note: We must create the method node/object pair as soon as we
539 * see the method declaration. This allows later pass1 parsing
540 * of invocations of the method (need to know the number of
543 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
544 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
545 WalkState, Op, Op->Named.Node));
547 if (!AcpiNsGetAttachedObject (Op->Named.Node))
549 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
550 WalkState->NumOperands = 1;
552 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
553 if (ACPI_SUCCESS (Status))
555 Status = AcpiExCreateMethod (Op->Named.Data,
556 Op->Named.Length, WalkState);
559 WalkState->Operands[0] = NULL;
560 WalkState->NumOperands = 0;
562 if (ACPI_FAILURE (Status))
564 return_ACPI_STATUS (Status);
570 /* Pop the scope stack (only if loading a table) */
572 if (!WalkState->MethodNode &&
573 AcpiNsOpensScope (ObjectType))
575 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
576 AcpiUtGetTypeName (ObjectType), Op));
578 Status = AcpiDsScopeStackPop (WalkState);
581 return_ACPI_STATUS (Status);