1 /******************************************************************************
2 *
3 * Module Name: tbxfload - Table load/unload external interfaces
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
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.
25 *
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.
29 *
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.
42 */
43
44 #include <linux/export.h>
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acnamesp.h"
48 #include "actables.h"
49
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME("tbxfload")
52
53 /* Local prototypes */
54 static acpi_status acpi_tb_load_namespace(void);
55
56 static int no_auto_ssdt;
57
58 /*******************************************************************************
59 *
60 * FUNCTION: acpi_load_tables
61 *
62 * PARAMETERS: None
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
67 *
68 ******************************************************************************/
69
acpi_load_tables(void)70 acpi_status acpi_load_tables(void)
71 {
72 acpi_status status;
73
74 ACPI_FUNCTION_TRACE(acpi_load_tables);
75
76 /* Load the namespace from the tables */
77
78 status = acpi_tb_load_namespace();
79 if (ACPI_FAILURE(status)) {
80 ACPI_EXCEPTION((AE_INFO, status,
81 "While loading namespace from ACPI tables"));
82 }
83
84 return_ACPI_STATUS(status);
85 }
86
ACPI_EXPORT_SYMBOL(acpi_load_tables)87 ACPI_EXPORT_SYMBOL(acpi_load_tables)
88
89 /*******************************************************************************
90 *
91 * FUNCTION: acpi_tb_load_namespace
92 *
93 * PARAMETERS: None
94 *
95 * RETURN: Status
96 *
97 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
98 * the RSDT/XSDT.
99 *
100 ******************************************************************************/
101 static acpi_status acpi_tb_load_namespace(void)
102 {
103 acpi_status status;
104 u32 i;
105 struct acpi_table_header *new_dsdt;
106
107 ACPI_FUNCTION_TRACE(tb_load_namespace);
108
109 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
110
111 /*
112 * Load the namespace. The DSDT is required, but any SSDT and
113 * PSDT tables are optional. Verify the DSDT.
114 */
115 if (!acpi_gbl_root_table_list.current_table_count ||
116 !ACPI_COMPARE_NAME(&
117 (acpi_gbl_root_table_list.
118 tables[ACPI_TABLE_INDEX_DSDT].signature),
119 ACPI_SIG_DSDT)
120 ||
121 ACPI_FAILURE(acpi_tb_verify_table
122 (&acpi_gbl_root_table_list.
123 tables[ACPI_TABLE_INDEX_DSDT]))) {
124 status = AE_NO_ACPI_TABLES;
125 goto unlock_and_exit;
126 }
127
128 /*
129 * Save the DSDT pointer for simple access. This is the mapped memory
130 * address. We must take care here because the address of the .Tables
131 * array can change dynamically as tables are loaded at run-time. Note:
132 * .Pointer field is not validated until after call to acpi_tb_verify_table.
133 */
134 acpi_gbl_DSDT =
135 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer;
136
137 /*
138 * Optionally copy the entire DSDT to local memory (instead of simply
139 * mapping it.) There are some BIOSs that corrupt or replace the original
140 * DSDT, creating the need for this option. Default is FALSE, do not copy
141 * the DSDT.
142 */
143 if (acpi_gbl_copy_dsdt_locally) {
144 new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT);
145 if (new_dsdt) {
146 acpi_gbl_DSDT = new_dsdt;
147 }
148 }
149
150 /*
151 * Save the original DSDT header for detection of table corruption
152 * and/or replacement of the DSDT from outside the OS.
153 */
154 ACPI_MEMCPY(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
155 sizeof(struct acpi_table_header));
156
157 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
158
159 /* Load and parse tables */
160
161 status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
162 if (ACPI_FAILURE(status)) {
163 return_ACPI_STATUS(status);
164 }
165
166 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
167
168 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
169 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
170 if ((!ACPI_COMPARE_NAME
171 (&(acpi_gbl_root_table_list.tables[i].signature),
172 ACPI_SIG_SSDT)
173 &&
174 !ACPI_COMPARE_NAME(&
175 (acpi_gbl_root_table_list.tables[i].
176 signature), ACPI_SIG_PSDT))
177 ||
178 ACPI_FAILURE(acpi_tb_verify_table
179 (&acpi_gbl_root_table_list.tables[i]))) {
180 continue;
181 }
182
183 if (no_auto_ssdt) {
184 printk(KERN_WARNING "ACPI: SSDT ignored due to \"acpi_no_auto_ssdt\"\n");
185 continue;
186 }
187
188 /* Ignore errors while loading tables, get as many as possible */
189
190 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
191 (void)acpi_ns_load_table(i, acpi_gbl_root_node);
192 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
193 }
194
195 ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired"));
196
197 unlock_and_exit:
198 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
199 return_ACPI_STATUS(status);
200 }
201
202 /*******************************************************************************
203 *
204 * FUNCTION: acpi_load_table
205 *
206 * PARAMETERS: table - Pointer to a buffer containing the ACPI
207 * table to be loaded.
208 *
209 * RETURN: Status
210 *
211 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
212 * be a valid ACPI table with a valid ACPI table header.
213 * Note1: Mainly intended to support hotplug addition of SSDTs.
214 * Note2: Does not copy the incoming table. User is responsible
215 * to ensure that the table is not deleted or unmapped.
216 *
217 ******************************************************************************/
218
acpi_load_table(struct acpi_table_header * table)219 acpi_status acpi_load_table(struct acpi_table_header *table)
220 {
221 acpi_status status;
222 struct acpi_table_desc table_desc;
223 u32 table_index;
224
225 ACPI_FUNCTION_TRACE(acpi_load_table);
226
227 /* Parameter validation */
228
229 if (!table) {
230 return_ACPI_STATUS(AE_BAD_PARAMETER);
231 }
232
233 /* Init local table descriptor */
234
235 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
236 table_desc.address = ACPI_PTR_TO_PHYSADDR(table);
237 table_desc.pointer = table;
238 table_desc.length = table->length;
239 table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
240
241 /* Must acquire the interpreter lock during this operation */
242
243 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
244 if (ACPI_FAILURE(status)) {
245 return_ACPI_STATUS(status);
246 }
247
248 /* Install the table and load it into the namespace */
249
250 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
251 status = acpi_tb_add_table(&table_desc, &table_index);
252 if (ACPI_FAILURE(status)) {
253 goto unlock_and_exit;
254 }
255
256 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
257
258 /* Invoke table handler if present */
259
260 if (acpi_gbl_table_handler) {
261 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
262 acpi_gbl_table_handler_context);
263 }
264
265 unlock_and_exit:
266 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
267 return_ACPI_STATUS(status);
268 }
269
ACPI_EXPORT_SYMBOL(acpi_load_table)270 ACPI_EXPORT_SYMBOL(acpi_load_table)
271
272 /*******************************************************************************
273 *
274 * FUNCTION: acpi_unload_parent_table
275 *
276 * PARAMETERS: object - Handle to any namespace object owned by
277 * the table to be unloaded
278 *
279 * RETURN: Status
280 *
281 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
282 * the table and deletes all namespace objects associated with
283 * that table. Unloading of the DSDT is not allowed.
284 * Note: Mainly intended to support hotplug removal of SSDTs.
285 *
286 ******************************************************************************/
287 acpi_status acpi_unload_parent_table(acpi_handle object)
288 {
289 struct acpi_namespace_node *node =
290 ACPI_CAST_PTR(struct acpi_namespace_node, object);
291 acpi_status status = AE_NOT_EXIST;
292 acpi_owner_id owner_id;
293 u32 i;
294
295 ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
296
297 /* Parameter validation */
298
299 if (!object) {
300 return_ACPI_STATUS(AE_BAD_PARAMETER);
301 }
302
303 /*
304 * The node owner_id is currently the same as the parent table ID.
305 * However, this could change in the future.
306 */
307 owner_id = node->owner_id;
308 if (!owner_id) {
309
310 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
311
312 return_ACPI_STATUS(AE_TYPE);
313 }
314
315 /* Must acquire the interpreter lock during this operation */
316
317 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
318 if (ACPI_FAILURE(status)) {
319 return_ACPI_STATUS(status);
320 }
321
322 /* Find the table in the global table list */
323
324 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
325 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
326 continue;
327 }
328
329 /*
330 * Allow unload of SSDT and OEMx tables only. Do not allow unload
331 * of the DSDT. No other types of tables should get here, since
332 * only these types can contain AML and thus are the only types
333 * that can create namespace objects.
334 */
335 if (ACPI_COMPARE_NAME
336 (acpi_gbl_root_table_list.tables[i].signature.ascii,
337 ACPI_SIG_DSDT)) {
338 status = AE_TYPE;
339 break;
340 }
341
342 /* Ensure the table is actually loaded */
343
344 if (!acpi_tb_is_table_loaded(i)) {
345 status = AE_NOT_EXIST;
346 break;
347 }
348
349 /* Invoke table handler if present */
350
351 if (acpi_gbl_table_handler) {
352 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
353 acpi_gbl_root_table_list.
354 tables[i].pointer,
355 acpi_gbl_table_handler_context);
356 }
357
358 /*
359 * Delete all namespace objects owned by this table. Note that
360 * these objects can appear anywhere in the namespace by virtue
361 * of the AML "Scope" operator. Thus, we need to track ownership
362 * by an ID, not simply a position within the hierarchy.
363 */
364 status = acpi_tb_delete_namespace_by_owner(i);
365 if (ACPI_FAILURE(status)) {
366 break;
367 }
368
369 status = acpi_tb_release_owner_id(i);
370 acpi_tb_set_table_loaded_flag(i, FALSE);
371 break;
372 }
373
374 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
375 return_ACPI_STATUS(status);
376 }
377
ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)378 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)
379
380 static int __init acpi_no_auto_ssdt_setup(char *s) {
381
382 printk(KERN_NOTICE "ACPI: SSDT auto-load disabled\n");
383
384 no_auto_ssdt = 1;
385
386 return 1;
387 }
388
389 __setup("acpi_no_auto_ssdt", acpi_no_auto_ssdt_setup);
390