blob: 51eb07cf989844842b6dce634a589d1e7440e154 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
Bob Moore42f47862013-06-08 00:59:02 +00003 * Module Name: tbutils - ACPI Table utilities
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, 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 Moorea4bbb812007-02-02 19:48:19 +030052static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +080053acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
54
Bob Moore33620c52012-02-14 18:14:27 +080055#if (!ACPI_REDUCED_HARDWARE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*******************************************************************************
57 *
Bob Moore009c4cbe2008-11-12 15:34:52 +080058 * FUNCTION: acpi_tb_initialize_facs
59 *
60 * PARAMETERS: None
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
65 * for accessing the Global Lock and Firmware Waking Vector
66 *
67 ******************************************************************************/
68
69acpi_status acpi_tb_initialize_facs(void)
70{
Lv Zheng74846192015-08-25 10:29:08 +080071 struct acpi_table_facs *facs;
Bob Moore009c4cbe2008-11-12 15:34:52 +080072
Bob Moore22e5b402011-11-16 10:57:28 +080073 /* If Hardware Reduced flag is set, there is no FACS */
74
75 if (acpi_gbl_reduced_hardware) {
76 acpi_gbl_FACS = NULL;
77 return (AE_OK);
Lv Zheng8ec3f452015-08-25 10:29:01 +080078 } else if (acpi_gbl_FADT.Xfacs &&
79 (!acpi_gbl_FADT.facs
80 || !acpi_gbl_use32_bit_facs_addresses)) {
81 (void)acpi_get_table_by_index(acpi_gbl_xfacs_index,
82 ACPI_CAST_INDIRECT_PTR(struct
83 acpi_table_header,
Lv Zheng74846192015-08-25 10:29:08 +080084 &facs));
85 acpi_gbl_FACS = facs;
Lv Zheng8ec3f452015-08-25 10:29:01 +080086 } else if (acpi_gbl_FADT.facs) {
87 (void)acpi_get_table_by_index(acpi_gbl_facs_index,
88 ACPI_CAST_INDIRECT_PTR(struct
89 acpi_table_header,
Lv Zheng74846192015-08-25 10:29:08 +080090 &facs));
91 acpi_gbl_FACS = facs;
Lv Zhengc04e1fb2015-07-01 14:43:11 +080092 }
93
Lv Zhengf06147f2015-07-01 14:43:18 +080094 /* If there is no FACS, just continue. There was already an error msg */
95
Lv Zhengc04e1fb2015-07-01 14:43:11 +080096 return (AE_OK);
Bob Moore009c4cbe2008-11-12 15:34:52 +080097}
Bob Moore33620c52012-02-14 18:14:27 +080098#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore009c4cbe2008-11-12 15:34:52 +080099
100/*******************************************************************************
101 *
Lin Ming729df0f2010-04-01 10:47:56 +0800102 * FUNCTION: acpi_tb_check_dsdt_header
103 *
104 * PARAMETERS: None
105 *
106 * RETURN: None
107 *
108 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
109 * if the DSDT has been replaced from outside the OS and/or if
110 * the DSDT header has been corrupted.
111 *
112 ******************************************************************************/
113
114void acpi_tb_check_dsdt_header(void)
115{
116
117 /* Compare original length and checksum to current values */
118
Bob Moore43323cb2010-04-07 11:05:11 +0800119 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
120 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800121 ACPI_BIOS_ERROR((AE_INFO,
122 "The DSDT has been corrupted or replaced - "
123 "old, new headers below"));
Bob Moore1fad8732015-12-29 13:54:36 +0800124
Lin Ming729df0f2010-04-01 10:47:56 +0800125 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
Bob Moore43323cb2010-04-07 11:05:11 +0800126 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
Lin Ming729df0f2010-04-01 10:47:56 +0800127
Lin Mingaa2110c2010-04-08 14:34:27 +0800128 ACPI_ERROR((AE_INFO,
129 "Please send DMI info to linux-acpi@vger.kernel.org\n"
130 "If system does not work as expected, please boot with acpi=copy_dsdt"));
131
Lin Ming729df0f2010-04-01 10:47:56 +0800132 /* Disable further error messages */
133
Bob Moore43323cb2010-04-07 11:05:11 +0800134 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
Lin Ming729df0f2010-04-01 10:47:56 +0800135 acpi_gbl_original_dsdt_header.checksum =
Bob Moore43323cb2010-04-07 11:05:11 +0800136 acpi_gbl_DSDT->checksum;
Lin Ming729df0f2010-04-01 10:47:56 +0800137 }
138}
139
140/*******************************************************************************
141 *
Lin Ming69ec87e2010-04-01 11:14:12 +0800142 * FUNCTION: acpi_tb_copy_dsdt
143 *
144 * PARAMETERS: table_desc - Installed table to copy
145 *
146 * RETURN: None
147 *
148 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
149 * Some very bad BIOSs are known to either corrupt the DSDT or
150 * install a new, bad DSDT. This copy works around the problem.
151 *
152 ******************************************************************************/
153
Bob Moore43323cb2010-04-07 11:05:11 +0800154struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
Lin Ming69ec87e2010-04-01 11:14:12 +0800155{
156 struct acpi_table_header *new_table;
Bob Moore43323cb2010-04-07 11:05:11 +0800157 struct acpi_table_desc *table_desc;
158
159 table_desc = &acpi_gbl_root_table_list.tables[table_index];
Lin Ming69ec87e2010-04-01 11:14:12 +0800160
161 new_table = ACPI_ALLOCATE(table_desc->length);
162 if (!new_table) {
163 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
164 table_desc->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800165 return (NULL);
Lin Ming69ec87e2010-04-01 11:14:12 +0800166 }
167
Bob Moore4fa46162015-07-01 14:45:11 +0800168 memcpy(new_table, table_desc->pointer, table_desc->length);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800169 acpi_tb_uninstall_table(table_desc);
Bob Mooreed6f1d42014-04-04 12:39:26 +0800170
171 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
Lv Zheng8ec3f452015-08-25 10:29:01 +0800172 tables[acpi_gbl_dsdt_index],
Bob Mooreed6f1d42014-04-04 12:39:26 +0800173 ACPI_PTR_TO_PHYSADDR(new_table),
174 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
175 new_table);
Lin Ming69ec87e2010-04-01 11:14:12 +0800176
Bob Moore05fb04b2016-02-19 14:16:42 +0800177 ACPI_INFO(("Forced DSDT copy: length 0x%05X copied locally, original unmapped", new_table->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800178
179 return (new_table);
Lin Ming69ec87e2010-04-01 11:14:12 +0800180}
181
182/*******************************************************************************
183 *
Bob Moorea4bbb812007-02-02 19:48:19 +0300184 * FUNCTION: acpi_tb_get_root_table_entry
185 *
186 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
187 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
188 *
189 * RETURN: Physical address extracted from the root table
190 *
191 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
192 * both 32-bit and 64-bit platforms
193 *
194 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
195 * 64-bit platforms.
196 *
197 ******************************************************************************/
198
199static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +0800200acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
Bob Moorea4bbb812007-02-02 19:48:19 +0300201{
202 u64 address64;
203
204 /*
205 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
206 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
207 */
Lv Zheng671cc682014-01-08 13:43:34 +0800208 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
Bob Moorea4bbb812007-02-02 19:48:19 +0300209 /*
210 * 32-bit platform, RSDT: Return 32-bit table entry
211 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
212 */
213 return ((acpi_physical_address)
214 (*ACPI_CAST_PTR(u32, table_entry)));
215 } else {
216 /*
217 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
Bob Mooreec41f192009-02-18 15:03:30 +0800218 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
219 * return 64-bit
Bob Moorea4bbb812007-02-02 19:48:19 +0300220 */
221 ACPI_MOVE_64_TO_64(&address64, table_entry);
222
223#if ACPI_MACHINE_WIDTH == 32
224 if (address64 > ACPI_UINT32_MAX) {
225
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300226 /* Will truncate 64-bit address to 32 bits, issue warning */
Bob Moorea4bbb812007-02-02 19:48:19 +0300227
Bob Moore3b3ea772012-07-16 09:39:54 +0800228 ACPI_BIOS_WARNING((AE_INFO,
229 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
230 " truncating",
231 ACPI_FORMAT_UINT64(address64)));
Bob Moorea4bbb812007-02-02 19:48:19 +0300232 }
233#endif
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800234 return ((acpi_physical_address)(address64));
Bob Moorea4bbb812007-02-02 19:48:19 +0300235 }
236}
237
238/*******************************************************************************
239 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300240 * FUNCTION: acpi_tb_parse_root_table
241 *
Bob Mooreba494be2012-07-12 09:40:10 +0800242 * PARAMETERS: rsdp - Pointer to the RSDP
Bob Mooref3d2e782007-02-02 19:48:18 +0300243 *
244 * RETURN: Status
245 *
246 * DESCRIPTION: This function is called to parse the Root System Description
247 * Table (RSDT or XSDT)
248 *
249 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
250 * be mapped and cannot be copied because it contains the actual
251 * memory location of the ACPI Global Lock.
252 *
253 ******************************************************************************/
254
Lv Zheng2368b1a2016-08-04 16:43:19 +0800255acpi_status ACPI_INIT_FUNCTION
256acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300257{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300258 struct acpi_table_rsdp *rsdp;
Bob Moore67a119f2008-06-10 13:42:13 +0800259 u32 table_entry_size;
260 u32 i;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300261 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300262 struct acpi_table_header *table;
263 acpi_physical_address address;
264 u32 length;
265 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300266 acpi_status status;
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800267 u32 table_index;
Bob Mooref3d2e782007-02-02 19:48:18 +0300268
269 ACPI_FUNCTION_TRACE(tb_parse_root_table);
270
Lv Zheng671cc682014-01-08 13:43:34 +0800271 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
272
Bob Moorec5fc42a2007-02-02 19:48:19 +0300273 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
274 if (!rsdp) {
275 return_ACPI_STATUS(AE_NO_MEMORY);
276 }
277
278 acpi_tb_print_table_header(rsdp_address,
279 ACPI_CAST_PTR(struct acpi_table_header,
280 rsdp));
281
Lv Zhengfab46102014-01-08 13:43:40 +0800282 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
Bob Mooref3d2e782007-02-02 19:48:18 +0300283
Lv Zhengfab46102014-01-08 13:43:40 +0800284 if ((rsdp->revision > 1) &&
285 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800286 /*
Lv Zheng671cc682014-01-08 13:43:34 +0800287 * RSDP contains an XSDT (64-bit physical addresses). We must use
288 * the XSDT if the revision is > 1 and the XSDT pointer is present,
289 * as per the ACPI specification.
Bob Moorea18ecf42005-08-15 03:42:00 -0800290 */
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800291 address = (acpi_physical_address)rsdp->xsdt_physical_address;
Lv Zheng671cc682014-01-08 13:43:34 +0800292 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
Bob Mooref3d2e782007-02-02 19:48:18 +0300293 } else {
294 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400295
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800296 address = (acpi_physical_address)rsdp->rsdt_physical_address;
Lv Zheng671cc682014-01-08 13:43:34 +0800297 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
Bob Mooref3d2e782007-02-02 19:48:18 +0300298 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700299
Bob Moorec5fc42a2007-02-02 19:48:19 +0300300 /*
301 * It is not possible to map more than one entry in some environments,
302 * so unmap the RSDP here before mapping other tables
303 */
304 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
305
306 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700307
Bob Mooref3d2e782007-02-02 19:48:18 +0300308 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
309 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300310 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300311 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700312
Bob Moorec5fc42a2007-02-02 19:48:19 +0300313 acpi_tb_print_table_header(address, table);
314
Lv Zheng671cc682014-01-08 13:43:34 +0800315 /*
316 * Validate length of the table, and map entire table.
317 * Minimum length table must contain at least one entry.
318 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300319 length = table->length;
320 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
321
Lv Zheng671cc682014-01-08 13:43:34 +0800322 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800323 ACPI_BIOS_ERROR((AE_INFO,
324 "Invalid table length 0x%X in RSDT/XSDT",
325 length));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300326 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300327 }
328
329 table = acpi_os_map_memory(address, length);
330 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300331 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300332 }
333
334 /* Validate the root table checksum */
335
Bob Moorec5fc42a2007-02-02 19:48:19 +0300336 status = acpi_tb_verify_checksum(table, length);
337 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300338 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300339 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300340 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300341
Lv Zheng671cc682014-01-08 13:43:34 +0800342 /* Get the number of entries and pointer to first entry */
Bob Mooref3d2e782007-02-02 19:48:18 +0300343
Bob Mooreec41f192009-02-18 15:03:30 +0800344 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
345 table_entry_size);
Lv Zheng671cc682014-01-08 13:43:34 +0800346 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
347
Lv Zheng671cc682014-01-08 13:43:34 +0800348 /* Initialize the root table array from the RSDT/XSDT */
349
Bob Moorec5fc42a2007-02-02 19:48:19 +0300350 for (i = 0; i < table_count; i++) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700351
Bob Moorea4bbb812007-02-02 19:48:19 +0300352 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
353
Lv Zheng0f929fb2014-04-30 10:05:56 +0800354 address =
355 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
356
357 /* Skip NULL entries in RSDT/XSDT */
358
359 if (!address) {
360 goto next_table;
361 }
362
363 status = acpi_tb_install_standard_table(address,
364 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
365 FALSE, TRUE,
366 &table_index);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800367
368 if (ACPI_SUCCESS(status) &&
369 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
370 tables[table_index].signature,
371 ACPI_SIG_FADT)) {
Lv Zheng62fcce92015-10-14 13:53:57 +0800372 acpi_gbl_fadt_index = table_index;
373 acpi_tb_parse_fadt();
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800374 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300375
Lv Zheng0f929fb2014-04-30 10:05:56 +0800376next_table:
377
Bob Moorec5fc42a2007-02-02 19:48:19 +0300378 table_entry += table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300379 }
380
Bob Mooref3d2e782007-02-02 19:48:18 +0300381 acpi_os_unmap_memory(table, length);
Len Brown4be44fc2005-08-05 00:44:28 -0400382 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700383}