1 /******************************************************************************
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2004, 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
52
53 #define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exconfig")
55
56
57 /*******************************************************************************
58 *
59 * FUNCTION: acpi_ex_add_table
60 *
61 * PARAMETERS: Table - Pointer to raw table
62 * parent_node - Where to load the table (scope)
63 * ddb_handle - Where to return the table handle.
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Common function to Install and Load an ACPI table with a
68 * returned table handle.
69 *
70 ******************************************************************************/
71
72 acpi_status
acpi_ex_add_table(struct acpi_table_header * table,struct acpi_namespace_node * parent_node,union acpi_operand_object ** ddb_handle)73 acpi_ex_add_table (
74 struct acpi_table_header *table,
75 struct acpi_namespace_node *parent_node,
76 union acpi_operand_object **ddb_handle)
77 {
78 acpi_status status;
79 struct acpi_table_desc table_info;
80 union acpi_operand_object *obj_desc;
81
82
83 ACPI_FUNCTION_TRACE ("ex_add_table");
84
85
86 /* Create an object to be the table handle */
87
88 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE);
89 if (!obj_desc) {
90 return_ACPI_STATUS (AE_NO_MEMORY);
91 }
92
93 /* Install the new table into the local data structures */
94
95 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc));
96
97 table_info.type = 5;
98 table_info.pointer = table;
99 table_info.length = (acpi_size) table->length;
100 table_info.allocation = ACPI_MEM_ALLOCATED;
101
102 status = acpi_tb_install_table (&table_info);
103 if (ACPI_FAILURE (status)) {
104 goto cleanup;
105 }
106
107 /* Add the table to the namespace */
108
109 status = acpi_ns_load_table (table_info.installed_desc, parent_node);
110 if (ACPI_FAILURE (status)) {
111 /* Uninstall table on error */
112
113 (void) acpi_tb_uninstall_table (table_info.installed_desc);
114 goto cleanup;
115 }
116
117 /* Init the table handle */
118
119 obj_desc->reference.opcode = AML_LOAD_OP;
120 obj_desc->reference.object = table_info.installed_desc;
121 *ddb_handle = obj_desc;
122 return_ACPI_STATUS (AE_OK);
123
124
125 cleanup:
126 acpi_ut_remove_reference (obj_desc);
127 return_ACPI_STATUS (status);
128 }
129
130
131 /*******************************************************************************
132 *
133 * FUNCTION: acpi_ex_load_table_op
134 *
135 * PARAMETERS: walk_state - Current state with operands
136 * return_desc - Where to store the return object
137 *
138 * RETURN: Status
139 *
140 * DESCRIPTION: Load an ACPI table
141 *
142 ******************************************************************************/
143
144 acpi_status
acpi_ex_load_table_op(struct acpi_walk_state * walk_state,union acpi_operand_object ** return_desc)145 acpi_ex_load_table_op (
146 struct acpi_walk_state *walk_state,
147 union acpi_operand_object **return_desc)
148 {
149 acpi_status status;
150 union acpi_operand_object **operand = &walk_state->operands[0];
151 struct acpi_table_header *table;
152 struct acpi_namespace_node *parent_node;
153 struct acpi_namespace_node *start_node;
154 struct acpi_namespace_node *parameter_node = NULL;
155 union acpi_operand_object *ddb_handle;
156
157
158 ACPI_FUNCTION_TRACE ("ex_load_table_op");
159
160
161 #if 0
162 /*
163 * Make sure that the signature does not match one of the tables that
164 * is already loaded.
165 */
166 status = acpi_tb_match_signature (operand[0]->string.pointer, NULL);
167 if (status == AE_OK) {
168 /* Signature matched -- don't allow override */
169
170 return_ACPI_STATUS (AE_ALREADY_EXISTS);
171 }
172 #endif
173
174 /* Find the ACPI table */
175
176 status = acpi_tb_find_table (operand[0]->string.pointer,
177 operand[1]->string.pointer,
178 operand[2]->string.pointer, &table);
179 if (ACPI_FAILURE (status)) {
180 if (status != AE_NOT_FOUND) {
181 return_ACPI_STATUS (status);
182 }
183
184 /* Table not found, return an Integer=0 and AE_OK */
185
186 ddb_handle = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
187 if (!ddb_handle) {
188 return_ACPI_STATUS (AE_NO_MEMORY);
189 }
190
191 ddb_handle->integer.value = 0;
192 *return_desc = ddb_handle;
193
194 return_ACPI_STATUS (AE_OK);
195 }
196
197 /* Default nodes */
198
199 start_node = walk_state->scope_info->scope.node;
200 parent_node = acpi_gbl_root_node;
201
202 /* root_path (optional parameter) */
203
204 if (operand[3]->string.length > 0) {
205 /*
206 * Find the node referenced by the root_path_string. This is the
207 * location within the namespace where the table will be loaded.
208 */
209 status = acpi_ns_get_node_by_path (operand[3]->string.pointer, start_node,
210 ACPI_NS_SEARCH_PARENT, &parent_node);
211 if (ACPI_FAILURE (status)) {
212 return_ACPI_STATUS (status);
213 }
214 }
215
216 /* parameter_path (optional parameter) */
217
218 if (operand[4]->string.length > 0) {
219 if ((operand[4]->string.pointer[0] != '\\') &&
220 (operand[4]->string.pointer[0] != '^')) {
221 /*
222 * Path is not absolute, so it will be relative to the node
223 * referenced by the root_path_string (or the NS root if omitted)
224 */
225 start_node = parent_node;
226 }
227
228 /*
229 * Find the node referenced by the parameter_path_string
230 */
231 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
232 ACPI_NS_SEARCH_PARENT, ¶meter_node);
233 if (ACPI_FAILURE (status)) {
234 return_ACPI_STATUS (status);
235 }
236 }
237
238 /* Load the table into the namespace */
239
240 status = acpi_ex_add_table (table, parent_node, &ddb_handle);
241 if (ACPI_FAILURE (status)) {
242 return_ACPI_STATUS (status);
243 }
244
245 /* Parameter Data (optional) */
246
247 if (parameter_node) {
248 /* Store the parameter data into the optional parameter object */
249
250 status = acpi_ex_store (operand[5], ACPI_CAST_PTR (union acpi_operand_object, parameter_node),
251 walk_state);
252 if (ACPI_FAILURE (status)) {
253 (void) acpi_ex_unload_table (ddb_handle);
254 return_ACPI_STATUS (status);
255 }
256 }
257
258 *return_desc = ddb_handle;
259 return_ACPI_STATUS (status);
260 }
261
262
263 /*******************************************************************************
264 *
265 * FUNCTION: acpi_ex_load_op
266 *
267 * PARAMETERS: obj_desc - Region or Field where the table will be
268 * obtained
269 * Target - Where a handle to the table will be stored
270 * walk_state - Current state
271 *
272 * RETURN: Status
273 *
274 * DESCRIPTION: Load an ACPI table from a field or operation region
275 *
276 ******************************************************************************/
277
278 acpi_status
acpi_ex_load_op(union acpi_operand_object * obj_desc,union acpi_operand_object * target,struct acpi_walk_state * walk_state)279 acpi_ex_load_op (
280 union acpi_operand_object *obj_desc,
281 union acpi_operand_object *target,
282 struct acpi_walk_state *walk_state)
283 {
284 acpi_status status;
285 union acpi_operand_object *ddb_handle;
286 union acpi_operand_object *buffer_desc = NULL;
287 struct acpi_table_header *table_ptr = NULL;
288 u8 *table_data_ptr;
289 struct acpi_table_header table_header;
290 u32 i;
291
292 ACPI_FUNCTION_TRACE ("ex_load_op");
293
294
295 /* Object can be either an op_region or a Field */
296
297 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
298 case ACPI_TYPE_REGION:
299
300 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
301 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
302
303 /* Get the table header */
304
305 table_header.length = 0;
306 for (i = 0; i < sizeof (struct acpi_table_header); i++) {
307 status = acpi_ev_address_space_dispatch (obj_desc, ACPI_READ,
308 (acpi_physical_address) i, 8,
309 ((u8 *) &table_header) + i);
310 if (ACPI_FAILURE (status)) {
311 return_ACPI_STATUS (status);
312 }
313 }
314
315 /* Allocate a buffer for the entire table */
316
317 table_ptr = ACPI_MEM_ALLOCATE (table_header.length);
318 if (!table_ptr) {
319 return_ACPI_STATUS (AE_NO_MEMORY);
320 }
321
322 /* Copy the header to the buffer */
323
324 ACPI_MEMCPY (table_ptr, &table_header, sizeof (struct acpi_table_header));
325 table_data_ptr = ACPI_PTR_ADD (u8, table_ptr, sizeof (struct acpi_table_header));
326
327 /* Get the table from the op region */
328
329 for (i = 0; i < table_header.length; i++) {
330 status = acpi_ev_address_space_dispatch (obj_desc, ACPI_READ,
331 (acpi_physical_address) i, 8,
332 ((u8 *) table_data_ptr + i));
333 if (ACPI_FAILURE (status)) {
334 goto cleanup;
335 }
336 }
337 break;
338
339
340 case ACPI_TYPE_LOCAL_REGION_FIELD:
341 case ACPI_TYPE_LOCAL_BANK_FIELD:
342 case ACPI_TYPE_LOCAL_INDEX_FIELD:
343
344 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Field %p %s\n",
345 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
346
347 /*
348 * The length of the field must be at least as large as the table.
349 * Read the entire field and thus the entire table. Buffer is
350 * allocated during the read.
351 */
352 status = acpi_ex_read_data_from_field (walk_state, obj_desc, &buffer_desc);
353 if (ACPI_FAILURE (status)) {
354 goto cleanup;
355 }
356
357 table_ptr = ACPI_CAST_PTR (struct acpi_table_header, buffer_desc->buffer.pointer);
358 break;
359
360
361 default:
362 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
363 }
364
365 /* The table must be either an SSDT or a PSDT */
366
367 if ((!ACPI_STRNCMP (table_ptr->signature,
368 acpi_gbl_table_data[ACPI_TABLE_PSDT].signature,
369 acpi_gbl_table_data[ACPI_TABLE_PSDT].sig_length)) &&
370 (!ACPI_STRNCMP (table_ptr->signature,
371 acpi_gbl_table_data[ACPI_TABLE_SSDT].signature,
372 acpi_gbl_table_data[ACPI_TABLE_SSDT].sig_length))) {
373 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
374 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
375 table_ptr->signature));
376 status = AE_BAD_SIGNATURE;
377 goto cleanup;
378 }
379
380 /* Install the new table into the local data structures */
381
382 status = acpi_ex_add_table (table_ptr, acpi_gbl_root_node, &ddb_handle);
383 if (ACPI_FAILURE (status)) {
384 goto cleanup;
385 }
386
387 /* Store the ddb_handle into the Target operand */
388
389 status = acpi_ex_store (ddb_handle, target, walk_state);
390 if (ACPI_FAILURE (status)) {
391 (void) acpi_ex_unload_table (ddb_handle);
392 }
393
394 return_ACPI_STATUS (status);
395
396
397 cleanup:
398
399 if (buffer_desc) {
400 acpi_ut_remove_reference (buffer_desc);
401 }
402 else {
403 ACPI_MEM_FREE (table_ptr);
404 }
405 return_ACPI_STATUS (status);
406 }
407
408
409 /*******************************************************************************
410 *
411 * FUNCTION: acpi_ex_unload_table
412 *
413 * PARAMETERS: ddb_handle - Handle to a previously loaded table
414 *
415 * RETURN: Status
416 *
417 * DESCRIPTION: Unload an ACPI table
418 *
419 ******************************************************************************/
420
421 acpi_status
acpi_ex_unload_table(union acpi_operand_object * ddb_handle)422 acpi_ex_unload_table (
423 union acpi_operand_object *ddb_handle)
424 {
425 acpi_status status = AE_OK;
426 union acpi_operand_object *table_desc = ddb_handle;
427 struct acpi_table_desc *table_info;
428
429
430 ACPI_FUNCTION_TRACE ("ex_unload_table");
431
432
433 /*
434 * Validate the handle
435 * Although the handle is partially validated in acpi_ex_reconfiguration(),
436 * when it calls acpi_ex_resolve_operands(), the handle is more completely
437 * validated here.
438 */
439 if ((!ddb_handle) ||
440 (ACPI_GET_DESCRIPTOR_TYPE (ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
441 (ACPI_GET_OBJECT_TYPE (ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) {
442 return_ACPI_STATUS (AE_BAD_PARAMETER);
443 }
444
445 /* Get the actual table descriptor from the ddb_handle */
446
447 table_info = (struct acpi_table_desc *) table_desc->reference.object;
448
449 /*
450 * Delete the entire namespace under this table Node
451 * (Offset contains the table_id)
452 */
453 acpi_ns_delete_namespace_by_owner (table_info->table_id);
454
455 /* Delete the table itself */
456
457 (void) acpi_tb_uninstall_table (table_info->installed_desc);
458
459 /* Delete the table descriptor (ddb_handle) */
460
461 acpi_ut_remove_reference (table_desc);
462 return_ACPI_STATUS (status);
463 }
464
465