ACPICA: Update info messages during ACPICA init
[deliverable/linux.git] / drivers / acpi / acpica / tbutils.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
42f47869 3 * Module Name: tbutils - ACPI Table utilities
1da177e4
LT
4 *
5 *****************************************************************************/
6
7/*
82a80941 8 * Copyright (C) 2000 - 2015, Intel Corp.
1da177e4
LT
9 * 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
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "actables.h"
1da177e4 47
1da177e4 48#define _COMPONENT ACPI_TABLES
4be44fcd 49ACPI_MODULE_NAME("tbutils")
1da177e4 50
44f6c012 51/* Local prototypes */
a4bbb810 52static acpi_physical_address
67a119f9
BM
53acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
54
33620c54 55#if (!ACPI_REDUCED_HARDWARE)
009c4cbe
BM
56/*******************************************************************************
57 *
58 * 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{
009c4cbe 71
22e5b40a
BM
72 /* If Hardware Reduced flag is set, there is no FACS */
73
74 if (acpi_gbl_reduced_hardware) {
75 acpi_gbl_FACS = NULL;
76 return (AE_OK);
77 }
78
c04e1fb4
LZ
79 (void)acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
80 ACPI_CAST_INDIRECT_PTR(struct
81 acpi_table_header,
f06147f9 82 &acpi_gbl_facs32));
c04e1fb4
LZ
83 (void)acpi_get_table_by_index(ACPI_TABLE_INDEX_X_FACS,
84 ACPI_CAST_INDIRECT_PTR(struct
85 acpi_table_header,
f06147f9 86 &acpi_gbl_facs64));
c04e1fb4 87
f06147f9
LZ
88 if (acpi_gbl_facs64
89 && (!acpi_gbl_facs32 || !acpi_gbl_use32_bit_facs_addresses)) {
90 acpi_gbl_FACS = acpi_gbl_facs64;
91 } else if (acpi_gbl_facs32) {
92 acpi_gbl_FACS = acpi_gbl_facs32;
c04e1fb4
LZ
93 }
94
f06147f9
LZ
95 /* If there is no FACS, just continue. There was already an error msg */
96
c04e1fb4 97 return (AE_OK);
009c4cbe 98}
33620c54 99#endif /* !ACPI_REDUCED_HARDWARE */
009c4cbe 100
c857303a
BM
101/*******************************************************************************
102 *
103 * FUNCTION: acpi_tb_tables_loaded
104 *
105 * PARAMETERS: None
106 *
107 * RETURN: TRUE if required ACPI tables are loaded
108 *
109 * DESCRIPTION: Determine if the minimum required ACPI tables are present
110 * (FADT, FACS, DSDT)
111 *
112 ******************************************************************************/
113
114u8 acpi_tb_tables_loaded(void)
115{
116
c04e1fb4 117 if (acpi_gbl_root_table_list.current_table_count >= 4) {
c857303a
BM
118 return (TRUE);
119 }
120
121 return (FALSE);
122}
123
729df0f8
LM
124/*******************************************************************************
125 *
126 * FUNCTION: acpi_tb_check_dsdt_header
127 *
128 * PARAMETERS: None
129 *
130 * RETURN: None
131 *
132 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
133 * if the DSDT has been replaced from outside the OS and/or if
134 * the DSDT header has been corrupted.
135 *
136 ******************************************************************************/
137
138void acpi_tb_check_dsdt_header(void)
139{
140
141 /* Compare original length and checksum to current values */
142
43323cb4
BM
143 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
144 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
3b3ea775
BM
145 ACPI_BIOS_ERROR((AE_INFO,
146 "The DSDT has been corrupted or replaced - "
147 "old, new headers below"));
729df0f8 148 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
43323cb4 149 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
729df0f8 150
aa2110cb
LM
151 ACPI_ERROR((AE_INFO,
152 "Please send DMI info to linux-acpi@vger.kernel.org\n"
153 "If system does not work as expected, please boot with acpi=copy_dsdt"));
154
729df0f8
LM
155 /* Disable further error messages */
156
43323cb4 157 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
729df0f8 158 acpi_gbl_original_dsdt_header.checksum =
43323cb4 159 acpi_gbl_DSDT->checksum;
729df0f8
LM
160 }
161}
162
69ec87ef
LM
163/*******************************************************************************
164 *
165 * FUNCTION: acpi_tb_copy_dsdt
166 *
167 * PARAMETERS: table_desc - Installed table to copy
168 *
169 * RETURN: None
170 *
171 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
172 * Some very bad BIOSs are known to either corrupt the DSDT or
173 * install a new, bad DSDT. This copy works around the problem.
174 *
175 ******************************************************************************/
176
43323cb4 177struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
69ec87ef
LM
178{
179 struct acpi_table_header *new_table;
43323cb4
BM
180 struct acpi_table_desc *table_desc;
181
182 table_desc = &acpi_gbl_root_table_list.tables[table_index];
69ec87ef
LM
183
184 new_table = ACPI_ALLOCATE(table_desc->length);
185 if (!new_table) {
186 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
187 table_desc->length));
43323cb4 188 return (NULL);
69ec87ef
LM
189 }
190
4fa4616e 191 memcpy(new_table, table_desc->pointer, table_desc->length);
7f9fc99c 192 acpi_tb_uninstall_table(table_desc);
ed6f1d44
BM
193
194 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
195 tables[ACPI_TABLE_INDEX_DSDT],
196 ACPI_PTR_TO_PHYSADDR(new_table),
197 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
198 new_table);
69ec87ef
LM
199
200 ACPI_INFO((AE_INFO,
201 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
202 new_table->length));
43323cb4
BM
203
204 return (new_table);
69ec87ef
LM
205}
206
a4bbb810
BM
207/*******************************************************************************
208 *
209 * FUNCTION: acpi_tb_get_root_table_entry
210 *
211 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
212 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
213 *
214 * RETURN: Physical address extracted from the root table
215 *
216 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
217 * both 32-bit and 64-bit platforms
218 *
219 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
220 * 64-bit platforms.
221 *
222 ******************************************************************************/
223
224static acpi_physical_address
67a119f9 225acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
a4bbb810
BM
226{
227 u64 address64;
228
229 /*
230 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
231 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
232 */
671cc68d 233 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
a4bbb810
BM
234 /*
235 * 32-bit platform, RSDT: Return 32-bit table entry
236 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
237 */
238 return ((acpi_physical_address)
239 (*ACPI_CAST_PTR(u32, table_entry)));
240 } else {
241 /*
242 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
ec41f193
BM
243 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
244 * return 64-bit
a4bbb810
BM
245 */
246 ACPI_MOVE_64_TO_64(&address64, table_entry);
247
248#if ACPI_MACHINE_WIDTH == 32
249 if (address64 > ACPI_UINT32_MAX) {
250
ea5d8ebc 251 /* Will truncate 64-bit address to 32 bits, issue warning */
a4bbb810 252
3b3ea775
BM
253 ACPI_BIOS_WARNING((AE_INFO,
254 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
255 " truncating",
256 ACPI_FORMAT_UINT64(address64)));
a4bbb810
BM
257 }
258#endif
259 return ((acpi_physical_address) (address64));
260 }
261}
262
793c2388
BM
263/*******************************************************************************
264 *
f3d2e786 265 * FUNCTION: acpi_tb_parse_root_table
793c2388 266 *
ba494bee 267 * PARAMETERS: rsdp - Pointer to the RSDP
f3d2e786
BM
268 *
269 * RETURN: Status
793c2388 270 *
f3d2e786
BM
271 * DESCRIPTION: This function is called to parse the Root System Description
272 * Table (RSDT or XSDT)
793c2388 273 *
f3d2e786
BM
274 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
275 * be mapped and cannot be copied because it contains the actual
276 * memory location of the ACPI Global Lock.
793c2388
BM
277 *
278 ******************************************************************************/
279
45c9f78b 280acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
793c2388 281{
c5fc42ac 282 struct acpi_table_rsdp *rsdp;
67a119f9
BM
283 u32 table_entry_size;
284 u32 i;
c5fc42ac 285 u32 table_count;
f3d2e786
BM
286 struct acpi_table_header *table;
287 acpi_physical_address address;
288 u32 length;
289 u8 *table_entry;
f3d2e786 290 acpi_status status;
86dfc6f3 291 u32 table_index;
f3d2e786
BM
292
293 ACPI_FUNCTION_TRACE(tb_parse_root_table);
294
671cc68d
LZ
295 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
296
c5fc42ac
BM
297 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
298 if (!rsdp) {
299 return_ACPI_STATUS(AE_NO_MEMORY);
300 }
301
302 acpi_tb_print_table_header(rsdp_address,
303 ACPI_CAST_PTR(struct acpi_table_header,
304 rsdp));
305
fab46105 306 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
f3d2e786 307
fab46105
LZ
308 if ((rsdp->revision > 1) &&
309 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
f3d2e786 310 /*
671cc68d
LZ
311 * RSDP contains an XSDT (64-bit physical addresses). We must use
312 * the XSDT if the revision is > 1 and the XSDT pointer is present,
313 * as per the ACPI specification.
f3d2e786 314 */
c5fc42ac 315 address = (acpi_physical_address) rsdp->xsdt_physical_address;
671cc68d 316 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
f3d2e786
BM
317 } else {
318 /* Root table is an RSDT (32-bit physical addresses) */
319
c5fc42ac 320 address = (acpi_physical_address) rsdp->rsdt_physical_address;
671cc68d 321 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
f3d2e786 322 }
793c2388 323
c5fc42ac
BM
324 /*
325 * It is not possible to map more than one entry in some environments,
326 * so unmap the RSDP here before mapping other tables
327 */
328 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
329
330 /* Map the RSDT/XSDT table header to get the full table length */
793c2388 331
f3d2e786
BM
332 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
333 if (!table) {
c5fc42ac 334 return_ACPI_STATUS(AE_NO_MEMORY);
f3d2e786
BM
335 }
336
c5fc42ac
BM
337 acpi_tb_print_table_header(address, table);
338
671cc68d
LZ
339 /*
340 * Validate length of the table, and map entire table.
341 * Minimum length table must contain at least one entry.
342 */
f3d2e786
BM
343 length = table->length;
344 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
345
671cc68d 346 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
3b3ea775
BM
347 ACPI_BIOS_ERROR((AE_INFO,
348 "Invalid table length 0x%X in RSDT/XSDT",
349 length));
c5fc42ac 350 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
f3d2e786
BM
351 }
352
353 table = acpi_os_map_memory(address, length);
354 if (!table) {
c5fc42ac 355 return_ACPI_STATUS(AE_NO_MEMORY);
f3d2e786
BM
356 }
357
358 /* Validate the root table checksum */
359
c5fc42ac
BM
360 status = acpi_tb_verify_checksum(table, length);
361 if (ACPI_FAILURE(status)) {
f3d2e786 362 acpi_os_unmap_memory(table, length);
c5fc42ac 363 return_ACPI_STATUS(status);
f3d2e786 364 }
f3d2e786 365
671cc68d 366 /* Get the number of entries and pointer to first entry */
f3d2e786 367
ec41f193
BM
368 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
369 table_entry_size);
671cc68d
LZ
370 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
371
c5fc42ac 372 /*
c04e1fb4
LZ
373 * First three entries in the table array are reserved for the DSDT
374 * and 32bit/64bit FACS, which are not actually present in the
375 * RSDT/XSDT - they come from the FADT
c5fc42ac 376 */
c04e1fb4 377 acpi_gbl_root_table_list.current_table_count = 3;
1da177e4 378
671cc68d
LZ
379 /* Initialize the root table array from the RSDT/XSDT */
380
c5fc42ac 381 for (i = 0; i < table_count; i++) {
f3d2e786 382
a4bbb810
BM
383 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
384
0f929fbf
LZ
385 address =
386 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
387
388 /* Skip NULL entries in RSDT/XSDT */
389
390 if (!address) {
391 goto next_table;
392 }
393
394 status = acpi_tb_install_standard_table(address,
395 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
396 FALSE, TRUE,
397 &table_index);
86dfc6f3
LZ
398
399 if (ACPI_SUCCESS(status) &&
400 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
401 tables[table_index].signature,
402 ACPI_SIG_FADT)) {
403 acpi_tb_parse_fadt(table_index);
404 }
f3d2e786 405
0f929fbf
LZ
406next_table:
407
c5fc42ac 408 table_entry += table_entry_size;
1da177e4 409 }
793c2388 410
f3d2e786
BM
411 acpi_os_unmap_memory(table, length);
412
f3d2e786 413 return_ACPI_STATUS(AE_OK);
1da177e4 414}
9f41fd8a
BM
415
416/*******************************************************************************
417 *
418 * FUNCTION: acpi_is_valid_signature
419 *
420 * PARAMETERS: signature - Sig string to be validated
421 *
422 * RETURN: TRUE if signature is correct length and has valid characters
423 *
424 * DESCRIPTION: Validate an ACPI table signature.
425 *
426 ******************************************************************************/
427
428u8 acpi_is_valid_signature(char *signature)
429{
430 u32 i;
431
432 /* Validate the signature length */
433
434 if (strlen(signature) != ACPI_NAME_SIZE) {
435 return (FALSE);
436 }
437
438 /* Validate each character in the signature */
439
440 for (i = 0; i < ACPI_NAME_SIZE; i++) {
441 if (!acpi_ut_valid_acpi_char(signature[i], i)) {
442 return (FALSE);
443 }
444 }
445
446 return (TRUE);
447}
This page took 0.780606 seconds and 5 git commands to generate.