blob: fb4d4e64f8aa2cc17163594cdff72a7ef4273151 [file] [log] [blame]
Bob Moored59b8ec2012-07-16 10:15:36 +08001/******************************************************************************
2 *
3 * Module Name: tbxfload - Table load/unload external interfaces
4 *
5 *****************************************************************************/
6
7/*
David E. Box82a80942015-02-05 15:20:45 +08008 * Copyright (C) 2000 - 2015, Intel Corp.
Bob Moored59b8ec2012-07-16 10:15:36 +08009 * 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
Lv Zheng839e9282013-10-29 09:29:51 +080044#define EXPORT_ACPI_INTERFACES
45
Bob Moored59b8ec2012-07-16 10:15:36 +080046#include <acpi/acpi.h>
47#include "accommon.h"
48#include "acnamesp.h"
49#include "actables.h"
50
51#define _COMPONENT ACPI_TABLES
52ACPI_MODULE_NAME("tbxfload")
53
54/* Local prototypes */
55static acpi_status acpi_tb_load_namespace(void);
56
Bob Moored59b8ec2012-07-16 10:15:36 +080057/*******************************************************************************
58 *
59 * FUNCTION: acpi_load_tables
60 *
61 * PARAMETERS: None
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
66 *
67 ******************************************************************************/
68
Lv Zheng45c9f782013-10-31 09:31:24 +080069acpi_status __init acpi_load_tables(void)
Bob Moored59b8ec2012-07-16 10:15:36 +080070{
71 acpi_status status;
72
73 ACPI_FUNCTION_TRACE(acpi_load_tables);
74
75 /* Load the namespace from the tables */
76
77 status = acpi_tb_load_namespace();
78 if (ACPI_FAILURE(status)) {
79 ACPI_EXCEPTION((AE_INFO, status,
80 "While loading namespace from ACPI tables"));
81 }
82
83 return_ACPI_STATUS(status);
84}
85
Lv Zhengd21f6002013-10-29 09:30:10 +080086ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
Bob Moored59b8ec2012-07-16 10:15:36 +080087
88/*******************************************************************************
89 *
90 * FUNCTION: acpi_tb_load_namespace
91 *
92 * PARAMETERS: None
93 *
94 * RETURN: Status
95 *
96 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
97 * the RSDT/XSDT.
98 *
99 ******************************************************************************/
100static acpi_status acpi_tb_load_namespace(void)
101{
102 acpi_status status;
103 u32 i;
104 struct acpi_table_header *new_dsdt;
Bob Moore4712f712015-08-25 10:28:26 +0800105 u32 tables_loaded = 0;
106 u32 tables_failed = 0;
Bob Moored59b8ec2012-07-16 10:15:36 +0800107
108 ACPI_FUNCTION_TRACE(tb_load_namespace);
109
110 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
111
112 /*
113 * Load the namespace. The DSDT is required, but any SSDT and
114 * PSDT tables are optional. Verify the DSDT.
115 */
116 if (!acpi_gbl_root_table_list.current_table_count ||
117 !ACPI_COMPARE_NAME(&
118 (acpi_gbl_root_table_list.
Lv Zheng8ec3f452015-08-25 10:29:01 +0800119 tables[acpi_gbl_dsdt_index].signature),
Bob Moored59b8ec2012-07-16 10:15:36 +0800120 ACPI_SIG_DSDT)
121 ||
Lv Zheng7f9fc992014-04-04 12:38:42 +0800122 ACPI_FAILURE(acpi_tb_validate_table
Bob Moored59b8ec2012-07-16 10:15:36 +0800123 (&acpi_gbl_root_table_list.
Lv Zheng8ec3f452015-08-25 10:29:01 +0800124 tables[acpi_gbl_dsdt_index]))) {
Bob Moored59b8ec2012-07-16 10:15:36 +0800125 status = AE_NO_ACPI_TABLES;
126 goto unlock_and_exit;
127 }
128
129 /*
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:
Lv Zheng7f9fc992014-04-04 12:38:42 +0800133 * .Pointer field is not validated until after call to acpi_tb_validate_table.
Bob Moored59b8ec2012-07-16 10:15:36 +0800134 */
135 acpi_gbl_DSDT =
Lv Zheng8ec3f452015-08-25 10:29:01 +0800136 acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index].pointer;
Bob Moored59b8ec2012-07-16 10:15:36 +0800137
138 /*
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
142 * the DSDT.
143 */
144 if (acpi_gbl_copy_dsdt_locally) {
Lv Zheng8ec3f452015-08-25 10:29:01 +0800145 new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
Bob Moored59b8ec2012-07-16 10:15:36 +0800146 if (new_dsdt) {
147 acpi_gbl_DSDT = new_dsdt;
148 }
149 }
150
151 /*
152 * Save the original DSDT header for detection of table corruption
153 * and/or replacement of the DSDT from outside the OS.
154 */
Bob Moore4fa46162015-07-01 14:45:11 +0800155 memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
156 sizeof(struct acpi_table_header));
Bob Moored59b8ec2012-07-16 10:15:36 +0800157
158 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
159
160 /* Load and parse tables */
161
Lv Zheng8ec3f452015-08-25 10:29:01 +0800162 status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
Bob Moored59b8ec2012-07-16 10:15:36 +0800163 if (ACPI_FAILURE(status)) {
Bob Moore4712f712015-08-25 10:28:26 +0800164 ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
165 tables_failed++;
166 } else {
167 tables_loaded++;
Bob Moored59b8ec2012-07-16 10:15:36 +0800168 }
169
170 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
171
172 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
173 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
Lv Zhengc04e1fb2015-07-01 14:43:11 +0800174 if (!acpi_gbl_root_table_list.tables[i].address ||
175 (!ACPI_COMPARE_NAME
Bob Moored59b8ec2012-07-16 10:15:36 +0800176 (&(acpi_gbl_root_table_list.tables[i].signature),
177 ACPI_SIG_SSDT)
178 &&
179 !ACPI_COMPARE_NAME(&
180 (acpi_gbl_root_table_list.tables[i].
Bob Moorefe536992015-07-01 14:44:23 +0800181 signature), ACPI_SIG_PSDT)
182 &&
183 !ACPI_COMPARE_NAME(&
184 (acpi_gbl_root_table_list.tables[i].
185 signature), ACPI_SIG_OSDT))
Bob Moored59b8ec2012-07-16 10:15:36 +0800186 ||
Lv Zheng7f9fc992014-04-04 12:38:42 +0800187 ACPI_FAILURE(acpi_tb_validate_table
Bob Moored59b8ec2012-07-16 10:15:36 +0800188 (&acpi_gbl_root_table_list.tables[i]))) {
189 continue;
190 }
191
Bob Moored59b8ec2012-07-16 10:15:36 +0800192 /* Ignore errors while loading tables, get as many as possible */
193
194 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore4712f712015-08-25 10:28:26 +0800195 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]));
201 tables_failed++;
202 } else {
203 tables_loaded++;
204 }
205
Bob Moored59b8ec2012-07-16 10:15:36 +0800206 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
207 }
208
Bob Moore4712f712015-08-25 10:28:26 +0800209 if (!tables_failed) {
210 ACPI_INFO((AE_INFO,
Bob Moore92b21a92015-08-25 10:28:54 +0800211 "%u ACPI AML tables successfully acquired and loaded",
Bob Moore4712f712015-08-25 10:28:26 +0800212 tables_loaded));
213 } else {
214 ACPI_ERROR((AE_INFO,
Bob Moore92b21a92015-08-25 10:28:54 +0800215 "%u ACPI AML tables successfully acquired and loaded, %u failed",
Bob Moore4712f712015-08-25 10:28:26 +0800216 tables_loaded, tables_failed));
217 }
Bob Moored59b8ec2012-07-16 10:15:36 +0800218
Lv Zheng10622bf2013-10-29 09:30:02 +0800219unlock_and_exit:
Bob Moored59b8ec2012-07-16 10:15:36 +0800220 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
221 return_ACPI_STATUS(status);
222}
223
Bob Mooref60d8182012-07-16 10:21:34 +0800224/*******************************************************************************
225 *
Lv Zhengcaf4a152014-04-04 12:39:18 +0800226 * FUNCTION: acpi_install_table
227 *
228 * PARAMETERS: address - Address of the ACPI table to be installed.
229 * physical - Whether the address is a physical table
230 * address or not
231 *
232 * RETURN: Status
233 *
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().
237 *
238 ******************************************************************************/
239
240acpi_status __init
241acpi_install_table(acpi_physical_address address, u8 physical)
242{
243 acpi_status status;
244 u8 flags;
245 u32 table_index;
246
247 ACPI_FUNCTION_TRACE(acpi_install_table);
248
249 if (physical) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800250 flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
Zhang Ruidc002032015-07-01 14:44:37 +0800251 } else {
252 flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
Lv Zhengcaf4a152014-04-04 12:39:18 +0800253 }
254
Bob Mooreed6f1d42014-04-04 12:39:26 +0800255 status = acpi_tb_install_standard_table(address, flags,
256 FALSE, FALSE, &table_index);
Lv Zhengcaf4a152014-04-04 12:39:18 +0800257
258 return_ACPI_STATUS(status);
259}
260
261ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
262
263/*******************************************************************************
264 *
Bob Mooref60d8182012-07-16 10:21:34 +0800265 * FUNCTION: acpi_load_table
266 *
267 * PARAMETERS: table - Pointer to a buffer containing the ACPI
268 * table to be loaded.
269 *
270 * RETURN: Status
271 *
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.
Bob Moore691fda52012-10-31 02:26:23 +0000275 * Note2: Does not copy the incoming table. User is responsible
Bob Mooref60d8182012-07-16 10:21:34 +0800276 * to ensure that the table is not deleted or unmapped.
277 *
278 ******************************************************************************/
Bob Mooref60d8182012-07-16 10:21:34 +0800279acpi_status acpi_load_table(struct acpi_table_header *table)
280{
281 acpi_status status;
Bob Mooref60d8182012-07-16 10:21:34 +0800282 u32 table_index;
283
284 ACPI_FUNCTION_TRACE(acpi_load_table);
285
286 /* Parameter validation */
287
288 if (!table) {
289 return_ACPI_STATUS(AE_BAD_PARAMETER);
290 }
291
Bob Mooref60d8182012-07-16 10:21:34 +0800292 /* Must acquire the interpreter lock during this operation */
293
294 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
295 if (ACPI_FAILURE(status)) {
296 return_ACPI_STATUS(status);
297 }
298
299 /* Install the table and load it into the namespace */
300
301 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800302 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreed6f1d42014-04-04 12:39:26 +0800303
304 status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table),
305 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
306 TRUE, FALSE, &table_index);
307
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800308 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
309 if (ACPI_FAILURE(status)) {
310 goto unlock_and_exit;
311 }
312
313 /*
314 * Note: Now table is "INSTALLED", it must be validated before
315 * using.
316 */
317 status =
318 acpi_tb_validate_table(&acpi_gbl_root_table_list.
319 tables[table_index]);
Bob Mooref60d8182012-07-16 10:21:34 +0800320 if (ACPI_FAILURE(status)) {
321 goto unlock_and_exit;
322 }
323
324 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
325
326 /* Invoke table handler if present */
327
328 if (acpi_gbl_table_handler) {
329 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
330 acpi_gbl_table_handler_context);
331 }
332
Lv Zheng10622bf2013-10-29 09:30:02 +0800333unlock_and_exit:
Bob Mooref60d8182012-07-16 10:21:34 +0800334 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
335 return_ACPI_STATUS(status);
336}
337
338ACPI_EXPORT_SYMBOL(acpi_load_table)
339
340/*******************************************************************************
341 *
342 * FUNCTION: acpi_unload_parent_table
343 *
344 * PARAMETERS: object - Handle to any namespace object owned by
345 * the table to be unloaded
346 *
347 * RETURN: Status
348 *
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.
353 *
354 ******************************************************************************/
355acpi_status acpi_unload_parent_table(acpi_handle object)
356{
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;
361 u32 i;
362
363 ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
364
365 /* Parameter validation */
366
367 if (!object) {
368 return_ACPI_STATUS(AE_BAD_PARAMETER);
369 }
370
371 /*
372 * The node owner_id is currently the same as the parent table ID.
373 * However, this could change in the future.
374 */
375 owner_id = node->owner_id;
376 if (!owner_id) {
377
378 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
379
380 return_ACPI_STATUS(AE_TYPE);
381 }
382
383 /* Must acquire the interpreter lock during this operation */
384
385 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
386 if (ACPI_FAILURE(status)) {
387 return_ACPI_STATUS(status);
388 }
389
390 /* Find the table in the global table list */
391
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) {
394 continue;
395 }
396
397 /*
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.
402 */
403 if (ACPI_COMPARE_NAME
404 (acpi_gbl_root_table_list.tables[i].signature.ascii,
405 ACPI_SIG_DSDT)) {
406 status = AE_TYPE;
407 break;
408 }
409
410 /* Ensure the table is actually loaded */
411
412 if (!acpi_tb_is_table_loaded(i)) {
413 status = AE_NOT_EXIST;
414 break;
415 }
416
417 /* Invoke table handler if present */
418
419 if (acpi_gbl_table_handler) {
420 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
421 acpi_gbl_root_table_list.
422 tables[i].pointer,
423 acpi_gbl_table_handler_context);
424 }
425
426 /*
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.
431 */
432 status = acpi_tb_delete_namespace_by_owner(i);
433 if (ACPI_FAILURE(status)) {
434 break;
435 }
436
437 status = acpi_tb_release_owner_id(i);
438 acpi_tb_set_table_loaded_flag(i, FALSE);
439 break;
440 }
441
442 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
443 return_ACPI_STATUS(status);
444}
445
446ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)