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)
114 acpi_status status = AE_OK;
116 ACPI_FUNCTION_TRACE(tb_add_table);
118 if (!table_desc->pointer) {
119 status = acpi_tb_verify_table(table_desc);
120 if (ACPI_FAILURE(status) || !table_desc->pointer) {
121 return_ACPI_STATUS(status);
126 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
127 * Next, we added support for OEMx tables, signature "OEM".
128 * Valid tables were encountered with a null signature, so we've just
129 * given up on validating the signature, since it seems to be a waste
130 * of code. The original code was removed (05/2008).
133 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
135 /* Check if table is already registered */
137 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
138 if (!acpi_gbl_root_table_list.tables[i].pointer) {
140 acpi_tb_verify_table(&acpi_gbl_root_table_list.
142 if (ACPI_FAILURE(status)
143 || !acpi_gbl_root_table_list.tables[i].pointer) {
148 length = ACPI_MIN(table_desc->length,
149 acpi_gbl_root_table_list.tables[i].length);
150 if (ACPI_MEMCMP(table_desc->pointer,
151 acpi_gbl_root_table_list.tables[i].pointer,
156 /* Table is already registered */
158 acpi_tb_delete_table(table_desc);
160 status = AE_ALREADY_EXISTS;
165 * Add the table to the global table list
167 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
168 table_desc->length, table_desc->flags,
170 if (ACPI_FAILURE(status)) {
174 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
177 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
178 return_ACPI_STATUS(status);
181 /*******************************************************************************
183 * FUNCTION: acpi_tb_resize_root_table_list
189 * DESCRIPTION: Expand the size of global table array
191 ******************************************************************************/
193 acpi_status acpi_tb_resize_root_table_list(void)
195 struct acpi_table_desc *tables;
197 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
199 /* allow_resize flag is a parameter to acpi_initialize_tables */
201 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
203 "Resize of Root Table Array is not allowed"));
204 return_ACPI_STATUS(AE_SUPPORT);
207 /* Increase the Table Array size */
209 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
210 size + ACPI_ROOT_TABLE_SIZE_INCREMENT)
211 * sizeof(struct acpi_table_desc));
214 "Could not allocate new root table array"));
215 return_ACPI_STATUS(AE_NO_MEMORY);
218 /* Copy and free the previous table array */
220 if (acpi_gbl_root_table_list.tables) {
221 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
222 (acpi_size) acpi_gbl_root_table_list.size *
223 sizeof(struct acpi_table_desc));
225 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
226 ACPI_FREE(acpi_gbl_root_table_list.tables);
230 acpi_gbl_root_table_list.tables = tables;
231 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
232 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
234 return_ACPI_STATUS(AE_OK);
237 /*******************************************************************************
239 * FUNCTION: acpi_tb_store_table
241 * PARAMETERS: Address - Table address
242 * Table - Table header
243 * Length - Table length
246 * RETURN: Status and table index.
248 * DESCRIPTION: Add an ACPI table to the global table list
250 ******************************************************************************/
253 acpi_tb_store_table(acpi_physical_address address,
254 struct acpi_table_header *table,
255 u32 length, u8 flags, u32 *table_index)
257 acpi_status status = AE_OK;
259 /* Ensure that there is room for the table in the Root Table List */
261 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
262 status = acpi_tb_resize_root_table_list();
263 if (ACPI_FAILURE(status)) {
268 /* Initialize added table */
270 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
272 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
274 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
276 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
278 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
282 (acpi_gbl_root_table_list.
283 tables[acpi_gbl_root_table_list.count].signature),
286 *table_index = acpi_gbl_root_table_list.count;
287 acpi_gbl_root_table_list.count++;
291 /*******************************************************************************
293 * FUNCTION: acpi_tb_delete_table
295 * PARAMETERS: table_index - Table index
299 * DESCRIPTION: Delete one internal ACPI table
301 ******************************************************************************/
303 void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
305 /* Table must be mapped or allocated */
306 if (!table_desc->pointer) {
309 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
310 case ACPI_TABLE_ORIGIN_MAPPED:
311 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
313 case ACPI_TABLE_ORIGIN_ALLOCATED:
314 ACPI_FREE(table_desc->pointer);
319 table_desc->pointer = NULL;
322 /*******************************************************************************
324 * FUNCTION: acpi_tb_terminate
330 * DESCRIPTION: Delete all internal ACPI tables
332 ******************************************************************************/
334 void acpi_tb_terminate(void)
338 ACPI_FUNCTION_TRACE(tb_terminate);
340 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
342 /* Delete the individual tables */
344 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
345 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
349 * Delete the root table array if allocated locally. Array cannot be
350 * mapped, so we don't need to check for that flag.
352 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
353 ACPI_FREE(acpi_gbl_root_table_list.tables);
356 acpi_gbl_root_table_list.tables = NULL;
357 acpi_gbl_root_table_list.flags = 0;
358 acpi_gbl_root_table_list.count = 0;
360 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
361 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
364 /*******************************************************************************
366 * FUNCTION: acpi_tb_delete_namespace_by_owner
368 * PARAMETERS: table_index - Table index
372 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
374 ******************************************************************************/
376 void acpi_tb_delete_namespace_by_owner(u32 table_index)
378 acpi_owner_id owner_id;
380 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
381 if (table_index < acpi_gbl_root_table_list.count) {
383 acpi_gbl_root_table_list.tables[table_index].owner_id;
385 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
389 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
390 acpi_ns_delete_namespace_by_owner(owner_id);
393 /*******************************************************************************
395 * FUNCTION: acpi_tb_allocate_owner_id
397 * PARAMETERS: table_index - Table index
401 * DESCRIPTION: Allocates owner_id in table_desc
403 ******************************************************************************/
405 acpi_status acpi_tb_allocate_owner_id(u32 table_index)
407 acpi_status status = AE_BAD_PARAMETER;
409 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
411 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
412 if (table_index < acpi_gbl_root_table_list.count) {
413 status = acpi_ut_allocate_owner_id
414 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
417 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
418 return_ACPI_STATUS(status);
421 /*******************************************************************************
423 * FUNCTION: acpi_tb_release_owner_id
425 * PARAMETERS: table_index - Table index
429 * DESCRIPTION: Releases owner_id in table_desc
431 ******************************************************************************/
433 acpi_status acpi_tb_release_owner_id(u32 table_index)
435 acpi_status status = AE_BAD_PARAMETER;
437 ACPI_FUNCTION_TRACE(tb_release_owner_id);
439 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
440 if (table_index < acpi_gbl_root_table_list.count) {
441 acpi_ut_release_owner_id(&
442 (acpi_gbl_root_table_list.
443 tables[table_index].owner_id));
447 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
448 return_ACPI_STATUS(status);
451 /*******************************************************************************
453 * FUNCTION: acpi_tb_get_owner_id
455 * PARAMETERS: table_index - Table index
456 * owner_id - Where the table owner_id is returned
460 * DESCRIPTION: returns owner_id for the ACPI table
462 ******************************************************************************/
464 acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
466 acpi_status status = AE_BAD_PARAMETER;
468 ACPI_FUNCTION_TRACE(tb_get_owner_id);
470 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
471 if (table_index < acpi_gbl_root_table_list.count) {
473 acpi_gbl_root_table_list.tables[table_index].owner_id;
477 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
478 return_ACPI_STATUS(status);
481 /*******************************************************************************
483 * FUNCTION: acpi_tb_is_table_loaded
485 * PARAMETERS: table_index - Table index
487 * RETURN: Table Loaded Flag
489 ******************************************************************************/
491 u8 acpi_tb_is_table_loaded(u32 table_index)
493 u8 is_loaded = FALSE;
495 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
496 if (table_index < acpi_gbl_root_table_list.count) {
498 (acpi_gbl_root_table_list.tables[table_index].
499 flags & ACPI_TABLE_IS_LOADED);
502 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
506 /*******************************************************************************
508 * FUNCTION: acpi_tb_set_table_loaded_flag
510 * PARAMETERS: table_index - Table index
511 * is_loaded - TRUE if table is loaded, FALSE otherwise
515 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
517 ******************************************************************************/
519 void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
522 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
523 if (table_index < acpi_gbl_root_table_list.count) {
525 acpi_gbl_root_table_list.tables[table_index].flags |=
526 ACPI_TABLE_IS_LOADED;
528 acpi_gbl_root_table_list.tables[table_index].flags &=
529 ~ACPI_TABLE_IS_LOADED;
533 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);