blob: 09ca39e143373c7dfeb11efc63f01540e62d3edb [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 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
Bob Moore22e5b402011-11-16 10:57:28 +0800138 /* If Hardware Reduced flag is set, there is no FACS */
139
140 if (acpi_gbl_reduced_hardware) {
141 acpi_gbl_FACS = NULL;
142 return (AE_OK);
143 }
144
Bob Moore009c4cbe2008-11-12 15:34:52 +0800145 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
146 ACPI_CAST_INDIRECT_PTR(struct
147 acpi_table_header,
148 &acpi_gbl_FACS));
149 return status;
150}
151
152/*******************************************************************************
153 *
Bob Moorec8573032007-02-02 19:48:23 +0300154 * FUNCTION: acpi_tb_tables_loaded
155 *
156 * PARAMETERS: None
157 *
158 * RETURN: TRUE if required ACPI tables are loaded
159 *
160 * DESCRIPTION: Determine if the minimum required ACPI tables are present
161 * (FADT, FACS, DSDT)
162 *
163 ******************************************************************************/
164
165u8 acpi_tb_tables_loaded(void)
166{
167
Bob Mooreb9ee2042010-04-27 11:16:14 +0800168 if (acpi_gbl_root_table_list.current_table_count >= 3) {
Bob Moorec8573032007-02-02 19:48:23 +0300169 return (TRUE);
170 }
171
172 return (FALSE);
173}
174
175/*******************************************************************************
176 *
Bob Moorecf02cd42009-06-24 11:38:46 +0800177 * FUNCTION: acpi_tb_fix_string
178 *
179 * PARAMETERS: String - String to be repaired
180 * Length - Maximum length
181 *
182 * RETURN: None
183 *
184 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
185 * with a question mark '?'.
186 *
187 ******************************************************************************/
188
189static void acpi_tb_fix_string(char *string, acpi_size length)
190{
191
192 while (length && *string) {
193 if (!ACPI_IS_PRINT(*string)) {
194 *string = '?';
195 }
196 string++;
197 length--;
198 }
199}
200
201/*******************************************************************************
202 *
203 * FUNCTION: acpi_tb_cleanup_table_header
204 *
205 * PARAMETERS: out_header - Where the cleaned header is returned
206 * Header - Input ACPI table header
207 *
208 * RETURN: Returns the cleaned header in out_header
209 *
210 * DESCRIPTION: Copy the table header and ensure that all "string" fields in
211 * the header consist of printable characters.
212 *
213 ******************************************************************************/
214
215static void
216acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
217 struct acpi_table_header *header)
218{
219
220 ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header));
221
222 acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
223 acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
224 acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
225 acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
226}
227
228/*******************************************************************************
229 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300230 * FUNCTION: acpi_tb_print_table_header
Robert Moore0c9938c2005-07-29 15:15:00 -0700231 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300232 * PARAMETERS: Address - Table physical address
233 * Header - Table header
Robert Moore0c9938c2005-07-29 15:15:00 -0700234 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300235 * RETURN: None
Robert Moore0c9938c2005-07-29 15:15:00 -0700236 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300237 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
Robert Moore0c9938c2005-07-29 15:15:00 -0700238 *
239 ******************************************************************************/
240
Bob Mooref3d2e782007-02-02 19:48:18 +0300241void
242acpi_tb_print_table_header(acpi_physical_address address,
243 struct acpi_table_header *header)
Robert Moore0c9938c2005-07-29 15:15:00 -0700244{
Bob Moorecf02cd42009-06-24 11:38:46 +0800245 struct acpi_table_header local_header;
Robert Moore0c9938c2005-07-29 15:15:00 -0700246
Bob Mooreb6bc3422009-02-23 10:26:19 +0800247 /*
248 * The reason that the Address is cast to a void pointer is so that we
249 * can use %p which will work properly on both 32-bit and 64-bit hosts.
250 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300251 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
252
Bob Mooreb6bc3422009-02-23 10:26:19 +0800253 /* FACS only has signature and length fields */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300254
Bob Mooreb6bc3422009-02-23 10:26:19 +0800255 ACPI_INFO((AE_INFO, "%4.4s %p %05X",
256 header->signature, ACPI_CAST_PTR(void, address),
Bob Moorec5fc42a2007-02-02 19:48:19 +0300257 header->length));
258 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
259
260 /* RSDP has no common fields */
261
Bob Moorecf02cd42009-06-24 11:38:46 +0800262 ACPI_MEMCPY(local_header.oem_id,
263 ACPI_CAST_PTR(struct acpi_table_rsdp,
264 header)->oem_id, ACPI_OEM_ID_SIZE);
265 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
266
Bob Mooreb6bc3422009-02-23 10:26:19 +0800267 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
268 ACPI_CAST_PTR (void, address),
Bob Moorea4bbb812007-02-02 19:48:19 +0300269 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
270 revision >
271 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
272 header)->length : 20,
273 ACPI_CAST_PTR(struct acpi_table_rsdp,
274 header)->revision,
Bob Moorecf02cd42009-06-24 11:38:46 +0800275 local_header.oem_id));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300276 } else {
Bob Moore4bf27392007-02-02 19:48:19 +0300277 /* Standard ACPI table with full common header */
278
Bob Moorecf02cd42009-06-24 11:38:46 +0800279 acpi_tb_cleanup_table_header(&local_header, header);
280
Bob Moorec5fc42a2007-02-02 19:48:19 +0300281 ACPI_INFO((AE_INFO,
Bob Mooreb6bc3422009-02-23 10:26:19 +0800282 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
Bob Moorecf02cd42009-06-24 11:38:46 +0800283 local_header.signature, ACPI_CAST_PTR(void, address),
284 local_header.length, local_header.revision,
285 local_header.oem_id, local_header.oem_table_id,
286 local_header.oem_revision,
287 local_header.asl_compiler_id,
288 local_header.asl_compiler_revision));
289
Bob Moorec5fc42a2007-02-02 19:48:19 +0300290 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300291}
Robert Moore0c9938c2005-07-29 15:15:00 -0700292
Bob Mooref3d2e782007-02-02 19:48:18 +0300293/*******************************************************************************
294 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300295 * FUNCTION: acpi_tb_validate_checksum
296 *
297 * PARAMETERS: Table - ACPI table to verify
298 * Length - Length of entire table
299 *
300 * RETURN: Status
301 *
302 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
303 * exception on bad checksum.
304 *
305 ******************************************************************************/
306
307acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
308{
309 u8 checksum;
310
311 /* Compute the checksum on the table */
312
313 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
314
315 /* Checksum ok? (should be zero) */
316
317 if (checksum) {
318 ACPI_WARNING((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800319 "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X",
Bob Moorec5fc42a2007-02-02 19:48:19 +0300320 table->signature, table->checksum,
321 (u8) (table->checksum - checksum)));
322
323#if (ACPI_CHECKSUM_ABORT)
324
325 return (AE_BAD_CHECKSUM);
326#endif
327 }
328
329 return (AE_OK);
330}
331
332/*******************************************************************************
333 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300334 * FUNCTION: acpi_tb_checksum
335 *
336 * PARAMETERS: Buffer - Pointer to memory region to be checked
337 * Length - Length of this memory region
338 *
339 * RETURN: Checksum (u8)
340 *
341 * DESCRIPTION: Calculates circular checksum of memory region.
342 *
343 ******************************************************************************/
344
Bob Moore67a119f2008-06-10 13:42:13 +0800345u8 acpi_tb_checksum(u8 *buffer, u32 length)
Bob Mooref3d2e782007-02-02 19:48:18 +0300346{
347 u8 sum = 0;
348 u8 *end = buffer + length;
349
350 while (buffer < end) {
351 sum = (u8) (sum + *(buffer++));
352 }
353
354 return sum;
355}
356
357/*******************************************************************************
358 *
Lin Ming729df0f2010-04-01 10:47:56 +0800359 * FUNCTION: acpi_tb_check_dsdt_header
360 *
361 * PARAMETERS: None
362 *
363 * RETURN: None
364 *
365 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
366 * if the DSDT has been replaced from outside the OS and/or if
367 * the DSDT header has been corrupted.
368 *
369 ******************************************************************************/
370
371void acpi_tb_check_dsdt_header(void)
372{
373
374 /* Compare original length and checksum to current values */
375
Bob Moore43323cb2010-04-07 11:05:11 +0800376 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
377 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
Lin Ming729df0f2010-04-01 10:47:56 +0800378 ACPI_ERROR((AE_INFO,
379 "The DSDT has been corrupted or replaced - old, new headers below"));
380 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
Bob Moore43323cb2010-04-07 11:05:11 +0800381 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
Lin Ming729df0f2010-04-01 10:47:56 +0800382
Lin Mingaa2110c2010-04-08 14:34:27 +0800383 ACPI_ERROR((AE_INFO,
384 "Please send DMI info to linux-acpi@vger.kernel.org\n"
385 "If system does not work as expected, please boot with acpi=copy_dsdt"));
386
Lin Ming729df0f2010-04-01 10:47:56 +0800387 /* Disable further error messages */
388
Bob Moore43323cb2010-04-07 11:05:11 +0800389 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
Lin Ming729df0f2010-04-01 10:47:56 +0800390 acpi_gbl_original_dsdt_header.checksum =
Bob Moore43323cb2010-04-07 11:05:11 +0800391 acpi_gbl_DSDT->checksum;
Lin Ming729df0f2010-04-01 10:47:56 +0800392 }
393}
394
395/*******************************************************************************
396 *
Lin Ming69ec87e2010-04-01 11:14:12 +0800397 * FUNCTION: acpi_tb_copy_dsdt
398 *
399 * PARAMETERS: table_desc - Installed table to copy
400 *
401 * RETURN: None
402 *
403 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
404 * Some very bad BIOSs are known to either corrupt the DSDT or
405 * install a new, bad DSDT. This copy works around the problem.
406 *
407 ******************************************************************************/
408
Bob Moore43323cb2010-04-07 11:05:11 +0800409struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
Lin Ming69ec87e2010-04-01 11:14:12 +0800410{
411 struct acpi_table_header *new_table;
Bob Moore43323cb2010-04-07 11:05:11 +0800412 struct acpi_table_desc *table_desc;
413
414 table_desc = &acpi_gbl_root_table_list.tables[table_index];
Lin Ming69ec87e2010-04-01 11:14:12 +0800415
416 new_table = ACPI_ALLOCATE(table_desc->length);
417 if (!new_table) {
418 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
419 table_desc->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800420 return (NULL);
Lin Ming69ec87e2010-04-01 11:14:12 +0800421 }
422
423 ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
424 acpi_tb_delete_table(table_desc);
425 table_desc->pointer = new_table;
426 table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED;
427
428 ACPI_INFO((AE_INFO,
429 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
430 new_table->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800431
432 return (new_table);
Lin Ming69ec87e2010-04-01 11:14:12 +0800433}
434
435/*******************************************************************************
436 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300437 * FUNCTION: acpi_tb_install_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300438 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300439 * PARAMETERS: Address - Physical address of DSDT or FACS
Bob Moorec5fc42a2007-02-02 19:48:19 +0300440 * Signature - Table signature, NULL if no need to
441 * match
442 * table_index - Index into root table array
Bob Mooref3d2e782007-02-02 19:48:18 +0300443 *
Bob Moorec5fc42a2007-02-02 19:48:19 +0300444 * RETURN: None
Bob Mooref3d2e782007-02-02 19:48:18 +0300445 *
Bob Mooreac5f98d2009-02-03 14:35:25 +0800446 * DESCRIPTION: Install an ACPI table into the global data structure. The
447 * table override mechanism is implemented here to allow the host
448 * OS to replace any table before it is installed in the root
449 * table array.
Bob Mooref3d2e782007-02-02 19:48:18 +0300450 *
451 ******************************************************************************/
452
Bob Moore765ec202007-02-02 19:48:20 +0300453void
Bob Moorec5fc42a2007-02-02 19:48:19 +0300454acpi_tb_install_table(acpi_physical_address address,
Bob Moore97cbb7d2009-02-03 14:41:03 +0800455 char *signature, u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300456{
Bob Moore97cbb7d2009-02-03 14:41:03 +0800457 u8 flags;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800458 acpi_status status;
459 struct acpi_table_header *table_to_install;
460 struct acpi_table_header *mapped_table;
461 struct acpi_table_header *override_table = NULL;
Bob Mooref3d2e782007-02-02 19:48:18 +0300462
Bob Moorec5fc42a2007-02-02 19:48:19 +0300463 if (!address) {
464 ACPI_ERROR((AE_INFO,
465 "Null physical address for ACPI table [%s]",
466 signature));
Bob Mooref3d2e782007-02-02 19:48:18 +0300467 return;
468 }
469
Bob Moorec5fc42a2007-02-02 19:48:19 +0300470 /* Map just the table header */
471
Bob Mooreac5f98d2009-02-03 14:35:25 +0800472 mapped_table =
473 acpi_os_map_memory(address, sizeof(struct acpi_table_header));
474 if (!mapped_table) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300475 return;
476 }
477
Bob Mooreac5f98d2009-02-03 14:35:25 +0800478 /* If a particular signature is expected (DSDT/FACS), it must match */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300479
Bob Mooreac5f98d2009-02-03 14:35:25 +0800480 if (signature && !ACPI_COMPARE_NAME(mapped_table->signature, signature)) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300481 ACPI_ERROR((AE_INFO,
Bob Mooreac5f98d2009-02-03 14:35:25 +0800482 "Invalid signature 0x%X for ACPI table, expected [%s]",
483 *ACPI_CAST_PTR(u32, mapped_table->signature),
484 signature));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300485 goto unmap_and_exit;
486 }
487
Bob Mooreac5f98d2009-02-03 14:35:25 +0800488 /*
489 * ACPI Table Override:
490 *
491 * Before we install the table, let the host OS override it with a new
492 * one if desired. Any table within the RSDT/XSDT can be replaced,
493 * including the DSDT which is pointed to by the FADT.
494 */
495 status = acpi_os_table_override(mapped_table, &override_table);
496 if (ACPI_SUCCESS(status) && override_table) {
497 ACPI_INFO((AE_INFO,
498 "%4.4s @ 0x%p Table override, replaced with:",
499 mapped_table->signature, ACPI_CAST_PTR(void,
500 address)));
501
502 acpi_gbl_root_table_list.tables[table_index].pointer =
503 override_table;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800504 address = ACPI_PTR_TO_PHYSADDR(override_table);
505
506 table_to_install = override_table;
Bob Moore97cbb7d2009-02-03 14:41:03 +0800507 flags = ACPI_TABLE_ORIGIN_OVERRIDE;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800508 } else {
509 table_to_install = mapped_table;
Bob Moore97cbb7d2009-02-03 14:41:03 +0800510 flags = ACPI_TABLE_ORIGIN_MAPPED;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800511 }
512
Bob Moorec5fc42a2007-02-02 19:48:19 +0300513 /* Initialize the table entry */
514
515 acpi_gbl_root_table_list.tables[table_index].address = address;
Bob Mooreac5f98d2009-02-03 14:35:25 +0800516 acpi_gbl_root_table_list.tables[table_index].length =
517 table_to_install->length;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300518 acpi_gbl_root_table_list.tables[table_index].flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300519
520 ACPI_MOVE_32_TO_32(&
Bob Moorec5fc42a2007-02-02 19:48:19 +0300521 (acpi_gbl_root_table_list.tables[table_index].
Bob Mooreac5f98d2009-02-03 14:35:25 +0800522 signature), table_to_install->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300523
Bob Mooreac5f98d2009-02-03 14:35:25 +0800524 acpi_tb_print_table_header(address, table_to_install);
Bob Mooref3d2e782007-02-02 19:48:18 +0300525
Bob Moorec5fc42a2007-02-02 19:48:19 +0300526 if (table_index == ACPI_TABLE_INDEX_DSDT) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300527
Bob Moorec5fc42a2007-02-02 19:48:19 +0300528 /* Global integer width is based upon revision of the DSDT */
529
Bob Mooreac5f98d2009-02-03 14:35:25 +0800530 acpi_ut_set_integer_width(table_to_install->revision);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300531 }
532
533 unmap_and_exit:
Bob Mooreac5f98d2009-02-03 14:35:25 +0800534 acpi_os_unmap_memory(mapped_table, sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300535}
536
537/*******************************************************************************
538 *
Bob Moorea4bbb812007-02-02 19:48:19 +0300539 * FUNCTION: acpi_tb_get_root_table_entry
540 *
541 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
542 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
543 *
544 * RETURN: Physical address extracted from the root table
545 *
546 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
547 * both 32-bit and 64-bit platforms
548 *
549 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
550 * 64-bit platforms.
551 *
552 ******************************************************************************/
553
554static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +0800555acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
Bob Moorea4bbb812007-02-02 19:48:19 +0300556{
557 u64 address64;
558
559 /*
560 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
561 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
562 */
563 if (table_entry_size == sizeof(u32)) {
564 /*
565 * 32-bit platform, RSDT: Return 32-bit table entry
566 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
567 */
568 return ((acpi_physical_address)
569 (*ACPI_CAST_PTR(u32, table_entry)));
570 } else {
571 /*
572 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
Bob Mooreec41f192009-02-18 15:03:30 +0800573 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
574 * return 64-bit
Bob Moorea4bbb812007-02-02 19:48:19 +0300575 */
576 ACPI_MOVE_64_TO_64(&address64, table_entry);
577
578#if ACPI_MACHINE_WIDTH == 32
579 if (address64 > ACPI_UINT32_MAX) {
580
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300581 /* Will truncate 64-bit address to 32 bits, issue warning */
Bob Moorea4bbb812007-02-02 19:48:19 +0300582
583 ACPI_WARNING((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800584 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
Bob Mooreec41f192009-02-18 15:03:30 +0800585 " truncating",
Bob Moorea4bbb812007-02-02 19:48:19 +0300586 ACPI_FORMAT_UINT64(address64)));
587 }
588#endif
589 return ((acpi_physical_address) (address64));
590 }
591}
592
593/*******************************************************************************
594 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300595 * FUNCTION: acpi_tb_parse_root_table
596 *
597 * PARAMETERS: Rsdp - Pointer to the RSDP
Bob Mooref3d2e782007-02-02 19:48:18 +0300598 *
599 * RETURN: Status
600 *
601 * DESCRIPTION: This function is called to parse the Root System Description
602 * Table (RSDT or XSDT)
603 *
604 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
605 * be mapped and cannot be copied because it contains the actual
606 * memory location of the ACPI Global Lock.
607 *
608 ******************************************************************************/
609
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300610acpi_status __init
Bob Moore97cbb7d2009-02-03 14:41:03 +0800611acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300612{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300613 struct acpi_table_rsdp *rsdp;
Bob Moore67a119f2008-06-10 13:42:13 +0800614 u32 table_entry_size;
615 u32 i;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300616 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300617 struct acpi_table_header *table;
618 acpi_physical_address address;
Andrew Morton8ab73672007-10-02 13:24:10 -0700619 acpi_physical_address uninitialized_var(rsdt_address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300620 u32 length;
621 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300622 acpi_status status;
623
624 ACPI_FUNCTION_TRACE(tb_parse_root_table);
625
Bob Moorec5fc42a2007-02-02 19:48:19 +0300626 /*
627 * Map the entire RSDP and extract the address of the RSDT or XSDT
628 */
629 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
630 if (!rsdp) {
631 return_ACPI_STATUS(AE_NO_MEMORY);
632 }
633
634 acpi_tb_print_table_header(rsdp_address,
635 ACPI_CAST_PTR(struct acpi_table_header,
636 rsdp));
637
Bob Mooref3d2e782007-02-02 19:48:18 +0300638 /* Differentiate between RSDT and XSDT root tables */
639
Zhao Yakui237889b2008-12-17 16:55:18 +0800640 if (rsdp->revision > 1 && rsdp->xsdt_physical_address
641 && !acpi_rsdt_forced) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800642 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300643 * Root table is an XSDT (64-bit physical addresses). We must use the
644 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
645 * the ACPI specification.
Bob Moorea18ecf42005-08-15 03:42:00 -0800646 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300647 address = (acpi_physical_address) rsdp->xsdt_physical_address;
648 table_entry_size = sizeof(u64);
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800649 rsdt_address = (acpi_physical_address)
650 rsdp->rsdt_physical_address;
Bob Mooref3d2e782007-02-02 19:48:18 +0300651 } else {
652 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400653
Bob Moorec5fc42a2007-02-02 19:48:19 +0300654 address = (acpi_physical_address) rsdp->rsdt_physical_address;
655 table_entry_size = sizeof(u32);
Bob Mooref3d2e782007-02-02 19:48:18 +0300656 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700657
Bob Moorec5fc42a2007-02-02 19:48:19 +0300658 /*
659 * It is not possible to map more than one entry in some environments,
660 * so unmap the RSDP here before mapping other tables
661 */
662 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
663
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800664 if (table_entry_size == sizeof(u64)) {
665 if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) {
666 /* XSDT has NULL entry, RSDT is used */
667 address = rsdt_address;
668 table_entry_size = sizeof(u32);
Joe Perches4fdb2a02007-11-19 17:48:02 -0800669 ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
Zhao Yakui9f3119b2007-08-24 16:18:16 +0800670 "using RSDT"));
671 }
672 }
Bob Moorec5fc42a2007-02-02 19:48:19 +0300673 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700674
Bob Mooref3d2e782007-02-02 19:48:18 +0300675 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
676 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300677 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300678 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700679
Bob Moorec5fc42a2007-02-02 19:48:19 +0300680 acpi_tb_print_table_header(address, table);
681
Bob Mooref3d2e782007-02-02 19:48:18 +0300682 /* Get the length of the full table, verify length and map entire table */
683
684 length = table->length;
685 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
686
687 if (length < sizeof(struct acpi_table_header)) {
688 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
689 length));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300690 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300691 }
692
693 table = acpi_os_map_memory(address, length);
694 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300695 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300696 }
697
698 /* Validate the root table checksum */
699
Bob Moorec5fc42a2007-02-02 19:48:19 +0300700 status = acpi_tb_verify_checksum(table, length);
701 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300702 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300703 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300704 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300705
706 /* Calculate the number of tables described in the root table */
707
Bob Mooreec41f192009-02-18 15:03:30 +0800708 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
709 table_entry_size);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300710 /*
Bob Mooreec41f192009-02-18 15:03:30 +0800711 * First two entries in the table array are reserved for the DSDT
712 * and FACS, which are not actually present in the RSDT/XSDT - they
713 * come from the FADT
Bob Moorec5fc42a2007-02-02 19:48:19 +0300714 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300715 table_entry =
716 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800717 acpi_gbl_root_table_list.current_table_count = 2;
Bob Mooref3d2e782007-02-02 19:48:18 +0300718
719 /*
Bob Moorec5fc42a2007-02-02 19:48:19 +0300720 * Initialize the root table array from the RSDT/XSDT
Bob Mooref3d2e782007-02-02 19:48:18 +0300721 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300722 for (i = 0; i < table_count; i++) {
Bob Mooreb9ee2042010-04-27 11:16:14 +0800723 if (acpi_gbl_root_table_list.current_table_count >=
724 acpi_gbl_root_table_list.max_table_count) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300725
726 /* There is no more room in the root table array, attempt resize */
727
Bob Mooref3d2e782007-02-02 19:48:18 +0300728 status = acpi_tb_resize_root_table_list();
729 if (ACPI_FAILURE(status)) {
730 ACPI_WARNING((AE_INFO,
731 "Truncating %u table entries!",
Myron Stowe386e4a82009-01-30 15:44:53 -0700732 (unsigned) (table_count -
733 (acpi_gbl_root_table_list.
Bob Mooreb9ee2042010-04-27 11:16:14 +0800734 current_table_count -
735 2))));
Bob Mooref3d2e782007-02-02 19:48:18 +0300736 break;
737 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700738 }
739
Bob Moorea4bbb812007-02-02 19:48:19 +0300740 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
741
Bob Mooreb9ee2042010-04-27 11:16:14 +0800742 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
743 current_table_count].address =
Bob Moorea4bbb812007-02-02 19:48:19 +0300744 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
Bob Mooref3d2e782007-02-02 19:48:18 +0300745
Bob Moorec5fc42a2007-02-02 19:48:19 +0300746 table_entry += table_entry_size;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800747 acpi_gbl_root_table_list.current_table_count++;
Bob Mooref3d2e782007-02-02 19:48:18 +0300748 }
749
750 /*
751 * It is not possible to map more than one entry in some environments,
752 * so unmap the root table here before mapping other tables
753 */
754 acpi_os_unmap_memory(table, length);
755
Bob Moorec5fc42a2007-02-02 19:48:19 +0300756 /*
757 * Complete the initialization of the root table array by examining
758 * the header of each table
759 */
Bob Mooreb9ee2042010-04-27 11:16:14 +0800760 for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300761 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
Bob Moore97cbb7d2009-02-03 14:41:03 +0800762 address, NULL, i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300763
Bob Moorec5fc42a2007-02-02 19:48:19 +0300764 /* Special case for FADT - get the DSDT and FACS */
Bob Mooref3d2e782007-02-02 19:48:18 +0300765
Bob Moorec5fc42a2007-02-02 19:48:19 +0300766 if (ACPI_COMPARE_NAME
767 (&acpi_gbl_root_table_list.tables[i].signature,
768 ACPI_SIG_FADT)) {
Bob Moore97cbb7d2009-02-03 14:41:03 +0800769 acpi_tb_parse_fadt(i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300770 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700771 }
772
Len Brown4be44fc2005-08-05 00:44:28 -0400773 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700774}