1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME("tbinstal")
51 /* Local prototypes */
53 acpi_tb_compare_tables(struct acpi_table_desc
*table_desc
, u32 table_index
);
55 /*******************************************************************************
57 * FUNCTION: acpi_tb_compare_tables
59 * PARAMETERS: table_desc - Table 1 descriptor to be compared
60 * table_index - Index of table 2 to be compared
62 * RETURN: TRUE if both tables are identical.
64 * DESCRIPTION: This function compares a table with another table that has
65 * already been installed in the root table list.
67 ******************************************************************************/
70 acpi_tb_compare_tables(struct acpi_table_desc
*table_desc
, u32 table_index
)
72 acpi_status status
= AE_OK
;
74 struct acpi_table_header
*table
;
79 acpi_tb_acquire_table(&acpi_gbl_root_table_list
.tables
[table_index
],
80 &table
, &table_length
, &table_flags
);
81 if (ACPI_FAILURE(status
)) {
86 * Check for a table match on the entire table length,
87 * not just the header.
89 is_identical
= (u8
)((table_desc
->length
!= table_length
||
90 memcmp(table_desc
->pointer
, table
, table_length
)) ?
93 /* Release the acquired table */
95 acpi_tb_release_table(table
, table_length
, table_flags
);
96 return (is_identical
);
99 /*******************************************************************************
101 * FUNCTION: acpi_tb_install_table_with_override
103 * PARAMETERS: new_table_desc - New table descriptor to install
104 * override - Whether override should be performed
105 * table_index - Where the table index is returned
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
114 ******************************************************************************/
117 acpi_tb_install_table_with_override(struct acpi_table_desc
*new_table_desc
,
118 u8 override
, u32
*table_index
)
123 status
= acpi_tb_get_next_table_descriptor(&i
, NULL
);
124 if (ACPI_FAILURE(status
)) {
129 * ACPI Table Override:
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.
136 acpi_tb_override_table(new_table_desc
);
139 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list
.tables
[i
],
140 new_table_desc
->address
,
141 new_table_desc
->flags
,
142 new_table_desc
->pointer
);
144 acpi_tb_print_table_header(new_table_desc
->address
,
145 new_table_desc
->pointer
);
147 /* This synchronizes acpi_gbl_dsdt_index */
151 /* Set the global integer width (based upon revision of the DSDT) */
153 if (i
== acpi_gbl_dsdt_index
) {
154 acpi_ut_set_integer_width(new_table_desc
->pointer
->revision
);
158 /*******************************************************************************
160 * FUNCTION: acpi_tb_install_standard_table
162 * PARAMETERS: address - Address of the table (might be a virtual
163 * address depending on the table_flags)
164 * flags - Flags for the table
165 * reload - Whether reload should be performed
166 * override - Whether override should be performed
167 * table_index - Where the table index is returned
171 * DESCRIPTION: This function is called to verify and install an ACPI table.
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".
177 ******************************************************************************/
180 acpi_tb_install_standard_table(acpi_physical_address address
,
182 u8 reload
, u8 override
, u32
*table_index
)
185 acpi_status status
= AE_OK
;
186 struct acpi_table_desc new_table_desc
;
188 ACPI_FUNCTION_TRACE(tb_install_standard_table
);
190 /* Acquire a temporary table descriptor for validation */
192 status
= acpi_tb_acquire_temp_table(&new_table_desc
, address
, flags
);
193 if (ACPI_FAILURE(status
)) {
195 "Could not acquire table length at %8.8X%8.8X",
196 ACPI_FORMAT_UINT64(address
)));
197 return_ACPI_STATUS(status
);
201 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
202 * be useful for debugging ACPI problems on some machines.
205 acpi_gbl_disable_ssdt_table_install
&&
206 ACPI_COMPARE_NAME(&new_table_desc
.signature
, ACPI_SIG_SSDT
)) {
207 ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
208 new_table_desc
.signature
.ascii
,
209 ACPI_FORMAT_UINT64(address
)));
210 goto release_and_exit
;
213 /* Validate and verify a table before installation */
215 status
= acpi_tb_verify_temp_table(&new_table_desc
, NULL
);
216 if (ACPI_FAILURE(status
)) {
217 goto release_and_exit
;
222 * Validate the incoming table signature.
224 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
225 * 2) We added support for OEMx tables, signature "OEM".
226 * 3) Valid tables were encountered with a null signature, so we just
227 * gave up on validating the signature, (05/2008).
228 * 4) We encountered non-AML tables such as the MADT, which caused
229 * interpreter errors and kernel faults. So now, we once again allow
230 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
232 if ((new_table_desc
.signature
.ascii
[0] != 0x00) &&
234 (&new_table_desc
.signature
, ACPI_SIG_SSDT
))
235 && (strncmp(new_table_desc
.signature
.ascii
, "OEM", 3))) {
236 ACPI_BIOS_ERROR((AE_INFO
,
237 "Table has invalid signature [%4.4s] (0x%8.8X), "
238 "must be SSDT or OEMx",
239 acpi_ut_valid_nameseg(new_table_desc
.
242 new_table_desc
.signature
.
244 new_table_desc
.signature
.integer
));
246 status
= AE_BAD_SIGNATURE
;
247 goto release_and_exit
;
250 /* Check if table is already registered */
252 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
;
255 * Check for a table match on the entire table length,
256 * not just the header.
258 if (!acpi_tb_compare_tables(&new_table_desc
, i
)) {
263 * Note: the current mechanism does not unregister a table if it is
264 * dynamically unloaded. The related namespace entries are deleted,
265 * but the table remains in the root table list.
267 * The assumption here is that the number of different tables that
268 * will be loaded is actually small, and there is minimal overhead
269 * in just keeping the table in case it is needed again.
271 * If this assumption changes in the future (perhaps on large
272 * machines with many table load/unload operations), tables will
273 * need to be unregistered when they are unloaded, and slots in the
274 * root table list should be reused when empty.
276 if (acpi_gbl_root_table_list
.tables
[i
].flags
&
277 ACPI_TABLE_IS_LOADED
) {
279 /* Table is still loaded, this is an error */
281 status
= AE_ALREADY_EXISTS
;
282 goto release_and_exit
;
285 * Table was unloaded, allow it to be reloaded.
286 * As we are going to return AE_OK to the caller, we should
287 * take the responsibility of freeing the input descriptor.
288 * Refill the input descriptor to ensure
289 * acpi_tb_install_table_with_override() can be called again to
290 * indicate the re-installation.
292 acpi_tb_uninstall_table(&new_table_desc
);
294 return_ACPI_STATUS(AE_OK
);
299 /* Add the table to the global root table list */
301 acpi_tb_install_table_with_override(&new_table_desc
, override
,
304 /* Invoke table handler if present */
306 if (acpi_gbl_table_handler
) {
307 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_INSTALL
,
308 new_table_desc
.pointer
,
309 acpi_gbl_table_handler_context
);
314 /* Release the temporary table descriptor */
316 acpi_tb_release_temp_table(&new_table_desc
);
317 return_ACPI_STATUS(status
);
320 /*******************************************************************************
322 * FUNCTION: acpi_tb_override_table
324 * PARAMETERS: old_table_desc - Validated table descriptor to be
329 * DESCRIPTION: Attempt table override by calling the OSL override functions.
330 * Note: If the table is overridden, then the entire new table
331 * is acquired and returned by this function.
332 * Before/after invocation, the table descriptor is in a state
333 * that is "VALIDATED".
335 ******************************************************************************/
337 void acpi_tb_override_table(struct acpi_table_desc
*old_table_desc
)
341 struct acpi_table_desc new_table_desc
;
342 struct acpi_table_header
*table
;
343 acpi_physical_address address
;
346 /* (1) Attempt logical override (returns a logical address) */
348 status
= acpi_os_table_override(old_table_desc
->pointer
, &table
);
349 if (ACPI_SUCCESS(status
) && table
) {
350 acpi_tb_acquire_temp_table(&new_table_desc
,
351 ACPI_PTR_TO_PHYSADDR(table
),
352 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
);
353 override_type
= "Logical";
354 goto finish_override
;
357 /* (2) Attempt physical override (returns a physical address) */
359 status
= acpi_os_physical_table_override(old_table_desc
->pointer
,
361 if (ACPI_SUCCESS(status
) && address
&& length
) {
362 acpi_tb_acquire_temp_table(&new_table_desc
, address
,
363 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
);
364 override_type
= "Physical";
365 goto finish_override
;
368 return; /* There was no override */
372 /* Validate and verify a table before overriding */
374 status
= acpi_tb_verify_temp_table(&new_table_desc
, NULL
);
375 if (ACPI_FAILURE(status
)) {
379 ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
380 " %s table override, new table: 0x%8.8X%8.8X",
381 old_table_desc
->signature
.ascii
,
382 ACPI_FORMAT_UINT64(old_table_desc
->address
),
383 override_type
, ACPI_FORMAT_UINT64(new_table_desc
.address
)));
385 /* We can now uninstall the original table */
387 acpi_tb_uninstall_table(old_table_desc
);
390 * Replace the original table descriptor and keep its state as
393 acpi_tb_init_table_descriptor(old_table_desc
, new_table_desc
.address
,
394 new_table_desc
.flags
,
395 new_table_desc
.pointer
);
396 acpi_tb_validate_temp_table(old_table_desc
);
398 /* Release the temporary table descriptor */
400 acpi_tb_release_temp_table(&new_table_desc
);
403 /*******************************************************************************
405 * FUNCTION: acpi_tb_uninstall_table
407 * PARAMETERS: table_desc - Table descriptor
411 * DESCRIPTION: Delete one internal ACPI table
413 ******************************************************************************/
415 void acpi_tb_uninstall_table(struct acpi_table_desc
*table_desc
)
418 ACPI_FUNCTION_TRACE(tb_uninstall_table
);
420 /* Table must be installed */
422 if (!table_desc
->address
) {
426 acpi_tb_invalidate_table(table_desc
);
428 if ((table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) ==
429 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
) {
430 ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc
->address
));
433 table_desc
->address
= ACPI_PTR_TO_PHYSADDR(NULL
);