Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 3 | * Module Name: tbutils - table utilities |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2012, 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 */ |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 52 | static void acpi_tb_fix_string(char *string, acpi_size length); |
| 53 | |
| 54 | static void |
| 55 | acpi_tb_cleanup_table_header(struct acpi_table_header *out_header, |
| 56 | struct acpi_table_header *header); |
| 57 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 58 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 59 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); |
| 60 | |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 61 | /******************************************************************************* |
| 62 | * |
| 63 | * FUNCTION: acpi_tb_check_xsdt |
| 64 | * |
| 65 | * PARAMETERS: address - Pointer to the XSDT |
| 66 | * |
| 67 | * RETURN: status |
| 68 | * AE_OK - XSDT is okay |
| 69 | * AE_NO_MEMORY - can't map XSDT |
| 70 | * AE_INVALID_TABLE_LENGTH - invalid table length |
| 71 | * AE_NULL_ENTRY - XSDT has NULL entry |
| 72 | * |
| 73 | * DESCRIPTION: validate XSDT |
| 74 | ******************************************************************************/ |
| 75 | |
| 76 | static acpi_status |
| 77 | acpi_tb_check_xsdt(acpi_physical_address address) |
| 78 | { |
| 79 | struct acpi_table_header *table; |
| 80 | u32 length; |
| 81 | u64 xsdt_entry_address; |
| 82 | u8 *table_entry; |
| 83 | u32 table_count; |
| 84 | int i; |
| 85 | |
| 86 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 87 | if (!table) |
| 88 | return AE_NO_MEMORY; |
| 89 | |
| 90 | length = table->length; |
| 91 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 92 | if (length < sizeof(struct acpi_table_header)) |
| 93 | return AE_INVALID_TABLE_LENGTH; |
| 94 | |
| 95 | table = acpi_os_map_memory(address, length); |
| 96 | if (!table) |
| 97 | return AE_NO_MEMORY; |
| 98 | |
| 99 | /* Calculate the number of tables described in XSDT */ |
| 100 | table_count = |
| 101 | (u32) ((table->length - |
| 102 | sizeof(struct acpi_table_header)) / sizeof(u64)); |
| 103 | table_entry = |
| 104 | ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header); |
| 105 | for (i = 0; i < table_count; i++) { |
| 106 | ACPI_MOVE_64_TO_64(&xsdt_entry_address, table_entry); |
| 107 | if (!xsdt_entry_address) { |
| 108 | /* XSDT has NULL entry */ |
| 109 | break; |
| 110 | } |
| 111 | table_entry += sizeof(u64); |
| 112 | } |
| 113 | acpi_os_unmap_memory(table, length); |
| 114 | |
| 115 | if (i < table_count) |
| 116 | return AE_NULL_ENTRY; |
| 117 | else |
| 118 | return AE_OK; |
| 119 | } |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 120 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 121 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /******************************************************************************* |
| 123 | * |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 124 | * FUNCTION: acpi_tb_initialize_facs |
| 125 | * |
| 126 | * PARAMETERS: None |
| 127 | * |
| 128 | * RETURN: Status |
| 129 | * |
| 130 | * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global |
| 131 | * for accessing the Global Lock and Firmware Waking Vector |
| 132 | * |
| 133 | ******************************************************************************/ |
| 134 | |
| 135 | acpi_status acpi_tb_initialize_facs(void) |
| 136 | { |
| 137 | acpi_status status; |
| 138 | |
Bob Moore | 22e5b40 | 2011-11-16 10:57:28 +0800 | [diff] [blame] | 139 | /* If Hardware Reduced flag is set, there is no FACS */ |
| 140 | |
| 141 | if (acpi_gbl_reduced_hardware) { |
| 142 | acpi_gbl_FACS = NULL; |
| 143 | return (AE_OK); |
| 144 | } |
| 145 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 146 | status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, |
| 147 | ACPI_CAST_INDIRECT_PTR(struct |
| 148 | acpi_table_header, |
| 149 | &acpi_gbl_FACS)); |
| 150 | return status; |
| 151 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 152 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 153 | |
| 154 | /******************************************************************************* |
| 155 | * |
Bob Moore | c857303 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 156 | * FUNCTION: acpi_tb_tables_loaded |
| 157 | * |
| 158 | * PARAMETERS: None |
| 159 | * |
| 160 | * RETURN: TRUE if required ACPI tables are loaded |
| 161 | * |
| 162 | * DESCRIPTION: Determine if the minimum required ACPI tables are present |
| 163 | * (FADT, FACS, DSDT) |
| 164 | * |
| 165 | ******************************************************************************/ |
| 166 | |
| 167 | u8 acpi_tb_tables_loaded(void) |
| 168 | { |
| 169 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 170 | if (acpi_gbl_root_table_list.current_table_count >= 3) { |
Bob Moore | c857303 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 171 | return (TRUE); |
| 172 | } |
| 173 | |
| 174 | return (FALSE); |
| 175 | } |
| 176 | |
| 177 | /******************************************************************************* |
| 178 | * |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 179 | * FUNCTION: acpi_tb_fix_string |
| 180 | * |
| 181 | * PARAMETERS: String - String to be repaired |
| 182 | * Length - Maximum length |
| 183 | * |
| 184 | * RETURN: None |
| 185 | * |
| 186 | * DESCRIPTION: Replace every non-printable or non-ascii byte in the string |
| 187 | * with a question mark '?'. |
| 188 | * |
| 189 | ******************************************************************************/ |
| 190 | |
| 191 | static void acpi_tb_fix_string(char *string, acpi_size length) |
| 192 | { |
| 193 | |
| 194 | while (length && *string) { |
| 195 | if (!ACPI_IS_PRINT(*string)) { |
| 196 | *string = '?'; |
| 197 | } |
| 198 | string++; |
| 199 | length--; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /******************************************************************************* |
| 204 | * |
| 205 | * FUNCTION: acpi_tb_cleanup_table_header |
| 206 | * |
| 207 | * PARAMETERS: out_header - Where the cleaned header is returned |
| 208 | * Header - Input ACPI table header |
| 209 | * |
| 210 | * RETURN: Returns the cleaned header in out_header |
| 211 | * |
| 212 | * DESCRIPTION: Copy the table header and ensure that all "string" fields in |
| 213 | * the header consist of printable characters. |
| 214 | * |
| 215 | ******************************************************************************/ |
| 216 | |
| 217 | static void |
| 218 | acpi_tb_cleanup_table_header(struct acpi_table_header *out_header, |
| 219 | struct acpi_table_header *header) |
| 220 | { |
| 221 | |
| 222 | ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header)); |
| 223 | |
| 224 | acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE); |
| 225 | acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE); |
| 226 | acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE); |
| 227 | acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE); |
| 228 | } |
| 229 | |
| 230 | /******************************************************************************* |
| 231 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 232 | * FUNCTION: acpi_tb_print_table_header |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 233 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 234 | * PARAMETERS: Address - Table physical address |
| 235 | * Header - Table header |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 236 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 237 | * RETURN: None |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 238 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 239 | * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP. |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 240 | * |
| 241 | ******************************************************************************/ |
| 242 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 243 | void |
| 244 | acpi_tb_print_table_header(acpi_physical_address address, |
| 245 | struct acpi_table_header *header) |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 246 | { |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 247 | struct acpi_table_header local_header; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 248 | |
Bob Moore | b6bc342 | 2009-02-23 10:26:19 +0800 | [diff] [blame] | 249 | /* |
| 250 | * The reason that the Address is cast to a void pointer is so that we |
| 251 | * can use %p which will work properly on both 32-bit and 64-bit hosts. |
| 252 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 253 | if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) { |
| 254 | |
Bob Moore | b6bc342 | 2009-02-23 10:26:19 +0800 | [diff] [blame] | 255 | /* FACS only has signature and length fields */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 256 | |
Bob Moore | b6bc342 | 2009-02-23 10:26:19 +0800 | [diff] [blame] | 257 | ACPI_INFO((AE_INFO, "%4.4s %p %05X", |
| 258 | header->signature, ACPI_CAST_PTR(void, address), |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 259 | header->length)); |
| 260 | } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) { |
| 261 | |
| 262 | /* RSDP has no common fields */ |
| 263 | |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 264 | ACPI_MEMCPY(local_header.oem_id, |
| 265 | ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 266 | header)->oem_id, ACPI_OEM_ID_SIZE); |
| 267 | acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE); |
| 268 | |
Bob Moore | b6bc342 | 2009-02-23 10:26:19 +0800 | [diff] [blame] | 269 | ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)", |
| 270 | ACPI_CAST_PTR (void, address), |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 271 | (ACPI_CAST_PTR(struct acpi_table_rsdp, header)-> |
| 272 | revision > |
| 273 | 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 274 | header)->length : 20, |
| 275 | ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 276 | header)->revision, |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 277 | local_header.oem_id)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 278 | } else { |
Bob Moore | 4bf2739 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 279 | /* Standard ACPI table with full common header */ |
| 280 | |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 281 | acpi_tb_cleanup_table_header(&local_header, header); |
| 282 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 283 | ACPI_INFO((AE_INFO, |
Bob Moore | b6bc342 | 2009-02-23 10:26:19 +0800 | [diff] [blame] | 284 | "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)", |
Bob Moore | cf02cd4 | 2009-06-24 11:38:46 +0800 | [diff] [blame] | 285 | local_header.signature, ACPI_CAST_PTR(void, address), |
| 286 | local_header.length, local_header.revision, |
| 287 | local_header.oem_id, local_header.oem_table_id, |
| 288 | local_header.oem_revision, |
| 289 | local_header.asl_compiler_id, |
| 290 | local_header.asl_compiler_revision)); |
| 291 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 292 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 293 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 294 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 295 | /******************************************************************************* |
| 296 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 297 | * FUNCTION: acpi_tb_validate_checksum |
| 298 | * |
| 299 | * PARAMETERS: Table - ACPI table to verify |
| 300 | * Length - Length of entire table |
| 301 | * |
| 302 | * RETURN: Status |
| 303 | * |
| 304 | * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns |
| 305 | * exception on bad checksum. |
| 306 | * |
| 307 | ******************************************************************************/ |
| 308 | |
| 309 | acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length) |
| 310 | { |
| 311 | u8 checksum; |
| 312 | |
| 313 | /* Compute the checksum on the table */ |
| 314 | |
| 315 | checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length); |
| 316 | |
| 317 | /* Checksum ok? (should be zero) */ |
| 318 | |
| 319 | if (checksum) { |
| 320 | ACPI_WARNING((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 321 | "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X", |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 322 | table->signature, table->checksum, |
| 323 | (u8) (table->checksum - checksum))); |
| 324 | |
| 325 | #if (ACPI_CHECKSUM_ABORT) |
| 326 | |
| 327 | return (AE_BAD_CHECKSUM); |
| 328 | #endif |
| 329 | } |
| 330 | |
| 331 | return (AE_OK); |
| 332 | } |
| 333 | |
| 334 | /******************************************************************************* |
| 335 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 336 | * FUNCTION: acpi_tb_checksum |
| 337 | * |
| 338 | * PARAMETERS: Buffer - Pointer to memory region to be checked |
| 339 | * Length - Length of this memory region |
| 340 | * |
| 341 | * RETURN: Checksum (u8) |
| 342 | * |
| 343 | * DESCRIPTION: Calculates circular checksum of memory region. |
| 344 | * |
| 345 | ******************************************************************************/ |
| 346 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 347 | u8 acpi_tb_checksum(u8 *buffer, u32 length) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 348 | { |
| 349 | u8 sum = 0; |
| 350 | u8 *end = buffer + length; |
| 351 | |
| 352 | while (buffer < end) { |
| 353 | sum = (u8) (sum + *(buffer++)); |
| 354 | } |
| 355 | |
| 356 | return sum; |
| 357 | } |
| 358 | |
| 359 | /******************************************************************************* |
| 360 | * |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 361 | * FUNCTION: acpi_tb_check_dsdt_header |
| 362 | * |
| 363 | * PARAMETERS: None |
| 364 | * |
| 365 | * RETURN: None |
| 366 | * |
| 367 | * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect |
| 368 | * if the DSDT has been replaced from outside the OS and/or if |
| 369 | * the DSDT header has been corrupted. |
| 370 | * |
| 371 | ******************************************************************************/ |
| 372 | |
| 373 | void acpi_tb_check_dsdt_header(void) |
| 374 | { |
| 375 | |
| 376 | /* Compare original length and checksum to current values */ |
| 377 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 378 | if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length || |
| 379 | acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) { |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 380 | ACPI_ERROR((AE_INFO, |
| 381 | "The DSDT has been corrupted or replaced - old, new headers below")); |
| 382 | acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 383 | acpi_tb_print_table_header(0, acpi_gbl_DSDT); |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 384 | |
Lin Ming | aa2110c | 2010-04-08 14:34:27 +0800 | [diff] [blame] | 385 | ACPI_ERROR((AE_INFO, |
| 386 | "Please send DMI info to linux-acpi@vger.kernel.org\n" |
| 387 | "If system does not work as expected, please boot with acpi=copy_dsdt")); |
| 388 | |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 389 | /* Disable further error messages */ |
| 390 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 391 | acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length; |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 392 | acpi_gbl_original_dsdt_header.checksum = |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 393 | acpi_gbl_DSDT->checksum; |
Lin Ming | 729df0f | 2010-04-01 10:47:56 +0800 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | /******************************************************************************* |
| 398 | * |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 399 | * FUNCTION: acpi_tb_copy_dsdt |
| 400 | * |
| 401 | * PARAMETERS: table_desc - Installed table to copy |
| 402 | * |
| 403 | * RETURN: None |
| 404 | * |
| 405 | * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory. |
| 406 | * Some very bad BIOSs are known to either corrupt the DSDT or |
| 407 | * install a new, bad DSDT. This copy works around the problem. |
| 408 | * |
| 409 | ******************************************************************************/ |
| 410 | |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 411 | struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index) |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 412 | { |
| 413 | struct acpi_table_header *new_table; |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 414 | struct acpi_table_desc *table_desc; |
| 415 | |
| 416 | table_desc = &acpi_gbl_root_table_list.tables[table_index]; |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 417 | |
| 418 | new_table = ACPI_ALLOCATE(table_desc->length); |
| 419 | if (!new_table) { |
| 420 | ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X", |
| 421 | table_desc->length)); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 422 | return (NULL); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length); |
| 426 | acpi_tb_delete_table(table_desc); |
| 427 | table_desc->pointer = new_table; |
| 428 | table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED; |
| 429 | |
| 430 | ACPI_INFO((AE_INFO, |
| 431 | "Forced DSDT copy: length 0x%05X copied locally, original unmapped", |
| 432 | new_table->length)); |
Bob Moore | 43323cb | 2010-04-07 11:05:11 +0800 | [diff] [blame] | 433 | |
| 434 | return (new_table); |
Lin Ming | 69ec87e | 2010-04-01 11:14:12 +0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /******************************************************************************* |
| 438 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 439 | * FUNCTION: acpi_tb_install_table |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 440 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 441 | * PARAMETERS: Address - Physical address of DSDT or FACS |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 442 | * Signature - Table signature, NULL if no need to |
| 443 | * match |
| 444 | * table_index - Index into root table array |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 445 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 446 | * RETURN: None |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 447 | * |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 448 | * DESCRIPTION: Install an ACPI table into the global data structure. The |
| 449 | * table override mechanism is implemented here to allow the host |
| 450 | * OS to replace any table before it is installed in the root |
| 451 | * table array. |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 452 | * |
| 453 | ******************************************************************************/ |
| 454 | |
Bob Moore | 765ec20 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 455 | void |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 456 | acpi_tb_install_table(acpi_physical_address address, |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 457 | char *signature, u32 table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 458 | { |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 459 | u8 flags; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 460 | acpi_status status; |
| 461 | struct acpi_table_header *table_to_install; |
| 462 | struct acpi_table_header *mapped_table; |
| 463 | struct acpi_table_header *override_table = NULL; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 464 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 465 | if (!address) { |
| 466 | ACPI_ERROR((AE_INFO, |
| 467 | "Null physical address for ACPI table [%s]", |
| 468 | signature)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 469 | return; |
| 470 | } |
| 471 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 472 | /* Map just the table header */ |
| 473 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 474 | mapped_table = |
| 475 | acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 476 | if (!mapped_table) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 480 | /* If a particular signature is expected (DSDT/FACS), it must match */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 481 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 482 | if (signature && !ACPI_COMPARE_NAME(mapped_table->signature, signature)) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 483 | ACPI_ERROR((AE_INFO, |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 484 | "Invalid signature 0x%X for ACPI table, expected [%s]", |
| 485 | *ACPI_CAST_PTR(u32, mapped_table->signature), |
| 486 | signature)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 487 | goto unmap_and_exit; |
| 488 | } |
| 489 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 490 | /* |
| 491 | * ACPI Table Override: |
| 492 | * |
| 493 | * Before we install the table, let the host OS override it with a new |
| 494 | * one if desired. Any table within the RSDT/XSDT can be replaced, |
| 495 | * including the DSDT which is pointed to by the FADT. |
| 496 | */ |
| 497 | status = acpi_os_table_override(mapped_table, &override_table); |
| 498 | if (ACPI_SUCCESS(status) && override_table) { |
| 499 | ACPI_INFO((AE_INFO, |
| 500 | "%4.4s @ 0x%p Table override, replaced with:", |
| 501 | mapped_table->signature, ACPI_CAST_PTR(void, |
| 502 | address))); |
| 503 | |
| 504 | acpi_gbl_root_table_list.tables[table_index].pointer = |
| 505 | override_table; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 506 | address = ACPI_PTR_TO_PHYSADDR(override_table); |
| 507 | |
| 508 | table_to_install = override_table; |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 509 | flags = ACPI_TABLE_ORIGIN_OVERRIDE; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 510 | } else { |
| 511 | table_to_install = mapped_table; |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 512 | flags = ACPI_TABLE_ORIGIN_MAPPED; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 513 | } |
| 514 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 515 | /* Initialize the table entry */ |
| 516 | |
| 517 | acpi_gbl_root_table_list.tables[table_index].address = address; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 518 | acpi_gbl_root_table_list.tables[table_index].length = |
| 519 | table_to_install->length; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 520 | acpi_gbl_root_table_list.tables[table_index].flags = flags; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 521 | |
| 522 | ACPI_MOVE_32_TO_32(& |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 523 | (acpi_gbl_root_table_list.tables[table_index]. |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 524 | signature), table_to_install->signature); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 525 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 526 | acpi_tb_print_table_header(address, table_to_install); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 527 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 528 | if (table_index == ACPI_TABLE_INDEX_DSDT) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 529 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 530 | /* Global integer width is based upon revision of the DSDT */ |
| 531 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 532 | acpi_ut_set_integer_width(table_to_install->revision); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | unmap_and_exit: |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 536 | acpi_os_unmap_memory(mapped_table, sizeof(struct acpi_table_header)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /******************************************************************************* |
| 540 | * |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 541 | * FUNCTION: acpi_tb_get_root_table_entry |
| 542 | * |
| 543 | * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry |
| 544 | * table_entry_size - sizeof 32 or 64 (RSDT or XSDT) |
| 545 | * |
| 546 | * RETURN: Physical address extracted from the root table |
| 547 | * |
| 548 | * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on |
| 549 | * both 32-bit and 64-bit platforms |
| 550 | * |
| 551 | * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on |
| 552 | * 64-bit platforms. |
| 553 | * |
| 554 | ******************************************************************************/ |
| 555 | |
| 556 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 557 | 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] | 558 | { |
| 559 | u64 address64; |
| 560 | |
| 561 | /* |
| 562 | * Get the table physical address (32-bit for RSDT, 64-bit for XSDT): |
| 563 | * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT |
| 564 | */ |
| 565 | if (table_entry_size == sizeof(u32)) { |
| 566 | /* |
| 567 | * 32-bit platform, RSDT: Return 32-bit table entry |
| 568 | * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return |
| 569 | */ |
| 570 | return ((acpi_physical_address) |
| 571 | (*ACPI_CAST_PTR(u32, table_entry))); |
| 572 | } else { |
| 573 | /* |
| 574 | * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 575 | * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, |
| 576 | * return 64-bit |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 577 | */ |
| 578 | ACPI_MOVE_64_TO_64(&address64, table_entry); |
| 579 | |
| 580 | #if ACPI_MACHINE_WIDTH == 32 |
| 581 | if (address64 > ACPI_UINT32_MAX) { |
| 582 | |
Bob Moore | ea5d8eb | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 583 | /* Will truncate 64-bit address to 32 bits, issue warning */ |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 584 | |
| 585 | ACPI_WARNING((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 586 | "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X)," |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 587 | " truncating", |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 588 | ACPI_FORMAT_UINT64(address64))); |
| 589 | } |
| 590 | #endif |
| 591 | return ((acpi_physical_address) (address64)); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /******************************************************************************* |
| 596 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 597 | * FUNCTION: acpi_tb_parse_root_table |
| 598 | * |
| 599 | * PARAMETERS: Rsdp - Pointer to the RSDP |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 600 | * |
| 601 | * RETURN: Status |
| 602 | * |
| 603 | * DESCRIPTION: This function is called to parse the Root System Description |
| 604 | * Table (RSDT or XSDT) |
| 605 | * |
| 606 | * NOTE: Tables are mapped (not copied) for efficiency. The FACS must |
| 607 | * be mapped and cannot be copied because it contains the actual |
| 608 | * memory location of the ACPI Global Lock. |
| 609 | * |
| 610 | ******************************************************************************/ |
| 611 | |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 612 | acpi_status __init |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 613 | acpi_tb_parse_root_table(acpi_physical_address rsdp_address) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 614 | { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 615 | struct acpi_table_rsdp *rsdp; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 616 | u32 table_entry_size; |
| 617 | u32 i; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 618 | u32 table_count; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 619 | struct acpi_table_header *table; |
| 620 | acpi_physical_address address; |
Andrew Morton | 8ab7367 | 2007-10-02 13:24:10 -0700 | [diff] [blame] | 621 | acpi_physical_address uninitialized_var(rsdt_address); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 622 | u32 length; |
| 623 | u8 *table_entry; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 624 | acpi_status status; |
| 625 | |
| 626 | ACPI_FUNCTION_TRACE(tb_parse_root_table); |
| 627 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 628 | /* |
| 629 | * Map the entire RSDP and extract the address of the RSDT or XSDT |
| 630 | */ |
| 631 | rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp)); |
| 632 | if (!rsdp) { |
| 633 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 634 | } |
| 635 | |
| 636 | acpi_tb_print_table_header(rsdp_address, |
| 637 | ACPI_CAST_PTR(struct acpi_table_header, |
| 638 | rsdp)); |
| 639 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 640 | /* Differentiate between RSDT and XSDT root tables */ |
| 641 | |
Zhao Yakui | 237889b | 2008-12-17 16:55:18 +0800 | [diff] [blame] | 642 | if (rsdp->revision > 1 && rsdp->xsdt_physical_address |
| 643 | && !acpi_rsdt_forced) { |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 644 | /* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 645 | * Root table is an XSDT (64-bit physical addresses). We must use the |
| 646 | * XSDT if the revision is > 1 and the XSDT pointer is present, as per |
| 647 | * the ACPI specification. |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 648 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 649 | address = (acpi_physical_address) rsdp->xsdt_physical_address; |
| 650 | table_entry_size = sizeof(u64); |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 651 | rsdt_address = (acpi_physical_address) |
| 652 | rsdp->rsdt_physical_address; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 653 | } else { |
| 654 | /* Root table is an RSDT (32-bit physical addresses) */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 655 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 656 | address = (acpi_physical_address) rsdp->rsdt_physical_address; |
| 657 | table_entry_size = sizeof(u32); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 658 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 659 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 660 | /* |
| 661 | * It is not possible to map more than one entry in some environments, |
| 662 | * so unmap the RSDP here before mapping other tables |
| 663 | */ |
| 664 | acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp)); |
| 665 | |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 666 | if (table_entry_size == sizeof(u64)) { |
| 667 | if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) { |
| 668 | /* XSDT has NULL entry, RSDT is used */ |
| 669 | address = rsdt_address; |
| 670 | table_entry_size = sizeof(u32); |
Joe Perches | 4fdb2a0 | 2007-11-19 17:48:02 -0800 | [diff] [blame] | 671 | ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, " |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 672 | "using RSDT")); |
| 673 | } |
| 674 | } |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 675 | /* Map the RSDT/XSDT table header to get the full table length */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 676 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 677 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 678 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 679 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 680 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 681 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 682 | acpi_tb_print_table_header(address, table); |
| 683 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 684 | /* Get the length of the full table, verify length and map entire table */ |
| 685 | |
| 686 | length = table->length; |
| 687 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 688 | |
| 689 | if (length < sizeof(struct acpi_table_header)) { |
| 690 | ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", |
| 691 | length)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 692 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | table = acpi_os_map_memory(address, length); |
| 696 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 697 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /* Validate the root table checksum */ |
| 701 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 702 | status = acpi_tb_verify_checksum(table, length); |
| 703 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 704 | acpi_os_unmap_memory(table, length); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 705 | return_ACPI_STATUS(status); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 706 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 707 | |
| 708 | /* Calculate the number of tables described in the root table */ |
| 709 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 710 | table_count = (u32)((table->length - sizeof(struct acpi_table_header)) / |
| 711 | table_entry_size); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 712 | /* |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 713 | * First two entries in the table array are reserved for the DSDT |
| 714 | * and FACS, which are not actually present in the RSDT/XSDT - they |
| 715 | * come from the FADT |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 716 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 717 | table_entry = |
| 718 | ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header); |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 719 | acpi_gbl_root_table_list.current_table_count = 2; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 720 | |
| 721 | /* |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 722 | * Initialize the root table array from the RSDT/XSDT |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 723 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 724 | for (i = 0; i < table_count; i++) { |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 725 | if (acpi_gbl_root_table_list.current_table_count >= |
| 726 | acpi_gbl_root_table_list.max_table_count) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 727 | |
| 728 | /* There is no more room in the root table array, attempt resize */ |
| 729 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 730 | status = acpi_tb_resize_root_table_list(); |
| 731 | if (ACPI_FAILURE(status)) { |
| 732 | ACPI_WARNING((AE_INFO, |
| 733 | "Truncating %u table entries!", |
Myron Stowe | 386e4a8 | 2009-01-30 15:44:53 -0700 | [diff] [blame] | 734 | (unsigned) (table_count - |
| 735 | (acpi_gbl_root_table_list. |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 736 | current_table_count - |
| 737 | 2)))); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 738 | break; |
| 739 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 742 | /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ |
| 743 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 744 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list. |
| 745 | current_table_count].address = |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 746 | acpi_tb_get_root_table_entry(table_entry, table_entry_size); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 747 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 748 | table_entry += table_entry_size; |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 749 | acpi_gbl_root_table_list.current_table_count++; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /* |
| 753 | * It is not possible to map more than one entry in some environments, |
| 754 | * so unmap the root table here before mapping other tables |
| 755 | */ |
| 756 | acpi_os_unmap_memory(table, length); |
| 757 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 758 | /* |
| 759 | * Complete the initialization of the root table array by examining |
| 760 | * the header of each table |
| 761 | */ |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 762 | 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] | 763 | acpi_tb_install_table(acpi_gbl_root_table_list.tables[i]. |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 764 | address, NULL, i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 765 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 766 | /* Special case for FADT - get the DSDT and FACS */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 767 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 768 | if (ACPI_COMPARE_NAME |
| 769 | (&acpi_gbl_root_table_list.tables[i].signature, |
| 770 | ACPI_SIG_FADT)) { |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 771 | acpi_tb_parse_fadt(i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 772 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 775 | return_ACPI_STATUS(AE_OK); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 776 | } |