ACPICA: Additional 2016 copyright changes
[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/*
c8100dc4 8 * Copyright (C) 2000 - 2016, 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{
7484619b 71 struct acpi_table_facs *facs;
009c4cbe 72
22e5b40a
BM
73 /* 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);
8ec3f459
LZ
78 } 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,
7484619b
LZ
84 &facs));
85 acpi_gbl_FACS = facs;
8ec3f459
LZ
86 } 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,
7484619b
LZ
90 &facs));
91 acpi_gbl_FACS = facs;
c04e1fb4
LZ
92 }
93
f06147f9
LZ
94 /* If there is no FACS, just continue. There was already an error msg */
95
c04e1fb4 96 return (AE_OK);
009c4cbe 97}
33620c54 98#endif /* !ACPI_REDUCED_HARDWARE */
009c4cbe 99
729df0f8
LM
100/*******************************************************************************
101 *
102 * 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
43323cb4
BM
119 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
120 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
3b3ea775
BM
121 ACPI_BIOS_ERROR((AE_INFO,
122 "The DSDT has been corrupted or replaced - "
123 "old, new headers below"));
1fad8738 124
729df0f8 125 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
43323cb4 126 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
729df0f8 127
aa2110cb
LM
128 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
729df0f8
LM
132 /* Disable further error messages */
133
43323cb4 134 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
729df0f8 135 acpi_gbl_original_dsdt_header.checksum =
43323cb4 136 acpi_gbl_DSDT->checksum;
729df0f8
LM
137 }
138}
139
69ec87ef
LM
140/*******************************************************************************
141 *
142 * 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
43323cb4 154struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
69ec87ef
LM
155{
156 struct acpi_table_header *new_table;
43323cb4
BM
157 struct acpi_table_desc *table_desc;
158
159 table_desc = &acpi_gbl_root_table_list.tables[table_index];
69ec87ef
LM
160
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));
43323cb4 165 return (NULL);
69ec87ef
LM
166 }
167
4fa4616e 168 memcpy(new_table, table_desc->pointer, table_desc->length);
7f9fc99c 169 acpi_tb_uninstall_table(table_desc);
ed6f1d44
BM
170
171 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
8ec3f459 172 tables[acpi_gbl_dsdt_index],
ed6f1d44
BM
173 ACPI_PTR_TO_PHYSADDR(new_table),
174 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
175 new_table);
69ec87ef
LM
176
177 ACPI_INFO((AE_INFO,
178 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
179 new_table->length));
43323cb4
BM
180
181 return (new_table);
69ec87ef
LM
182}
183
a4bbb810
BM
184/*******************************************************************************
185 *
186 * FUNCTION: acpi_tb_get_root_table_entry
187 *
188 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
189 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
190 *
191 * RETURN: Physical address extracted from the root table
192 *
193 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
194 * both 32-bit and 64-bit platforms
195 *
196 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
197 * 64-bit platforms.
198 *
199 ******************************************************************************/
200
201static acpi_physical_address
67a119f9 202acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
a4bbb810
BM
203{
204 u64 address64;
205
206 /*
207 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
208 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
209 */
671cc68d 210 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
a4bbb810
BM
211 /*
212 * 32-bit platform, RSDT: Return 32-bit table entry
213 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
214 */
215 return ((acpi_physical_address)
216 (*ACPI_CAST_PTR(u32, table_entry)));
217 } else {
218 /*
219 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
ec41f193
BM
220 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
221 * return 64-bit
a4bbb810
BM
222 */
223 ACPI_MOVE_64_TO_64(&address64, table_entry);
224
225#if ACPI_MACHINE_WIDTH == 32
226 if (address64 > ACPI_UINT32_MAX) {
227
ea5d8ebc 228 /* Will truncate 64-bit address to 32 bits, issue warning */
a4bbb810 229
3b3ea775
BM
230 ACPI_BIOS_WARNING((AE_INFO,
231 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
232 " truncating",
233 ACPI_FORMAT_UINT64(address64)));
a4bbb810
BM
234 }
235#endif
236 return ((acpi_physical_address) (address64));
237 }
238}
239
793c2388
BM
240/*******************************************************************************
241 *
f3d2e786 242 * FUNCTION: acpi_tb_parse_root_table
793c2388 243 *
ba494bee 244 * PARAMETERS: rsdp - Pointer to the RSDP
f3d2e786
BM
245 *
246 * RETURN: Status
793c2388 247 *
f3d2e786
BM
248 * DESCRIPTION: This function is called to parse the Root System Description
249 * Table (RSDT or XSDT)
793c2388 250 *
f3d2e786
BM
251 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
252 * be mapped and cannot be copied because it contains the actual
253 * memory location of the ACPI Global Lock.
793c2388
BM
254 *
255 ******************************************************************************/
256
45c9f78b 257acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
793c2388 258{
c5fc42ac 259 struct acpi_table_rsdp *rsdp;
67a119f9
BM
260 u32 table_entry_size;
261 u32 i;
c5fc42ac 262 u32 table_count;
f3d2e786
BM
263 struct acpi_table_header *table;
264 acpi_physical_address address;
265 u32 length;
266 u8 *table_entry;
f3d2e786 267 acpi_status status;
86dfc6f3 268 u32 table_index;
f3d2e786
BM
269
270 ACPI_FUNCTION_TRACE(tb_parse_root_table);
271
671cc68d
LZ
272 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
273
c5fc42ac
BM
274 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
275 if (!rsdp) {
276 return_ACPI_STATUS(AE_NO_MEMORY);
277 }
278
279 acpi_tb_print_table_header(rsdp_address,
280 ACPI_CAST_PTR(struct acpi_table_header,
281 rsdp));
282
fab46105 283 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
f3d2e786 284
fab46105
LZ
285 if ((rsdp->revision > 1) &&
286 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
f3d2e786 287 /*
671cc68d
LZ
288 * RSDP contains an XSDT (64-bit physical addresses). We must use
289 * the XSDT if the revision is > 1 and the XSDT pointer is present,
290 * as per the ACPI specification.
f3d2e786 291 */
c5fc42ac 292 address = (acpi_physical_address) rsdp->xsdt_physical_address;
671cc68d 293 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
f3d2e786
BM
294 } else {
295 /* Root table is an RSDT (32-bit physical addresses) */
296
c5fc42ac 297 address = (acpi_physical_address) rsdp->rsdt_physical_address;
671cc68d 298 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
f3d2e786 299 }
793c2388 300
c5fc42ac
BM
301 /*
302 * It is not possible to map more than one entry in some environments,
303 * so unmap the RSDP here before mapping other tables
304 */
305 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
306
307 /* Map the RSDT/XSDT table header to get the full table length */
793c2388 308
f3d2e786
BM
309 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
310 if (!table) {
c5fc42ac 311 return_ACPI_STATUS(AE_NO_MEMORY);
f3d2e786
BM
312 }
313
c5fc42ac
BM
314 acpi_tb_print_table_header(address, table);
315
671cc68d
LZ
316 /*
317 * Validate length of the table, and map entire table.
318 * Minimum length table must contain at least one entry.
319 */
f3d2e786
BM
320 length = table->length;
321 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
322
671cc68d 323 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
3b3ea775
BM
324 ACPI_BIOS_ERROR((AE_INFO,
325 "Invalid table length 0x%X in RSDT/XSDT",
326 length));
c5fc42ac 327 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
f3d2e786
BM
328 }
329
330 table = acpi_os_map_memory(address, length);
331 if (!table) {
c5fc42ac 332 return_ACPI_STATUS(AE_NO_MEMORY);
f3d2e786
BM
333 }
334
335 /* Validate the root table checksum */
336
c5fc42ac
BM
337 status = acpi_tb_verify_checksum(table, length);
338 if (ACPI_FAILURE(status)) {
f3d2e786 339 acpi_os_unmap_memory(table, length);
c5fc42ac 340 return_ACPI_STATUS(status);
f3d2e786 341 }
f3d2e786 342
671cc68d 343 /* Get the number of entries and pointer to first entry */
f3d2e786 344
ec41f193
BM
345 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
346 table_entry_size);
671cc68d
LZ
347 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
348
671cc68d
LZ
349 /* Initialize the root table array from the RSDT/XSDT */
350
c5fc42ac 351 for (i = 0; i < table_count; i++) {
f3d2e786 352
a4bbb810
BM
353 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
354
0f929fbf
LZ
355 address =
356 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
357
358 /* Skip NULL entries in RSDT/XSDT */
359
360 if (!address) {
361 goto next_table;
362 }
363
364 status = acpi_tb_install_standard_table(address,
365 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
366 FALSE, TRUE,
367 &table_index);
86dfc6f3
LZ
368
369 if (ACPI_SUCCESS(status) &&
370 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
371 tables[table_index].signature,
372 ACPI_SIG_FADT)) {
62fcce91
LZ
373 acpi_gbl_fadt_index = table_index;
374 acpi_tb_parse_fadt();
86dfc6f3 375 }
f3d2e786 376
0f929fbf
LZ
377next_table:
378
c5fc42ac 379 table_entry += table_entry_size;
1da177e4 380 }
793c2388 381
f3d2e786 382 acpi_os_unmap_memory(table, length);
f3d2e786 383 return_ACPI_STATUS(AE_OK);
1da177e4 384}
9f41fd8a
BM
385
386/*******************************************************************************
387 *
388 * FUNCTION: acpi_is_valid_signature
389 *
390 * PARAMETERS: signature - Sig string to be validated
391 *
395ec731 392 * RETURN: TRUE if signature is has 4 valid ACPI characters
9f41fd8a
BM
393 *
394 * DESCRIPTION: Validate an ACPI table signature.
395 *
396 ******************************************************************************/
397
398u8 acpi_is_valid_signature(char *signature)
399{
400 u32 i;
401
9f41fd8a
BM
402 /* Validate each character in the signature */
403
404 for (i = 0; i < ACPI_NAME_SIZE; i++) {
405 if (!acpi_ut_valid_acpi_char(signature[i], i)) {
406 return (FALSE);
407 }
408 }
409
410 return (TRUE);
411}
This page took 0.687338 seconds and 5 git commands to generate.