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
), target_node
->type
);
147 /* Since both operands are Nodes, we don't need to delete them */
149 return_ACPI_STATUS (status
);
153 /*******************************************************************************
155 * FUNCTION: acpi_ex_create_event
157 * PARAMETERS: walk_state - Current state
161 * DESCRIPTION: Create a new event object
163 ******************************************************************************/
166 acpi_ex_create_event (
167 struct acpi_walk_state
*walk_state
)
170 union acpi_operand_object
*obj_desc
;
173 ACPI_FUNCTION_TRACE ("ex_create_event");
176 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_EVENT
);
178 status
= AE_NO_MEMORY
;
183 * Create the actual OS semaphore, with zero initial units -- meaning
184 * that the event is created in an unsignalled state
186 status
= acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT
, 0,
187 &obj_desc
->event
.semaphore
);
188 if (ACPI_FAILURE (status
)) {
192 /* Attach object to the Node */
194 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) walk_state
->operands
[0],
195 obj_desc
, ACPI_TYPE_EVENT
);
199 * Remove local reference to the object (on error, will cause deletion
200 * of both object and semaphore if present.)
202 acpi_ut_remove_reference (obj_desc
);
203 return_ACPI_STATUS (status
);
207 /*******************************************************************************
209 * FUNCTION: acpi_ex_create_mutex
211 * PARAMETERS: walk_state - Current state
215 * DESCRIPTION: Create a new mutex object
217 * Mutex (Name[0], sync_level[1])
219 ******************************************************************************/
222 acpi_ex_create_mutex (
223 struct acpi_walk_state
*walk_state
)
225 acpi_status status
= AE_OK
;
226 union acpi_operand_object
*obj_desc
;
229 ACPI_FUNCTION_TRACE_PTR ("ex_create_mutex", ACPI_WALK_OPERANDS
);
232 /* Create the new mutex object */
234 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_MUTEX
);
236 status
= AE_NO_MEMORY
;
241 * Create the actual OS semaphore.
242 * One unit max to make it a mutex, with one initial unit to allow
243 * the mutex to be acquired.
245 status
= acpi_os_create_semaphore (1, 1, &obj_desc
->mutex
.semaphore
);
246 if (ACPI_FAILURE (status
)) {
250 /* Init object and attach to NS node */
252 obj_desc
->mutex
.sync_level
= (u8
) walk_state
->operands
[1]->integer
.value
;
253 obj_desc
->mutex
.node
= (struct acpi_namespace_node
*) walk_state
->operands
[0];
255 status
= acpi_ns_attach_object (obj_desc
->mutex
.node
,
256 obj_desc
, ACPI_TYPE_MUTEX
);
261 * Remove local reference to the object (on error, will cause deletion
262 * of both object and semaphore if present.)
264 acpi_ut_remove_reference (obj_desc
);
265 return_ACPI_STATUS (status
);
269 /*******************************************************************************
271 * FUNCTION: acpi_ex_create_region
273 * PARAMETERS: aml_start - Pointer to the region declaration AML
274 * aml_length - Max length of the declaration AML
275 * region_space - space_iD for the region
276 * walk_state - Current state
280 * DESCRIPTION: Create a new operation region object
282 ******************************************************************************/
285 acpi_ex_create_region (
289 struct acpi_walk_state
*walk_state
)
292 union acpi_operand_object
*obj_desc
;
293 struct acpi_namespace_node
*node
;
294 union acpi_operand_object
*region_obj2
;
297 ACPI_FUNCTION_TRACE ("ex_create_region");
300 /* Get the Namespace Node */
302 node
= walk_state
->op
->common
.node
;
305 * If the region object is already attached to this node,
308 if (acpi_ns_get_attached_object (node
)) {
309 return_ACPI_STATUS (AE_OK
);
313 * Space ID must be one of the predefined IDs, or in the user-defined
316 if ((region_space
>= ACPI_NUM_PREDEFINED_REGIONS
) &&
317 (region_space
< ACPI_USER_REGION_BEGIN
)) {
318 ACPI_REPORT_ERROR (("Invalid address_space type %X\n", region_space
));
319 return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID
);
322 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "Region Type - %s (%X)\n",
323 acpi_ut_get_region_name (region_space
), region_space
));
325 /* Create the region descriptor */
327 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_REGION
);
329 status
= AE_NO_MEMORY
;
334 * Remember location in AML stream of address & length
335 * operands since they need to be evaluated at run time.
337 region_obj2
= obj_desc
->common
.next_object
;
338 region_obj2
->extra
.aml_start
= aml_start
;
339 region_obj2
->extra
.aml_length
= aml_length
;
341 /* Init the region from the operands */
343 obj_desc
->region
.space_id
= region_space
;
344 obj_desc
->region
.address
= 0;
345 obj_desc
->region
.length
= 0;
346 obj_desc
->region
.node
= node
;
348 /* Install the new region object in the parent Node */
350 status
= acpi_ns_attach_object (node
, obj_desc
, ACPI_TYPE_REGION
);
355 /* Remove local reference to the object */
357 acpi_ut_remove_reference (obj_desc
);
358 return_ACPI_STATUS (status
);
362 /*******************************************************************************
364 * FUNCTION: acpi_ex_create_table_region
366 * PARAMETERS: walk_state - Current state
370 * DESCRIPTION: Create a new data_table_region object
372 ******************************************************************************/
375 acpi_ex_create_table_region (
376 struct acpi_walk_state
*walk_state
)
379 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
380 union acpi_operand_object
*obj_desc
;
381 struct acpi_namespace_node
*node
;
382 struct acpi_table_header
*table
;
383 union acpi_operand_object
*region_obj2
;
386 ACPI_FUNCTION_TRACE ("ex_create_table_region");
389 /* Get the Node from the object stack */
391 node
= walk_state
->op
->common
.node
;
394 * If the region object is already attached to this node,
397 if (acpi_ns_get_attached_object (node
)) {
398 return_ACPI_STATUS (AE_OK
);
401 /* Find the ACPI table */
403 status
= acpi_tb_find_table (operand
[1]->string
.pointer
,
404 operand
[2]->string
.pointer
,
405 operand
[3]->string
.pointer
, &table
);
406 if (ACPI_FAILURE (status
)) {
407 return_ACPI_STATUS (status
);
410 /* Create the region descriptor */
412 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_REGION
);
414 return_ACPI_STATUS (AE_NO_MEMORY
);
417 region_obj2
= obj_desc
->common
.next_object
;
418 region_obj2
->extra
.region_context
= NULL
;
420 /* Init the region from the operands */
422 obj_desc
->region
.space_id
= REGION_DATA_TABLE
;
423 obj_desc
->region
.address
= (acpi_physical_address
) ACPI_TO_INTEGER (table
);
424 obj_desc
->region
.length
= table
->length
;
425 obj_desc
->region
.node
= node
;
426 obj_desc
->region
.flags
= AOPOBJ_DATA_VALID
;
428 /* Install the new region object in the parent Node */
430 status
= acpi_ns_attach_object (node
, obj_desc
, ACPI_TYPE_REGION
);
431 if (ACPI_FAILURE (status
)) {
435 status
= acpi_ev_initialize_region (obj_desc
, FALSE
);
436 if (ACPI_FAILURE (status
)) {
437 if (status
== AE_NOT_EXIST
) {
445 obj_desc
->region
.flags
|= AOPOBJ_SETUP_COMPLETE
;
450 /* Remove local reference to the object */
452 acpi_ut_remove_reference (obj_desc
);
453 return_ACPI_STATUS (status
);
457 /*******************************************************************************
459 * FUNCTION: acpi_ex_create_processor
461 * PARAMETERS: walk_state - Current state
465 * DESCRIPTION: Create a new processor object and populate the fields
467 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
469 ******************************************************************************/
472 acpi_ex_create_processor (
473 struct acpi_walk_state
*walk_state
)
475 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
476 union acpi_operand_object
*obj_desc
;
480 ACPI_FUNCTION_TRACE_PTR ("ex_create_processor", walk_state
);
483 /* Create the processor object */
485 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_PROCESSOR
);
487 return_ACPI_STATUS (AE_NO_MEMORY
);
490 /* Initialize the processor object from the operands */
492 obj_desc
->processor
.proc_id
= (u8
) operand
[1]->integer
.value
;
493 obj_desc
->processor
.address
= (acpi_io_address
) operand
[2]->integer
.value
;
494 obj_desc
->processor
.length
= (u8
) operand
[3]->integer
.value
;
496 /* Install the processor object in the parent Node */
498 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) operand
[0],
499 obj_desc
, ACPI_TYPE_PROCESSOR
);
501 /* Remove local reference to the object */
503 acpi_ut_remove_reference (obj_desc
);
504 return_ACPI_STATUS (status
);
508 /*******************************************************************************
510 * FUNCTION: acpi_ex_create_power_resource
512 * PARAMETERS: walk_state - Current state
516 * DESCRIPTION: Create a new power_resource object and populate the fields
518 * power_resource (Name[0], system_level[1], resource_order[2])
520 ******************************************************************************/
523 acpi_ex_create_power_resource (
524 struct acpi_walk_state
*walk_state
)
526 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
528 union acpi_operand_object
*obj_desc
;
531 ACPI_FUNCTION_TRACE_PTR ("ex_create_power_resource", walk_state
);
534 /* Create the power resource object */
536 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_POWER
);
538 return_ACPI_STATUS (AE_NO_MEMORY
);
541 /* Initialize the power object from the operands */
543 obj_desc
->power_resource
.system_level
= (u8
) operand
[1]->integer
.value
;
544 obj_desc
->power_resource
.resource_order
= (u16
) operand
[2]->integer
.value
;
546 /* Install the power resource object in the parent Node */
548 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) operand
[0],
549 obj_desc
, ACPI_TYPE_POWER
);
551 /* Remove local reference to the object */
553 acpi_ut_remove_reference (obj_desc
);
554 return_ACPI_STATUS (status
);
559 /*******************************************************************************
561 * FUNCTION: acpi_ex_create_method
563 * PARAMETERS: aml_start - First byte of the method's AML
564 * aml_length - AML byte count for this method
565 * walk_state - Current state
569 * DESCRIPTION: Create a new method object
571 ******************************************************************************/
574 acpi_ex_create_method (
577 struct acpi_walk_state
*walk_state
)
579 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
580 union acpi_operand_object
*obj_desc
;
585 ACPI_FUNCTION_TRACE_PTR ("ex_create_method", walk_state
);
588 /* Create a new method object */
590 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_METHOD
);
592 return_ACPI_STATUS (AE_NO_MEMORY
);
595 /* Save the method's AML pointer and length */
597 obj_desc
->method
.aml_start
= aml_start
;
598 obj_desc
->method
.aml_length
= aml_length
;
601 * Disassemble the method flags. Split off the Arg Count
604 method_flags
= (u8
) operand
[1]->integer
.value
;
606 obj_desc
->method
.method_flags
= (u8
) (method_flags
& ~AML_METHOD_ARG_COUNT
);
607 obj_desc
->method
.param_count
= (u8
) (method_flags
& AML_METHOD_ARG_COUNT
);
610 * Get the concurrency count. If required, a semaphore will be
611 * created for this method when it is parsed.
613 if (acpi_gbl_all_methods_serialized
) {
614 obj_desc
->method
.concurrency
= 1;
615 obj_desc
->method
.method_flags
|= AML_METHOD_SERIALIZED
;
617 else if (method_flags
& AML_METHOD_SERIALIZED
) {
619 * ACPI 1.0: Concurrency = 1
620 * ACPI 2.0: Concurrency = (sync_level (in method declaration) + 1)
622 obj_desc
->method
.concurrency
= (u8
)
623 (((method_flags
& AML_METHOD_SYNCH_LEVEL
) >> 4) + 1);
626 obj_desc
->method
.concurrency
= ACPI_INFINITE_CONCURRENCY
;
629 /* Attach the new object to the method Node */
631 status
= acpi_ns_attach_object ((struct acpi_namespace_node
*) operand
[0],
632 obj_desc
, ACPI_TYPE_METHOD
);
634 /* Remove local reference to the object */
636 acpi_ut_remove_reference (obj_desc
);
638 /* Remove a reference to the operand */
640 acpi_ut_remove_reference (operand
[1]);
641 return_ACPI_STATUS (status
);