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")
58 /*******************************************************************************
60 * FUNCTION: acpi_ex_add_table
62 * PARAMETERS: Table - Pointer to raw table
63 * parent_node - Where to load the table (scope)
64 * ddb_handle - Where to return the table handle.
68 * DESCRIPTION: Common function to Install and Load an ACPI table with a
69 * returned table handle.
71 ******************************************************************************/
75 struct acpi_table_header
*table
,
76 struct acpi_namespace_node
*parent_node
,
77 union acpi_operand_object
**ddb_handle
)
80 struct acpi_table_desc table_info
;
81 union acpi_operand_object
*obj_desc
;
84 ACPI_FUNCTION_TRACE ("ex_add_table");
87 /* Create an object to be the table handle */
89 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE
);
91 return_ACPI_STATUS (AE_NO_MEMORY
);
94 /* Install the new table into the local data structures */
96 ACPI_MEMSET (&table_info
, 0, sizeof (struct acpi_table_desc
));
98 table_info
.type
= ACPI_TABLE_SSDT
;
99 table_info
.pointer
= table
;
100 table_info
.length
= (acpi_size
) table
->length
;
101 table_info
.allocation
= ACPI_MEM_ALLOCATED
;
103 status
= acpi_tb_install_table (&table_info
);
104 if (ACPI_FAILURE (status
)) {
108 /* Add the table to the namespace */
110 status
= acpi_ns_load_table (table_info
.installed_desc
, parent_node
);
111 if (ACPI_FAILURE (status
)) {
112 /* Uninstall table on error */
114 (void) acpi_tb_uninstall_table (table_info
.installed_desc
);
118 /* Init the table handle */
120 obj_desc
->reference
.opcode
= AML_LOAD_OP
;
121 obj_desc
->reference
.object
= table_info
.installed_desc
;
122 *ddb_handle
= obj_desc
;
123 return_ACPI_STATUS (AE_OK
);
127 acpi_ut_remove_reference (obj_desc
);
128 return_ACPI_STATUS (status
);
132 /*******************************************************************************
134 * FUNCTION: acpi_ex_load_table_op
136 * PARAMETERS: walk_state - Current state with operands
137 * return_desc - Where to store the return object
141 * DESCRIPTION: Load an ACPI table
143 ******************************************************************************/
146 acpi_ex_load_table_op (
147 struct acpi_walk_state
*walk_state
,
148 union acpi_operand_object
**return_desc
)
151 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
152 struct acpi_table_header
*table
;
153 struct acpi_namespace_node
*parent_node
;
154 struct acpi_namespace_node
*start_node
;
155 struct acpi_namespace_node
*parameter_node
= NULL
;
156 union acpi_operand_object
*ddb_handle
;
159 ACPI_FUNCTION_TRACE ("ex_load_table_op");
164 * Make sure that the signature does not match one of the tables that
167 status
= acpi_tb_match_signature (operand
[0]->string
.pointer
, NULL
);
168 if (status
== AE_OK
) {
169 /* Signature matched -- don't allow override */
171 return_ACPI_STATUS (AE_ALREADY_EXISTS
);
175 /* Find the ACPI table */
177 status
= acpi_tb_find_table (operand
[0]->string
.pointer
,
178 operand
[1]->string
.pointer
,
179 operand
[2]->string
.pointer
, &table
);
180 if (ACPI_FAILURE (status
)) {
181 if (status
!= AE_NOT_FOUND
) {
182 return_ACPI_STATUS (status
);
185 /* Table not found, return an Integer=0 and AE_OK */
187 ddb_handle
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
189 return_ACPI_STATUS (AE_NO_MEMORY
);
192 ddb_handle
->integer
.value
= 0;
193 *return_desc
= ddb_handle
;
195 return_ACPI_STATUS (AE_OK
);
200 start_node
= walk_state
->scope_info
->scope
.node
;
201 parent_node
= acpi_gbl_root_node
;
203 /* root_path (optional parameter) */
205 if (operand
[3]->string
.length
> 0) {
207 * Find the node referenced by the root_path_string. This is the
208 * location within the namespace where the table will be loaded.
210 status
= acpi_ns_get_node_by_path (operand
[3]->string
.pointer
, start_node
,
211 ACPI_NS_SEARCH_PARENT
, &parent_node
);
212 if (ACPI_FAILURE (status
)) {
213 return_ACPI_STATUS (status
);
217 /* parameter_path (optional parameter) */
219 if (operand
[4]->string
.length
> 0) {
220 if ((operand
[4]->string
.pointer
[0] != '\\') &&
221 (operand
[4]->string
.pointer
[0] != '^')) {
223 * Path is not absolute, so it will be relative to the node
224 * referenced by the root_path_string (or the NS root if omitted)
226 start_node
= parent_node
;
230 * Find the node referenced by the parameter_path_string
232 status
= acpi_ns_get_node_by_path (operand
[4]->string
.pointer
, start_node
,
233 ACPI_NS_SEARCH_PARENT
, ¶meter_node
);
234 if (ACPI_FAILURE (status
)) {
235 return_ACPI_STATUS (status
);
239 /* Load the table into the namespace */
241 status
= acpi_ex_add_table (table
, parent_node
, &ddb_handle
);
242 if (ACPI_FAILURE (status
)) {
243 return_ACPI_STATUS (status
);
246 /* Parameter Data (optional) */
248 if (parameter_node
) {
249 /* Store the parameter data into the optional parameter object */
251 status
= acpi_ex_store (operand
[5], ACPI_CAST_PTR (union acpi_operand_object
, parameter_node
),
253 if (ACPI_FAILURE (status
)) {
254 (void) acpi_ex_unload_table (ddb_handle
);
255 return_ACPI_STATUS (status
);
259 *return_desc
= ddb_handle
;
260 return_ACPI_STATUS (status
);
264 /*******************************************************************************
266 * FUNCTION: acpi_ex_load_op
268 * PARAMETERS: obj_desc - Region or Field where the table will be
270 * Target - Where a handle to the table will be stored
271 * walk_state - Current state
275 * DESCRIPTION: Load an ACPI table from a field or operation region
277 ******************************************************************************/
281 union acpi_operand_object
*obj_desc
,
282 union acpi_operand_object
*target
,
283 struct acpi_walk_state
*walk_state
)
286 union acpi_operand_object
*ddb_handle
;
287 union acpi_operand_object
*buffer_desc
= NULL
;
288 struct acpi_table_header
*table_ptr
= NULL
;
289 acpi_physical_address address
;
290 struct acpi_table_header table_header
;
293 ACPI_FUNCTION_TRACE ("ex_load_op");
296 /* Object can be either an op_region or a Field */
298 switch (ACPI_GET_OBJECT_TYPE (obj_desc
)) {
299 case ACPI_TYPE_REGION
:
301 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Load from Region %p %s\n",
302 obj_desc
, acpi_ut_get_object_type_name (obj_desc
)));
305 * If the Region Address and Length have not been previously evaluated,
306 * evaluate them now and save the results.
308 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
309 status
= acpi_ds_get_region_arguments (obj_desc
);
310 if (ACPI_FAILURE (status
)) {
311 return_ACPI_STATUS (status
);
315 /* Get the base physical address of the region */
317 address
= obj_desc
->region
.address
;
319 /* Get the table length from the table header */
321 table_header
.length
= 0;
322 for (i
= 0; i
< 8; i
++) {
323 status
= acpi_ev_address_space_dispatch (obj_desc
, ACPI_READ
,
324 (acpi_physical_address
) (i
+ address
), 8,
325 ((u8
*) &table_header
) + i
);
326 if (ACPI_FAILURE (status
)) {
327 return_ACPI_STATUS (status
);
331 /* Sanity check the table length */
333 if (table_header
.length
< sizeof (struct acpi_table_header
)) {
334 return_ACPI_STATUS (AE_BAD_HEADER
);
337 /* Allocate a buffer for the entire table */
339 table_ptr
= ACPI_MEM_ALLOCATE (table_header
.length
);
341 return_ACPI_STATUS (AE_NO_MEMORY
);
344 /* Get the entire table from the op region */
346 for (i
= 0; i
< table_header
.length
; i
++) {
347 status
= acpi_ev_address_space_dispatch (obj_desc
, ACPI_READ
,
348 (acpi_physical_address
) (i
+ address
), 8,
349 ((u8
*) table_ptr
+ i
));
350 if (ACPI_FAILURE (status
)) {
357 case ACPI_TYPE_LOCAL_REGION_FIELD
:
358 case ACPI_TYPE_LOCAL_BANK_FIELD
:
359 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
361 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Load from Field %p %s\n",
362 obj_desc
, acpi_ut_get_object_type_name (obj_desc
)));
365 * The length of the field must be at least as large as the table.
366 * Read the entire field and thus the entire table. Buffer is
367 * allocated during the read.
369 status
= acpi_ex_read_data_from_field (walk_state
, obj_desc
, &buffer_desc
);
370 if (ACPI_FAILURE (status
)) {
374 table_ptr
= ACPI_CAST_PTR (struct acpi_table_header
, buffer_desc
->buffer
.pointer
);
376 /* Sanity check the table length */
378 if (table_ptr
->length
< sizeof (struct acpi_table_header
)) {
379 return_ACPI_STATUS (AE_BAD_HEADER
);
385 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
388 /* The table must be either an SSDT or a PSDT */
390 if ((!ACPI_STRNCMP (table_ptr
->signature
,
391 acpi_gbl_table_data
[ACPI_TABLE_PSDT
].signature
,
392 acpi_gbl_table_data
[ACPI_TABLE_PSDT
].sig_length
)) &&
393 (!ACPI_STRNCMP (table_ptr
->signature
,
394 acpi_gbl_table_data
[ACPI_TABLE_SSDT
].signature
,
395 acpi_gbl_table_data
[ACPI_TABLE_SSDT
].sig_length
))) {
396 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
397 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
398 table_ptr
->signature
));
399 status
= AE_BAD_SIGNATURE
;
403 /* Install the new table into the local data structures */
405 status
= acpi_ex_add_table (table_ptr
, acpi_gbl_root_node
, &ddb_handle
);
406 if (ACPI_FAILURE (status
)) {
410 /* Store the ddb_handle into the Target operand */
412 status
= acpi_ex_store (ddb_handle
, target
, walk_state
);
413 if (ACPI_FAILURE (status
)) {
414 (void) acpi_ex_unload_table (ddb_handle
);
417 return_ACPI_STATUS (status
);
423 acpi_ut_remove_reference (buffer_desc
);
426 ACPI_MEM_FREE (table_ptr
);
428 return_ACPI_STATUS (status
);
432 /*******************************************************************************
434 * FUNCTION: acpi_ex_unload_table
436 * PARAMETERS: ddb_handle - Handle to a previously loaded table
440 * DESCRIPTION: Unload an ACPI table
442 ******************************************************************************/
445 acpi_ex_unload_table (
446 union acpi_operand_object
*ddb_handle
)
448 acpi_status status
= AE_OK
;
449 union acpi_operand_object
*table_desc
= ddb_handle
;
450 struct acpi_table_desc
*table_info
;
453 ACPI_FUNCTION_TRACE ("ex_unload_table");
457 * Validate the handle
458 * Although the handle is partially validated in acpi_ex_reconfiguration(),
459 * when it calls acpi_ex_resolve_operands(), the handle is more completely
463 (ACPI_GET_DESCRIPTOR_TYPE (ddb_handle
) != ACPI_DESC_TYPE_OPERAND
) ||
464 (ACPI_GET_OBJECT_TYPE (ddb_handle
) != ACPI_TYPE_LOCAL_REFERENCE
)) {
465 return_ACPI_STATUS (AE_BAD_PARAMETER
);
468 /* Get the actual table descriptor from the ddb_handle */
470 table_info
= (struct acpi_table_desc
*) table_desc
->reference
.object
;
473 * Delete the entire namespace under this table Node
474 * (Offset contains the table_id)
476 acpi_ns_delete_namespace_by_owner (table_info
->table_id
);
478 /* Delete the table itself */
480 (void) acpi_tb_uninstall_table (table_info
->installed_desc
);
482 /* Delete the table descriptor (ddb_handle) */
484 acpi_ut_remove_reference (table_desc
);
485 return_ACPI_STATUS (status
);