Linux 3.12.49
[linux/fpc-iii.git] / drivers / acpi / acpica / tbxfload.c
blob981631717e476a55b05382124f626f3ab5f5ac8f
1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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>
46 #include "accommon.h"
47 #include "acnamesp.h"
48 #include "actables.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
60 * PARAMETERS: None
62 * RETURN: Status
64 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
66 ******************************************************************************/
68 acpi_status acpi_load_tables(void)
70 acpi_status status;
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
91 * PARAMETERS: None
93 * RETURN: Status
95 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
96 * the RSDT/XSDT.
98 ******************************************************************************/
99 static acpi_status acpi_tb_load_namespace(void)
101 acpi_status status;
102 u32 i;
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 ||
114 !ACPI_COMPARE_NAME(&
115 (acpi_gbl_root_table_list.
116 tables[ACPI_TABLE_INDEX_DSDT].signature),
117 ACPI_SIG_DSDT)
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.
132 acpi_gbl_DSDT =
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
139 * the DSDT.
141 if (acpi_gbl_copy_dsdt_locally) {
142 new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT);
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 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),
170 ACPI_SIG_SSDT)
172 !ACPI_COMPARE_NAME(&
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]))) {
178 continue;
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 %8.8X%8.8X",
187 acpi_gbl_root_table_list.tables[i].signature.
188 ascii, ACPI_FORMAT_UINT64(acpi_gbl_root_table_list.
189 tables[i].address)));
190 continue;
193 /* Ignore errors while loading tables, get as many as possible */
195 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
196 (void)acpi_ns_load_table(i, acpi_gbl_root_node);
197 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
200 ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired"));
202 unlock_and_exit:
203 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
204 return_ACPI_STATUS(status);
207 /*******************************************************************************
209 * FUNCTION: acpi_load_table
211 * PARAMETERS: table - Pointer to a buffer containing the ACPI
212 * table to be loaded.
214 * RETURN: Status
216 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
217 * be a valid ACPI table with a valid ACPI table header.
218 * Note1: Mainly intended to support hotplug addition of SSDTs.
219 * Note2: Does not copy the incoming table. User is responsible
220 * to ensure that the table is not deleted or unmapped.
222 ******************************************************************************/
224 acpi_status acpi_load_table(struct acpi_table_header *table)
226 acpi_status status;
227 struct acpi_table_desc table_desc;
228 u32 table_index;
230 ACPI_FUNCTION_TRACE(acpi_load_table);
232 /* Parameter validation */
234 if (!table) {
235 return_ACPI_STATUS(AE_BAD_PARAMETER);
238 /* Init local table descriptor */
240 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
241 table_desc.address = ACPI_PTR_TO_PHYSADDR(table);
242 table_desc.pointer = table;
243 table_desc.length = table->length;
244 table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
246 /* Must acquire the interpreter lock during this operation */
248 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
249 if (ACPI_FAILURE(status)) {
250 return_ACPI_STATUS(status);
253 /* Install the table and load it into the namespace */
255 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
256 status = acpi_tb_add_table(&table_desc, &table_index);
257 if (ACPI_FAILURE(status)) {
258 goto unlock_and_exit;
261 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
263 /* Invoke table handler if present */
265 if (acpi_gbl_table_handler) {
266 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
267 acpi_gbl_table_handler_context);
270 unlock_and_exit:
271 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
272 return_ACPI_STATUS(status);
275 ACPI_EXPORT_SYMBOL(acpi_load_table)
277 /*******************************************************************************
279 * FUNCTION: acpi_unload_parent_table
281 * PARAMETERS: object - Handle to any namespace object owned by
282 * the table to be unloaded
284 * RETURN: Status
286 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
287 * the table and deletes all namespace objects associated with
288 * that table. Unloading of the DSDT is not allowed.
289 * Note: Mainly intended to support hotplug removal of SSDTs.
291 ******************************************************************************/
292 acpi_status acpi_unload_parent_table(acpi_handle object)
294 struct acpi_namespace_node *node =
295 ACPI_CAST_PTR(struct acpi_namespace_node, object);
296 acpi_status status = AE_NOT_EXIST;
297 acpi_owner_id owner_id;
298 u32 i;
300 ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
302 /* Parameter validation */
304 if (!object) {
305 return_ACPI_STATUS(AE_BAD_PARAMETER);
309 * The node owner_id is currently the same as the parent table ID.
310 * However, this could change in the future.
312 owner_id = node->owner_id;
313 if (!owner_id) {
315 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
317 return_ACPI_STATUS(AE_TYPE);
320 /* Must acquire the interpreter lock during this operation */
322 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
323 if (ACPI_FAILURE(status)) {
324 return_ACPI_STATUS(status);
327 /* Find the table in the global table list */
329 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
330 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
331 continue;
335 * Allow unload of SSDT and OEMx tables only. Do not allow unload
336 * of the DSDT. No other types of tables should get here, since
337 * only these types can contain AML and thus are the only types
338 * that can create namespace objects.
340 if (ACPI_COMPARE_NAME
341 (acpi_gbl_root_table_list.tables[i].signature.ascii,
342 ACPI_SIG_DSDT)) {
343 status = AE_TYPE;
344 break;
347 /* Ensure the table is actually loaded */
349 if (!acpi_tb_is_table_loaded(i)) {
350 status = AE_NOT_EXIST;
351 break;
354 /* Invoke table handler if present */
356 if (acpi_gbl_table_handler) {
357 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
358 acpi_gbl_root_table_list.
359 tables[i].pointer,
360 acpi_gbl_table_handler_context);
364 * Delete all namespace objects owned by this table. Note that
365 * these objects can appear anywhere in the namespace by virtue
366 * of the AML "Scope" operator. Thus, we need to track ownership
367 * by an ID, not simply a position within the hierarchy.
369 status = acpi_tb_delete_namespace_by_owner(i);
370 if (ACPI_FAILURE(status)) {
371 break;
374 status = acpi_tb_release_owner_id(i);
375 acpi_tb_set_table_loaded_flag(i, FALSE);
376 break;
379 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
380 return_ACPI_STATUS(status);
383 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)