1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, Intel Corp.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
46 #include <acpi/actables.h>
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME("tbinstal")
51 /******************************************************************************
53 * FUNCTION: acpi_tb_verify_table
55 * PARAMETERS: table_desc - table
59 * DESCRIPTION: this function is called to verify and map table
61 *****************************************************************************/
62 acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
64 acpi_status status = AE_OK;
66 ACPI_FUNCTION_TRACE(tb_verify_table);
68 /* Map the table if necessary */
70 if (!table_desc->pointer) {
71 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
72 ACPI_TABLE_ORIGIN_MAPPED) {
74 acpi_os_map_memory(table_desc->address,
77 if (!table_desc->pointer) {
78 return_ACPI_STATUS(AE_NO_MEMORY);
82 /* FACS is the odd table, has no standard ACPI header and no checksum */
84 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
86 /* Always calculate checksum, ignore bad checksum if requested */
89 acpi_tb_verify_checksum(table_desc->pointer,
93 return_ACPI_STATUS(status);
96 /*******************************************************************************
98 * FUNCTION: acpi_tb_add_table
100 * PARAMETERS: table_desc - Table descriptor
101 * table_index - Where the table index is returned
105 * DESCRIPTION: This function is called to add the ACPI table
107 ******************************************************************************/
110 acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
113 acpi_status status = AE_OK;
115 ACPI_FUNCTION_TRACE(tb_add_table);
117 if (!table_desc->pointer) {
118 status = acpi_tb_verify_table(table_desc);
119 if (ACPI_FAILURE(status) || !table_desc->pointer) {
120 return_ACPI_STATUS(status);
125 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
126 * Next, we added support for OEMx tables, signature "OEM".
127 * Valid tables were encountered with a null signature, so we've just
128 * given up on validating the signature, since it seems to be a waste
129 * of code. The original code was removed (05/2008).
132 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
134 /* Check if table is already registered */
136 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
137 if (!acpi_gbl_root_table_list.tables[i].pointer) {
139 acpi_tb_verify_table(&acpi_gbl_root_table_list.
141 if (ACPI_FAILURE(status)
142 || !acpi_gbl_root_table_list.tables[i].pointer) {
148 * Check for a table match on the entire table length,
149 * not just the header.
151 if (table_desc->length !=
152 acpi_gbl_root_table_list.tables[i].length) {
156 if (ACPI_MEMCMP(table_desc->pointer,
157 acpi_gbl_root_table_list.tables[i].pointer,
158 acpi_gbl_root_table_list.tables[i].length)) {
163 * Note: the current mechanism does not unregister a table if it is
164 * dynamically unloaded. The related namespace entries are deleted,
165 * but the table remains in the root table list.
167 * The assumption here is that the number of different tables that
168 * will be loaded is actually small, and there is minimal overhead
169 * in just keeping the table in case it is needed again.
171 * If this assumption changes in the future (perhaps on large
172 * machines with many table load/unload operations), tables will
173 * need to be unregistered when they are unloaded, and slots in the
174 * root table list should be reused when empty.
178 * Table is already registered.
179 * We can delete the table that was passed as a parameter.
181 acpi_tb_delete_table(table_desc);
184 if (acpi_gbl_root_table_list.tables[i].
185 flags & ACPI_TABLE_IS_LOADED) {
187 /* Table is still loaded, this is an error */
189 status = AE_ALREADY_EXISTS;
192 /* Table was unloaded, allow it to be reloaded */
194 table_desc->pointer =
195 acpi_gbl_root_table_list.tables[i].pointer;
196 table_desc->address =
197 acpi_gbl_root_table_list.tables[i].address;
203 /* Add the table to the global root table list */
205 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
206 table_desc->length, table_desc->flags,
208 if (ACPI_FAILURE(status)) {
213 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
216 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
217 return_ACPI_STATUS(status);
220 /*******************************************************************************
222 * FUNCTION: acpi_tb_resize_root_table_list
228 * DESCRIPTION: Expand the size of global table array
230 ******************************************************************************/
232 acpi_status acpi_tb_resize_root_table_list(void)
234 struct acpi_table_desc *tables;
236 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
238 /* allow_resize flag is a parameter to acpi_initialize_tables */
240 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
242 "Resize of Root Table Array is not allowed"));
243 return_ACPI_STATUS(AE_SUPPORT);
246 /* Increase the Table Array size */
248 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
249 size + ACPI_ROOT_TABLE_SIZE_INCREMENT)
250 * sizeof(struct acpi_table_desc));
253 "Could not allocate new root table array"));
254 return_ACPI_STATUS(AE_NO_MEMORY);
257 /* Copy and free the previous table array */
259 if (acpi_gbl_root_table_list.tables) {
260 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
261 (acpi_size) acpi_gbl_root_table_list.size *
262 sizeof(struct acpi_table_desc));
264 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
265 ACPI_FREE(acpi_gbl_root_table_list.tables);
269 acpi_gbl_root_table_list.tables = tables;
270 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
271 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
273 return_ACPI_STATUS(AE_OK);
276 /*******************************************************************************
278 * FUNCTION: acpi_tb_store_table
280 * PARAMETERS: Address - Table address
281 * Table - Table header
282 * Length - Table length
285 * RETURN: Status and table index.
287 * DESCRIPTION: Add an ACPI table to the global table list
289 ******************************************************************************/
292 acpi_tb_store_table(acpi_physical_address address,
293 struct acpi_table_header *table,
294 u32 length, u8 flags, u32 *table_index)
296 acpi_status status = AE_OK;
298 /* Ensure that there is room for the table in the Root Table List */
300 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
301 status = acpi_tb_resize_root_table_list();
302 if (ACPI_FAILURE(status)) {
307 /* Initialize added table */
309 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
311 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
313 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
315 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
317 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
321 (acpi_gbl_root_table_list.
322 tables[acpi_gbl_root_table_list.count].signature),
325 *table_index = acpi_gbl_root_table_list.count;
326 acpi_gbl_root_table_list.count++;
330 /*******************************************************************************
332 * FUNCTION: acpi_tb_delete_table
334 * PARAMETERS: table_index - Table index
338 * DESCRIPTION: Delete one internal ACPI table
340 ******************************************************************************/
342 void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
344 /* Table must be mapped or allocated */
345 if (!table_desc->pointer) {
348 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
349 case ACPI_TABLE_ORIGIN_MAPPED:
350 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
352 case ACPI_TABLE_ORIGIN_ALLOCATED:
353 ACPI_FREE(table_desc->pointer);
358 table_desc->pointer = NULL;
361 /*******************************************************************************
363 * FUNCTION: acpi_tb_terminate
369 * DESCRIPTION: Delete all internal ACPI tables
371 ******************************************************************************/
373 void acpi_tb_terminate(void)
377 ACPI_FUNCTION_TRACE(tb_terminate);
379 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
381 /* Delete the individual tables */
383 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
384 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
388 * Delete the root table array if allocated locally. Array cannot be
389 * mapped, so we don't need to check for that flag.
391 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
392 ACPI_FREE(acpi_gbl_root_table_list.tables);
395 acpi_gbl_root_table_list.tables = NULL;
396 acpi_gbl_root_table_list.flags = 0;
397 acpi_gbl_root_table_list.count = 0;
399 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
400 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
403 /*******************************************************************************
405 * FUNCTION: acpi_tb_delete_namespace_by_owner
407 * PARAMETERS: table_index - Table index
411 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
413 ******************************************************************************/
415 void acpi_tb_delete_namespace_by_owner(u32 table_index)
417 acpi_owner_id owner_id;
419 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
420 if (table_index < acpi_gbl_root_table_list.count) {
422 acpi_gbl_root_table_list.tables[table_index].owner_id;
424 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
428 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
429 acpi_ns_delete_namespace_by_owner(owner_id);
432 /*******************************************************************************
434 * FUNCTION: acpi_tb_allocate_owner_id
436 * PARAMETERS: table_index - Table index
440 * DESCRIPTION: Allocates owner_id in table_desc
442 ******************************************************************************/
444 acpi_status acpi_tb_allocate_owner_id(u32 table_index)
446 acpi_status status = AE_BAD_PARAMETER;
448 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
450 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
451 if (table_index < acpi_gbl_root_table_list.count) {
452 status = acpi_ut_allocate_owner_id
453 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
456 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
457 return_ACPI_STATUS(status);
460 /*******************************************************************************
462 * FUNCTION: acpi_tb_release_owner_id
464 * PARAMETERS: table_index - Table index
468 * DESCRIPTION: Releases owner_id in table_desc
470 ******************************************************************************/
472 acpi_status acpi_tb_release_owner_id(u32 table_index)
474 acpi_status status = AE_BAD_PARAMETER;
476 ACPI_FUNCTION_TRACE(tb_release_owner_id);
478 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
479 if (table_index < acpi_gbl_root_table_list.count) {
480 acpi_ut_release_owner_id(&
481 (acpi_gbl_root_table_list.
482 tables[table_index].owner_id));
486 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
487 return_ACPI_STATUS(status);
490 /*******************************************************************************
492 * FUNCTION: acpi_tb_get_owner_id
494 * PARAMETERS: table_index - Table index
495 * owner_id - Where the table owner_id is returned
499 * DESCRIPTION: returns owner_id for the ACPI table
501 ******************************************************************************/
503 acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
505 acpi_status status = AE_BAD_PARAMETER;
507 ACPI_FUNCTION_TRACE(tb_get_owner_id);
509 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
510 if (table_index < acpi_gbl_root_table_list.count) {
512 acpi_gbl_root_table_list.tables[table_index].owner_id;
516 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
517 return_ACPI_STATUS(status);
520 /*******************************************************************************
522 * FUNCTION: acpi_tb_is_table_loaded
524 * PARAMETERS: table_index - Table index
526 * RETURN: Table Loaded Flag
528 ******************************************************************************/
530 u8 acpi_tb_is_table_loaded(u32 table_index)
532 u8 is_loaded = FALSE;
534 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
535 if (table_index < acpi_gbl_root_table_list.count) {
537 (acpi_gbl_root_table_list.tables[table_index].
538 flags & ACPI_TABLE_IS_LOADED);
541 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
545 /*******************************************************************************
547 * FUNCTION: acpi_tb_set_table_loaded_flag
549 * PARAMETERS: table_index - Table index
550 * is_loaded - TRUE if table is loaded, FALSE otherwise
554 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
556 ******************************************************************************/
558 void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
561 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
562 if (table_index < acpi_gbl_root_table_list.count) {
564 acpi_gbl_root_table_list.tables[table_index].flags |=
565 ACPI_TABLE_IS_LOADED;
567 acpi_gbl_root_table_list.tables[table_index].flags &=
568 ~ACPI_TABLE_IS_LOADED;
572 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);