1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2010, 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 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
130 * Next, we added support for OEMx tables, signature "OEM".
131 * Valid tables were encountered with a null signature, so we've just
132 * given up on validating the signature, since it seems to be a waste
133 * of code. The original code was removed (05/2008).
136 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
138 /* Check if table is already registered */
140 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
141 if (!acpi_gbl_root_table_list
.tables
[i
].pointer
) {
143 acpi_tb_verify_table(&acpi_gbl_root_table_list
.
145 if (ACPI_FAILURE(status
)
146 || !acpi_gbl_root_table_list
.tables
[i
].pointer
) {
152 * Check for a table match on the entire table length,
153 * not just the header.
155 if (table_desc
->length
!=
156 acpi_gbl_root_table_list
.tables
[i
].length
) {
160 if (ACPI_MEMCMP(table_desc
->pointer
,
161 acpi_gbl_root_table_list
.tables
[i
].pointer
,
162 acpi_gbl_root_table_list
.tables
[i
].length
)) {
167 * Note: the current mechanism does not unregister a table if it is
168 * dynamically unloaded. The related namespace entries are deleted,
169 * but the table remains in the root table list.
171 * The assumption here is that the number of different tables that
172 * will be loaded is actually small, and there is minimal overhead
173 * in just keeping the table in case it is needed again.
175 * If this assumption changes in the future (perhaps on large
176 * machines with many table load/unload operations), tables will
177 * need to be unregistered when they are unloaded, and slots in the
178 * root table list should be reused when empty.
182 * Table is already registered.
183 * We can delete the table that was passed as a parameter.
185 acpi_tb_delete_table(table_desc
);
188 if (acpi_gbl_root_table_list
.tables
[i
].
189 flags
& ACPI_TABLE_IS_LOADED
) {
191 /* Table is still loaded, this is an error */
193 status
= AE_ALREADY_EXISTS
;
196 /* Table was unloaded, allow it to be reloaded */
198 table_desc
->pointer
=
199 acpi_gbl_root_table_list
.tables
[i
].pointer
;
200 table_desc
->address
=
201 acpi_gbl_root_table_list
.tables
[i
].address
;
208 * ACPI Table Override:
209 * Allow the host to override dynamically loaded tables.
211 status
= acpi_os_table_override(table_desc
->pointer
, &override_table
);
212 if (ACPI_SUCCESS(status
) && override_table
) {
214 "%4.4s @ 0x%p Table override, replaced with:",
215 table_desc
->pointer
->signature
,
216 ACPI_CAST_PTR(void, table_desc
->address
)));
218 /* We can delete the table that was passed as a parameter */
220 acpi_tb_delete_table(table_desc
);
222 /* Setup descriptor for the new table */
224 table_desc
->address
= ACPI_PTR_TO_PHYSADDR(override_table
);
225 table_desc
->pointer
= override_table
;
226 table_desc
->length
= override_table
->length
;
227 table_desc
->flags
= ACPI_TABLE_ORIGIN_OVERRIDE
;
230 /* Add the table to the global root table list */
232 status
= acpi_tb_store_table(table_desc
->address
, table_desc
->pointer
,
233 table_desc
->length
, table_desc
->flags
,
235 if (ACPI_FAILURE(status
)) {
240 acpi_tb_print_table_header(table_desc
->address
, table_desc
->pointer
);
243 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
244 return_ACPI_STATUS(status
);
247 /*******************************************************************************
249 * FUNCTION: acpi_tb_resize_root_table_list
255 * DESCRIPTION: Expand the size of global table array
257 ******************************************************************************/
259 acpi_status
acpi_tb_resize_root_table_list(void)
261 struct acpi_table_desc
*tables
;
263 ACPI_FUNCTION_TRACE(tb_resize_root_table_list
);
265 /* allow_resize flag is a parameter to acpi_initialize_tables */
267 if (!(acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ALLOW_RESIZE
)) {
269 "Resize of Root Table Array is not allowed"));
270 return_ACPI_STATUS(AE_SUPPORT
);
273 /* Increase the Table Array size */
275 tables
= ACPI_ALLOCATE_ZEROED(((acpi_size
) acpi_gbl_root_table_list
.
277 ACPI_ROOT_TABLE_SIZE_INCREMENT
) *
278 sizeof(struct acpi_table_desc
));
281 "Could not allocate new root table array"));
282 return_ACPI_STATUS(AE_NO_MEMORY
);
285 /* Copy and free the previous table array */
287 if (acpi_gbl_root_table_list
.tables
) {
288 ACPI_MEMCPY(tables
, acpi_gbl_root_table_list
.tables
,
289 (acpi_size
) acpi_gbl_root_table_list
.size
*
290 sizeof(struct acpi_table_desc
));
292 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
293 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
297 acpi_gbl_root_table_list
.tables
= tables
;
298 acpi_gbl_root_table_list
.size
+= ACPI_ROOT_TABLE_SIZE_INCREMENT
;
299 acpi_gbl_root_table_list
.flags
|= (u8
) ACPI_ROOT_ORIGIN_ALLOCATED
;
301 return_ACPI_STATUS(AE_OK
);
304 /*******************************************************************************
306 * FUNCTION: acpi_tb_store_table
308 * PARAMETERS: Address - Table address
309 * Table - Table header
310 * Length - Table length
313 * RETURN: Status and table index.
315 * DESCRIPTION: Add an ACPI table to the global table list
317 ******************************************************************************/
320 acpi_tb_store_table(acpi_physical_address address
,
321 struct acpi_table_header
*table
,
322 u32 length
, u8 flags
, u32
*table_index
)
324 acpi_status status
= AE_OK
;
326 /* Ensure that there is room for the table in the Root Table List */
328 if (acpi_gbl_root_table_list
.count
>= acpi_gbl_root_table_list
.size
) {
329 status
= acpi_tb_resize_root_table_list();
330 if (ACPI_FAILURE(status
)) {
335 /* Initialize added table */
337 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
339 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
341 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].length
=
343 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
345 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].flags
=
349 (acpi_gbl_root_table_list
.
350 tables
[acpi_gbl_root_table_list
.count
].signature
),
353 *table_index
= acpi_gbl_root_table_list
.count
;
354 acpi_gbl_root_table_list
.count
++;
358 /*******************************************************************************
360 * FUNCTION: acpi_tb_delete_table
362 * PARAMETERS: table_index - Table index
366 * DESCRIPTION: Delete one internal ACPI table
368 ******************************************************************************/
370 void acpi_tb_delete_table(struct acpi_table_desc
*table_desc
)
372 /* Table must be mapped or allocated */
373 if (!table_desc
->pointer
) {
376 switch (table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) {
377 case ACPI_TABLE_ORIGIN_MAPPED
:
378 acpi_os_unmap_memory(table_desc
->pointer
, table_desc
->length
);
380 case ACPI_TABLE_ORIGIN_ALLOCATED
:
381 ACPI_FREE(table_desc
->pointer
);
386 table_desc
->pointer
= NULL
;
389 /*******************************************************************************
391 * FUNCTION: acpi_tb_terminate
397 * DESCRIPTION: Delete all internal ACPI tables
399 ******************************************************************************/
401 void acpi_tb_terminate(void)
405 ACPI_FUNCTION_TRACE(tb_terminate
);
407 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
409 /* Delete the individual tables */
411 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
412 acpi_tb_delete_table(&acpi_gbl_root_table_list
.tables
[i
]);
416 * Delete the root table array if allocated locally. Array cannot be
417 * mapped, so we don't need to check for that flag.
419 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
420 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
423 acpi_gbl_root_table_list
.tables
= NULL
;
424 acpi_gbl_root_table_list
.flags
= 0;
425 acpi_gbl_root_table_list
.count
= 0;
427 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "ACPI Tables freed\n"));
428 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
431 /*******************************************************************************
433 * FUNCTION: acpi_tb_delete_namespace_by_owner
435 * PARAMETERS: table_index - Table index
439 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
441 ******************************************************************************/
443 acpi_status
acpi_tb_delete_namespace_by_owner(u32 table_index
)
445 acpi_owner_id owner_id
;
448 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner
);
450 status
= acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
451 if (ACPI_FAILURE(status
)) {
452 return_ACPI_STATUS(status
);
455 if (table_index
>= acpi_gbl_root_table_list
.count
) {
457 /* The table index does not exist */
459 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
460 return_ACPI_STATUS(AE_NOT_EXIST
);
463 /* Get the owner ID for this table, used to delete namespace nodes */
465 owner_id
= acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
466 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
469 * Need to acquire the namespace writer lock to prevent interference
470 * with any concurrent namespace walks. The interpreter must be
471 * released during the deletion since the acquisition of the deletion
472 * lock may block, and also since the execution of a namespace walk
473 * must be allowed to use the interpreter.
475 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
476 status
= acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock
);
478 acpi_ns_delete_namespace_by_owner(owner_id
);
479 if (ACPI_FAILURE(status
)) {
480 return_ACPI_STATUS(status
);
483 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock
);
485 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
486 return_ACPI_STATUS(status
);
489 /*******************************************************************************
491 * FUNCTION: acpi_tb_allocate_owner_id
493 * PARAMETERS: table_index - Table index
497 * DESCRIPTION: Allocates owner_id in table_desc
499 ******************************************************************************/
501 acpi_status
acpi_tb_allocate_owner_id(u32 table_index
)
503 acpi_status status
= AE_BAD_PARAMETER
;
505 ACPI_FUNCTION_TRACE(tb_allocate_owner_id
);
507 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
508 if (table_index
< acpi_gbl_root_table_list
.count
) {
509 status
= acpi_ut_allocate_owner_id
510 (&(acpi_gbl_root_table_list
.tables
[table_index
].owner_id
));
513 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
514 return_ACPI_STATUS(status
);
517 /*******************************************************************************
519 * FUNCTION: acpi_tb_release_owner_id
521 * PARAMETERS: table_index - Table index
525 * DESCRIPTION: Releases owner_id in table_desc
527 ******************************************************************************/
529 acpi_status
acpi_tb_release_owner_id(u32 table_index
)
531 acpi_status status
= AE_BAD_PARAMETER
;
533 ACPI_FUNCTION_TRACE(tb_release_owner_id
);
535 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
536 if (table_index
< acpi_gbl_root_table_list
.count
) {
537 acpi_ut_release_owner_id(&
538 (acpi_gbl_root_table_list
.
539 tables
[table_index
].owner_id
));
543 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
544 return_ACPI_STATUS(status
);
547 /*******************************************************************************
549 * FUNCTION: acpi_tb_get_owner_id
551 * PARAMETERS: table_index - Table index
552 * owner_id - Where the table owner_id is returned
556 * DESCRIPTION: returns owner_id for the ACPI table
558 ******************************************************************************/
560 acpi_status
acpi_tb_get_owner_id(u32 table_index
, acpi_owner_id
*owner_id
)
562 acpi_status status
= AE_BAD_PARAMETER
;
564 ACPI_FUNCTION_TRACE(tb_get_owner_id
);
566 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
567 if (table_index
< acpi_gbl_root_table_list
.count
) {
569 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
573 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
574 return_ACPI_STATUS(status
);
577 /*******************************************************************************
579 * FUNCTION: acpi_tb_is_table_loaded
581 * PARAMETERS: table_index - Table index
583 * RETURN: Table Loaded Flag
585 ******************************************************************************/
587 u8
acpi_tb_is_table_loaded(u32 table_index
)
589 u8 is_loaded
= FALSE
;
591 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
592 if (table_index
< acpi_gbl_root_table_list
.count
) {
594 (acpi_gbl_root_table_list
.tables
[table_index
].flags
&
595 ACPI_TABLE_IS_LOADED
);
598 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
602 /*******************************************************************************
604 * FUNCTION: acpi_tb_set_table_loaded_flag
606 * PARAMETERS: table_index - Table index
607 * is_loaded - TRUE if table is loaded, FALSE otherwise
611 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
613 ******************************************************************************/
615 void acpi_tb_set_table_loaded_flag(u32 table_index
, u8 is_loaded
)
618 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
619 if (table_index
< acpi_gbl_root_table_list
.count
) {
621 acpi_gbl_root_table_list
.tables
[table_index
].flags
|=
622 ACPI_TABLE_IS_LOADED
;
624 acpi_gbl_root_table_list
.tables
[table_index
].flags
&=
625 ~ACPI_TABLE_IS_LOADED
;
629 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);