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 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2008, 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 | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 52 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 53 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); |
| 54 | |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 55 | /******************************************************************************* |
| 56 | * |
| 57 | * FUNCTION: acpi_tb_check_xsdt |
| 58 | * |
| 59 | * PARAMETERS: address - Pointer to the XSDT |
| 60 | * |
| 61 | * RETURN: status |
| 62 | * AE_OK - XSDT is okay |
| 63 | * AE_NO_MEMORY - can't map XSDT |
| 64 | * AE_INVALID_TABLE_LENGTH - invalid table length |
| 65 | * AE_NULL_ENTRY - XSDT has NULL entry |
| 66 | * |
| 67 | * DESCRIPTION: validate XSDT |
| 68 | ******************************************************************************/ |
| 69 | |
| 70 | static acpi_status |
| 71 | acpi_tb_check_xsdt(acpi_physical_address address) |
| 72 | { |
| 73 | struct acpi_table_header *table; |
| 74 | u32 length; |
| 75 | u64 xsdt_entry_address; |
| 76 | u8 *table_entry; |
| 77 | u32 table_count; |
| 78 | int i; |
| 79 | |
| 80 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 81 | if (!table) |
| 82 | return AE_NO_MEMORY; |
| 83 | |
| 84 | length = table->length; |
| 85 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 86 | if (length < sizeof(struct acpi_table_header)) |
| 87 | return AE_INVALID_TABLE_LENGTH; |
| 88 | |
| 89 | table = acpi_os_map_memory(address, length); |
| 90 | if (!table) |
| 91 | return AE_NO_MEMORY; |
| 92 | |
| 93 | /* Calculate the number of tables described in XSDT */ |
| 94 | table_count = |
| 95 | (u32) ((table->length - |
| 96 | sizeof(struct acpi_table_header)) / sizeof(u64)); |
| 97 | table_entry = |
| 98 | ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header); |
| 99 | for (i = 0; i < table_count; i++) { |
| 100 | ACPI_MOVE_64_TO_64(&xsdt_entry_address, table_entry); |
| 101 | if (!xsdt_entry_address) { |
| 102 | /* XSDT has NULL entry */ |
| 103 | break; |
| 104 | } |
| 105 | table_entry += sizeof(u64); |
| 106 | } |
| 107 | acpi_os_unmap_memory(table, length); |
| 108 | |
| 109 | if (i < table_count) |
| 110 | return AE_NULL_ENTRY; |
| 111 | else |
| 112 | return AE_OK; |
| 113 | } |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /******************************************************************************* |
| 116 | * |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 117 | * FUNCTION: acpi_tb_initialize_facs |
| 118 | * |
| 119 | * PARAMETERS: None |
| 120 | * |
| 121 | * RETURN: Status |
| 122 | * |
| 123 | * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global |
| 124 | * for accessing the Global Lock and Firmware Waking Vector |
| 125 | * |
| 126 | ******************************************************************************/ |
| 127 | |
| 128 | acpi_status acpi_tb_initialize_facs(void) |
| 129 | { |
| 130 | acpi_status status; |
| 131 | |
| 132 | status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, |
| 133 | ACPI_CAST_INDIRECT_PTR(struct |
| 134 | acpi_table_header, |
| 135 | &acpi_gbl_FACS)); |
| 136 | return status; |
| 137 | } |
| 138 | |
| 139 | /******************************************************************************* |
| 140 | * |
Bob Moore | c857303 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 141 | * FUNCTION: acpi_tb_tables_loaded |
| 142 | * |
| 143 | * PARAMETERS: None |
| 144 | * |
| 145 | * RETURN: TRUE if required ACPI tables are loaded |
| 146 | * |
| 147 | * DESCRIPTION: Determine if the minimum required ACPI tables are present |
| 148 | * (FADT, FACS, DSDT) |
| 149 | * |
| 150 | ******************************************************************************/ |
| 151 | |
| 152 | u8 acpi_tb_tables_loaded(void) |
| 153 | { |
| 154 | |
| 155 | if (acpi_gbl_root_table_list.count >= 3) { |
| 156 | return (TRUE); |
| 157 | } |
| 158 | |
| 159 | return (FALSE); |
| 160 | } |
| 161 | |
| 162 | /******************************************************************************* |
| 163 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 164 | * FUNCTION: acpi_tb_print_table_header |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 165 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 166 | * PARAMETERS: Address - Table physical address |
| 167 | * Header - Table header |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 168 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 169 | * RETURN: None |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 170 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 171 | * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP. |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 172 | * |
| 173 | ******************************************************************************/ |
| 174 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 175 | void |
| 176 | acpi_tb_print_table_header(acpi_physical_address address, |
| 177 | struct acpi_table_header *header) |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 178 | { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 179 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 180 | if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) { |
| 181 | |
| 182 | /* FACS only has signature and length fields of common table header */ |
| 183 | |
Len Brown | 03c6d13 | 2007-02-06 15:28:23 -0500 | [diff] [blame] | 184 | ACPI_INFO((AE_INFO, "%4.4s %08lX, %04X", |
| 185 | header->signature, (unsigned long)address, |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 186 | header->length)); |
| 187 | } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) { |
| 188 | |
| 189 | /* RSDP has no common fields */ |
| 190 | |
Len Brown | 03c6d13 | 2007-02-06 15:28:23 -0500 | [diff] [blame] | 191 | ACPI_INFO((AE_INFO, "RSDP %08lX, %04X (r%d %6.6s)", |
| 192 | (unsigned long)address, |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 193 | (ACPI_CAST_PTR(struct acpi_table_rsdp, header)-> |
| 194 | revision > |
| 195 | 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 196 | header)->length : 20, |
| 197 | ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 198 | header)->revision, |
| 199 | ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 200 | header)->oem_id)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 201 | } else { |
Bob Moore | 4bf2739 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 202 | /* Standard ACPI table with full common header */ |
| 203 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 204 | ACPI_INFO((AE_INFO, |
Len Brown | 03c6d13 | 2007-02-06 15:28:23 -0500 | [diff] [blame] | 205 | "%4.4s %08lX, %04X (r%d %6.6s %8.8s %8X %4.4s %8X)", |
| 206 | header->signature, (unsigned long)address, |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 207 | header->length, header->revision, header->oem_id, |
| 208 | header->oem_table_id, header->oem_revision, |
| 209 | header->asl_compiler_id, |
| 210 | header->asl_compiler_revision)); |
| 211 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 212 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 213 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 214 | /******************************************************************************* |
| 215 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 216 | * FUNCTION: acpi_tb_validate_checksum |
| 217 | * |
| 218 | * PARAMETERS: Table - ACPI table to verify |
| 219 | * Length - Length of entire table |
| 220 | * |
| 221 | * RETURN: Status |
| 222 | * |
| 223 | * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns |
| 224 | * exception on bad checksum. |
| 225 | * |
| 226 | ******************************************************************************/ |
| 227 | |
| 228 | acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length) |
| 229 | { |
| 230 | u8 checksum; |
| 231 | |
| 232 | /* Compute the checksum on the table */ |
| 233 | |
| 234 | checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length); |
| 235 | |
| 236 | /* Checksum ok? (should be zero) */ |
| 237 | |
| 238 | if (checksum) { |
| 239 | ACPI_WARNING((AE_INFO, |
Bob Moore | 98af37f | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 240 | "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X", |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 241 | table->signature, table->checksum, |
| 242 | (u8) (table->checksum - checksum))); |
| 243 | |
| 244 | #if (ACPI_CHECKSUM_ABORT) |
| 245 | |
| 246 | return (AE_BAD_CHECKSUM); |
| 247 | #endif |
| 248 | } |
| 249 | |
| 250 | return (AE_OK); |
| 251 | } |
| 252 | |
| 253 | /******************************************************************************* |
| 254 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 255 | * FUNCTION: acpi_tb_checksum |
| 256 | * |
| 257 | * PARAMETERS: Buffer - Pointer to memory region to be checked |
| 258 | * Length - Length of this memory region |
| 259 | * |
| 260 | * RETURN: Checksum (u8) |
| 261 | * |
| 262 | * DESCRIPTION: Calculates circular checksum of memory region. |
| 263 | * |
| 264 | ******************************************************************************/ |
| 265 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 266 | u8 acpi_tb_checksum(u8 *buffer, u32 length) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 267 | { |
| 268 | u8 sum = 0; |
| 269 | u8 *end = buffer + length; |
| 270 | |
| 271 | while (buffer < end) { |
| 272 | sum = (u8) (sum + *(buffer++)); |
| 273 | } |
| 274 | |
| 275 | return sum; |
| 276 | } |
| 277 | |
| 278 | /******************************************************************************* |
| 279 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 280 | * FUNCTION: acpi_tb_install_table |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 281 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 282 | * PARAMETERS: Address - Physical address of DSDT or FACS |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 283 | * Signature - Table signature, NULL if no need to |
| 284 | * match |
| 285 | * table_index - Index into root table array |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 286 | * |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 287 | * RETURN: None |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 288 | * |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 289 | * DESCRIPTION: Install an ACPI table into the global data structure. The |
| 290 | * table override mechanism is implemented here to allow the host |
| 291 | * OS to replace any table before it is installed in the root |
| 292 | * table array. |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 293 | * |
| 294 | ******************************************************************************/ |
| 295 | |
Bob Moore | 765ec20 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 296 | void |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 297 | acpi_tb_install_table(acpi_physical_address address, |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 298 | char *signature, u32 table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 299 | { |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 300 | u8 flags; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 301 | acpi_status status; |
| 302 | struct acpi_table_header *table_to_install; |
| 303 | struct acpi_table_header *mapped_table; |
| 304 | struct acpi_table_header *override_table = NULL; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 305 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 306 | if (!address) { |
| 307 | ACPI_ERROR((AE_INFO, |
| 308 | "Null physical address for ACPI table [%s]", |
| 309 | signature)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 313 | /* Map just the table header */ |
| 314 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 315 | mapped_table = |
| 316 | acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 317 | if (!mapped_table) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 318 | return; |
| 319 | } |
| 320 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 321 | /* If a particular signature is expected (DSDT/FACS), it must match */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 322 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 323 | if (signature && !ACPI_COMPARE_NAME(mapped_table->signature, signature)) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 324 | ACPI_ERROR((AE_INFO, |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 325 | "Invalid signature 0x%X for ACPI table, expected [%s]", |
| 326 | *ACPI_CAST_PTR(u32, mapped_table->signature), |
| 327 | signature)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 328 | goto unmap_and_exit; |
| 329 | } |
| 330 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 331 | /* |
| 332 | * ACPI Table Override: |
| 333 | * |
| 334 | * Before we install the table, let the host OS override it with a new |
| 335 | * one if desired. Any table within the RSDT/XSDT can be replaced, |
| 336 | * including the DSDT which is pointed to by the FADT. |
| 337 | */ |
| 338 | status = acpi_os_table_override(mapped_table, &override_table); |
| 339 | if (ACPI_SUCCESS(status) && override_table) { |
| 340 | ACPI_INFO((AE_INFO, |
| 341 | "%4.4s @ 0x%p Table override, replaced with:", |
| 342 | mapped_table->signature, ACPI_CAST_PTR(void, |
| 343 | address))); |
| 344 | |
| 345 | acpi_gbl_root_table_list.tables[table_index].pointer = |
| 346 | override_table; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 347 | address = ACPI_PTR_TO_PHYSADDR(override_table); |
| 348 | |
| 349 | table_to_install = override_table; |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 350 | flags = ACPI_TABLE_ORIGIN_OVERRIDE; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 351 | } else { |
| 352 | table_to_install = mapped_table; |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 353 | flags = ACPI_TABLE_ORIGIN_MAPPED; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 354 | } |
| 355 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 356 | /* Initialize the table entry */ |
| 357 | |
| 358 | acpi_gbl_root_table_list.tables[table_index].address = address; |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 359 | acpi_gbl_root_table_list.tables[table_index].length = |
| 360 | table_to_install->length; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 361 | acpi_gbl_root_table_list.tables[table_index].flags = flags; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 362 | |
| 363 | ACPI_MOVE_32_TO_32(& |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 364 | (acpi_gbl_root_table_list.tables[table_index]. |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 365 | signature), table_to_install->signature); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 366 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 367 | acpi_tb_print_table_header(address, table_to_install); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 368 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 369 | if (table_index == ACPI_TABLE_INDEX_DSDT) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 370 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 371 | /* Global integer width is based upon revision of the DSDT */ |
| 372 | |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 373 | acpi_ut_set_integer_width(table_to_install->revision); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | unmap_and_exit: |
Bob Moore | ac5f98d | 2009-02-03 14:35:25 +0800 | [diff] [blame] | 377 | acpi_os_unmap_memory(mapped_table, sizeof(struct acpi_table_header)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /******************************************************************************* |
| 381 | * |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 382 | * FUNCTION: acpi_tb_get_root_table_entry |
| 383 | * |
| 384 | * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry |
| 385 | * table_entry_size - sizeof 32 or 64 (RSDT or XSDT) |
| 386 | * |
| 387 | * RETURN: Physical address extracted from the root table |
| 388 | * |
| 389 | * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on |
| 390 | * both 32-bit and 64-bit platforms |
| 391 | * |
| 392 | * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on |
| 393 | * 64-bit platforms. |
| 394 | * |
| 395 | ******************************************************************************/ |
| 396 | |
| 397 | static acpi_physical_address |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 398 | 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] | 399 | { |
| 400 | u64 address64; |
| 401 | |
| 402 | /* |
| 403 | * Get the table physical address (32-bit for RSDT, 64-bit for XSDT): |
| 404 | * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT |
| 405 | */ |
| 406 | if (table_entry_size == sizeof(u32)) { |
| 407 | /* |
| 408 | * 32-bit platform, RSDT: Return 32-bit table entry |
| 409 | * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return |
| 410 | */ |
| 411 | return ((acpi_physical_address) |
| 412 | (*ACPI_CAST_PTR(u32, table_entry))); |
| 413 | } else { |
| 414 | /* |
| 415 | * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame^] | 416 | * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, |
| 417 | * return 64-bit |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 418 | */ |
| 419 | ACPI_MOVE_64_TO_64(&address64, table_entry); |
| 420 | |
| 421 | #if ACPI_MACHINE_WIDTH == 32 |
| 422 | if (address64 > ACPI_UINT32_MAX) { |
| 423 | |
Bob Moore | ea5d8eb | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 424 | /* Will truncate 64-bit address to 32 bits, issue warning */ |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 425 | |
| 426 | ACPI_WARNING((AE_INFO, |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame^] | 427 | "64-bit Physical Address in XSDT is too large (%8.8X%8.8X)," |
| 428 | " truncating", |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 429 | ACPI_FORMAT_UINT64(address64))); |
| 430 | } |
| 431 | #endif |
| 432 | return ((acpi_physical_address) (address64)); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /******************************************************************************* |
| 437 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 438 | * FUNCTION: acpi_tb_parse_root_table |
| 439 | * |
| 440 | * PARAMETERS: Rsdp - Pointer to the RSDP |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 441 | * |
| 442 | * RETURN: Status |
| 443 | * |
| 444 | * DESCRIPTION: This function is called to parse the Root System Description |
| 445 | * Table (RSDT or XSDT) |
| 446 | * |
| 447 | * NOTE: Tables are mapped (not copied) for efficiency. The FACS must |
| 448 | * be mapped and cannot be copied because it contains the actual |
| 449 | * memory location of the ACPI Global Lock. |
| 450 | * |
| 451 | ******************************************************************************/ |
| 452 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 453 | acpi_status __init |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 454 | acpi_tb_parse_root_table(acpi_physical_address rsdp_address) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 455 | { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 456 | struct acpi_table_rsdp *rsdp; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 457 | u32 table_entry_size; |
| 458 | u32 i; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 459 | u32 table_count; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 460 | struct acpi_table_header *table; |
| 461 | acpi_physical_address address; |
Andrew Morton | 8ab7367 | 2007-10-02 13:24:10 -0700 | [diff] [blame] | 462 | acpi_physical_address uninitialized_var(rsdt_address); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 463 | u32 length; |
| 464 | u8 *table_entry; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 465 | acpi_status status; |
| 466 | |
| 467 | ACPI_FUNCTION_TRACE(tb_parse_root_table); |
| 468 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 469 | /* |
| 470 | * Map the entire RSDP and extract the address of the RSDT or XSDT |
| 471 | */ |
| 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 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 481 | /* Differentiate between RSDT and XSDT root tables */ |
| 482 | |
Zhao Yakui | 237889b | 2008-12-17 16:55:18 +0800 | [diff] [blame] | 483 | if (rsdp->revision > 1 && rsdp->xsdt_physical_address |
| 484 | && !acpi_rsdt_forced) { |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 485 | /* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 486 | * Root table is an XSDT (64-bit physical addresses). We must use the |
| 487 | * XSDT if the revision is > 1 and the XSDT pointer is present, as per |
| 488 | * 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; |
| 491 | table_entry_size = sizeof(u64); |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 492 | rsdt_address = (acpi_physical_address) |
| 493 | rsdp->rsdt_physical_address; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 494 | } else { |
| 495 | /* Root table is an RSDT (32-bit physical addresses) */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 496 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 497 | address = (acpi_physical_address) rsdp->rsdt_physical_address; |
| 498 | table_entry_size = sizeof(u32); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 499 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 500 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 501 | /* |
| 502 | * It is not possible to map more than one entry in some environments, |
| 503 | * so unmap the RSDP here before mapping other tables |
| 504 | */ |
| 505 | acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp)); |
| 506 | |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 507 | if (table_entry_size == sizeof(u64)) { |
| 508 | if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) { |
| 509 | /* XSDT has NULL entry, RSDT is used */ |
| 510 | address = rsdt_address; |
| 511 | table_entry_size = sizeof(u32); |
Joe Perches | 4fdb2a0 | 2007-11-19 17:48:02 -0800 | [diff] [blame] | 512 | ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, " |
Zhao Yakui | 9f3119b | 2007-08-24 16:18:16 +0800 | [diff] [blame] | 513 | "using RSDT")); |
| 514 | } |
| 515 | } |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 516 | /* Map the RSDT/XSDT table header to get the full table length */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 517 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 518 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
| 519 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 520 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 521 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 522 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 523 | acpi_tb_print_table_header(address, table); |
| 524 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 525 | /* Get the length of the full table, verify length and map entire table */ |
| 526 | |
| 527 | length = table->length; |
| 528 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
| 529 | |
| 530 | if (length < sizeof(struct acpi_table_header)) { |
| 531 | ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", |
| 532 | length)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 533 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | table = acpi_os_map_memory(address, length); |
| 537 | if (!table) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 538 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /* Validate the root table checksum */ |
| 542 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 543 | status = acpi_tb_verify_checksum(table, length); |
| 544 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 545 | acpi_os_unmap_memory(table, length); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 546 | return_ACPI_STATUS(status); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 547 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 548 | |
| 549 | /* Calculate the number of tables described in the root table */ |
| 550 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame^] | 551 | table_count = (u32)((table->length - sizeof(struct acpi_table_header)) / |
| 552 | table_entry_size); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 553 | /* |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame^] | 554 | * First two entries in the table array are reserved for the DSDT |
| 555 | * and FACS, which are not actually present in the RSDT/XSDT - they |
| 556 | * come from the FADT |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 557 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 558 | table_entry = |
| 559 | ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header); |
| 560 | acpi_gbl_root_table_list.count = 2; |
| 561 | |
| 562 | /* |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 563 | * Initialize the root table array from the RSDT/XSDT |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 564 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 565 | for (i = 0; i < table_count; i++) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 566 | if (acpi_gbl_root_table_list.count >= |
| 567 | acpi_gbl_root_table_list.size) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 568 | |
| 569 | /* There is no more room in the root table array, attempt resize */ |
| 570 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 571 | status = acpi_tb_resize_root_table_list(); |
| 572 | if (ACPI_FAILURE(status)) { |
| 573 | ACPI_WARNING((AE_INFO, |
| 574 | "Truncating %u table entries!", |
Myron Stowe | 386e4a8 | 2009-01-30 15:44:53 -0700 | [diff] [blame] | 575 | (unsigned) (table_count - |
| 576 | (acpi_gbl_root_table_list. |
| 577 | count - 2)))); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 578 | break; |
| 579 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 582 | /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ |
| 583 | |
| 584 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count]. |
| 585 | address = |
| 586 | acpi_tb_get_root_table_entry(table_entry, table_entry_size); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 587 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 588 | table_entry += table_entry_size; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 589 | acpi_gbl_root_table_list.count++; |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | * It is not possible to map more than one entry in some environments, |
| 594 | * so unmap the root table here before mapping other tables |
| 595 | */ |
| 596 | acpi_os_unmap_memory(table, length); |
| 597 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 598 | /* |
| 599 | * Complete the initialization of the root table array by examining |
| 600 | * the header of each table |
| 601 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 602 | for (i = 2; i < acpi_gbl_root_table_list.count; i++) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 603 | acpi_tb_install_table(acpi_gbl_root_table_list.tables[i]. |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 604 | address, NULL, i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 605 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 606 | /* Special case for FADT - get the DSDT and FACS */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 607 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 608 | if (ACPI_COMPARE_NAME |
| 609 | (&acpi_gbl_root_table_list.tables[i].signature, |
| 610 | ACPI_SIG_FADT)) { |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 611 | acpi_tb_parse_fadt(i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 612 | } |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 615 | return_ACPI_STATUS(AE_OK); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 616 | } |