ACPICA: Update info messages during ACPICA init
[deliverable/linux.git] / drivers / acpi / acpica / tbinstal.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
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 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
LZ
102 *
103 * PARAMETERS: table_index - Index into root table array
104 * new_table_desc - New table descriptor to install
caf4a15c 105 * override - Whether override should be performed
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
ed6f1d44
BM
117acpi_tb_install_table_with_override(u32 table_index,
118 struct acpi_table_desc *new_table_desc,
119 u8 override)
86dfc6f3 120{
ed6f1d44 121
86dfc6f3
LZ
122 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
123 return;
1da177e4
LT
124 }
125
d3ccaff8
BM
126 /*
127 * ACPI Table Override:
86dfc6f3
LZ
128 *
129 * Before we install the table, let the host OS override it with a new
130 * one if desired. Any table within the RSDT/XSDT can be replaced,
131 * including the DSDT which is pointed to by the FADT.
d3ccaff8 132 */
caf4a15c
LZ
133 if (override) {
134 acpi_tb_override_table(new_table_desc);
135 }
7f9fc99c 136
ed6f1d44
BM
137 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
138 tables[table_index],
139 new_table_desc->address,
140 new_table_desc->flags,
141 new_table_desc->pointer);
7f9fc99c 142
86dfc6f3
LZ
143 acpi_tb_print_table_header(new_table_desc->address,
144 new_table_desc->pointer);
145
146 /* Set the global integer width (based upon revision of the DSDT) */
147
148 if (table_index == ACPI_TABLE_INDEX_DSDT) {
149 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
150 }
151}
152
153/*******************************************************************************
154 *
155 * FUNCTION: acpi_tb_install_fixed_table
156 *
157 * PARAMETERS: address - Physical address of DSDT or FACS
158 * signature - Table signature, NULL if no need to
159 * match
160 * table_index - Index into root table array
161 *
162 * RETURN: Status
163 *
164 * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
165 * structure.
166 *
167 ******************************************************************************/
168
169acpi_status
170acpi_tb_install_fixed_table(acpi_physical_address address,
171 char *signature, u32 table_index)
172{
173 struct acpi_table_desc new_table_desc;
174 acpi_status status;
175
176 ACPI_FUNCTION_TRACE(tb_install_fixed_table);
177
178 if (!address) {
179 ACPI_ERROR((AE_INFO,
180 "Null physical address for ACPI table [%s]",
181 signature));
182 return (AE_NO_MEMORY);
183 }
184
185 /* Fill a table descriptor for validation */
186
ed6f1d44
BM
187 status = acpi_tb_acquire_temp_table(&new_table_desc, address,
188 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
86dfc6f3 189 if (ACPI_FAILURE(status)) {
cc2080b0
LZ
190 ACPI_ERROR((AE_INFO,
191 "Could not acquire table length at %8.8X%8.8X",
192 ACPI_FORMAT_UINT64(address)));
86dfc6f3
LZ
193 return_ACPI_STATUS(status);
194 }
195
196 /* Validate and verify a table before installation */
197
47d68c7f 198 status = acpi_tb_verify_temp_table(&new_table_desc, signature);
86dfc6f3
LZ
199 if (ACPI_FAILURE(status)) {
200 goto release_and_exit;
201 }
202
ed6f1d44 203 acpi_tb_install_table_with_override(table_index, &new_table_desc, TRUE);
86dfc6f3
LZ
204
205release_and_exit:
206
ed6f1d44 207 /* Release the temporary table descriptor */
86dfc6f3 208
ed6f1d44 209 acpi_tb_release_temp_table(&new_table_desc);
86dfc6f3
LZ
210 return_ACPI_STATUS(status);
211}
212
86dfc6f3
LZ
213/*******************************************************************************
214 *
ed6f1d44 215 * FUNCTION: acpi_tb_install_standard_table
86dfc6f3 216 *
8a216d7f 217 * PARAMETERS: address - Address of the table (might be a virtual
86dfc6f3
LZ
218 * address depending on the table_flags)
219 * flags - Flags for the table
220 * reload - Whether reload should be performed
caf4a15c 221 * override - Whether override should be performed
86dfc6f3
LZ
222 * table_index - Where the table index is returned
223 *
224 * RETURN: Status
225 *
226 * DESCRIPTION: This function is called to install an ACPI table that is
ed6f1d44 227 * neither DSDT nor FACS (a "standard" table.)
86dfc6f3
LZ
228 * When this function is called by "Load" or "LoadTable" opcodes,
229 * or by acpi_load_table() API, the "Reload" parameter is set.
230 * After sucessfully returning from this function, table is
231 * "INSTALLED" but not "VALIDATED".
232 *
233 ******************************************************************************/
234
235acpi_status
ed6f1d44
BM
236acpi_tb_install_standard_table(acpi_physical_address address,
237 u8 flags,
238 u8 reload, u8 override, u32 *table_index)
86dfc6f3
LZ
239{
240 u32 i;
241 acpi_status status = AE_OK;
242 struct acpi_table_desc new_table_desc;
243
ed6f1d44 244 ACPI_FUNCTION_TRACE(tb_install_standard_table);
86dfc6f3 245
ed6f1d44 246 /* Acquire a temporary table descriptor for validation */
86dfc6f3 247
ed6f1d44 248 status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
86dfc6f3 249 if (ACPI_FAILURE(status)) {
cc2080b0
LZ
250 ACPI_ERROR((AE_INFO,
251 "Could not acquire table length at %8.8X%8.8X",
252 ACPI_FORMAT_UINT64(address)));
86dfc6f3
LZ
253 return_ACPI_STATUS(status);
254 }
255
a94e88cd
LZ
256 /*
257 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
258 * be useful for debugging ACPI problems on some machines.
259 */
ed6f1d44
BM
260 if (!reload &&
261 acpi_gbl_disable_ssdt_table_install &&
a94e88cd 262 ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
cc2080b0
LZ
263 ACPI_INFO((AE_INFO,
264 "Ignoring installation of %4.4s at %8.8X%8.8X",
6d3fd3cc 265 new_table_desc.signature.ascii,
cc2080b0 266 ACPI_FORMAT_UINT64(address)));
a94e88cd
LZ
267 goto release_and_exit;
268 }
269
86dfc6f3
LZ
270 /* Validate and verify a table before installation */
271
47d68c7f 272 status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
86dfc6f3
LZ
273 if (ACPI_FAILURE(status)) {
274 goto release_and_exit;
275 }
276
277 if (reload) {
278 /*
279 * Validate the incoming table signature.
280 *
281 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
282 * 2) We added support for OEMx tables, signature "OEM".
283 * 3) Valid tables were encountered with a null signature, so we just
284 * gave up on validating the signature, (05/2008).
285 * 4) We encountered non-AML tables such as the MADT, which caused
286 * interpreter errors and kernel faults. So now, we once again allow
287 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
288 */
289 if ((new_table_desc.signature.ascii[0] != 0x00) &&
290 (!ACPI_COMPARE_NAME
291 (&new_table_desc.signature, ACPI_SIG_SSDT))
4fa4616e 292 && (strncmp(new_table_desc.signature.ascii, "OEM", 3))) {
86dfc6f3
LZ
293 ACPI_BIOS_ERROR((AE_INFO,
294 "Table has invalid signature [%4.4s] (0x%8.8X), "
295 "must be SSDT or OEMx",
296 acpi_ut_valid_acpi_name(new_table_desc.
297 signature.
298 ascii) ?
299 new_table_desc.signature.
300 ascii : "????",
301 new_table_desc.signature.integer));
302
303 status = AE_BAD_SIGNATURE;
304 goto release_and_exit;
305 }
306
307 /* Check if table is already registered */
308
309 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
310 ++i) {
311 /*
312 * Check for a table match on the entire table length,
313 * not just the header.
314 */
c418ce19 315 if (!acpi_tb_compare_tables(&new_table_desc, i)) {
86dfc6f3
LZ
316 continue;
317 }
318
319 /*
320 * Note: the current mechanism does not unregister a table if it is
321 * dynamically unloaded. The related namespace entries are deleted,
322 * but the table remains in the root table list.
323 *
324 * The assumption here is that the number of different tables that
325 * will be loaded is actually small, and there is minimal overhead
326 * in just keeping the table in case it is needed again.
327 *
328 * If this assumption changes in the future (perhaps on large
329 * machines with many table load/unload operations), tables will
330 * need to be unregistered when they are unloaded, and slots in the
331 * root table list should be reused when empty.
332 */
333 if (acpi_gbl_root_table_list.tables[i].
334 flags & ACPI_TABLE_IS_LOADED) {
335
336 /* Table is still loaded, this is an error */
337
338 status = AE_ALREADY_EXISTS;
339 goto release_and_exit;
340 } else {
341 /*
342 * Table was unloaded, allow it to be reloaded.
343 * As we are going to return AE_OK to the caller, we should
344 * take the responsibility of freeing the input descriptor.
345 * Refill the input descriptor to ensure
ed6f1d44 346 * acpi_tb_install_table_with_override() can be called again to
86dfc6f3
LZ
347 * indicate the re-installation.
348 */
349 acpi_tb_uninstall_table(&new_table_desc);
350 *table_index = i;
86dfc6f3
LZ
351 return_ACPI_STATUS(AE_OK);
352 }
353 }
7f9fc99c 354 }
d3ccaff8 355
e56f5617
BM
356 /* Add the table to the global root table list */
357
76cffa79 358 status = acpi_tb_get_next_table_descriptor(&i, NULL);
4be44fcd 359 if (ACPI_FAILURE(status)) {
86dfc6f3 360 goto release_and_exit;
0c9938cc 361 }
ed6f1d44 362
86dfc6f3 363 *table_index = i;
ed6f1d44 364 acpi_tb_install_table_with_override(i, &new_table_desc, override);
86dfc6f3
LZ
365
366release_and_exit:
0c9938cc 367
ed6f1d44 368 /* Release the temporary table descriptor */
1da177e4 369
ed6f1d44 370 acpi_tb_release_temp_table(&new_table_desc);
4be44fcd 371 return_ACPI_STATUS(status);
1da177e4
LT
372}
373
f7b004a1
BM
374/*******************************************************************************
375 *
7f9fc99c 376 * FUNCTION: acpi_tb_override_table
f7b004a1 377 *
86dfc6f3
LZ
378 * PARAMETERS: old_table_desc - Validated table descriptor to be
379 * overridden
f7b004a1 380 *
86dfc6f3 381 * RETURN: None
f7b004a1
BM
382 *
383 * DESCRIPTION: Attempt table override by calling the OSL override functions.
384 * Note: If the table is overridden, then the entire new table
7f9fc99c 385 * is acquired and returned by this function.
86dfc6f3
LZ
386 * Before/after invocation, the table descriptor is in a state
387 * that is "VALIDATED".
f7b004a1
BM
388 *
389 ******************************************************************************/
390
86dfc6f3 391void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
f7b004a1
BM
392{
393 acpi_status status;
f7b004a1 394 char *override_type;
7f9fc99c 395 struct acpi_table_desc new_table_desc;
86dfc6f3
LZ
396 struct acpi_table_header *table;
397 acpi_physical_address address;
398 u32 length;
f7b004a1
BM
399
400 /* (1) Attempt logical override (returns a logical address) */
401
86dfc6f3
LZ
402 status = acpi_os_table_override(old_table_desc->pointer, &table);
403 if (ACPI_SUCCESS(status) && table) {
ed6f1d44
BM
404 acpi_tb_acquire_temp_table(&new_table_desc,
405 ACPI_PTR_TO_PHYSADDR(table),
406 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
f7b004a1
BM
407 override_type = "Logical";
408 goto finish_override;
409 }
410
411 /* (2) Attempt physical override (returns a physical address) */
412
86dfc6f3
LZ
413 status = acpi_os_physical_table_override(old_table_desc->pointer,
414 &address, &length);
415 if (ACPI_SUCCESS(status) && address && length) {
ed6f1d44
BM
416 acpi_tb_acquire_temp_table(&new_table_desc, address,
417 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
f7b004a1 418 override_type = "Physical";
f7b004a1
BM
419 goto finish_override;
420 }
421
86dfc6f3 422 return; /* There was no override */
f7b004a1 423
10622bf8 424finish_override:
f7b004a1 425
86dfc6f3
LZ
426 /* Validate and verify a table before overriding */
427
47d68c7f 428 status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
7f9fc99c 429 if (ACPI_FAILURE(status)) {
86dfc6f3 430 return;
7f9fc99c
LZ
431 }
432
1d0a0b2f
LZ
433 ACPI_INFO((AE_INFO, "%4.4s 0x%8.8X%8.8X"
434 " %s table override, new table: 0x%8.8X%8.8X",
86dfc6f3 435 old_table_desc->signature.ascii,
1d0a0b2f
LZ
436 ACPI_FORMAT_UINT64(old_table_desc->address),
437 override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
f7b004a1 438
86dfc6f3 439 /* We can now uninstall the original table */
f7b004a1 440
86dfc6f3 441 acpi_tb_uninstall_table(old_table_desc);
f7b004a1 442
86dfc6f3
LZ
443 /*
444 * Replace the original table descriptor and keep its state as
445 * "VALIDATED".
446 */
ed6f1d44
BM
447 acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
448 new_table_desc.flags,
449 new_table_desc.pointer);
47d68c7f 450 acpi_tb_validate_temp_table(old_table_desc);
f7b004a1 451
ed6f1d44 452 /* Release the temporary table descriptor */
f7b004a1 453
ed6f1d44 454 acpi_tb_release_temp_table(&new_table_desc);
f7b004a1
BM
455}
456
f3d2e786
BM
457/*******************************************************************************
458 *
7f9fc99c 459 * FUNCTION: acpi_tb_uninstall_table
f3d2e786 460 *
7f9fc99c 461 * PARAMETERS: table_desc - Table descriptor
f3d2e786
BM
462 *
463 * RETURN: None
464 *
465 * DESCRIPTION: Delete one internal ACPI table
466 *
467 ******************************************************************************/
1da177e4 468
7f9fc99c 469void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
f3d2e786 470{
5582982d 471
7f9fc99c 472 ACPI_FUNCTION_TRACE(tb_uninstall_table);
5582982d 473
7f9fc99c 474 /* Table must be installed */
5582982d 475
7f9fc99c
LZ
476 if (!table_desc->address) {
477 return_VOID;
478 }
f7b004a1 479
7f9fc99c 480 acpi_tb_invalidate_table(table_desc);
1d1ea1b7 481
7f9fc99c 482 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
ed6f1d44 483 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
6d3fd3cc 484 ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
1da177e4
LT
485 }
486
7f9fc99c 487 table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
7f9fc99c 488 return_VOID;
1da177e4 489}
This page took 0.752222 seconds and 5 git commands to generate.