blob: 77c7e873ec37c7ffc23f3769c991ff1173c1f095 [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
63/* Table used for conversion of FADT to common format */
64
65typedef struct acpi_fadt_conversion {
66 u8 target;
67 u8 source;
68 u8 length;
69
70} acpi_fadt_conversion;
71
72static struct acpi_fadt_conversion fadt_conversion_table[] = {
73 {ACPI_FADT_OFFSET(xpm1a_event_block),
74 ACPI_FADT_OFFSET(pm1a_event_block),
75 ACPI_FADT_OFFSET(pm1_event_length)},
76 {ACPI_FADT_OFFSET(xpm1b_event_block),
77 ACPI_FADT_OFFSET(pm1b_event_block),
78 ACPI_FADT_OFFSET(pm1_event_length)},
79 {ACPI_FADT_OFFSET(xpm1a_control_block),
80 ACPI_FADT_OFFSET(pm1a_control_block),
81 ACPI_FADT_OFFSET(pm1_control_length)},
82 {ACPI_FADT_OFFSET(xpm1b_control_block),
83 ACPI_FADT_OFFSET(pm1b_control_block),
84 ACPI_FADT_OFFSET(pm1_control_length)},
85 {ACPI_FADT_OFFSET(xpm2_control_block),
86 ACPI_FADT_OFFSET(pm2_control_block),
87 ACPI_FADT_OFFSET(pm2_control_length)},
88 {ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block),
89 ACPI_FADT_OFFSET(pm_timer_length)},
90 {ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block),
91 ACPI_FADT_OFFSET(gpe0_block_length)},
92 {ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block),
93 ACPI_FADT_OFFSET(gpe1_block_length)}
94};
95
96#define ACPI_FADT_CONVERSION_ENTRIES (sizeof (fadt_conversion_table) / sizeof (struct acpi_fadt_conversion))
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098/*******************************************************************************
99 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300100 * FUNCTION: acpi_tb_print_table_header
Robert Moore0c9938c2005-07-29 15:15:00 -0700101 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300102 * PARAMETERS: Address - Table physical address
103 * Header - Table header
Robert Moore0c9938c2005-07-29 15:15:00 -0700104 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300105 * RETURN: None
Robert Moore0c9938c2005-07-29 15:15:00 -0700106 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300107 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
Robert Moore0c9938c2005-07-29 15:15:00 -0700108 *
109 ******************************************************************************/
110
Bob Mooref3d2e782007-02-02 19:48:18 +0300111void
112acpi_tb_print_table_header(acpi_physical_address address,
113 struct acpi_table_header *header)
Robert Moore0c9938c2005-07-29 15:15:00 -0700114{
Robert Moore0c9938c2005-07-29 15:15:00 -0700115
Bob Moorec5fc42a2007-02-02 19:48:19 +0300116 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
117
118 /* FACS only has signature and length fields of common table header */
119
120 ACPI_INFO((AE_INFO, "%4.4s @ 0x%p/0x%04X",
121 header->signature, ACPI_CAST_PTR(void, address),
122 header->length));
123 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
124
125 /* RSDP has no common fields */
126
127 ACPI_INFO((AE_INFO, "RSDP @ 0x%p/0x%04X (v%3.3d %6.6s)",
128 ACPI_CAST_PTR(void, address),
129 (((struct acpi_table_rsdp *)header)->revision > 0) ?
130 ((struct acpi_table_rsdp *)header)->length : 20,
131 ((struct acpi_table_rsdp *)header)->revision,
132 ((struct acpi_table_rsdp *)header)->oem_id));
133 } else {
Bob Moore4bf27392007-02-02 19:48:19 +0300134 /* Standard ACPI table with full common header */
135
Bob Moorec5fc42a2007-02-02 19:48:19 +0300136 ACPI_INFO((AE_INFO,
137 "%4.4s @ 0x%p/0x%04X (v%3.3d %6.6s %8.8s 0x%08X %4.4s 0x%08X)",
138 header->signature, ACPI_CAST_PTR(void, address),
139 header->length, header->revision, header->oem_id,
140 header->oem_table_id, header->oem_revision,
141 header->asl_compiler_id,
142 header->asl_compiler_revision));
143 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300144}
Robert Moore0c9938c2005-07-29 15:15:00 -0700145
Bob Mooref3d2e782007-02-02 19:48:18 +0300146/*******************************************************************************
147 *
148 * FUNCTION: acpi_tb_init_generic_address
149 *
150 * PARAMETERS: new_gas_struct - GAS struct to be initialized
151 * bit_width - Width of this register
152 * Address - Address of the register
153 *
154 * RETURN: None
155 *
156 * DESCRIPTION: Initialize a GAS structure.
157 *
158 ******************************************************************************/
Robert Moore0c9938c2005-07-29 15:15:00 -0700159
Bob Mooref3d2e782007-02-02 19:48:18 +0300160static void inline
161acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300162 u8 bit_width, u64 address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300163{
Robert Moore0c9938c2005-07-29 15:15:00 -0700164
Bob Moore4bf27392007-02-02 19:48:19 +0300165 ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300166 new_gas_struct->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
167 new_gas_struct->bit_width = bit_width;
168 new_gas_struct->bit_offset = 0;
169 new_gas_struct->access_width = 0;
170}
Robert Moore0c9938c2005-07-29 15:15:00 -0700171
Bob Mooref3d2e782007-02-02 19:48:18 +0300172/*******************************************************************************
173 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300174 * FUNCTION: acpi_tb_validate_checksum
175 *
176 * PARAMETERS: Table - ACPI table to verify
177 * Length - Length of entire table
178 *
179 * RETURN: Status
180 *
181 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
182 * exception on bad checksum.
183 *
184 ******************************************************************************/
185
186acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
187{
188 u8 checksum;
189
190 /* Compute the checksum on the table */
191
192 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
193
194 /* Checksum ok? (should be zero) */
195
196 if (checksum) {
197 ACPI_WARNING((AE_INFO,
198 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
199 table->signature, table->checksum,
200 (u8) (table->checksum - checksum)));
201
202#if (ACPI_CHECKSUM_ABORT)
203
204 return (AE_BAD_CHECKSUM);
205#endif
206 }
207
208 return (AE_OK);
209}
210
211/*******************************************************************************
212 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300213 * FUNCTION: acpi_tb_checksum
214 *
215 * PARAMETERS: Buffer - Pointer to memory region to be checked
216 * Length - Length of this memory region
217 *
218 * RETURN: Checksum (u8)
219 *
220 * DESCRIPTION: Calculates circular checksum of memory region.
221 *
222 ******************************************************************************/
223
224u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
225{
226 u8 sum = 0;
227 u8 *end = buffer + length;
228
229 while (buffer < end) {
230 sum = (u8) (sum + *(buffer++));
231 }
232
233 return sum;
234}
235
236/*******************************************************************************
237 *
238 * FUNCTION: acpi_tb_convert_fadt
239 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300240 * PARAMETERS: None, uses acpi_gbl_FADT
Bob Mooref3d2e782007-02-02 19:48:18 +0300241 *
242 * RETURN: None
243 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300244 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
245 *
246 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must contain
247 * a copy of the actual FADT.
248 *
249 * ACPICA will use the "X" fields of the FADT for all addresses.
250 *
251 * "X" fields are optional extensions to the original V1.0 fields. Even if
252 * they are present in the structure, they can be optionally not used by
253 * setting them to zero. Therefore, we must selectively expand V1.0 fields
254 * if the corresponding X field is zero.
255 *
256 * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
257 * "X" fields.
258 *
259 * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
260 * expanding the corresponding ACPI 1.0 field.
Bob Mooref3d2e782007-02-02 19:48:18 +0300261 *
262 ******************************************************************************/
263
Bob Moorec5fc42a2007-02-02 19:48:19 +0300264static void acpi_tb_convert_fadt(void)
Bob Mooref3d2e782007-02-02 19:48:18 +0300265{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300266 u8 pm1_register_length;
267 struct acpi_generic_address *target;
268 acpi_native_uint i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300269
Bob Moorec5fc42a2007-02-02 19:48:19 +0300270 /* Expand the FACS and DSDT addresses as necessary */
271
Bob Mooref3d2e782007-02-02 19:48:18 +0300272 if (!acpi_gbl_FADT.Xfacs) {
273 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
274 }
275
276 if (!acpi_gbl_FADT.Xdsdt) {
277 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
278 }
279
280 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300281 * Expand the V1.0 addresses to the "X" generic address structs,
282 * as necessary.
Bob Mooref3d2e782007-02-02 19:48:18 +0300283 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300284 for (i = 0; i < ACPI_FADT_CONVERSION_ENTRIES; i++) {
285 target =
286 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
287 fadt_conversion_table[i].target);
288
Bob Moore4bf27392007-02-02 19:48:19 +0300289 /* Expand only if the X target is null */
290
Bob Moorec5fc42a2007-02-02 19:48:19 +0300291 if (!target->address) {
292 acpi_tb_init_generic_address(target,
293 *ACPI_ADD_PTR(u8,
294 &acpi_gbl_FADT,
295 fadt_conversion_table
296 [i].length),
Bob Moore4bf27392007-02-02 19:48:19 +0300297 *ACPI_ADD_PTR(u32,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300298 &acpi_gbl_FADT,
299 fadt_conversion_table
300 [i].source));
301 }
302 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300303
304 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300305 * Calculate separate GAS structs for the PM1 Enable registers.
306 * These addresses do not appear (directly) in the FADT, so it is
307 * useful to calculate them once, here.
Bob Moore4bf27392007-02-02 19:48:19 +0300308 *
309 * The PM event blocks are split into two register blocks, first is the
310 * PM Status Register block, followed immediately by the PM Enable Register
311 * block. Each is of length (pm1_event_length/2)
Bob Mooref3d2e782007-02-02 19:48:18 +0300312 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300313 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
314
315 /* PM1A is required */
316
Bob Mooref3d2e782007-02-02 19:48:18 +0300317 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300318 pm1_register_length,
Bob Moore4bf27392007-02-02 19:48:19 +0300319 (acpi_gbl_FADT.xpm1a_event_block.address +
320 pm1_register_length));
Bob Mooref3d2e782007-02-02 19:48:18 +0300321
Bob Moorec5fc42a2007-02-02 19:48:19 +0300322 /* PM1B is optional; leave null if not present */
323
Bob Mooref3d2e782007-02-02 19:48:18 +0300324 if (acpi_gbl_FADT.xpm1b_event_block.address) {
325 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300326 pm1_register_length,
Bob Moore4bf27392007-02-02 19:48:19 +0300327 (acpi_gbl_FADT.xpm1b_event_block.
328 address + pm1_register_length));
Bob Mooref3d2e782007-02-02 19:48:18 +0300329 }
330
331 /* Global FADT is the new common V2.0 FADT */
332
333 acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
334}
335
336/*******************************************************************************
337 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300338 * FUNCTION: acpi_tb_install_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300339 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300340 * PARAMETERS: Address - Physical address of DSDT or FACS
341 * Flags - Flags
342 * Signature - Table signature, NULL if no need to
343 * match
344 * table_index - Index into root table array
Bob Mooref3d2e782007-02-02 19:48:18 +0300345 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300346 * RETURN: None
Bob Mooref3d2e782007-02-02 19:48:18 +0300347 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300348 * DESCRIPTION: Install an ACPI table into the global data structure.
Bob Mooref3d2e782007-02-02 19:48:18 +0300349 *
350 ******************************************************************************/
351
Bob Moorec5fc42a2007-02-02 19:48:19 +0300352static void
353acpi_tb_install_table(acpi_physical_address address,
354 u8 flags, char *signature, acpi_native_uint table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300355{
Bob Mooref3d2e782007-02-02 19:48:18 +0300356 struct acpi_table_header *table;
357
Bob Moorec5fc42a2007-02-02 19:48:19 +0300358 if (!address) {
359 ACPI_ERROR((AE_INFO,
360 "Null physical address for ACPI table [%s]",
361 signature));
Bob Mooref3d2e782007-02-02 19:48:18 +0300362 return;
363 }
364
Bob Moorec5fc42a2007-02-02 19:48:19 +0300365 /* Map just the table header */
366
367 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300368 if (!table) {
369 return;
370 }
371
Bob Moorec5fc42a2007-02-02 19:48:19 +0300372 /* If a particular signature is expected, signature must match */
373
374 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
375 ACPI_ERROR((AE_INFO,
376 "Invalid signature 0x%X for ACPI table [%s]",
377 *ACPI_CAST_PTR(u32, table->signature), signature));
378 goto unmap_and_exit;
379 }
380
381 /* Initialize the table entry */
382
383 acpi_gbl_root_table_list.tables[table_index].address = address;
384 acpi_gbl_root_table_list.tables[table_index].length = table->length;
385 acpi_gbl_root_table_list.tables[table_index].flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300386
387 ACPI_MOVE_32_TO_32(&
Bob Moorec5fc42a2007-02-02 19:48:19 +0300388 (acpi_gbl_root_table_list.tables[table_index].
389 signature), table->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300390
Bob Moorec5fc42a2007-02-02 19:48:19 +0300391 acpi_tb_print_table_header(address, table);
Bob Mooref3d2e782007-02-02 19:48:18 +0300392
Bob Moorec5fc42a2007-02-02 19:48:19 +0300393 if (table_index == ACPI_TABLE_INDEX_DSDT) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300394
Bob Moorec5fc42a2007-02-02 19:48:19 +0300395 /* Global integer width is based upon revision of the DSDT */
396
397 acpi_ut_set_integer_width(table->revision);
398 }
399
400 unmap_and_exit:
Bob Mooref3d2e782007-02-02 19:48:18 +0300401 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
402}
403
404/*******************************************************************************
405 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300406 * FUNCTION: acpi_tb_parse_fadt
407 *
408 * PARAMETERS: table_index - Index for the FADT
409 * Flags - Flags
410 *
411 * RETURN: None
412 *
413 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
414 * (FADT contains the addresses of the DSDT and FACS)
415 *
416 ******************************************************************************/
417
418static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
419{
420 u32 length;
421 struct acpi_table_header *table;
422
423 /*
424 * Special case for the FADT because of multiple versions and the fact
425 * that it contains pointers to both the DSDT and FACS tables.
426 *
427 * Get a local copy of the FADT and convert it to a common format
428 * Map entire FADT, assumed to be smaller than one page.
429 */
430 length = acpi_gbl_root_table_list.tables[table_index].length;
431
432 table =
433 acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
434 address, length);
435 if (!table) {
436 return;
437 }
438
439 /*
440 * Validate the FADT checksum before we copy the table. Ignore
441 * checksum error as we want to try to get the DSDT and FACS.
442 */
443 (void)acpi_tb_verify_checksum(table, length);
444
445 /* Copy the entire FADT locally */
446
447 ACPI_MEMSET(&acpi_gbl_FADT, sizeof(struct acpi_table_fadt), 0);
448
449 ACPI_MEMCPY(&acpi_gbl_FADT, table,
450 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
451 acpi_os_unmap_memory(table, length);
452
453 /* Convert local FADT to the common internal format */
454
455 acpi_tb_convert_fadt();
456
457 /* Extract the DSDT and FACS tables from the FADT */
458
459 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
460 flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
461
462 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
463 flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
464}
465
466/*******************************************************************************
467 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300468 * FUNCTION: acpi_tb_parse_root_table
469 *
470 * PARAMETERS: Rsdp - Pointer to the RSDP
471 * Flags - Flags
472 *
473 * RETURN: Status
474 *
475 * DESCRIPTION: This function is called to parse the Root System Description
476 * Table (RSDT or XSDT)
477 *
478 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
479 * be mapped and cannot be copied because it contains the actual
480 * memory location of the ACPI Global Lock.
481 *
482 ******************************************************************************/
483
Bob Moorec5fc42a2007-02-02 19:48:19 +0300484acpi_status
485acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
Bob Mooref3d2e782007-02-02 19:48:18 +0300486{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300487 struct acpi_table_rsdp *rsdp;
488 acpi_native_uint table_entry_size;
489 acpi_native_uint i;
490 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300491 struct acpi_table_header *table;
492 acpi_physical_address address;
493 u32 length;
494 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300495 acpi_status status;
496
497 ACPI_FUNCTION_TRACE(tb_parse_root_table);
498
Bob Moorec5fc42a2007-02-02 19:48:19 +0300499 /*
500 * Map the entire RSDP and extract the address of the RSDT or XSDT
501 */
502 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
503 if (!rsdp) {
504 return_ACPI_STATUS(AE_NO_MEMORY);
505 }
506
507 acpi_tb_print_table_header(rsdp_address,
508 ACPI_CAST_PTR(struct acpi_table_header,
509 rsdp));
510
Bob Mooref3d2e782007-02-02 19:48:18 +0300511 /* Differentiate between RSDT and XSDT root tables */
512
513 if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800514 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300515 * Root table is an XSDT (64-bit physical addresses). We must use the
516 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
517 * the ACPI specification.
Bob Moorea18ecf42005-08-15 03:42:00 -0800518 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300519 address = (acpi_physical_address) rsdp->xsdt_physical_address;
520 table_entry_size = sizeof(u64);
Bob Mooref3d2e782007-02-02 19:48:18 +0300521 } else {
522 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400523
Bob Moorec5fc42a2007-02-02 19:48:19 +0300524 address = (acpi_physical_address) rsdp->rsdt_physical_address;
525 table_entry_size = sizeof(u32);
Bob Mooref3d2e782007-02-02 19:48:18 +0300526 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700527
Bob Moorec5fc42a2007-02-02 19:48:19 +0300528 /*
529 * It is not possible to map more than one entry in some environments,
530 * so unmap the RSDP here before mapping other tables
531 */
532 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
533
534 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700535
Bob Mooref3d2e782007-02-02 19:48:18 +0300536 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
537 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300538 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300539 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700540
Bob Moorec5fc42a2007-02-02 19:48:19 +0300541 acpi_tb_print_table_header(address, table);
542
Bob Mooref3d2e782007-02-02 19:48:18 +0300543 /* Get the length of the full table, verify length and map entire table */
544
545 length = table->length;
546 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
547
548 if (length < sizeof(struct acpi_table_header)) {
549 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
550 length));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300551 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300552 }
553
554 table = acpi_os_map_memory(address, length);
555 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300556 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300557 }
558
559 /* Validate the root table checksum */
560
Bob Moorec5fc42a2007-02-02 19:48:19 +0300561 status = acpi_tb_verify_checksum(table, length);
562 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300563 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300564 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300565 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300566
567 /* Calculate the number of tables described in the root table */
568
569 table_count =
Bob Moorec5fc42a2007-02-02 19:48:19 +0300570 (table->length -
571 sizeof(struct acpi_table_header)) / table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300572
Bob Moorec5fc42a2007-02-02 19:48:19 +0300573 /*
574 * First two entries in the table array are reserved for the DSDT and FACS,
575 * which are not actually present in the RSDT/XSDT - they come from the FADT
576 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300577 table_entry =
578 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
579 acpi_gbl_root_table_list.count = 2;
580
581 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300582 * Initialize the root table array from the RSDT/XSDT
Bob Mooref3d2e782007-02-02 19:48:18 +0300583 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300584 for (i = 0; i < table_count; i++) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300585 if (acpi_gbl_root_table_list.count >=
586 acpi_gbl_root_table_list.size) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300587
588 /* There is no more room in the root table array, attempt resize */
589
Bob Mooref3d2e782007-02-02 19:48:18 +0300590 status = acpi_tb_resize_root_table_list();
591 if (ACPI_FAILURE(status)) {
592 ACPI_WARNING((AE_INFO,
593 "Truncating %u table entries!",
594 (unsigned)
595 (acpi_gbl_root_table_list.size -
596 acpi_gbl_root_table_list.
597 count)));
598 break;
599 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700600 }
601
Bob Moorec5fc42a2007-02-02 19:48:19 +0300602 /*
603 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT)
604 */
605 if ((table_entry_size == sizeof(u32)) ||
606 (sizeof(acpi_physical_address) == sizeof(u32))) {
607 /*
608 * 32-bit platform, RSDT: Move 32-bit to 32-bit
609 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit
610 * 64-bit platform, RSDT: Expand 32-bit to 64-bit
611 *
612 * Note: Addresses are 32-bit aligned in both RSDT and XSDT
613 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300614 acpi_gbl_root_table_list.
615 tables[acpi_gbl_root_table_list.count].address =
616 (acpi_physical_address) (*ACPI_CAST_PTR
617 (u32, table_entry));
618 } else {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300619 /*
620 * 64-bit platform, XSDT: Move 64-bit to 64-bit
621 *
622 * Note: 64-bit addresses are only 32-bit aligned in the XSDT
623 */
624 ACPI_MOVE_64_TO_64(&acpi_gbl_root_table_list.
625 tables[acpi_gbl_root_table_list.
626 count].address, table_entry);
Bob Mooref3d2e782007-02-02 19:48:18 +0300627 }
628
Bob Moorec5fc42a2007-02-02 19:48:19 +0300629 table_entry += table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300630 acpi_gbl_root_table_list.count++;
631 }
632
633 /*
634 * It is not possible to map more than one entry in some environments,
635 * so unmap the root table here before mapping other tables
636 */
637 acpi_os_unmap_memory(table, length);
638
Bob Moorec5fc42a2007-02-02 19:48:19 +0300639 /*
640 * Complete the initialization of the root table array by examining
641 * the header of each table
642 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300643 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300644 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
645 address, flags, NULL, i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300646
Bob Moorec5fc42a2007-02-02 19:48:19 +0300647 /* Special case for FADT - get the DSDT and FACS */
Bob Mooref3d2e782007-02-02 19:48:18 +0300648
Bob Moorec5fc42a2007-02-02 19:48:19 +0300649 if (ACPI_COMPARE_NAME
650 (&acpi_gbl_root_table_list.tables[i].signature,
651 ACPI_SIG_FADT)) {
652 acpi_tb_parse_fadt(i, flags);
Bob Mooref3d2e782007-02-02 19:48:18 +0300653 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700654 }
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700657}
658
Bob Mooref3d2e782007-02-02 19:48:18 +0300659/******************************************************************************
Robert Moore0c9938c2005-07-29 15:15:00 -0700660 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300661 * FUNCTION: acpi_tb_map
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300663 * PARAMETERS: Address - Address to be mapped
664 * Length - Length to be mapped
665 * Flags - Logical or physical addressing mode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300667 * RETURN: Pointer to mapped region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300669 * DESCRIPTION: Maps memory according to flag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300671 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Bob Mooref3d2e782007-02-02 19:48:18 +0300673void *acpi_tb_map(acpi_physical_address address, u32 length, u32 flags)
Bob Moore793c2382006-03-31 00:00:00 -0500674{
675
Bob Mooref3d2e782007-02-02 19:48:18 +0300676 if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
677 return (acpi_os_map_memory(address, length));
678 } else {
679 return (ACPI_CAST_PTR(void, address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Bob Mooref3d2e782007-02-02 19:48:18 +0300683/******************************************************************************
Robert Moore44f6c012005-04-18 22:49:35 -0400684 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300685 * FUNCTION: acpi_tb_unmap
Robert Moore44f6c012005-04-18 22:49:35 -0400686 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300687 * PARAMETERS: Pointer - To mapped region
688 * Length - Length to be unmapped
689 * Flags - Logical or physical addressing mode
Robert Moore44f6c012005-04-18 22:49:35 -0400690 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300691 * RETURN: None
Robert Moore44f6c012005-04-18 22:49:35 -0400692 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300693 * DESCRIPTION: Unmaps memory according to flag
694 *
695 *****************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400696
Bob Mooref3d2e782007-02-02 19:48:18 +0300697void acpi_tb_unmap(void *pointer, u32 length, u32 flags)
Robert Moore44f6c012005-04-18 22:49:35 -0400698{
Robert Moore44f6c012005-04-18 22:49:35 -0400699
Bob Mooref3d2e782007-02-02 19:48:18 +0300700 if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
701 acpi_os_unmap_memory(pointer, length);
Robert Moore44f6c012005-04-18 22:49:35 -0400702 }
Robert Moore44f6c012005-04-18 22:49:35 -0400703}