1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: tbdata - Table manager data structure functions
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
16 #define _COMPONENT ACPI_TABLES
17 ACPI_MODULE_NAME("tbdata")
19 /* Local prototypes */
21 acpi_tb_check_duplication(struct acpi_table_desc
*table_desc
, u32
*table_index
);
24 acpi_tb_compare_tables(struct acpi_table_desc
*table_desc
, u32 table_index
);
26 /*******************************************************************************
28 * FUNCTION: acpi_tb_compare_tables
30 * PARAMETERS: table_desc - Table 1 descriptor to be compared
31 * table_index - Index of table 2 to be compared
33 * RETURN: TRUE if both tables are identical.
35 * DESCRIPTION: This function compares a table with another table that has
36 * already been installed in the root table list.
38 ******************************************************************************/
41 acpi_tb_compare_tables(struct acpi_table_desc
*table_desc
, u32 table_index
)
43 acpi_status status
= AE_OK
;
45 struct acpi_table_header
*table
;
50 acpi_tb_acquire_table(&acpi_gbl_root_table_list
.tables
[table_index
],
51 &table
, &table_length
, &table_flags
);
52 if (ACPI_FAILURE(status
)) {
57 * Check for a table match on the entire table length,
58 * not just the header.
60 is_identical
= (u8
)((table_desc
->length
!= table_length
||
61 memcmp(table_desc
->pointer
, table
, table_length
)) ?
64 /* Release the acquired table */
66 acpi_tb_release_table(table
, table_length
, table_flags
);
67 return (is_identical
);
70 /*******************************************************************************
72 * FUNCTION: acpi_tb_init_table_descriptor
74 * PARAMETERS: table_desc - Table descriptor
75 * address - Physical address of the table
76 * flags - Allocation flags of the table
77 * table - Pointer to the table
81 * DESCRIPTION: Initialize a new table descriptor
83 ******************************************************************************/
86 acpi_tb_init_table_descriptor(struct acpi_table_desc
*table_desc
,
87 acpi_physical_address address
,
88 u8 flags
, struct acpi_table_header
*table
)
92 * Initialize the table descriptor. Set the pointer to NULL, since the
93 * table is not fully mapped at this time.
95 memset(table_desc
, 0, sizeof(struct acpi_table_desc
));
96 table_desc
->address
= address
;
97 table_desc
->length
= table
->length
;
98 table_desc
->flags
= flags
;
99 ACPI_MOVE_32_TO_32(table_desc
->signature
.ascii
, table
->signature
);
102 /*******************************************************************************
104 * FUNCTION: acpi_tb_acquire_table
106 * PARAMETERS: table_desc - Table descriptor
107 * table_ptr - Where table is returned
108 * table_length - Where table length is returned
109 * table_flags - Where table allocation flags are returned
113 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
114 * maintained in the acpi_gbl_root_table_list.
116 ******************************************************************************/
119 acpi_tb_acquire_table(struct acpi_table_desc
*table_desc
,
120 struct acpi_table_header
**table_ptr
,
121 u32
*table_length
, u8
*table_flags
)
123 struct acpi_table_header
*table
= NULL
;
125 switch (table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) {
126 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
:
129 acpi_os_map_memory(table_desc
->address
, table_desc
->length
);
132 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
:
133 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
:
135 table
= ACPI_CAST_PTR(struct acpi_table_header
,
136 ACPI_PHYSADDR_TO_PTR(table_desc
->
145 /* Table is not valid yet */
148 return (AE_NO_MEMORY
);
151 /* Fill the return values */
154 *table_length
= table_desc
->length
;
155 *table_flags
= table_desc
->flags
;
159 /*******************************************************************************
161 * FUNCTION: acpi_tb_release_table
163 * PARAMETERS: table - Pointer for the table
164 * table_length - Length for the table
165 * table_flags - Allocation flags for the table
169 * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
171 ******************************************************************************/
174 acpi_tb_release_table(struct acpi_table_header
*table
,
175 u32 table_length
, u8 table_flags
)
178 switch (table_flags
& ACPI_TABLE_ORIGIN_MASK
) {
179 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
:
181 acpi_os_unmap_memory(table
, table_length
);
184 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
:
185 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
:
192 /*******************************************************************************
194 * FUNCTION: acpi_tb_acquire_temp_table
196 * PARAMETERS: table_desc - Table descriptor to be acquired
197 * address - Address of the table
198 * flags - Allocation flags of the table
202 * DESCRIPTION: This function validates the table header to obtain the length
203 * of a table and fills the table descriptor to make its state as
204 * "INSTALLED". Such a table descriptor is only used for verified
207 ******************************************************************************/
210 acpi_tb_acquire_temp_table(struct acpi_table_desc
*table_desc
,
211 acpi_physical_address address
, u8 flags
)
213 struct acpi_table_header
*table_header
;
215 switch (flags
& ACPI_TABLE_ORIGIN_MASK
) {
216 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
:
218 /* Get the length of the full table from the header */
221 acpi_os_map_memory(address
,
222 sizeof(struct acpi_table_header
));
224 return (AE_NO_MEMORY
);
227 acpi_tb_init_table_descriptor(table_desc
, address
, flags
,
229 acpi_os_unmap_memory(table_header
,
230 sizeof(struct acpi_table_header
));
233 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
:
234 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
:
236 table_header
= ACPI_CAST_PTR(struct acpi_table_header
,
237 ACPI_PHYSADDR_TO_PTR(address
));
239 return (AE_NO_MEMORY
);
242 acpi_tb_init_table_descriptor(table_desc
, address
, flags
,
251 /* Table is not valid yet */
253 return (AE_NO_MEMORY
);
256 /*******************************************************************************
258 * FUNCTION: acpi_tb_release_temp_table
260 * PARAMETERS: table_desc - Table descriptor to be released
264 * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
266 *****************************************************************************/
268 void acpi_tb_release_temp_table(struct acpi_table_desc
*table_desc
)
272 * Note that the .Address is maintained by the callers of
273 * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
274 * where .Address will be freed.
276 acpi_tb_invalidate_table(table_desc
);
279 /******************************************************************************
281 * FUNCTION: acpi_tb_validate_table
283 * PARAMETERS: table_desc - Table descriptor
287 * DESCRIPTION: This function is called to validate the table, the returned
288 * table descriptor is in "VALIDATED" state.
290 *****************************************************************************/
292 acpi_status
acpi_tb_validate_table(struct acpi_table_desc
*table_desc
)
294 acpi_status status
= AE_OK
;
296 ACPI_FUNCTION_TRACE(tb_validate_table
);
298 /* Validate the table if necessary */
300 if (!table_desc
->pointer
) {
301 status
= acpi_tb_acquire_table(table_desc
, &table_desc
->pointer
,
304 if (!table_desc
->pointer
) {
305 status
= AE_NO_MEMORY
;
309 return_ACPI_STATUS(status
);
312 /*******************************************************************************
314 * FUNCTION: acpi_tb_invalidate_table
316 * PARAMETERS: table_desc - Table descriptor
320 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
321 * acpi_tb_validate_table().
323 ******************************************************************************/
325 void acpi_tb_invalidate_table(struct acpi_table_desc
*table_desc
)
328 ACPI_FUNCTION_TRACE(tb_invalidate_table
);
330 /* Table must be validated */
332 if (!table_desc
->pointer
) {
336 acpi_tb_release_table(table_desc
->pointer
, table_desc
->length
,
338 table_desc
->pointer
= NULL
;
343 /******************************************************************************
345 * FUNCTION: acpi_tb_validate_temp_table
347 * PARAMETERS: table_desc - Table descriptor
351 * DESCRIPTION: This function is called to validate the table, the returned
352 * table descriptor is in "VALIDATED" state.
354 *****************************************************************************/
356 acpi_status
acpi_tb_validate_temp_table(struct acpi_table_desc
*table_desc
)
359 if (!table_desc
->pointer
&& !acpi_gbl_enable_table_validation
) {
361 * Only validates the header of the table.
362 * Note that Length contains the size of the mapping after invoking
363 * this work around, this value is required by
364 * acpi_tb_release_temp_table().
365 * We can do this because in acpi_init_table_descriptor(), the Length
366 * field of the installed descriptor is filled with the actual
367 * table length obtaining from the table header.
369 table_desc
->length
= sizeof(struct acpi_table_header
);
372 return (acpi_tb_validate_table(table_desc
));
375 /*******************************************************************************
377 * FUNCTION: acpi_tb_check_duplication
379 * PARAMETERS: table_desc - Table descriptor
380 * table_index - Where the table index is returned
384 * DESCRIPTION: Avoid installing duplicated tables. However table override and
385 * user aided dynamic table load is allowed, thus comparing the
386 * address of the table is not sufficient, and checking the entire
387 * table content is required.
389 ******************************************************************************/
392 acpi_tb_check_duplication(struct acpi_table_desc
*table_desc
, u32
*table_index
)
396 ACPI_FUNCTION_TRACE(tb_check_duplication
);
398 /* Check if table is already registered */
400 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; ++i
) {
402 /* Do not compare with unverified tables */
405 (acpi_gbl_root_table_list
.tables
[i
].
406 flags
& ACPI_TABLE_IS_VERIFIED
)) {
411 * Check for a table match on the entire table length,
412 * not just the header.
414 if (!acpi_tb_compare_tables(table_desc
, i
)) {
419 * Note: the current mechanism does not unregister a table if it is
420 * dynamically unloaded. The related namespace entries are deleted,
421 * but the table remains in the root table list.
423 * The assumption here is that the number of different tables that
424 * will be loaded is actually small, and there is minimal overhead
425 * in just keeping the table in case it is needed again.
427 * If this assumption changes in the future (perhaps on large
428 * machines with many table load/unload operations), tables will
429 * need to be unregistered when they are unloaded, and slots in the
430 * root table list should be reused when empty.
432 if (acpi_gbl_root_table_list
.tables
[i
].flags
&
433 ACPI_TABLE_IS_LOADED
) {
435 /* Table is still loaded, this is an error */
437 return_ACPI_STATUS(AE_ALREADY_EXISTS
);
440 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
444 /* Indicate no duplication to the caller */
446 return_ACPI_STATUS(AE_OK
);
449 /******************************************************************************
451 * FUNCTION: acpi_tb_verify_temp_table
453 * PARAMETERS: table_desc - Table descriptor
454 * signature - Table signature to verify
455 * table_index - Where the table index is returned
459 * DESCRIPTION: This function is called to validate and verify the table, the
460 * returned table descriptor is in "VALIDATED" state.
461 * Note that 'TableIndex' is required to be set to !NULL to
462 * enable duplication check.
464 *****************************************************************************/
467 acpi_tb_verify_temp_table(struct acpi_table_desc
*table_desc
,
468 char *signature
, u32
*table_index
)
470 acpi_status status
= AE_OK
;
472 ACPI_FUNCTION_TRACE(tb_verify_temp_table
);
474 /* Validate the table */
476 status
= acpi_tb_validate_temp_table(table_desc
);
477 if (ACPI_FAILURE(status
)) {
478 return_ACPI_STATUS(AE_NO_MEMORY
);
481 /* If a particular signature is expected (DSDT/FACS), it must match */
483 if (signature
&& !ACPI_COMPARE_NAME(&table_desc
->signature
, signature
)) {
484 ACPI_BIOS_ERROR((AE_INFO
,
485 "Invalid signature 0x%X for ACPI table, expected [%s]",
486 table_desc
->signature
.integer
, signature
));
487 status
= AE_BAD_SIGNATURE
;
488 goto invalidate_and_exit
;
491 if (acpi_gbl_enable_table_validation
) {
493 /* Verify the checksum */
496 acpi_tb_verify_checksum(table_desc
->pointer
,
498 if (ACPI_FAILURE(status
)) {
499 ACPI_EXCEPTION((AE_INFO
, AE_NO_MEMORY
,
501 " Attempted table install failed",
502 acpi_ut_valid_nameseg(table_desc
->
505 table_desc
->signature
.ascii
: "????",
506 ACPI_FORMAT_UINT64(table_desc
->
509 goto invalidate_and_exit
;
512 /* Avoid duplications */
516 acpi_tb_check_duplication(table_desc
, table_index
);
517 if (ACPI_FAILURE(status
)) {
518 if (status
!= AE_CTRL_TERMINATE
) {
519 ACPI_EXCEPTION((AE_INFO
, status
,
521 " Table is already loaded",
522 acpi_ut_valid_nameseg
523 (table_desc
->signature
.
524 ascii
) ? table_desc
->
528 (table_desc
->address
)));
531 goto invalidate_and_exit
;
535 table_desc
->flags
|= ACPI_TABLE_IS_VERIFIED
;
538 return_ACPI_STATUS(status
);
541 acpi_tb_invalidate_table(table_desc
);
542 return_ACPI_STATUS(status
);
545 /*******************************************************************************
547 * FUNCTION: acpi_tb_resize_root_table_list
553 * DESCRIPTION: Expand the size of global table array
555 ******************************************************************************/
557 acpi_status
acpi_tb_resize_root_table_list(void)
559 struct acpi_table_desc
*tables
;
561 u32 current_table_count
, max_table_count
;
564 ACPI_FUNCTION_TRACE(tb_resize_root_table_list
);
566 /* allow_resize flag is a parameter to acpi_initialize_tables */
568 if (!(acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ALLOW_RESIZE
)) {
570 "Resize of Root Table Array is not allowed"));
571 return_ACPI_STATUS(AE_SUPPORT
);
574 /* Increase the Table Array size */
576 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
577 table_count
= acpi_gbl_root_table_list
.max_table_count
;
579 table_count
= acpi_gbl_root_table_list
.current_table_count
;
582 max_table_count
= table_count
+ ACPI_ROOT_TABLE_SIZE_INCREMENT
;
583 tables
= ACPI_ALLOCATE_ZEROED(((acpi_size
)max_table_count
) *
584 sizeof(struct acpi_table_desc
));
587 "Could not allocate new root table array"));
588 return_ACPI_STATUS(AE_NO_MEMORY
);
591 /* Copy and free the previous table array */
593 current_table_count
= 0;
594 if (acpi_gbl_root_table_list
.tables
) {
595 for (i
= 0; i
< table_count
; i
++) {
596 if (acpi_gbl_root_table_list
.tables
[i
].address
) {
597 memcpy(tables
+ current_table_count
,
598 acpi_gbl_root_table_list
.tables
+ i
,
599 sizeof(struct acpi_table_desc
));
600 current_table_count
++;
604 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
605 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
609 acpi_gbl_root_table_list
.tables
= tables
;
610 acpi_gbl_root_table_list
.max_table_count
= max_table_count
;
611 acpi_gbl_root_table_list
.current_table_count
= current_table_count
;
612 acpi_gbl_root_table_list
.flags
|= ACPI_ROOT_ORIGIN_ALLOCATED
;
614 return_ACPI_STATUS(AE_OK
);
617 /*******************************************************************************
619 * FUNCTION: acpi_tb_get_next_table_descriptor
621 * PARAMETERS: table_index - Where table index is returned
622 * table_desc - Where table descriptor is returned
624 * RETURN: Status and table index/descriptor.
626 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
628 ******************************************************************************/
631 acpi_tb_get_next_table_descriptor(u32
*table_index
,
632 struct acpi_table_desc
**table_desc
)
637 /* Ensure that there is room for the table in the Root Table List */
639 if (acpi_gbl_root_table_list
.current_table_count
>=
640 acpi_gbl_root_table_list
.max_table_count
) {
641 status
= acpi_tb_resize_root_table_list();
642 if (ACPI_FAILURE(status
)) {
647 i
= acpi_gbl_root_table_list
.current_table_count
;
648 acpi_gbl_root_table_list
.current_table_count
++;
654 *table_desc
= &acpi_gbl_root_table_list
.tables
[i
];
660 /*******************************************************************************
662 * FUNCTION: acpi_tb_terminate
668 * DESCRIPTION: Delete all internal ACPI tables
670 ******************************************************************************/
672 void acpi_tb_terminate(void)
676 ACPI_FUNCTION_TRACE(tb_terminate
);
678 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
680 /* Delete the individual tables */
682 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; i
++) {
683 acpi_tb_uninstall_table(&acpi_gbl_root_table_list
.tables
[i
]);
687 * Delete the root table array if allocated locally. Array cannot be
688 * mapped, so we don't need to check for that flag.
690 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
691 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
694 acpi_gbl_root_table_list
.tables
= NULL
;
695 acpi_gbl_root_table_list
.flags
= 0;
696 acpi_gbl_root_table_list
.current_table_count
= 0;
698 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "ACPI Tables freed\n"));
700 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
704 /*******************************************************************************
706 * FUNCTION: acpi_tb_delete_namespace_by_owner
708 * PARAMETERS: table_index - Table index
712 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
714 ******************************************************************************/
716 acpi_status
acpi_tb_delete_namespace_by_owner(u32 table_index
)
718 acpi_owner_id owner_id
;
721 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner
);
723 status
= acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
724 if (ACPI_FAILURE(status
)) {
725 return_ACPI_STATUS(status
);
728 if (table_index
>= acpi_gbl_root_table_list
.current_table_count
) {
730 /* The table index does not exist */
732 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
733 return_ACPI_STATUS(AE_NOT_EXIST
);
736 /* Get the owner ID for this table, used to delete namespace nodes */
738 owner_id
= acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
739 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
742 * Need to acquire the namespace writer lock to prevent interference
743 * with any concurrent namespace walks. The interpreter must be
744 * released during the deletion since the acquisition of the deletion
745 * lock may block, and also since the execution of a namespace walk
746 * must be allowed to use the interpreter.
748 status
= acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock
);
749 if (ACPI_FAILURE(status
)) {
750 return_ACPI_STATUS(status
);
752 acpi_ns_delete_namespace_by_owner(owner_id
);
753 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock
);
754 return_ACPI_STATUS(status
);
757 /*******************************************************************************
759 * FUNCTION: acpi_tb_allocate_owner_id
761 * PARAMETERS: table_index - Table index
765 * DESCRIPTION: Allocates owner_id in table_desc
767 ******************************************************************************/
769 acpi_status
acpi_tb_allocate_owner_id(u32 table_index
)
771 acpi_status status
= AE_BAD_PARAMETER
;
773 ACPI_FUNCTION_TRACE(tb_allocate_owner_id
);
775 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
776 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
778 acpi_ut_allocate_owner_id(&
779 (acpi_gbl_root_table_list
.
780 tables
[table_index
].owner_id
));
783 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
784 return_ACPI_STATUS(status
);
787 /*******************************************************************************
789 * FUNCTION: acpi_tb_release_owner_id
791 * PARAMETERS: table_index - Table index
795 * DESCRIPTION: Releases owner_id in table_desc
797 ******************************************************************************/
799 acpi_status
acpi_tb_release_owner_id(u32 table_index
)
801 acpi_status status
= AE_BAD_PARAMETER
;
803 ACPI_FUNCTION_TRACE(tb_release_owner_id
);
805 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
806 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
807 acpi_ut_release_owner_id(&
808 (acpi_gbl_root_table_list
.
809 tables
[table_index
].owner_id
));
813 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
814 return_ACPI_STATUS(status
);
817 /*******************************************************************************
819 * FUNCTION: acpi_tb_get_owner_id
821 * PARAMETERS: table_index - Table index
822 * owner_id - Where the table owner_id is returned
826 * DESCRIPTION: returns owner_id for the ACPI table
828 ******************************************************************************/
830 acpi_status
acpi_tb_get_owner_id(u32 table_index
, acpi_owner_id
*owner_id
)
832 acpi_status status
= AE_BAD_PARAMETER
;
834 ACPI_FUNCTION_TRACE(tb_get_owner_id
);
836 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
837 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
839 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
843 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
844 return_ACPI_STATUS(status
);
847 /*******************************************************************************
849 * FUNCTION: acpi_tb_is_table_loaded
851 * PARAMETERS: table_index - Index into the root table
853 * RETURN: Table Loaded Flag
855 ******************************************************************************/
857 u8
acpi_tb_is_table_loaded(u32 table_index
)
859 u8 is_loaded
= FALSE
;
861 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
862 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
864 (acpi_gbl_root_table_list
.tables
[table_index
].flags
&
865 ACPI_TABLE_IS_LOADED
);
868 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
872 /*******************************************************************************
874 * FUNCTION: acpi_tb_set_table_loaded_flag
876 * PARAMETERS: table_index - Table index
877 * is_loaded - TRUE if table is loaded, FALSE otherwise
881 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
883 ******************************************************************************/
885 void acpi_tb_set_table_loaded_flag(u32 table_index
, u8 is_loaded
)
888 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
889 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
891 acpi_gbl_root_table_list
.tables
[table_index
].flags
|=
892 ACPI_TABLE_IS_LOADED
;
894 acpi_gbl_root_table_list
.tables
[table_index
].flags
&=
895 ~ACPI_TABLE_IS_LOADED
;
899 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
902 /*******************************************************************************
904 * FUNCTION: acpi_tb_load_table
906 * PARAMETERS: table_index - Table index
907 * parent_node - Where table index is returned
911 * DESCRIPTION: Load an ACPI table
913 ******************************************************************************/
916 acpi_tb_load_table(u32 table_index
, struct acpi_namespace_node
*parent_node
)
918 struct acpi_table_header
*table
;
920 acpi_owner_id owner_id
;
922 ACPI_FUNCTION_TRACE(tb_load_table
);
925 * Note: Now table is "INSTALLED", it must be validated before
928 status
= acpi_get_table_by_index(table_index
, &table
);
929 if (ACPI_FAILURE(status
)) {
930 return_ACPI_STATUS(status
);
933 status
= acpi_ns_load_table(table_index
, parent_node
);
936 * This case handles the legacy option that groups all module-level
937 * code blocks together and defers execution until all of the tables
938 * are loaded. Execute all of these blocks at this time.
939 * Execute any module-level code that was detected during the table
942 * Note: this option is deprecated and will be eliminated in the
943 * future. Use of this option can cause problems with AML code that
944 * depends upon in-order immediate execution of module-level code.
946 acpi_ns_exec_module_code_list();
949 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
950 * responsible for discovering any new wake GPEs by running _PRW methods
951 * that may have been loaded by this table.
953 status
= acpi_tb_get_owner_id(table_index
, &owner_id
);
954 if (ACPI_SUCCESS(status
)) {
955 acpi_ev_update_gpes(owner_id
);
958 /* Invoke table handler */
960 acpi_tb_notify_table(ACPI_TABLE_EVENT_LOAD
, table
);
961 return_ACPI_STATUS(status
);
964 /*******************************************************************************
966 * FUNCTION: acpi_tb_install_and_load_table
968 * PARAMETERS: address - Physical address of the table
969 * flags - Allocation flags of the table
970 * override - Whether override should be performed
971 * table_index - Where table index is returned
975 * DESCRIPTION: Install and load an ACPI table
977 ******************************************************************************/
980 acpi_tb_install_and_load_table(acpi_physical_address address
,
981 u8 flags
, u8 override
, u32
*table_index
)
986 ACPI_FUNCTION_TRACE(tb_install_and_load_table
);
988 /* Install the table and load it into the namespace */
990 status
= acpi_tb_install_standard_table(address
, flags
, TRUE
,
992 if (ACPI_FAILURE(status
)) {
996 status
= acpi_tb_load_table(i
, acpi_gbl_root_node
);
1000 return_ACPI_STATUS(status
);
1003 ACPI_EXPORT_SYMBOL(acpi_tb_install_and_load_table
)
1005 /*******************************************************************************
1007 * FUNCTION: acpi_tb_unload_table
1009 * PARAMETERS: table_index - Table index
1013 * DESCRIPTION: Unload an ACPI table
1015 ******************************************************************************/
1017 acpi_status
acpi_tb_unload_table(u32 table_index
)
1019 acpi_status status
= AE_OK
;
1020 struct acpi_table_header
*table
;
1022 ACPI_FUNCTION_TRACE(tb_unload_table
);
1024 /* Ensure the table is still loaded */
1026 if (!acpi_tb_is_table_loaded(table_index
)) {
1027 return_ACPI_STATUS(AE_NOT_EXIST
);
1030 /* Invoke table handler */
1032 status
= acpi_get_table_by_index(table_index
, &table
);
1033 if (ACPI_SUCCESS(status
)) {
1034 acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD
, table
);
1037 /* Delete the portion of the namespace owned by this table */
1039 status
= acpi_tb_delete_namespace_by_owner(table_index
);
1040 if (ACPI_FAILURE(status
)) {
1041 return_ACPI_STATUS(status
);
1044 (void)acpi_tb_release_owner_id(table_index
);
1045 acpi_tb_set_table_loaded_flag(table_index
, FALSE
);
1046 return_ACPI_STATUS(status
);
1049 ACPI_EXPORT_SYMBOL(acpi_tb_unload_table
)
1051 /*******************************************************************************
1053 * FUNCTION: acpi_tb_notify_table
1055 * PARAMETERS: event - Table event
1056 * table - Validated table pointer
1060 * DESCRIPTION: Notify a table event to the users.
1062 ******************************************************************************/
1064 void acpi_tb_notify_table(u32 event
, void *table
)
1066 /* Invoke table handler if present */
1068 if (acpi_gbl_table_handler
) {
1069 (void)acpi_gbl_table_handler(event
, table
,
1070 acpi_gbl_table_handler_context
);