blob: 6b1ca9991b9049147115992e44c752d97eb1da64 [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 Moorefbb7a2d2014-02-08 09:42:25 +08008 * Copyright (C) 2000 - 2014, 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{
71 acpi_status status;
72
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);
78 }
79
Bob Moore009c4cbe2008-11-12 15:34:52 +080080 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
81 ACPI_CAST_INDIRECT_PTR(struct
82 acpi_table_header,
83 &acpi_gbl_FACS));
Lv Zheng9c0d7932012-12-19 05:37:21 +000084 return (status);
Bob Moore009c4cbe2008-11-12 15:34:52 +080085}
Bob Moore33620c52012-02-14 18:14:27 +080086#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore009c4cbe2008-11-12 15:34:52 +080087
88/*******************************************************************************
89 *
Bob Moorec8573032007-02-02 19:48:23 +030090 * FUNCTION: acpi_tb_tables_loaded
91 *
92 * PARAMETERS: None
93 *
94 * RETURN: TRUE if required ACPI tables are loaded
95 *
96 * DESCRIPTION: Determine if the minimum required ACPI tables are present
97 * (FADT, FACS, DSDT)
98 *
99 ******************************************************************************/
100
101u8 acpi_tb_tables_loaded(void)
102{
103
Bob Mooreb9ee2042010-04-27 11:16:14 +0800104 if (acpi_gbl_root_table_list.current_table_count >= 3) {
Bob Moorec8573032007-02-02 19:48:23 +0300105 return (TRUE);
106 }
107
108 return (FALSE);
109}
110
111/*******************************************************************************
112 *
Lin Ming729df0f2010-04-01 10:47:56 +0800113 * FUNCTION: acpi_tb_check_dsdt_header
114 *
115 * PARAMETERS: None
116 *
117 * RETURN: None
118 *
119 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
120 * if the DSDT has been replaced from outside the OS and/or if
121 * the DSDT header has been corrupted.
122 *
123 ******************************************************************************/
124
125void acpi_tb_check_dsdt_header(void)
126{
127
128 /* Compare original length and checksum to current values */
129
Bob Moore43323cb2010-04-07 11:05:11 +0800130 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
131 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800132 ACPI_BIOS_ERROR((AE_INFO,
133 "The DSDT has been corrupted or replaced - "
134 "old, new headers below"));
Lin Ming729df0f2010-04-01 10:47:56 +0800135 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
Bob Moore43323cb2010-04-07 11:05:11 +0800136 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
Lin Ming729df0f2010-04-01 10:47:56 +0800137
Lin Mingaa2110c2010-04-08 14:34:27 +0800138 ACPI_ERROR((AE_INFO,
139 "Please send DMI info to linux-acpi@vger.kernel.org\n"
140 "If system does not work as expected, please boot with acpi=copy_dsdt"));
141
Lin Ming729df0f2010-04-01 10:47:56 +0800142 /* Disable further error messages */
143
Bob Moore43323cb2010-04-07 11:05:11 +0800144 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
Lin Ming729df0f2010-04-01 10:47:56 +0800145 acpi_gbl_original_dsdt_header.checksum =
Bob Moore43323cb2010-04-07 11:05:11 +0800146 acpi_gbl_DSDT->checksum;
Lin Ming729df0f2010-04-01 10:47:56 +0800147 }
148}
149
150/*******************************************************************************
151 *
Lin Ming69ec87e2010-04-01 11:14:12 +0800152 * FUNCTION: acpi_tb_copy_dsdt
153 *
154 * PARAMETERS: table_desc - Installed table to copy
155 *
156 * RETURN: None
157 *
158 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
159 * Some very bad BIOSs are known to either corrupt the DSDT or
160 * install a new, bad DSDT. This copy works around the problem.
161 *
162 ******************************************************************************/
163
Bob Moore43323cb2010-04-07 11:05:11 +0800164struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
Lin Ming69ec87e2010-04-01 11:14:12 +0800165{
166 struct acpi_table_header *new_table;
Bob Moore43323cb2010-04-07 11:05:11 +0800167 struct acpi_table_desc *table_desc;
168
169 table_desc = &acpi_gbl_root_table_list.tables[table_index];
Lin Ming69ec87e2010-04-01 11:14:12 +0800170
171 new_table = ACPI_ALLOCATE(table_desc->length);
172 if (!new_table) {
173 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
174 table_desc->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800175 return (NULL);
Lin Ming69ec87e2010-04-01 11:14:12 +0800176 }
177
178 ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800179 acpi_tb_uninstall_table(table_desc);
Bob Mooreed6f1d42014-04-04 12:39:26 +0800180
181 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
182 tables[ACPI_TABLE_INDEX_DSDT],
183 ACPI_PTR_TO_PHYSADDR(new_table),
184 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
185 new_table);
Lin Ming69ec87e2010-04-01 11:14:12 +0800186
187 ACPI_INFO((AE_INFO,
188 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
189 new_table->length));
Bob Moore43323cb2010-04-07 11:05:11 +0800190
191 return (new_table);
Lin Ming69ec87e2010-04-01 11:14:12 +0800192}
193
194/*******************************************************************************
195 *
Bob Moorea4bbb812007-02-02 19:48:19 +0300196 * FUNCTION: acpi_tb_get_root_table_entry
197 *
198 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
199 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
200 *
201 * RETURN: Physical address extracted from the root table
202 *
203 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
204 * both 32-bit and 64-bit platforms
205 *
206 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
207 * 64-bit platforms.
208 *
209 ******************************************************************************/
210
211static acpi_physical_address
Bob Moore67a119f2008-06-10 13:42:13 +0800212acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
Bob Moorea4bbb812007-02-02 19:48:19 +0300213{
214 u64 address64;
215
216 /*
217 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
218 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
219 */
Lv Zheng671cc682014-01-08 13:43:34 +0800220 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
Bob Moorea4bbb812007-02-02 19:48:19 +0300221 /*
222 * 32-bit platform, RSDT: Return 32-bit table entry
223 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
224 */
225 return ((acpi_physical_address)
226 (*ACPI_CAST_PTR(u32, table_entry)));
227 } else {
228 /*
229 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
Bob Mooreec41f192009-02-18 15:03:30 +0800230 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
231 * return 64-bit
Bob Moorea4bbb812007-02-02 19:48:19 +0300232 */
233 ACPI_MOVE_64_TO_64(&address64, table_entry);
234
235#if ACPI_MACHINE_WIDTH == 32
236 if (address64 > ACPI_UINT32_MAX) {
237
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300238 /* Will truncate 64-bit address to 32 bits, issue warning */
Bob Moorea4bbb812007-02-02 19:48:19 +0300239
Bob Moore3b3ea772012-07-16 09:39:54 +0800240 ACPI_BIOS_WARNING((AE_INFO,
241 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
242 " truncating",
243 ACPI_FORMAT_UINT64(address64)));
Bob Moorea4bbb812007-02-02 19:48:19 +0300244 }
245#endif
246 return ((acpi_physical_address) (address64));
247 }
248}
249
250/*******************************************************************************
251 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300252 * FUNCTION: acpi_tb_parse_root_table
253 *
Bob Mooreba494be2012-07-12 09:40:10 +0800254 * PARAMETERS: rsdp - Pointer to the RSDP
Bob Mooref3d2e782007-02-02 19:48:18 +0300255 *
256 * RETURN: Status
257 *
258 * DESCRIPTION: This function is called to parse the Root System Description
259 * Table (RSDT or XSDT)
260 *
261 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
262 * be mapped and cannot be copied because it contains the actual
263 * memory location of the ACPI Global Lock.
264 *
265 ******************************************************************************/
266
Lv Zheng45c9f782013-10-31 09:31:24 +0800267acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
Bob Mooref3d2e782007-02-02 19:48:18 +0300268{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300269 struct acpi_table_rsdp *rsdp;
Bob Moore67a119f2008-06-10 13:42:13 +0800270 u32 table_entry_size;
271 u32 i;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300272 u32 table_count;
Bob Mooref3d2e782007-02-02 19:48:18 +0300273 struct acpi_table_header *table;
274 acpi_physical_address address;
275 u32 length;
276 u8 *table_entry;
Bob Mooref3d2e782007-02-02 19:48:18 +0300277 acpi_status status;
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800278 u32 table_index;
Bob Mooref3d2e782007-02-02 19:48:18 +0300279
280 ACPI_FUNCTION_TRACE(tb_parse_root_table);
281
Lv Zheng671cc682014-01-08 13:43:34 +0800282 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
283
Bob Moorec5fc42a2007-02-02 19:48:19 +0300284 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
285 if (!rsdp) {
286 return_ACPI_STATUS(AE_NO_MEMORY);
287 }
288
289 acpi_tb_print_table_header(rsdp_address,
290 ACPI_CAST_PTR(struct acpi_table_header,
291 rsdp));
292
Lv Zhengfab46102014-01-08 13:43:40 +0800293 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
Bob Mooref3d2e782007-02-02 19:48:18 +0300294
Lv Zhengfab46102014-01-08 13:43:40 +0800295 if ((rsdp->revision > 1) &&
296 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
Bob Moorea18ecf42005-08-15 03:42:00 -0800297 /*
Lv Zheng671cc682014-01-08 13:43:34 +0800298 * RSDP contains an XSDT (64-bit physical addresses). We must use
299 * the XSDT if the revision is > 1 and the XSDT pointer is present,
300 * as per the ACPI specification.
Bob Moorea18ecf42005-08-15 03:42:00 -0800301 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300302 address = (acpi_physical_address) rsdp->xsdt_physical_address;
Lv Zheng671cc682014-01-08 13:43:34 +0800303 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
Bob Mooref3d2e782007-02-02 19:48:18 +0300304 } else {
305 /* Root table is an RSDT (32-bit physical addresses) */
Bob Moore52fc0b02006-10-02 00:00:00 -0400306
Bob Moorec5fc42a2007-02-02 19:48:19 +0300307 address = (acpi_physical_address) rsdp->rsdt_physical_address;
Lv Zheng671cc682014-01-08 13:43:34 +0800308 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
Bob Mooref3d2e782007-02-02 19:48:18 +0300309 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700310
Bob Moorec5fc42a2007-02-02 19:48:19 +0300311 /*
312 * It is not possible to map more than one entry in some environments,
313 * so unmap the RSDP here before mapping other tables
314 */
315 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
316
317 /* Map the RSDT/XSDT table header to get the full table length */
Robert Moore0c9938c2005-07-29 15:15:00 -0700318
Bob Mooref3d2e782007-02-02 19:48:18 +0300319 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
320 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300321 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300322 }
Robert Moore0c9938c2005-07-29 15:15:00 -0700323
Bob Moorec5fc42a2007-02-02 19:48:19 +0300324 acpi_tb_print_table_header(address, table);
325
Lv Zheng671cc682014-01-08 13:43:34 +0800326 /*
327 * Validate length of the table, and map entire table.
328 * Minimum length table must contain at least one entry.
329 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300330 length = table->length;
331 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
332
Lv Zheng671cc682014-01-08 13:43:34 +0800333 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800334 ACPI_BIOS_ERROR((AE_INFO,
335 "Invalid table length 0x%X in RSDT/XSDT",
336 length));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300337 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Bob Mooref3d2e782007-02-02 19:48:18 +0300338 }
339
340 table = acpi_os_map_memory(address, length);
341 if (!table) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300342 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Mooref3d2e782007-02-02 19:48:18 +0300343 }
344
345 /* Validate the root table checksum */
346
Bob Moorec5fc42a2007-02-02 19:48:19 +0300347 status = acpi_tb_verify_checksum(table, length);
348 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300349 acpi_os_unmap_memory(table, length);
Bob Moorec5fc42a2007-02-02 19:48:19 +0300350 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300351 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300352
Lv Zheng671cc682014-01-08 13:43:34 +0800353 /* Get the number of entries and pointer to first entry */
Bob Mooref3d2e782007-02-02 19:48:18 +0300354
Bob Mooreec41f192009-02-18 15:03:30 +0800355 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
356 table_entry_size);
Lv Zheng671cc682014-01-08 13:43:34 +0800357 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
358
Bob Moorec5fc42a2007-02-02 19:48:19 +0300359 /*
Bob Mooreec41f192009-02-18 15:03:30 +0800360 * First two entries in the table array are reserved for the DSDT
361 * and FACS, which are not actually present in the RSDT/XSDT - they
362 * come from the FADT
Bob Moorec5fc42a2007-02-02 19:48:19 +0300363 */
Bob Mooreb9ee2042010-04-27 11:16:14 +0800364 acpi_gbl_root_table_list.current_table_count = 2;
Bob Mooref3d2e782007-02-02 19:48:18 +0300365
Lv Zheng671cc682014-01-08 13:43:34 +0800366 /* Initialize the root table array from the RSDT/XSDT */
367
Bob Moorec5fc42a2007-02-02 19:48:19 +0300368 for (i = 0; i < table_count; i++) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700369
Bob Moorea4bbb812007-02-02 19:48:19 +0300370 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
371
Lv Zheng0f929fb2014-04-30 10:05:56 +0800372 address =
373 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
374
375 /* Skip NULL entries in RSDT/XSDT */
376
377 if (!address) {
378 goto next_table;
379 }
380
381 status = acpi_tb_install_standard_table(address,
382 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
383 FALSE, TRUE,
384 &table_index);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800385
386 if (ACPI_SUCCESS(status) &&
387 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
388 tables[table_index].signature,
389 ACPI_SIG_FADT)) {
390 acpi_tb_parse_fadt(table_index);
391 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300392
Lv Zheng0f929fb2014-04-30 10:05:56 +0800393next_table:
394
Bob Moorec5fc42a2007-02-02 19:48:19 +0300395 table_entry += table_entry_size;
Bob Mooref3d2e782007-02-02 19:48:18 +0300396 }
397
Bob Mooref3d2e782007-02-02 19:48:18 +0300398 acpi_os_unmap_memory(table, length);
399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 return_ACPI_STATUS(AE_OK);
Robert Moore0c9938c2005-07-29 15:15:00 -0700401}