1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 <linux/export.h>
45 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME("tbxfload")
53 /* Local prototypes */
54 static acpi_status
acpi_tb_load_namespace(void);
56 /*******************************************************************************
58 * FUNCTION: acpi_load_tables
64 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
66 ******************************************************************************/
68 acpi_status
acpi_load_tables(void)
72 ACPI_FUNCTION_TRACE(acpi_load_tables
);
74 /* Load the namespace from the tables */
76 status
= acpi_tb_load_namespace();
77 if (ACPI_FAILURE(status
)) {
78 ACPI_EXCEPTION((AE_INFO
, status
,
79 "While loading namespace from ACPI tables"));
82 return_ACPI_STATUS(status
);
85 ACPI_EXPORT_SYMBOL(acpi_load_tables
)
87 /*******************************************************************************
89 * FUNCTION: acpi_tb_load_namespace
95 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
98 ******************************************************************************/
99 static acpi_status
acpi_tb_load_namespace(void)
103 struct acpi_table_header
*new_dsdt
;
105 ACPI_FUNCTION_TRACE(tb_load_namespace
);
107 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
110 * Load the namespace. The DSDT is required, but any SSDT and
111 * PSDT tables are optional. Verify the DSDT.
113 if (!acpi_gbl_root_table_list
.current_table_count
||
115 (acpi_gbl_root_table_list
.
116 tables
[ACPI_TABLE_INDEX_DSDT
].signature
),
119 ACPI_FAILURE(acpi_tb_verify_table
120 (&acpi_gbl_root_table_list
.
121 tables
[ACPI_TABLE_INDEX_DSDT
]))) {
122 status
= AE_NO_ACPI_TABLES
;
123 goto unlock_and_exit
;
127 * Save the DSDT pointer for simple access. This is the mapped memory
128 * address. We must take care here because the address of the .Tables
129 * array can change dynamically as tables are loaded at run-time. Note:
130 * .Pointer field is not validated until after call to acpi_tb_verify_table.
133 acpi_gbl_root_table_list
.tables
[ACPI_TABLE_INDEX_DSDT
].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
141 if (acpi_gbl_copy_dsdt_locally
) {
142 new_dsdt
= acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_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 ACPI_MEMCPY(&acpi_gbl_original_dsdt_header
, acpi_gbl_DSDT
,
153 sizeof(struct acpi_table_header
));
155 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
157 /* Load and parse tables */
159 status
= acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT
, acpi_gbl_root_node
);
160 if (ACPI_FAILURE(status
)) {
161 return_ACPI_STATUS(status
);
164 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
166 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
167 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; ++i
) {
168 if ((!ACPI_COMPARE_NAME
169 (&(acpi_gbl_root_table_list
.tables
[i
].signature
),
173 (acpi_gbl_root_table_list
.tables
[i
].
174 signature
), ACPI_SIG_PSDT
))
176 ACPI_FAILURE(acpi_tb_verify_table
177 (&acpi_gbl_root_table_list
.tables
[i
]))) {
182 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
183 * be useful for debugging ACPI problems on some machines.
185 if (acpi_gbl_disable_ssdt_table_load
) {
186 ACPI_INFO((AE_INFO
, "Ignoring %4.4s at %p",
187 acpi_gbl_root_table_list
.tables
[i
].signature
.
188 ascii
, ACPI_CAST_PTR(void,
189 acpi_gbl_root_table_list
.
190 tables
[i
].address
)));
194 /* Ignore errors while loading tables, get as many as possible */
196 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
197 (void)acpi_ns_load_table(i
, acpi_gbl_root_node
);
198 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
201 ACPI_INFO((AE_INFO
, "All ACPI Tables successfully acquired"));
204 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
205 return_ACPI_STATUS(status
);
208 /*******************************************************************************
210 * FUNCTION: acpi_load_table
212 * PARAMETERS: table - Pointer to a buffer containing the ACPI
213 * table to be loaded.
217 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
218 * be a valid ACPI table with a valid ACPI table header.
219 * Note1: Mainly intended to support hotplug addition of SSDTs.
220 * Note2: Does not copy the incoming table. User is responsible
221 * to ensure that the table is not deleted or unmapped.
223 ******************************************************************************/
225 acpi_status
acpi_load_table(struct acpi_table_header
*table
)
228 struct acpi_table_desc table_desc
;
231 ACPI_FUNCTION_TRACE(acpi_load_table
);
233 /* Parameter validation */
236 return_ACPI_STATUS(AE_BAD_PARAMETER
);
239 /* Init local table descriptor */
241 ACPI_MEMSET(&table_desc
, 0, sizeof(struct acpi_table_desc
));
242 table_desc
.address
= ACPI_PTR_TO_PHYSADDR(table
);
243 table_desc
.pointer
= table
;
244 table_desc
.length
= table
->length
;
245 table_desc
.flags
= ACPI_TABLE_ORIGIN_UNKNOWN
;
247 /* Must acquire the interpreter lock during this operation */
249 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
250 if (ACPI_FAILURE(status
)) {
251 return_ACPI_STATUS(status
);
254 /* Install the table and load it into the namespace */
256 ACPI_INFO((AE_INFO
, "Host-directed Dynamic ACPI Table Load:"));
257 status
= acpi_tb_add_table(&table_desc
, &table_index
);
258 if (ACPI_FAILURE(status
)) {
259 goto unlock_and_exit
;
262 status
= acpi_ns_load_table(table_index
, acpi_gbl_root_node
);
264 /* Invoke table handler if present */
266 if (acpi_gbl_table_handler
) {
267 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD
, table
,
268 acpi_gbl_table_handler_context
);
272 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
273 return_ACPI_STATUS(status
);
276 ACPI_EXPORT_SYMBOL(acpi_load_table
)
278 /*******************************************************************************
280 * FUNCTION: acpi_unload_parent_table
282 * PARAMETERS: object - Handle to any namespace object owned by
283 * the table to be unloaded
287 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
288 * the table and deletes all namespace objects associated with
289 * that table. Unloading of the DSDT is not allowed.
290 * Note: Mainly intended to support hotplug removal of SSDTs.
292 ******************************************************************************/
293 acpi_status
acpi_unload_parent_table(acpi_handle object
)
295 struct acpi_namespace_node
*node
=
296 ACPI_CAST_PTR(struct acpi_namespace_node
, object
);
297 acpi_status status
= AE_NOT_EXIST
;
298 acpi_owner_id owner_id
;
301 ACPI_FUNCTION_TRACE(acpi_unload_parent_table
);
303 /* Parameter validation */
306 return_ACPI_STATUS(AE_BAD_PARAMETER
);
310 * The node owner_id is currently the same as the parent table ID.
311 * However, this could change in the future.
313 owner_id
= node
->owner_id
;
316 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
318 return_ACPI_STATUS(AE_TYPE
);
321 /* Must acquire the interpreter lock during this operation */
323 status
= acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER
);
324 if (ACPI_FAILURE(status
)) {
325 return_ACPI_STATUS(status
);
328 /* Find the table in the global table list */
330 for (i
= 0; i
< acpi_gbl_root_table_list
.current_table_count
; i
++) {
331 if (owner_id
!= acpi_gbl_root_table_list
.tables
[i
].owner_id
) {
336 * Allow unload of SSDT and OEMx tables only. Do not allow unload
337 * of the DSDT. No other types of tables should get here, since
338 * only these types can contain AML and thus are the only types
339 * that can create namespace objects.
341 if (ACPI_COMPARE_NAME
342 (acpi_gbl_root_table_list
.tables
[i
].signature
.ascii
,
348 /* Ensure the table is actually loaded */
350 if (!acpi_tb_is_table_loaded(i
)) {
351 status
= AE_NOT_EXIST
;
355 /* Invoke table handler if present */
357 if (acpi_gbl_table_handler
) {
358 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD
,
359 acpi_gbl_root_table_list
.
361 acpi_gbl_table_handler_context
);
365 * Delete all namespace objects owned by this table. Note that
366 * these objects can appear anywhere in the namespace by virtue
367 * of the AML "Scope" operator. Thus, we need to track ownership
368 * by an ID, not simply a position within the hierarchy.
370 status
= acpi_tb_delete_namespace_by_owner(i
);
371 if (ACPI_FAILURE(status
)) {
375 status
= acpi_tb_release_owner_id(i
);
376 acpi_tb_set_table_loaded_flag(i
, FALSE
);
380 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER
);
381 return_ACPI_STATUS(status
);
384 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table
)