Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / acpi / acpica / tbdata.c
blobec69267f1447a24aa7dd8e6bf952b2572e80aaad
1 /******************************************************************************
3 * Module Name: tbdata - Table manager data structure functions
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 "accommon.h"
46 #include "acnamesp.h"
47 #include "actables.h"
48 #include "acevents.h"
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME("tbdata")
53 /* Local prototypes */
54 static acpi_status
55 acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index);
57 static u8
58 acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
60 /*******************************************************************************
62 * FUNCTION: acpi_tb_compare_tables
64 * PARAMETERS: table_desc - Table 1 descriptor to be compared
65 * table_index - Index of table 2 to be compared
67 * RETURN: TRUE if both tables are identical.
69 * DESCRIPTION: This function compares a table with another table that has
70 * already been installed in the root table list.
72 ******************************************************************************/
74 static u8
75 acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
77 acpi_status status = AE_OK;
78 u8 is_identical;
79 struct acpi_table_header *table;
80 u32 table_length;
81 u8 table_flags;
83 status =
84 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
85 &table, &table_length, &table_flags);
86 if (ACPI_FAILURE(status)) {
87 return (FALSE);
91 * Check for a table match on the entire table length,
92 * not just the header.
94 is_identical = (u8)((table_desc->length != table_length ||
95 memcmp(table_desc->pointer, table, table_length)) ?
96 FALSE : TRUE);
98 /* Release the acquired table */
100 acpi_tb_release_table(table, table_length, table_flags);
101 return (is_identical);
104 /*******************************************************************************
106 * FUNCTION: acpi_tb_init_table_descriptor
108 * PARAMETERS: table_desc - Table descriptor
109 * address - Physical address of the table
110 * flags - Allocation flags of the table
111 * table - Pointer to the table
113 * RETURN: None
115 * DESCRIPTION: Initialize a new table descriptor
117 ******************************************************************************/
119 void
120 acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc,
121 acpi_physical_address address,
122 u8 flags, struct acpi_table_header *table)
126 * Initialize the table descriptor. Set the pointer to NULL, since the
127 * table is not fully mapped at this time.
129 memset(table_desc, 0, sizeof(struct acpi_table_desc));
130 table_desc->address = address;
131 table_desc->length = table->length;
132 table_desc->flags = flags;
133 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
136 /*******************************************************************************
138 * FUNCTION: acpi_tb_acquire_table
140 * PARAMETERS: table_desc - Table descriptor
141 * table_ptr - Where table is returned
142 * table_length - Where table length is returned
143 * table_flags - Where table allocation flags are returned
145 * RETURN: Status
147 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
148 * maintained in the acpi_gbl_root_table_list.
150 ******************************************************************************/
152 acpi_status
153 acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
154 struct acpi_table_header **table_ptr,
155 u32 *table_length, u8 *table_flags)
157 struct acpi_table_header *table = NULL;
159 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
160 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
162 table =
163 acpi_os_map_memory(table_desc->address, table_desc->length);
164 break;
166 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
167 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
169 table = ACPI_CAST_PTR(struct acpi_table_header,
170 ACPI_PHYSADDR_TO_PTR(table_desc->
171 address));
172 break;
174 default:
176 break;
179 /* Table is not valid yet */
181 if (!table) {
182 return (AE_NO_MEMORY);
185 /* Fill the return values */
187 *table_ptr = table;
188 *table_length = table_desc->length;
189 *table_flags = table_desc->flags;
190 return (AE_OK);
193 /*******************************************************************************
195 * FUNCTION: acpi_tb_release_table
197 * PARAMETERS: table - Pointer for the table
198 * table_length - Length for the table
199 * table_flags - Allocation flags for the table
201 * RETURN: None
203 * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
205 ******************************************************************************/
207 void
208 acpi_tb_release_table(struct acpi_table_header *table,
209 u32 table_length, u8 table_flags)
212 switch (table_flags & ACPI_TABLE_ORIGIN_MASK) {
213 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
215 acpi_os_unmap_memory(table, table_length);
216 break;
218 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
219 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
220 default:
222 break;
226 /*******************************************************************************
228 * FUNCTION: acpi_tb_acquire_temp_table
230 * PARAMETERS: table_desc - Table descriptor to be acquired
231 * address - Address of the table
232 * flags - Allocation flags of the table
234 * RETURN: Status
236 * DESCRIPTION: This function validates the table header to obtain the length
237 * of a table and fills the table descriptor to make its state as
238 * "INSTALLED". Such a table descriptor is only used for verified
239 * installation.
241 ******************************************************************************/
243 acpi_status
244 acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc,
245 acpi_physical_address address, u8 flags)
247 struct acpi_table_header *table_header;
249 switch (flags & ACPI_TABLE_ORIGIN_MASK) {
250 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
252 /* Get the length of the full table from the header */
254 table_header =
255 acpi_os_map_memory(address,
256 sizeof(struct acpi_table_header));
257 if (!table_header) {
258 return (AE_NO_MEMORY);
261 acpi_tb_init_table_descriptor(table_desc, address, flags,
262 table_header);
263 acpi_os_unmap_memory(table_header,
264 sizeof(struct acpi_table_header));
265 return (AE_OK);
267 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
268 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
270 table_header = ACPI_CAST_PTR(struct acpi_table_header,
271 ACPI_PHYSADDR_TO_PTR(address));
272 if (!table_header) {
273 return (AE_NO_MEMORY);
276 acpi_tb_init_table_descriptor(table_desc, address, flags,
277 table_header);
278 return (AE_OK);
280 default:
282 break;
285 /* Table is not valid yet */
287 return (AE_NO_MEMORY);
290 /*******************************************************************************
292 * FUNCTION: acpi_tb_release_temp_table
294 * PARAMETERS: table_desc - Table descriptor to be released
296 * RETURN: Status
298 * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
300 *****************************************************************************/
302 void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc)
306 * Note that the .Address is maintained by the callers of
307 * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
308 * where .Address will be freed.
310 acpi_tb_invalidate_table(table_desc);
313 /******************************************************************************
315 * FUNCTION: acpi_tb_validate_table
317 * PARAMETERS: table_desc - Table descriptor
319 * RETURN: Status
321 * DESCRIPTION: This function is called to validate the table, the returned
322 * table descriptor is in "VALIDATED" state.
324 *****************************************************************************/
326 acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
328 acpi_status status = AE_OK;
330 ACPI_FUNCTION_TRACE(tb_validate_table);
332 /* Validate the table if necessary */
334 if (!table_desc->pointer) {
335 status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
336 &table_desc->length,
337 &table_desc->flags);
338 if (!table_desc->pointer) {
339 status = AE_NO_MEMORY;
343 return_ACPI_STATUS(status);
346 /*******************************************************************************
348 * FUNCTION: acpi_tb_invalidate_table
350 * PARAMETERS: table_desc - Table descriptor
352 * RETURN: None
354 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
355 * acpi_tb_validate_table().
357 ******************************************************************************/
359 void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
362 ACPI_FUNCTION_TRACE(tb_invalidate_table);
364 /* Table must be validated */
366 if (!table_desc->pointer) {
367 return_VOID;
370 acpi_tb_release_table(table_desc->pointer, table_desc->length,
371 table_desc->flags);
372 table_desc->pointer = NULL;
374 return_VOID;
377 /******************************************************************************
379 * FUNCTION: acpi_tb_validate_temp_table
381 * PARAMETERS: table_desc - Table descriptor
383 * RETURN: Status
385 * DESCRIPTION: This function is called to validate the table, the returned
386 * table descriptor is in "VALIDATED" state.
388 *****************************************************************************/
390 acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc)
393 if (!table_desc->pointer && !acpi_gbl_enable_table_validation) {
395 * Only validates the header of the table.
396 * Note that Length contains the size of the mapping after invoking
397 * this work around, this value is required by
398 * acpi_tb_release_temp_table().
399 * We can do this because in acpi_init_table_descriptor(), the Length
400 * field of the installed descriptor is filled with the actual
401 * table length obtaining from the table header.
403 table_desc->length = sizeof(struct acpi_table_header);
406 return (acpi_tb_validate_table(table_desc));
409 /*******************************************************************************
411 * FUNCTION: acpi_tb_check_duplication
413 * PARAMETERS: table_desc - Table descriptor
414 * table_index - Where the table index is returned
416 * RETURN: Status
418 * DESCRIPTION: Avoid installing duplicated tables. However table override and
419 * user aided dynamic table load is allowed, thus comparing the
420 * address of the table is not sufficient, and checking the entire
421 * table content is required.
423 ******************************************************************************/
425 static acpi_status
426 acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index)
428 u32 i;
430 ACPI_FUNCTION_TRACE(tb_check_duplication);
432 /* Check if table is already registered */
434 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
436 /* Do not compare with unverified tables */
438 if (!
439 (acpi_gbl_root_table_list.tables[i].
440 flags & ACPI_TABLE_IS_VERIFIED)) {
441 continue;
445 * Check for a table match on the entire table length,
446 * not just the header.
448 if (!acpi_tb_compare_tables(table_desc, i)) {
449 continue;
453 * Note: the current mechanism does not unregister a table if it is
454 * dynamically unloaded. The related namespace entries are deleted,
455 * but the table remains in the root table list.
457 * The assumption here is that the number of different tables that
458 * will be loaded is actually small, and there is minimal overhead
459 * in just keeping the table in case it is needed again.
461 * If this assumption changes in the future (perhaps on large
462 * machines with many table load/unload operations), tables will
463 * need to be unregistered when they are unloaded, and slots in the
464 * root table list should be reused when empty.
466 if (acpi_gbl_root_table_list.tables[i].flags &
467 ACPI_TABLE_IS_LOADED) {
469 /* Table is still loaded, this is an error */
471 return_ACPI_STATUS(AE_ALREADY_EXISTS);
472 } else {
473 *table_index = i;
474 return_ACPI_STATUS(AE_CTRL_TERMINATE);
478 /* Indicate no duplication to the caller */
480 return_ACPI_STATUS(AE_OK);
483 /******************************************************************************
485 * FUNCTION: acpi_tb_verify_temp_table
487 * PARAMETERS: table_desc - Table descriptor
488 * signature - Table signature to verify
489 * table_index - Where the table index is returned
491 * RETURN: Status
493 * DESCRIPTION: This function is called to validate and verify the table, the
494 * returned table descriptor is in "VALIDATED" state.
495 * Note that 'TableIndex' is required to be set to !NULL to
496 * enable duplication check.
498 *****************************************************************************/
500 acpi_status
501 acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc,
502 char *signature, u32 *table_index)
504 acpi_status status = AE_OK;
506 ACPI_FUNCTION_TRACE(tb_verify_temp_table);
508 /* Validate the table */
510 status = acpi_tb_validate_temp_table(table_desc);
511 if (ACPI_FAILURE(status)) {
512 return_ACPI_STATUS(AE_NO_MEMORY);
515 /* If a particular signature is expected (DSDT/FACS), it must match */
517 if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
518 ACPI_BIOS_ERROR((AE_INFO,
519 "Invalid signature 0x%X for ACPI table, expected [%s]",
520 table_desc->signature.integer, signature));
521 status = AE_BAD_SIGNATURE;
522 goto invalidate_and_exit;
525 if (acpi_gbl_enable_table_validation) {
527 /* Verify the checksum */
529 status =
530 acpi_tb_verify_checksum(table_desc->pointer,
531 table_desc->length);
532 if (ACPI_FAILURE(status)) {
533 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
534 "%4.4s 0x%8.8X%8.8X"
535 " Attempted table install failed",
536 acpi_ut_valid_nameseg(table_desc->
537 signature.
538 ascii) ?
539 table_desc->signature.ascii : "????",
540 ACPI_FORMAT_UINT64(table_desc->
541 address)));
543 goto invalidate_and_exit;
546 /* Avoid duplications */
548 if (table_index) {
549 status =
550 acpi_tb_check_duplication(table_desc, table_index);
551 if (ACPI_FAILURE(status)) {
552 if (status != AE_CTRL_TERMINATE) {
553 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
554 "%4.4s 0x%8.8X%8.8X"
555 " Table is duplicated",
556 acpi_ut_valid_nameseg
557 (table_desc->signature.
558 ascii) ? table_desc->
559 signature.
560 ascii : "????",
561 ACPI_FORMAT_UINT64
562 (table_desc->address)));
565 goto invalidate_and_exit;
569 table_desc->flags |= ACPI_TABLE_IS_VERIFIED;
572 return_ACPI_STATUS(status);
574 invalidate_and_exit:
575 acpi_tb_invalidate_table(table_desc);
576 return_ACPI_STATUS(status);
579 /*******************************************************************************
581 * FUNCTION: acpi_tb_resize_root_table_list
583 * PARAMETERS: None
585 * RETURN: Status
587 * DESCRIPTION: Expand the size of global table array
589 ******************************************************************************/
591 acpi_status acpi_tb_resize_root_table_list(void)
593 struct acpi_table_desc *tables;
594 u32 table_count;
595 u32 current_table_count, max_table_count;
596 u32 i;
598 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
600 /* allow_resize flag is a parameter to acpi_initialize_tables */
602 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
603 ACPI_ERROR((AE_INFO,
604 "Resize of Root Table Array is not allowed"));
605 return_ACPI_STATUS(AE_SUPPORT);
608 /* Increase the Table Array size */
610 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
611 table_count = acpi_gbl_root_table_list.max_table_count;
612 } else {
613 table_count = acpi_gbl_root_table_list.current_table_count;
616 max_table_count = table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
617 tables = ACPI_ALLOCATE_ZEROED(((acpi_size)max_table_count) *
618 sizeof(struct acpi_table_desc));
619 if (!tables) {
620 ACPI_ERROR((AE_INFO,
621 "Could not allocate new root table array"));
622 return_ACPI_STATUS(AE_NO_MEMORY);
625 /* Copy and free the previous table array */
627 current_table_count = 0;
628 if (acpi_gbl_root_table_list.tables) {
629 for (i = 0; i < table_count; i++) {
630 if (acpi_gbl_root_table_list.tables[i].address) {
631 memcpy(tables + current_table_count,
632 acpi_gbl_root_table_list.tables + i,
633 sizeof(struct acpi_table_desc));
634 current_table_count++;
638 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
639 ACPI_FREE(acpi_gbl_root_table_list.tables);
643 acpi_gbl_root_table_list.tables = tables;
644 acpi_gbl_root_table_list.max_table_count = max_table_count;
645 acpi_gbl_root_table_list.current_table_count = current_table_count;
646 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
648 return_ACPI_STATUS(AE_OK);
651 /*******************************************************************************
653 * FUNCTION: acpi_tb_get_next_table_descriptor
655 * PARAMETERS: table_index - Where table index is returned
656 * table_desc - Where table descriptor is returned
658 * RETURN: Status and table index/descriptor.
660 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
662 ******************************************************************************/
664 acpi_status
665 acpi_tb_get_next_table_descriptor(u32 *table_index,
666 struct acpi_table_desc **table_desc)
668 acpi_status status;
669 u32 i;
671 /* Ensure that there is room for the table in the Root Table List */
673 if (acpi_gbl_root_table_list.current_table_count >=
674 acpi_gbl_root_table_list.max_table_count) {
675 status = acpi_tb_resize_root_table_list();
676 if (ACPI_FAILURE(status)) {
677 return (status);
681 i = acpi_gbl_root_table_list.current_table_count;
682 acpi_gbl_root_table_list.current_table_count++;
684 if (table_index) {
685 *table_index = i;
687 if (table_desc) {
688 *table_desc = &acpi_gbl_root_table_list.tables[i];
691 return (AE_OK);
694 /*******************************************************************************
696 * FUNCTION: acpi_tb_terminate
698 * PARAMETERS: None
700 * RETURN: None
702 * DESCRIPTION: Delete all internal ACPI tables
704 ******************************************************************************/
706 void acpi_tb_terminate(void)
708 u32 i;
710 ACPI_FUNCTION_TRACE(tb_terminate);
712 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
714 /* Delete the individual tables */
716 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
717 acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
721 * Delete the root table array if allocated locally. Array cannot be
722 * mapped, so we don't need to check for that flag.
724 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
725 ACPI_FREE(acpi_gbl_root_table_list.tables);
728 acpi_gbl_root_table_list.tables = NULL;
729 acpi_gbl_root_table_list.flags = 0;
730 acpi_gbl_root_table_list.current_table_count = 0;
732 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
734 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
735 return_VOID;
738 /*******************************************************************************
740 * FUNCTION: acpi_tb_delete_namespace_by_owner
742 * PARAMETERS: table_index - Table index
744 * RETURN: Status
746 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
748 ******************************************************************************/
750 acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
752 acpi_owner_id owner_id;
753 acpi_status status;
755 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
757 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
758 if (ACPI_FAILURE(status)) {
759 return_ACPI_STATUS(status);
762 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
764 /* The table index does not exist */
766 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
767 return_ACPI_STATUS(AE_NOT_EXIST);
770 /* Get the owner ID for this table, used to delete namespace nodes */
772 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
773 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
776 * Need to acquire the namespace writer lock to prevent interference
777 * with any concurrent namespace walks. The interpreter must be
778 * released during the deletion since the acquisition of the deletion
779 * lock may block, and also since the execution of a namespace walk
780 * must be allowed to use the interpreter.
782 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
783 if (ACPI_FAILURE(status)) {
784 return_ACPI_STATUS(status);
786 acpi_ns_delete_namespace_by_owner(owner_id);
787 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
788 return_ACPI_STATUS(status);
791 /*******************************************************************************
793 * FUNCTION: acpi_tb_allocate_owner_id
795 * PARAMETERS: table_index - Table index
797 * RETURN: Status
799 * DESCRIPTION: Allocates owner_id in table_desc
801 ******************************************************************************/
803 acpi_status acpi_tb_allocate_owner_id(u32 table_index)
805 acpi_status status = AE_BAD_PARAMETER;
807 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
809 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
810 if (table_index < acpi_gbl_root_table_list.current_table_count) {
811 status =
812 acpi_ut_allocate_owner_id(&
813 (acpi_gbl_root_table_list.
814 tables[table_index].owner_id));
817 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
818 return_ACPI_STATUS(status);
821 /*******************************************************************************
823 * FUNCTION: acpi_tb_release_owner_id
825 * PARAMETERS: table_index - Table index
827 * RETURN: Status
829 * DESCRIPTION: Releases owner_id in table_desc
831 ******************************************************************************/
833 acpi_status acpi_tb_release_owner_id(u32 table_index)
835 acpi_status status = AE_BAD_PARAMETER;
837 ACPI_FUNCTION_TRACE(tb_release_owner_id);
839 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
840 if (table_index < acpi_gbl_root_table_list.current_table_count) {
841 acpi_ut_release_owner_id(&
842 (acpi_gbl_root_table_list.
843 tables[table_index].owner_id));
844 status = AE_OK;
847 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
848 return_ACPI_STATUS(status);
851 /*******************************************************************************
853 * FUNCTION: acpi_tb_get_owner_id
855 * PARAMETERS: table_index - Table index
856 * owner_id - Where the table owner_id is returned
858 * RETURN: Status
860 * DESCRIPTION: returns owner_id for the ACPI table
862 ******************************************************************************/
864 acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
866 acpi_status status = AE_BAD_PARAMETER;
868 ACPI_FUNCTION_TRACE(tb_get_owner_id);
870 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
871 if (table_index < acpi_gbl_root_table_list.current_table_count) {
872 *owner_id =
873 acpi_gbl_root_table_list.tables[table_index].owner_id;
874 status = AE_OK;
877 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
878 return_ACPI_STATUS(status);
881 /*******************************************************************************
883 * FUNCTION: acpi_tb_is_table_loaded
885 * PARAMETERS: table_index - Index into the root table
887 * RETURN: Table Loaded Flag
889 ******************************************************************************/
891 u8 acpi_tb_is_table_loaded(u32 table_index)
893 u8 is_loaded = FALSE;
895 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
896 if (table_index < acpi_gbl_root_table_list.current_table_count) {
897 is_loaded = (u8)
898 (acpi_gbl_root_table_list.tables[table_index].flags &
899 ACPI_TABLE_IS_LOADED);
902 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
903 return (is_loaded);
906 /*******************************************************************************
908 * FUNCTION: acpi_tb_set_table_loaded_flag
910 * PARAMETERS: table_index - Table index
911 * is_loaded - TRUE if table is loaded, FALSE otherwise
913 * RETURN: None
915 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
917 ******************************************************************************/
919 void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
922 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
923 if (table_index < acpi_gbl_root_table_list.current_table_count) {
924 if (is_loaded) {
925 acpi_gbl_root_table_list.tables[table_index].flags |=
926 ACPI_TABLE_IS_LOADED;
927 } else {
928 acpi_gbl_root_table_list.tables[table_index].flags &=
929 ~ACPI_TABLE_IS_LOADED;
933 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
936 /*******************************************************************************
938 * FUNCTION: acpi_tb_load_table
940 * PARAMETERS: table_index - Table index
941 * parent_node - Where table index is returned
943 * RETURN: Status
945 * DESCRIPTION: Load an ACPI table
947 ******************************************************************************/
949 acpi_status
950 acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node)
952 struct acpi_table_header *table;
953 acpi_status status;
954 acpi_owner_id owner_id;
956 ACPI_FUNCTION_TRACE(tb_load_table);
959 * Note: Now table is "INSTALLED", it must be validated before
960 * using.
962 status = acpi_get_table_by_index(table_index, &table);
963 if (ACPI_FAILURE(status)) {
964 return_ACPI_STATUS(status);
967 status = acpi_ns_load_table(table_index, parent_node);
969 /* Execute any module-level code that was found in the table */
971 if (!acpi_gbl_parse_table_as_term_list
972 && acpi_gbl_group_module_level_code) {
973 acpi_ns_exec_module_code_list();
977 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
978 * responsible for discovering any new wake GPEs by running _PRW methods
979 * that may have been loaded by this table.
981 status = acpi_tb_get_owner_id(table_index, &owner_id);
982 if (ACPI_SUCCESS(status)) {
983 acpi_ev_update_gpes(owner_id);
986 /* Invoke table handler */
988 acpi_tb_notify_table(ACPI_TABLE_EVENT_LOAD, table);
989 return_ACPI_STATUS(status);
992 /*******************************************************************************
994 * FUNCTION: acpi_tb_install_and_load_table
996 * PARAMETERS: address - Physical address of the table
997 * flags - Allocation flags of the table
998 * override - Whether override should be performed
999 * table_index - Where table index is returned
1001 * RETURN: Status
1003 * DESCRIPTION: Install and load an ACPI table
1005 ******************************************************************************/
1007 acpi_status
1008 acpi_tb_install_and_load_table(acpi_physical_address address,
1009 u8 flags, u8 override, u32 *table_index)
1011 acpi_status status;
1012 u32 i;
1014 ACPI_FUNCTION_TRACE(tb_install_and_load_table);
1016 /* Install the table and load it into the namespace */
1018 status = acpi_tb_install_standard_table(address, flags, TRUE,
1019 override, &i);
1020 if (ACPI_FAILURE(status)) {
1021 goto exit;
1024 status = acpi_tb_load_table(i, acpi_gbl_root_node);
1026 exit:
1027 *table_index = i;
1028 return_ACPI_STATUS(status);
1031 ACPI_EXPORT_SYMBOL(acpi_tb_install_and_load_table)
1033 /*******************************************************************************
1035 * FUNCTION: acpi_tb_unload_table
1037 * PARAMETERS: table_index - Table index
1039 * RETURN: Status
1041 * DESCRIPTION: Unload an ACPI table
1043 ******************************************************************************/
1045 acpi_status acpi_tb_unload_table(u32 table_index)
1047 acpi_status status = AE_OK;
1048 struct acpi_table_header *table;
1050 ACPI_FUNCTION_TRACE(tb_unload_table);
1052 /* Ensure the table is still loaded */
1054 if (!acpi_tb_is_table_loaded(table_index)) {
1055 return_ACPI_STATUS(AE_NOT_EXIST);
1058 /* Invoke table handler */
1060 status = acpi_get_table_by_index(table_index, &table);
1061 if (ACPI_SUCCESS(status)) {
1062 acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table);
1065 /* Delete the portion of the namespace owned by this table */
1067 status = acpi_tb_delete_namespace_by_owner(table_index);
1068 if (ACPI_FAILURE(status)) {
1069 return_ACPI_STATUS(status);
1072 (void)acpi_tb_release_owner_id(table_index);
1073 acpi_tb_set_table_loaded_flag(table_index, FALSE);
1074 return_ACPI_STATUS(status);
1077 ACPI_EXPORT_SYMBOL(acpi_tb_unload_table)
1079 /*******************************************************************************
1081 * FUNCTION: acpi_tb_notify_table
1083 * PARAMETERS: event - Table event
1084 * table - Validated table pointer
1086 * RETURN: None
1088 * DESCRIPTION: Notify a table event to the users.
1090 ******************************************************************************/
1092 void acpi_tb_notify_table(u32 event, void *table)
1094 /* Invoke table handler if present */
1096 if (acpi_gbl_table_handler) {
1097 (void)acpi_gbl_table_handler(event, table,
1098 acpi_gbl_table_handler_context);