ACPICA: Tables: Do not validate signature for dynamic table load
[linux-2.6-block.git] / drivers / acpi / acpica / tbinstal.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
7735ca0e 8 * Copyright (C) 2000 - 2017, 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 45#include "accommon.h"
e2f7a777 46#include "actables.h"
1da177e4 47
1da177e4 48#define _COMPONENT ACPI_TABLES
4be44fcd 49ACPI_MODULE_NAME("tbinstal")
1da177e4 50
86dfc6f3 51/* Local prototypes */
86dfc6f3 52static u8
c418ce19 53acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
1da177e4 54
7f9fc99c
LZ
55/*******************************************************************************
56 *
c418ce19 57 * FUNCTION: acpi_tb_compare_tables
7f9fc99c 58 *
c418ce19
BM
59 * PARAMETERS: table_desc - Table 1 descriptor to be compared
60 * table_index - Index of table 2 to be compared
7f9fc99c 61 *
c418ce19 62 * RETURN: TRUE if both tables are identical.
7f9fc99c 63 *
c418ce19
BM
64 * DESCRIPTION: This function compares a table with another table that has
65 * already been installed in the root table list.
7f9fc99c
LZ
66 *
67 ******************************************************************************/
68
c418ce19
BM
69static u8
70acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
1da177e4 71{
f3d2e786 72 acpi_status status = AE_OK;
c418ce19
BM
73 u8 is_identical;
74 struct acpi_table_header *table;
75 u32 table_length;
76 u8 table_flags;
1da177e4 77
86dfc6f3 78 status =
c418ce19
BM
79 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
80 &table, &table_length, &table_flags);
86dfc6f3 81 if (ACPI_FAILURE(status)) {
c418ce19 82 return (FALSE);
86dfc6f3 83 }
f3d2e786 84
86dfc6f3 85 /*
c418ce19
BM
86 * Check for a table match on the entire table length,
87 * not just the header.
86dfc6f3 88 */
c418ce19 89 is_identical = (u8)((table_desc->length != table_length ||
4fa4616e
BM
90 memcmp(table_desc->pointer, table, table_length)) ?
91 FALSE : TRUE);
e56f5617 92
c418ce19 93 /* Release the acquired table */
ed6f1d44 94
c418ce19
BM
95 acpi_tb_release_table(table, table_length, table_flags);
96 return (is_identical);
86dfc6f3 97}
e56f5617 98
86dfc6f3
LZ
99/*******************************************************************************
100 *
ed6f1d44 101 * FUNCTION: acpi_tb_install_table_with_override
86dfc6f3 102 *
8ec3f459 103 * PARAMETERS: new_table_desc - New table descriptor to install
caf4a15c 104 * override - Whether override should be performed
8ec3f459 105 * table_index - Where the table index is returned
86dfc6f3
LZ
106 *
107 * RETURN: None
108 *
109 * DESCRIPTION: Install an ACPI table into the global data structure. The
110 * table override mechanism is called to allow the host
111 * OS to replace any table before it is installed in the root
112 * table array.
113 *
114 ******************************************************************************/
115
116void
8ec3f459
LZ
117acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
118 u8 override, u32 *table_index)
86dfc6f3 119{
8ec3f459
LZ
120 u32 i;
121 acpi_status status;
ed6f1d44 122
8ec3f459
LZ
123 status = acpi_tb_get_next_table_descriptor(&i, NULL);
124 if (ACPI_FAILURE(status)) {
86dfc6f3 125 return;
1da177e4
LT
126 }
127
d3ccaff8
BM
128 /*
129 * ACPI Table Override:
86dfc6f3
LZ
130 *
131 * Before we install the table, let the host OS override it with a new
132 * one if desired. Any table within the RSDT/XSDT can be replaced,
133 * including the DSDT which is pointed to by the FADT.
d3ccaff8 134 */
caf4a15c
LZ
135 if (override) {
136 acpi_tb_override_table(new_table_desc);
137 }
7f9fc99c 138
8ec3f459 139 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
ed6f1d44
BM
140 new_table_desc->address,
141 new_table_desc->flags,
142 new_table_desc->pointer);
7f9fc99c 143
86dfc6f3
LZ
144 acpi_tb_print_table_header(new_table_desc->address,
145 new_table_desc->pointer);
146
8ec3f459
LZ
147 /* This synchronizes acpi_gbl_dsdt_index */
148
149 *table_index = i;
150
86dfc6f3
LZ
151 /* Set the global integer width (based upon revision of the DSDT) */
152
8ec3f459 153 if (i == acpi_gbl_dsdt_index) {
86dfc6f3
LZ
154 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
155 }
156}
157
86dfc6f3
LZ
158/*******************************************************************************
159 *
ed6f1d44 160 * FUNCTION: acpi_tb_install_standard_table
86dfc6f3 161 *
8a216d7f 162 * PARAMETERS: address - Address of the table (might be a virtual
86dfc6f3
LZ
163 * address depending on the table_flags)
164 * flags - Flags for the table
165 * reload - Whether reload should be performed
caf4a15c 166 * override - Whether override should be performed
86dfc6f3
LZ
167 * table_index - Where the table index is returned
168 *
169 * RETURN: Status
170 *
752db101 171 * DESCRIPTION: This function is called to verify and install an ACPI table.
86dfc6f3
LZ
172 * When this function is called by "Load" or "LoadTable" opcodes,
173 * or by acpi_load_table() API, the "Reload" parameter is set.
174 * After sucessfully returning from this function, table is
175 * "INSTALLED" but not "VALIDATED".
176 *
177 ******************************************************************************/
178
179acpi_status
ed6f1d44
BM
180acpi_tb_install_standard_table(acpi_physical_address address,
181 u8 flags,
182 u8 reload, u8 override, u32 *table_index)
86dfc6f3
LZ
183{
184 u32 i;
185 acpi_status status = AE_OK;
186 struct acpi_table_desc new_table_desc;
187
ed6f1d44 188 ACPI_FUNCTION_TRACE(tb_install_standard_table);
86dfc6f3 189
ed6f1d44 190 /* Acquire a temporary table descriptor for validation */
86dfc6f3 191
ed6f1d44 192 status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
86dfc6f3 193 if (ACPI_FAILURE(status)) {
cc2080b0
LZ
194 ACPI_ERROR((AE_INFO,
195 "Could not acquire table length at %8.8X%8.8X",
196 ACPI_FORMAT_UINT64(address)));
86dfc6f3
LZ
197 return_ACPI_STATUS(status);
198 }
199
a94e88cd
LZ
200 /*
201 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
202 * be useful for debugging ACPI problems on some machines.
203 */
ed6f1d44
BM
204 if (!reload &&
205 acpi_gbl_disable_ssdt_table_install &&
a94e88cd 206 ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
05fb04b5 207 ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
6d3fd3cc 208 new_table_desc.signature.ascii,
cc2080b0 209 ACPI_FORMAT_UINT64(address)));
a94e88cd
LZ
210 goto release_and_exit;
211 }
212
86dfc6f3
LZ
213 /* Validate and verify a table before installation */
214
47d68c7f 215 status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
86dfc6f3
LZ
216 if (ACPI_FAILURE(status)) {
217 goto release_and_exit;
218 }
219
7a37052a
LZ
220 /* Acquire the table lock */
221
222 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
223
86dfc6f3 224 if (reload) {
86dfc6f3
LZ
225
226 /* Check if table is already registered */
227
228 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
229 ++i) {
230 /*
231 * Check for a table match on the entire table length,
232 * not just the header.
233 */
c418ce19 234 if (!acpi_tb_compare_tables(&new_table_desc, i)) {
86dfc6f3
LZ
235 continue;
236 }
237
238 /*
239 * Note: the current mechanism does not unregister a table if it is
240 * dynamically unloaded. The related namespace entries are deleted,
241 * but the table remains in the root table list.
242 *
243 * The assumption here is that the number of different tables that
244 * will be loaded is actually small, and there is minimal overhead
245 * in just keeping the table in case it is needed again.
246 *
247 * If this assumption changes in the future (perhaps on large
248 * machines with many table load/unload operations), tables will
249 * need to be unregistered when they are unloaded, and slots in the
250 * root table list should be reused when empty.
251 */
1fad8738
BM
252 if (acpi_gbl_root_table_list.tables[i].flags &
253 ACPI_TABLE_IS_LOADED) {
86dfc6f3
LZ
254
255 /* Table is still loaded, this is an error */
256
257 status = AE_ALREADY_EXISTS;
7a37052a 258 goto unlock_and_exit;
86dfc6f3
LZ
259 } else {
260 /*
261 * Table was unloaded, allow it to be reloaded.
262 * As we are going to return AE_OK to the caller, we should
263 * take the responsibility of freeing the input descriptor.
264 * Refill the input descriptor to ensure
ed6f1d44 265 * acpi_tb_install_table_with_override() can be called again to
86dfc6f3
LZ
266 * indicate the re-installation.
267 */
268 acpi_tb_uninstall_table(&new_table_desc);
7a37052a 269 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
86dfc6f3 270 *table_index = i;
86dfc6f3
LZ
271 return_ACPI_STATUS(AE_OK);
272 }
273 }
7f9fc99c 274 }
d3ccaff8 275
e56f5617
BM
276 /* Add the table to the global root table list */
277
8ec3f459
LZ
278 acpi_tb_install_table_with_override(&new_table_desc, override,
279 table_index);
86dfc6f3 280
9b019b0f 281 /* Invoke table handler */
bdbe5df0 282
7a37052a 283 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
9b019b0f 284 acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
7a37052a
LZ
285 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
286
287unlock_and_exit:
288
289 /* Release the table lock */
290
291 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
bdbe5df0 292
86dfc6f3 293release_and_exit:
0c9938cc 294
ed6f1d44 295 /* Release the temporary table descriptor */
1da177e4 296
ed6f1d44 297 acpi_tb_release_temp_table(&new_table_desc);
4be44fcd 298 return_ACPI_STATUS(status);
1da177e4
LT
299}
300
f7b004a1
BM
301/*******************************************************************************
302 *
7f9fc99c 303 * FUNCTION: acpi_tb_override_table
f7b004a1 304 *
86dfc6f3
LZ
305 * PARAMETERS: old_table_desc - Validated table descriptor to be
306 * overridden
f7b004a1 307 *
86dfc6f3 308 * RETURN: None
f7b004a1
BM
309 *
310 * DESCRIPTION: Attempt table override by calling the OSL override functions.
311 * Note: If the table is overridden, then the entire new table
7f9fc99c 312 * is acquired and returned by this function.
86dfc6f3
LZ
313 * Before/after invocation, the table descriptor is in a state
314 * that is "VALIDATED".
f7b004a1
BM
315 *
316 ******************************************************************************/
317
86dfc6f3 318void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
f7b004a1
BM
319{
320 acpi_status status;
f7b004a1 321 char *override_type;
7f9fc99c 322 struct acpi_table_desc new_table_desc;
86dfc6f3
LZ
323 struct acpi_table_header *table;
324 acpi_physical_address address;
325 u32 length;
f7b004a1
BM
326
327 /* (1) Attempt logical override (returns a logical address) */
328
86dfc6f3
LZ
329 status = acpi_os_table_override(old_table_desc->pointer, &table);
330 if (ACPI_SUCCESS(status) && table) {
ed6f1d44
BM
331 acpi_tb_acquire_temp_table(&new_table_desc,
332 ACPI_PTR_TO_PHYSADDR(table),
333 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
f7b004a1
BM
334 override_type = "Logical";
335 goto finish_override;
336 }
337
338 /* (2) Attempt physical override (returns a physical address) */
339
86dfc6f3
LZ
340 status = acpi_os_physical_table_override(old_table_desc->pointer,
341 &address, &length);
342 if (ACPI_SUCCESS(status) && address && length) {
ed6f1d44
BM
343 acpi_tb_acquire_temp_table(&new_table_desc, address,
344 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
f7b004a1 345 override_type = "Physical";
f7b004a1
BM
346 goto finish_override;
347 }
348
86dfc6f3 349 return; /* There was no override */
f7b004a1 350
10622bf8 351finish_override:
f7b004a1 352
86dfc6f3
LZ
353 /* Validate and verify a table before overriding */
354
47d68c7f 355 status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
7f9fc99c 356 if (ACPI_FAILURE(status)) {
86dfc6f3 357 return;
7f9fc99c
LZ
358 }
359
05fb04b5 360 ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
1d0a0b2f 361 " %s table override, new table: 0x%8.8X%8.8X",
86dfc6f3 362 old_table_desc->signature.ascii,
1d0a0b2f
LZ
363 ACPI_FORMAT_UINT64(old_table_desc->address),
364 override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
f7b004a1 365
86dfc6f3 366 /* We can now uninstall the original table */
f7b004a1 367
86dfc6f3 368 acpi_tb_uninstall_table(old_table_desc);
f7b004a1 369
86dfc6f3
LZ
370 /*
371 * Replace the original table descriptor and keep its state as
372 * "VALIDATED".
373 */
ed6f1d44
BM
374 acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
375 new_table_desc.flags,
376 new_table_desc.pointer);
47d68c7f 377 acpi_tb_validate_temp_table(old_table_desc);
f7b004a1 378
ed6f1d44 379 /* Release the temporary table descriptor */
f7b004a1 380
ed6f1d44 381 acpi_tb_release_temp_table(&new_table_desc);
f7b004a1
BM
382}
383
f3d2e786
BM
384/*******************************************************************************
385 *
7f9fc99c 386 * FUNCTION: acpi_tb_uninstall_table
f3d2e786 387 *
7f9fc99c 388 * PARAMETERS: table_desc - Table descriptor
f3d2e786
BM
389 *
390 * RETURN: None
391 *
392 * DESCRIPTION: Delete one internal ACPI table
393 *
394 ******************************************************************************/
1da177e4 395
7f9fc99c 396void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
f3d2e786 397{
5582982d 398
7f9fc99c 399 ACPI_FUNCTION_TRACE(tb_uninstall_table);
5582982d 400
7f9fc99c 401 /* Table must be installed */
5582982d 402
7f9fc99c
LZ
403 if (!table_desc->address) {
404 return_VOID;
405 }
f7b004a1 406
7f9fc99c 407 acpi_tb_invalidate_table(table_desc);
1d1ea1b7 408
7f9fc99c 409 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
ed6f1d44 410 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
6d3fd3cc 411 ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
1da177e4
LT
412 }
413
7f9fc99c 414 table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
7f9fc99c 415 return_VOID;
1da177e4 416}