Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
Bob Moore | 42f4786 | 2013-06-08 00:59:02 +0000 | [diff] [blame] | 4 | * Module Name: tbutils - ACPI Table utilities |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Bob Moore | 4441e55 | 2021-01-15 10:48:25 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2021, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #define _COMPONENT ACPI_TABLES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 15 | ACPI_MODULE_NAME("tbutils") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 17 | /* Local prototypes */ |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 18 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 19 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); |
| 20 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 21 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /******************************************************************************* |
| 23 | * |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 24 | * FUNCTION: acpi_tb_initialize_facs |
| 25 | * |
| 26 | * PARAMETERS: None |
| 27 | * |
| 28 | * RETURN: Status |
| 29 | * |
| 30 | * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global |
| 31 | * for accessing the Global Lock and Firmware Waking Vector |
| 32 | * |
| 33 | ******************************************************************************/ |
| 34 | |
| 35 | acpi_status acpi_tb_initialize_facs(void) |
| 36 | { |
Lv Zheng | 7484619 | 2015-08-25 10:29:08 +0800 | [diff] [blame] | 37 | struct acpi_table_facs *facs; |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 38 | |
Bob Moore | 22e5b40 | 2011-11-16 10:57:28 +0800 | [diff] [blame] | 39 | /* If Hardware Reduced flag is set, there is no FACS */ |
| 40 | |
| 41 | if (acpi_gbl_reduced_hardware) { |
| 42 | acpi_gbl_FACS = NULL; |
| 43 | return (AE_OK); |
Lv Zheng | 8ec3f45 | 2015-08-25 10:29:01 +0800 | [diff] [blame] | 44 | } else if (acpi_gbl_FADT.Xfacs && |
| 45 | (!acpi_gbl_FADT.facs |
| 46 | || !acpi_gbl_use32_bit_facs_addresses)) { |
| 47 | (void)acpi_get_table_by_index(acpi_gbl_xfacs_index, |
| 48 | ACPI_CAST_INDIRECT_PTR(struct |
| 49 | acpi_table_header, |
Lv Zheng | 7484619 | 2015-08-25 10:29:08 +0800 | [diff] [blame] | 50 | &facs)); |
| 51 | acpi_gbl_FACS = facs; |
Lv Zheng | 8ec3f45 | 2015-08-25 10:29:01 +0800 | [diff] [blame] | 52 | } else if (acpi_gbl_FADT.facs) { |
| 53 | (void)acpi_get_table_by_index(acpi_gbl_facs_index, |
| 54 | ACPI_CAST_INDIRECT_PTR(struct |
| 55 | acpi_table_header, |
Lv Zheng | 7484619 | 2015-08-25 10:29:08 +0800 | [diff] [blame] | 56 | &facs)); |
| 57 | acpi_gbl_FACS = facs; |
Lv Zheng | c04e1fb | 2015-07-01 14:43:11 +0800 | [diff] [blame] | 58 | } |
| 59 | |
Lv Zheng | f06147f | 2015-07-01 14:43:18 +0800 | [diff] [blame] | 60 | /* If there is no FACS, just continue. There was already an error msg */ |
| 61 | |
Lv Zheng | c04e1fb | 2015-07-01 14:43:11 +0800 | [diff] [blame] | 62 | return (AE_OK); |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 63 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 64 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 65 | |
| 66 | /******************************************************************************* |
| 67 | * |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 68 | * FUNCTION: acpi_tb_check_dsdt_header |
| 69 | * |
| 70 | * PARAMETERS: None |
| 71 | * |
| 72 | * RETURN: None |
| 73 | * |
| 74 | * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect |
| 75 | * if the DSDT has been replaced from outside the OS and/or if |
| 76 | * the DSDT header has been corrupted. |
| 77 | * |
| 78 | ******************************************************************************/ |
| 79 | |
| 80 | void acpi_tb_check_dsdt_header(void) |
| 81 | { |
| 82 | |
| 83 | /* Compare original length and checksum to current values */ |
| 84 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 85 | if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length || |
| 86 | acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) { |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 87 | ACPI_BIOS_ERROR((AE_INFO, |
| 88 | "The DSDT has been corrupted or replaced - " |
| 89 | "old, new headers below")); |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 90 | |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 91 | acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 92 | acpi_tb_print_table_header(0, acpi_gbl_DSDT); |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 93 | |
Lin Ming | aa2110c | 2010-04-08 14:34:27 +0800 | [diff] [blame] | 94 | ACPI_ERROR((AE_INFO, |
| 95 | "Please send DMI info to linux-acpi@vger.kernel.org\n" |
| 96 | "If system does not work as expected, please boot with acpi=copy_dsdt")); |
| 97 | |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 98 | /* Disable further error messages */ |
| 99 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 100 | acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length; |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 101 | acpi_gbl_original_dsdt_header.checksum = |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 102 | acpi_gbl_DSDT->checksum; |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | /******************************************************************************* |
| 107 | * |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 108 | * FUNCTION: acpi_tb_copy_dsdt |
| 109 | * |
Cao Jin | 32d8004 | 2017-06-05 16:41:04 +0800 | [diff] [blame] | 110 | * PARAMETERS: table_index - Index of installed table to copy |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 111 | * |
Cao Jin | 32d8004 | 2017-06-05 16:41:04 +0800 | [diff] [blame] | 112 | * RETURN: The copied DSDT |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 113 | * |
| 114 | * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory. |
| 115 | * Some very bad BIOSs are known to either corrupt the DSDT or |
| 116 | * install a new, bad DSDT. This copy works around the problem. |
| 117 | * |
| 118 | ******************************************************************************/ |
| 119 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 120 | struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index) |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 121 | { |
| 122 | struct acpi_table_header *new_table; |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 123 | struct acpi_table_desc *table_desc; |
| 124 | |
| 125 | table_desc = &acpi_gbl_root_table_list.tables[table_index]; |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 126 | |
| 127 | new_table = ACPI_ALLOCATE(table_desc->length); |
| 128 | if (!new_table) { |
| 129 | ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X", |
| 130 | table_desc->length)); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 131 | return (NULL); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 132 | } |
| 133 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 134 | memcpy(new_table, table_desc->pointer, table_desc->length); |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame] | 135 | acpi_tb_uninstall_table(table_desc); |
Bob Moore | ed6f1d4 | 2014-04-04 12:39:26 +0800 | [diff] [blame] | 136 | |
| 137 | acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list. |
Lv Zheng | 8ec3f45 | 2015-08-25 10:29:01 +0800 | [diff] [blame] | 138 | tables[acpi_gbl_dsdt_index], |
Bob Moore | ed6f1d4 | 2014-04-04 12:39:26 +0800 | [diff] [blame] | 139 | ACPI_PTR_TO_PHYSADDR(new_table), |
| 140 | ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, |
| 141 | new_table); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 142 | |
Bob Moore | 05fb04b | 2016-02-19 14:16:42 +0800 | [diff] [blame] | 143 | ACPI_INFO(("Forced DSDT copy: length 0x%05X copied locally, original unmapped", new_table->length)); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 144 | |
| 145 | return (new_table); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /******************************************************************************* |
| 149 | * |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 150 | * FUNCTION: acpi_tb_get_root_table_entry |
| 151 | * |
| 152 | * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry |
| 153 | * table_entry_size - sizeof 32 or 64 (RSDT or XSDT) |
| 154 | * |
| 155 | * RETURN: Physical address extracted from the root table |
| 156 | * |
| 157 | * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on |
| 158 | * both 32-bit and 64-bit platforms |
| 159 | * |
| 160 | * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on |
| 161 | * 64-bit platforms. |
| 162 | * |
| 163 | ******************************************************************************/ |
| 164 | |
| 165 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 166 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size) |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 167 | { |
| 168 | u64 address64; |
| 169 | |
| 170 | /* |
| 171 | * Get the table physical address (32-bit for RSDT, 64-bit for XSDT): |
| 172 | * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT |
| 173 | */ |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 174 | if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) { |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 175 | /* |
| 176 | * 32-bit platform, RSDT: Return 32-bit table entry |
| 177 | * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return |
| 178 | */ |
| 179 | return ((acpi_physical_address) |
| 180 | (*ACPI_CAST_PTR(u32, table_entry))); |
| 181 | } else { |
| 182 | /* |
| 183 | * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 184 | * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, |
| 185 | * return 64-bit |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 186 | */ |
| 187 | ACPI_MOVE_64_TO_64(&address64, table_entry); |
| 188 | |
| 189 | #if ACPI_MACHINE_WIDTH == 32 |
| 190 | if (address64 > ACPI_UINT32_MAX) { |
| 191 | |
Bob Moore | ea5d8eb | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 192 | /* Will truncate 64-bit address to 32 bits, issue warning */ |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 193 | |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 194 | ACPI_BIOS_WARNING((AE_INFO, |
| 195 | "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X)," |
| 196 | " truncating", |
| 197 | ACPI_FORMAT_UINT64(address64))); |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 198 | } |
| 199 | #endif |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 200 | return ((acpi_physical_address)(address64)); |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | /******************************************************************************* |
| 205 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 206 | * FUNCTION: acpi_tb_parse_root_table |
| 207 | * |
Cao Jin | 32d8004 | 2017-06-05 16:41:04 +0800 | [diff] [blame] | 208 | * PARAMETERS: rsdp_address - Pointer to the RSDP |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 209 | * |
| 210 | * RETURN: Status |
| 211 | * |
| 212 | * DESCRIPTION: This function is called to parse the Root System Description |
| 213 | * Table (RSDT or XSDT) |
| 214 | * |
| 215 | * NOTE: Tables are mapped (not copied) for efficiency. The FACS must |
| 216 | * be mapped and cannot be copied because it contains the actual |
| 217 | * memory location of the ACPI Global Lock. |
| 218 | * |
| 219 | ******************************************************************************/ |
| 220 | |
Lv Zheng | 2368b1a | 2016-08-04 16:43:19 +0800 | [diff] [blame] | 221 | acpi_status ACPI_INIT_FUNCTION |
| 222 | acpi_tb_parse_root_table(acpi_physical_address rsdp_address) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 223 | { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 224 | struct acpi_table_rsdp *rsdp; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 225 | u32 table_entry_size; |
| 226 | u32 i; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 227 | u32 table_count; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 228 | struct acpi_table_header *table; |
| 229 | acpi_physical_address address; |
| 230 | u32 length; |
| 231 | u8 *table_entry; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 232 | acpi_status status; |
Lv Zheng | 86dfc6f3 | 2014-04-04 12:38:57 +0800 | [diff] [blame] | 233 | u32 table_index; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 234 | |
| 235 | ACPI_FUNCTION_TRACE(tb_parse_root_table); |
| 236 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 237 | /* Map the entire RSDP and extract the address of the RSDT or XSDT */ |
| 238 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 239 | rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp)); |
| 240 | if (!rsdp) { |
| 241 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 242 | } |
| 243 | |
| 244 | acpi_tb_print_table_header(rsdp_address, |
| 245 | ACPI_CAST_PTR(struct acpi_table_header, |
| 246 | rsdp)); |
| 247 | |
Lv Zheng | fab4610 | 2014-01-08 13:43:40 +0800 | [diff] [blame] | 248 | /* Use XSDT if present and not overridden. Otherwise, use RSDT */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 249 | |
Lv Zheng | fab4610 | 2014-01-08 13:43:40 +0800 | [diff] [blame] | 250 | if ((rsdp->revision > 1) && |
| 251 | rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) { |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 252 | /* |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 253 | * RSDP contains an XSDT (64-bit physical addresses). We must use |
| 254 | * the XSDT if the revision is > 1 and the XSDT pointer is present, |
| 255 | * as per the ACPI specification. |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 256 | */ |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 257 | address = (acpi_physical_address)rsdp->xsdt_physical_address; |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 258 | table_entry_size = ACPI_XSDT_ENTRY_SIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 259 | } else { |
| 260 | /* Root table is an RSDT (32-bit physical addresses) */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 261 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 262 | address = (acpi_physical_address)rsdp->rsdt_physical_address; |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 263 | table_entry_size = ACPI_RSDT_ENTRY_SIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 264 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 265 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 266 | /* |
| 267 | * It is not possible to map more than one entry in some environments, |
| 268 | * so unmap the RSDP here before mapping other tables |
| 269 | */ |
| 270 | acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp)); |
| 271 | |
| 272 | /* Map the RSDT/XSDT table header to get the full table length */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 273 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 274 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 275 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 276 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 277 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 278 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 279 | acpi_tb_print_table_header(address, table); |
| 280 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 281 | /* |
| 282 | * Validate length of the table, and map entire table. |
| 283 | * Minimum length table must contain at least one entry. |
| 284 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 285 | length = table->length; |
| 286 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 287 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 288 | if (length < (sizeof(struct acpi_table_header) + table_entry_size)) { |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 289 | ACPI_BIOS_ERROR((AE_INFO, |
| 290 | "Invalid table length 0x%X in RSDT/XSDT", |
| 291 | length)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 292 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | table = acpi_os_map_memory(address, length); |
| 296 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 297 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* Validate the root table checksum */ |
| 301 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 302 | status = acpi_tb_verify_checksum(table, length); |
| 303 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 304 | acpi_os_unmap_memory(table, length); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 305 | return_ACPI_STATUS(status); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 306 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 307 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 308 | /* Get the number of entries and pointer to first entry */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 309 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 310 | table_count = (u32)((table->length - sizeof(struct acpi_table_header)) / |
| 311 | table_entry_size); |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 312 | table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header)); |
| 313 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 314 | /* Initialize the root table array from the RSDT/XSDT */ |
| 315 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 316 | for (i = 0; i < table_count; i++) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 317 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 318 | /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ |
| 319 | |
Lv Zheng | 0f929fbf | 2014-04-30 10:05:56 +0800 | [diff] [blame] | 320 | address = |
| 321 | acpi_tb_get_root_table_entry(table_entry, table_entry_size); |
| 322 | |
| 323 | /* Skip NULL entries in RSDT/XSDT */ |
| 324 | |
| 325 | if (!address) { |
| 326 | goto next_table; |
| 327 | } |
| 328 | |
| 329 | status = acpi_tb_install_standard_table(address, |
| 330 | ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, |
Jessica Clarke | 5d6e596 | 2021-12-22 17:22:28 +0100 | [diff] [blame] | 331 | NULL, FALSE, TRUE, |
Lv Zheng | 0f929fbf | 2014-04-30 10:05:56 +0800 | [diff] [blame] | 332 | &table_index); |
Lv Zheng | 86dfc6f3 | 2014-04-04 12:38:57 +0800 | [diff] [blame] | 333 | |
| 334 | if (ACPI_SUCCESS(status) && |
Bob Moore | 5599fb6 | 2019-04-08 13:42:24 -0700 | [diff] [blame] | 335 | ACPI_COMPARE_NAMESEG(&acpi_gbl_root_table_list. |
| 336 | tables[table_index].signature, |
| 337 | ACPI_SIG_FADT)) { |
Lv Zheng | 62fcce9 | 2015-10-14 13:53:57 +0800 | [diff] [blame] | 338 | acpi_gbl_fadt_index = table_index; |
| 339 | acpi_tb_parse_fadt(); |
Lv Zheng | 86dfc6f3 | 2014-04-04 12:38:57 +0800 | [diff] [blame] | 340 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 341 | |
Lv Zheng | 0f929fbf | 2014-04-30 10:05:56 +0800 | [diff] [blame] | 342 | next_table: |
| 343 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 344 | table_entry += table_entry_size; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 345 | } |
| 346 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 347 | acpi_os_unmap_memory(table, length); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | return_ACPI_STATUS(AE_OK); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 349 | } |
Lv Zheng | 174cc71 | 2016-12-14 15:04:25 +0800 | [diff] [blame] | 350 | |
| 351 | /******************************************************************************* |
| 352 | * |
| 353 | * FUNCTION: acpi_tb_get_table |
| 354 | * |
| 355 | * PARAMETERS: table_desc - Table descriptor |
| 356 | * out_table - Where the pointer to the table is returned |
| 357 | * |
| 358 | * RETURN: Status and pointer to the requested table |
| 359 | * |
| 360 | * DESCRIPTION: Increase a reference to a table descriptor and return the |
| 361 | * validated table pointer. |
| 362 | * If the table descriptor is an entry of the root table list, |
| 363 | * this API must be invoked with ACPI_MTX_TABLES acquired. |
| 364 | * |
| 365 | ******************************************************************************/ |
| 366 | |
| 367 | acpi_status |
| 368 | acpi_tb_get_table(struct acpi_table_desc *table_desc, |
| 369 | struct acpi_table_header **out_table) |
| 370 | { |
| 371 | acpi_status status; |
| 372 | |
| 373 | ACPI_FUNCTION_TRACE(acpi_tb_get_table); |
| 374 | |
| 375 | if (table_desc->validation_count == 0) { |
| 376 | |
| 377 | /* Table need to be "VALIDATED" */ |
| 378 | |
| 379 | status = acpi_tb_validate_table(table_desc); |
| 380 | if (ACPI_FAILURE(status)) { |
| 381 | return_ACPI_STATUS(status); |
| 382 | } |
| 383 | } |
| 384 | |
Lv Zheng | 83848fb | 2017-06-07 12:54:58 +0800 | [diff] [blame] | 385 | if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) { |
| 386 | table_desc->validation_count++; |
| 387 | |
| 388 | /* |
| 389 | * Detect validation_count overflows to ensure that the warning |
| 390 | * message will only be printed once. |
| 391 | */ |
| 392 | if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) { |
| 393 | ACPI_WARNING((AE_INFO, |
| 394 | "Table %p, Validation count overflows\n", |
| 395 | table_desc)); |
| 396 | } |
Lv Zheng | 174cc71 | 2016-12-14 15:04:25 +0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | *out_table = table_desc->pointer; |
| 400 | return_ACPI_STATUS(AE_OK); |
| 401 | } |
| 402 | |
| 403 | /******************************************************************************* |
| 404 | * |
| 405 | * FUNCTION: acpi_tb_put_table |
| 406 | * |
| 407 | * PARAMETERS: table_desc - Table descriptor |
| 408 | * |
| 409 | * RETURN: None |
| 410 | * |
| 411 | * DESCRIPTION: Decrease a reference to a table descriptor and release the |
| 412 | * validated table pointer if no references. |
| 413 | * If the table descriptor is an entry of the root table list, |
| 414 | * this API must be invoked with ACPI_MTX_TABLES acquired. |
| 415 | * |
| 416 | ******************************************************************************/ |
| 417 | |
| 418 | void acpi_tb_put_table(struct acpi_table_desc *table_desc) |
| 419 | { |
| 420 | |
| 421 | ACPI_FUNCTION_TRACE(acpi_tb_put_table); |
| 422 | |
Lv Zheng | 83848fb | 2017-06-07 12:54:58 +0800 | [diff] [blame] | 423 | if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) { |
| 424 | table_desc->validation_count--; |
| 425 | |
| 426 | /* |
| 427 | * Detect validation_count underflows to ensure that the warning |
| 428 | * message will only be printed once. |
| 429 | */ |
| 430 | if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) { |
| 431 | ACPI_WARNING((AE_INFO, |
| 432 | "Table %p, Validation count underflows\n", |
| 433 | table_desc)); |
| 434 | return_VOID; |
| 435 | } |
Lv Zheng | 174cc71 | 2016-12-14 15:04:25 +0800 | [diff] [blame] | 436 | } |
Lv Zheng | 174cc71 | 2016-12-14 15:04:25 +0800 | [diff] [blame] | 437 | |
| 438 | if (table_desc->validation_count == 0) { |
| 439 | |
| 440 | /* Table need to be "INVALIDATED" */ |
| 441 | |
| 442 | acpi_tb_invalidate_table(table_desc); |
| 443 | } |
| 444 | |
| 445 | return_VOID; |
| 446 | } |