Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Bob Moore | 42f4786 | 2013-06-08 00:59:02 +0000 | [diff] [blame] | 3 | * Module Name: tbutils - ACPI Table utilities |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | fbb7a2d | 2014-02-08 09:42:25 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2014, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 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. |
| 25 | * |
| 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. |
| 29 | * |
| 30 | * NO WARRANTY |
| 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. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define _COMPONENT ACPI_TABLES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("tbutils") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 51 | /* Local prototypes */ |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 52 | static acpi_status acpi_tb_validate_xsdt(acpi_physical_address address); |
| 53 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 54 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 55 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); |
| 56 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 57 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /******************************************************************************* |
| 59 | * |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 60 | * FUNCTION: acpi_tb_initialize_facs |
| 61 | * |
| 62 | * PARAMETERS: None |
| 63 | * |
| 64 | * RETURN: Status |
| 65 | * |
| 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 |
| 68 | * |
| 69 | ******************************************************************************/ |
| 70 | |
| 71 | acpi_status acpi_tb_initialize_facs(void) |
| 72 | { |
| 73 | acpi_status status; |
| 74 | |
Bob Moore | 22e5b40 | 2011-11-16 10:57:28 +0800 | [diff] [blame] | 75 | /* If Hardware Reduced flag is set, there is no FACS */ |
| 76 | |
| 77 | if (acpi_gbl_reduced_hardware) { |
| 78 | acpi_gbl_FACS = NULL; |
| 79 | return (AE_OK); |
| 80 | } |
| 81 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 82 | status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, |
| 83 | ACPI_CAST_INDIRECT_PTR(struct |
| 84 | acpi_table_header, |
| 85 | &acpi_gbl_FACS)); |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 86 | return (status); |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 87 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 88 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 89 | |
| 90 | /******************************************************************************* |
| 91 | * |
Bob Moore | c857303 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 92 | * FUNCTION: acpi_tb_tables_loaded |
| 93 | * |
| 94 | * PARAMETERS: None |
| 95 | * |
| 96 | * RETURN: TRUE if required ACPI tables are loaded |
| 97 | * |
| 98 | * DESCRIPTION: Determine if the minimum required ACPI tables are present |
| 99 | * (FADT, FACS, DSDT) |
| 100 | * |
| 101 | ******************************************************************************/ |
| 102 | |
| 103 | u8 acpi_tb_tables_loaded(void) |
| 104 | { |
| 105 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 106 | if (acpi_gbl_root_table_list.current_table_count >= 3) { |
Bob Moore | c857303 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 107 | return (TRUE); |
| 108 | } |
| 109 | |
| 110 | return (FALSE); |
| 111 | } |
| 112 | |
| 113 | /******************************************************************************* |
| 114 | * |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 115 | * FUNCTION: acpi_tb_check_dsdt_header |
| 116 | * |
| 117 | * PARAMETERS: None |
| 118 | * |
| 119 | * RETURN: None |
| 120 | * |
| 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. |
| 124 | * |
| 125 | ******************************************************************************/ |
| 126 | |
| 127 | void acpi_tb_check_dsdt_header(void) |
| 128 | { |
| 129 | |
| 130 | /* Compare original length and checksum to current values */ |
| 131 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 132 | if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length || |
| 133 | acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) { |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 134 | ACPI_BIOS_ERROR((AE_INFO, |
| 135 | "The DSDT has been corrupted or replaced - " |
| 136 | "old, new headers below")); |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 137 | acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 138 | acpi_tb_print_table_header(0, acpi_gbl_DSDT); |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 139 | |
Lin Ming | aa2110c | 2010-04-08 14:34:27 +0800 | [diff] [blame] | 140 | ACPI_ERROR((AE_INFO, |
| 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")); |
| 143 | |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 144 | /* Disable further error messages */ |
| 145 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 146 | acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length; |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 147 | acpi_gbl_original_dsdt_header.checksum = |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 148 | acpi_gbl_DSDT->checksum; |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | /******************************************************************************* |
| 153 | * |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 154 | * FUNCTION: acpi_tb_copy_dsdt |
| 155 | * |
| 156 | * PARAMETERS: table_desc - Installed table to copy |
| 157 | * |
| 158 | * RETURN: None |
| 159 | * |
| 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. |
| 163 | * |
| 164 | ******************************************************************************/ |
| 165 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 166 | struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index) |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 167 | { |
| 168 | struct acpi_table_header *new_table; |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 169 | struct acpi_table_desc *table_desc; |
| 170 | |
| 171 | table_desc = &acpi_gbl_root_table_list.tables[table_index]; |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 172 | |
| 173 | new_table = ACPI_ALLOCATE(table_desc->length); |
| 174 | if (!new_table) { |
| 175 | ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X", |
| 176 | table_desc->length)); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 177 | return (NULL); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 178 | } |
| 179 | |
| 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; |
| 184 | |
| 185 | ACPI_INFO((AE_INFO, |
| 186 | "Forced DSDT copy: length 0x%05X copied locally, original unmapped", |
| 187 | new_table->length)); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 188 | |
| 189 | return (new_table); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /******************************************************************************* |
| 193 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 194 | * FUNCTION: acpi_tb_install_table |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 195 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 196 | * PARAMETERS: address - Physical address of DSDT or FACS |
| 197 | * signature - Table signature, NULL if no need to |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 198 | * match |
| 199 | * table_index - Index into root table array |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 200 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 201 | * RETURN: None |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 202 | * |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 203 | * DESCRIPTION: Install an ACPI table into the global data structure. The |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 204 | * table override mechanism is called to allow the host |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 205 | * OS to replace any table before it is installed in the root |
| 206 | * table array. |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 207 | * |
| 208 | ******************************************************************************/ |
| 209 | |
Bob Moore | 765ec20 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 210 | void |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 211 | acpi_tb_install_table(acpi_physical_address address, |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 212 | char *signature, u32 table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 213 | { |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 214 | struct acpi_table_header *table; |
| 215 | struct acpi_table_header *final_table; |
| 216 | struct acpi_table_desc *table_desc; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 217 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 218 | if (!address) { |
| 219 | ACPI_ERROR((AE_INFO, |
| 220 | "Null physical address for ACPI table [%s]", |
| 221 | signature)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 222 | return; |
| 223 | } |
| 224 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 225 | /* Map just the table header */ |
| 226 | |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 227 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 228 | if (!table) { |
| 229 | ACPI_ERROR((AE_INFO, |
| 230 | "Could not map memory for table [%s] at %p", |
| 231 | signature, ACPI_CAST_PTR(void, address))); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 232 | return; |
| 233 | } |
| 234 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 235 | /* If a particular signature is expected (DSDT/FACS), it must match */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 236 | |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 237 | if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) { |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 238 | ACPI_BIOS_ERROR((AE_INFO, |
| 239 | "Invalid signature 0x%X for ACPI table, expected [%s]", |
| 240 | *ACPI_CAST_PTR(u32, table->signature), |
| 241 | signature)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 242 | goto unmap_and_exit; |
| 243 | } |
| 244 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 245 | /* |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 246 | * Initialize the table entry. Set the pointer to NULL, since the |
| 247 | * table is not fully mapped at this time. |
| 248 | */ |
| 249 | table_desc = &acpi_gbl_root_table_list.tables[table_index]; |
| 250 | |
| 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); |
| 256 | |
| 257 | /* |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 258 | * ACPI Table Override: |
| 259 | * |
| 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. |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 263 | * |
| 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. |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 269 | */ |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 270 | final_table = acpi_tb_table_override(table, table_desc); |
| 271 | if (!final_table) { |
| 272 | final_table = table; /* There was no override */ |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 273 | } |
| 274 | |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 275 | acpi_tb_print_table_header(table_desc->address, final_table); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 276 | |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 277 | /* Set the global integer width (based upon revision of the DSDT) */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 278 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 279 | if (table_index == ACPI_TABLE_INDEX_DSDT) { |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 280 | acpi_ut_set_integer_width(final_table->revision); |
| 281 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 282 | |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 283 | /* |
| 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. |
| 290 | */ |
| 291 | if (final_table != table) { |
| 292 | acpi_tb_delete_table(table_desc); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 293 | } |
| 294 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 295 | unmap_and_exit: |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 296 | |
| 297 | /* Always unmap the table header that we mapped above */ |
| 298 | |
| 299 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /******************************************************************************* |
| 303 | * |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 304 | * FUNCTION: acpi_tb_get_root_table_entry |
| 305 | * |
| 306 | * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry |
| 307 | * table_entry_size - sizeof 32 or 64 (RSDT or XSDT) |
| 308 | * |
| 309 | * RETURN: Physical address extracted from the root table |
| 310 | * |
| 311 | * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on |
| 312 | * both 32-bit and 64-bit platforms |
| 313 | * |
| 314 | * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on |
| 315 | * 64-bit platforms. |
| 316 | * |
| 317 | ******************************************************************************/ |
| 318 | |
| 319 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 320 | 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] | 321 | { |
| 322 | u64 address64; |
| 323 | |
| 324 | /* |
| 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 |
| 327 | */ |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 328 | if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) { |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 329 | /* |
| 330 | * 32-bit platform, RSDT: Return 32-bit table entry |
| 331 | * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return |
| 332 | */ |
| 333 | return ((acpi_physical_address) |
| 334 | (*ACPI_CAST_PTR(u32, table_entry))); |
| 335 | } else { |
| 336 | /* |
| 337 | * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 338 | * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, |
| 339 | * return 64-bit |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 340 | */ |
| 341 | ACPI_MOVE_64_TO_64(&address64, table_entry); |
| 342 | |
| 343 | #if ACPI_MACHINE_WIDTH == 32 |
| 344 | if (address64 > ACPI_UINT32_MAX) { |
| 345 | |
Bob Moore | ea5d8eb | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 346 | /* Will truncate 64-bit address to 32 bits, issue warning */ |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 347 | |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 348 | ACPI_BIOS_WARNING((AE_INFO, |
| 349 | "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X)," |
| 350 | " truncating", |
| 351 | ACPI_FORMAT_UINT64(address64))); |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 352 | } |
| 353 | #endif |
| 354 | return ((acpi_physical_address) (address64)); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /******************************************************************************* |
| 359 | * |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 360 | * FUNCTION: acpi_tb_validate_xsdt |
| 361 | * |
| 362 | * PARAMETERS: address - Physical address of the XSDT (from RSDP) |
| 363 | * |
| 364 | * RETURN: Status. AE_OK if the table appears to be valid. |
| 365 | * |
| 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. |
| 370 | * |
| 371 | ******************************************************************************/ |
| 372 | |
| 373 | static acpi_status acpi_tb_validate_xsdt(acpi_physical_address xsdt_address) |
| 374 | { |
| 375 | struct acpi_table_header *table; |
| 376 | u8 *next_entry; |
| 377 | acpi_physical_address address; |
| 378 | u32 length; |
| 379 | u32 entry_count; |
| 380 | acpi_status status; |
| 381 | u32 i; |
| 382 | |
| 383 | /* Get the XSDT length */ |
| 384 | |
| 385 | table = |
| 386 | acpi_os_map_memory(xsdt_address, sizeof(struct acpi_table_header)); |
| 387 | if (!table) { |
| 388 | return (AE_NO_MEMORY); |
| 389 | } |
| 390 | |
| 391 | length = table->length; |
| 392 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 393 | |
| 394 | /* |
| 395 | * Minimum XSDT length is the size of the standard ACPI header |
| 396 | * plus one physical address entry |
| 397 | */ |
| 398 | if (length < (sizeof(struct acpi_table_header) + ACPI_XSDT_ENTRY_SIZE)) { |
| 399 | return (AE_INVALID_TABLE_LENGTH); |
| 400 | } |
| 401 | |
| 402 | /* Map the entire XSDT */ |
| 403 | |
| 404 | table = acpi_os_map_memory(xsdt_address, length); |
| 405 | if (!table) { |
| 406 | return (AE_NO_MEMORY); |
| 407 | } |
| 408 | |
| 409 | /* Get the number of entries and pointer to first entry */ |
| 410 | |
| 411 | status = AE_OK; |
| 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); |
| 415 | |
| 416 | /* Validate each entry (physical address) within the XSDT */ |
| 417 | |
| 418 | for (i = 0; i < entry_count; i++) { |
| 419 | address = |
| 420 | acpi_tb_get_root_table_entry(next_entry, |
| 421 | ACPI_XSDT_ENTRY_SIZE); |
| 422 | if (!address) { |
| 423 | |
| 424 | /* Detected a NULL entry, XSDT is invalid */ |
| 425 | |
| 426 | status = AE_NULL_ENTRY; |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | next_entry += ACPI_XSDT_ENTRY_SIZE; |
| 431 | } |
| 432 | |
| 433 | /* Unmap table */ |
| 434 | |
| 435 | acpi_os_unmap_memory(table, length); |
| 436 | return (status); |
| 437 | } |
| 438 | |
| 439 | /******************************************************************************* |
| 440 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 441 | * FUNCTION: acpi_tb_parse_root_table |
| 442 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 443 | * PARAMETERS: rsdp - Pointer to the RSDP |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 444 | * |
| 445 | * RETURN: Status |
| 446 | * |
| 447 | * DESCRIPTION: This function is called to parse the Root System Description |
| 448 | * Table (RSDT or XSDT) |
| 449 | * |
| 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. |
| 453 | * |
| 454 | ******************************************************************************/ |
| 455 | |
Lv Zheng | 45c9f78 | 2013-10-31 09:31:24 +0800 | [diff] [blame] | 456 | acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 457 | { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 458 | struct acpi_table_rsdp *rsdp; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 459 | u32 table_entry_size; |
| 460 | u32 i; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 461 | u32 table_count; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 462 | struct acpi_table_header *table; |
| 463 | acpi_physical_address address; |
| 464 | u32 length; |
| 465 | u8 *table_entry; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 466 | acpi_status status; |
| 467 | |
| 468 | ACPI_FUNCTION_TRACE(tb_parse_root_table); |
| 469 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 470 | /* Map the entire RSDP and extract the address of the RSDT or XSDT */ |
| 471 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 472 | rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp)); |
| 473 | if (!rsdp) { |
| 474 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 475 | } |
| 476 | |
| 477 | acpi_tb_print_table_header(rsdp_address, |
| 478 | ACPI_CAST_PTR(struct acpi_table_header, |
| 479 | rsdp)); |
| 480 | |
Lv Zheng | fab4610 | 2014-01-08 13:43:40 +0800 | [diff] [blame] | 481 | /* Use XSDT if present and not overridden. Otherwise, use RSDT */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 482 | |
Lv Zheng | fab4610 | 2014-01-08 13:43:40 +0800 | [diff] [blame] | 483 | if ((rsdp->revision > 1) && |
| 484 | rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) { |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 485 | /* |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 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. |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 489 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 490 | address = (acpi_physical_address) rsdp->xsdt_physical_address; |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 491 | table_entry_size = ACPI_XSDT_ENTRY_SIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 492 | } else { |
| 493 | /* Root table is an RSDT (32-bit physical addresses) */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 494 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 495 | address = (acpi_physical_address) rsdp->rsdt_physical_address; |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 496 | table_entry_size = ACPI_RSDT_ENTRY_SIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 497 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 498 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 499 | /* |
| 500 | * It is not possible to map more than one entry in some environments, |
| 501 | * so unmap the RSDP here before mapping other tables |
| 502 | */ |
| 503 | acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp)); |
| 504 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 505 | /* |
Lv Zheng | fab4610 | 2014-01-08 13:43:40 +0800 | [diff] [blame] | 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 |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 508 | */ |
| 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))); |
| 515 | |
| 516 | /* Fall back to the RSDT */ |
| 517 | |
| 518 | address = |
| 519 | (acpi_physical_address) rsdp->rsdt_physical_address; |
| 520 | table_entry_size = ACPI_RSDT_ENTRY_SIZE; |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 521 | } |
| 522 | } |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 523 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 524 | /* Map the RSDT/XSDT table header to get the full table length */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 525 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 526 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 527 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 528 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 529 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 530 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 531 | acpi_tb_print_table_header(address, table); |
| 532 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 533 | /* |
| 534 | * Validate length of the table, and map entire table. |
| 535 | * Minimum length table must contain at least one entry. |
| 536 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 537 | length = table->length; |
| 538 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 539 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 540 | if (length < (sizeof(struct acpi_table_header) + table_entry_size)) { |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 541 | ACPI_BIOS_ERROR((AE_INFO, |
| 542 | "Invalid table length 0x%X in RSDT/XSDT", |
| 543 | length)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 544 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | table = acpi_os_map_memory(address, length); |
| 548 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 549 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /* Validate the root table checksum */ |
| 553 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 554 | status = acpi_tb_verify_checksum(table, length); |
| 555 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 556 | acpi_os_unmap_memory(table, length); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 557 | return_ACPI_STATUS(status); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 558 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 559 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 560 | /* Get the number of entries and pointer to first entry */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 561 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 562 | table_count = (u32)((table->length - sizeof(struct acpi_table_header)) / |
| 563 | table_entry_size); |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 564 | table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header)); |
| 565 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 566 | /* |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 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 |
| 569 | * come from the FADT |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 570 | */ |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 571 | acpi_gbl_root_table_list.current_table_count = 2; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 572 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 573 | /* Initialize the root table array from the RSDT/XSDT */ |
| 574 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 575 | for (i = 0; i < table_count; i++) { |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 576 | if (acpi_gbl_root_table_list.current_table_count >= |
| 577 | acpi_gbl_root_table_list.max_table_count) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 578 | |
| 579 | /* There is no more room in the root table array, attempt resize */ |
| 580 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 581 | status = acpi_tb_resize_root_table_list(); |
| 582 | if (ACPI_FAILURE(status)) { |
| 583 | ACPI_WARNING((AE_INFO, |
| 584 | "Truncating %u table entries!", |
Myron Stowe | 386e4a8 | 2009-01-30 15:44:53 -0700 | [diff] [blame] | 585 | (unsigned) (table_count - |
| 586 | (acpi_gbl_root_table_list. |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 587 | current_table_count - |
| 588 | 2)))); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 589 | break; |
| 590 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 593 | /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ |
| 594 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 595 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list. |
| 596 | current_table_count].address = |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 597 | acpi_tb_get_root_table_entry(table_entry, table_entry_size); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 598 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 599 | table_entry += table_entry_size; |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 600 | acpi_gbl_root_table_list.current_table_count++; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /* |
| 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 |
| 606 | */ |
| 607 | acpi_os_unmap_memory(table, length); |
| 608 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 609 | /* |
| 610 | * Complete the initialization of the root table array by examining |
| 611 | * the header of each table |
| 612 | */ |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 613 | for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 614 | acpi_tb_install_table(acpi_gbl_root_table_list.tables[i]. |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 615 | address, NULL, i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 616 | |
Lv Zheng | 671cc68 | 2014-01-08 13:43:34 +0800 | [diff] [blame] | 617 | /* Special case for FADT - validate it then get the DSDT and FACS */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 618 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 619 | if (ACPI_COMPARE_NAME |
| 620 | (&acpi_gbl_root_table_list.tables[i].signature, |
| 621 | ACPI_SIG_FADT)) { |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 622 | acpi_tb_parse_fadt(i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 623 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | return_ACPI_STATUS(AE_OK); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 627 | } |