1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME("tbinstal")
52 /******************************************************************************
54 * FUNCTION: acpi_tb_verify_table
56 * PARAMETERS: table_desc - table
60 * DESCRIPTION: this function is called to verify and map table
62 *****************************************************************************/
63 acpi_status
acpi_tb_verify_table(struct acpi_table_desc
*table_desc
)
65 acpi_status status
= AE_OK
;
67 ACPI_FUNCTION_TRACE(tb_verify_table
);
69 /* Map the table if necessary */
71 if (!table_desc
->pointer
) {
72 if ((table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) ==
73 ACPI_TABLE_ORIGIN_MAPPED
) {
75 acpi_os_map_memory(table_desc
->address
,
78 if (!table_desc
->pointer
) {
79 return_ACPI_STATUS(AE_NO_MEMORY
);
83 /* FACS is the odd table, has no standard ACPI header and no checksum */
85 if (!ACPI_COMPARE_NAME(&table_desc
->signature
, ACPI_SIG_FACS
)) {
87 /* Always calculate checksum, ignore bad checksum if requested */
90 acpi_tb_verify_checksum(table_desc
->pointer
,
94 return_ACPI_STATUS(status
);
97 /*******************************************************************************
99 * FUNCTION: acpi_tb_add_table
101 * PARAMETERS: table_desc - Table descriptor
102 * table_index - Where the table index is returned
106 * DESCRIPTION: This function is called to add an ACPI table. It is used to
107 * dynamically load tables via the Load and load_table AML
110 ******************************************************************************/
113 acpi_tb_add_table(struct acpi_table_desc
*table_desc
, u32
*table_index
)
116 acpi_status status
= AE_OK
;
117 struct acpi_table_header
*override_table
= NULL
;
119 ACPI_FUNCTION_TRACE(tb_add_table
);
121 if (!table_desc
->pointer
) {
122 status
= acpi_tb_verify_table(table_desc
);
123 if (ACPI_FAILURE(status
) || !table_desc
->pointer
) {
124 return_ACPI_STATUS(status
);
129 * Validate the incoming table signature.
131 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
132 * 2) We added support for OEMx tables, signature "OEM".
133 * 3) Valid tables were encountered with a null signature, so we just
134 * gave up on validating the signature, (05/2008).
135 * 4) We encountered non-AML tables such as the MADT, which caused
136 * interpreter errors and kernel faults. So now, we once again allow
137 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
139 if ((table_desc
->pointer
->signature
[0] != 0x00) &&
140 (!ACPI_COMPARE_NAME(table_desc
->pointer
->signature
, ACPI_SIG_SSDT
))
141 && (ACPI_STRNCMP(table_desc
->pointer
->signature
, "OEM", 3))) {
143 "Table has invalid signature [%4.4s] (0x%8.8X), must be SSDT or OEMx",
144 acpi_ut_valid_acpi_name(*(u32
*)table_desc
->
146 signature
) ? table_desc
->
147 pointer
->signature
: "????",
148 *(u32
*)table_desc
->pointer
->signature
));
150 return_ACPI_STATUS(AE_BAD_SIGNATURE
);
153 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
155 /* Check if table is already registered */
157 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; ++i
) {
158 if (!acpi_gbl_root_table_list
.tables
[i
].pointer
) {
160 acpi_tb_verify_table(&acpi_gbl_root_table_list
.
162 if (ACPI_FAILURE(status
)
163 || !acpi_gbl_root_table_list
.tables
[i
].pointer
) {
169 * Check for a table match on the entire table length,
170 * not just the header.
172 if (table_desc
->length
!=
173 acpi_gbl_root_table_list
.tables
[i
].length
) {
177 if (ACPI_MEMCMP(table_desc
->pointer
,
178 acpi_gbl_root_table_list
.tables
[i
].pointer
,
179 acpi_gbl_root_table_list
.tables
[i
].length
)) {
184 * Note: the current mechanism does not unregister a table if it is
185 * dynamically unloaded. The related namespace entries are deleted,
186 * but the table remains in the root table list.
188 * The assumption here is that the number of different tables that
189 * will be loaded is actually small, and there is minimal overhead
190 * in just keeping the table in case it is needed again.
192 * If this assumption changes in the future (perhaps on large
193 * machines with many table load/unload operations), tables will
194 * need to be unregistered when they are unloaded, and slots in the
195 * root table list should be reused when empty.
199 * Table is already registered.
200 * We can delete the table that was passed as a parameter.
202 acpi_tb_delete_table(table_desc
);
205 if (acpi_gbl_root_table_list
.tables
[i
].
206 flags
& ACPI_TABLE_IS_LOADED
) {
208 /* Table is still loaded, this is an error */
210 status
= AE_ALREADY_EXISTS
;
213 /* Table was unloaded, allow it to be reloaded */
215 table_desc
->pointer
=
216 acpi_gbl_root_table_list
.tables
[i
].pointer
;
217 table_desc
->address
=
218 acpi_gbl_root_table_list
.tables
[i
].address
;
225 * ACPI Table Override:
226 * Allow the host to override dynamically loaded tables.
228 status
= acpi_os_table_override(table_desc
->pointer
, &override_table
);
229 if (ACPI_SUCCESS(status
) && override_table
) {
231 "%4.4s @ 0x%p Table override, replaced with:",
232 table_desc
->pointer
->signature
,
233 ACPI_CAST_PTR(void, table_desc
->address
)));
235 /* We can delete the table that was passed as a parameter */
237 acpi_tb_delete_table(table_desc
);
239 /* Setup descriptor for the new table */
241 table_desc
->address
= ACPI_PTR_TO_PHYSADDR(override_table
);
242 table_desc
->pointer
= override_table
;
243 table_desc
->length
= override_table
->length
;
244 table_desc
->flags
= ACPI_TABLE_ORIGIN_OVERRIDE
;
247 /* Add the table to the global root table list */
249 status
= acpi_tb_store_table(table_desc
->address
, table_desc
->pointer
,
250 table_desc
->length
, table_desc
->flags
,
252 if (ACPI_FAILURE(status
)) {
257 acpi_tb_print_table_header(table_desc
->address
, table_desc
->pointer
);
260 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
261 return_ACPI_STATUS(status
);
264 /*******************************************************************************
266 * FUNCTION: acpi_tb_resize_root_table_list
272 * DESCRIPTION: Expand the size of global table array
274 ******************************************************************************/
276 acpi_status
acpi_tb_resize_root_table_list(void)
278 struct acpi_table_desc
*tables
;
280 ACPI_FUNCTION_TRACE(tb_resize_root_table_list
);
282 /* allow_resize flag is a parameter to acpi_initialize_tables */
284 if (!(acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ALLOW_RESIZE
)) {
286 "Resize of Root Table Array is not allowed"));
287 return_ACPI_STATUS(AE_SUPPORT
);
290 /* Increase the Table Array size */
292 tables
= ACPI_ALLOCATE_ZEROED(((acpi_size
) acpi_gbl_root_table_list
.
294 ACPI_ROOT_TABLE_SIZE_INCREMENT
) *
295 sizeof(struct acpi_table_desc
));
298 "Could not allocate new root table array"));
299 return_ACPI_STATUS(AE_NO_MEMORY
);
302 /* Copy and free the previous table array */
304 if (acpi_gbl_root_table_list
.tables
) {
305 ACPI_MEMCPY(tables
, acpi_gbl_root_table_list
.tables
,
306 (acpi_size
) acpi_gbl_root_table_list
.
307 max_table_count
* sizeof(struct acpi_table_desc
));
309 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
310 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
314 acpi_gbl_root_table_list
.tables
= tables
;
315 acpi_gbl_root_table_list
.max_table_count
+=
316 ACPI_ROOT_TABLE_SIZE_INCREMENT
;
317 acpi_gbl_root_table_list
.flags
|= (u8
)ACPI_ROOT_ORIGIN_ALLOCATED
;
319 return_ACPI_STATUS(AE_OK
);
322 /*******************************************************************************
324 * FUNCTION: acpi_tb_store_table
326 * PARAMETERS: Address - Table address
327 * Table - Table header
328 * Length - Table length
331 * RETURN: Status and table index.
333 * DESCRIPTION: Add an ACPI table to the global table list
335 ******************************************************************************/
338 acpi_tb_store_table(acpi_physical_address address
,
339 struct acpi_table_header
*table
,
340 u32 length
, u8 flags
, u32
*table_index
)
343 struct acpi_table_desc
*new_table
;
345 /* Ensure that there is room for the table in the Root Table List */
347 if (acpi_gbl_root_table_list
.current_table_count
>=
348 acpi_gbl_root_table_list
.max_table_count
) {
349 status
= acpi_tb_resize_root_table_list();
350 if (ACPI_FAILURE(status
)) {
356 &acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.
357 current_table_count
];
359 /* Initialize added table */
361 new_table
->address
= address
;
362 new_table
->pointer
= table
;
363 new_table
->length
= length
;
364 new_table
->owner_id
= 0;
365 new_table
->flags
= flags
;
367 ACPI_MOVE_32_TO_32(&new_table
->signature
, table
->signature
);
369 *table_index
= acpi_gbl_root_table_list
.current_table_count
;
370 acpi_gbl_root_table_list
.current_table_count
++;
374 /*******************************************************************************
376 * FUNCTION: acpi_tb_delete_table
378 * PARAMETERS: table_index - Table index
382 * DESCRIPTION: Delete one internal ACPI table
384 ******************************************************************************/
386 void acpi_tb_delete_table(struct acpi_table_desc
*table_desc
)
388 /* Table must be mapped or allocated */
389 if (!table_desc
->pointer
) {
392 switch (table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) {
393 case ACPI_TABLE_ORIGIN_MAPPED
:
394 acpi_os_unmap_memory(table_desc
->pointer
, table_desc
->length
);
396 case ACPI_TABLE_ORIGIN_ALLOCATED
:
397 ACPI_FREE(table_desc
->pointer
);
402 table_desc
->pointer
= NULL
;
405 /*******************************************************************************
407 * FUNCTION: acpi_tb_terminate
413 * DESCRIPTION: Delete all internal ACPI tables
415 ******************************************************************************/
417 void acpi_tb_terminate(void)
421 ACPI_FUNCTION_TRACE(tb_terminate
);
423 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
425 /* Delete the individual tables */
427 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; i
++) {
428 acpi_tb_delete_table(&acpi_gbl_root_table_list
.tables
[i
]);
432 * Delete the root table array if allocated locally. Array cannot be
433 * mapped, so we don't need to check for that flag.
435 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
436 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
439 acpi_gbl_root_table_list
.tables
= NULL
;
440 acpi_gbl_root_table_list
.flags
= 0;
441 acpi_gbl_root_table_list
.current_table_count
= 0;
443 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "ACPI Tables freed\n"));
444 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
447 /*******************************************************************************
449 * FUNCTION: acpi_tb_delete_namespace_by_owner
451 * PARAMETERS: table_index - Table index
455 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
457 ******************************************************************************/
459 acpi_status
acpi_tb_delete_namespace_by_owner(u32 table_index
)
461 acpi_owner_id owner_id
;
464 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner
);
466 status
= acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
467 if (ACPI_FAILURE(status
)) {
468 return_ACPI_STATUS(status
);
471 if (table_index
>= acpi_gbl_root_table_list
.current_table_count
) {
473 /* The table index does not exist */
475 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
476 return_ACPI_STATUS(AE_NOT_EXIST
);
479 /* Get the owner ID for this table, used to delete namespace nodes */
481 owner_id
= acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
482 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
485 * Need to acquire the namespace writer lock to prevent interference
486 * with any concurrent namespace walks. The interpreter must be
487 * released during the deletion since the acquisition of the deletion
488 * lock may block, and also since the execution of a namespace walk
489 * must be allowed to use the interpreter.
491 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
492 status
= acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock
);
494 acpi_ns_delete_namespace_by_owner(owner_id
);
495 if (ACPI_FAILURE(status
)) {
496 return_ACPI_STATUS(status
);
499 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock
);
501 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
502 return_ACPI_STATUS(status
);
505 /*******************************************************************************
507 * FUNCTION: acpi_tb_allocate_owner_id
509 * PARAMETERS: table_index - Table index
513 * DESCRIPTION: Allocates owner_id in table_desc
515 ******************************************************************************/
517 acpi_status
acpi_tb_allocate_owner_id(u32 table_index
)
519 acpi_status status
= AE_BAD_PARAMETER
;
521 ACPI_FUNCTION_TRACE(tb_allocate_owner_id
);
523 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
524 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
525 status
= acpi_ut_allocate_owner_id
526 (&(acpi_gbl_root_table_list
.tables
[table_index
].owner_id
));
529 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
530 return_ACPI_STATUS(status
);
533 /*******************************************************************************
535 * FUNCTION: acpi_tb_release_owner_id
537 * PARAMETERS: table_index - Table index
541 * DESCRIPTION: Releases owner_id in table_desc
543 ******************************************************************************/
545 acpi_status
acpi_tb_release_owner_id(u32 table_index
)
547 acpi_status status
= AE_BAD_PARAMETER
;
549 ACPI_FUNCTION_TRACE(tb_release_owner_id
);
551 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
552 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
553 acpi_ut_release_owner_id(&
554 (acpi_gbl_root_table_list
.
555 tables
[table_index
].owner_id
));
559 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
560 return_ACPI_STATUS(status
);
563 /*******************************************************************************
565 * FUNCTION: acpi_tb_get_owner_id
567 * PARAMETERS: table_index - Table index
568 * owner_id - Where the table owner_id is returned
572 * DESCRIPTION: returns owner_id for the ACPI table
574 ******************************************************************************/
576 acpi_status
acpi_tb_get_owner_id(u32 table_index
, acpi_owner_id
*owner_id
)
578 acpi_status status
= AE_BAD_PARAMETER
;
580 ACPI_FUNCTION_TRACE(tb_get_owner_id
);
582 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
583 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
585 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
589 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
590 return_ACPI_STATUS(status
);
593 /*******************************************************************************
595 * FUNCTION: acpi_tb_is_table_loaded
597 * PARAMETERS: table_index - Table index
599 * RETURN: Table Loaded Flag
601 ******************************************************************************/
603 u8
acpi_tb_is_table_loaded(u32 table_index
)
605 u8 is_loaded
= FALSE
;
607 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
608 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
610 (acpi_gbl_root_table_list
.tables
[table_index
].flags
&
611 ACPI_TABLE_IS_LOADED
);
614 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
618 /*******************************************************************************
620 * FUNCTION: acpi_tb_set_table_loaded_flag
622 * PARAMETERS: table_index - Table index
623 * is_loaded - TRUE if table is loaded, FALSE otherwise
627 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
629 ******************************************************************************/
631 void acpi_tb_set_table_loaded_flag(u32 table_index
, u8 is_loaded
)
634 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
635 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
637 acpi_gbl_root_table_list
.tables
[table_index
].flags
|=
638 ACPI_TABLE_IS_LOADED
;
640 acpi_gbl_root_table_list
.tables
[table_index
].flags
&=
641 ~ACPI_TABLE_IS_LOADED
;
645 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);