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