1 /******************************************************************************
3 * Module Name: tbutils - ACPI Table utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 #if (!ACPI_REDUCED_HARDWARE)
56 /*******************************************************************************
58 * FUNCTION: acpi_tb_initialize_facs
64 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
65 * for accessing the Global Lock and Firmware Waking Vector
67 ******************************************************************************/
69 acpi_status
acpi_tb_initialize_facs(void)
71 struct acpi_table_facs
*facs
;
73 /* If Hardware Reduced flag is set, there is no FACS */
75 if (acpi_gbl_reduced_hardware
) {
78 } else if (acpi_gbl_FADT
.Xfacs
&&
80 || !acpi_gbl_use32_bit_facs_addresses
)) {
81 (void)acpi_get_table_by_index(acpi_gbl_xfacs_index
,
82 ACPI_CAST_INDIRECT_PTR(struct
86 } else if (acpi_gbl_FADT
.facs
) {
87 (void)acpi_get_table_by_index(acpi_gbl_facs_index
,
88 ACPI_CAST_INDIRECT_PTR(struct
94 /* If there is no FACS, just continue. There was already an error msg */
98 #endif /* !ACPI_REDUCED_HARDWARE */
100 /*******************************************************************************
102 * FUNCTION: acpi_tb_tables_loaded
106 * RETURN: TRUE if required ACPI tables are loaded
108 * DESCRIPTION: Determine if the minimum required ACPI tables are present
111 ******************************************************************************/
113 u8
acpi_tb_tables_loaded(void)
116 if (acpi_gbl_root_table_list
.current_table_count
>= 4) {
123 /*******************************************************************************
125 * FUNCTION: acpi_tb_check_dsdt_header
131 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
132 * if the DSDT has been replaced from outside the OS and/or if
133 * the DSDT header has been corrupted.
135 ******************************************************************************/
137 void acpi_tb_check_dsdt_header(void)
140 /* Compare original length and checksum to current values */
142 if (acpi_gbl_original_dsdt_header
.length
!= acpi_gbl_DSDT
->length
||
143 acpi_gbl_original_dsdt_header
.checksum
!= acpi_gbl_DSDT
->checksum
) {
144 ACPI_BIOS_ERROR((AE_INFO
,
145 "The DSDT has been corrupted or replaced - "
146 "old, new headers below"));
147 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header
);
148 acpi_tb_print_table_header(0, acpi_gbl_DSDT
);
151 "Please send DMI info to linux-acpi@vger.kernel.org\n"
152 "If system does not work as expected, please boot with acpi=copy_dsdt"));
154 /* Disable further error messages */
156 acpi_gbl_original_dsdt_header
.length
= acpi_gbl_DSDT
->length
;
157 acpi_gbl_original_dsdt_header
.checksum
=
158 acpi_gbl_DSDT
->checksum
;
162 /*******************************************************************************
164 * FUNCTION: acpi_tb_copy_dsdt
166 * PARAMETERS: table_desc - Installed table to copy
170 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
171 * Some very bad BIOSs are known to either corrupt the DSDT or
172 * install a new, bad DSDT. This copy works around the problem.
174 ******************************************************************************/
176 struct acpi_table_header
*acpi_tb_copy_dsdt(u32 table_index
)
178 struct acpi_table_header
*new_table
;
179 struct acpi_table_desc
*table_desc
;
181 table_desc
= &acpi_gbl_root_table_list
.tables
[table_index
];
183 new_table
= ACPI_ALLOCATE(table_desc
->length
);
185 ACPI_ERROR((AE_INFO
, "Could not copy DSDT of length 0x%X",
186 table_desc
->length
));
190 memcpy(new_table
, table_desc
->pointer
, table_desc
->length
);
191 acpi_tb_uninstall_table(table_desc
);
193 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list
.
194 tables
[acpi_gbl_dsdt_index
],
195 ACPI_PTR_TO_PHYSADDR(new_table
),
196 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
,
200 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
206 /*******************************************************************************
208 * FUNCTION: acpi_tb_get_root_table_entry
210 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
211 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
213 * RETURN: Physical address extracted from the root table
215 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
216 * both 32-bit and 64-bit platforms
218 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
221 ******************************************************************************/
223 static acpi_physical_address
224 acpi_tb_get_root_table_entry(u8
*table_entry
, u32 table_entry_size
)
229 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
230 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
232 if (table_entry_size
== ACPI_RSDT_ENTRY_SIZE
) {
234 * 32-bit platform, RSDT: Return 32-bit table entry
235 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
237 return ((acpi_physical_address
)
238 (*ACPI_CAST_PTR(u32
, table_entry
)));
241 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
242 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
245 ACPI_MOVE_64_TO_64(&address64
, table_entry
);
247 #if ACPI_MACHINE_WIDTH == 32
248 if (address64
> ACPI_UINT32_MAX
) {
250 /* Will truncate 64-bit address to 32 bits, issue warning */
252 ACPI_BIOS_WARNING((AE_INFO
,
253 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
255 ACPI_FORMAT_UINT64(address64
)));
258 return ((acpi_physical_address
) (address64
));
262 /*******************************************************************************
264 * FUNCTION: acpi_tb_parse_root_table
266 * PARAMETERS: rsdp - Pointer to the RSDP
270 * DESCRIPTION: This function is called to parse the Root System Description
271 * Table (RSDT or XSDT)
273 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
274 * be mapped and cannot be copied because it contains the actual
275 * memory location of the ACPI Global Lock.
277 ******************************************************************************/
279 acpi_status __init
acpi_tb_parse_root_table(acpi_physical_address rsdp_address
)
281 struct acpi_table_rsdp
*rsdp
;
282 u32 table_entry_size
;
285 struct acpi_table_header
*table
;
286 acpi_physical_address address
;
292 ACPI_FUNCTION_TRACE(tb_parse_root_table
);
294 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
296 rsdp
= acpi_os_map_memory(rsdp_address
, sizeof(struct acpi_table_rsdp
));
298 return_ACPI_STATUS(AE_NO_MEMORY
);
301 acpi_tb_print_table_header(rsdp_address
,
302 ACPI_CAST_PTR(struct acpi_table_header
,
305 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
307 if ((rsdp
->revision
> 1) &&
308 rsdp
->xsdt_physical_address
&& !acpi_gbl_do_not_use_xsdt
) {
310 * RSDP contains an XSDT (64-bit physical addresses). We must use
311 * the XSDT if the revision is > 1 and the XSDT pointer is present,
312 * as per the ACPI specification.
314 address
= (acpi_physical_address
) rsdp
->xsdt_physical_address
;
315 table_entry_size
= ACPI_XSDT_ENTRY_SIZE
;
317 /* Root table is an RSDT (32-bit physical addresses) */
319 address
= (acpi_physical_address
) rsdp
->rsdt_physical_address
;
320 table_entry_size
= ACPI_RSDT_ENTRY_SIZE
;
324 * It is not possible to map more than one entry in some environments,
325 * so unmap the RSDP here before mapping other tables
327 acpi_os_unmap_memory(rsdp
, sizeof(struct acpi_table_rsdp
));
329 /* Map the RSDT/XSDT table header to get the full table length */
331 table
= acpi_os_map_memory(address
, sizeof(struct acpi_table_header
));
333 return_ACPI_STATUS(AE_NO_MEMORY
);
336 acpi_tb_print_table_header(address
, table
);
339 * Validate length of the table, and map entire table.
340 * Minimum length table must contain at least one entry.
342 length
= table
->length
;
343 acpi_os_unmap_memory(table
, sizeof(struct acpi_table_header
));
345 if (length
< (sizeof(struct acpi_table_header
) + table_entry_size
)) {
346 ACPI_BIOS_ERROR((AE_INFO
,
347 "Invalid table length 0x%X in RSDT/XSDT",
349 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH
);
352 table
= acpi_os_map_memory(address
, length
);
354 return_ACPI_STATUS(AE_NO_MEMORY
);
357 /* Validate the root table checksum */
359 status
= acpi_tb_verify_checksum(table
, length
);
360 if (ACPI_FAILURE(status
)) {
361 acpi_os_unmap_memory(table
, length
);
362 return_ACPI_STATUS(status
);
365 /* Get the number of entries and pointer to first entry */
367 table_count
= (u32
)((table
->length
- sizeof(struct acpi_table_header
)) /
369 table_entry
= ACPI_ADD_PTR(u8
, table
, sizeof(struct acpi_table_header
));
371 /* Initialize the root table array from the RSDT/XSDT */
373 for (i
= 0; i
< table_count
; i
++) {
375 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
378 acpi_tb_get_root_table_entry(table_entry
, table_entry_size
);
380 /* Skip NULL entries in RSDT/XSDT */
386 status
= acpi_tb_install_standard_table(address
,
387 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
,
391 if (ACPI_SUCCESS(status
) &&
392 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list
.
393 tables
[table_index
].signature
,
395 acpi_tb_parse_fadt(table_index
);
400 table_entry
+= table_entry_size
;
403 acpi_os_unmap_memory(table
, length
);
405 return_ACPI_STATUS(AE_OK
);
408 /*******************************************************************************
410 * FUNCTION: acpi_is_valid_signature
412 * PARAMETERS: signature - Sig string to be validated
414 * RETURN: TRUE if signature is correct length and has valid characters
416 * DESCRIPTION: Validate an ACPI table signature.
418 ******************************************************************************/
420 u8
acpi_is_valid_signature(char *signature
)
424 /* Validate the signature length */
426 if (strlen(signature
) != ACPI_NAME_SIZE
) {
430 /* Validate each character in the signature */
432 for (i
= 0; i
< ACPI_NAME_SIZE
; i
++) {
433 if (!acpi_ut_valid_acpi_char(signature
[i
], i
)) {