[ACPI] ACPICA 20050729 from Bob Moore
[deliverable/linux.git] / drivers / acpi / executer / exconfig.c
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 /* Local prototypes */
58
59 static acpi_status
60 acpi_ex_add_table (
61 struct acpi_table_header *table,
62 struct acpi_namespace_node *parent_node,
63 union acpi_operand_object **ddb_handle);
64
65
66 /*******************************************************************************
67 *
68 * FUNCTION: acpi_ex_add_table
69 *
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.
73 *
74 * RETURN: Status
75 *
76 * DESCRIPTION: Common function to Install and Load an ACPI table with a
77 * returned table handle.
78 *
79 ******************************************************************************/
80
81 static acpi_status
82 acpi_ex_add_table (
83 struct acpi_table_header *table,
84 struct acpi_namespace_node *parent_node,
85 union acpi_operand_object **ddb_handle)
86 {
87 acpi_status status;
88 struct acpi_table_desc table_info;
89 union acpi_operand_object *obj_desc;
90
91
92 ACPI_FUNCTION_TRACE ("ex_add_table");
93
94
95 /* Create an object to be the table handle */
96
97 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE);
98 if (!obj_desc) {
99 return_ACPI_STATUS (AE_NO_MEMORY);
100 }
101
102 /* Init the table handle */
103
104 obj_desc->reference.opcode = AML_LOAD_OP;
105 *ddb_handle = obj_desc;
106
107 /* Install the new table into the local data structures */
108
109 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc));
110
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;
115
116 status = acpi_tb_install_table (&table_info);
117 obj_desc->reference.object = table_info.installed_desc;
118
119 if (ACPI_FAILURE (status)) {
120 if (status == AE_ALREADY_EXISTS) {
121 /* Table already exists, just return the handle */
122
123 return_ACPI_STATUS (AE_OK);
124 }
125 goto cleanup;
126 }
127
128 /* Add the table to the namespace */
129
130 status = acpi_ns_load_table (table_info.installed_desc, parent_node);
131 if (ACPI_FAILURE (status)) {
132 /* Uninstall table on error */
133
134 (void) acpi_tb_uninstall_table (table_info.installed_desc);
135 goto cleanup;
136 }
137
138 return_ACPI_STATUS (AE_OK);
139
140
141 cleanup:
142 acpi_ut_remove_reference (obj_desc);
143 *ddb_handle = NULL;
144 return_ACPI_STATUS (status);
145 }
146
147
148 /*******************************************************************************
149 *
150 * FUNCTION: acpi_ex_load_table_op
151 *
152 * PARAMETERS: walk_state - Current state with operands
153 * return_desc - Where to store the return object
154 *
155 * RETURN: Status
156 *
157 * DESCRIPTION: Load an ACPI table
158 *
159 ******************************************************************************/
160
161 acpi_status
162 acpi_ex_load_table_op (
163 struct acpi_walk_state *walk_state,
164 union acpi_operand_object **return_desc)
165 {
166 acpi_status status;
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;
173
174
175 ACPI_FUNCTION_TRACE ("ex_load_table_op");
176
177
178 #if 0
179 /*
180 * Make sure that the signature does not match one of the tables that
181 * is already loaded.
182 */
183 status = acpi_tb_match_signature (operand[0]->string.pointer, NULL);
184 if (status == AE_OK) {
185 /* Signature matched -- don't allow override */
186
187 return_ACPI_STATUS (AE_ALREADY_EXISTS);
188 }
189 #endif
190
191 /* Find the ACPI table */
192
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);
199 }
200
201 /* Table not found, return an Integer=0 and AE_OK */
202
203 ddb_handle = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
204 if (!ddb_handle) {
205 return_ACPI_STATUS (AE_NO_MEMORY);
206 }
207
208 ddb_handle->integer.value = 0;
209 *return_desc = ddb_handle;
210
211 return_ACPI_STATUS (AE_OK);
212 }
213
214 /* Default nodes */
215
216 start_node = walk_state->scope_info->scope.node;
217 parent_node = acpi_gbl_root_node;
218
219 /* root_path (optional parameter) */
220
221 if (operand[3]->string.length > 0) {
222 /*
223 * Find the node referenced by the root_path_string. This is the
224 * location within the namespace where the table will be loaded.
225 */
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);
230 }
231 }
232
233 /* parameter_path (optional parameter) */
234
235 if (operand[4]->string.length > 0) {
236 if ((operand[4]->string.pointer[0] != '\\') &&
237 (operand[4]->string.pointer[0] != '^')) {
238 /*
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)
241 */
242 start_node = parent_node;
243 }
244
245 /* Find the node referenced by the parameter_path_string */
246
247 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
248 ACPI_NS_SEARCH_PARENT, &parameter_node);
249 if (ACPI_FAILURE (status)) {
250 return_ACPI_STATUS (status);
251 }
252 }
253
254 /* Load the table into the namespace */
255
256 status = acpi_ex_add_table (table, parent_node, &ddb_handle);
257 if (ACPI_FAILURE (status)) {
258 return_ACPI_STATUS (status);
259 }
260
261 /* Parameter Data (optional) */
262
263 if (parameter_node) {
264 /* Store the parameter data into the optional parameter object */
265
266 status = acpi_ex_store (operand[5],
267 ACPI_CAST_PTR (union acpi_operand_object, parameter_node),
268 walk_state);
269 if (ACPI_FAILURE (status)) {
270 (void) acpi_ex_unload_table (ddb_handle);
271 return_ACPI_STATUS (status);
272 }
273 }
274
275 *return_desc = ddb_handle;
276 return_ACPI_STATUS (status);
277 }
278
279
280 /*******************************************************************************
281 *
282 * FUNCTION: acpi_ex_load_op
283 *
284 * PARAMETERS: obj_desc - Region or Field where the table will be
285 * obtained
286 * Target - Where a handle to the table will be stored
287 * walk_state - Current state
288 *
289 * RETURN: Status
290 *
291 * DESCRIPTION: Load an ACPI table from a field or operation region
292 *
293 ******************************************************************************/
294
295 acpi_status
296 acpi_ex_load_op (
297 union acpi_operand_object *obj_desc,
298 union acpi_operand_object *target,
299 struct acpi_walk_state *walk_state)
300 {
301 acpi_status status;
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;
307 u32 i;
308
309 ACPI_FUNCTION_TRACE ("ex_load_op");
310
311
312 /* Object can be either an op_region or a Field */
313
314 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
315 case ACPI_TYPE_REGION:
316
317 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
318 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
319
320 /*
321 * If the Region Address and Length have not been previously evaluated,
322 * evaluate them now and save the results.
323 */
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);
328 }
329 }
330
331 /* Get the base physical address of the region */
332
333 address = obj_desc->region.address;
334
335 /* Get the table length from the table header */
336
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);
344 }
345 }
346
347 /* Sanity check the table length */
348
349 if (table_header.length < sizeof (struct acpi_table_header)) {
350 return_ACPI_STATUS (AE_BAD_HEADER);
351 }
352
353 /* Allocate a buffer for the entire table */
354
355 table_ptr = ACPI_MEM_ALLOCATE (table_header.length);
356 if (!table_ptr) {
357 return_ACPI_STATUS (AE_NO_MEMORY);
358 }
359
360 /* Get the entire table from the op region */
361
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)) {
367 goto cleanup;
368 }
369 }
370 break;
371
372
373 case ACPI_TYPE_LOCAL_REGION_FIELD:
374 case ACPI_TYPE_LOCAL_BANK_FIELD:
375 case ACPI_TYPE_LOCAL_INDEX_FIELD:
376
377 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Field %p %s\n",
378 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
379
380 /*
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.
384 */
385 status = acpi_ex_read_data_from_field (walk_state, obj_desc, &buffer_desc);
386 if (ACPI_FAILURE (status)) {
387 return_ACPI_STATUS (status);
388 }
389
390 table_ptr = ACPI_CAST_PTR (struct acpi_table_header,
391 buffer_desc->buffer.pointer);
392
393 /* All done with the buffer_desc, delete it */
394
395 buffer_desc->buffer.pointer = NULL;
396 acpi_ut_remove_reference (buffer_desc);
397
398 /* Sanity check the table length */
399
400 if (table_ptr->length < sizeof (struct acpi_table_header)) {
401 status = AE_BAD_HEADER;
402 goto cleanup;
403 }
404 break;
405
406
407 default:
408 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
409 }
410
411 /* The table must be either an SSDT or a PSDT */
412
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;
423 goto cleanup;
424 }
425
426 /* Install the new table into the local data structures */
427
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 */
431
432 return_ACPI_STATUS (status);
433 }
434
435 /* Store the ddb_handle into the Target operand */
436
437 status = acpi_ex_store (ddb_handle, target, walk_state);
438 if (ACPI_FAILURE (status)) {
439 (void) acpi_ex_unload_table (ddb_handle);
440
441 /* table_ptr was deallocated above */
442
443 return_ACPI_STATUS (status);
444 }
445
446 cleanup:
447 if (ACPI_FAILURE (status)) {
448 ACPI_MEM_FREE (table_ptr);
449 }
450 return_ACPI_STATUS (status);
451 }
452
453
454 /*******************************************************************************
455 *
456 * FUNCTION: acpi_ex_unload_table
457 *
458 * PARAMETERS: ddb_handle - Handle to a previously loaded table
459 *
460 * RETURN: Status
461 *
462 * DESCRIPTION: Unload an ACPI table
463 *
464 ******************************************************************************/
465
466 acpi_status
467 acpi_ex_unload_table (
468 union acpi_operand_object *ddb_handle)
469 {
470 acpi_status status = AE_OK;
471 union acpi_operand_object *table_desc = ddb_handle;
472 struct acpi_table_desc *table_info;
473
474
475 ACPI_FUNCTION_TRACE ("ex_unload_table");
476
477
478 /*
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
482 * validated here.
483 */
484 if ((!ddb_handle) ||
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);
488 }
489
490 /* Get the actual table descriptor from the ddb_handle */
491
492 table_info = (struct acpi_table_desc *) table_desc->reference.object;
493
494 /*
495 * Delete the entire namespace under this table Node
496 * (Offset contains the table_id)
497 */
498 acpi_ns_delete_namespace_by_owner (table_info->owner_id);
499 acpi_ut_release_owner_id (&table_info->owner_id);
500
501 /* Delete the table itself */
502
503 (void) acpi_tb_uninstall_table (table_info->installed_desc);
504
505 /* Delete the table descriptor (ddb_handle) */
506
507 acpi_ut_remove_reference (table_desc);
508 return_ACPI_STATUS (status);
509 }
510
This page took 0.067728 seconds and 6 git commands to generate.