1 /******************************************************************************
3 * Module Name: tbutils - table utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, 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_physical_address
53 acpi_tb_get_root_table_entry(u8
*table_entry
, u32 table_entry_size
);
55 /*******************************************************************************
57 * FUNCTION: acpi_tb_check_xsdt
59 * PARAMETERS: address - Pointer to the XSDT
62 * AE_OK - XSDT is okay
63 * AE_NO_MEMORY - can't map XSDT
64 * AE_INVALID_TABLE_LENGTH - invalid table length
65 * AE_NULL_ENTRY - XSDT has NULL entry
67 * DESCRIPTION: validate XSDT
68 ******************************************************************************/
71 acpi_tb_check_xsdt(acpi_physical_address address
)
73 struct acpi_table_header
*table
;
75 u64 xsdt_entry_address
;
80 table
= acpi_os_map_memory(address
, sizeof(struct acpi_table_header
));
84 length
= table
->length
;
85 acpi_os_unmap_memory(table
, sizeof(struct acpi_table_header
));
86 if (length
< sizeof(struct acpi_table_header
))
87 return AE_INVALID_TABLE_LENGTH
;
89 table
= acpi_os_map_memory(address
, length
);
93 /* Calculate the number of tables described in XSDT */
95 (u32
) ((table
->length
-
96 sizeof(struct acpi_table_header
)) / sizeof(u64
));
98 ACPI_CAST_PTR(u8
, table
) + sizeof(struct acpi_table_header
);
99 for (i
= 0; i
< table_count
; i
++) {
100 ACPI_MOVE_64_TO_64(&xsdt_entry_address
, table_entry
);
101 if (!xsdt_entry_address
) {
102 /* XSDT has NULL entry */
105 table_entry
+= sizeof(u64
);
107 acpi_os_unmap_memory(table
, length
);
110 return AE_NULL_ENTRY
;
115 /*******************************************************************************
117 * FUNCTION: acpi_tb_initialize_facs
123 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
124 * for accessing the Global Lock and Firmware Waking Vector
126 ******************************************************************************/
128 acpi_status
acpi_tb_initialize_facs(void)
132 status
= acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS
,
133 ACPI_CAST_INDIRECT_PTR(struct
139 /*******************************************************************************
141 * FUNCTION: acpi_tb_tables_loaded
145 * RETURN: TRUE if required ACPI tables are loaded
147 * DESCRIPTION: Determine if the minimum required ACPI tables are present
150 ******************************************************************************/
152 u8
acpi_tb_tables_loaded(void)
155 if (acpi_gbl_root_table_list
.count
>= 3) {
162 /*******************************************************************************
164 * FUNCTION: acpi_tb_print_table_header
166 * PARAMETERS: Address - Table physical address
167 * Header - Table header
171 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
173 ******************************************************************************/
176 acpi_tb_print_table_header(acpi_physical_address address
,
177 struct acpi_table_header
*header
)
181 * The reason that the Address is cast to a void pointer is so that we
182 * can use %p which will work properly on both 32-bit and 64-bit hosts.
184 if (ACPI_COMPARE_NAME(header
->signature
, ACPI_SIG_FACS
)) {
186 /* FACS only has signature and length fields */
188 ACPI_INFO((AE_INFO
, "%4.4s %p %05X",
189 header
->signature
, ACPI_CAST_PTR(void, address
),
191 } else if (ACPI_COMPARE_NAME(header
->signature
, ACPI_SIG_RSDP
)) {
193 /* RSDP has no common fields */
195 ACPI_INFO((AE_INFO
, "RSDP %p %05X (v%.2d %6.6s)",
196 ACPI_CAST_PTR (void, address
),
197 (ACPI_CAST_PTR(struct acpi_table_rsdp
, header
)->
199 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp
,
200 header
)->length
: 20,
201 ACPI_CAST_PTR(struct acpi_table_rsdp
,
203 ACPI_CAST_PTR(struct acpi_table_rsdp
,
206 /* Standard ACPI table with full common header */
209 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
210 header
->signature
, ACPI_CAST_PTR (void, address
),
211 header
->length
, header
->revision
, header
->oem_id
,
212 header
->oem_table_id
, header
->oem_revision
,
213 header
->asl_compiler_id
,
214 header
->asl_compiler_revision
));
218 /*******************************************************************************
220 * FUNCTION: acpi_tb_validate_checksum
222 * PARAMETERS: Table - ACPI table to verify
223 * Length - Length of entire table
227 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
228 * exception on bad checksum.
230 ******************************************************************************/
232 acpi_status
acpi_tb_verify_checksum(struct acpi_table_header
*table
, u32 length
)
236 /* Compute the checksum on the table */
238 checksum
= acpi_tb_checksum(ACPI_CAST_PTR(u8
, table
), length
);
240 /* Checksum ok? (should be zero) */
243 ACPI_WARNING((AE_INFO
,
244 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
245 table
->signature
, table
->checksum
,
246 (u8
) (table
->checksum
- checksum
)));
248 #if (ACPI_CHECKSUM_ABORT)
250 return (AE_BAD_CHECKSUM
);
257 /*******************************************************************************
259 * FUNCTION: acpi_tb_checksum
261 * PARAMETERS: Buffer - Pointer to memory region to be checked
262 * Length - Length of this memory region
264 * RETURN: Checksum (u8)
266 * DESCRIPTION: Calculates circular checksum of memory region.
268 ******************************************************************************/
270 u8
acpi_tb_checksum(u8
*buffer
, u32 length
)
273 u8
*end
= buffer
+ length
;
275 while (buffer
< end
) {
276 sum
= (u8
) (sum
+ *(buffer
++));
282 /*******************************************************************************
284 * FUNCTION: acpi_tb_install_table
286 * PARAMETERS: Address - Physical address of DSDT or FACS
287 * Signature - Table signature, NULL if no need to
289 * table_index - Index into root table array
293 * DESCRIPTION: Install an ACPI table into the global data structure. The
294 * table override mechanism is implemented here to allow the host
295 * OS to replace any table before it is installed in the root
298 ******************************************************************************/
301 acpi_tb_install_table(acpi_physical_address address
,
302 char *signature
, u32 table_index
)
306 struct acpi_table_header
*table_to_install
;
307 struct acpi_table_header
*mapped_table
;
308 struct acpi_table_header
*override_table
= NULL
;
312 "Null physical address for ACPI table [%s]",
317 /* Map just the table header */
320 acpi_os_map_memory(address
, sizeof(struct acpi_table_header
));
325 /* If a particular signature is expected (DSDT/FACS), it must match */
327 if (signature
&& !ACPI_COMPARE_NAME(mapped_table
->signature
, signature
)) {
329 "Invalid signature 0x%X for ACPI table, expected [%s]",
330 *ACPI_CAST_PTR(u32
, mapped_table
->signature
),
336 * ACPI Table Override:
338 * Before we install the table, let the host OS override it with a new
339 * one if desired. Any table within the RSDT/XSDT can be replaced,
340 * including the DSDT which is pointed to by the FADT.
342 status
= acpi_os_table_override(mapped_table
, &override_table
);
343 if (ACPI_SUCCESS(status
) && override_table
) {
345 "%4.4s @ 0x%p Table override, replaced with:",
346 mapped_table
->signature
, ACPI_CAST_PTR(void,
349 acpi_gbl_root_table_list
.tables
[table_index
].pointer
=
351 address
= ACPI_PTR_TO_PHYSADDR(override_table
);
353 table_to_install
= override_table
;
354 flags
= ACPI_TABLE_ORIGIN_OVERRIDE
;
356 table_to_install
= mapped_table
;
357 flags
= ACPI_TABLE_ORIGIN_MAPPED
;
360 /* Initialize the table entry */
362 acpi_gbl_root_table_list
.tables
[table_index
].address
= address
;
363 acpi_gbl_root_table_list
.tables
[table_index
].length
=
364 table_to_install
->length
;
365 acpi_gbl_root_table_list
.tables
[table_index
].flags
= flags
;
368 (acpi_gbl_root_table_list
.tables
[table_index
].
369 signature
), table_to_install
->signature
);
371 acpi_tb_print_table_header(address
, table_to_install
);
373 if (table_index
== ACPI_TABLE_INDEX_DSDT
) {
375 /* Global integer width is based upon revision of the DSDT */
377 acpi_ut_set_integer_width(table_to_install
->revision
);
381 acpi_os_unmap_memory(mapped_table
, sizeof(struct acpi_table_header
));
384 /*******************************************************************************
386 * FUNCTION: acpi_tb_get_root_table_entry
388 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
389 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
391 * RETURN: Physical address extracted from the root table
393 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
394 * both 32-bit and 64-bit platforms
396 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
399 ******************************************************************************/
401 static acpi_physical_address
402 acpi_tb_get_root_table_entry(u8
*table_entry
, u32 table_entry_size
)
407 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
408 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
410 if (table_entry_size
== sizeof(u32
)) {
412 * 32-bit platform, RSDT: Return 32-bit table entry
413 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
415 return ((acpi_physical_address
)
416 (*ACPI_CAST_PTR(u32
, table_entry
)));
419 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
420 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
423 ACPI_MOVE_64_TO_64(&address64
, table_entry
);
425 #if ACPI_MACHINE_WIDTH == 32
426 if (address64
> ACPI_UINT32_MAX
) {
428 /* Will truncate 64-bit address to 32 bits, issue warning */
430 ACPI_WARNING((AE_INFO
,
431 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X),"
433 ACPI_FORMAT_UINT64(address64
)));
436 return ((acpi_physical_address
) (address64
));
440 /*******************************************************************************
442 * FUNCTION: acpi_tb_parse_root_table
444 * PARAMETERS: Rsdp - Pointer to the RSDP
448 * DESCRIPTION: This function is called to parse the Root System Description
449 * Table (RSDT or XSDT)
451 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
452 * be mapped and cannot be copied because it contains the actual
453 * memory location of the ACPI Global Lock.
455 ******************************************************************************/
458 acpi_tb_parse_root_table(acpi_physical_address rsdp_address
)
460 struct acpi_table_rsdp
*rsdp
;
461 u32 table_entry_size
;
464 struct acpi_table_header
*table
;
465 acpi_physical_address address
;
466 acpi_physical_address
uninitialized_var(rsdt_address
);
471 ACPI_FUNCTION_TRACE(tb_parse_root_table
);
474 * Map the entire RSDP and extract the address of the RSDT or XSDT
476 rsdp
= acpi_os_map_memory(rsdp_address
, sizeof(struct acpi_table_rsdp
));
478 return_ACPI_STATUS(AE_NO_MEMORY
);
481 acpi_tb_print_table_header(rsdp_address
,
482 ACPI_CAST_PTR(struct acpi_table_header
,
485 /* Differentiate between RSDT and XSDT root tables */
487 if (rsdp
->revision
> 1 && rsdp
->xsdt_physical_address
488 && !acpi_rsdt_forced
) {
490 * Root table is an XSDT (64-bit physical addresses). We must use the
491 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
492 * the ACPI specification.
494 address
= (acpi_physical_address
) rsdp
->xsdt_physical_address
;
495 table_entry_size
= sizeof(u64
);
496 rsdt_address
= (acpi_physical_address
)
497 rsdp
->rsdt_physical_address
;
499 /* Root table is an RSDT (32-bit physical addresses) */
501 address
= (acpi_physical_address
) rsdp
->rsdt_physical_address
;
502 table_entry_size
= sizeof(u32
);
506 * It is not possible to map more than one entry in some environments,
507 * so unmap the RSDP here before mapping other tables
509 acpi_os_unmap_memory(rsdp
, sizeof(struct acpi_table_rsdp
));
511 if (table_entry_size
== sizeof(u64
)) {
512 if (acpi_tb_check_xsdt(address
) == AE_NULL_ENTRY
) {
513 /* XSDT has NULL entry, RSDT is used */
514 address
= rsdt_address
;
515 table_entry_size
= sizeof(u32
);
516 ACPI_WARNING((AE_INFO
, "BIOS XSDT has NULL entry, "
520 /* Map the RSDT/XSDT table header to get the full table length */
522 table
= acpi_os_map_memory(address
, sizeof(struct acpi_table_header
));
524 return_ACPI_STATUS(AE_NO_MEMORY
);
527 acpi_tb_print_table_header(address
, table
);
529 /* Get the length of the full table, verify length and map entire table */
531 length
= table
->length
;
532 acpi_os_unmap_memory(table
, sizeof(struct acpi_table_header
));
534 if (length
< sizeof(struct acpi_table_header
)) {
535 ACPI_ERROR((AE_INFO
, "Invalid length 0x%X in RSDT/XSDT",
537 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH
);
540 table
= acpi_os_map_memory(address
, length
);
542 return_ACPI_STATUS(AE_NO_MEMORY
);
545 /* Validate the root table checksum */
547 status
= acpi_tb_verify_checksum(table
, length
);
548 if (ACPI_FAILURE(status
)) {
549 acpi_os_unmap_memory(table
, length
);
550 return_ACPI_STATUS(status
);
553 /* Calculate the number of tables described in the root table */
555 table_count
= (u32
)((table
->length
- sizeof(struct acpi_table_header
)) /
558 * First two entries in the table array are reserved for the DSDT
559 * and FACS, which are not actually present in the RSDT/XSDT - they
563 ACPI_CAST_PTR(u8
, table
) + sizeof(struct acpi_table_header
);
564 acpi_gbl_root_table_list
.count
= 2;
567 * Initialize the root table array from the RSDT/XSDT
569 for (i
= 0; i
< table_count
; i
++) {
570 if (acpi_gbl_root_table_list
.count
>=
571 acpi_gbl_root_table_list
.size
) {
573 /* There is no more room in the root table array, attempt resize */
575 status
= acpi_tb_resize_root_table_list();
576 if (ACPI_FAILURE(status
)) {
577 ACPI_WARNING((AE_INFO
,
578 "Truncating %u table entries!",
579 (unsigned) (table_count
-
580 (acpi_gbl_root_table_list
.
586 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
588 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
590 acpi_tb_get_root_table_entry(table_entry
, table_entry_size
);
592 table_entry
+= table_entry_size
;
593 acpi_gbl_root_table_list
.count
++;
597 * It is not possible to map more than one entry in some environments,
598 * so unmap the root table here before mapping other tables
600 acpi_os_unmap_memory(table
, length
);
603 * Complete the initialization of the root table array by examining
604 * the header of each table
606 for (i
= 2; i
< acpi_gbl_root_table_list
.count
; i
++) {
607 acpi_tb_install_table(acpi_gbl_root_table_list
.tables
[i
].
610 /* Special case for FADT - get the DSDT and FACS */
612 if (ACPI_COMPARE_NAME
613 (&acpi_gbl_root_table_list
.tables
[i
].signature
,
615 acpi_tb_parse_fadt(i
);
619 return_ACPI_STATUS(AE_OK
);