Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / tbxfload.c
blobbcba993d4dacffff8196a4701ee599849961c6a2
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: tbxfload - Table load/unload external interfaces
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #define EXPORT_ACPI_INTERFACES
12 #include <acpi/acpi.h>
13 #include "accommon.h"
14 #include "acnamesp.h"
15 #include "actables.h"
16 #include "acevents.h"
18 #define _COMPONENT ACPI_TABLES
19 ACPI_MODULE_NAME("tbxfload")
21 /*******************************************************************************
23 * FUNCTION: acpi_load_tables
25 * PARAMETERS: None
27 * RETURN: Status
29 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
31 ******************************************************************************/
32 acpi_status ACPI_INIT_FUNCTION acpi_load_tables(void)
34 acpi_status status;
36 ACPI_FUNCTION_TRACE(acpi_load_tables);
39 * Install the default operation region handlers. These are the
40 * handlers that are defined by the ACPI specification to be
41 * "always accessible" -- namely, system_memory, system_IO, and
42 * PCI_Config. This also means that no _REG methods need to be
43 * run for these address spaces. We need to have these handlers
44 * installed before any AML code can be executed, especially any
45 * module-level code (11/2015).
46 * Note that we allow OSPMs to install their own region handlers
47 * between acpi_initialize_subsystem() and acpi_load_tables() to use
48 * their customized default region handlers.
50 status = acpi_ev_install_region_handlers();
51 if (ACPI_FAILURE(status)) {
52 ACPI_EXCEPTION((AE_INFO, status,
53 "During Region initialization"));
54 return_ACPI_STATUS(status);
57 /* Load the namespace from the tables */
59 status = acpi_tb_load_namespace();
61 /* Don't let single failures abort the load */
63 if (status == AE_CTRL_TERMINATE) {
64 status = AE_OK;
67 if (ACPI_FAILURE(status)) {
68 ACPI_EXCEPTION((AE_INFO, status,
69 "While loading namespace from ACPI tables"));
73 * Initialize the objects in the namespace that remain uninitialized.
74 * This runs the executable AML that may be part of the declaration of
75 * these name objects:
76 * operation_regions, buffer_fields, Buffers, and Packages.
79 status = acpi_ns_initialize_objects();
80 if (ACPI_SUCCESS(status)) {
81 acpi_gbl_namespace_initialized = TRUE;
84 return_ACPI_STATUS(status);
87 ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
89 /*******************************************************************************
91 * FUNCTION: acpi_tb_load_namespace
93 * PARAMETERS: None
95 * RETURN: Status
97 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
98 * the RSDT/XSDT.
100 ******************************************************************************/
101 acpi_status acpi_tb_load_namespace(void)
103 acpi_status status;
104 u32 i;
105 struct acpi_table_header *new_dsdt;
106 struct acpi_table_desc *table;
107 u32 tables_loaded = 0;
108 u32 tables_failed = 0;
110 ACPI_FUNCTION_TRACE(tb_load_namespace);
112 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
115 * Load the namespace. The DSDT is required, but any SSDT and
116 * PSDT tables are optional. Verify the DSDT.
118 table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index];
120 if (!acpi_gbl_root_table_list.current_table_count ||
121 !ACPI_COMPARE_NAMESEG(table->signature.ascii, ACPI_SIG_DSDT) ||
122 ACPI_FAILURE(acpi_tb_validate_table(table))) {
123 status = AE_NO_ACPI_TABLES;
124 goto unlock_and_exit;
128 * Save the DSDT pointer for simple access. This is the mapped memory
129 * address. We must take care here because the address of the .Tables
130 * array can change dynamically as tables are loaded at run-time. Note:
131 * .Pointer field is not validated until after call to acpi_tb_validate_table.
133 acpi_gbl_DSDT = table->pointer;
136 * Optionally copy the entire DSDT to local memory (instead of simply
137 * mapping it.) There are some BIOSs that corrupt or replace the original
138 * DSDT, creating the need for this option. Default is FALSE, do not copy
139 * the DSDT.
141 if (acpi_gbl_copy_dsdt_locally) {
142 new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
143 if (new_dsdt) {
144 acpi_gbl_DSDT = new_dsdt;
149 * Save the original DSDT header for detection of table corruption
150 * and/or replacement of the DSDT from outside the OS.
152 memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
153 sizeof(struct acpi_table_header));
155 /* Load and parse tables */
157 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
158 status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
159 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
160 if (ACPI_FAILURE(status)) {
161 ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
162 tables_failed++;
163 } else {
164 tables_loaded++;
167 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
169 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
170 table = &acpi_gbl_root_table_list.tables[i];
172 if (!table->address ||
173 (!ACPI_COMPARE_NAMESEG
174 (table->signature.ascii, ACPI_SIG_SSDT)
175 && !ACPI_COMPARE_NAMESEG(table->signature.ascii,
176 ACPI_SIG_PSDT)
177 && !ACPI_COMPARE_NAMESEG(table->signature.ascii,
178 ACPI_SIG_OSDT))
179 || ACPI_FAILURE(acpi_tb_validate_table(table))) {
180 continue;
183 /* Ignore errors while loading tables, get as many as possible */
185 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
186 status = acpi_ns_load_table(i, acpi_gbl_root_node);
187 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
188 if (ACPI_FAILURE(status)) {
189 ACPI_EXCEPTION((AE_INFO, status,
190 "(%4.4s:%8.8s) while loading table",
191 table->signature.ascii,
192 table->pointer->oem_table_id));
194 tables_failed++;
196 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
197 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
198 table->signature.ascii,
199 table->pointer->oem_table_id));
200 } else {
201 tables_loaded++;
205 if (!tables_failed) {
206 ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded", tables_loaded));
207 } else {
208 ACPI_ERROR((AE_INFO,
209 "%u table load failures, %u successful",
210 tables_failed, tables_loaded));
212 /* Indicate at least one failure */
214 status = AE_CTRL_TERMINATE;
217 #ifdef ACPI_APPLICATION
218 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "\n"));
219 #endif
221 unlock_and_exit:
222 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
223 return_ACPI_STATUS(status);
226 /*******************************************************************************
228 * FUNCTION: acpi_install_table
230 * PARAMETERS: address - Address of the ACPI table to be installed.
231 * physical - Whether the address is a physical table
232 * address or not
234 * RETURN: Status
236 * DESCRIPTION: Dynamically install an ACPI table.
237 * Note: This function should only be invoked after
238 * acpi_initialize_tables() and before acpi_load_tables().
240 ******************************************************************************/
242 acpi_status ACPI_INIT_FUNCTION
243 acpi_install_table(acpi_physical_address address, u8 physical)
245 acpi_status status;
246 u8 flags;
247 u32 table_index;
249 ACPI_FUNCTION_TRACE(acpi_install_table);
251 if (physical) {
252 flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
253 } else {
254 flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
257 status = acpi_tb_install_standard_table(address, flags,
258 FALSE, FALSE, &table_index);
260 return_ACPI_STATUS(status);
263 ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
265 /*******************************************************************************
267 * FUNCTION: acpi_load_table
269 * PARAMETERS: table - Pointer to a buffer containing the ACPI
270 * table to be loaded.
271 * table_idx - Pointer to a u32 for storing the table
272 * index, might be NULL
274 * RETURN: Status
276 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
277 * be a valid ACPI table with a valid ACPI table header.
278 * Note1: Mainly intended to support hotplug addition of SSDTs.
279 * Note2: Does not copy the incoming table. User is responsible
280 * to ensure that the table is not deleted or unmapped.
282 ******************************************************************************/
283 acpi_status acpi_load_table(struct acpi_table_header *table, u32 *table_idx)
285 acpi_status status;
286 u32 table_index;
288 ACPI_FUNCTION_TRACE(acpi_load_table);
290 /* Parameter validation */
292 if (!table) {
293 return_ACPI_STATUS(AE_BAD_PARAMETER);
296 /* Install the table and load it into the namespace */
298 ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
299 status = acpi_tb_install_and_load_table(ACPI_PTR_TO_PHYSADDR(table),
300 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
301 FALSE, &table_index);
302 if (table_idx) {
303 *table_idx = table_index;
306 if (ACPI_SUCCESS(status)) {
308 /* Complete the initialization/resolution of new objects */
310 acpi_ns_initialize_objects();
313 return_ACPI_STATUS(status);
316 ACPI_EXPORT_SYMBOL(acpi_load_table)
318 /*******************************************************************************
320 * FUNCTION: acpi_unload_parent_table
322 * PARAMETERS: object - Handle to any namespace object owned by
323 * the table to be unloaded
325 * RETURN: Status
327 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
328 * the table and deletes all namespace objects associated with
329 * that table. Unloading of the DSDT is not allowed.
330 * Note: Mainly intended to support hotplug removal of SSDTs.
332 ******************************************************************************/
333 acpi_status acpi_unload_parent_table(acpi_handle object)
335 struct acpi_namespace_node *node =
336 ACPI_CAST_PTR(struct acpi_namespace_node, object);
337 acpi_status status = AE_NOT_EXIST;
338 acpi_owner_id owner_id;
339 u32 i;
341 ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
343 /* Parameter validation */
345 if (!object) {
346 return_ACPI_STATUS(AE_BAD_PARAMETER);
350 * The node owner_id is currently the same as the parent table ID.
351 * However, this could change in the future.
353 owner_id = node->owner_id;
354 if (!owner_id) {
356 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
358 return_ACPI_STATUS(AE_TYPE);
361 /* Must acquire the table lock during this operation */
363 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
364 if (ACPI_FAILURE(status)) {
365 return_ACPI_STATUS(status);
368 /* Find the table in the global table list */
370 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
371 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
372 continue;
376 * Allow unload of SSDT and OEMx tables only. Do not allow unload
377 * of the DSDT. No other types of tables should get here, since
378 * only these types can contain AML and thus are the only types
379 * that can create namespace objects.
381 if (ACPI_COMPARE_NAMESEG
382 (acpi_gbl_root_table_list.tables[i].signature.ascii,
383 ACPI_SIG_DSDT)) {
384 status = AE_TYPE;
385 break;
388 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
389 status = acpi_tb_unload_table(i);
390 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
391 break;
394 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
395 return_ACPI_STATUS(status);
398 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)
399 /*******************************************************************************
401 * FUNCTION: acpi_unload_table
403 * PARAMETERS: table_index - Index as returned by acpi_load_table
405 * RETURN: Status
407 * DESCRIPTION: Via the table_index representing an SSDT or OEMx table, unloads
408 * the table and deletes all namespace objects associated with
409 * that table. Unloading of the DSDT is not allowed.
410 * Note: Mainly intended to support hotplug removal of SSDTs.
412 ******************************************************************************/
413 acpi_status acpi_unload_table(u32 table_index)
415 acpi_status status;
417 ACPI_FUNCTION_TRACE(acpi_unload_table);
419 if (table_index == 1) {
421 /* table_index==1 means DSDT is the owner. DSDT cannot be unloaded */
423 return_ACPI_STATUS(AE_TYPE);
426 status = acpi_tb_unload_table(table_index);
427 return_ACPI_STATUS(status);
430 ACPI_EXPORT_SYMBOL(acpi_unload_table)