blob: 07bc7437f82bca5cd8bc5e1ee569cd8efbae5321 [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 Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("tbutils")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Bob Moorecf02cd42009-06-24 11:38:46 +080052static 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
Bob Moorea4bbb812007-02-02 19:48:19 +030058static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +080059acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
60
Zhao Yakui9f3119b2007-08-24 16:18:16 +080061/*******************************************************************************
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}
Bob Moorea4bbb812007-02-02 19:48:19 +0300120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121/*******************************************************************************
122 *
Bob Moore009c4cbe2008-11-12 15:34:52 +0800123 * 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
145/*******************************************************************************
146 *
Bob Moorec8573032007-02-02 19:48:23 +0300147 * 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
168/*******************************************************************************
169 *
Bob Moorecf02cd42009-06-24 11:38:46 +0800170 * 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
221/*******************************************************************************
222 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300223 * FUNCTION: acpi_tb_print_table_header
Robert Moore0c9938c2005-07-29 15:15:00 -0700224 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300225 * PARAMETERS: Address - Table physical address
226 * Header - Table header
Robert Moore0c9938c2005-07-29 15:15:00 -0700227 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300228 * RETURN: None
Robert Moore0c9938c2005-07-29 15:15:00 -0700229 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300230 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
Robert Moore0c9938c2005-07-29 15:15:00 -0700231 *
232 ******************************************************************************/
233
Bob Mooref3d2e782007-02-02 19:48:18 +0300234void
235acpi_tb_print_table_header(acpi_physical_address address,
236 struct acpi_table_header *header)
Robert Moore0c9938c2005-07-29 15:15:00 -0700237{
Bob Moorecf02cd42009-06-24 11:38:46 +0800238 struct acpi_table_header local_header;
Robert Moore0c9938c2005-07-29 15:15:00 -0700239
Bob Mooreb6bc3422009-02-23 10:26:19 +0800240 /*
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 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300244 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
245
Bob Mooreb6bc3422009-02-23 10:26:19 +0800246 /* FACS only has signature and length fields */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300247
Bob Mooreb6bc3422009-02-23 10:26:19 +0800248 ACPI_INFO((AE_INFO, "%4.4s %p %05X",
249 header->signature, ACPI_CAST_PTR(void, address),
Bob Moorec5fc42a2007-02-02 19:48:19 +0300250 header->length));
251 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
252
253 /* RSDP has no common fields */
254
Bob Moorecf02cd42009-06-24 11:38:46 +0800255 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
Bob Mooreb6bc3422009-02-23 10:26:19 +0800260 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
261 ACPI_CAST_PTR (void, address),
Bob Moorea4bbb812007-02-02 19:48:19 +0300262 (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,
Bob Moorecf02cd42009-06-24 11:38:46 +0800268 local_header.oem_id));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300269 } else {
Bob Moore4bf27392007-02-02 19:48:19 +0300270 /* Standard ACPI table with full common header */
271
Bob Moorecf02cd42009-06-24 11:38:46 +0800272 acpi_tb_cleanup_table_header(&local_header, header);
273
Bob Moorec5fc42a2007-02-02 19:48:19 +0300274 ACPI_INFO((AE_INFO,
Bob Mooreb6bc3422009-02-23 10:26:19 +0800275 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
Bob Moorecf02cd42009-06-24 11:38:46 +0800276 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
Bob Moorec5fc42a2007-02-02 19:48:19 +0300283 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300284}
Robert Moore0c9938c2005-07-29 15:15:00 -0700285
Bob Mooref3d2e782007-02-02 19:48:18 +0300286/*******************************************************************************
287 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300288 * 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,
Bob Mooref6a22b02010-03-05 17:56:40 +0800312 "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X",
Bob Moorec5fc42a2007-02-02 19:48:19 +0300313 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
325/*******************************************************************************
326 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300327 * FUNCTION: acpi_tb_checksum
328 *
329 * PARAMETERS: Buffer - Pointer to memory region to be checked
330 * Length - Length of this memory region
331 *
332 * RETURN: Checksum (u8)
333 *
334 * DESCRIPTION: Calculates circular checksum of memory region.
335 *
336 ******************************************************************************/
337
Bob Moore67a119f2008-06-10 13:42:13 +0800338u8 acpi_tb_checksum(u8 *buffer, u32 length)
Bob Mooref3d2e782007-02-02 19:48:18 +0300339{
340 u8 sum = 0;
341 u8 *end = buffer + length;
342
343 while (buffer < end) {
344 sum = (u8) (sum + *(buffer++));
345 }
346
347 return sum;
348}
349
350/*******************************************************************************
351 *
Lin Ming729df0f2010-04-01 10:47:56 +0800352 * 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
388/*******************************************************************************
389 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300390 * FUNCTION: acpi_tb_install_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300391 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300392 * PARAMETERS: Address - Physical address of DSDT or FACS
Bob Moorec5fc42a2007-02-02 19:48:19 +0300393 * Signature - Table signature, NULL if no need to
394 * match
395 * table_index - Index into root table array
Bob Mooref3d2e782007-02-02 19:48:18 +0300396 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300397 * RETURN: None
Bob Mooref3d2e782007-02-02 19:48:18 +0300398 *
Bob Mooreac5f98d2009-02-03 14:35:25 +0800399 * 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.
Bob Mooref3d2e782007-02-02 19:48:18 +0300403 *
404 ******************************************************************************/
405
Bob Moore765ec202007-02-02 19:48:20 +0300406void
Bob Moorec5fc42a2007-02-02 19:48:19 +0300407acpi_tb_install_table(acpi_physical_address address,
Bob Moore97cbb7d2009-02-03 14:41:03 +0800408 char *signature, u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300409{
Bob Moore97cbb7d2009-02-03 14:41:03 +0800410 u8 flags;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800411 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;
Bob Mooref3d2e782007-02-02 19:48:18 +0300415
Bob Moorec5fc42a2007-02-02 19:48:19 +0300416 if (!address) {
417 ACPI_ERROR((AE_INFO,
418 "Null physical address for ACPI table [%s]",
419 signature));
Bob Mooref3d2e782007-02-02 19:48:18 +0300420 return;
421 }
422
Bob Moorec5fc42a2007-02-02 19:48:19 +0300423 /* Map just the table header */
424
Bob Mooreac5f98d2009-02-03 14:35:25 +0800425 mapped_table =
426 acpi_os_map_memory(address, sizeof(struct acpi_table_header));
427 if (!mapped_table) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300428 return;
429 }
430
Bob Mooreac5f98d2009-02-03 14:35:25 +0800431 /* If a particular signature is expected (DSDT/FACS), it must match */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300432
Bob Mooreac5f98d2009-02-03 14:35:25 +0800433 if (signature && !ACPI_COMPARE_NAME(mapped_table->signature, signature)) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300434 ACPI_ERROR((AE_INFO,
Bob Mooreac5f98d2009-02-03 14:35:25 +0800435 "Invalid signature 0x%X for ACPI table, expected [%s]",
436 *ACPI_CAST_PTR(u32, mapped_table->signature),
437 signature));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300438 goto unmap_and_exit;
439 }
440
Bob Mooreac5f98d2009-02-03 14:35:25 +0800441 /*
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;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800457 address = ACPI_PTR_TO_PHYSADDR(override_table);
458
459 table_to_install = override_table;
Bob Moore97cbb7d2009-02-03 14:41:03 +0800460 flags = ACPI_TABLE_ORIGIN_OVERRIDE;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800461 } else {
462 table_to_install = mapped_table;
Bob Moore97cbb7d2009-02-03 14:41:03 +0800463 flags = ACPI_TABLE_ORIGIN_MAPPED;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800464 }
465
Bob Moorec5fc42a2007-02-02 19:48:19 +0300466 /* Initialize the table entry */
467
468 acpi_gbl_root_table_list.tables[table_index].address = address;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800469 acpi_gbl_root_table_list.tables[table_index].length =
470 table_to_install->length;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300471 acpi_gbl_root_table_list.tables[table_index].flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300472
473 ACPI_MOVE_32_TO_32(&
Bob Moorec5fc42a2007-02-02 19:48:19 +0300474 (acpi_gbl_root_table_list.tables[table_index].
Bob Mooreac5f98d2009-02-03 14:35:25 +0800475 signature), table_to_install->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300476
Bob Mooreac5f98d2009-02-03 14:35:25 +0800477 acpi_tb_print_table_header(address, table_to_install);
Bob Mooref3d2e782007-02-02 19:48:18 +0300478
Bob Moorec5fc42a2007-02-02 19:48:19 +0300479 if (table_index == ACPI_TABLE_INDEX_DSDT) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300480
Bob Moorec5fc42a2007-02-02 19:48:19 +0300481 /* Global integer width is based upon revision of the DSDT */
482
Bob Mooreac5f98d2009-02-03 14:35:25 +0800483 acpi_ut_set_integer_width(table_to_install->revision);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300484 }
485
486 unmap_and_exit:
Bob Mooreac5f98d2009-02-03 14:35:25 +0800487 acpi_os_unmap_memory(mapped_table, sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300488}
489
490/*******************************************************************************
491 *
Bob Moorea4bbb812007-02-02 19:48:19 +0300492 * 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
Bob Moore67a119f2008-06-10 13:42:13 +0800508acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
Bob Moorea4bbb812007-02-02 19:48:19 +0300509{
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
Bob Mooreec41f192009-02-18 15:03:30 +0800526 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
527 * return 64-bit
Bob Moorea4bbb812007-02-02 19:48:19 +0300528 */
529 ACPI_MOVE_64_TO_64(&address64, table_entry);
530
531#if ACPI_MACHINE_WIDTH == 32
532 if (address64 > ACPI_UINT32_MAX) {
533
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300534 /* Will truncate 64-bit address to 32 bits, issue warning */
Bob Moorea4bbb812007-02-02 19:48:19 +0300535
536 ACPI_WARNING((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800537 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
Bob Mooreec41f192009-02-18 15:03:30 +0800538 " truncating",
Bob Moorea4bbb812007-02-02 19:48:19 +0300539 ACPI_FORMAT_UINT64(address64)));
540 }
541#endif
542 return ((acpi_physical_address) (address64));
543 }
544}
545
546/*******************************************************************************
547 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300548 * FUNCTION: acpi_tb_parse_root_table
549 *
550 * PARAMETERS: Rsdp - Pointer to the RSDP
Bob Mooref3d2e782007-02-02 19:48:18 +0300551 *
552 * RETURN: Status
553 *
554 * DESCRIPTION: This function is called to parse the Root System Description
555 * Table (RSDT or XSDT)
556 *
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.
560 *
561 ******************************************************************************/
562
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300563acpi_status __init
Bob Moore97cbb7d2009-02-03 14:41:03 +0800564acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300565{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300566 struct acpi_table_rsdp *rsdp;
Bob Moore67a119f2008-06-10 13:42:13 +0800567 u32 table_entry_size;
568 u32 i;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300569 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300570 struct acpi_table_header *table;
571 acpi_physical_address address;
Andrew Morton8ab73672007-10-02 13:24:10 -0700572 acpi_physical_address uninitialized_var(rsdt_address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300573 u32 length;
574 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300575 acpi_status status;
576
577 ACPI_FUNCTION_TRACE(tb_parse_root_table);
578
Bob Moorec5fc42a2007-02-02 19:48:19 +0300579 /*
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
Bob Mooref3d2e782007-02-02 19:48:18 +0300591 /* Differentiate between RSDT and XSDT root tables */
592
Zhao Yakui237889b2008-12-17 16:55:18 +0800593 if (rsdp->revision > 1 && rsdp->xsdt_physical_address
594 && !acpi_rsdt_forced) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800595 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300596 * 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.
Bob Moorea18ecf42005-08-15 03:42:00 -0800599 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300600 address = (acpi_physical_address) rsdp->xsdt_physical_address;
601 table_entry_size = sizeof(u64);
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800602 rsdt_address = (acpi_physical_address)
603 rsdp->rsdt_physical_address;
Bob Mooref3d2e782007-02-02 19:48:18 +0300604 } else {
605 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400606
Bob Moorec5fc42a2007-02-02 19:48:19 +0300607 address = (acpi_physical_address) rsdp->rsdt_physical_address;
608 table_entry_size = sizeof(u32);
Bob Mooref3d2e782007-02-02 19:48:18 +0300609 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700610
Bob Moorec5fc42a2007-02-02 19:48:19 +0300611 /*
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
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800617 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);
Joe Perches4fdb2a02007-11-19 17:48:02 -0800622 ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800623 "using RSDT"));
624 }
625 }
Bob Moorec5fc42a2007-02-02 19:48:19 +0300626 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700627
Bob Mooref3d2e782007-02-02 19:48:18 +0300628 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
629 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300630 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300631 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700632
Bob Moorec5fc42a2007-02-02 19:48:19 +0300633 acpi_tb_print_table_header(address, table);
634
Bob Mooref3d2e782007-02-02 19:48:18 +0300635 /* 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));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300643 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300644 }
645
646 table = acpi_os_map_memory(address, length);
647 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300648 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300649 }
650
651 /* Validate the root table checksum */
652
Bob Moorec5fc42a2007-02-02 19:48:19 +0300653 status = acpi_tb_verify_checksum(table, length);
654 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300655 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300656 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300657 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300658
659 /* Calculate the number of tables described in the root table */
660
Bob Mooreec41f192009-02-18 15:03:30 +0800661 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
662 table_entry_size);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300663 /*
Bob Mooreec41f192009-02-18 15:03:30 +0800664 * 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
Bob Moorec5fc42a2007-02-02 19:48:19 +0300667 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300668 table_entry =
669 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
670 acpi_gbl_root_table_list.count = 2;
671
672 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300673 * Initialize the root table array from the RSDT/XSDT
Bob Mooref3d2e782007-02-02 19:48:18 +0300674 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300675 for (i = 0; i < table_count; i++) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300676 if (acpi_gbl_root_table_list.count >=
677 acpi_gbl_root_table_list.size) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300678
679 /* There is no more room in the root table array, attempt resize */
680
Bob Mooref3d2e782007-02-02 19:48:18 +0300681 status = acpi_tb_resize_root_table_list();
682 if (ACPI_FAILURE(status)) {
683 ACPI_WARNING((AE_INFO,
684 "Truncating %u table entries!",
Myron Stowe386e4a82009-01-30 15:44:53 -0700685 (unsigned) (table_count -
686 (acpi_gbl_root_table_list.
687 count - 2))));
Bob Mooref3d2e782007-02-02 19:48:18 +0300688 break;
689 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700690 }
691
Bob Moorea4bbb812007-02-02 19:48:19 +0300692 /* 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);
Bob Mooref3d2e782007-02-02 19:48:18 +0300697
Bob Moorec5fc42a2007-02-02 19:48:19 +0300698 table_entry += table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300699 acpi_gbl_root_table_list.count++;
700 }
701
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
Bob Moorec5fc42a2007-02-02 19:48:19 +0300708 /*
709 * Complete the initialization of the root table array by examining
710 * the header of each table
711 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300712 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300713 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
Bob Moore97cbb7d2009-02-03 14:41:03 +0800714 address, NULL, i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300715
Bob Moorec5fc42a2007-02-02 19:48:19 +0300716 /* Special case for FADT - get the DSDT and FACS */
Bob Mooref3d2e782007-02-02 19:48:18 +0300717
Bob Moorec5fc42a2007-02-02 19:48:19 +0300718 if (ACPI_COMPARE_NAME
719 (&acpi_gbl_root_table_list.tables[i].signature,
720 ACPI_SIG_FADT)) {
Bob Moore97cbb7d2009-02-03 14:41:03 +0800721 acpi_tb_parse_fadt(i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300722 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700723 }
724
Len Brown4be44fc2005-08-05 00:44:28 -0400725 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700726}