blob: 50e677711e5b68561af337fbf8b78297bde6bc13 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
Bob Mooref3d2e782007-02-02 19:48:18 +03003 * Module Name: tbutils - table utilities
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 *****************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("tbutils")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Bob Moorea4bbb812007-02-02 19:48:19 +030051static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +080052acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
53
Zhao Yakui9f3119b2007-08-24 16:18:16 +080054/*******************************************************************************
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
69static acpi_status
70acpi_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 Moorea4bbb812007-02-02 19:48:19 +0300113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/*******************************************************************************
115 *
Bob Moore009c4cbe2008-11-12 15:34:52 +0800116 * FUNCTION: acpi_tb_initialize_facs
117 *
118 * PARAMETERS: None
119 *
120 * RETURN: Status
121 *
122 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
123 * for accessing the Global Lock and Firmware Waking Vector
124 *
125 ******************************************************************************/
126
127acpi_status acpi_tb_initialize_facs(void)
128{
129 acpi_status status;
130
131 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
132 ACPI_CAST_INDIRECT_PTR(struct
133 acpi_table_header,
134 &acpi_gbl_FACS));
135 return status;
136}
137
138/*******************************************************************************
139 *
Bob Moorec8573032007-02-02 19:48:23 +0300140 * FUNCTION: acpi_tb_tables_loaded
141 *
142 * PARAMETERS: None
143 *
144 * RETURN: TRUE if required ACPI tables are loaded
145 *
146 * DESCRIPTION: Determine if the minimum required ACPI tables are present
147 * (FADT, FACS, DSDT)
148 *
149 ******************************************************************************/
150
151u8 acpi_tb_tables_loaded(void)
152{
153
154 if (acpi_gbl_root_table_list.count >= 3) {
155 return (TRUE);
156 }
157
158 return (FALSE);
159}
160
161/*******************************************************************************
162 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300163 * FUNCTION: acpi_tb_print_table_header
Robert Moore0c9938c2005-07-29 15:15:00 -0700164 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300165 * PARAMETERS: Address - Table physical address
166 * Header - Table header
Robert Moore0c9938c2005-07-29 15:15:00 -0700167 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300168 * RETURN: None
Robert Moore0c9938c2005-07-29 15:15:00 -0700169 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300170 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
Robert Moore0c9938c2005-07-29 15:15:00 -0700171 *
172 ******************************************************************************/
173
Bob Mooref3d2e782007-02-02 19:48:18 +0300174void
175acpi_tb_print_table_header(acpi_physical_address address,
176 struct acpi_table_header *header)
Robert Moore0c9938c2005-07-29 15:15:00 -0700177{
Robert Moore0c9938c2005-07-29 15:15:00 -0700178
Bob Moorec5fc42a2007-02-02 19:48:19 +0300179 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
180
181 /* FACS only has signature and length fields of common table header */
182
Len Brown03c6d132007-02-06 15:28:23 -0500183 ACPI_INFO((AE_INFO, "%4.4s %08lX, %04X",
184 header->signature, (unsigned long)address,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300185 header->length));
186 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
187
188 /* RSDP has no common fields */
189
Len Brown03c6d132007-02-06 15:28:23 -0500190 ACPI_INFO((AE_INFO, "RSDP %08lX, %04X (r%d %6.6s)",
191 (unsigned long)address,
Bob Moorea4bbb812007-02-02 19:48:19 +0300192 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
193 revision >
194 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
195 header)->length : 20,
196 ACPI_CAST_PTR(struct acpi_table_rsdp,
197 header)->revision,
198 ACPI_CAST_PTR(struct acpi_table_rsdp,
199 header)->oem_id));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300200 } else {
Bob Moore4bf27392007-02-02 19:48:19 +0300201 /* Standard ACPI table with full common header */
202
Bob Moorec5fc42a2007-02-02 19:48:19 +0300203 ACPI_INFO((AE_INFO,
Len Brown03c6d132007-02-06 15:28:23 -0500204 "%4.4s %08lX, %04X (r%d %6.6s %8.8s %8X %4.4s %8X)",
205 header->signature, (unsigned long)address,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300206 header->length, header->revision, header->oem_id,
207 header->oem_table_id, header->oem_revision,
208 header->asl_compiler_id,
209 header->asl_compiler_revision));
210 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300211}
Robert Moore0c9938c2005-07-29 15:15:00 -0700212
Bob Mooref3d2e782007-02-02 19:48:18 +0300213/*******************************************************************************
214 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300215 * FUNCTION: acpi_tb_validate_checksum
216 *
217 * PARAMETERS: Table - ACPI table to verify
218 * Length - Length of entire table
219 *
220 * RETURN: Status
221 *
222 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
223 * exception on bad checksum.
224 *
225 ******************************************************************************/
226
227acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
228{
229 u8 checksum;
230
231 /* Compute the checksum on the table */
232
233 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
234
235 /* Checksum ok? (should be zero) */
236
237 if (checksum) {
238 ACPI_WARNING((AE_INFO,
Bob Moore98af37f2008-04-10 19:06:39 +0400239 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
Bob Moorec5fc42a2007-02-02 19:48:19 +0300240 table->signature, table->checksum,
241 (u8) (table->checksum - checksum)));
242
243#if (ACPI_CHECKSUM_ABORT)
244
245 return (AE_BAD_CHECKSUM);
246#endif
247 }
248
249 return (AE_OK);
250}
251
252/*******************************************************************************
253 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300254 * FUNCTION: acpi_tb_checksum
255 *
256 * PARAMETERS: Buffer - Pointer to memory region to be checked
257 * Length - Length of this memory region
258 *
259 * RETURN: Checksum (u8)
260 *
261 * DESCRIPTION: Calculates circular checksum of memory region.
262 *
263 ******************************************************************************/
264
Bob Moore67a119f2008-06-10 13:42:13 +0800265u8 acpi_tb_checksum(u8 *buffer, u32 length)
Bob Mooref3d2e782007-02-02 19:48:18 +0300266{
267 u8 sum = 0;
268 u8 *end = buffer + length;
269
270 while (buffer < end) {
271 sum = (u8) (sum + *(buffer++));
272 }
273
274 return sum;
275}
276
277/*******************************************************************************
278 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300279 * FUNCTION: acpi_tb_install_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300280 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300281 * PARAMETERS: Address - Physical address of DSDT or FACS
282 * Flags - Flags
283 * Signature - Table signature, NULL if no need to
284 * match
285 * table_index - Index into root table array
Bob Mooref3d2e782007-02-02 19:48:18 +0300286 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300287 * RETURN: None
Bob Mooref3d2e782007-02-02 19:48:18 +0300288 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300289 * DESCRIPTION: Install an ACPI table into the global data structure.
Bob Mooref3d2e782007-02-02 19:48:18 +0300290 *
291 ******************************************************************************/
292
Bob Moore765ec202007-02-02 19:48:20 +0300293void
Bob Moorec5fc42a2007-02-02 19:48:19 +0300294acpi_tb_install_table(acpi_physical_address address,
Bob Moore67a119f2008-06-10 13:42:13 +0800295 u8 flags, char *signature, u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300296{
Bob Mooref3d2e782007-02-02 19:48:18 +0300297 struct acpi_table_header *table;
298
Bob Moorec5fc42a2007-02-02 19:48:19 +0300299 if (!address) {
300 ACPI_ERROR((AE_INFO,
301 "Null physical address for ACPI table [%s]",
302 signature));
Bob Mooref3d2e782007-02-02 19:48:18 +0300303 return;
304 }
305
Bob Moorec5fc42a2007-02-02 19:48:19 +0300306 /* Map just the table header */
307
308 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300309 if (!table) {
310 return;
311 }
312
Bob Moorec5fc42a2007-02-02 19:48:19 +0300313 /* If a particular signature is expected, signature must match */
314
315 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
316 ACPI_ERROR((AE_INFO,
317 "Invalid signature 0x%X for ACPI table [%s]",
318 *ACPI_CAST_PTR(u32, table->signature), signature));
319 goto unmap_and_exit;
320 }
321
322 /* Initialize the table entry */
323
324 acpi_gbl_root_table_list.tables[table_index].address = address;
325 acpi_gbl_root_table_list.tables[table_index].length = table->length;
326 acpi_gbl_root_table_list.tables[table_index].flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300327
328 ACPI_MOVE_32_TO_32(&
Bob Moorec5fc42a2007-02-02 19:48:19 +0300329 (acpi_gbl_root_table_list.tables[table_index].
330 signature), table->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300331
Bob Moorec5fc42a2007-02-02 19:48:19 +0300332 acpi_tb_print_table_header(address, table);
Bob Mooref3d2e782007-02-02 19:48:18 +0300333
Bob Moorec5fc42a2007-02-02 19:48:19 +0300334 if (table_index == ACPI_TABLE_INDEX_DSDT) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300335
Bob Moorec5fc42a2007-02-02 19:48:19 +0300336 /* Global integer width is based upon revision of the DSDT */
337
338 acpi_ut_set_integer_width(table->revision);
339 }
340
341 unmap_and_exit:
Bob Mooref3d2e782007-02-02 19:48:18 +0300342 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
343}
344
345/*******************************************************************************
346 *
Bob Moorea4bbb812007-02-02 19:48:19 +0300347 * FUNCTION: acpi_tb_get_root_table_entry
348 *
349 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
350 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
351 *
352 * RETURN: Physical address extracted from the root table
353 *
354 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
355 * both 32-bit and 64-bit platforms
356 *
357 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
358 * 64-bit platforms.
359 *
360 ******************************************************************************/
361
362static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +0800363acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
Bob Moorea4bbb812007-02-02 19:48:19 +0300364{
365 u64 address64;
366
367 /*
368 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
369 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
370 */
371 if (table_entry_size == sizeof(u32)) {
372 /*
373 * 32-bit platform, RSDT: Return 32-bit table entry
374 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
375 */
376 return ((acpi_physical_address)
377 (*ACPI_CAST_PTR(u32, table_entry)));
378 } else {
379 /*
380 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
381 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit
382 */
383 ACPI_MOVE_64_TO_64(&address64, table_entry);
384
385#if ACPI_MACHINE_WIDTH == 32
386 if (address64 > ACPI_UINT32_MAX) {
387
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300388 /* Will truncate 64-bit address to 32 bits, issue warning */
Bob Moorea4bbb812007-02-02 19:48:19 +0300389
390 ACPI_WARNING((AE_INFO,
391 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating",
392 ACPI_FORMAT_UINT64(address64)));
393 }
394#endif
395 return ((acpi_physical_address) (address64));
396 }
397}
398
399/*******************************************************************************
400 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300401 * FUNCTION: acpi_tb_parse_root_table
402 *
403 * PARAMETERS: Rsdp - Pointer to the RSDP
404 * Flags - Flags
405 *
406 * RETURN: Status
407 *
408 * DESCRIPTION: This function is called to parse the Root System Description
409 * Table (RSDT or XSDT)
410 *
411 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
412 * be mapped and cannot be copied because it contains the actual
413 * memory location of the ACPI Global Lock.
414 *
415 ******************************************************************************/
416
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300417acpi_status __init
Bob Moorec5fc42a2007-02-02 19:48:19 +0300418acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
Bob Mooref3d2e782007-02-02 19:48:18 +0300419{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300420 struct acpi_table_rsdp *rsdp;
Bob Moore67a119f2008-06-10 13:42:13 +0800421 u32 table_entry_size;
422 u32 i;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300423 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300424 struct acpi_table_header *table;
425 acpi_physical_address address;
Andrew Morton8ab73672007-10-02 13:24:10 -0700426 acpi_physical_address uninitialized_var(rsdt_address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300427 u32 length;
428 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300429 acpi_status status;
430
431 ACPI_FUNCTION_TRACE(tb_parse_root_table);
432
Bob Moorec5fc42a2007-02-02 19:48:19 +0300433 /*
434 * Map the entire RSDP and extract the address of the RSDT or XSDT
435 */
436 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
437 if (!rsdp) {
438 return_ACPI_STATUS(AE_NO_MEMORY);
439 }
440
441 acpi_tb_print_table_header(rsdp_address,
442 ACPI_CAST_PTR(struct acpi_table_header,
443 rsdp));
444
Bob Mooref3d2e782007-02-02 19:48:18 +0300445 /* Differentiate between RSDT and XSDT root tables */
446
447 if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800448 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300449 * Root table is an XSDT (64-bit physical addresses). We must use the
450 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
451 * the ACPI specification.
Bob Moorea18ecf42005-08-15 03:42:00 -0800452 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300453 address = (acpi_physical_address) rsdp->xsdt_physical_address;
454 table_entry_size = sizeof(u64);
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800455 rsdt_address = (acpi_physical_address)
456 rsdp->rsdt_physical_address;
Bob Mooref3d2e782007-02-02 19:48:18 +0300457 } else {
458 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400459
Bob Moorec5fc42a2007-02-02 19:48:19 +0300460 address = (acpi_physical_address) rsdp->rsdt_physical_address;
461 table_entry_size = sizeof(u32);
Bob Mooref3d2e782007-02-02 19:48:18 +0300462 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700463
Bob Moorec5fc42a2007-02-02 19:48:19 +0300464 /*
465 * It is not possible to map more than one entry in some environments,
466 * so unmap the RSDP here before mapping other tables
467 */
468 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
469
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800470 if (table_entry_size == sizeof(u64)) {
471 if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) {
472 /* XSDT has NULL entry, RSDT is used */
473 address = rsdt_address;
474 table_entry_size = sizeof(u32);
Joe Perches4fdb2a02007-11-19 17:48:02 -0800475 ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800476 "using RSDT"));
477 }
478 }
Bob Moorec5fc42a2007-02-02 19:48:19 +0300479 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700480
Bob Mooref3d2e782007-02-02 19:48:18 +0300481 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
482 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300483 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300484 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700485
Bob Moorec5fc42a2007-02-02 19:48:19 +0300486 acpi_tb_print_table_header(address, table);
487
Bob Mooref3d2e782007-02-02 19:48:18 +0300488 /* Get the length of the full table, verify length and map entire table */
489
490 length = table->length;
491 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
492
493 if (length < sizeof(struct acpi_table_header)) {
494 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
495 length));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300496 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300497 }
498
499 table = acpi_os_map_memory(address, length);
500 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300501 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300502 }
503
504 /* Validate the root table checksum */
505
Bob Moorec5fc42a2007-02-02 19:48:19 +0300506 status = acpi_tb_verify_checksum(table, length);
507 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300508 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300509 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300510 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300511
512 /* Calculate the number of tables described in the root table */
513
514 table_count =
Bob Moorea4bbb812007-02-02 19:48:19 +0300515 (u32) ((table->length -
516 sizeof(struct acpi_table_header)) / table_entry_size);
Bob Mooref3d2e782007-02-02 19:48:18 +0300517
Bob Moorec5fc42a2007-02-02 19:48:19 +0300518 /*
519 * First two entries in the table array are reserved for the DSDT and FACS,
520 * which are not actually present in the RSDT/XSDT - they come from the FADT
521 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300522 table_entry =
523 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
524 acpi_gbl_root_table_list.count = 2;
525
526 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300527 * Initialize the root table array from the RSDT/XSDT
Bob Mooref3d2e782007-02-02 19:48:18 +0300528 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300529 for (i = 0; i < table_count; i++) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300530 if (acpi_gbl_root_table_list.count >=
531 acpi_gbl_root_table_list.size) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300532
533 /* There is no more room in the root table array, attempt resize */
534
Bob Mooref3d2e782007-02-02 19:48:18 +0300535 status = acpi_tb_resize_root_table_list();
536 if (ACPI_FAILURE(status)) {
537 ACPI_WARNING((AE_INFO,
538 "Truncating %u table entries!",
539 (unsigned)
540 (acpi_gbl_root_table_list.size -
541 acpi_gbl_root_table_list.
542 count)));
543 break;
544 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700545 }
546
Bob Moorea4bbb812007-02-02 19:48:19 +0300547 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
548
549 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
550 address =
551 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
Bob Mooref3d2e782007-02-02 19:48:18 +0300552
Bob Moorec5fc42a2007-02-02 19:48:19 +0300553 table_entry += table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300554 acpi_gbl_root_table_list.count++;
555 }
556
557 /*
558 * It is not possible to map more than one entry in some environments,
559 * so unmap the root table here before mapping other tables
560 */
561 acpi_os_unmap_memory(table, length);
562
Bob Moorec5fc42a2007-02-02 19:48:19 +0300563 /*
564 * Complete the initialization of the root table array by examining
565 * the header of each table
566 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300567 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300568 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
569 address, flags, NULL, i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300570
Bob Moorec5fc42a2007-02-02 19:48:19 +0300571 /* Special case for FADT - get the DSDT and FACS */
Bob Mooref3d2e782007-02-02 19:48:18 +0300572
Bob Moorec5fc42a2007-02-02 19:48:19 +0300573 if (ACPI_COMPARE_NAME
574 (&acpi_gbl_root_table_list.tables[i].signature,
575 ACPI_SIG_FADT)) {
576 acpi_tb_parse_fadt(i, flags);
Bob Mooref3d2e782007-02-02 19:48:18 +0300577 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700578 }
579
Len Brown4be44fc2005-08-05 00:44:28 -0400580 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700581}