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 /* Install the new table into the local data structures */
104 ACPI_MEMSET (&table_info
, 0, sizeof (struct acpi_table_desc
));
106 table_info
.type
= ACPI_TABLE_SSDT
;
107 table_info
.pointer
= table
;
108 table_info
.length
= (acpi_size
) table
->length
;
109 table_info
.allocation
= ACPI_MEM_ALLOCATED
;
111 status
= acpi_tb_install_table (&table_info
);
112 if (ACPI_FAILURE (status
)) {
116 /* Add the table to the namespace */
118 status
= acpi_ns_load_table (table_info
.installed_desc
, parent_node
);
119 if (ACPI_FAILURE (status
)) {
120 /* Uninstall table on error */
122 (void) acpi_tb_uninstall_table (table_info
.installed_desc
);
126 /* Init the table handle */
128 obj_desc
->reference
.opcode
= AML_LOAD_OP
;
129 obj_desc
->reference
.object
= table_info
.installed_desc
;
130 *ddb_handle
= obj_desc
;
131 return_ACPI_STATUS (AE_OK
);
135 acpi_ut_remove_reference (obj_desc
);
136 return_ACPI_STATUS (status
);
140 /*******************************************************************************
142 * FUNCTION: acpi_ex_load_table_op
144 * PARAMETERS: walk_state - Current state with operands
145 * return_desc - Where to store the return object
149 * DESCRIPTION: Load an ACPI table
151 ******************************************************************************/
154 acpi_ex_load_table_op (
155 struct acpi_walk_state
*walk_state
,
156 union acpi_operand_object
**return_desc
)
159 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
160 struct acpi_table_header
*table
;
161 struct acpi_namespace_node
*parent_node
;
162 struct acpi_namespace_node
*start_node
;
163 struct acpi_namespace_node
*parameter_node
= NULL
;
164 union acpi_operand_object
*ddb_handle
;
167 ACPI_FUNCTION_TRACE ("ex_load_table_op");
172 * Make sure that the signature does not match one of the tables that
175 status
= acpi_tb_match_signature (operand
[0]->string
.pointer
, NULL
);
176 if (status
== AE_OK
) {
177 /* Signature matched -- don't allow override */
179 return_ACPI_STATUS (AE_ALREADY_EXISTS
);
183 /* Find the ACPI table */
185 status
= acpi_tb_find_table (operand
[0]->string
.pointer
,
186 operand
[1]->string
.pointer
,
187 operand
[2]->string
.pointer
, &table
);
188 if (ACPI_FAILURE (status
)) {
189 if (status
!= AE_NOT_FOUND
) {
190 return_ACPI_STATUS (status
);
193 /* Table not found, return an Integer=0 and AE_OK */
195 ddb_handle
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
197 return_ACPI_STATUS (AE_NO_MEMORY
);
200 ddb_handle
->integer
.value
= 0;
201 *return_desc
= ddb_handle
;
203 return_ACPI_STATUS (AE_OK
);
208 start_node
= walk_state
->scope_info
->scope
.node
;
209 parent_node
= acpi_gbl_root_node
;
211 /* root_path (optional parameter) */
213 if (operand
[3]->string
.length
> 0) {
215 * Find the node referenced by the root_path_string. This is the
216 * location within the namespace where the table will be loaded.
218 status
= acpi_ns_get_node_by_path (operand
[3]->string
.pointer
, start_node
,
219 ACPI_NS_SEARCH_PARENT
, &parent_node
);
220 if (ACPI_FAILURE (status
)) {
221 return_ACPI_STATUS (status
);
225 /* parameter_path (optional parameter) */
227 if (operand
[4]->string
.length
> 0) {
228 if ((operand
[4]->string
.pointer
[0] != '\\') &&
229 (operand
[4]->string
.pointer
[0] != '^')) {
231 * Path is not absolute, so it will be relative to the node
232 * referenced by the root_path_string (or the NS root if omitted)
234 start_node
= parent_node
;
237 /* Find the node referenced by the parameter_path_string */
239 status
= acpi_ns_get_node_by_path (operand
[4]->string
.pointer
, start_node
,
240 ACPI_NS_SEARCH_PARENT
, ¶meter_node
);
241 if (ACPI_FAILURE (status
)) {
242 return_ACPI_STATUS (status
);
246 /* Load the table into the namespace */
248 status
= acpi_ex_add_table (table
, parent_node
, &ddb_handle
);
249 if (ACPI_FAILURE (status
)) {
250 return_ACPI_STATUS (status
);
253 /* Parameter Data (optional) */
255 if (parameter_node
) {
256 /* Store the parameter data into the optional parameter object */
258 status
= acpi_ex_store (operand
[5],
259 ACPI_CAST_PTR (union acpi_operand_object
, parameter_node
),
261 if (ACPI_FAILURE (status
)) {
262 (void) acpi_ex_unload_table (ddb_handle
);
263 return_ACPI_STATUS (status
);
267 *return_desc
= ddb_handle
;
268 return_ACPI_STATUS (status
);
272 /*******************************************************************************
274 * FUNCTION: acpi_ex_load_op
276 * PARAMETERS: obj_desc - Region or Field where the table will be
278 * Target - Where a handle to the table will be stored
279 * walk_state - Current state
283 * DESCRIPTION: Load an ACPI table from a field or operation region
285 ******************************************************************************/
289 union acpi_operand_object
*obj_desc
,
290 union acpi_operand_object
*target
,
291 struct acpi_walk_state
*walk_state
)
294 union acpi_operand_object
*ddb_handle
;
295 union acpi_operand_object
*buffer_desc
= NULL
;
296 struct acpi_table_header
*table_ptr
= NULL
;
297 acpi_physical_address address
;
298 struct acpi_table_header table_header
;
301 ACPI_FUNCTION_TRACE ("ex_load_op");
304 /* Object can be either an op_region or a Field */
306 switch (ACPI_GET_OBJECT_TYPE (obj_desc
)) {
307 case ACPI_TYPE_REGION
:
309 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Load from Region %p %s\n",
310 obj_desc
, acpi_ut_get_object_type_name (obj_desc
)));
313 * If the Region Address and Length have not been previously evaluated,
314 * evaluate them now and save the results.
316 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
317 status
= acpi_ds_get_region_arguments (obj_desc
);
318 if (ACPI_FAILURE (status
)) {
319 return_ACPI_STATUS (status
);
323 /* Get the base physical address of the region */
325 address
= obj_desc
->region
.address
;
327 /* Get the table length from the table header */
329 table_header
.length
= 0;
330 for (i
= 0; i
< 8; i
++) {
331 status
= acpi_ev_address_space_dispatch (obj_desc
, ACPI_READ
,
332 (acpi_physical_address
) (i
+ address
), 8,
333 ((u8
*) &table_header
) + i
);
334 if (ACPI_FAILURE (status
)) {
335 return_ACPI_STATUS (status
);
339 /* Sanity check the table length */
341 if (table_header
.length
< sizeof (struct acpi_table_header
)) {
342 return_ACPI_STATUS (AE_BAD_HEADER
);
345 /* Allocate a buffer for the entire table */
347 table_ptr
= ACPI_MEM_ALLOCATE (table_header
.length
);
349 return_ACPI_STATUS (AE_NO_MEMORY
);
352 /* Get the entire table from the op region */
354 for (i
= 0; i
< table_header
.length
; i
++) {
355 status
= acpi_ev_address_space_dispatch (obj_desc
, ACPI_READ
,
356 (acpi_physical_address
) (i
+ address
), 8,
357 ((u8
*) table_ptr
+ i
));
358 if (ACPI_FAILURE (status
)) {
365 case ACPI_TYPE_LOCAL_REGION_FIELD
:
366 case ACPI_TYPE_LOCAL_BANK_FIELD
:
367 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
369 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Load from Field %p %s\n",
370 obj_desc
, acpi_ut_get_object_type_name (obj_desc
)));
373 * The length of the field must be at least as large as the table.
374 * Read the entire field and thus the entire table. Buffer is
375 * allocated during the read.
377 status
= acpi_ex_read_data_from_field (walk_state
, obj_desc
, &buffer_desc
);
378 if (ACPI_FAILURE (status
)) {
379 return_ACPI_STATUS (status
);
382 table_ptr
= ACPI_CAST_PTR (struct acpi_table_header
,
383 buffer_desc
->buffer
.pointer
);
385 /* All done with the buffer_desc, delete it */
387 buffer_desc
->buffer
.pointer
= NULL
;
388 acpi_ut_remove_reference (buffer_desc
);
390 /* Sanity check the table length */
392 if (table_ptr
->length
< sizeof (struct acpi_table_header
)) {
393 status
= AE_BAD_HEADER
;
400 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
403 /* The table must be either an SSDT or a PSDT */
405 if ((!ACPI_STRNCMP (table_ptr
->signature
,
406 acpi_gbl_table_data
[ACPI_TABLE_PSDT
].signature
,
407 acpi_gbl_table_data
[ACPI_TABLE_PSDT
].sig_length
)) &&
408 (!ACPI_STRNCMP (table_ptr
->signature
,
409 acpi_gbl_table_data
[ACPI_TABLE_SSDT
].signature
,
410 acpi_gbl_table_data
[ACPI_TABLE_SSDT
].sig_length
))) {
411 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
412 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
413 table_ptr
->signature
));
414 status
= AE_BAD_SIGNATURE
;
418 /* Install the new table into the local data structures */
420 status
= acpi_ex_add_table (table_ptr
, acpi_gbl_root_node
, &ddb_handle
);
421 if (ACPI_FAILURE (status
)) {
422 /* On error, table_ptr was deallocated above */
424 return_ACPI_STATUS (status
);
427 /* Store the ddb_handle into the Target operand */
429 status
= acpi_ex_store (ddb_handle
, target
, walk_state
);
430 if (ACPI_FAILURE (status
)) {
431 (void) acpi_ex_unload_table (ddb_handle
);
433 /* table_ptr was deallocated above */
435 return_ACPI_STATUS (status
);
439 if (ACPI_FAILURE (status
)) {
440 ACPI_MEM_FREE (table_ptr
);
442 return_ACPI_STATUS (status
);
446 /*******************************************************************************
448 * FUNCTION: acpi_ex_unload_table
450 * PARAMETERS: ddb_handle - Handle to a previously loaded table
454 * DESCRIPTION: Unload an ACPI table
456 ******************************************************************************/
459 acpi_ex_unload_table (
460 union acpi_operand_object
*ddb_handle
)
462 acpi_status status
= AE_OK
;
463 union acpi_operand_object
*table_desc
= ddb_handle
;
464 struct acpi_table_desc
*table_info
;
467 ACPI_FUNCTION_TRACE ("ex_unload_table");
471 * Validate the handle
472 * Although the handle is partially validated in acpi_ex_reconfiguration(),
473 * when it calls acpi_ex_resolve_operands(), the handle is more completely
477 (ACPI_GET_DESCRIPTOR_TYPE (ddb_handle
) != ACPI_DESC_TYPE_OPERAND
) ||
478 (ACPI_GET_OBJECT_TYPE (ddb_handle
) != ACPI_TYPE_LOCAL_REFERENCE
)) {
479 return_ACPI_STATUS (AE_BAD_PARAMETER
);
482 /* Get the actual table descriptor from the ddb_handle */
484 table_info
= (struct acpi_table_desc
*) table_desc
->reference
.object
;
487 * Delete the entire namespace under this table Node
488 * (Offset contains the table_id)
490 acpi_ns_delete_namespace_by_owner (table_info
->owner_id
);
492 /* Delete the table itself */
494 (void) acpi_tb_uninstall_table (table_info
->installed_desc
);
496 /* Delete the table descriptor (ddb_handle) */
498 acpi_ut_remove_reference (table_desc
);
499 return_ACPI_STATUS (status
);