blob: 6818b31954c8449eca7b3ff5a19c78eccc3c1967 [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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 Moorea4bbb8102007-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 Moorea4bbb8102007-02-02 19:48:19 +0300120
Bob Moore33620c52012-02-14 18:14:27 +0800121#if (!ACPI_REDUCED_HARDWARE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/*******************************************************************************
123 *
Bob Moore009c4cbe2008-11-12 15:34:52 +0800124 * FUNCTION: acpi_tb_initialize_facs
125 *
126 * PARAMETERS: None
127 *
128 * RETURN: Status
129 *
130 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
131 * for accessing the Global Lock and Firmware Waking Vector
132 *
133 ******************************************************************************/
134
135acpi_status acpi_tb_initialize_facs(void)
136{
137 acpi_status status;
138
Bob Moore22e5b402011-11-16 10:57:28 +0800139 /* If Hardware Reduced flag is set, there is no FACS */
140
141 if (acpi_gbl_reduced_hardware) {
142 acpi_gbl_FACS = NULL;
143 return (AE_OK);
144 }
145
Bob Moore009c4cbe2008-11-12 15:34:52 +0800146 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
147 ACPI_CAST_INDIRECT_PTR(struct
148 acpi_table_header,
149 &acpi_gbl_FACS));
150 return status;
151}
Bob Moore33620c52012-02-14 18:14:27 +0800152#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore009c4cbe2008-11-12 15:34:52 +0800153
154/*******************************************************************************
155 *
Bob Moorec8573032007-02-02 19:48:23 +0300156 * FUNCTION: acpi_tb_tables_loaded
157 *
158 * PARAMETERS: None
159 *
160 * RETURN: TRUE if required ACPI tables are loaded
161 *
162 * DESCRIPTION: Determine if the minimum required ACPI tables are present
163 * (FADT, FACS, DSDT)
164 *
165 ******************************************************************************/
166
167u8 acpi_tb_tables_loaded(void)
168{
169
Bob Mooreb9ee2042010-04-27 11:16:14 +0800170 if (acpi_gbl_root_table_list.current_table_count >= 3) {
Bob Moorec8573032007-02-02 19:48:23 +0300171 return (TRUE);
172 }
173
174 return (FALSE);
175}
176
177/*******************************************************************************
178 *
Bob Moorecf02cd42009-06-24 11:38:46 +0800179 * FUNCTION: acpi_tb_fix_string
180 *
181 * PARAMETERS: String - String to be repaired
182 * Length - Maximum length
183 *
184 * RETURN: None
185 *
186 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
187 * with a question mark '?'.
188 *
189 ******************************************************************************/
190
191static void acpi_tb_fix_string(char *string, acpi_size length)
192{
193
194 while (length && *string) {
195 if (!ACPI_IS_PRINT(*string)) {
196 *string = '?';
197 }
198 string++;
199 length--;
200 }
201}
202
203/*******************************************************************************
204 *
205 * FUNCTION: acpi_tb_cleanup_table_header
206 *
207 * PARAMETERS: out_header - Where the cleaned header is returned
208 * Header - Input ACPI table header
209 *
210 * RETURN: Returns the cleaned header in out_header
211 *
212 * DESCRIPTION: Copy the table header and ensure that all "string" fields in
213 * the header consist of printable characters.
214 *
215 ******************************************************************************/
216
217static void
218acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
219 struct acpi_table_header *header)
220{
221
222 ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header));
223
224 acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
225 acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
226 acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
227 acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
228}
229
230/*******************************************************************************
231 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300232 * FUNCTION: acpi_tb_print_table_header
Robert Moore0c9938c2005-07-29 15:15:00 -0700233 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300234 * PARAMETERS: Address - Table physical address
235 * Header - Table header
Robert Moore0c9938c2005-07-29 15:15:00 -0700236 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300237 * RETURN: None
Robert Moore0c9938c2005-07-29 15:15:00 -0700238 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300239 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
Robert Moore0c9938c2005-07-29 15:15:00 -0700240 *
241 ******************************************************************************/
242
Bob Mooref3d2e782007-02-02 19:48:18 +0300243void
244acpi_tb_print_table_header(acpi_physical_address address,
245 struct acpi_table_header *header)
Robert Moore0c9938c2005-07-29 15:15:00 -0700246{
Bob Moorecf02cd42009-06-24 11:38:46 +0800247 struct acpi_table_header local_header;
Robert Moore0c9938c2005-07-29 15:15:00 -0700248
Bob Mooreb6bc3422009-02-23 10:26:19 +0800249 /*
250 * The reason that the Address is cast to a void pointer is so that we
251 * can use %p which will work properly on both 32-bit and 64-bit hosts.
252 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300253 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
254
Bob Mooreb6bc3422009-02-23 10:26:19 +0800255 /* FACS only has signature and length fields */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300256
Bob Mooreb6bc3422009-02-23 10:26:19 +0800257 ACPI_INFO((AE_INFO, "%4.4s %p %05X",
258 header->signature, ACPI_CAST_PTR(void, address),
Bob Moorec5fc42a2007-02-02 19:48:19 +0300259 header->length));
260 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
261
262 /* RSDP has no common fields */
263
Bob Moorecf02cd42009-06-24 11:38:46 +0800264 ACPI_MEMCPY(local_header.oem_id,
265 ACPI_CAST_PTR(struct acpi_table_rsdp,
266 header)->oem_id, ACPI_OEM_ID_SIZE);
267 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
268
Bob Mooreb6bc3422009-02-23 10:26:19 +0800269 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
270 ACPI_CAST_PTR (void, address),
Bob Moorea4bbb8102007-02-02 19:48:19 +0300271 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
272 revision >
273 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
274 header)->length : 20,
275 ACPI_CAST_PTR(struct acpi_table_rsdp,
276 header)->revision,
Bob Moorecf02cd42009-06-24 11:38:46 +0800277 local_header.oem_id));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300278 } else {
Bob Moore4bf27392007-02-02 19:48:19 +0300279 /* Standard ACPI table with full common header */
280
Bob Moorecf02cd42009-06-24 11:38:46 +0800281 acpi_tb_cleanup_table_header(&local_header, header);
282
Bob Moorec5fc42a2007-02-02 19:48:19 +0300283 ACPI_INFO((AE_INFO,
Bob Mooreb6bc3422009-02-23 10:26:19 +0800284 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
Bob Moorecf02cd42009-06-24 11:38:46 +0800285 local_header.signature, ACPI_CAST_PTR(void, address),
286 local_header.length, local_header.revision,
287 local_header.oem_id, local_header.oem_table_id,
288 local_header.oem_revision,
289 local_header.asl_compiler_id,
290 local_header.asl_compiler_revision));
291
Bob Moorec5fc42a2007-02-02 19:48:19 +0300292 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300293}
Robert Moore0c9938c2005-07-29 15:15:00 -0700294
Bob Mooref3d2e782007-02-02 19:48:18 +0300295/*******************************************************************************
296 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300297 * FUNCTION: acpi_tb_validate_checksum
298 *
299 * PARAMETERS: Table - ACPI table to verify
300 * Length - Length of entire table
301 *
302 * RETURN: Status
303 *
304 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
305 * exception on bad checksum.
306 *
307 ******************************************************************************/
308
309acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
310{
311 u8 checksum;
312
313 /* Compute the checksum on the table */
314
315 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
316
317 /* Checksum ok? (should be zero) */
318
319 if (checksum) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800320 ACPI_BIOS_WARNING((AE_INFO,
321 "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
322 "should be 0x%2.2X",
323 table->signature, table->checksum,
324 (u8)(table->checksum - checksum)));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300325
326#if (ACPI_CHECKSUM_ABORT)
327
328 return (AE_BAD_CHECKSUM);
329#endif
330 }
331
332 return (AE_OK);
333}
334
335/*******************************************************************************
336 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300337 * FUNCTION: acpi_tb_checksum
338 *
339 * PARAMETERS: Buffer - Pointer to memory region to be checked
340 * Length - Length of this memory region
341 *
342 * RETURN: Checksum (u8)
343 *
344 * DESCRIPTION: Calculates circular checksum of memory region.
345 *
346 ******************************************************************************/
347
Bob Moore67a119f2008-06-10 13:42:13 +0800348u8 acpi_tb_checksum(u8 *buffer, u32 length)
Bob Mooref3d2e782007-02-02 19:48:18 +0300349{
350 u8 sum = 0;
351 u8 *end = buffer + length;
352
353 while (buffer < end) {
354 sum = (u8) (sum + *(buffer++));
355 }
356
357 return sum;
358}
359
360/*******************************************************************************
361 *
Lin Ming729df0f2010-04-01 10:47:56 +0800362 * FUNCTION: acpi_tb_check_dsdt_header
363 *
364 * PARAMETERS: None
365 *
366 * RETURN: None
367 *
368 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
369 * if the DSDT has been replaced from outside the OS and/or if
370 * the DSDT header has been corrupted.
371 *
372 ******************************************************************************/
373
374void acpi_tb_check_dsdt_header(void)
375{
376
377 /* Compare original length and checksum to current values */
378
Bob Moore43323cb2010-04-07 11:05:11 +0800379 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
380 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800381 ACPI_BIOS_ERROR((AE_INFO,
382 "The DSDT has been corrupted or replaced - "
383 "old, new headers below"));
Lin Ming729df0f2010-04-01 10:47:56 +0800384 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
Bob Moore43323cb2010-04-07 11:05:11 +0800385 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
Lin Ming729df0f2010-04-01 10:47:56 +0800386
Lin Mingaa2110c2010-04-08 14:34:27 +0800387 ACPI_ERROR((AE_INFO,
388 "Please send DMI info to linux-acpi@vger.kernel.org\n"
389 "If system does not work as expected, please boot with acpi=copy_dsdt"));
390
Lin Ming729df0f2010-04-01 10:47:56 +0800391 /* Disable further error messages */
392
Bob Moore43323cb2010-04-07 11:05:11 +0800393 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
Lin Ming729df0f2010-04-01 10:47:56 +0800394 acpi_gbl_original_dsdt_header.checksum =
Bob Moore43323cb2010-04-07 11:05:11 +0800395 acpi_gbl_DSDT->checksum;
Lin Ming729df0f2010-04-01 10:47:56 +0800396 }
397}
398
399/*******************************************************************************
400 *
Lin Ming69ec87e2010-04-01 11:14:12 +0800401 * FUNCTION: acpi_tb_copy_dsdt
402 *
403 * PARAMETERS: table_desc - Installed table to copy
404 *
405 * RETURN: None
406 *
407 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
408 * Some very bad BIOSs are known to either corrupt the DSDT or
409 * install a new, bad DSDT. This copy works around the problem.
410 *
411 ******************************************************************************/
412
Bob Moore43323cb2010-04-07 11:05:11 +0800413struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
Lin Ming69ec87e2010-04-01 11:14:12 +0800414{
415 struct acpi_table_header *new_table;
Bob Moore43323cb2010-04-07 11:05:11 +0800416 struct acpi_table_desc *table_desc;
417
418 table_desc = &acpi_gbl_root_table_list.tables[table_index];
Lin Ming69ec87e2010-04-01 11:14:12 +0800419
420 new_table = ACPI_ALLOCATE(table_desc->length);
421 if (!new_table) {
422 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
423 table_desc->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800424 return (NULL);
Lin Ming69ec87e2010-04-01 11:14:12 +0800425 }
426
427 ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
428 acpi_tb_delete_table(table_desc);
429 table_desc->pointer = new_table;
430 table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED;
431
432 ACPI_INFO((AE_INFO,
433 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
434 new_table->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800435
436 return (new_table);
Lin Ming69ec87e2010-04-01 11:14:12 +0800437}
438
439/*******************************************************************************
440 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300441 * FUNCTION: acpi_tb_install_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300442 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300443 * PARAMETERS: Address - Physical address of DSDT or FACS
Bob Moorec5fc42a2007-02-02 19:48:19 +0300444 * Signature - Table signature, NULL if no need to
445 * match
446 * table_index - Index into root table array
Bob Mooref3d2e782007-02-02 19:48:18 +0300447 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300448 * RETURN: None
Bob Mooref3d2e782007-02-02 19:48:18 +0300449 *
Bob Mooreac5f98d2009-02-03 14:35:25 +0800450 * DESCRIPTION: Install an ACPI table into the global data structure. The
Bob Mooref7b004a2012-02-14 18:31:56 +0800451 * table override mechanism is called to allow the host
Bob Mooreac5f98d2009-02-03 14:35:25 +0800452 * OS to replace any table before it is installed in the root
453 * table array.
Bob Mooref3d2e782007-02-02 19:48:18 +0300454 *
455 ******************************************************************************/
456
Bob Moore765ec202007-02-02 19:48:20 +0300457void
Bob Moorec5fc42a2007-02-02 19:48:19 +0300458acpi_tb_install_table(acpi_physical_address address,
Bob Moore97cbb7d2009-02-03 14:41:03 +0800459 char *signature, u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300460{
Bob Mooref7b004a2012-02-14 18:31:56 +0800461 struct acpi_table_header *table;
462 struct acpi_table_header *final_table;
463 struct acpi_table_desc *table_desc;
Bob Mooref3d2e782007-02-02 19:48:18 +0300464
Bob Moorec5fc42a2007-02-02 19:48:19 +0300465 if (!address) {
466 ACPI_ERROR((AE_INFO,
467 "Null physical address for ACPI table [%s]",
468 signature));
Bob Mooref3d2e782007-02-02 19:48:18 +0300469 return;
470 }
471
Bob Moorec5fc42a2007-02-02 19:48:19 +0300472 /* Map just the table header */
473
Bob Mooref7b004a2012-02-14 18:31:56 +0800474 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
475 if (!table) {
476 ACPI_ERROR((AE_INFO,
477 "Could not map memory for table [%s] at %p",
478 signature, ACPI_CAST_PTR(void, address)));
Bob Mooref3d2e782007-02-02 19:48:18 +0300479 return;
480 }
481
Bob Mooreac5f98d2009-02-03 14:35:25 +0800482 /* If a particular signature is expected (DSDT/FACS), it must match */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300483
Bob Mooref7b004a2012-02-14 18:31:56 +0800484 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800485 ACPI_BIOS_ERROR((AE_INFO,
486 "Invalid signature 0x%X for ACPI table, expected [%s]",
487 *ACPI_CAST_PTR(u32, table->signature),
488 signature));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300489 goto unmap_and_exit;
490 }
491
Bob Mooreac5f98d2009-02-03 14:35:25 +0800492 /*
Bob Mooref7b004a2012-02-14 18:31:56 +0800493 * Initialize the table entry. Set the pointer to NULL, since the
494 * table is not fully mapped at this time.
495 */
496 table_desc = &acpi_gbl_root_table_list.tables[table_index];
497
498 table_desc->address = address;
499 table_desc->pointer = NULL;
500 table_desc->length = table->length;
501 table_desc->flags = ACPI_TABLE_ORIGIN_MAPPED;
502 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
503
504 /*
Bob Mooreac5f98d2009-02-03 14:35:25 +0800505 * ACPI Table Override:
506 *
507 * Before we install the table, let the host OS override it with a new
508 * one if desired. Any table within the RSDT/XSDT can be replaced,
509 * including the DSDT which is pointed to by the FADT.
Bob Mooref7b004a2012-02-14 18:31:56 +0800510 *
511 * NOTE: If the table is overridden, then final_table will contain a
512 * mapped pointer to the full new table. If the table is not overridden,
513 * or if there has been a physical override, then the table will be
514 * fully mapped later (in verify table). In any case, we must
515 * unmap the header that was mapped above.
Bob Mooreac5f98d2009-02-03 14:35:25 +0800516 */
Bob Mooref7b004a2012-02-14 18:31:56 +0800517 final_table = acpi_tb_table_override(table, table_desc);
518 if (!final_table) {
519 final_table = table; /* There was no override */
Bob Mooreac5f98d2009-02-03 14:35:25 +0800520 }
521
Bob Mooref7b004a2012-02-14 18:31:56 +0800522 acpi_tb_print_table_header(table_desc->address, final_table);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300523
Bob Mooref7b004a2012-02-14 18:31:56 +0800524 /* Set the global integer width (based upon revision of the DSDT) */
Bob Mooref3d2e782007-02-02 19:48:18 +0300525
Bob Moorec5fc42a2007-02-02 19:48:19 +0300526 if (table_index == ACPI_TABLE_INDEX_DSDT) {
Bob Mooref7b004a2012-02-14 18:31:56 +0800527 acpi_ut_set_integer_width(final_table->revision);
528 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300529
Bob Mooref7b004a2012-02-14 18:31:56 +0800530 /*
531 * If we have a physical override during this early loading of the ACPI
532 * tables, unmap the table for now. It will be mapped again later when
533 * it is actually used. This supports very early loading of ACPI tables,
534 * before virtual memory is fully initialized and running within the
535 * host OS. Note: A logical override has the ACPI_TABLE_ORIGIN_OVERRIDE
536 * flag set and will not be deleted below.
537 */
538 if (final_table != table) {
539 acpi_tb_delete_table(table_desc);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300540 }
541
542 unmap_and_exit:
Bob Mooref7b004a2012-02-14 18:31:56 +0800543
544 /* Always unmap the table header that we mapped above */
545
546 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300547}
548
549/*******************************************************************************
550 *
Bob Moorea4bbb8102007-02-02 19:48:19 +0300551 * FUNCTION: acpi_tb_get_root_table_entry
552 *
553 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
554 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
555 *
556 * RETURN: Physical address extracted from the root table
557 *
558 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
559 * both 32-bit and 64-bit platforms
560 *
561 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
562 * 64-bit platforms.
563 *
564 ******************************************************************************/
565
566static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +0800567acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
Bob Moorea4bbb8102007-02-02 19:48:19 +0300568{
569 u64 address64;
570
571 /*
572 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
573 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
574 */
575 if (table_entry_size == sizeof(u32)) {
576 /*
577 * 32-bit platform, RSDT: Return 32-bit table entry
578 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
579 */
580 return ((acpi_physical_address)
581 (*ACPI_CAST_PTR(u32, table_entry)));
582 } else {
583 /*
584 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
Bob Mooreec41f192009-02-18 15:03:30 +0800585 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
586 * return 64-bit
Bob Moorea4bbb8102007-02-02 19:48:19 +0300587 */
588 ACPI_MOVE_64_TO_64(&address64, table_entry);
589
590#if ACPI_MACHINE_WIDTH == 32
591 if (address64 > ACPI_UINT32_MAX) {
592
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300593 /* Will truncate 64-bit address to 32 bits, issue warning */
Bob Moorea4bbb8102007-02-02 19:48:19 +0300594
Bob Moore3b3ea772012-07-16 09:39:54 +0800595 ACPI_BIOS_WARNING((AE_INFO,
596 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
597 " truncating",
598 ACPI_FORMAT_UINT64(address64)));
Bob Moorea4bbb8102007-02-02 19:48:19 +0300599 }
600#endif
601 return ((acpi_physical_address) (address64));
602 }
603}
604
605/*******************************************************************************
606 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300607 * FUNCTION: acpi_tb_parse_root_table
608 *
609 * PARAMETERS: Rsdp - Pointer to the RSDP
Bob Mooref3d2e782007-02-02 19:48:18 +0300610 *
611 * RETURN: Status
612 *
613 * DESCRIPTION: This function is called to parse the Root System Description
614 * Table (RSDT or XSDT)
615 *
616 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
617 * be mapped and cannot be copied because it contains the actual
618 * memory location of the ACPI Global Lock.
619 *
620 ******************************************************************************/
621
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300622acpi_status __init
Bob Moore97cbb7d2009-02-03 14:41:03 +0800623acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300624{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300625 struct acpi_table_rsdp *rsdp;
Bob Moore67a119f2008-06-10 13:42:13 +0800626 u32 table_entry_size;
627 u32 i;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300628 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300629 struct acpi_table_header *table;
630 acpi_physical_address address;
Andrew Morton8ab73672007-10-02 13:24:10 -0700631 acpi_physical_address uninitialized_var(rsdt_address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300632 u32 length;
633 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300634 acpi_status status;
635
636 ACPI_FUNCTION_TRACE(tb_parse_root_table);
637
Bob Moorec5fc42a2007-02-02 19:48:19 +0300638 /*
639 * Map the entire RSDP and extract the address of the RSDT or XSDT
640 */
641 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
642 if (!rsdp) {
643 return_ACPI_STATUS(AE_NO_MEMORY);
644 }
645
646 acpi_tb_print_table_header(rsdp_address,
647 ACPI_CAST_PTR(struct acpi_table_header,
648 rsdp));
649
Bob Mooref3d2e782007-02-02 19:48:18 +0300650 /* Differentiate between RSDT and XSDT root tables */
651
Zhao Yakui237889b2008-12-17 16:55:18 +0800652 if (rsdp->revision > 1 && rsdp->xsdt_physical_address
653 && !acpi_rsdt_forced) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800654 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300655 * Root table is an XSDT (64-bit physical addresses). We must use the
656 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
657 * the ACPI specification.
Bob Moorea18ecf42005-08-15 03:42:00 -0800658 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300659 address = (acpi_physical_address) rsdp->xsdt_physical_address;
660 table_entry_size = sizeof(u64);
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800661 rsdt_address = (acpi_physical_address)
662 rsdp->rsdt_physical_address;
Bob Mooref3d2e782007-02-02 19:48:18 +0300663 } else {
664 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400665
Bob Moorec5fc42a2007-02-02 19:48:19 +0300666 address = (acpi_physical_address) rsdp->rsdt_physical_address;
667 table_entry_size = sizeof(u32);
Bob Mooref3d2e782007-02-02 19:48:18 +0300668 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700669
Bob Moorec5fc42a2007-02-02 19:48:19 +0300670 /*
671 * It is not possible to map more than one entry in some environments,
672 * so unmap the RSDP here before mapping other tables
673 */
674 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
675
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800676 if (table_entry_size == sizeof(u64)) {
677 if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) {
678 /* XSDT has NULL entry, RSDT is used */
679 address = rsdt_address;
680 table_entry_size = sizeof(u32);
Joe Perches4fdb2a02007-11-19 17:48:02 -0800681 ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800682 "using RSDT"));
683 }
684 }
Bob Moorec5fc42a2007-02-02 19:48:19 +0300685 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700686
Bob Mooref3d2e782007-02-02 19:48:18 +0300687 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
688 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300689 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300690 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700691
Bob Moorec5fc42a2007-02-02 19:48:19 +0300692 acpi_tb_print_table_header(address, table);
693
Bob Mooref3d2e782007-02-02 19:48:18 +0300694 /* Get the length of the full table, verify length and map entire table */
695
696 length = table->length;
697 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
698
699 if (length < sizeof(struct acpi_table_header)) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800700 ACPI_BIOS_ERROR((AE_INFO,
701 "Invalid table length 0x%X in RSDT/XSDT",
702 length));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300703 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300704 }
705
706 table = acpi_os_map_memory(address, length);
707 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300708 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300709 }
710
711 /* Validate the root table checksum */
712
Bob Moorec5fc42a2007-02-02 19:48:19 +0300713 status = acpi_tb_verify_checksum(table, length);
714 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300715 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300716 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300717 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300718
719 /* Calculate the number of tables described in the root table */
720
Bob Mooreec41f192009-02-18 15:03:30 +0800721 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
722 table_entry_size);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300723 /*
Bob Mooreec41f192009-02-18 15:03:30 +0800724 * First two entries in the table array are reserved for the DSDT
725 * and FACS, which are not actually present in the RSDT/XSDT - they
726 * come from the FADT
Bob Moorec5fc42a2007-02-02 19:48:19 +0300727 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300728 table_entry =
729 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800730 acpi_gbl_root_table_list.current_table_count = 2;
Bob Mooref3d2e782007-02-02 19:48:18 +0300731
732 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300733 * Initialize the root table array from the RSDT/XSDT
Bob Mooref3d2e782007-02-02 19:48:18 +0300734 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300735 for (i = 0; i < table_count; i++) {
Bob Mooreb9ee2042010-04-27 11:16:14 +0800736 if (acpi_gbl_root_table_list.current_table_count >=
737 acpi_gbl_root_table_list.max_table_count) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300738
739 /* There is no more room in the root table array, attempt resize */
740
Bob Mooref3d2e782007-02-02 19:48:18 +0300741 status = acpi_tb_resize_root_table_list();
742 if (ACPI_FAILURE(status)) {
743 ACPI_WARNING((AE_INFO,
744 "Truncating %u table entries!",
Myron Stowe386e4a82009-01-30 15:44:53 -0700745 (unsigned) (table_count -
746 (acpi_gbl_root_table_list.
Bob Mooreb9ee2042010-04-27 11:16:14 +0800747 current_table_count -
748 2))));
Bob Mooref3d2e782007-02-02 19:48:18 +0300749 break;
750 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700751 }
752
Bob Moorea4bbb8102007-02-02 19:48:19 +0300753 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
754
Bob Mooreb9ee2042010-04-27 11:16:14 +0800755 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
756 current_table_count].address =
Bob Moorea4bbb8102007-02-02 19:48:19 +0300757 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
Bob Mooref3d2e782007-02-02 19:48:18 +0300758
Bob Moorec5fc42a2007-02-02 19:48:19 +0300759 table_entry += table_entry_size;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800760 acpi_gbl_root_table_list.current_table_count++;
Bob Mooref3d2e782007-02-02 19:48:18 +0300761 }
762
763 /*
764 * It is not possible to map more than one entry in some environments,
765 * so unmap the root table here before mapping other tables
766 */
767 acpi_os_unmap_memory(table, length);
768
Bob Moorec5fc42a2007-02-02 19:48:19 +0300769 /*
770 * Complete the initialization of the root table array by examining
771 * the header of each table
772 */
Bob Mooreb9ee2042010-04-27 11:16:14 +0800773 for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300774 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
Bob Moore97cbb7d2009-02-03 14:41:03 +0800775 address, NULL, i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300776
Bob Moorec5fc42a2007-02-02 19:48:19 +0300777 /* Special case for FADT - get the DSDT and FACS */
Bob Mooref3d2e782007-02-02 19:48:18 +0300778
Bob Moorec5fc42a2007-02-02 19:48:19 +0300779 if (ACPI_COMPARE_NAME
780 (&acpi_gbl_root_table_list.tables[i].signature,
781 ACPI_SIG_FADT)) {
Bob Moore97cbb7d2009-02-03 14:41:03 +0800782 acpi_tb_parse_fadt(i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300783 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700784 }
785
Len Brown4be44fc2005-08-05 00:44:28 -0400786 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700787}