1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
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>
51 #include <acpi/acdispat.h>
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exconfig")
57 /* Local prototypes */
61 struct acpi_table_header
*table
,
62 struct acpi_namespace_node
*parent_node
,
63 union acpi_operand_object
**ddb_handle
);
66 /*******************************************************************************
68 * FUNCTION: acpi_ex_add_table
70 * PARAMETERS: Table - Pointer to raw table
71 * parent_node - Where to load the table (scope)
72 * ddb_handle - Where to return the table handle.
76 * DESCRIPTION: Common function to Install and Load an ACPI table with a
77 * returned table handle.
79 ******************************************************************************/
83 struct acpi_table_header
*table
,
84 struct acpi_namespace_node
*parent_node
,
85 union acpi_operand_object
**ddb_handle
)
88 struct acpi_table_desc table_info
;
89 union acpi_operand_object
*obj_desc
;
92 ACPI_FUNCTION_TRACE ("ex_add_table");
95 /* Create an object to be the table handle */
97 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE
);
99 return_ACPI_STATUS (AE_NO_MEMORY
);
102 /* Init the table handle */
104 obj_desc
->reference
.opcode
= AML_LOAD_OP
;
105 *ddb_handle
= obj_desc
;
107 /* Install the new table into the local data structures */
109 ACPI_MEMSET (&table_info
, 0, sizeof (struct acpi_table_desc
));
111 table_info
.type
= ACPI_TABLE_SSDT
;
112 table_info
.pointer
= table
;
113 table_info
.length
= (acpi_size
) table
->length
;
114 table_info
.allocation
= ACPI_MEM_ALLOCATED
;
116 status
= acpi_tb_install_table (&table_info
);
117 obj_desc
->reference
.object
= table_info
.installed_desc
;
119 if (ACPI_FAILURE (status
)) {
120 if (status
== AE_ALREADY_EXISTS
) {
121 /* Table already exists, just return the handle */
123 return_ACPI_STATUS (AE_OK
);
128 /* Add the table to the namespace */
130 status
= acpi_ns_load_table (table_info
.installed_desc
, parent_node
);
131 if (ACPI_FAILURE (status
)) {
132 /* Uninstall table on error */
134 (void) acpi_tb_uninstall_table (table_info
.installed_desc
);
138 return_ACPI_STATUS (AE_OK
);
142 acpi_ut_remove_reference (obj_desc
);
144 return_ACPI_STATUS (status
);
148 /*******************************************************************************
150 * FUNCTION: acpi_ex_load_table_op
152 * PARAMETERS: walk_state - Current state with operands
153 * return_desc - Where to store the return object
157 * DESCRIPTION: Load an ACPI table
159 ******************************************************************************/
162 acpi_ex_load_table_op (
163 struct acpi_walk_state
*walk_state
,
164 union acpi_operand_object
**return_desc
)
167 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
168 struct acpi_table_header
*table
;
169 struct acpi_namespace_node
*parent_node
;
170 struct acpi_namespace_node
*start_node
;
171 struct acpi_namespace_node
*parameter_node
= NULL
;
172 union acpi_operand_object
*ddb_handle
;
175 ACPI_FUNCTION_TRACE ("ex_load_table_op");
180 * Make sure that the signature does not match one of the tables that
183 status
= acpi_tb_match_signature (operand
[0]->string
.pointer
, NULL
);
184 if (status
== AE_OK
) {
185 /* Signature matched -- don't allow override */
187 return_ACPI_STATUS (AE_ALREADY_EXISTS
);
191 /* Find the ACPI table */
193 status
= acpi_tb_find_table (operand
[0]->string
.pointer
,
194 operand
[1]->string
.pointer
,
195 operand
[2]->string
.pointer
, &table
);
196 if (ACPI_FAILURE (status
)) {
197 if (status
!= AE_NOT_FOUND
) {
198 return_ACPI_STATUS (status
);
201 /* Table not found, return an Integer=0 and AE_OK */
203 ddb_handle
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
205 return_ACPI_STATUS (AE_NO_MEMORY
);
208 ddb_handle
->integer
.value
= 0;
209 *return_desc
= ddb_handle
;
211 return_ACPI_STATUS (AE_OK
);
216 start_node
= walk_state
->scope_info
->scope
.node
;
217 parent_node
= acpi_gbl_root_node
;
219 /* root_path (optional parameter) */
221 if (operand
[3]->string
.length
> 0) {
223 * Find the node referenced by the root_path_string. This is the
224 * location within the namespace where the table will be loaded.
226 status
= acpi_ns_get_node_by_path (operand
[3]->string
.pointer
, start_node
,
227 ACPI_NS_SEARCH_PARENT
, &parent_node
);
228 if (ACPI_FAILURE (status
)) {
229 return_ACPI_STATUS (status
);
233 /* parameter_path (optional parameter) */
235 if (operand
[4]->string
.length
> 0) {
236 if ((operand
[4]->string
.pointer
[0] != '\\') &&
237 (operand
[4]->string
.pointer
[0] != '^')) {
239 * Path is not absolute, so it will be relative to the node
240 * referenced by the root_path_string (or the NS root if omitted)
242 start_node
= parent_node
;
245 /* Find the node referenced by the parameter_path_string */
247 status
= acpi_ns_get_node_by_path (operand
[4]->string
.pointer
, start_node
,
248 ACPI_NS_SEARCH_PARENT
, ¶meter_node
);
249 if (ACPI_FAILURE (status
)) {
250 return_ACPI_STATUS (status
);
254 /* Load the table into the namespace */
256 status
= acpi_ex_add_table (table
, parent_node
, &ddb_handle
);
257 if (ACPI_FAILURE (status
)) {
258 return_ACPI_STATUS (status
);
261 /* Parameter Data (optional) */
263 if (parameter_node
) {
264 /* Store the parameter data into the optional parameter object */
266 status
= acpi_ex_store (operand
[5],
267 ACPI_CAST_PTR (union acpi_operand_object
, parameter_node
),
269 if (ACPI_FAILURE (status
)) {
270 (void) acpi_ex_unload_table (ddb_handle
);
271 return_ACPI_STATUS (status
);
275 *return_desc
= ddb_handle
;
276 return_ACPI_STATUS (status
);
280 /*******************************************************************************
282 * FUNCTION: acpi_ex_load_op
284 * PARAMETERS: obj_desc - Region or Field where the table will be
286 * Target - Where a handle to the table will be stored
287 * walk_state - Current state
291 * DESCRIPTION: Load an ACPI table from a field or operation region
293 ******************************************************************************/
297 union acpi_operand_object
*obj_desc
,
298 union acpi_operand_object
*target
,
299 struct acpi_walk_state
*walk_state
)
302 union acpi_operand_object
*ddb_handle
;
303 union acpi_operand_object
*buffer_desc
= NULL
;
304 struct acpi_table_header
*table_ptr
= NULL
;
305 acpi_physical_address address
;
306 struct acpi_table_header table_header
;
309 ACPI_FUNCTION_TRACE ("ex_load_op");
312 /* Object can be either an op_region or a Field */
314 switch (ACPI_GET_OBJECT_TYPE (obj_desc
)) {
315 case ACPI_TYPE_REGION
:
317 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Load from Region %p %s\n",
318 obj_desc
, acpi_ut_get_object_type_name (obj_desc
)));
321 * If the Region Address and Length have not been previously evaluated,
322 * evaluate them now and save the results.
324 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
325 status
= acpi_ds_get_region_arguments (obj_desc
);
326 if (ACPI_FAILURE (status
)) {
327 return_ACPI_STATUS (status
);
331 /* Get the base physical address of the region */
333 address
= obj_desc
->region
.address
;
335 /* Get the table length from the table header */
337 table_header
.length
= 0;
338 for (i
= 0; i
< 8; i
++) {
339 status
= acpi_ev_address_space_dispatch (obj_desc
, ACPI_READ
,
340 (acpi_physical_address
) (i
+ address
), 8,
341 ((u8
*) &table_header
) + i
);
342 if (ACPI_FAILURE (status
)) {
343 return_ACPI_STATUS (status
);
347 /* Sanity check the table length */
349 if (table_header
.length
< sizeof (struct acpi_table_header
)) {
350 return_ACPI_STATUS (AE_BAD_HEADER
);
353 /* Allocate a buffer for the entire table */
355 table_ptr
= ACPI_MEM_ALLOCATE (table_header
.length
);
357 return_ACPI_STATUS (AE_NO_MEMORY
);
360 /* Get the entire table from the op region */
362 for (i
= 0; i
< table_header
.length
; i
++) {
363 status
= acpi_ev_address_space_dispatch (obj_desc
, ACPI_READ
,
364 (acpi_physical_address
) (i
+ address
), 8,
365 ((u8
*) table_ptr
+ i
));
366 if (ACPI_FAILURE (status
)) {
373 case ACPI_TYPE_LOCAL_REGION_FIELD
:
374 case ACPI_TYPE_LOCAL_BANK_FIELD
:
375 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
377 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Load from Field %p %s\n",
378 obj_desc
, acpi_ut_get_object_type_name (obj_desc
)));
381 * The length of the field must be at least as large as the table.
382 * Read the entire field and thus the entire table. Buffer is
383 * allocated during the read.
385 status
= acpi_ex_read_data_from_field (walk_state
, obj_desc
, &buffer_desc
);
386 if (ACPI_FAILURE (status
)) {
387 return_ACPI_STATUS (status
);
390 table_ptr
= ACPI_CAST_PTR (struct acpi_table_header
,
391 buffer_desc
->buffer
.pointer
);
393 /* All done with the buffer_desc, delete it */
395 buffer_desc
->buffer
.pointer
= NULL
;
396 acpi_ut_remove_reference (buffer_desc
);
398 /* Sanity check the table length */
400 if (table_ptr
->length
< sizeof (struct acpi_table_header
)) {
401 status
= AE_BAD_HEADER
;
408 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
411 /* The table must be either an SSDT or a PSDT */
413 if ((!ACPI_STRNCMP (table_ptr
->signature
,
414 acpi_gbl_table_data
[ACPI_TABLE_PSDT
].signature
,
415 acpi_gbl_table_data
[ACPI_TABLE_PSDT
].sig_length
)) &&
416 (!ACPI_STRNCMP (table_ptr
->signature
,
417 acpi_gbl_table_data
[ACPI_TABLE_SSDT
].signature
,
418 acpi_gbl_table_data
[ACPI_TABLE_SSDT
].sig_length
))) {
419 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
420 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
421 table_ptr
->signature
));
422 status
= AE_BAD_SIGNATURE
;
426 /* Install the new table into the local data structures */
428 status
= acpi_ex_add_table (table_ptr
, acpi_gbl_root_node
, &ddb_handle
);
429 if (ACPI_FAILURE (status
)) {
430 /* On error, table_ptr was deallocated above */
432 return_ACPI_STATUS (status
);
435 /* Store the ddb_handle into the Target operand */
437 status
= acpi_ex_store (ddb_handle
, target
, walk_state
);
438 if (ACPI_FAILURE (status
)) {
439 (void) acpi_ex_unload_table (ddb_handle
);
441 /* table_ptr was deallocated above */
443 return_ACPI_STATUS (status
);
447 if (ACPI_FAILURE (status
)) {
448 ACPI_MEM_FREE (table_ptr
);
450 return_ACPI_STATUS (status
);
454 /*******************************************************************************
456 * FUNCTION: acpi_ex_unload_table
458 * PARAMETERS: ddb_handle - Handle to a previously loaded table
462 * DESCRIPTION: Unload an ACPI table
464 ******************************************************************************/
467 acpi_ex_unload_table (
468 union acpi_operand_object
*ddb_handle
)
470 acpi_status status
= AE_OK
;
471 union acpi_operand_object
*table_desc
= ddb_handle
;
472 struct acpi_table_desc
*table_info
;
475 ACPI_FUNCTION_TRACE ("ex_unload_table");
479 * Validate the handle
480 * Although the handle is partially validated in acpi_ex_reconfiguration(),
481 * when it calls acpi_ex_resolve_operands(), the handle is more completely
485 (ACPI_GET_DESCRIPTOR_TYPE (ddb_handle
) != ACPI_DESC_TYPE_OPERAND
) ||
486 (ACPI_GET_OBJECT_TYPE (ddb_handle
) != ACPI_TYPE_LOCAL_REFERENCE
)) {
487 return_ACPI_STATUS (AE_BAD_PARAMETER
);
490 /* Get the actual table descriptor from the ddb_handle */
492 table_info
= (struct acpi_table_desc
*) table_desc
->reference
.object
;
495 * Delete the entire namespace under this table Node
496 * (Offset contains the table_id)
498 acpi_ns_delete_namespace_by_owner (table_info
->owner_id
);
499 acpi_ut_release_owner_id (&table_info
->owner_id
);
501 /* Delete the table itself */
503 (void) acpi_tb_uninstall_table (table_info
->installed_desc
);
505 /* Delete the table descriptor (ddb_handle) */
507 acpi_ut_remove_reference (table_desc
);
508 return_ACPI_STATUS (status
);