aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/executer/exconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/executer/exconfig.c')
-rw-r--r--drivers/acpi/executer/exconfig.c487
1 files changed, 487 insertions, 0 deletions
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
new file mode 100644
index 000000000000..ac3c061967f2
--- /dev/null
+++ b/drivers/acpi/executer/exconfig.c
@@ -0,0 +1,487 @@
1/******************************************************************************
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44
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>
52
53
54#define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exconfig")
56
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ex_add_table
61 *
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.
65 *
66 * RETURN: Status
67 *
68 * DESCRIPTION: Common function to Install and Load an ACPI table with a
69 * returned table handle.
70 *
71 ******************************************************************************/
72
73acpi_status
74acpi_ex_add_table (
75 struct acpi_table_header *table,
76 struct acpi_namespace_node *parent_node,
77 union acpi_operand_object **ddb_handle)
78{
79 acpi_status status;
80 struct acpi_table_desc table_info;
81 union acpi_operand_object *obj_desc;
82
83
84 ACPI_FUNCTION_TRACE ("ex_add_table");
85
86
87 /* Create an object to be the table handle */
88
89 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE);
90 if (!obj_desc) {
91 return_ACPI_STATUS (AE_NO_MEMORY);
92 }
93
94 /* Install the new table into the local data structures */
95
96 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc));
97
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;
102
103 status = acpi_tb_install_table (&table_info);
104 if (ACPI_FAILURE (status)) {
105 goto cleanup;
106 }
107
108 /* Add the table to the namespace */
109
110 status = acpi_ns_load_table (table_info.installed_desc, parent_node);
111 if (ACPI_FAILURE (status)) {
112 /* Uninstall table on error */
113
114 (void) acpi_tb_uninstall_table (table_info.installed_desc);
115 goto cleanup;
116 }
117
118 /* Init the table handle */
119
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);
124
125
126cleanup:
127 acpi_ut_remove_reference (obj_desc);
128 return_ACPI_STATUS (status);
129}
130
131
132/*******************************************************************************
133 *
134 * FUNCTION: acpi_ex_load_table_op
135 *
136 * PARAMETERS: walk_state - Current state with operands
137 * return_desc - Where to store the return object
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Load an ACPI table
142 *
143 ******************************************************************************/
144
145acpi_status
146acpi_ex_load_table_op (
147 struct acpi_walk_state *walk_state,
148 union acpi_operand_object **return_desc)
149{
150 acpi_status status;
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;
157
158
159 ACPI_FUNCTION_TRACE ("ex_load_table_op");
160
161
162#if 0
163 /*
164 * Make sure that the signature does not match one of the tables that
165 * is already loaded.
166 */
167 status = acpi_tb_match_signature (operand[0]->string.pointer, NULL);
168 if (status == AE_OK) {
169 /* Signature matched -- don't allow override */
170
171 return_ACPI_STATUS (AE_ALREADY_EXISTS);
172 }
173#endif
174
175 /* Find the ACPI table */
176
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);
183 }
184
185 /* Table not found, return an Integer=0 and AE_OK */
186
187 ddb_handle = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
188 if (!ddb_handle) {
189 return_ACPI_STATUS (AE_NO_MEMORY);
190 }
191
192 ddb_handle->integer.value = 0;
193 *return_desc = ddb_handle;
194
195 return_ACPI_STATUS (AE_OK);
196 }
197
198 /* Default nodes */
199
200 start_node = walk_state->scope_info->scope.node;
201 parent_node = acpi_gbl_root_node;
202
203 /* root_path (optional parameter) */
204
205 if (operand[3]->string.length > 0) {
206 /*
207 * Find the node referenced by the root_path_string. This is the
208 * location within the namespace where the table will be loaded.
209 */
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);
214 }
215 }
216
217 /* parameter_path (optional parameter) */
218
219 if (operand[4]->string.length > 0) {
220 if ((operand[4]->string.pointer[0] != '\\') &&
221 (operand[4]->string.pointer[0] != '^')) {
222 /*
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)
225 */
226 start_node = parent_node;
227 }
228
229 /*
230 * Find the node referenced by the parameter_path_string
231 */
232 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
233 ACPI_NS_SEARCH_PARENT, &parameter_node);
234 if (ACPI_FAILURE (status)) {
235 return_ACPI_STATUS (status);
236 }
237 }
238
239 /* Load the table into the namespace */
240
241 status = acpi_ex_add_table (table, parent_node, &ddb_handle);
242 if (ACPI_FAILURE (status)) {
243 return_ACPI_STATUS (status);
244 }
245
246 /* Parameter Data (optional) */
247
248 if (parameter_node) {
249 /* Store the parameter data into the optional parameter object */
250
251 status = acpi_ex_store (operand[5], ACPI_CAST_PTR (union acpi_operand_object, parameter_node),
252 walk_state);
253 if (ACPI_FAILURE (status)) {
254 (void) acpi_ex_unload_table (ddb_handle);
255 return_ACPI_STATUS (status);
256 }
257 }
258
259 *return_desc = ddb_handle;
260 return_ACPI_STATUS (status);
261}
262
263
264/*******************************************************************************
265 *
266 * FUNCTION: acpi_ex_load_op
267 *
268 * PARAMETERS: obj_desc - Region or Field where the table will be
269 * obtained
270 * Target - Where a handle to the table will be stored
271 * walk_state - Current state
272 *
273 * RETURN: Status
274 *
275 * DESCRIPTION: Load an ACPI table from a field or operation region
276 *
277 ******************************************************************************/
278
279acpi_status
280acpi_ex_load_op (
281 union acpi_operand_object *obj_desc,
282 union acpi_operand_object *target,
283 struct acpi_walk_state *walk_state)
284{
285 acpi_status status;
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;
291 u32 i;
292
293 ACPI_FUNCTION_TRACE ("ex_load_op");
294
295
296 /* Object can be either an op_region or a Field */
297
298 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
299 case ACPI_TYPE_REGION:
300
301 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
302 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
303
304 /*
305 * If the Region Address and Length have not been previously evaluated,
306 * evaluate them now and save the results.
307 */
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);
312 }
313 }
314
315 /* Get the base physical address of the region */
316
317 address = obj_desc->region.address;
318
319 /* Get the table length from the table header */
320
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);
328 }
329 }
330
331 /* Sanity check the table length */
332
333 if (table_header.length < sizeof (struct acpi_table_header)) {
334 return_ACPI_STATUS (AE_BAD_HEADER);
335 }
336
337 /* Allocate a buffer for the entire table */
338
339 table_ptr = ACPI_MEM_ALLOCATE (table_header.length);
340 if (!table_ptr) {
341 return_ACPI_STATUS (AE_NO_MEMORY);
342 }
343
344 /* Get the entire table from the op region */
345
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)) {
351 goto cleanup;
352 }
353 }
354 break;
355
356
357 case ACPI_TYPE_LOCAL_REGION_FIELD:
358 case ACPI_TYPE_LOCAL_BANK_FIELD:
359 case ACPI_TYPE_LOCAL_INDEX_FIELD:
360
361 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Field %p %s\n",
362 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
363
364 /*
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.
368 */
369 status = acpi_ex_read_data_from_field (walk_state, obj_desc, &buffer_desc);
370 if (ACPI_FAILURE (status)) {
371 goto cleanup;
372 }
373
374 table_ptr = ACPI_CAST_PTR (struct acpi_table_header, buffer_desc->buffer.pointer);
375
376 /* Sanity check the table length */
377
378 if (table_ptr->length < sizeof (struct acpi_table_header)) {
379 return_ACPI_STATUS (AE_BAD_HEADER);
380 }
381 break;
382
383
384 default:
385 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
386 }
387
388 /* The table must be either an SSDT or a PSDT */
389
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;
400 goto cleanup;
401 }
402
403 /* Install the new table into the local data structures */
404
405 status = acpi_ex_add_table (table_ptr, acpi_gbl_root_node, &ddb_handle);
406 if (ACPI_FAILURE (status)) {
407 goto cleanup;
408 }
409
410 /* Store the ddb_handle into the Target operand */
411
412 status = acpi_ex_store (ddb_handle, target, walk_state);
413 if (ACPI_FAILURE (status)) {
414 (void) acpi_ex_unload_table (ddb_handle);
415 }
416
417 return_ACPI_STATUS (status);
418
419
420cleanup:
421
422 if (buffer_desc) {
423 acpi_ut_remove_reference (buffer_desc);
424 }
425 else {
426 ACPI_MEM_FREE (table_ptr);
427 }
428 return_ACPI_STATUS (status);
429}
430
431
432/*******************************************************************************
433 *
434 * FUNCTION: acpi_ex_unload_table
435 *
436 * PARAMETERS: ddb_handle - Handle to a previously loaded table
437 *
438 * RETURN: Status
439 *
440 * DESCRIPTION: Unload an ACPI table
441 *
442 ******************************************************************************/
443
444acpi_status
445acpi_ex_unload_table (
446 union acpi_operand_object *ddb_handle)
447{
448 acpi_status status = AE_OK;
449 union acpi_operand_object *table_desc = ddb_handle;
450 struct acpi_table_desc *table_info;
451
452
453 ACPI_FUNCTION_TRACE ("ex_unload_table");
454
455
456 /*
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
460 * validated here.
461 */
462 if ((!ddb_handle) ||
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);
466 }
467
468 /* Get the actual table descriptor from the ddb_handle */
469
470 table_info = (struct acpi_table_desc *) table_desc->reference.object;
471
472 /*
473 * Delete the entire namespace under this table Node
474 * (Offset contains the table_id)
475 */
476 acpi_ns_delete_namespace_by_owner (table_info->table_id);
477
478 /* Delete the table itself */
479
480 (void) acpi_tb_uninstall_table (table_info->installed_desc);
481
482 /* Delete the table descriptor (ddb_handle) */
483
484 acpi_ut_remove_reference (table_desc);
485 return_ACPI_STATUS (status);
486}
487