1 /******************************************************************************
3 * Module Name: excreate - Named object creation
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.
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("excreate")
55 #ifndef ACPI_NO_METHOD_EXECUTION
56 /*******************************************************************************
58 * FUNCTION: AcpiExCreateAlias
60 * PARAMETERS: WalkState - Current state, contains operands
64 * DESCRIPTION: Create a new named alias
66 ******************************************************************************/
70 ACPI_WALK_STATE *WalkState)
72 ACPI_NAMESPACE_NODE *TargetNode;
73 ACPI_NAMESPACE_NODE *AliasNode;
74 ACPI_STATUS Status = AE_OK;
77 ACPI_FUNCTION_TRACE (ExCreateAlias);
80 /* Get the source/alias operands (both namespace nodes) */
82 AliasNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
83 TargetNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[1];
85 if ((TargetNode->Type == ACPI_TYPE_LOCAL_ALIAS) ||
86 (TargetNode->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
89 * Dereference an existing alias so that we don't create a chain
90 * of aliases. With this code, we guarantee that an alias is
91 * always exactly one level of indirection away from the
92 * actual aliased name.
94 TargetNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, TargetNode->Object);
98 * For objects that can never change (i.e., the NS node will
99 * permanently point to the same object), we can simply attach
100 * the object to the new NS node. For other objects (such as
101 * Integers, buffers, etc.), we have to point the Alias node
102 * to the original Node.
104 switch (TargetNode->Type)
107 /* For these types, the sub-object can change dynamically via a Store */
109 case ACPI_TYPE_INTEGER:
110 case ACPI_TYPE_STRING:
111 case ACPI_TYPE_BUFFER:
112 case ACPI_TYPE_PACKAGE:
113 case ACPI_TYPE_BUFFER_FIELD:
115 * These types open a new scope, so we need the NS node in order to access
118 case ACPI_TYPE_DEVICE:
119 case ACPI_TYPE_POWER:
120 case ACPI_TYPE_PROCESSOR:
121 case ACPI_TYPE_THERMAL:
122 case ACPI_TYPE_LOCAL_SCOPE:
124 * The new alias has the type ALIAS and points to the original
125 * NS node, not the object itself.
127 AliasNode->Type = ACPI_TYPE_LOCAL_ALIAS;
128 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
131 case ACPI_TYPE_METHOD:
133 * Control method aliases need to be differentiated
135 AliasNode->Type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
136 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
141 /* Attach the original source object to the new Alias Node */
144 * The new alias assumes the type of the target, and it points
145 * to the same object. The reference count of the object has an
146 * additional reference to prevent deletion out from under either the
147 * target node or the alias Node
149 Status = AcpiNsAttachObject (AliasNode,
150 AcpiNsGetAttachedObject (TargetNode), TargetNode->Type);
154 /* Since both operands are Nodes, we don't need to delete them */
156 return_ACPI_STATUS (Status);
160 /*******************************************************************************
162 * FUNCTION: AcpiExCreateEvent
164 * PARAMETERS: WalkState - Current state
168 * DESCRIPTION: Create a new event object
170 ******************************************************************************/
174 ACPI_WALK_STATE *WalkState)
177 ACPI_OPERAND_OBJECT *ObjDesc;
180 ACPI_FUNCTION_TRACE (ExCreateEvent);
183 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_EVENT);
186 Status = AE_NO_MEMORY;
191 * Create the actual OS semaphore, with zero initial units -- meaning
192 * that the event is created in an unsignalled state
194 Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
195 &ObjDesc->Event.OsSemaphore);
196 if (ACPI_FAILURE (Status))
201 /* Attach object to the Node */
203 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
204 ObjDesc, ACPI_TYPE_EVENT);
208 * Remove local reference to the object (on error, will cause deletion
209 * of both object and semaphore if present.)
211 AcpiUtRemoveReference (ObjDesc);
212 return_ACPI_STATUS (Status);
216 /*******************************************************************************
218 * FUNCTION: AcpiExCreateMutex
220 * PARAMETERS: WalkState - Current state
224 * DESCRIPTION: Create a new mutex object
226 * Mutex (Name[0], SyncLevel[1])
228 ******************************************************************************/
232 ACPI_WALK_STATE *WalkState)
234 ACPI_STATUS Status = AE_OK;
235 ACPI_OPERAND_OBJECT *ObjDesc;
238 ACPI_FUNCTION_TRACE_PTR (ExCreateMutex, ACPI_WALK_OPERANDS);
241 /* Create the new mutex object */
243 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
246 Status = AE_NO_MEMORY;
250 /* Create the actual OS Mutex */
252 Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
253 if (ACPI_FAILURE (Status))
258 /* Init object and attach to NS node */
260 ObjDesc->Mutex.SyncLevel = (UINT8) WalkState->Operands[1]->Integer.Value;
261 ObjDesc->Mutex.Node = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
263 Status = AcpiNsAttachObject (ObjDesc->Mutex.Node, ObjDesc, ACPI_TYPE_MUTEX);
268 * Remove local reference to the object (on error, will cause deletion
269 * of both object and semaphore if present.)
271 AcpiUtRemoveReference (ObjDesc);
272 return_ACPI_STATUS (Status);
276 /*******************************************************************************
278 * FUNCTION: AcpiExCreateRegion
280 * PARAMETERS: AmlStart - Pointer to the region declaration AML
281 * AmlLength - Max length of the declaration AML
282 * SpaceId - Address space ID for the region
283 * WalkState - Current state
287 * DESCRIPTION: Create a new operation region object
289 ******************************************************************************/
296 ACPI_WALK_STATE *WalkState)
299 ACPI_OPERAND_OBJECT *ObjDesc;
300 ACPI_NAMESPACE_NODE *Node;
301 ACPI_OPERAND_OBJECT *RegionObj2;
304 ACPI_FUNCTION_TRACE (ExCreateRegion);
307 /* Get the Namespace Node */
309 Node = WalkState->Op->Common.Node;
312 * If the region object is already attached to this node,
315 if (AcpiNsGetAttachedObject (Node))
317 return_ACPI_STATUS (AE_OK);
321 * Space ID must be one of the predefined IDs, or in the user-defined
324 if (!AcpiIsValidSpaceId (SpaceId))
327 * Print an error message, but continue. We don't want to abort
328 * a table load for this exception. Instead, if the region is
329 * actually used at runtime, abort the executing method.
331 ACPI_ERROR ((AE_INFO, "Invalid/unknown Address Space ID: 0x%2.2X", SpaceId));
334 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
335 AcpiUtGetRegionName (SpaceId), SpaceId));
337 /* Create the region descriptor */
339 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
342 Status = AE_NO_MEMORY;
347 * Remember location in AML stream of address & length
348 * operands since they need to be evaluated at run time.
350 RegionObj2 = ObjDesc->Common.NextObject;
351 RegionObj2->Extra.AmlStart = AmlStart;
352 RegionObj2->Extra.AmlLength = AmlLength;
353 if (WalkState->ScopeInfo)
355 RegionObj2->Extra.ScopeNode = WalkState->ScopeInfo->Scope.Node;
359 RegionObj2->Extra.ScopeNode = Node;
362 /* Init the region from the operands */
364 ObjDesc->Region.SpaceId = SpaceId;
365 ObjDesc->Region.Address = 0;
366 ObjDesc->Region.Length = 0;
367 ObjDesc->Region.Node = Node;
369 /* Install the new region object in the parent Node */
371 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_REGION);
376 /* Remove local reference to the object */
378 AcpiUtRemoveReference (ObjDesc);
379 return_ACPI_STATUS (Status);
383 /*******************************************************************************
385 * FUNCTION: AcpiExCreateProcessor
387 * PARAMETERS: WalkState - Current state
391 * DESCRIPTION: Create a new processor object and populate the fields
393 * Processor (Name[0], CpuID[1], PblockAddr[2], PblockLength[3])
395 ******************************************************************************/
398 AcpiExCreateProcessor (
399 ACPI_WALK_STATE *WalkState)
401 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
402 ACPI_OPERAND_OBJECT *ObjDesc;
406 ACPI_FUNCTION_TRACE_PTR (ExCreateProcessor, WalkState);
409 /* Create the processor object */
411 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PROCESSOR);
414 return_ACPI_STATUS (AE_NO_MEMORY);
417 /* Initialize the processor object from the operands */
419 ObjDesc->Processor.ProcId = (UINT8) Operand[1]->Integer.Value;
420 ObjDesc->Processor.Length = (UINT8) Operand[3]->Integer.Value;
421 ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Operand[2]->Integer.Value;
423 /* Install the processor object in the parent Node */
425 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
426 ObjDesc, ACPI_TYPE_PROCESSOR);
428 /* Remove local reference to the object */
430 AcpiUtRemoveReference (ObjDesc);
431 return_ACPI_STATUS (Status);
435 /*******************************************************************************
437 * FUNCTION: AcpiExCreatePowerResource
439 * PARAMETERS: WalkState - Current state
443 * DESCRIPTION: Create a new PowerResource object and populate the fields
445 * PowerResource (Name[0], SystemLevel[1], ResourceOrder[2])
447 ******************************************************************************/
450 AcpiExCreatePowerResource (
451 ACPI_WALK_STATE *WalkState)
453 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
455 ACPI_OPERAND_OBJECT *ObjDesc;
458 ACPI_FUNCTION_TRACE_PTR (ExCreatePowerResource, WalkState);
461 /* Create the power resource object */
463 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_POWER);
466 return_ACPI_STATUS (AE_NO_MEMORY);
469 /* Initialize the power object from the operands */
471 ObjDesc->PowerResource.SystemLevel = (UINT8) Operand[1]->Integer.Value;
472 ObjDesc->PowerResource.ResourceOrder = (UINT16) Operand[2]->Integer.Value;
474 /* Install the power resource object in the parent Node */
476 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
477 ObjDesc, ACPI_TYPE_POWER);
479 /* Remove local reference to the object */
481 AcpiUtRemoveReference (ObjDesc);
482 return_ACPI_STATUS (Status);
487 /*******************************************************************************
489 * FUNCTION: AcpiExCreateMethod
491 * PARAMETERS: AmlStart - First byte of the method's AML
492 * AmlLength - AML byte count for this method
493 * WalkState - Current state
497 * DESCRIPTION: Create a new method object
499 ******************************************************************************/
505 ACPI_WALK_STATE *WalkState)
507 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
508 ACPI_OPERAND_OBJECT *ObjDesc;
513 ACPI_FUNCTION_TRACE_PTR (ExCreateMethod, WalkState);
516 /* Create a new method object */
518 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
521 Status = AE_NO_MEMORY;
525 /* Save the method's AML pointer and length */
527 ObjDesc->Method.AmlStart = AmlStart;
528 ObjDesc->Method.AmlLength = AmlLength;
529 ObjDesc->Method.Node = Operand[0];
532 * Disassemble the method flags. Split off the ArgCount, Serialized
533 * flag, and SyncLevel for efficiency.
535 MethodFlags = (UINT8) Operand[1]->Integer.Value;
536 ObjDesc->Method.ParamCount = (UINT8) (MethodFlags & AML_METHOD_ARG_COUNT);
539 * Get the SyncLevel. If method is serialized, a mutex will be
540 * created for this method when it is parsed.
542 if (MethodFlags & AML_METHOD_SERIALIZED)
544 ObjDesc->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
547 * ACPI 1.0: SyncLevel = 0
548 * ACPI 2.0: SyncLevel = SyncLevel in method declaration
550 ObjDesc->Method.SyncLevel = (UINT8)
551 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
554 /* Attach the new object to the method Node */
556 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
557 ObjDesc, ACPI_TYPE_METHOD);
559 /* Remove local reference to the object */
561 AcpiUtRemoveReference (ObjDesc);
564 /* Remove a reference to the operand */
566 AcpiUtRemoveReference (Operand[1]);
567 return_ACPI_STATUS (Status);