blob: 0dfc0ac3c141f1c8e3cb386c1c12339e8cf9b4ee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
Bob Moore7735ca02017-02-08 11:00:08 +08008 * Copyright (C) 2000 - 2017, 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"
Len Browne2f7a772009-01-09 00:30:03 -050046#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("tbinstal")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Lv Zheng86dfc6f32014-04-04 12:38:57 +080051/*******************************************************************************
52 *
Bob Mooreed6f1d42014-04-04 12:39:26 +080053 * FUNCTION: acpi_tb_install_table_with_override
Lv Zheng86dfc6f32014-04-04 12:38:57 +080054 *
Lv Zheng8ec3f452015-08-25 10:29:01 +080055 * PARAMETERS: new_table_desc - New table descriptor to install
Lv Zhengcaf4a152014-04-04 12:39:18 +080056 * override - Whether override should be performed
Lv Zheng8ec3f452015-08-25 10:29:01 +080057 * table_index - Where the table index is returned
Lv Zheng86dfc6f32014-04-04 12:38:57 +080058 *
59 * RETURN: None
60 *
61 * DESCRIPTION: Install an ACPI table into the global data structure. The
62 * table override mechanism is called to allow the host
63 * OS to replace any table before it is installed in the root
64 * table array.
65 *
66 ******************************************************************************/
Lv Zheng86dfc6f32014-04-04 12:38:57 +080067void
Lv Zheng8ec3f452015-08-25 10:29:01 +080068acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
69 u8 override, u32 *table_index)
Lv Zheng86dfc6f32014-04-04 12:38:57 +080070{
Lv Zheng8ec3f452015-08-25 10:29:01 +080071 u32 i;
72 acpi_status status;
Bob Mooreed6f1d42014-04-04 12:39:26 +080073
Lv Zheng8ec3f452015-08-25 10:29:01 +080074 status = acpi_tb_get_next_table_descriptor(&i, NULL);
75 if (ACPI_FAILURE(status)) {
Lv Zheng86dfc6f32014-04-04 12:38:57 +080076 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
78
Bob Moored3ccaff2009-02-03 14:43:04 +080079 /*
80 * ACPI Table Override:
Lv Zheng86dfc6f32014-04-04 12:38:57 +080081 *
82 * Before we install the table, let the host OS override it with a new
83 * one if desired. Any table within the RSDT/XSDT can be replaced,
84 * including the DSDT which is pointed to by the FADT.
Bob Moored3ccaff2009-02-03 14:43:04 +080085 */
Lv Zhengcaf4a152014-04-04 12:39:18 +080086 if (override) {
87 acpi_tb_override_table(new_table_desc);
88 }
Lv Zheng7f9fc992014-04-04 12:38:42 +080089
Lv Zheng8ec3f452015-08-25 10:29:01 +080090 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
Bob Mooreed6f1d42014-04-04 12:39:26 +080091 new_table_desc->address,
92 new_table_desc->flags,
93 new_table_desc->pointer);
Lv Zheng7f9fc992014-04-04 12:38:42 +080094
Lv Zheng86dfc6f32014-04-04 12:38:57 +080095 acpi_tb_print_table_header(new_table_desc->address,
96 new_table_desc->pointer);
97
Lv Zheng8ec3f452015-08-25 10:29:01 +080098 /* This synchronizes acpi_gbl_dsdt_index */
99
100 *table_index = i;
101
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800102 /* Set the global integer width (based upon revision of the DSDT) */
103
Lv Zheng8ec3f452015-08-25 10:29:01 +0800104 if (i == acpi_gbl_dsdt_index) {
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800105 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
106 }
107}
108
109/*******************************************************************************
110 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800111 * FUNCTION: acpi_tb_install_standard_table
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800112 *
Lv Zheng8a216d72014-04-04 12:39:04 +0800113 * PARAMETERS: address - Address of the table (might be a virtual
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800114 * address depending on the table_flags)
115 * flags - Flags for the table
116 * reload - Whether reload should be performed
Lv Zhengcaf4a152014-04-04 12:39:18 +0800117 * override - Whether override should be performed
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800118 * table_index - Where the table index is returned
119 *
120 * RETURN: Status
121 *
Lv Zheng752db102016-09-07 14:06:17 +0800122 * DESCRIPTION: This function is called to verify and install an ACPI table.
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800123 * When this function is called by "Load" or "LoadTable" opcodes,
124 * or by acpi_load_table() API, the "Reload" parameter is set.
125 * After sucessfully returning from this function, table is
126 * "INSTALLED" but not "VALIDATED".
127 *
128 ******************************************************************************/
129
130acpi_status
Bob Mooreed6f1d42014-04-04 12:39:26 +0800131acpi_tb_install_standard_table(acpi_physical_address address,
132 u8 flags,
133 u8 reload, u8 override, u32 *table_index)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800134{
135 u32 i;
136 acpi_status status = AE_OK;
137 struct acpi_table_desc new_table_desc;
138
Bob Mooreed6f1d42014-04-04 12:39:26 +0800139 ACPI_FUNCTION_TRACE(tb_install_standard_table);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800140
Bob Mooreed6f1d42014-04-04 12:39:26 +0800141 /* Acquire a temporary table descriptor for validation */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800142
Bob Mooreed6f1d42014-04-04 12:39:26 +0800143 status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800144 if (ACPI_FAILURE(status)) {
Lv Zhengcc2080b2015-04-13 11:48:46 +0800145 ACPI_ERROR((AE_INFO,
146 "Could not acquire table length at %8.8X%8.8X",
147 ACPI_FORMAT_UINT64(address)));
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800148 return_ACPI_STATUS(status);
149 }
150
Lv Zhenga94e88c2014-04-04 12:39:11 +0800151 /*
152 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
153 * be useful for debugging ACPI problems on some machines.
154 */
Bob Mooreed6f1d42014-04-04 12:39:26 +0800155 if (!reload &&
156 acpi_gbl_disable_ssdt_table_install &&
Lv Zhenga94e88c2014-04-04 12:39:11 +0800157 ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
Bob Moore05fb04b2016-02-19 14:16:42 +0800158 ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
Lv Zheng6d3fd3c2015-04-13 11:48:37 +0800159 new_table_desc.signature.ascii,
Lv Zhengcc2080b2015-04-13 11:48:46 +0800160 ACPI_FORMAT_UINT64(address)));
Lv Zhenga94e88c2014-04-04 12:39:11 +0800161 goto release_and_exit;
162 }
163
Lv Zheng7a370522017-01-19 15:21:34 +0800164 /* Acquire the table lock */
165
166 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
167
Lv Zhengf9d472e2017-07-10 15:23:50 +0800168 /* Validate and verify a table before installation */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800169
Lv Zhengf9d472e2017-07-10 15:23:50 +0800170 status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i);
171 if (ACPI_FAILURE(status)) {
172 if (status == AE_CTRL_TERMINATE) {
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800173 /*
Lv Zhengf9d472e2017-07-10 15:23:50 +0800174 * Table was unloaded, allow it to be reloaded.
175 * As we are going to return AE_OK to the caller, we should
176 * take the responsibility of freeing the input descriptor.
177 * Refill the input descriptor to ensure
178 * acpi_tb_install_table_with_override() can be called again to
179 * indicate the re-installation.
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800180 */
Lv Zhengf9d472e2017-07-10 15:23:50 +0800181 acpi_tb_uninstall_table(&new_table_desc);
182 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
183 *table_index = i;
184 return_ACPI_STATUS(AE_OK);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800185 }
Lv Zhengf9d472e2017-07-10 15:23:50 +0800186 goto unlock_and_exit;
Lv Zheng7f9fc992014-04-04 12:38:42 +0800187 }
Bob Moored3ccaff2009-02-03 14:43:04 +0800188
Bob Mooree56f5612008-07-04 10:48:43 +0800189 /* Add the table to the global root table list */
190
Lv Zheng8ec3f452015-08-25 10:29:01 +0800191 acpi_tb_install_table_with_override(&new_table_desc, override,
192 table_index);
Robert Moore0c9938c2005-07-29 15:15:00 -0700193
Lv Zheng9b019b02017-07-10 15:23:28 +0800194 /* Invoke table handler */
Lv Zhengbdbe5df2016-09-07 14:06:32 +0800195
Lv Zheng7a370522017-01-19 15:21:34 +0800196 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Lv Zheng9b019b02017-07-10 15:23:28 +0800197 acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
Lv Zheng7a370522017-01-19 15:21:34 +0800198 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
199
200unlock_and_exit:
201
202 /* Release the table lock */
203
204 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Lv Zhengbdbe5df2016-09-07 14:06:32 +0800205
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800206release_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Bob Mooreed6f1d42014-04-04 12:39:26 +0800208 /* Release the temporary table descriptor */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800209
Bob Mooreed6f1d42014-04-04 12:39:26 +0800210 acpi_tb_release_temp_table(&new_table_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400211 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/*******************************************************************************
215 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800216 * FUNCTION: acpi_tb_override_table
Bob Mooref7b004a2012-02-14 18:31:56 +0800217 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800218 * PARAMETERS: old_table_desc - Validated table descriptor to be
219 * overridden
Bob Mooref7b004a2012-02-14 18:31:56 +0800220 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800221 * RETURN: None
Bob Mooref7b004a2012-02-14 18:31:56 +0800222 *
223 * DESCRIPTION: Attempt table override by calling the OSL override functions.
224 * Note: If the table is overridden, then the entire new table
Lv Zheng7f9fc992014-04-04 12:38:42 +0800225 * is acquired and returned by this function.
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800226 * Before/after invocation, the table descriptor is in a state
227 * that is "VALIDATED".
Bob Mooref7b004a2012-02-14 18:31:56 +0800228 *
229 ******************************************************************************/
230
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800231void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
Bob Mooref7b004a2012-02-14 18:31:56 +0800232{
233 acpi_status status;
Bob Mooref7b004a2012-02-14 18:31:56 +0800234 char *override_type;
Lv Zheng7f9fc992014-04-04 12:38:42 +0800235 struct acpi_table_desc new_table_desc;
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800236 struct acpi_table_header *table;
237 acpi_physical_address address;
238 u32 length;
Bob Mooref7b004a2012-02-14 18:31:56 +0800239
240 /* (1) Attempt logical override (returns a logical address) */
241
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800242 status = acpi_os_table_override(old_table_desc->pointer, &table);
243 if (ACPI_SUCCESS(status) && table) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800244 acpi_tb_acquire_temp_table(&new_table_desc,
245 ACPI_PTR_TO_PHYSADDR(table),
246 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
Bob Mooref7b004a2012-02-14 18:31:56 +0800247 override_type = "Logical";
248 goto finish_override;
249 }
250
251 /* (2) Attempt physical override (returns a physical address) */
252
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800253 status = acpi_os_physical_table_override(old_table_desc->pointer,
254 &address, &length);
255 if (ACPI_SUCCESS(status) && address && length) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800256 acpi_tb_acquire_temp_table(&new_table_desc, address,
257 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
Bob Mooref7b004a2012-02-14 18:31:56 +0800258 override_type = "Physical";
Bob Mooref7b004a2012-02-14 18:31:56 +0800259 goto finish_override;
260 }
261
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800262 return; /* There was no override */
Bob Mooref7b004a2012-02-14 18:31:56 +0800263
Lv Zheng10622bf2013-10-29 09:30:02 +0800264finish_override:
Bob Mooref7b004a2012-02-14 18:31:56 +0800265
Lv Zhengf9d472e2017-07-10 15:23:50 +0800266 /*
267 * Validate and verify a table before overriding, no nested table
268 * duplication check as it's too complicated and unnecessary.
269 */
270 status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800271 if (ACPI_FAILURE(status)) {
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800272 return;
Lv Zheng7f9fc992014-04-04 12:38:42 +0800273 }
274
Bob Moore05fb04b2016-02-19 14:16:42 +0800275 ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
Lv Zheng1d0a0b22015-04-13 11:48:52 +0800276 " %s table override, new table: 0x%8.8X%8.8X",
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800277 old_table_desc->signature.ascii,
Lv Zheng1d0a0b22015-04-13 11:48:52 +0800278 ACPI_FORMAT_UINT64(old_table_desc->address),
279 override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
Bob Mooref7b004a2012-02-14 18:31:56 +0800280
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800281 /* We can now uninstall the original table */
Bob Mooref7b004a2012-02-14 18:31:56 +0800282
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800283 acpi_tb_uninstall_table(old_table_desc);
Bob Mooref7b004a2012-02-14 18:31:56 +0800284
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800285 /*
286 * Replace the original table descriptor and keep its state as
287 * "VALIDATED".
288 */
Bob Mooreed6f1d42014-04-04 12:39:26 +0800289 acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
290 new_table_desc.flags,
291 new_table_desc.pointer);
Lv Zheng47d68c72014-05-31 08:14:44 +0800292 acpi_tb_validate_temp_table(old_table_desc);
Bob Mooref7b004a2012-02-14 18:31:56 +0800293
Bob Mooreed6f1d42014-04-04 12:39:26 +0800294 /* Release the temporary table descriptor */
Bob Mooref7b004a2012-02-14 18:31:56 +0800295
Bob Mooreed6f1d42014-04-04 12:39:26 +0800296 acpi_tb_release_temp_table(&new_table_desc);
Bob Mooref7b004a2012-02-14 18:31:56 +0800297}
298
299/*******************************************************************************
300 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800301 * FUNCTION: acpi_tb_uninstall_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300302 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800303 * PARAMETERS: table_desc - Table descriptor
Bob Mooref3d2e782007-02-02 19:48:18 +0300304 *
305 * RETURN: None
306 *
307 * DESCRIPTION: Delete one internal ACPI table
308 *
309 ******************************************************************************/
310
Lv Zheng7f9fc992014-04-04 12:38:42 +0800311void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300312{
Lv Zheng55829822014-04-04 12:38:18 +0800313
Lv Zheng7f9fc992014-04-04 12:38:42 +0800314 ACPI_FUNCTION_TRACE(tb_uninstall_table);
Lv Zheng55829822014-04-04 12:38:18 +0800315
Lv Zheng7f9fc992014-04-04 12:38:42 +0800316 /* Table must be installed */
317
318 if (!table_desc->address) {
319 return_VOID;
Bob Mooref3d2e782007-02-02 19:48:18 +0300320 }
Lv Zheng55829822014-04-04 12:38:18 +0800321
Lv Zheng7f9fc992014-04-04 12:38:42 +0800322 acpi_tb_invalidate_table(table_desc);
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000323
Lv Zheng7f9fc992014-04-04 12:38:42 +0800324 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
Bob Mooreed6f1d42014-04-04 12:39:26 +0800325 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
Lv Zheng6d3fd3c2015-04-13 11:48:37 +0800326 ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
Bob Mooref3d2e782007-02-02 19:48:18 +0300327 }
328
Lv Zheng7f9fc992014-04-04 12:38:42 +0800329 table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800330 return_VOID;
Bob Mooref3d2e782007-02-02 19:48:18 +0300331}