1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: tbinstal - ACPI table installation and removal
6 * Copyright (C) 2000 - 2023, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
14 #define _COMPONENT ACPI_TABLES
15 ACPI_MODULE_NAME("tbinstal")
17 /*******************************************************************************
19 * FUNCTION: acpi_tb_install_table_with_override
21 * PARAMETERS: new_table_desc - New table descriptor to install
22 * override - Whether override should be performed
23 * table_index - Where the table index is returned
27 * DESCRIPTION: Install an ACPI table into the global data structure. The
28 * table override mechanism is called to allow the host
29 * OS to replace any table before it is installed in the root
32 ******************************************************************************/
34 acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
35 u8 override, u32 *table_index)
40 status = acpi_tb_get_next_table_descriptor(&i, NULL);
41 if (ACPI_FAILURE(status)) {
46 * ACPI Table Override:
48 * Before we install the table, let the host OS override it with a new
49 * one if desired. Any table within the RSDT/XSDT can be replaced,
50 * including the DSDT which is pointed to by the FADT.
53 acpi_tb_override_table(new_table_desc);
56 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
57 new_table_desc->address,
58 new_table_desc->flags,
59 new_table_desc->pointer);
61 acpi_tb_print_table_header(new_table_desc->address,
62 new_table_desc->pointer);
64 /* This synchronizes acpi_gbl_dsdt_index */
68 /* Set the global integer width (based upon revision of the DSDT) */
70 if (i == acpi_gbl_dsdt_index) {
71 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
75 /*******************************************************************************
77 * FUNCTION: acpi_tb_install_standard_table
79 * PARAMETERS: address - Address of the table (might be a virtual
80 * address depending on the table_flags)
81 * flags - Flags for the table
82 * table - Pointer to the table (required for virtual
83 * origins, optional for physical)
84 * reload - Whether reload should be performed
85 * override - Whether override should be performed
86 * table_index - Where the table index is returned
90 * DESCRIPTION: This function is called to verify and install an ACPI table.
91 * When this function is called by "Load" or "LoadTable" opcodes,
92 * or by acpi_load_table() API, the "Reload" parameter is set.
93 * After successfully returning from this function, table is
94 * "INSTALLED" but not "VALIDATED".
96 ******************************************************************************/
99 acpi_tb_install_standard_table(acpi_physical_address address,
101 struct acpi_table_header *table,
102 u8 reload, u8 override, u32 *table_index)
105 acpi_status status = AE_OK;
106 struct acpi_table_desc new_table_desc;
108 ACPI_FUNCTION_TRACE(tb_install_standard_table);
110 /* Acquire a temporary table descriptor for validation */
113 acpi_tb_acquire_temp_table(&new_table_desc, address, flags, table);
114 if (ACPI_FAILURE(status)) {
116 "Could not acquire table length at %8.8X%8.8X",
117 ACPI_FORMAT_UINT64(address)));
118 return_ACPI_STATUS(status);
122 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
123 * be useful for debugging ACPI problems on some machines.
126 acpi_gbl_disable_ssdt_table_install &&
127 ACPI_COMPARE_NAMESEG(&new_table_desc.signature, ACPI_SIG_SSDT)) {
128 ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
129 new_table_desc.signature.ascii,
130 ACPI_FORMAT_UINT64(address)));
131 goto release_and_exit;
134 /* Acquire the table lock */
136 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
138 /* Validate and verify a table before installation */
140 status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i);
141 if (ACPI_FAILURE(status)) {
142 if (status == AE_CTRL_TERMINATE) {
144 * Table was unloaded, allow it to be reloaded.
145 * As we are going to return AE_OK to the caller, we should
146 * take the responsibility of freeing the input descriptor.
147 * Refill the input descriptor to ensure
148 * acpi_tb_install_table_with_override() can be called again to
149 * indicate the re-installation.
151 acpi_tb_uninstall_table(&new_table_desc);
152 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
154 return_ACPI_STATUS(AE_OK);
156 goto unlock_and_exit;
159 /* Add the table to the global root table list */
161 acpi_tb_install_table_with_override(&new_table_desc, override,
164 /* Invoke table handler */
166 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
167 acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
168 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
172 /* Release the table lock */
174 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
178 /* Release the temporary table descriptor */
180 acpi_tb_release_temp_table(&new_table_desc);
181 return_ACPI_STATUS(status);
184 /*******************************************************************************
186 * FUNCTION: acpi_tb_override_table
188 * PARAMETERS: old_table_desc - Validated table descriptor to be
193 * DESCRIPTION: Attempt table override by calling the OSL override functions.
194 * Note: If the table is overridden, then the entire new table
195 * is acquired and returned by this function.
196 * Before/after invocation, the table descriptor is in a state
197 * that is "VALIDATED".
199 ******************************************************************************/
201 void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
204 struct acpi_table_desc new_table_desc;
205 struct acpi_table_header *table;
206 acpi_physical_address address;
208 ACPI_ERROR_ONLY(char *override_type);
210 /* (1) Attempt logical override (returns a logical address) */
212 status = acpi_os_table_override(old_table_desc->pointer, &table);
213 if (ACPI_SUCCESS(status) && table) {
214 acpi_tb_acquire_temp_table(&new_table_desc,
215 ACPI_PTR_TO_PHYSADDR(table),
216 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
218 ACPI_ERROR_ONLY(override_type = "Logical");
219 goto finish_override;
222 /* (2) Attempt physical override (returns a physical address) */
224 status = acpi_os_physical_table_override(old_table_desc->pointer,
226 if (ACPI_SUCCESS(status) && address && length) {
227 acpi_tb_acquire_temp_table(&new_table_desc, address,
228 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
230 ACPI_ERROR_ONLY(override_type = "Physical");
231 goto finish_override;
234 return; /* There was no override */
239 * Validate and verify a table before overriding, no nested table
240 * duplication check as it's too complicated and unnecessary.
242 status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL);
243 if (ACPI_FAILURE(status)) {
247 ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
248 " %s table override, new table: 0x%8.8X%8.8X",
249 old_table_desc->signature.ascii,
250 ACPI_FORMAT_UINT64(old_table_desc->address),
251 override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
253 /* We can now uninstall the original table */
255 acpi_tb_uninstall_table(old_table_desc);
258 * Replace the original table descriptor and keep its state as
261 acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
262 new_table_desc.flags,
263 new_table_desc.pointer);
264 acpi_tb_validate_temp_table(old_table_desc);
266 /* Release the temporary table descriptor */
268 acpi_tb_release_temp_table(&new_table_desc);
271 /*******************************************************************************
273 * FUNCTION: acpi_tb_uninstall_table
275 * PARAMETERS: table_desc - Table descriptor
279 * DESCRIPTION: Delete one internal ACPI table
281 ******************************************************************************/
283 void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
286 ACPI_FUNCTION_TRACE(tb_uninstall_table);
288 /* Table must be installed */
290 if (!table_desc->address) {
294 acpi_tb_invalidate_table(table_desc);
296 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
297 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
298 ACPI_FREE(table_desc->pointer);
299 table_desc->pointer = NULL;
302 table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);