1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2007, R. Byron Moore
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,
111 acpi_native_uint * table_index)
114 acpi_native_uint length;
115 acpi_status status = AE_OK;
117 ACPI_FUNCTION_TRACE(tb_add_table);
119 if (!table_desc->pointer) {
120 status = acpi_tb_verify_table(table_desc);
121 if (ACPI_FAILURE(status) || !table_desc->pointer) {
122 return_ACPI_STATUS(status);
126 /* The table must be either an SSDT or a PSDT or an OEMx */
128 if (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_PSDT)&&
129 !ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)&&
130 strncmp(table_desc->pointer->signature, "OEM", 3)) {
131 /* Check for a printable name */
132 if (acpi_ut_valid_acpi_name(
133 *(u32 *) table_desc->pointer->signature)) {
134 ACPI_ERROR((AE_INFO, "Table has invalid signature "
135 "[%4.4s], must be SSDT or PSDT",
136 table_desc->pointer->signature));
138 ACPI_ERROR((AE_INFO, "Table has invalid signature "
139 "(0x%8.8X), must be SSDT or PSDT",
140 *(u32 *) table_desc->pointer->signature));
142 return_ACPI_STATUS(AE_BAD_SIGNATURE);
145 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
147 /* Check if table is already registered */
149 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
150 if (!acpi_gbl_root_table_list.tables[i].pointer) {
152 acpi_tb_verify_table(&acpi_gbl_root_table_list.
154 if (ACPI_FAILURE(status)
155 || !acpi_gbl_root_table_list.tables[i].pointer) {
160 length = ACPI_MIN(table_desc->length,
161 acpi_gbl_root_table_list.tables[i].length);
162 if (ACPI_MEMCMP(table_desc->pointer,
163 acpi_gbl_root_table_list.tables[i].pointer,
168 /* Table is already registered */
170 acpi_tb_delete_table(table_desc);
176 * Add the table to the global table list
178 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
179 table_desc->length, table_desc->flags,
181 if (ACPI_FAILURE(status)) {
185 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
188 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
189 return_ACPI_STATUS(status);
192 /*******************************************************************************
194 * FUNCTION: acpi_tb_resize_root_table_list
200 * DESCRIPTION: Expand the size of global table array
202 ******************************************************************************/
204 acpi_status acpi_tb_resize_root_table_list(void)
206 struct acpi_table_desc *tables;
208 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
210 /* allow_resize flag is a parameter to acpi_initialize_tables */
212 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
214 "Resize of Root Table Array is not allowed"));
215 return_ACPI_STATUS(AE_SUPPORT);
218 /* Increase the Table Array size */
220 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
221 ACPI_ROOT_TABLE_SIZE_INCREMENT)
222 * sizeof(struct acpi_table_desc));
225 "Could not allocate new root table array"));
226 return_ACPI_STATUS(AE_NO_MEMORY);
229 /* Copy and free the previous table array */
231 if (acpi_gbl_root_table_list.tables) {
232 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
233 acpi_gbl_root_table_list.size *
234 sizeof(struct acpi_table_desc));
236 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
237 ACPI_FREE(acpi_gbl_root_table_list.tables);
241 acpi_gbl_root_table_list.tables = tables;
242 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
243 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
245 return_ACPI_STATUS(AE_OK);
248 /*******************************************************************************
250 * FUNCTION: acpi_tb_store_table
252 * PARAMETERS: Address - Table address
253 * Table - Table header
254 * Length - Table length
257 * RETURN: Status and table index.
259 * DESCRIPTION: Add an ACPI table to the global table list
261 ******************************************************************************/
264 acpi_tb_store_table(acpi_physical_address address,
265 struct acpi_table_header *table,
266 u32 length, u8 flags, acpi_native_uint * table_index)
268 acpi_status status = AE_OK;
270 /* Ensure that there is room for the table in the Root Table List */
272 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
273 status = acpi_tb_resize_root_table_list();
274 if (ACPI_FAILURE(status)) {
279 /* Initialize added table */
281 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
283 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
285 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
287 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
289 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
293 (acpi_gbl_root_table_list.
294 tables[acpi_gbl_root_table_list.count].signature),
297 *table_index = acpi_gbl_root_table_list.count;
298 acpi_gbl_root_table_list.count++;
302 /*******************************************************************************
304 * FUNCTION: acpi_tb_delete_table
306 * PARAMETERS: table_index - Table index
310 * DESCRIPTION: Delete one internal ACPI table
312 ******************************************************************************/
314 void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
316 /* Table must be mapped or allocated */
317 if (!table_desc->pointer) {
320 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
321 case ACPI_TABLE_ORIGIN_MAPPED:
322 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
324 case ACPI_TABLE_ORIGIN_ALLOCATED:
325 ACPI_FREE(table_desc->pointer);
330 table_desc->pointer = NULL;
333 /*******************************************************************************
335 * FUNCTION: acpi_tb_terminate
341 * DESCRIPTION: Delete all internal ACPI tables
343 ******************************************************************************/
345 void acpi_tb_terminate(void)
349 ACPI_FUNCTION_TRACE(tb_terminate);
351 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
353 /* Delete the individual tables */
355 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
356 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
360 * Delete the root table array if allocated locally. Array cannot be
361 * mapped, so we don't need to check for that flag.
363 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
364 ACPI_FREE(acpi_gbl_root_table_list.tables);
367 acpi_gbl_root_table_list.tables = NULL;
368 acpi_gbl_root_table_list.flags = 0;
369 acpi_gbl_root_table_list.count = 0;
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
372 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
375 /*******************************************************************************
377 * FUNCTION: acpi_tb_delete_namespace_by_owner
379 * PARAMETERS: table_index - Table index
383 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
385 ******************************************************************************/
387 void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
389 acpi_owner_id owner_id;
391 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
392 if (table_index < acpi_gbl_root_table_list.count) {
394 acpi_gbl_root_table_list.tables[table_index].owner_id;
396 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
400 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
401 acpi_ns_delete_namespace_by_owner(owner_id);
404 /*******************************************************************************
406 * FUNCTION: acpi_tb_allocate_owner_id
408 * PARAMETERS: table_index - Table index
412 * DESCRIPTION: Allocates owner_id in table_desc
414 ******************************************************************************/
416 acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
418 acpi_status status = AE_BAD_PARAMETER;
420 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
422 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
423 if (table_index < acpi_gbl_root_table_list.count) {
424 status = acpi_ut_allocate_owner_id
425 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
428 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
429 return_ACPI_STATUS(status);
432 /*******************************************************************************
434 * FUNCTION: acpi_tb_release_owner_id
436 * PARAMETERS: table_index - Table index
440 * DESCRIPTION: Releases owner_id in table_desc
442 ******************************************************************************/
444 acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
446 acpi_status status = AE_BAD_PARAMETER;
448 ACPI_FUNCTION_TRACE(tb_release_owner_id);
450 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
451 if (table_index < acpi_gbl_root_table_list.count) {
452 acpi_ut_release_owner_id(&
453 (acpi_gbl_root_table_list.
454 tables[table_index].owner_id));
458 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
459 return_ACPI_STATUS(status);
462 /*******************************************************************************
464 * FUNCTION: acpi_tb_get_owner_id
466 * PARAMETERS: table_index - Table index
467 * owner_id - Where the table owner_id is returned
471 * DESCRIPTION: returns owner_id for the ACPI table
473 ******************************************************************************/
476 acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
478 acpi_status status = AE_BAD_PARAMETER;
480 ACPI_FUNCTION_TRACE(tb_get_owner_id);
482 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
483 if (table_index < acpi_gbl_root_table_list.count) {
485 acpi_gbl_root_table_list.tables[table_index].owner_id;
489 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
490 return_ACPI_STATUS(status);
493 /*******************************************************************************
495 * FUNCTION: acpi_tb_is_table_loaded
497 * PARAMETERS: table_index - Table index
499 * RETURN: Table Loaded Flag
501 ******************************************************************************/
503 u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
505 u8 is_loaded = FALSE;
507 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
508 if (table_index < acpi_gbl_root_table_list.count) {
510 (acpi_gbl_root_table_list.tables[table_index].
511 flags & ACPI_TABLE_IS_LOADED);
514 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
518 /*******************************************************************************
520 * FUNCTION: acpi_tb_set_table_loaded_flag
522 * PARAMETERS: table_index - Table index
523 * is_loaded - TRUE if table is loaded, FALSE otherwise
527 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
529 ******************************************************************************/
531 void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
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].flags |=
538 ACPI_TABLE_IS_LOADED;
540 acpi_gbl_root_table_list.tables[table_index].flags &=
541 ~ACPI_TABLE_IS_LOADED;
545 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);