1 /******************************************************************************
3 * Module Name: excreate - Named object creation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acinterp.h>
47 #include <acpi/amlcode.h>
48 #include <acpi/acnamesp.h>
49 #include <acpi/acevents.h>
50 #include <acpi/actables.h>
53 #define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("excreate")
57 #ifndef ACPI_NO_METHOD_EXECUTION
58 /*****************************************************************************
60 * FUNCTION: acpi_ex_create_alias
62 * PARAMETERS: walk_state - Current state, contains operands
66 * DESCRIPTION: Create a new named alias
68 ****************************************************************************/
71 acpi_ex_create_alias (
72 struct acpi_walk_state
*walk_state
)
74 struct acpi_namespace_node
*target_node
;
75 struct acpi_namespace_node
*alias_node
;
76 acpi_status status
= AE_OK
;
79 ACPI_FUNCTION_TRACE ("ex_create_alias");
82 /* Get the source/alias operands (both namespace nodes) */
84 alias_node
= (struct acpi_namespace_node
*) walk_state
->operands
[0];
85 target_node
= (struct acpi_namespace_node
*) walk_state
->operands
[1];
87 if ((target_node
->type
== ACPI_TYPE_LOCAL_ALIAS
) ||
88 (target_node
->type
== ACPI_TYPE_LOCAL_METHOD_ALIAS
)) {
90 * Dereference an existing alias so that we don't create a chain
91 * of aliases. With this code, we guarantee that an alias is
92 * always exactly one level of indirection away from the
93 * actual aliased name.
95 target_node
= ACPI_CAST_PTR (struct acpi_namespace_node
, target_node
->object
);
99 * For objects that can never change (i.e., the NS node will
100 * permanently point to the same object), we can simply attach
101 * the object to the new NS node. For other objects (such as
102 * Integers, buffers, etc.), we have to point the Alias node
103 * to the original Node.
105 switch (target_node
->type
) {
106 case ACPI_TYPE_INTEGER
:
107 case ACPI_TYPE_STRING
:
108 case ACPI_TYPE_BUFFER
:
109 case ACPI_TYPE_PACKAGE
:
110 case ACPI_TYPE_BUFFER_FIELD
:
113 * The new alias has the type ALIAS and points to the original
114 * NS node, not the object itself. This is because for these
115 * types, the object can change dynamically via a Store.
117 alias_node
->type
= ACPI_TYPE_LOCAL_ALIAS
;
118 alias_node
->object
= ACPI_CAST_PTR (union acpi_operand_object
, target_node
);
121 case ACPI_TYPE_METHOD
:
124 * The new alias has the type ALIAS and points to the original
125 * NS node, not the object itself. This is because for these
126 * types, the object can change dynamically via a Store.
128 alias_node
->type
= ACPI_TYPE_LOCAL_METHOD_ALIAS
;
129 alias_node
->object
= ACPI_CAST_PTR (union acpi_operand_object
, target_node
);
134 /* Attach the original source object to the new Alias Node */
137 * The new alias assumes the type of the target, and it points
138 * to the same object. The reference count of the object has an
139 * additional reference to prevent deletion out from under either the
140 * target node or the alias Node
142 status
= acpi_ns_attach_object (alias_node
,
143 acpi_ns_get_attached_object (target_node
),
148 /* Since both operands are Nodes, we don't need to delete them */
150 return_ACPI_STATUS (status
);
154 /*****************************************************************************
156 * FUNCTION: acpi_ex_create_event
158 * PARAMETERS: walk_state - Current state
162 * DESCRIPTION: Create a new event object
164 ****************************************************************************/
167 acpi_ex_create_event (
168 struct acpi_walk_state
*walk_state
)
171 union acpi_operand_object
*obj_desc
;
174 ACPI_FUNCTION_TRACE ("ex_create_event");
177 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_EVENT
);
179 status
= AE_NO_MEMORY
;
184 * Create the actual OS semaphore, with zero initial units -- meaning
185 * that the event is created in an unsignalled state
187 status
= acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT
, 0,
188 &obj_desc
->event
.semaphore
);
189 if (ACPI_FAILURE (status
)) {
193 /* Attach object to the Node */
195 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) walk_state
->operands
[0],
196 obj_desc
, ACPI_TYPE_EVENT
);
200 * Remove local reference to the object (on error, will cause deletion
201 * of both object and semaphore if present.)
203 acpi_ut_remove_reference (obj_desc
);
204 return_ACPI_STATUS (status
);
208 /*****************************************************************************
210 * FUNCTION: acpi_ex_create_mutex
212 * PARAMETERS: walk_state - Current state
216 * DESCRIPTION: Create a new mutex object
218 * Mutex (Name[0], sync_level[1])
220 ****************************************************************************/
223 acpi_ex_create_mutex (
224 struct acpi_walk_state
*walk_state
)
226 acpi_status status
= AE_OK
;
227 union acpi_operand_object
*obj_desc
;
230 ACPI_FUNCTION_TRACE_PTR ("ex_create_mutex", ACPI_WALK_OPERANDS
);
233 /* Create the new mutex object */
235 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_MUTEX
);
237 status
= AE_NO_MEMORY
;
242 * Create the actual OS semaphore.
243 * One unit max to make it a mutex, with one initial unit to allow
244 * the mutex to be acquired.
246 status
= acpi_os_create_semaphore (1, 1, &obj_desc
->mutex
.semaphore
);
247 if (ACPI_FAILURE (status
)) {
251 /* Init object and attach to NS node */
253 obj_desc
->mutex
.sync_level
= (u8
) walk_state
->operands
[1]->integer
.value
;
254 obj_desc
->mutex
.node
= (struct acpi_namespace_node
*) walk_state
->operands
[0];
256 status
= acpi_ns_attach_object (obj_desc
->mutex
.node
,
257 obj_desc
, ACPI_TYPE_MUTEX
);
262 * Remove local reference to the object (on error, will cause deletion
263 * of both object and semaphore if present.)
265 acpi_ut_remove_reference (obj_desc
);
266 return_ACPI_STATUS (status
);
270 /*****************************************************************************
272 * FUNCTION: acpi_ex_create_region
274 * PARAMETERS: aml_start - Pointer to the region declaration AML
275 * aml_length - Max length of the declaration AML
276 * Operands - List of operands for the opcode
277 * walk_state - Current state
281 * DESCRIPTION: Create a new operation region object
283 ****************************************************************************/
286 acpi_ex_create_region (
290 struct acpi_walk_state
*walk_state
)
293 union acpi_operand_object
*obj_desc
;
294 struct acpi_namespace_node
*node
;
295 union acpi_operand_object
*region_obj2
;
298 ACPI_FUNCTION_TRACE ("ex_create_region");
301 /* Get the Namespace Node */
303 node
= walk_state
->op
->common
.node
;
306 * If the region object is already attached to this node,
309 if (acpi_ns_get_attached_object (node
)) {
310 return_ACPI_STATUS (AE_OK
);
314 * Space ID must be one of the predefined IDs, or in the user-defined
317 if ((region_space
>= ACPI_NUM_PREDEFINED_REGIONS
) &&
318 (region_space
< ACPI_USER_REGION_BEGIN
)) {
319 ACPI_REPORT_ERROR (("Invalid address_space type %X\n", region_space
));
320 return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID
);
323 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "Region Type - %s (%X)\n",
324 acpi_ut_get_region_name (region_space
), region_space
));
326 /* Create the region descriptor */
328 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_REGION
);
330 status
= AE_NO_MEMORY
;
335 * Remember location in AML stream of address & length
336 * operands since they need to be evaluated at run time.
338 region_obj2
= obj_desc
->common
.next_object
;
339 region_obj2
->extra
.aml_start
= aml_start
;
340 region_obj2
->extra
.aml_length
= aml_length
;
342 /* Init the region from the operands */
344 obj_desc
->region
.space_id
= region_space
;
345 obj_desc
->region
.address
= 0;
346 obj_desc
->region
.length
= 0;
347 obj_desc
->region
.node
= node
;
349 /* Install the new region object in the parent Node */
351 status
= acpi_ns_attach_object (node
, obj_desc
, ACPI_TYPE_REGION
);
356 /* Remove local reference to the object */
358 acpi_ut_remove_reference (obj_desc
);
359 return_ACPI_STATUS (status
);
363 /*****************************************************************************
365 * FUNCTION: acpi_ex_create_table_region
367 * PARAMETERS: walk_state - Current state
371 * DESCRIPTION: Create a new data_table_region object
373 ****************************************************************************/
376 acpi_ex_create_table_region (
377 struct acpi_walk_state
*walk_state
)
380 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
381 union acpi_operand_object
*obj_desc
;
382 struct acpi_namespace_node
*node
;
383 struct acpi_table_header
*table
;
384 union acpi_operand_object
*region_obj2
;
387 ACPI_FUNCTION_TRACE ("ex_create_table_region");
390 /* Get the Node from the object stack */
392 node
= walk_state
->op
->common
.node
;
395 * If the region object is already attached to this node,
398 if (acpi_ns_get_attached_object (node
)) {
399 return_ACPI_STATUS (AE_OK
);
402 /* Find the ACPI table */
404 status
= acpi_tb_find_table (operand
[1]->string
.pointer
,
405 operand
[2]->string
.pointer
,
406 operand
[3]->string
.pointer
, &table
);
407 if (ACPI_FAILURE (status
)) {
408 return_ACPI_STATUS (status
);
411 /* Create the region descriptor */
413 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_REGION
);
415 return_ACPI_STATUS (AE_NO_MEMORY
);
418 region_obj2
= obj_desc
->common
.next_object
;
419 region_obj2
->extra
.region_context
= NULL
;
421 /* Init the region from the operands */
423 obj_desc
->region
.space_id
= REGION_DATA_TABLE
;
424 obj_desc
->region
.address
= (acpi_physical_address
) ACPI_TO_INTEGER (table
);
425 obj_desc
->region
.length
= table
->length
;
426 obj_desc
->region
.node
= node
;
427 obj_desc
->region
.flags
= AOPOBJ_DATA_VALID
;
429 /* Install the new region object in the parent Node */
431 status
= acpi_ns_attach_object (node
, obj_desc
, ACPI_TYPE_REGION
);
432 if (ACPI_FAILURE (status
)) {
436 status
= acpi_ev_initialize_region (obj_desc
, FALSE
);
437 if (ACPI_FAILURE (status
)) {
438 if (status
== AE_NOT_EXIST
) {
446 obj_desc
->region
.flags
|= AOPOBJ_SETUP_COMPLETE
;
451 /* Remove local reference to the object */
453 acpi_ut_remove_reference (obj_desc
);
454 return_ACPI_STATUS (status
);
458 /*****************************************************************************
460 * FUNCTION: acpi_ex_create_processor
462 * PARAMETERS: walk_state - Current state
466 * DESCRIPTION: Create a new processor object and populate the fields
468 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
470 ****************************************************************************/
473 acpi_ex_create_processor (
474 struct acpi_walk_state
*walk_state
)
476 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
477 union acpi_operand_object
*obj_desc
;
481 ACPI_FUNCTION_TRACE_PTR ("ex_create_processor", walk_state
);
484 /* Create the processor object */
486 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_PROCESSOR
);
488 return_ACPI_STATUS (AE_NO_MEMORY
);
492 * Initialize the processor object from the operands
494 obj_desc
->processor
.proc_id
= (u8
) operand
[1]->integer
.value
;
495 obj_desc
->processor
.address
= (acpi_io_address
) operand
[2]->integer
.value
;
496 obj_desc
->processor
.length
= (u8
) operand
[3]->integer
.value
;
498 /* Install the processor object in the parent Node */
500 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) operand
[0],
501 obj_desc
, ACPI_TYPE_PROCESSOR
);
503 /* Remove local reference to the object */
505 acpi_ut_remove_reference (obj_desc
);
506 return_ACPI_STATUS (status
);
510 /*****************************************************************************
512 * FUNCTION: acpi_ex_create_power_resource
514 * PARAMETERS: walk_state - Current state
518 * DESCRIPTION: Create a new power_resource object and populate the fields
520 * power_resource (Name[0], system_level[1], resource_order[2])
522 ****************************************************************************/
525 acpi_ex_create_power_resource (
526 struct acpi_walk_state
*walk_state
)
528 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
530 union acpi_operand_object
*obj_desc
;
533 ACPI_FUNCTION_TRACE_PTR ("ex_create_power_resource", walk_state
);
536 /* Create the power resource object */
538 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_POWER
);
540 return_ACPI_STATUS (AE_NO_MEMORY
);
543 /* Initialize the power object from the operands */
545 obj_desc
->power_resource
.system_level
= (u8
) operand
[1]->integer
.value
;
546 obj_desc
->power_resource
.resource_order
= (u16
) operand
[2]->integer
.value
;
548 /* Install the power resource object in the parent Node */
550 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) operand
[0],
551 obj_desc
, ACPI_TYPE_POWER
);
553 /* Remove local reference to the object */
555 acpi_ut_remove_reference (obj_desc
);
556 return_ACPI_STATUS (status
);
561 /*****************************************************************************
563 * FUNCTION: acpi_ex_create_method
565 * PARAMETERS: aml_start - First byte of the method's AML
566 * aml_length - AML byte count for this method
567 * walk_state - Current state
571 * DESCRIPTION: Create a new method object
573 ****************************************************************************/
576 acpi_ex_create_method (
579 struct acpi_walk_state
*walk_state
)
581 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
582 union acpi_operand_object
*obj_desc
;
587 ACPI_FUNCTION_TRACE_PTR ("ex_create_method", walk_state
);
590 /* Create a new method object */
592 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_METHOD
);
594 return_ACPI_STATUS (AE_NO_MEMORY
);
597 /* Save the method's AML pointer and length */
599 obj_desc
->method
.aml_start
= aml_start
;
600 obj_desc
->method
.aml_length
= aml_length
;
603 * Disassemble the method flags. Split off the Arg Count
606 method_flags
= (u8
) operand
[1]->integer
.value
;
608 obj_desc
->method
.method_flags
= (u8
) (method_flags
& ~AML_METHOD_ARG_COUNT
);
609 obj_desc
->method
.param_count
= (u8
) (method_flags
& AML_METHOD_ARG_COUNT
);
612 * Get the concurrency count. If required, a semaphore will be
613 * created for this method when it is parsed.
615 if (acpi_gbl_all_methods_serialized
) {
616 obj_desc
->method
.concurrency
= 1;
617 obj_desc
->method
.method_flags
|= AML_METHOD_SERIALIZED
;
619 else if (method_flags
& AML_METHOD_SERIALIZED
) {
621 * ACPI 1.0: Concurrency = 1
622 * ACPI 2.0: Concurrency = (sync_level (in method declaration) + 1)
624 obj_desc
->method
.concurrency
= (u8
)
625 (((method_flags
& AML_METHOD_SYNCH_LEVEL
) >> 4) + 1);
628 obj_desc
->method
.concurrency
= ACPI_INFINITE_CONCURRENCY
;
631 /* Attach the new object to the method Node */
633 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) operand
[0],
634 obj_desc
, ACPI_TYPE_METHOD
);
636 /* Remove local reference to the object */
638 acpi_ut_remove_reference (obj_desc
);
640 /* Remove a reference to the operand */
642 acpi_ut_remove_reference (operand
[1]);
643 return_ACPI_STATUS (status
);