Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbinstal - ACPI table installation and removal | |
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/actables.h> | |
47 | ||
48 | ||
49 | #define _COMPONENT ACPI_TABLES | |
50 | ACPI_MODULE_NAME ("tbinstal") | |
51 | ||
44f6c012 RM |
52 | /* Local prototypes */ |
53 | ||
54 | static acpi_status | |
55 | acpi_tb_match_signature ( | |
56 | char *signature, | |
57 | struct acpi_table_desc *table_info, | |
58 | u8 search_type); | |
59 | ||
1da177e4 LT |
60 | |
61 | /******************************************************************************* | |
62 | * | |
63 | * FUNCTION: acpi_tb_match_signature | |
64 | * | |
65 | * PARAMETERS: Signature - Table signature to match | |
66 | * table_info - Return data | |
44f6c012 | 67 | * search_type - Table type to match (primary/secondary) |
1da177e4 LT |
68 | * |
69 | * RETURN: Status | |
70 | * | |
71 | * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned" | |
72 | * tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match. | |
73 | * | |
74 | ******************************************************************************/ | |
75 | ||
44f6c012 | 76 | static acpi_status |
1da177e4 LT |
77 | acpi_tb_match_signature ( |
78 | char *signature, | |
79 | struct acpi_table_desc *table_info, | |
80 | u8 search_type) | |
81 | { | |
82 | acpi_native_uint i; | |
83 | ||
84 | ||
85 | ACPI_FUNCTION_TRACE ("tb_match_signature"); | |
86 | ||
87 | ||
44f6c012 RM |
88 | /* Search for a signature match among the known table types */ |
89 | ||
1da177e4 LT |
90 | for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) { |
91 | if (!(acpi_gbl_table_data[i].flags & search_type)) { | |
92 | continue; | |
93 | } | |
94 | ||
95 | if (!ACPI_STRNCMP (signature, acpi_gbl_table_data[i].signature, | |
96 | acpi_gbl_table_data[i].sig_length)) { | |
97 | /* Found a signature match, return index if requested */ | |
98 | ||
99 | if (table_info) { | |
100 | table_info->type = (u8) i; | |
101 | } | |
102 | ||
103 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
104 | "Table [%4.4s] is an ACPI table consumed by the core subsystem\n", | |
105 | (char *) acpi_gbl_table_data[i].signature)); | |
106 | ||
107 | return_ACPI_STATUS (AE_OK); | |
108 | } | |
109 | } | |
110 | ||
111 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
112 | "Table [%4.4s] is not an ACPI table consumed by the core subsystem - ignored\n", | |
113 | (char *) signature)); | |
114 | ||
115 | return_ACPI_STATUS (AE_TABLE_NOT_SUPPORTED); | |
116 | } | |
117 | ||
118 | ||
119 | /******************************************************************************* | |
120 | * | |
121 | * FUNCTION: acpi_tb_install_table | |
122 | * | |
123 | * PARAMETERS: table_info - Return value from acpi_tb_get_table_body | |
124 | * | |
125 | * RETURN: Status | |
126 | * | |
0c9938cc | 127 | * DESCRIPTION: Install the table into the global data structures. |
1da177e4 LT |
128 | * |
129 | ******************************************************************************/ | |
130 | ||
131 | acpi_status | |
132 | acpi_tb_install_table ( | |
133 | struct acpi_table_desc *table_info) | |
134 | { | |
135 | acpi_status status; | |
136 | ||
0c9938cc | 137 | |
1da177e4 LT |
138 | ACPI_FUNCTION_TRACE ("tb_install_table"); |
139 | ||
140 | ||
141 | /* Lock tables while installing */ | |
142 | ||
143 | status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES); | |
144 | if (ACPI_FAILURE (status)) { | |
0c9938cc RM |
145 | ACPI_REPORT_ERROR (("Could not acquire table mutex, %s\n", |
146 | acpi_format_exception (status))); | |
1da177e4 LT |
147 | return_ACPI_STATUS (status); |
148 | } | |
149 | ||
0c9938cc RM |
150 | /* |
151 | * Ignore a table that is already installed. For example, some BIOS | |
152 | * ASL code will repeatedly attempt to load the same SSDT. | |
153 | */ | |
154 | status = acpi_tb_is_table_installed (table_info); | |
155 | if (ACPI_FAILURE (status)) { | |
156 | goto unlock_and_exit; | |
157 | } | |
158 | ||
1da177e4 LT |
159 | /* Install the table into the global data structure */ |
160 | ||
161 | status = acpi_tb_init_table_descriptor (table_info->type, table_info); | |
162 | if (ACPI_FAILURE (status)) { | |
0c9938cc | 163 | ACPI_REPORT_ERROR (("Could not install table [%4.4s], %s\n", |
1da177e4 LT |
164 | table_info->pointer->signature, acpi_format_exception (status))); |
165 | } | |
166 | ||
167 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s located at %p\n", | |
168 | acpi_gbl_table_data[table_info->type].name, table_info->pointer)); | |
169 | ||
0c9938cc RM |
170 | |
171 | unlock_and_exit: | |
1da177e4 LT |
172 | (void) acpi_ut_release_mutex (ACPI_MTX_TABLES); |
173 | return_ACPI_STATUS (status); | |
174 | } | |
175 | ||
176 | ||
177 | /******************************************************************************* | |
178 | * | |
179 | * FUNCTION: acpi_tb_recognize_table | |
180 | * | |
181 | * PARAMETERS: table_info - Return value from acpi_tb_get_table_body | |
44f6c012 | 182 | * search_type - Table type to match (primary/secondary) |
1da177e4 LT |
183 | * |
184 | * RETURN: Status | |
185 | * | |
186 | * DESCRIPTION: Check a table signature for a match against known table types | |
187 | * | |
188 | * NOTE: All table pointers are validated as follows: | |
189 | * 1) Table pointer must point to valid physical memory | |
190 | * 2) Signature must be 4 ASCII chars, even if we don't recognize the | |
191 | * name | |
192 | * 3) Table must be readable for length specified in the header | |
193 | * 4) Table checksum must be valid (with the exception of the FACS | |
194 | * which has no checksum for some odd reason) | |
195 | * | |
196 | ******************************************************************************/ | |
197 | ||
198 | acpi_status | |
199 | acpi_tb_recognize_table ( | |
200 | struct acpi_table_desc *table_info, | |
201 | u8 search_type) | |
202 | { | |
203 | struct acpi_table_header *table_header; | |
204 | acpi_status status; | |
205 | ||
206 | ||
207 | ACPI_FUNCTION_TRACE ("tb_recognize_table"); | |
208 | ||
209 | ||
210 | /* Ensure that we have a valid table pointer */ | |
211 | ||
212 | table_header = (struct acpi_table_header *) table_info->pointer; | |
213 | if (!table_header) { | |
214 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
215 | } | |
216 | ||
217 | /* | |
218 | * We only "recognize" a limited number of ACPI tables -- namely, the | |
219 | * ones that are used by the subsystem (DSDT, FADT, etc.) | |
220 | * | |
221 | * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized. | |
222 | * This can be any one of many valid ACPI tables, it just isn't one of | |
223 | * the tables that is consumed by the core subsystem | |
224 | */ | |
44f6c012 RM |
225 | status = acpi_tb_match_signature (table_header->signature, |
226 | table_info, search_type); | |
1da177e4 LT |
227 | if (ACPI_FAILURE (status)) { |
228 | return_ACPI_STATUS (status); | |
229 | } | |
230 | ||
231 | status = acpi_tb_validate_table_header (table_header); | |
232 | if (ACPI_FAILURE (status)) { | |
233 | return_ACPI_STATUS (status); | |
234 | } | |
235 | ||
236 | /* Return the table type and length via the info struct */ | |
237 | ||
238 | table_info->length = (acpi_size) table_header->length; | |
239 | ||
240 | return_ACPI_STATUS (status); | |
241 | } | |
242 | ||
243 | ||
244 | /******************************************************************************* | |
245 | * | |
246 | * FUNCTION: acpi_tb_init_table_descriptor | |
247 | * | |
248 | * PARAMETERS: table_type - The type of the table | |
249 | * table_info - A table info struct | |
250 | * | |
251 | * RETURN: None. | |
252 | * | |
253 | * DESCRIPTION: Install a table into the global data structs. | |
254 | * | |
255 | ******************************************************************************/ | |
256 | ||
257 | acpi_status | |
258 | acpi_tb_init_table_descriptor ( | |
259 | acpi_table_type table_type, | |
260 | struct acpi_table_desc *table_info) | |
261 | { | |
262 | struct acpi_table_list *list_head; | |
263 | struct acpi_table_desc *table_desc; | |
f9f4601f | 264 | acpi_status status; |
1da177e4 LT |
265 | |
266 | ||
267 | ACPI_FUNCTION_TRACE_U32 ("tb_init_table_descriptor", table_type); | |
268 | ||
269 | ||
270 | /* Allocate a descriptor for this table */ | |
271 | ||
272 | table_desc = ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc)); | |
273 | if (!table_desc) { | |
274 | return_ACPI_STATUS (AE_NO_MEMORY); | |
275 | } | |
276 | ||
f9f4601f RM |
277 | /* Get a new owner ID for the table */ |
278 | ||
279 | status = acpi_ut_allocate_owner_id (&table_desc->owner_id); | |
280 | if (ACPI_FAILURE (status)) { | |
281 | return_ACPI_STATUS (status); | |
282 | } | |
283 | ||
44f6c012 RM |
284 | /* Install the table into the global data structure */ |
285 | ||
1da177e4 LT |
286 | list_head = &acpi_gbl_table_lists[table_type]; |
287 | ||
288 | /* | |
289 | * Two major types of tables: 1) Only one instance is allowed. This | |
290 | * includes most ACPI tables such as the DSDT. 2) Multiple instances of | |
291 | * the table are allowed. This includes SSDT and PSDTs. | |
292 | */ | |
293 | if (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags)) { | |
294 | /* | |
295 | * Only one table allowed, and a table has alread been installed | |
296 | * at this location, so return an error. | |
297 | */ | |
298 | if (list_head->next) { | |
299 | ACPI_MEM_FREE (table_desc); | |
300 | return_ACPI_STATUS (AE_ALREADY_EXISTS); | |
301 | } | |
302 | ||
303 | table_desc->next = list_head->next; | |
304 | list_head->next = table_desc; | |
305 | ||
306 | if (table_desc->next) { | |
307 | table_desc->next->prev = table_desc; | |
308 | } | |
309 | ||
310 | list_head->count++; | |
311 | } | |
312 | else { | |
313 | /* | |
314 | * Link the new table in to the list of tables of this type. | |
315 | * Insert at the end of the list, order IS IMPORTANT. | |
316 | * | |
317 | * table_desc->Prev & Next are already NULL from calloc() | |
318 | */ | |
319 | list_head->count++; | |
320 | ||
321 | if (!list_head->next) { | |
322 | list_head->next = table_desc; | |
323 | } | |
324 | else { | |
325 | table_desc->next = list_head->next; | |
326 | ||
327 | while (table_desc->next->next) { | |
328 | table_desc->next = table_desc->next->next; | |
329 | } | |
330 | ||
331 | table_desc->next->next = table_desc; | |
332 | table_desc->prev = table_desc->next; | |
333 | table_desc->next = NULL; | |
334 | } | |
335 | } | |
336 | ||
337 | /* Finish initialization of the table descriptor */ | |
338 | ||
339 | table_desc->type = (u8) table_type; | |
340 | table_desc->pointer = table_info->pointer; | |
341 | table_desc->length = table_info->length; | |
342 | table_desc->allocation = table_info->allocation; | |
343 | table_desc->aml_start = (u8 *) (table_desc->pointer + 1), | |
344 | table_desc->aml_length = (u32) (table_desc->length - | |
345 | (u32) sizeof (struct acpi_table_header)); | |
1da177e4 LT |
346 | table_desc->loaded_into_namespace = FALSE; |
347 | ||
348 | /* | |
349 | * Set the appropriate global pointer (if there is one) to point to the | |
350 | * newly installed table | |
351 | */ | |
352 | if (acpi_gbl_table_data[table_type].global_ptr) { | |
353 | *(acpi_gbl_table_data[table_type].global_ptr) = table_info->pointer; | |
354 | } | |
355 | ||
356 | /* Return Data */ | |
357 | ||
f9f4601f | 358 | table_info->owner_id = table_desc->owner_id; |
1da177e4 LT |
359 | table_info->installed_desc = table_desc; |
360 | ||
361 | return_ACPI_STATUS (AE_OK); | |
362 | } | |
363 | ||
364 | ||
365 | /******************************************************************************* | |
366 | * | |
367 | * FUNCTION: acpi_tb_delete_all_tables | |
368 | * | |
369 | * PARAMETERS: None. | |
370 | * | |
371 | * RETURN: None. | |
372 | * | |
373 | * DESCRIPTION: Delete all internal ACPI tables | |
374 | * | |
375 | ******************************************************************************/ | |
376 | ||
377 | void | |
44f6c012 RM |
378 | acpi_tb_delete_all_tables ( |
379 | void) | |
1da177e4 LT |
380 | { |
381 | acpi_table_type type; | |
382 | ||
383 | ||
384 | /* | |
385 | * Free memory allocated for ACPI tables | |
386 | * Memory can either be mapped or allocated | |
387 | */ | |
388 | for (type = 0; type < NUM_ACPI_TABLE_TYPES; type++) { | |
389 | acpi_tb_delete_tables_by_type (type); | |
390 | } | |
391 | } | |
392 | ||
393 | ||
394 | /******************************************************************************* | |
395 | * | |
396 | * FUNCTION: acpi_tb_delete_tables_by_type | |
397 | * | |
398 | * PARAMETERS: Type - The table type to be deleted | |
399 | * | |
400 | * RETURN: None. | |
401 | * | |
402 | * DESCRIPTION: Delete an internal ACPI table | |
403 | * Locks the ACPI table mutex | |
404 | * | |
405 | ******************************************************************************/ | |
406 | ||
407 | void | |
408 | acpi_tb_delete_tables_by_type ( | |
409 | acpi_table_type type) | |
410 | { | |
411 | struct acpi_table_desc *table_desc; | |
412 | u32 count; | |
413 | u32 i; | |
414 | ||
415 | ||
416 | ACPI_FUNCTION_TRACE_U32 ("tb_delete_tables_by_type", type); | |
417 | ||
418 | ||
419 | if (type > ACPI_TABLE_MAX) { | |
420 | return_VOID; | |
421 | } | |
422 | ||
423 | if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_TABLES))) { | |
424 | return; | |
425 | } | |
426 | ||
427 | /* Clear the appropriate "typed" global table pointer */ | |
428 | ||
429 | switch (type) { | |
430 | case ACPI_TABLE_RSDP: | |
431 | acpi_gbl_RSDP = NULL; | |
432 | break; | |
433 | ||
434 | case ACPI_TABLE_DSDT: | |
435 | acpi_gbl_DSDT = NULL; | |
436 | break; | |
437 | ||
438 | case ACPI_TABLE_FADT: | |
439 | acpi_gbl_FADT = NULL; | |
440 | break; | |
441 | ||
442 | case ACPI_TABLE_FACS: | |
443 | acpi_gbl_FACS = NULL; | |
444 | break; | |
445 | ||
446 | case ACPI_TABLE_XSDT: | |
447 | acpi_gbl_XSDT = NULL; | |
448 | break; | |
449 | ||
450 | case ACPI_TABLE_SSDT: | |
451 | case ACPI_TABLE_PSDT: | |
452 | default: | |
453 | break; | |
454 | } | |
455 | ||
456 | /* | |
457 | * Free the table | |
458 | * 1) Get the head of the list | |
459 | */ | |
460 | table_desc = acpi_gbl_table_lists[type].next; | |
461 | count = acpi_gbl_table_lists[type].count; | |
462 | ||
463 | /* | |
464 | * 2) Walk the entire list, deleting both the allocated tables | |
465 | * and the table descriptors | |
466 | */ | |
467 | for (i = 0; i < count; i++) { | |
468 | table_desc = acpi_tb_uninstall_table (table_desc); | |
469 | } | |
470 | ||
471 | (void) acpi_ut_release_mutex (ACPI_MTX_TABLES); | |
472 | return_VOID; | |
473 | } | |
474 | ||
475 | ||
476 | /******************************************************************************* | |
477 | * | |
478 | * FUNCTION: acpi_tb_delete_single_table | |
479 | * | |
480 | * PARAMETERS: table_info - A table info struct | |
481 | * | |
482 | * RETURN: None. | |
483 | * | |
484 | * DESCRIPTION: Low-level free for a single ACPI table. Handles cases where | |
485 | * the table was allocated a buffer or was mapped. | |
486 | * | |
487 | ******************************************************************************/ | |
488 | ||
489 | void | |
490 | acpi_tb_delete_single_table ( | |
491 | struct acpi_table_desc *table_desc) | |
492 | { | |
493 | ||
494 | /* Must have a valid table descriptor and pointer */ | |
495 | ||
496 | if ((!table_desc) || | |
497 | (!table_desc->pointer)) { | |
498 | return; | |
499 | } | |
500 | ||
501 | /* Valid table, determine type of memory allocation */ | |
502 | ||
503 | switch (table_desc->allocation) { | |
504 | case ACPI_MEM_NOT_ALLOCATED: | |
505 | break; | |
506 | ||
507 | case ACPI_MEM_ALLOCATED: | |
508 | ||
509 | ACPI_MEM_FREE (table_desc->pointer); | |
510 | break; | |
511 | ||
512 | case ACPI_MEM_MAPPED: | |
513 | ||
514 | acpi_os_unmap_memory (table_desc->pointer, table_desc->length); | |
515 | break; | |
516 | ||
517 | default: | |
518 | break; | |
519 | } | |
520 | } | |
521 | ||
522 | ||
523 | /******************************************************************************* | |
524 | * | |
525 | * FUNCTION: acpi_tb_uninstall_table | |
526 | * | |
527 | * PARAMETERS: table_info - A table info struct | |
528 | * | |
529 | * RETURN: Pointer to the next table in the list (of same type) | |
530 | * | |
531 | * DESCRIPTION: Free the memory associated with an internal ACPI table that | |
532 | * is either installed or has never been installed. | |
533 | * Table mutex should be locked. | |
534 | * | |
535 | ******************************************************************************/ | |
536 | ||
537 | struct acpi_table_desc * | |
538 | acpi_tb_uninstall_table ( | |
539 | struct acpi_table_desc *table_desc) | |
540 | { | |
541 | struct acpi_table_desc *next_desc; | |
542 | ||
543 | ||
544 | ACPI_FUNCTION_TRACE_PTR ("tb_uninstall_table", table_desc); | |
545 | ||
546 | ||
547 | if (!table_desc) { | |
548 | return_PTR (NULL); | |
549 | } | |
550 | ||
551 | /* Unlink the descriptor from the doubly linked list */ | |
552 | ||
553 | if (table_desc->prev) { | |
554 | table_desc->prev->next = table_desc->next; | |
555 | } | |
556 | else { | |
557 | /* Is first on list, update list head */ | |
558 | ||
559 | acpi_gbl_table_lists[table_desc->type].next = table_desc->next; | |
560 | } | |
561 | ||
562 | if (table_desc->next) { | |
563 | table_desc->next->prev = table_desc->prev; | |
564 | } | |
565 | ||
566 | /* Free the memory allocated for the table itself */ | |
567 | ||
568 | acpi_tb_delete_single_table (table_desc); | |
569 | ||
570 | /* Free the table descriptor */ | |
571 | ||
572 | next_desc = table_desc->next; | |
573 | ACPI_MEM_FREE (table_desc); | |
574 | ||
575 | /* Return pointer to the next descriptor */ | |
576 | ||
577 | return_PTR (next_desc); | |
578 | } | |
579 | ||
580 |