1 /******************************************************************************
3 * Module Name: tbutils - ACPI Table utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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>
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME("tbutils")
51 /* Local prototypes */
52 static acpi_status
acpi_tb_validate_xsdt(acpi_physical_address address
);
54 static acpi_physical_address
55 acpi_tb_get_root_table_entry(u8
*table_entry
, u32 table_entry_size
);
57 #if (!ACPI_REDUCED_HARDWARE)
58 /*******************************************************************************
60 * FUNCTION: acpi_tb_initialize_facs
66 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
67 * for accessing the Global Lock and Firmware Waking Vector
69 ******************************************************************************/
71 acpi_status
acpi_tb_initialize_facs(void)
75 /* If Hardware Reduced flag is set, there is no FACS */
77 if (acpi_gbl_reduced_hardware
) {
82 status
= acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS
,
83 ACPI_CAST_INDIRECT_PTR(struct
88 #endif /* !ACPI_REDUCED_HARDWARE */
90 /*******************************************************************************
92 * FUNCTION: acpi_tb_tables_loaded
96 * RETURN: TRUE if required ACPI tables are loaded
98 * DESCRIPTION: Determine if the minimum required ACPI tables are present
101 ******************************************************************************/
103 u8
acpi_tb_tables_loaded(void)
106 if (acpi_gbl_root_table_list
.current_table_count
>= 3) {
113 /*******************************************************************************
115 * FUNCTION: acpi_tb_check_dsdt_header
121 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
122 * if the DSDT has been replaced from outside the OS and/or if
123 * the DSDT header has been corrupted.
125 ******************************************************************************/
127 void acpi_tb_check_dsdt_header(void)
130 /* Compare original length and checksum to current values */
132 if (acpi_gbl_original_dsdt_header
.length
!= acpi_gbl_DSDT
->length
||
133 acpi_gbl_original_dsdt_header
.checksum
!= acpi_gbl_DSDT
->checksum
) {
134 ACPI_BIOS_ERROR((AE_INFO
,
135 "The DSDT has been corrupted or replaced - "
136 "old, new headers below"));
137 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header
);
138 acpi_tb_print_table_header(0, acpi_gbl_DSDT
);
141 "Please send DMI info to linux-acpi@vger.kernel.org\n"
142 "If system does not work as expected, please boot with acpi=copy_dsdt"));
144 /* Disable further error messages */
146 acpi_gbl_original_dsdt_header
.length
= acpi_gbl_DSDT
->length
;
147 acpi_gbl_original_dsdt_header
.checksum
=
148 acpi_gbl_DSDT
->checksum
;
152 /*******************************************************************************
154 * FUNCTION: acpi_tb_copy_dsdt
156 * PARAMETERS: table_desc - Installed table to copy
160 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
161 * Some very bad BIOSs are known to either corrupt the DSDT or
162 * install a new, bad DSDT. This copy works around the problem.
164 ******************************************************************************/
166 struct acpi_table_header
*acpi_tb_copy_dsdt(u32 table_index
)
168 struct acpi_table_header
*new_table
;
169 struct acpi_table_desc
*table_desc
;
171 table_desc
= &acpi_gbl_root_table_list
.tables
[table_index
];
173 new_table
= ACPI_ALLOCATE(table_desc
->length
);
175 ACPI_ERROR((AE_INFO
, "Could not copy DSDT of length 0x%X",
176 table_desc
->length
));
180 ACPI_MEMCPY(new_table
, table_desc
->pointer
, table_desc
->length
);
181 acpi_tb_delete_table(table_desc
);
182 table_desc
->pointer
= new_table
;
183 table_desc
->flags
= ACPI_TABLE_ORIGIN_ALLOCATED
;
186 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
192 /*******************************************************************************
194 * FUNCTION: acpi_tb_install_table
196 * PARAMETERS: address - Physical address of DSDT or FACS
197 * signature - Table signature, NULL if no need to
199 * table_index - Index into root table array
203 * DESCRIPTION: Install an ACPI table into the global data structure. The
204 * table override mechanism is called to allow the host
205 * OS to replace any table before it is installed in the root
208 ******************************************************************************/
211 acpi_tb_install_table(acpi_physical_address address
,
212 char *signature
, u32 table_index
)
214 struct acpi_table_header
*table
;
215 struct acpi_table_header
*final_table
;
216 struct acpi_table_desc
*table_desc
;
220 "Null physical address for ACPI table [%s]",
225 /* Map just the table header */
227 table
= acpi_os_map_memory(address
, sizeof(struct acpi_table_header
));
230 "Could not map memory for table [%s] at %p",
231 signature
, ACPI_CAST_PTR(void, address
)));
235 /* If a particular signature is expected (DSDT/FACS), it must match */
237 if (signature
&& !ACPI_COMPARE_NAME(table
->signature
, signature
)) {
238 ACPI_BIOS_ERROR((AE_INFO
,
239 "Invalid signature 0x%X for ACPI table, expected [%s]",
240 *ACPI_CAST_PTR(u32
, table
->signature
),
246 * Initialize the table entry. Set the pointer to NULL, since the
247 * table is not fully mapped at this time.
249 table_desc
= &acpi_gbl_root_table_list
.tables
[table_index
];
251 table_desc
->address
= address
;
252 table_desc
->pointer
= NULL
;
253 table_desc
->length
= table
->length
;
254 table_desc
->flags
= ACPI_TABLE_ORIGIN_MAPPED
;
255 ACPI_MOVE_32_TO_32(table_desc
->signature
.ascii
, table
->signature
);
258 * ACPI Table Override:
260 * Before we install the table, let the host OS override it with a new
261 * one if desired. Any table within the RSDT/XSDT can be replaced,
262 * including the DSDT which is pointed to by the FADT.
264 * NOTE: If the table is overridden, then final_table will contain a
265 * mapped pointer to the full new table. If the table is not overridden,
266 * or if there has been a physical override, then the table will be
267 * fully mapped later (in verify table). In any case, we must
268 * unmap the header that was mapped above.
270 final_table
= acpi_tb_table_override(table
, table_desc
);
272 final_table
= table
; /* There was no override */
275 acpi_tb_print_table_header(table_desc
->address
, final_table
);
277 /* Set the global integer width (based upon revision of the DSDT) */
279 if (table_index
== ACPI_TABLE_INDEX_DSDT
) {
280 acpi_ut_set_integer_width(final_table
->revision
);
284 * If we have a physical override during this early loading of the ACPI
285 * tables, unmap the table for now. It will be mapped again later when
286 * it is actually used. This supports very early loading of ACPI tables,
287 * before virtual memory is fully initialized and running within the
288 * host OS. Note: A logical override has the ACPI_TABLE_ORIGIN_OVERRIDE
289 * flag set and will not be deleted below.
291 if (final_table
!= table
) {
292 acpi_tb_delete_table(table_desc
);
297 /* Always unmap the table header that we mapped above */
299 acpi_os_unmap_memory(table
, sizeof(struct acpi_table_header
));
302 /*******************************************************************************
304 * FUNCTION: acpi_tb_get_root_table_entry
306 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
307 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
309 * RETURN: Physical address extracted from the root table
311 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
312 * both 32-bit and 64-bit platforms
314 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
317 ******************************************************************************/
319 static acpi_physical_address
320 acpi_tb_get_root_table_entry(u8
*table_entry
, u32 table_entry_size
)
325 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
326 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
328 if (table_entry_size
== ACPI_RSDT_ENTRY_SIZE
) {
330 * 32-bit platform, RSDT: Return 32-bit table entry
331 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
333 return ((acpi_physical_address
)
334 (*ACPI_CAST_PTR(u32
, table_entry
)));
337 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
338 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
341 ACPI_MOVE_64_TO_64(&address64
, table_entry
);
343 #if ACPI_MACHINE_WIDTH == 32
344 if (address64
> ACPI_UINT32_MAX
) {
346 /* Will truncate 64-bit address to 32 bits, issue warning */
348 ACPI_BIOS_WARNING((AE_INFO
,
349 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
351 ACPI_FORMAT_UINT64(address64
)));
354 return ((acpi_physical_address
) (address64
));
358 /*******************************************************************************
360 * FUNCTION: acpi_tb_validate_xsdt
362 * PARAMETERS: address - Physical address of the XSDT (from RSDP)
364 * RETURN: Status. AE_OK if the table appears to be valid.
366 * DESCRIPTION: Validate an XSDT to ensure that it is of minimum size and does
367 * not contain any NULL entries. A problem that is seen in the
368 * field is that the XSDT exists, but is actually useless because
369 * of one or more (or all) NULL entries.
371 ******************************************************************************/
373 static acpi_status
acpi_tb_validate_xsdt(acpi_physical_address xsdt_address
)
375 struct acpi_table_header
*table
;
377 acpi_physical_address address
;
383 /* Get the XSDT length */
386 acpi_os_map_memory(xsdt_address
, sizeof(struct acpi_table_header
));
388 return (AE_NO_MEMORY
);
391 length
= table
->length
;
392 acpi_os_unmap_memory(table
, sizeof(struct acpi_table_header
));
395 * Minimum XSDT length is the size of the standard ACPI header
396 * plus one physical address entry
398 if (length
< (sizeof(struct acpi_table_header
) + ACPI_XSDT_ENTRY_SIZE
)) {
399 return (AE_INVALID_TABLE_LENGTH
);
402 /* Map the entire XSDT */
404 table
= acpi_os_map_memory(xsdt_address
, length
);
406 return (AE_NO_MEMORY
);
409 /* Get the number of entries and pointer to first entry */
412 next_entry
= ACPI_ADD_PTR(u8
, table
, sizeof(struct acpi_table_header
));
413 entry_count
= (u32
)((table
->length
- sizeof(struct acpi_table_header
)) /
414 ACPI_XSDT_ENTRY_SIZE
);
416 /* Validate each entry (physical address) within the XSDT */
418 for (i
= 0; i
< entry_count
; i
++) {
420 acpi_tb_get_root_table_entry(next_entry
,
421 ACPI_XSDT_ENTRY_SIZE
);
424 /* Detected a NULL entry, XSDT is invalid */
426 status
= AE_NULL_ENTRY
;
430 next_entry
+= ACPI_XSDT_ENTRY_SIZE
;
435 acpi_os_unmap_memory(table
, length
);
439 /*******************************************************************************
441 * FUNCTION: acpi_tb_parse_root_table
443 * PARAMETERS: rsdp - Pointer to the RSDP
447 * DESCRIPTION: This function is called to parse the Root System Description
448 * Table (RSDT or XSDT)
450 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
451 * be mapped and cannot be copied because it contains the actual
452 * memory location of the ACPI Global Lock.
454 ******************************************************************************/
456 acpi_status __init
acpi_tb_parse_root_table(acpi_physical_address rsdp_address
)
458 struct acpi_table_rsdp
*rsdp
;
459 u32 table_entry_size
;
462 struct acpi_table_header
*table
;
463 acpi_physical_address address
;
468 ACPI_FUNCTION_TRACE(tb_parse_root_table
);
470 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
472 rsdp
= acpi_os_map_memory(rsdp_address
, sizeof(struct acpi_table_rsdp
));
474 return_ACPI_STATUS(AE_NO_MEMORY
);
477 acpi_tb_print_table_header(rsdp_address
,
478 ACPI_CAST_PTR(struct acpi_table_header
,
481 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
483 if ((rsdp
->revision
> 1) &&
484 rsdp
->xsdt_physical_address
&& !acpi_gbl_do_not_use_xsdt
) {
486 * RSDP contains an XSDT (64-bit physical addresses). We must use
487 * the XSDT if the revision is > 1 and the XSDT pointer is present,
488 * as per the ACPI specification.
490 address
= (acpi_physical_address
) rsdp
->xsdt_physical_address
;
491 table_entry_size
= ACPI_XSDT_ENTRY_SIZE
;
493 /* Root table is an RSDT (32-bit physical addresses) */
495 address
= (acpi_physical_address
) rsdp
->rsdt_physical_address
;
496 table_entry_size
= ACPI_RSDT_ENTRY_SIZE
;
500 * It is not possible to map more than one entry in some environments,
501 * so unmap the RSDP here before mapping other tables
503 acpi_os_unmap_memory(rsdp
, sizeof(struct acpi_table_rsdp
));
506 * If it is present and used, validate the XSDT for access/size
507 * and ensure that all table entries are at least non-NULL
509 if (table_entry_size
== ACPI_XSDT_ENTRY_SIZE
) {
510 status
= acpi_tb_validate_xsdt(address
);
511 if (ACPI_FAILURE(status
)) {
512 ACPI_BIOS_WARNING((AE_INFO
,
513 "XSDT is invalid (%s), using RSDT",
514 acpi_format_exception(status
)));
516 /* Fall back to the RSDT */
519 (acpi_physical_address
) rsdp
->rsdt_physical_address
;
520 table_entry_size
= ACPI_RSDT_ENTRY_SIZE
;
524 /* Map the RSDT/XSDT table header to get the full table length */
526 table
= acpi_os_map_memory(address
, sizeof(struct acpi_table_header
));
528 return_ACPI_STATUS(AE_NO_MEMORY
);
531 acpi_tb_print_table_header(address
, table
);
534 * Validate length of the table, and map entire table.
535 * Minimum length table must contain at least one entry.
537 length
= table
->length
;
538 acpi_os_unmap_memory(table
, sizeof(struct acpi_table_header
));
540 if (length
< (sizeof(struct acpi_table_header
) + table_entry_size
)) {
541 ACPI_BIOS_ERROR((AE_INFO
,
542 "Invalid table length 0x%X in RSDT/XSDT",
544 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH
);
547 table
= acpi_os_map_memory(address
, length
);
549 return_ACPI_STATUS(AE_NO_MEMORY
);
552 /* Validate the root table checksum */
554 status
= acpi_tb_verify_checksum(table
, length
);
555 if (ACPI_FAILURE(status
)) {
556 acpi_os_unmap_memory(table
, length
);
557 return_ACPI_STATUS(status
);
560 /* Get the number of entries and pointer to first entry */
562 table_count
= (u32
)((table
->length
- sizeof(struct acpi_table_header
)) /
564 table_entry
= ACPI_ADD_PTR(u8
, table
, sizeof(struct acpi_table_header
));
567 * First two entries in the table array are reserved for the DSDT
568 * and FACS, which are not actually present in the RSDT/XSDT - they
571 acpi_gbl_root_table_list
.current_table_count
= 2;
573 /* Initialize the root table array from the RSDT/XSDT */
575 for (i
= 0; i
< table_count
; i
++) {
576 if (acpi_gbl_root_table_list
.current_table_count
>=
577 acpi_gbl_root_table_list
.max_table_count
) {
579 /* There is no more room in the root table array, attempt resize */
581 status
= acpi_tb_resize_root_table_list();
582 if (ACPI_FAILURE(status
)) {
583 ACPI_WARNING((AE_INFO
,
584 "Truncating %u table entries!",
585 (unsigned) (table_count
-
586 (acpi_gbl_root_table_list
.
587 current_table_count
-
593 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
595 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.
596 current_table_count
].address
=
597 acpi_tb_get_root_table_entry(table_entry
, table_entry_size
);
599 table_entry
+= table_entry_size
;
600 acpi_gbl_root_table_list
.current_table_count
++;
604 * It is not possible to map more than one entry in some environments,
605 * so unmap the root table here before mapping other tables
607 acpi_os_unmap_memory(table
, length
);
610 * Complete the initialization of the root table array by examining
611 * the header of each table
613 for (i
= 2; i
< acpi_gbl_root_table_list
.current_table_count
; i
++) {
614 acpi_tb_install_table(acpi_gbl_root_table_list
.tables
[i
].
617 /* Special case for FADT - validate it then get the DSDT and FACS */
619 if (ACPI_COMPARE_NAME
620 (&acpi_gbl_root_table_list
.tables
[i
].signature
,
622 acpi_tb_parse_fadt(i
);
626 return_ACPI_STATUS(AE_OK
);