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
;
106 ACPI_FUNCTION_TRACE(tb_load_namespace
);
108 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
111 * Load the namespace. The DSDT is required, but any SSDT and
112 * PSDT tables are optional. Verify the DSDT.
114 if (!acpi_gbl_root_table_list
.current_table_count
||
116 (acpi_gbl_root_table_list
.
117 tables
[ACPI_TABLE_INDEX_DSDT
].signature
),
120 ACPI_FAILURE(acpi_tb_validate_table
121 (&acpi_gbl_root_table_list
.
122 tables
[ACPI_TABLE_INDEX_DSDT
]))) {
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.
134 acpi_gbl_root_table_list
.tables
[ACPI_TABLE_INDEX_DSDT
].pointer
;
137 * Optionally copy the entire DSDT to local memory (instead of simply
138 * mapping it.) There are some BIOSs that corrupt or replace the original
139 * DSDT, creating the need for this option. Default is FALSE, do not copy
142 if (acpi_gbl_copy_dsdt_locally
) {
143 new_dsdt
= acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT
);
145 acpi_gbl_DSDT
= new_dsdt
;
150 * Save the original DSDT header for detection of table corruption
151 * and/or replacement of the DSDT from outside the OS.
153 ACPI_MEMCPY(&acpi_gbl_original_dsdt_header
, acpi_gbl_DSDT
,
154 sizeof(struct acpi_table_header
));
156 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
158 /* Load and parse tables */
160 status
= acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT
, acpi_gbl_root_node
);
161 if (ACPI_FAILURE(status
)) {
162 return_ACPI_STATUS(status
);
165 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
167 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
168 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; ++i
) {
169 if (!acpi_gbl_root_table_list
.tables
[i
].address
||
171 (&(acpi_gbl_root_table_list
.tables
[i
].signature
),
175 (acpi_gbl_root_table_list
.tables
[i
].
176 signature
), ACPI_SIG_PSDT
))
178 ACPI_FAILURE(acpi_tb_validate_table
179 (&acpi_gbl_root_table_list
.tables
[i
]))) {
183 /* Ignore errors while loading tables, get as many as possible */
185 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
186 (void)acpi_ns_load_table(i
, acpi_gbl_root_node
);
187 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
190 ACPI_INFO((AE_INFO
, "All ACPI Tables successfully acquired"));
193 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
194 return_ACPI_STATUS(status
);
197 /*******************************************************************************
199 * FUNCTION: acpi_install_table
201 * PARAMETERS: address - Address of the ACPI table to be installed.
202 * physical - Whether the address is a physical table
207 * DESCRIPTION: Dynamically install an ACPI table.
208 * Note: This function should only be invoked after
209 * acpi_initialize_tables() and before acpi_load_tables().
211 ******************************************************************************/
214 acpi_install_table(acpi_physical_address address
, u8 physical
)
220 ACPI_FUNCTION_TRACE(acpi_install_table
);
223 flags
= ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
;
225 flags
= ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
;
228 status
= acpi_tb_install_standard_table(address
, flags
,
229 FALSE
, FALSE
, &table_index
);
231 return_ACPI_STATUS(status
);
234 ACPI_EXPORT_SYMBOL_INIT(acpi_install_table
)
236 /*******************************************************************************
238 * FUNCTION: acpi_load_table
240 * PARAMETERS: table - Pointer to a buffer containing the ACPI
241 * table to be loaded.
245 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
246 * be a valid ACPI table with a valid ACPI table header.
247 * Note1: Mainly intended to support hotplug addition of SSDTs.
248 * Note2: Does not copy the incoming table. User is responsible
249 * to ensure that the table is not deleted or unmapped.
251 ******************************************************************************/
252 acpi_status
acpi_load_table(struct acpi_table_header
*table
)
257 ACPI_FUNCTION_TRACE(acpi_load_table
);
259 /* Parameter validation */
262 return_ACPI_STATUS(AE_BAD_PARAMETER
);
265 /* Must acquire the interpreter lock during this operation */
267 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
268 if (ACPI_FAILURE(status
)) {
269 return_ACPI_STATUS(status
);
272 /* Install the table and load it into the namespace */
274 ACPI_INFO((AE_INFO
, "Host-directed Dynamic ACPI Table Load:"));
275 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
277 status
= acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table
),
278 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
,
279 TRUE
, FALSE
, &table_index
);
281 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
282 if (ACPI_FAILURE(status
)) {
283 goto unlock_and_exit
;
287 * Note: Now table is "INSTALLED", it must be validated before
291 acpi_tb_validate_table(&acpi_gbl_root_table_list
.
292 tables
[table_index
]);
293 if (ACPI_FAILURE(status
)) {
294 goto unlock_and_exit
;
297 status
= acpi_ns_load_table(table_index
, acpi_gbl_root_node
);
299 /* Invoke table handler if present */
301 if (acpi_gbl_table_handler
) {
302 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD
, table
,
303 acpi_gbl_table_handler_context
);
307 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
308 return_ACPI_STATUS(status
);
311 ACPI_EXPORT_SYMBOL(acpi_load_table
)
313 /*******************************************************************************
315 * FUNCTION: acpi_unload_parent_table
317 * PARAMETERS: object - Handle to any namespace object owned by
318 * the table to be unloaded
322 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
323 * the table and deletes all namespace objects associated with
324 * that table. Unloading of the DSDT is not allowed.
325 * Note: Mainly intended to support hotplug removal of SSDTs.
327 ******************************************************************************/
328 acpi_status
acpi_unload_parent_table(acpi_handle object
)
330 struct acpi_namespace_node
*node
=
331 ACPI_CAST_PTR(struct acpi_namespace_node
, object
);
332 acpi_status status
= AE_NOT_EXIST
;
333 acpi_owner_id owner_id
;
336 ACPI_FUNCTION_TRACE(acpi_unload_parent_table
);
338 /* Parameter validation */
341 return_ACPI_STATUS(AE_BAD_PARAMETER
);
345 * The node owner_id is currently the same as the parent table ID.
346 * However, this could change in the future.
348 owner_id
= node
->owner_id
;
351 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
353 return_ACPI_STATUS(AE_TYPE
);
356 /* Must acquire the interpreter lock during this operation */
358 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
359 if (ACPI_FAILURE(status
)) {
360 return_ACPI_STATUS(status
);
363 /* Find the table in the global table list */
365 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; i
++) {
366 if (owner_id
!= acpi_gbl_root_table_list
.tables
[i
].owner_id
) {
371 * Allow unload of SSDT and OEMx tables only. Do not allow unload
372 * of the DSDT. No other types of tables should get here, since
373 * only these types can contain AML and thus are the only types
374 * that can create namespace objects.
376 if (ACPI_COMPARE_NAME
377 (acpi_gbl_root_table_list
.tables
[i
].signature
.ascii
,
383 /* Ensure the table is actually loaded */
385 if (!acpi_tb_is_table_loaded(i
)) {
386 status
= AE_NOT_EXIST
;
390 /* Invoke table handler if present */
392 if (acpi_gbl_table_handler
) {
393 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD
,
394 acpi_gbl_root_table_list
.
396 acpi_gbl_table_handler_context
);
400 * Delete all namespace objects owned by this table. Note that
401 * these objects can appear anywhere in the namespace by virtue
402 * of the AML "Scope" operator. Thus, we need to track ownership
403 * by an ID, not simply a position within the hierarchy.
405 status
= acpi_tb_delete_namespace_by_owner(i
);
406 if (ACPI_FAILURE(status
)) {
410 status
= acpi_tb_release_owner_id(i
);
411 acpi_tb_set_table_loaded_flag(i
, FALSE
);
415 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
416 return_ACPI_STATUS(status
);
419 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table
)