ACPICA: minimal patch to integrate new tables into Linux
[linux-2.6-block.git] / drivers / acpi / tables / tbutils.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
f3d2e786 3 * Module Name: tbutils - table utilities
1da177e4
LT
4 *
5 *****************************************************************************/
6
7/*
4a90c7e8 8 * Copyright (C) 2000 - 2006, R. Byron Moore
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
LT
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
1da177e4 47#define _COMPONENT ACPI_TABLES
4be44fcd 48ACPI_MODULE_NAME("tbutils")
1da177e4 49
44f6c012 50/* Local prototypes */
c5fc42ac
BM
51static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags);
52
53static void acpi_tb_convert_fadt(void);
54
55static void
56acpi_tb_install_table(acpi_physical_address address,
57 u8 flags, char *signature, acpi_native_uint table_index);
f3d2e786
BM
58
59static void inline
60acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
c5fc42ac
BM
61 u8 bit_width, u64 address);
62
a4bbb810
BM
63static acpi_physical_address
64acpi_tb_get_root_table_entry(u8 * table_entry,
65 acpi_native_uint table_entry_size);
66
c5fc42ac
BM
67/* Table used for conversion of FADT to common format */
68
69typedef struct acpi_fadt_conversion {
70 u8 target;
71 u8 source;
72 u8 length;
73
74} acpi_fadt_conversion;
75
76static struct acpi_fadt_conversion fadt_conversion_table[] = {
77 {ACPI_FADT_OFFSET(xpm1a_event_block),
78 ACPI_FADT_OFFSET(pm1a_event_block),
79 ACPI_FADT_OFFSET(pm1_event_length)},
80 {ACPI_FADT_OFFSET(xpm1b_event_block),
81 ACPI_FADT_OFFSET(pm1b_event_block),
82 ACPI_FADT_OFFSET(pm1_event_length)},
83 {ACPI_FADT_OFFSET(xpm1a_control_block),
84 ACPI_FADT_OFFSET(pm1a_control_block),
85 ACPI_FADT_OFFSET(pm1_control_length)},
86 {ACPI_FADT_OFFSET(xpm1b_control_block),
87 ACPI_FADT_OFFSET(pm1b_control_block),
88 ACPI_FADT_OFFSET(pm1_control_length)},
89 {ACPI_FADT_OFFSET(xpm2_control_block),
90 ACPI_FADT_OFFSET(pm2_control_block),
91 ACPI_FADT_OFFSET(pm2_control_length)},
92 {ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block),
93 ACPI_FADT_OFFSET(pm_timer_length)},
94 {ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block),
95 ACPI_FADT_OFFSET(gpe0_block_length)},
96 {ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block),
97 ACPI_FADT_OFFSET(gpe1_block_length)}
98};
99
100#define ACPI_FADT_CONVERSION_ENTRIES (sizeof (fadt_conversion_table) / sizeof (struct acpi_fadt_conversion))
1da177e4 101
0c9938cc
RM
102/*******************************************************************************
103 *
f3d2e786 104 * FUNCTION: acpi_tb_print_table_header
0c9938cc 105 *
f3d2e786
BM
106 * PARAMETERS: Address - Table physical address
107 * Header - Table header
0c9938cc 108 *
f3d2e786 109 * RETURN: None
0c9938cc 110 *
c5fc42ac 111 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
0c9938cc
RM
112 *
113 ******************************************************************************/
114
f3d2e786
BM
115void
116acpi_tb_print_table_header(acpi_physical_address address,
117 struct acpi_table_header *header)
0c9938cc 118{
0c9938cc 119
c5fc42ac
BM
120 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
121
122 /* FACS only has signature and length fields of common table header */
123
124 ACPI_INFO((AE_INFO, "%4.4s @ 0x%p/0x%04X",
125 header->signature, ACPI_CAST_PTR(void, address),
126 header->length));
127 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
128
129 /* RSDP has no common fields */
130
131 ACPI_INFO((AE_INFO, "RSDP @ 0x%p/0x%04X (v%3.3d %6.6s)",
132 ACPI_CAST_PTR(void, address),
a4bbb810
BM
133 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
134 revision >
135 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
136 header)->length : 20,
137 ACPI_CAST_PTR(struct acpi_table_rsdp,
138 header)->revision,
139 ACPI_CAST_PTR(struct acpi_table_rsdp,
140 header)->oem_id));
c5fc42ac 141 } else {
4bf27393
BM
142 /* Standard ACPI table with full common header */
143
c5fc42ac
BM
144 ACPI_INFO((AE_INFO,
145 "%4.4s @ 0x%p/0x%04X (v%3.3d %6.6s %8.8s 0x%08X %4.4s 0x%08X)",
146 header->signature, ACPI_CAST_PTR(void, address),
147 header->length, header->revision, header->oem_id,
148 header->oem_table_id, header->oem_revision,
149 header->asl_compiler_id,
150 header->asl_compiler_revision));
151 }
0c9938cc
RM
152}
153
1da177e4
LT
154/*******************************************************************************
155 *
f3d2e786 156 * FUNCTION: acpi_tb_init_generic_address
1da177e4 157 *
f3d2e786
BM
158 * PARAMETERS: new_gas_struct - GAS struct to be initialized
159 * bit_width - Width of this register
160 * Address - Address of the register
1da177e4 161 *
f3d2e786 162 * RETURN: None
1da177e4 163 *
f3d2e786 164 * DESCRIPTION: Initialize a GAS structure.
1da177e4
LT
165 *
166 ******************************************************************************/
167
f3d2e786
BM
168static void inline
169acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
c5fc42ac 170 u8 bit_width, u64 address)
1da177e4 171{
44f6c012 172
4bf27393 173 ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address);
f3d2e786
BM
174 new_gas_struct->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
175 new_gas_struct->bit_width = bit_width;
176 new_gas_struct->bit_offset = 0;
177 new_gas_struct->access_width = 0;
1da177e4
LT
178}
179
c5fc42ac
BM
180/*******************************************************************************
181 *
182 * FUNCTION: acpi_tb_validate_checksum
183 *
184 * PARAMETERS: Table - ACPI table to verify
185 * Length - Length of entire table
186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
190 * exception on bad checksum.
191 *
192 ******************************************************************************/
193
194acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
195{
196 u8 checksum;
197
198 /* Compute the checksum on the table */
199
200 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
201
202 /* Checksum ok? (should be zero) */
203
204 if (checksum) {
205 ACPI_WARNING((AE_INFO,
206 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
207 table->signature, table->checksum,
208 (u8) (table->checksum - checksum)));
209
210#if (ACPI_CHECKSUM_ABORT)
211
212 return (AE_BAD_CHECKSUM);
213#endif
214 }
215
216 return (AE_OK);
217}
218
1da177e4
LT
219/*******************************************************************************
220 *
f3d2e786 221 * FUNCTION: acpi_tb_checksum
1da177e4 222 *
f3d2e786
BM
223 * PARAMETERS: Buffer - Pointer to memory region to be checked
224 * Length - Length of this memory region
1da177e4 225 *
f3d2e786 226 * RETURN: Checksum (u8)
1da177e4 227 *
f3d2e786 228 * DESCRIPTION: Calculates circular checksum of memory region.
1da177e4
LT
229 *
230 ******************************************************************************/
231
f3d2e786 232u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
793c2388 233{
793c2388 234 u8 sum = 0;
f3d2e786 235 u8 *end = buffer + length;
793c2388 236
f3d2e786
BM
237 while (buffer < end) {
238 sum = (u8) (sum + *(buffer++));
793c2388
BM
239 }
240
f3d2e786 241 return sum;
793c2388
BM
242}
243
244/*******************************************************************************
245 *
f3d2e786 246 * FUNCTION: acpi_tb_convert_fadt
793c2388 247 *
c5fc42ac 248 * PARAMETERS: None, uses acpi_gbl_FADT
793c2388 249 *
f3d2e786 250 * RETURN: None
793c2388 251 *
c5fc42ac
BM
252 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
253 *
254 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must contain
255 * a copy of the actual FADT.
256 *
257 * ACPICA will use the "X" fields of the FADT for all addresses.
258 *
259 * "X" fields are optional extensions to the original V1.0 fields. Even if
260 * they are present in the structure, they can be optionally not used by
261 * setting them to zero. Therefore, we must selectively expand V1.0 fields
262 * if the corresponding X field is zero.
263 *
264 * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
265 * "X" fields.
266 *
267 * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
268 * expanding the corresponding ACPI 1.0 field.
793c2388
BM
269 *
270 ******************************************************************************/
271
c5fc42ac 272static void acpi_tb_convert_fadt(void)
1da177e4 273{
c5fc42ac
BM
274 u8 pm1_register_length;
275 struct acpi_generic_address *target;
276 acpi_native_uint i;
277
278 /* Expand the FACS and DSDT addresses as necessary */
1da177e4 279
f3d2e786
BM
280 if (!acpi_gbl_FADT.Xfacs) {
281 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
282 }
1da177e4 283
f3d2e786
BM
284 if (!acpi_gbl_FADT.Xdsdt) {
285 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
286 }
1da177e4 287
f3d2e786 288 /*
a4bbb810
BM
289 * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
290 * structures as necessary.
f3d2e786 291 */
c5fc42ac
BM
292 for (i = 0; i < ACPI_FADT_CONVERSION_ENTRIES; i++) {
293 target =
294 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
295 fadt_conversion_table[i].target);
296
4bf27393
BM
297 /* Expand only if the X target is null */
298
c5fc42ac
BM
299 if (!target->address) {
300 acpi_tb_init_generic_address(target,
301 *ACPI_ADD_PTR(u8,
302 &acpi_gbl_FADT,
303 fadt_conversion_table
304 [i].length),
a4bbb810
BM
305 (u64) * ACPI_ADD_PTR(u32,
306 &acpi_gbl_FADT,
307 fadt_conversion_table
308 [i].
309 source));
c5fc42ac
BM
310 }
311 }
f3d2e786
BM
312
313 /*
c5fc42ac
BM
314 * Calculate separate GAS structs for the PM1 Enable registers.
315 * These addresses do not appear (directly) in the FADT, so it is
316 * useful to calculate them once, here.
4bf27393
BM
317 *
318 * The PM event blocks are split into two register blocks, first is the
319 * PM Status Register block, followed immediately by the PM Enable Register
320 * block. Each is of length (pm1_event_length/2)
f3d2e786 321 */
c5fc42ac
BM
322 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
323
324 /* PM1A is required */
325
f3d2e786 326 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
c5fc42ac 327 pm1_register_length,
4bf27393
BM
328 (acpi_gbl_FADT.xpm1a_event_block.address +
329 pm1_register_length));
c5fc42ac
BM
330
331 /* PM1B is optional; leave null if not present */
f3d2e786 332
f3d2e786
BM
333 if (acpi_gbl_FADT.xpm1b_event_block.address) {
334 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
c5fc42ac 335 pm1_register_length,
4bf27393
BM
336 (acpi_gbl_FADT.xpm1b_event_block.
337 address + pm1_register_length));
f3d2e786 338 }
1da177e4 339
f3d2e786 340 /* Global FADT is the new common V2.0 FADT */
1da177e4 341
f3d2e786 342 acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
1da177e4
LT
343}
344
1da177e4
LT
345/*******************************************************************************
346 *
c5fc42ac 347 * FUNCTION: acpi_tb_install_table
1da177e4 348 *
c5fc42ac
BM
349 * PARAMETERS: Address - Physical address of DSDT or FACS
350 * Flags - Flags
351 * Signature - Table signature, NULL if no need to
352 * match
353 * table_index - Index into root table array
1da177e4 354 *
c5fc42ac 355 * RETURN: None
1da177e4 356 *
c5fc42ac 357 * DESCRIPTION: Install an ACPI table into the global data structure.
1da177e4
LT
358 *
359 ******************************************************************************/
360
c5fc42ac
BM
361static void
362acpi_tb_install_table(acpi_physical_address address,
363 u8 flags, char *signature, acpi_native_uint table_index)
1da177e4 364{
f3d2e786
BM
365 struct acpi_table_header *table;
366
c5fc42ac
BM
367 if (!address) {
368 ACPI_ERROR((AE_INFO,
369 "Null physical address for ACPI table [%s]",
370 signature));
371 return;
f3d2e786
BM
372 }
373
c5fc42ac
BM
374 /* Map just the table header */
375
376 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
f3d2e786 377 if (!table) {
c5fc42ac
BM
378 return;
379 }
380
381 /* If a particular signature is expected, signature must match */
382
383 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
384 ACPI_ERROR((AE_INFO,
385 "Invalid signature 0x%X for ACPI table [%s]",
386 *ACPI_CAST_PTR(u32, table->signature), signature));
387 goto unmap_and_exit;
f3d2e786
BM
388 }
389
c5fc42ac
BM
390 /* Initialize the table entry */
391
392 acpi_gbl_root_table_list.tables[table_index].address = address;
393 acpi_gbl_root_table_list.tables[table_index].length = table->length;
394 acpi_gbl_root_table_list.tables[table_index].flags = flags;
f3d2e786
BM
395
396 ACPI_MOVE_32_TO_32(&
c5fc42ac
BM
397 (acpi_gbl_root_table_list.tables[table_index].
398 signature), table->signature);
f3d2e786 399
c5fc42ac 400 acpi_tb_print_table_header(address, table);
f3d2e786 401
c5fc42ac 402 if (table_index == ACPI_TABLE_INDEX_DSDT) {
f3d2e786 403
c5fc42ac 404 /* Global integer width is based upon revision of the DSDT */
f3d2e786 405
c5fc42ac
BM
406 acpi_ut_set_integer_width(table->revision);
407 }
408
409 unmap_and_exit:
f3d2e786 410 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
c5fc42ac 411}
f3d2e786 412
c5fc42ac
BM
413/*******************************************************************************
414 *
415 * FUNCTION: acpi_tb_parse_fadt
416 *
417 * PARAMETERS: table_index - Index for the FADT
418 * Flags - Flags
419 *
420 * RETURN: None
421 *
422 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
423 * (FADT contains the addresses of the DSDT and FACS)
424 *
425 ******************************************************************************/
426
427static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
428{
429 u32 length;
430 struct acpi_table_header *table;
431
432 /*
433 * Special case for the FADT because of multiple versions and the fact
434 * that it contains pointers to both the DSDT and FACS tables.
435 *
436 * Get a local copy of the FADT and convert it to a common format
437 * Map entire FADT, assumed to be smaller than one page.
438 */
439 length = acpi_gbl_root_table_list.tables[table_index].length;
1da177e4 440
f3d2e786 441 table =
c5fc42ac
BM
442 acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
443 address, length);
f3d2e786
BM
444 if (!table) {
445 return;
446 }
447
c5fc42ac
BM
448 /*
449 * Validate the FADT checksum before we copy the table. Ignore
450 * checksum error as we want to try to get the DSDT and FACS.
451 */
452 (void)acpi_tb_verify_checksum(table, length);
f3d2e786 453
c5fc42ac 454 /* Copy the entire FADT locally */
f3d2e786 455
a4bbb810 456 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
f3d2e786 457
c5fc42ac
BM
458 ACPI_MEMCPY(&acpi_gbl_FADT, table,
459 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
460 acpi_os_unmap_memory(table, length);
f3d2e786 461
c5fc42ac
BM
462 /* Convert local FADT to the common internal format */
463
464 acpi_tb_convert_fadt();
465
466 /* Extract the DSDT and FACS tables from the FADT */
467
468 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
469 flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
470
471 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
472 flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
793c2388
BM
473}
474
a4bbb810
BM
475/*******************************************************************************
476 *
477 * FUNCTION: acpi_tb_get_root_table_entry
478 *
479 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
480 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
481 *
482 * RETURN: Physical address extracted from the root table
483 *
484 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
485 * both 32-bit and 64-bit platforms
486 *
487 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
488 * 64-bit platforms.
489 *
490 ******************************************************************************/
491
492static acpi_physical_address
493acpi_tb_get_root_table_entry(u8 * table_entry,
494 acpi_native_uint table_entry_size)
495{
496 u64 address64;
497
498 /*
499 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
500 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
501 */
502 if (table_entry_size == sizeof(u32)) {
503 /*
504 * 32-bit platform, RSDT: Return 32-bit table entry
505 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
506 */
507 return ((acpi_physical_address)
508 (*ACPI_CAST_PTR(u32, table_entry)));
509 } else {
510 /*
511 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
512 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit
513 */
514 ACPI_MOVE_64_TO_64(&address64, table_entry);
515
516#if ACPI_MACHINE_WIDTH == 32
517 if (address64 > ACPI_UINT32_MAX) {
518
519 /* Will truncate 64-bit address to 32 bits */
520
521 ACPI_WARNING((AE_INFO,
522 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating",
523 ACPI_FORMAT_UINT64(address64)));
524 }
525#endif
526 return ((acpi_physical_address) (address64));
527 }
528}
529
793c2388
BM
530/*******************************************************************************
531 *
f3d2e786 532 * FUNCTION: acpi_tb_parse_root_table
793c2388 533 *
f3d2e786
BM
534 * PARAMETERS: Rsdp - Pointer to the RSDP
535 * Flags - Flags
536 *
537 * RETURN: Status
793c2388 538 *
f3d2e786
BM
539 * DESCRIPTION: This function is called to parse the Root System Description
540 * Table (RSDT or XSDT)
793c2388 541 *
f3d2e786
BM
542 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
543 * be mapped and cannot be copied because it contains the actual
544 * memory location of the ACPI Global Lock.
793c2388
BM
545 *
546 ******************************************************************************/
547
ad71860a 548acpi_status __init
c5fc42ac 549acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
793c2388 550{
c5fc42ac
BM
551 struct acpi_table_rsdp *rsdp;
552 acpi_native_uint table_entry_size;
553 acpi_native_uint i;
554 u32 table_count;
f3d2e786
BM
555 struct acpi_table_header *table;
556 acpi_physical_address address;
557 u32 length;
558 u8 *table_entry;
f3d2e786
BM
559 acpi_status status;
560
561 ACPI_FUNCTION_TRACE(tb_parse_root_table);
562
c5fc42ac
BM
563 /*
564 * Map the entire RSDP and extract the address of the RSDT or XSDT
565 */
566 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
567 if (!rsdp) {
568 return_ACPI_STATUS(AE_NO_MEMORY);
569 }
570
571 acpi_tb_print_table_header(rsdp_address,
572 ACPI_CAST_PTR(struct acpi_table_header,
573 rsdp));
574
f3d2e786
BM
575 /* Differentiate between RSDT and XSDT root tables */
576
577 if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
578 /*
579 * Root table is an XSDT (64-bit physical addresses). We must use the
580 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
581 * the ACPI specification.
582 */
c5fc42ac
BM
583 address = (acpi_physical_address) rsdp->xsdt_physical_address;
584 table_entry_size = sizeof(u64);
f3d2e786
BM
585 } else {
586 /* Root table is an RSDT (32-bit physical addresses) */
587
c5fc42ac
BM
588 address = (acpi_physical_address) rsdp->rsdt_physical_address;
589 table_entry_size = sizeof(u32);
f3d2e786 590 }
793c2388 591
c5fc42ac
BM
592 /*
593 * It is not possible to map more than one entry in some environments,
594 * so unmap the RSDP here before mapping other tables
595 */
596 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
597
598 /* Map the RSDT/XSDT table header to get the full table length */
793c2388 599
f3d2e786
BM
600 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
601 if (!table) {
c5fc42ac 602 return_ACPI_STATUS(AE_NO_MEMORY);
f3d2e786
BM
603 }
604
c5fc42ac
BM
605 acpi_tb_print_table_header(address, table);
606
f3d2e786
BM
607 /* Get the length of the full table, verify length and map entire table */
608
609 length = table->length;
610 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
611
612 if (length < sizeof(struct acpi_table_header)) {
613 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
614 length));
c5fc42ac 615 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
f3d2e786
BM
616 }
617
618 table = acpi_os_map_memory(address, length);
619 if (!table) {
c5fc42ac 620 return_ACPI_STATUS(AE_NO_MEMORY);
f3d2e786
BM
621 }
622
623 /* Validate the root table checksum */
624
c5fc42ac
BM
625 status = acpi_tb_verify_checksum(table, length);
626 if (ACPI_FAILURE(status)) {
f3d2e786 627 acpi_os_unmap_memory(table, length);
c5fc42ac 628 return_ACPI_STATUS(status);
f3d2e786 629 }
f3d2e786
BM
630
631 /* Calculate the number of tables described in the root table */
632
633 table_count =
a4bbb810
BM
634 (u32) ((table->length -
635 sizeof(struct acpi_table_header)) / table_entry_size);
52fc0b02 636
c5fc42ac
BM
637 /*
638 * First two entries in the table array are reserved for the DSDT and FACS,
639 * which are not actually present in the RSDT/XSDT - they come from the FADT
640 */
f3d2e786
BM
641 table_entry =
642 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
643 acpi_gbl_root_table_list.count = 2;
1da177e4 644
f3d2e786 645 /*
c5fc42ac 646 * Initialize the root table array from the RSDT/XSDT
f3d2e786 647 */
c5fc42ac 648 for (i = 0; i < table_count; i++) {
f3d2e786
BM
649 if (acpi_gbl_root_table_list.count >=
650 acpi_gbl_root_table_list.size) {
c5fc42ac
BM
651
652 /* There is no more room in the root table array, attempt resize */
653
f3d2e786
BM
654 status = acpi_tb_resize_root_table_list();
655 if (ACPI_FAILURE(status)) {
656 ACPI_WARNING((AE_INFO,
657 "Truncating %u table entries!",
658 (unsigned)
659 (acpi_gbl_root_table_list.size -
660 acpi_gbl_root_table_list.
661 count)));
662 break;
663 }
664 }
665
a4bbb810
BM
666 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
667
668 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
669 address =
670 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
f3d2e786 671
c5fc42ac 672 table_entry += table_entry_size;
f3d2e786 673 acpi_gbl_root_table_list.count++;
1da177e4 674 }
793c2388 675
f3d2e786
BM
676 /*
677 * It is not possible to map more than one entry in some environments,
678 * so unmap the root table here before mapping other tables
679 */
680 acpi_os_unmap_memory(table, length);
681
c5fc42ac
BM
682 /*
683 * Complete the initialization of the root table array by examining
684 * the header of each table
685 */
f3d2e786 686 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
c5fc42ac
BM
687 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
688 address, flags, NULL, i);
f3d2e786 689
c5fc42ac 690 /* Special case for FADT - get the DSDT and FACS */
f3d2e786 691
c5fc42ac
BM
692 if (ACPI_COMPARE_NAME
693 (&acpi_gbl_root_table_list.tables[i].signature,
694 ACPI_SIG_FADT)) {
695 acpi_tb_parse_fadt(i, flags);
f3d2e786
BM
696 }
697 }
698
699 return_ACPI_STATUS(AE_OK);
1da177e4
LT
700}
701
f3d2e786 702/******************************************************************************
44f6c012 703 *
f3d2e786 704 * FUNCTION: acpi_tb_map
44f6c012 705 *
f3d2e786
BM
706 * PARAMETERS: Address - Address to be mapped
707 * Length - Length to be mapped
708 * Flags - Logical or physical addressing mode
44f6c012 709 *
f3d2e786 710 * RETURN: Pointer to mapped region
44f6c012 711 *
f3d2e786
BM
712 * DESCRIPTION: Maps memory according to flag
713 *
714 *****************************************************************************/
44f6c012 715
f3d2e786 716void *acpi_tb_map(acpi_physical_address address, u32 length, u32 flags)
44f6c012 717{
44f6c012 718
f3d2e786
BM
719 if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
720 return (acpi_os_map_memory(address, length));
721 } else {
722 return (ACPI_CAST_PTR(void, address));
723 }
724}
44f6c012 725
f3d2e786
BM
726/******************************************************************************
727 *
728 * FUNCTION: acpi_tb_unmap
729 *
730 * PARAMETERS: Pointer - To mapped region
731 * Length - Length to be unmapped
732 * Flags - Logical or physical addressing mode
733 *
734 * RETURN: None
735 *
736 * DESCRIPTION: Unmaps memory according to flag
737 *
738 *****************************************************************************/
44f6c012 739
f3d2e786
BM
740void acpi_tb_unmap(void *pointer, u32 length, u32 flags)
741{
44f6c012 742
f3d2e786
BM
743 if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
744 acpi_os_unmap_memory(pointer, length);
745 }
44f6c012 746}