1 /******************************************************************************
3 * Module Name: tbdata - Table manager data structure functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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("tbdata")
52 /*******************************************************************************
54 * FUNCTION: acpi_tb_init_table_descriptor
56 * PARAMETERS: table_desc - Table descriptor
57 * address - Physical address of the table
58 * flags - Allocation flags of the table
59 * table - Pointer to the table
63 * DESCRIPTION: Initialize a new table descriptor
65 ******************************************************************************/
67 acpi_tb_init_table_descriptor(struct acpi_table_desc
*table_desc
,
68 acpi_physical_address address
,
69 u8 flags
, struct acpi_table_header
*table
)
73 * Initialize the table descriptor. Set the pointer to NULL, since the
74 * table is not fully mapped at this time.
76 ACPI_MEMSET(table_desc
, 0, sizeof(struct acpi_table_desc
));
77 table_desc
->address
= address
;
78 table_desc
->length
= table
->length
;
79 table_desc
->flags
= flags
;
80 ACPI_MOVE_32_TO_32(table_desc
->signature
.ascii
, table
->signature
);
83 /*******************************************************************************
85 * FUNCTION: acpi_tb_acquire_table
87 * PARAMETERS: table_desc - Table descriptor
88 * table_ptr - Where table is returned
89 * table_length - Where table length is returned
90 * table_flags - Where table allocation flags are returned
94 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
95 * maintained in the acpi_gbl_root_table_list.
97 ******************************************************************************/
100 acpi_tb_acquire_table(struct acpi_table_desc
*table_desc
,
101 struct acpi_table_header
**table_ptr
,
102 u32
*table_length
, u8
*table_flags
)
104 struct acpi_table_header
*table
= NULL
;
106 switch (table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) {
107 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
:
110 acpi_os_map_memory(table_desc
->address
, table_desc
->length
);
113 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
:
114 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
:
117 ACPI_CAST_PTR(struct acpi_table_header
,
118 table_desc
->address
);
126 /* Table is not valid yet */
129 return (AE_NO_MEMORY
);
132 /* Fill the return values */
135 *table_length
= table_desc
->length
;
136 *table_flags
= table_desc
->flags
;
140 /*******************************************************************************
142 * FUNCTION: acpi_tb_release_table
144 * PARAMETERS: table - Pointer for the table
145 * table_length - Length for the table
146 * table_flags - Allocation flags for the table
150 * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
152 ******************************************************************************/
155 acpi_tb_release_table(struct acpi_table_header
*table
,
156 u32 table_length
, u8 table_flags
)
159 switch (table_flags
& ACPI_TABLE_ORIGIN_MASK
) {
160 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
:
162 acpi_os_unmap_memory(table
, table_length
);
165 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
:
166 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
:
173 /*******************************************************************************
175 * FUNCTION: acpi_tb_acquire_temp_table
177 * PARAMETERS: table_desc - Table descriptor to be acquired
178 * address - Address of the table
179 * flags - Allocation flags of the table
183 * DESCRIPTION: This function validates the table header to obtain the length
184 * of a table and fills the table descriptor to make its state as
185 * "INSTALLED". Such a table descriptor is only used for verified
188 ******************************************************************************/
191 acpi_tb_acquire_temp_table(struct acpi_table_desc
*table_desc
,
192 acpi_physical_address address
, u8 flags
)
194 struct acpi_table_header
*table_header
;
196 switch (flags
& ACPI_TABLE_ORIGIN_MASK
) {
197 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
:
199 /* Get the length of the full table from the header */
202 acpi_os_map_memory(address
,
203 sizeof(struct acpi_table_header
));
205 return (AE_NO_MEMORY
);
208 acpi_tb_init_table_descriptor(table_desc
, address
, flags
,
210 acpi_os_unmap_memory(table_header
,
211 sizeof(struct acpi_table_header
));
214 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
:
215 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
:
217 table_header
= ACPI_CAST_PTR(struct acpi_table_header
, address
);
219 return (AE_NO_MEMORY
);
222 acpi_tb_init_table_descriptor(table_desc
, address
, flags
,
231 /* Table is not valid yet */
233 return (AE_NO_MEMORY
);
236 /*******************************************************************************
238 * FUNCTION: acpi_tb_release_temp_table
240 * PARAMETERS: table_desc - Table descriptor to be released
244 * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
246 *****************************************************************************/
248 void acpi_tb_release_temp_table(struct acpi_table_desc
*table_desc
)
252 * Note that the .Address is maintained by the callers of
253 * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
254 * where .Address will be freed.
256 acpi_tb_invalidate_table(table_desc
);
259 /******************************************************************************
261 * FUNCTION: acpi_tb_validate_table
263 * PARAMETERS: table_desc - Table descriptor
267 * DESCRIPTION: This function is called to validate the table, the returned
268 * table descriptor is in "VALIDATED" state.
270 *****************************************************************************/
272 acpi_status
acpi_tb_validate_table(struct acpi_table_desc
*table_desc
)
274 acpi_status status
= AE_OK
;
276 ACPI_FUNCTION_TRACE(tb_validate_table
);
278 /* Validate the table if necessary */
280 if (!table_desc
->pointer
) {
281 status
= acpi_tb_acquire_table(table_desc
, &table_desc
->pointer
,
284 if (!table_desc
->pointer
) {
285 status
= AE_NO_MEMORY
;
289 return_ACPI_STATUS(status
);
292 /*******************************************************************************
294 * FUNCTION: acpi_tb_invalidate_table
296 * PARAMETERS: table_desc - Table descriptor
300 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
301 * acpi_tb_validate_table().
303 ******************************************************************************/
305 void acpi_tb_invalidate_table(struct acpi_table_desc
*table_desc
)
308 ACPI_FUNCTION_TRACE(tb_invalidate_table
);
310 /* Table must be validated */
312 if (!table_desc
->pointer
) {
316 acpi_tb_release_table(table_desc
->pointer
, table_desc
->length
,
318 table_desc
->pointer
= NULL
;
323 /******************************************************************************
325 * FUNCTION: acpi_tb_validate_temp_table
327 * PARAMETERS: table_desc - Table descriptor
331 * DESCRIPTION: This function is called to validate the table, the returned
332 * table descriptor is in "VALIDATED" state.
334 *****************************************************************************/
336 acpi_status
acpi_tb_validate_temp_table(struct acpi_table_desc
*table_desc
)
339 if (!table_desc
->pointer
&& !acpi_gbl_verify_table_checksum
) {
341 * Only validates the header of the table.
342 * Note that Length contains the size of the mapping after invoking
343 * this work around, this value is required by
344 * acpi_tb_release_temp_table().
345 * We can do this because in acpi_init_table_descriptor(), the Length
346 * field of the installed descriptor is filled with the actual
347 * table length obtaining from the table header.
349 table_desc
->length
= sizeof(struct acpi_table_header
);
352 return (acpi_tb_validate_table(table_desc
));
355 /******************************************************************************
357 * FUNCTION: acpi_tb_verify_temp_table
359 * PARAMETERS: table_desc - Table descriptor
360 * signature - Table signature to verify
364 * DESCRIPTION: This function is called to validate and verify the table, the
365 * returned table descriptor is in "VALIDATED" state.
367 *****************************************************************************/
370 acpi_tb_verify_temp_table(struct acpi_table_desc
* table_desc
, char *signature
)
372 acpi_status status
= AE_OK
;
374 ACPI_FUNCTION_TRACE(tb_verify_temp_table
);
376 /* Validate the table */
378 status
= acpi_tb_validate_temp_table(table_desc
);
379 if (ACPI_FAILURE(status
)) {
380 return_ACPI_STATUS(AE_NO_MEMORY
);
383 /* If a particular signature is expected (DSDT/FACS), it must match */
385 if (signature
&& !ACPI_COMPARE_NAME(&table_desc
->signature
, signature
)) {
386 ACPI_BIOS_ERROR((AE_INFO
,
387 "Invalid signature 0x%X for ACPI table, expected [%s]",
388 table_desc
->signature
.integer
, signature
));
389 status
= AE_BAD_SIGNATURE
;
390 goto invalidate_and_exit
;
393 /* Verify the checksum */
395 if (acpi_gbl_verify_table_checksum
) {
397 acpi_tb_verify_checksum(table_desc
->pointer
,
399 if (ACPI_FAILURE(status
)) {
400 ACPI_EXCEPTION((AE_INFO
, AE_NO_MEMORY
,
401 "%4.4s " ACPI_PRINTF_UINT
402 " Attempted table install failed",
403 acpi_ut_valid_acpi_name(table_desc
->
406 table_desc
->signature
.ascii
: "????",
407 ACPI_FORMAT_TO_UINT(table_desc
->
409 goto invalidate_and_exit
;
413 return_ACPI_STATUS(AE_OK
);
416 acpi_tb_invalidate_table(table_desc
);
417 return_ACPI_STATUS(status
);
420 /*******************************************************************************
422 * FUNCTION: acpi_tb_resize_root_table_list
428 * DESCRIPTION: Expand the size of global table array
430 ******************************************************************************/
432 acpi_status
acpi_tb_resize_root_table_list(void)
434 struct acpi_table_desc
*tables
;
437 ACPI_FUNCTION_TRACE(tb_resize_root_table_list
);
439 /* allow_resize flag is a parameter to acpi_initialize_tables */
441 if (!(acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ALLOW_RESIZE
)) {
443 "Resize of Root Table Array is not allowed"));
444 return_ACPI_STATUS(AE_SUPPORT
);
447 /* Increase the Table Array size */
449 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
450 table_count
= acpi_gbl_root_table_list
.max_table_count
;
452 table_count
= acpi_gbl_root_table_list
.current_table_count
;
455 tables
= ACPI_ALLOCATE_ZEROED(((acpi_size
) table_count
+
456 ACPI_ROOT_TABLE_SIZE_INCREMENT
) *
457 sizeof(struct acpi_table_desc
));
460 "Could not allocate new root table array"));
461 return_ACPI_STATUS(AE_NO_MEMORY
);
464 /* Copy and free the previous table array */
466 if (acpi_gbl_root_table_list
.tables
) {
467 ACPI_MEMCPY(tables
, acpi_gbl_root_table_list
.tables
,
468 (acpi_size
) table_count
*
469 sizeof(struct acpi_table_desc
));
471 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
472 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
476 acpi_gbl_root_table_list
.tables
= tables
;
477 acpi_gbl_root_table_list
.max_table_count
=
478 table_count
+ ACPI_ROOT_TABLE_SIZE_INCREMENT
;
479 acpi_gbl_root_table_list
.flags
|= ACPI_ROOT_ORIGIN_ALLOCATED
;
481 return_ACPI_STATUS(AE_OK
);
484 /*******************************************************************************
486 * FUNCTION: acpi_tb_get_next_root_index
488 * PARAMETERS: table_index - Where table index is returned
490 * RETURN: Status and table index.
492 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
494 ******************************************************************************/
496 acpi_status
acpi_tb_get_next_root_index(u32
*table_index
)
500 /* Ensure that there is room for the table in the Root Table List */
502 if (acpi_gbl_root_table_list
.current_table_count
>=
503 acpi_gbl_root_table_list
.max_table_count
) {
504 status
= acpi_tb_resize_root_table_list();
505 if (ACPI_FAILURE(status
)) {
510 *table_index
= acpi_gbl_root_table_list
.current_table_count
;
511 acpi_gbl_root_table_list
.current_table_count
++;
515 /*******************************************************************************
517 * FUNCTION: acpi_tb_terminate
523 * DESCRIPTION: Delete all internal ACPI tables
525 ******************************************************************************/
527 void acpi_tb_terminate(void)
531 ACPI_FUNCTION_TRACE(tb_terminate
);
533 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
535 /* Delete the individual tables */
537 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; i
++) {
538 acpi_tb_uninstall_table(&acpi_gbl_root_table_list
.tables
[i
]);
542 * Delete the root table array if allocated locally. Array cannot be
543 * mapped, so we don't need to check for that flag.
545 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
546 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
549 acpi_gbl_root_table_list
.tables
= NULL
;
550 acpi_gbl_root_table_list
.flags
= 0;
551 acpi_gbl_root_table_list
.current_table_count
= 0;
553 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "ACPI Tables freed\n"));
555 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
559 /*******************************************************************************
561 * FUNCTION: acpi_tb_delete_namespace_by_owner
563 * PARAMETERS: table_index - Table index
567 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
569 ******************************************************************************/
571 acpi_status
acpi_tb_delete_namespace_by_owner(u32 table_index
)
573 acpi_owner_id owner_id
;
576 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner
);
578 status
= acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
579 if (ACPI_FAILURE(status
)) {
580 return_ACPI_STATUS(status
);
583 if (table_index
>= acpi_gbl_root_table_list
.current_table_count
) {
585 /* The table index does not exist */
587 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
588 return_ACPI_STATUS(AE_NOT_EXIST
);
591 /* Get the owner ID for this table, used to delete namespace nodes */
593 owner_id
= acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
594 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
597 * Need to acquire the namespace writer lock to prevent interference
598 * with any concurrent namespace walks. The interpreter must be
599 * released during the deletion since the acquisition of the deletion
600 * lock may block, and also since the execution of a namespace walk
601 * must be allowed to use the interpreter.
603 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
604 status
= acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock
);
606 acpi_ns_delete_namespace_by_owner(owner_id
);
607 if (ACPI_FAILURE(status
)) {
608 return_ACPI_STATUS(status
);
611 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock
);
613 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
614 return_ACPI_STATUS(status
);
617 /*******************************************************************************
619 * FUNCTION: acpi_tb_allocate_owner_id
621 * PARAMETERS: table_index - Table index
625 * DESCRIPTION: Allocates owner_id in table_desc
627 ******************************************************************************/
629 acpi_status
acpi_tb_allocate_owner_id(u32 table_index
)
631 acpi_status status
= AE_BAD_PARAMETER
;
633 ACPI_FUNCTION_TRACE(tb_allocate_owner_id
);
635 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
636 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
638 acpi_ut_allocate_owner_id(&
639 (acpi_gbl_root_table_list
.
640 tables
[table_index
].owner_id
));
643 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
644 return_ACPI_STATUS(status
);
647 /*******************************************************************************
649 * FUNCTION: acpi_tb_release_owner_id
651 * PARAMETERS: table_index - Table index
655 * DESCRIPTION: Releases owner_id in table_desc
657 ******************************************************************************/
659 acpi_status
acpi_tb_release_owner_id(u32 table_index
)
661 acpi_status status
= AE_BAD_PARAMETER
;
663 ACPI_FUNCTION_TRACE(tb_release_owner_id
);
665 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
666 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
667 acpi_ut_release_owner_id(&
668 (acpi_gbl_root_table_list
.
669 tables
[table_index
].owner_id
));
673 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
674 return_ACPI_STATUS(status
);
677 /*******************************************************************************
679 * FUNCTION: acpi_tb_get_owner_id
681 * PARAMETERS: table_index - Table index
682 * owner_id - Where the table owner_id is returned
686 * DESCRIPTION: returns owner_id for the ACPI table
688 ******************************************************************************/
690 acpi_status
acpi_tb_get_owner_id(u32 table_index
, acpi_owner_id
* owner_id
)
692 acpi_status status
= AE_BAD_PARAMETER
;
694 ACPI_FUNCTION_TRACE(tb_get_owner_id
);
696 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
697 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
699 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
703 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
704 return_ACPI_STATUS(status
);
707 /*******************************************************************************
709 * FUNCTION: acpi_tb_is_table_loaded
711 * PARAMETERS: table_index - Index into the root table
713 * RETURN: Table Loaded Flag
715 ******************************************************************************/
717 u8
acpi_tb_is_table_loaded(u32 table_index
)
719 u8 is_loaded
= FALSE
;
721 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
722 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
724 (acpi_gbl_root_table_list
.tables
[table_index
].flags
&
725 ACPI_TABLE_IS_LOADED
);
728 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
732 /*******************************************************************************
734 * FUNCTION: acpi_tb_set_table_loaded_flag
736 * PARAMETERS: table_index - Table index
737 * is_loaded - TRUE if table is loaded, FALSE otherwise
741 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
743 ******************************************************************************/
745 void acpi_tb_set_table_loaded_flag(u32 table_index
, u8 is_loaded
)
748 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
749 if (table_index
< acpi_gbl_root_table_list
.current_table_count
) {
751 acpi_gbl_root_table_list
.tables
[table_index
].flags
|=
752 ACPI_TABLE_IS_LOADED
;
754 acpi_gbl_root_table_list
.tables
[table_index
].flags
&=
755 ~ACPI_TABLE_IS_LOADED
;
759 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);