blob: 6d13737f3f899479e87502a59cf1c9f8e0d8beca [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/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
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 Moorec5fc42a2007-02-02 19:48:19 +030051static 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);
Bob Mooref3d2e782007-02-02 19:48:18 +030058
59static void inline
60acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
Bob Moorec5fc42a2007-02-02 19:48:19 +030061 u8 bit_width, u64 address);
62
Bob Moorea4bbb8102007-02-02 19:48:19 +030063static acpi_physical_address
64acpi_tb_get_root_table_entry(u8 * table_entry,
65 acpi_native_uint table_entry_size);
66
Bob Moorec5fc42a2007-02-02 19:48:19 +030067/* 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))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/*******************************************************************************
103 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300104 * FUNCTION: acpi_tb_print_table_header
Robert Moore0c9938c2005-07-29 15:15:00 -0700105 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300106 * PARAMETERS: Address - Table physical address
107 * Header - Table header
Robert Moore0c9938c2005-07-29 15:15:00 -0700108 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300109 * RETURN: None
Robert Moore0c9938c2005-07-29 15:15:00 -0700110 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300111 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
Robert Moore0c9938c2005-07-29 15:15:00 -0700112 *
113 ******************************************************************************/
114
Bob Mooref3d2e782007-02-02 19:48:18 +0300115void
116acpi_tb_print_table_header(acpi_physical_address address,
117 struct acpi_table_header *header)
Robert Moore0c9938c2005-07-29 15:15:00 -0700118{
Robert Moore0c9938c2005-07-29 15:15:00 -0700119
Bob Moorec5fc42a2007-02-02 19:48:19 +0300120 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),
Bob Moorea4bbb8102007-02-02 19:48:19 +0300133 (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));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300141 } else {
Bob Moore4bf27392007-02-02 19:48:19 +0300142 /* Standard ACPI table with full common header */
143
Bob Moorec5fc42a2007-02-02 19:48:19 +0300144 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 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300152}
Robert Moore0c9938c2005-07-29 15:15:00 -0700153
Bob Mooref3d2e782007-02-02 19:48:18 +0300154/*******************************************************************************
155 *
156 * FUNCTION: acpi_tb_init_generic_address
157 *
158 * PARAMETERS: new_gas_struct - GAS struct to be initialized
159 * bit_width - Width of this register
160 * Address - Address of the register
161 *
162 * RETURN: None
163 *
164 * DESCRIPTION: Initialize a GAS structure.
165 *
166 ******************************************************************************/
Robert Moore0c9938c2005-07-29 15:15:00 -0700167
Bob Mooref3d2e782007-02-02 19:48:18 +0300168static void inline
169acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300170 u8 bit_width, u64 address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300171{
Robert Moore0c9938c2005-07-29 15:15:00 -0700172
Bob Moore4bf27392007-02-02 19:48:19 +0300173 ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300174 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;
178}
Robert Moore0c9938c2005-07-29 15:15:00 -0700179
Bob Mooref3d2e782007-02-02 19:48:18 +0300180/*******************************************************************************
181 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300182 * 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
219/*******************************************************************************
220 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300221 * FUNCTION: acpi_tb_checksum
222 *
223 * PARAMETERS: Buffer - Pointer to memory region to be checked
224 * Length - Length of this memory region
225 *
226 * RETURN: Checksum (u8)
227 *
228 * DESCRIPTION: Calculates circular checksum of memory region.
229 *
230 ******************************************************************************/
231
232u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
233{
234 u8 sum = 0;
235 u8 *end = buffer + length;
236
237 while (buffer < end) {
238 sum = (u8) (sum + *(buffer++));
239 }
240
241 return sum;
242}
243
244/*******************************************************************************
245 *
246 * FUNCTION: acpi_tb_convert_fadt
247 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300248 * PARAMETERS: None, uses acpi_gbl_FADT
Bob Mooref3d2e782007-02-02 19:48:18 +0300249 *
250 * RETURN: None
251 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300252 * 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.
Bob Mooref3d2e782007-02-02 19:48:18 +0300269 *
270 ******************************************************************************/
271
Bob Moorec5fc42a2007-02-02 19:48:19 +0300272static void acpi_tb_convert_fadt(void)
Bob Mooref3d2e782007-02-02 19:48:18 +0300273{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300274 u8 pm1_register_length;
275 struct acpi_generic_address *target;
276 acpi_native_uint i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300277
Bob Moorec5fc42a2007-02-02 19:48:19 +0300278 /* Expand the FACS and DSDT addresses as necessary */
279
Bob Mooref3d2e782007-02-02 19:48:18 +0300280 if (!acpi_gbl_FADT.Xfacs) {
281 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
282 }
283
284 if (!acpi_gbl_FADT.Xdsdt) {
285 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
286 }
287
288 /*
Bob Moorea4bbb8102007-02-02 19:48:19 +0300289 * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
290 * structures as necessary.
Bob Mooref3d2e782007-02-02 19:48:18 +0300291 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300292 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
Bob Moore4bf27392007-02-02 19:48:19 +0300297 /* Expand only if the X target is null */
298
Bob Moorec5fc42a2007-02-02 19:48:19 +0300299 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),
Bob Moorea4bbb8102007-02-02 19:48:19 +0300305 (u64) * ACPI_ADD_PTR(u32,
306 &acpi_gbl_FADT,
307 fadt_conversion_table
308 [i].
309 source));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300310 }
311 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300312
313 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300314 * 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.
Bob Moore4bf27392007-02-02 19:48:19 +0300317 *
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)
Bob Mooref3d2e782007-02-02 19:48:18 +0300321 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300322 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
323
324 /* PM1A is required */
325
Bob Mooref3d2e782007-02-02 19:48:18 +0300326 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300327 pm1_register_length,
Bob Moore4bf27392007-02-02 19:48:19 +0300328 (acpi_gbl_FADT.xpm1a_event_block.address +
329 pm1_register_length));
Bob Mooref3d2e782007-02-02 19:48:18 +0300330
Bob Moorec5fc42a2007-02-02 19:48:19 +0300331 /* PM1B is optional; leave null if not present */
332
Bob Mooref3d2e782007-02-02 19:48:18 +0300333 if (acpi_gbl_FADT.xpm1b_event_block.address) {
334 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300335 pm1_register_length,
Bob Moore4bf27392007-02-02 19:48:19 +0300336 (acpi_gbl_FADT.xpm1b_event_block.
337 address + pm1_register_length));
Bob Mooref3d2e782007-02-02 19:48:18 +0300338 }
339
340 /* Global FADT is the new common V2.0 FADT */
341
342 acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
343}
344
345/*******************************************************************************
346 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300347 * FUNCTION: acpi_tb_install_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300348 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300349 * 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
Bob Mooref3d2e782007-02-02 19:48:18 +0300354 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300355 * RETURN: None
Bob Mooref3d2e782007-02-02 19:48:18 +0300356 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300357 * DESCRIPTION: Install an ACPI table into the global data structure.
Bob Mooref3d2e782007-02-02 19:48:18 +0300358 *
359 ******************************************************************************/
360
Bob Moorec5fc42a2007-02-02 19:48:19 +0300361static void
362acpi_tb_install_table(acpi_physical_address address,
363 u8 flags, char *signature, acpi_native_uint table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300364{
Bob Mooref3d2e782007-02-02 19:48:18 +0300365 struct acpi_table_header *table;
366
Bob Moorec5fc42a2007-02-02 19:48:19 +0300367 if (!address) {
368 ACPI_ERROR((AE_INFO,
369 "Null physical address for ACPI table [%s]",
370 signature));
Bob Mooref3d2e782007-02-02 19:48:18 +0300371 return;
372 }
373
Bob Moorec5fc42a2007-02-02 19:48:19 +0300374 /* Map just the table header */
375
376 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300377 if (!table) {
378 return;
379 }
380
Bob Moorec5fc42a2007-02-02 19:48:19 +0300381 /* 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;
388 }
389
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;
Bob Mooref3d2e782007-02-02 19:48:18 +0300395
396 ACPI_MOVE_32_TO_32(&
Bob Moorec5fc42a2007-02-02 19:48:19 +0300397 (acpi_gbl_root_table_list.tables[table_index].
398 signature), table->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300399
Bob Moorec5fc42a2007-02-02 19:48:19 +0300400 acpi_tb_print_table_header(address, table);
Bob Mooref3d2e782007-02-02 19:48:18 +0300401
Bob Moorec5fc42a2007-02-02 19:48:19 +0300402 if (table_index == ACPI_TABLE_INDEX_DSDT) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300403
Bob Moorec5fc42a2007-02-02 19:48:19 +0300404 /* Global integer width is based upon revision of the DSDT */
405
406 acpi_ut_set_integer_width(table->revision);
407 }
408
409 unmap_and_exit:
Bob Mooref3d2e782007-02-02 19:48:18 +0300410 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
411}
412
413/*******************************************************************************
414 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300415 * 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;
440
441 table =
442 acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
443 address, length);
444 if (!table) {
445 return;
446 }
447
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);
453
454 /* Copy the entire FADT locally */
455
Bob Moorea4bbb8102007-02-02 19:48:19 +0300456 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300457
458 ACPI_MEMCPY(&acpi_gbl_FADT, table,
459 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
460 acpi_os_unmap_memory(table, length);
461
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);
473}
474
475/*******************************************************************************
476 *
Bob Moorea4bbb8102007-02-02 19:48:19 +0300477 * 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
530/*******************************************************************************
531 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300532 * FUNCTION: acpi_tb_parse_root_table
533 *
534 * PARAMETERS: Rsdp - Pointer to the RSDP
535 * Flags - Flags
536 *
537 * RETURN: Status
538 *
539 * DESCRIPTION: This function is called to parse the Root System Description
540 * Table (RSDT or XSDT)
541 *
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.
545 *
546 ******************************************************************************/
547
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300548acpi_status __init
Bob Moorec5fc42a2007-02-02 19:48:19 +0300549acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
Bob Mooref3d2e782007-02-02 19:48:18 +0300550{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300551 struct acpi_table_rsdp *rsdp;
552 acpi_native_uint table_entry_size;
553 acpi_native_uint i;
554 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300555 struct acpi_table_header *table;
556 acpi_physical_address address;
557 u32 length;
558 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300559 acpi_status status;
560
561 ACPI_FUNCTION_TRACE(tb_parse_root_table);
562
Bob Moorec5fc42a2007-02-02 19:48:19 +0300563 /*
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
Bob Mooref3d2e782007-02-02 19:48:18 +0300575 /* Differentiate between RSDT and XSDT root tables */
576
577 if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800578 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300579 * 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.
Bob Moorea18ecf42005-08-15 03:42:00 -0800582 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300583 address = (acpi_physical_address) rsdp->xsdt_physical_address;
584 table_entry_size = sizeof(u64);
Bob Mooref3d2e782007-02-02 19:48:18 +0300585 } else {
586 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400587
Bob Moorec5fc42a2007-02-02 19:48:19 +0300588 address = (acpi_physical_address) rsdp->rsdt_physical_address;
589 table_entry_size = sizeof(u32);
Bob Mooref3d2e782007-02-02 19:48:18 +0300590 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700591
Bob Moorec5fc42a2007-02-02 19:48:19 +0300592 /*
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 */
Robert Moore0c9938c2005-07-29 15:15:00 -0700599
Bob Mooref3d2e782007-02-02 19:48:18 +0300600 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
601 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300602 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300603 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700604
Bob Moorec5fc42a2007-02-02 19:48:19 +0300605 acpi_tb_print_table_header(address, table);
606
Bob Mooref3d2e782007-02-02 19:48:18 +0300607 /* 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));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300615 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300616 }
617
618 table = acpi_os_map_memory(address, length);
619 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300620 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300621 }
622
623 /* Validate the root table checksum */
624
Bob Moorec5fc42a2007-02-02 19:48:19 +0300625 status = acpi_tb_verify_checksum(table, length);
626 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300627 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300628 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300629 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300630
631 /* Calculate the number of tables described in the root table */
632
633 table_count =
Bob Moorea4bbb8102007-02-02 19:48:19 +0300634 (u32) ((table->length -
635 sizeof(struct acpi_table_header)) / table_entry_size);
Bob Mooref3d2e782007-02-02 19:48:18 +0300636
Bob Moorec5fc42a2007-02-02 19:48:19 +0300637 /*
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 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300641 table_entry =
642 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
643 acpi_gbl_root_table_list.count = 2;
644
645 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300646 * Initialize the root table array from the RSDT/XSDT
Bob Mooref3d2e782007-02-02 19:48:18 +0300647 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300648 for (i = 0; i < table_count; i++) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300649 if (acpi_gbl_root_table_list.count >=
650 acpi_gbl_root_table_list.size) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300651
652 /* There is no more room in the root table array, attempt resize */
653
Bob Mooref3d2e782007-02-02 19:48:18 +0300654 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 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700664 }
665
Bob Moorea4bbb8102007-02-02 19:48:19 +0300666 /* 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);
Bob Mooref3d2e782007-02-02 19:48:18 +0300671
Bob Moorec5fc42a2007-02-02 19:48:19 +0300672 table_entry += table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300673 acpi_gbl_root_table_list.count++;
674 }
675
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
Bob Moorec5fc42a2007-02-02 19:48:19 +0300682 /*
683 * Complete the initialization of the root table array by examining
684 * the header of each table
685 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300686 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300687 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
688 address, flags, NULL, i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300689
Bob Moorec5fc42a2007-02-02 19:48:19 +0300690 /* Special case for FADT - get the DSDT and FACS */
Bob Mooref3d2e782007-02-02 19:48:18 +0300691
Bob Moorec5fc42a2007-02-02 19:48:19 +0300692 if (ACPI_COMPARE_NAME
693 (&acpi_gbl_root_table_list.tables[i].signature,
694 ACPI_SIG_FADT)) {
695 acpi_tb_parse_fadt(i, flags);
Bob Mooref3d2e782007-02-02 19:48:18 +0300696 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700697 }
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700700}
701
Bob Mooref3d2e782007-02-02 19:48:18 +0300702/******************************************************************************
Robert Moore0c9938c2005-07-29 15:15:00 -0700703 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300704 * FUNCTION: acpi_tb_map
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300706 * PARAMETERS: Address - Address to be mapped
707 * Length - Length to be mapped
708 * Flags - Logical or physical addressing mode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300710 * RETURN: Pointer to mapped region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300712 * DESCRIPTION: Maps memory according to flag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300714 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Bob Mooref3d2e782007-02-02 19:48:18 +0300716void *acpi_tb_map(acpi_physical_address address, u32 length, u32 flags)
Bob Moore793c2382006-03-31 00:00:00 -0500717{
718
Bob Mooref3d2e782007-02-02 19:48:18 +0300719 if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
720 return (acpi_os_map_memory(address, length));
721 } else {
722 return (ACPI_CAST_PTR(void, address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
725
Bob Mooref3d2e782007-02-02 19:48:18 +0300726/******************************************************************************
Robert Moore44f6c012005-04-18 22:49:35 -0400727 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300728 * FUNCTION: acpi_tb_unmap
Robert Moore44f6c012005-04-18 22:49:35 -0400729 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300730 * PARAMETERS: Pointer - To mapped region
731 * Length - Length to be unmapped
732 * Flags - Logical or physical addressing mode
Robert Moore44f6c012005-04-18 22:49:35 -0400733 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300734 * RETURN: None
Robert Moore44f6c012005-04-18 22:49:35 -0400735 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300736 * DESCRIPTION: Unmaps memory according to flag
737 *
738 *****************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400739
Bob Mooref3d2e782007-02-02 19:48:18 +0300740void acpi_tb_unmap(void *pointer, u32 length, u32 flags)
Robert Moore44f6c012005-04-18 22:49:35 -0400741{
Robert Moore44f6c012005-04-18 22:49:35 -0400742
Bob Mooref3d2e782007-02-02 19:48:18 +0300743 if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
744 acpi_os_unmap_memory(pointer, length);
Robert Moore44f6c012005-04-18 22:49:35 -0400745 }
Robert Moore44f6c012005-04-18 22:49:35 -0400746}