1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_TABLES
52 ACPI_MODULE_NAME("tbxfload")
54 /* Local prototypes */
55 static acpi_status acpi_tb_load_namespace(void);
57 /*******************************************************************************
59 * FUNCTION: acpi_load_tables
65 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
67 ******************************************************************************/
69 acpi_status __init acpi_load_tables(void)
73 ACPI_FUNCTION_TRACE(acpi_load_tables);
75 /* Load the namespace from the tables */
77 status = acpi_tb_load_namespace();
78 if (ACPI_FAILURE(status)) {
79 ACPI_EXCEPTION((AE_INFO, status,
80 "While loading namespace from ACPI tables"));
83 return_ACPI_STATUS(status);
86 ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
88 /*******************************************************************************
90 * FUNCTION: acpi_tb_load_namespace
96 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
99 ******************************************************************************/
100 static acpi_status acpi_tb_load_namespace(void)
104 struct acpi_table_header *new_dsdt;
105 u32 tables_loaded = 0;
106 u32 tables_failed = 0;
108 ACPI_FUNCTION_TRACE(tb_load_namespace);
110 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
113 * Load the namespace. The DSDT is required, but any SSDT and
114 * PSDT tables are optional. Verify the DSDT.
116 if (!acpi_gbl_root_table_list.current_table_count ||
118 (acpi_gbl_root_table_list.
119 tables[ACPI_TABLE_INDEX_DSDT].signature),
122 ACPI_FAILURE(acpi_tb_validate_table
123 (&acpi_gbl_root_table_list.
124 tables[ACPI_TABLE_INDEX_DSDT]))) {
125 status = AE_NO_ACPI_TABLES;
126 goto unlock_and_exit;
130 * Save the DSDT pointer for simple access. This is the mapped memory
131 * address. We must take care here because the address of the .Tables
132 * array can change dynamically as tables are loaded at run-time. Note:
133 * .Pointer field is not validated until after call to acpi_tb_validate_table.
136 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer;
139 * Optionally copy the entire DSDT to local memory (instead of simply
140 * mapping it.) There are some BIOSs that corrupt or replace the original
141 * DSDT, creating the need for this option. Default is FALSE, do not copy
144 if (acpi_gbl_copy_dsdt_locally) {
145 new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT);
147 acpi_gbl_DSDT = new_dsdt;
152 * Save the original DSDT header for detection of table corruption
153 * and/or replacement of the DSDT from outside the OS.
155 memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
156 sizeof(struct acpi_table_header));
158 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
160 /* Load and parse tables */
162 status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
163 if (ACPI_FAILURE(status)) {
164 ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
170 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
172 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
173 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
174 if (!acpi_gbl_root_table_list.tables[i].address ||
176 (&(acpi_gbl_root_table_list.tables[i].signature),
180 (acpi_gbl_root_table_list.tables[i].
181 signature), ACPI_SIG_PSDT)
184 (acpi_gbl_root_table_list.tables[i].
185 signature), ACPI_SIG_OSDT))
187 ACPI_FAILURE(acpi_tb_validate_table
188 (&acpi_gbl_root_table_list.tables[i]))) {
192 /* Ignore errors while loading tables, get as many as possible */
194 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
195 status = acpi_ns_load_table(i, acpi_gbl_root_node);
196 if (ACPI_FAILURE(status)) {
197 ACPI_EXCEPTION((AE_INFO, status,
198 "[%4.4s] table load failed",
199 &acpi_gbl_root_table_list.tables[i].
200 signature.ascii[0]));
206 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
209 if (!tables_failed) {
211 "All (%u) ACPI AML tables successfully loaded",
215 "%u ACPI AML tables loaded, %u failed",
216 tables_loaded, tables_failed));
220 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
221 return_ACPI_STATUS(status);
224 /*******************************************************************************
226 * FUNCTION: acpi_install_table
228 * PARAMETERS: address - Address of the ACPI table to be installed.
229 * physical - Whether the address is a physical table
234 * DESCRIPTION: Dynamically install an ACPI table.
235 * Note: This function should only be invoked after
236 * acpi_initialize_tables() and before acpi_load_tables().
238 ******************************************************************************/
241 acpi_install_table(acpi_physical_address address, u8 physical)
247 ACPI_FUNCTION_TRACE(acpi_install_table);
250 flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
252 flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
255 status = acpi_tb_install_standard_table(address, flags,
256 FALSE, FALSE, &table_index);
258 return_ACPI_STATUS(status);
261 ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
263 /*******************************************************************************
265 * FUNCTION: acpi_load_table
267 * PARAMETERS: table - Pointer to a buffer containing the ACPI
268 * table to be loaded.
272 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
273 * be a valid ACPI table with a valid ACPI table header.
274 * Note1: Mainly intended to support hotplug addition of SSDTs.
275 * Note2: Does not copy the incoming table. User is responsible
276 * to ensure that the table is not deleted or unmapped.
278 ******************************************************************************/
279 acpi_status acpi_load_table(struct acpi_table_header *table)
284 ACPI_FUNCTION_TRACE(acpi_load_table);
286 /* Parameter validation */
289 return_ACPI_STATUS(AE_BAD_PARAMETER);
292 /* Must acquire the interpreter lock during this operation */
294 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
295 if (ACPI_FAILURE(status)) {
296 return_ACPI_STATUS(status);
299 /* Install the table and load it into the namespace */
301 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
302 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
304 status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table),
305 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
306 TRUE, FALSE, &table_index);
308 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
309 if (ACPI_FAILURE(status)) {
310 goto unlock_and_exit;
314 * Note: Now table is "INSTALLED", it must be validated before
318 acpi_tb_validate_table(&acpi_gbl_root_table_list.
319 tables[table_index]);
320 if (ACPI_FAILURE(status)) {
321 goto unlock_and_exit;
324 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
326 /* Invoke table handler if present */
328 if (acpi_gbl_table_handler) {
329 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
330 acpi_gbl_table_handler_context);
334 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
335 return_ACPI_STATUS(status);
338 ACPI_EXPORT_SYMBOL(acpi_load_table)
340 /*******************************************************************************
342 * FUNCTION: acpi_unload_parent_table
344 * PARAMETERS: object - Handle to any namespace object owned by
345 * the table to be unloaded
349 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
350 * the table and deletes all namespace objects associated with
351 * that table. Unloading of the DSDT is not allowed.
352 * Note: Mainly intended to support hotplug removal of SSDTs.
354 ******************************************************************************/
355 acpi_status acpi_unload_parent_table(acpi_handle object)
357 struct acpi_namespace_node *node =
358 ACPI_CAST_PTR(struct acpi_namespace_node, object);
359 acpi_status status = AE_NOT_EXIST;
360 acpi_owner_id owner_id;
363 ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
365 /* Parameter validation */
368 return_ACPI_STATUS(AE_BAD_PARAMETER);
372 * The node owner_id is currently the same as the parent table ID.
373 * However, this could change in the future.
375 owner_id = node->owner_id;
378 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
380 return_ACPI_STATUS(AE_TYPE);
383 /* Must acquire the interpreter lock during this operation */
385 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
386 if (ACPI_FAILURE(status)) {
387 return_ACPI_STATUS(status);
390 /* Find the table in the global table list */
392 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
393 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
398 * Allow unload of SSDT and OEMx tables only. Do not allow unload
399 * of the DSDT. No other types of tables should get here, since
400 * only these types can contain AML and thus are the only types
401 * that can create namespace objects.
403 if (ACPI_COMPARE_NAME
404 (acpi_gbl_root_table_list.tables[i].signature.ascii,
410 /* Ensure the table is actually loaded */
412 if (!acpi_tb_is_table_loaded(i)) {
413 status = AE_NOT_EXIST;
417 /* Invoke table handler if present */
419 if (acpi_gbl_table_handler) {
420 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
421 acpi_gbl_root_table_list.
423 acpi_gbl_table_handler_context);
427 * Delete all namespace objects owned by this table. Note that
428 * these objects can appear anywhere in the namespace by virtue
429 * of the AML "Scope" operator. Thus, we need to track ownership
430 * by an ID, not simply a position within the hierarchy.
432 status = acpi_tb_delete_namespace_by_owner(i);
433 if (ACPI_FAILURE(status)) {
437 status = acpi_tb_release_owner_id(i);
438 acpi_tb_set_table_loaded_flag(i, FALSE);
442 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
443 return_ACPI_STATUS(status);
446 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)