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