Commit | Line | Data |
---|---|---|
d59b8ecd BM |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbxfload - Table load/unload external interfaces | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
82a80941 | 8 | * Copyright (C) 2000 - 2015, Intel Corp. |
d59b8ecd BM |
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 | ||
839e928f LZ |
44 | #define EXPORT_ACPI_INTERFACES |
45 | ||
d59b8ecd BM |
46 | #include <acpi/acpi.h> |
47 | #include "accommon.h" | |
48 | #include "acnamesp.h" | |
49 | #include "actables.h" | |
50 | ||
51 | #define _COMPONENT ACPI_TABLES | |
52 | ACPI_MODULE_NAME("tbxfload") | |
53 | ||
54 | /* Local prototypes */ | |
55 | static acpi_status acpi_tb_load_namespace(void); | |
56 | ||
d59b8ecd BM |
57 | /******************************************************************************* |
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 | ||
45c9f78b | 69 | acpi_status __init acpi_load_tables(void) |
d59b8ecd BM |
70 | { |
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 | ||
d21f600b | 86 | ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables) |
d59b8ecd BM |
87 | |
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 | ******************************************************************************/ | |
100 | static acpi_status acpi_tb_load_namespace(void) | |
101 | { | |
102 | acpi_status status; | |
103 | u32 i; | |
104 | struct acpi_table_header *new_dsdt; | |
105 | ||
106 | ACPI_FUNCTION_TRACE(tb_load_namespace); | |
107 | ||
108 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | |
109 | ||
110 | /* | |
111 | * Load the namespace. The DSDT is required, but any SSDT and | |
112 | * PSDT tables are optional. Verify the DSDT. | |
113 | */ | |
114 | if (!acpi_gbl_root_table_list.current_table_count || | |
115 | !ACPI_COMPARE_NAME(& | |
116 | (acpi_gbl_root_table_list. | |
117 | tables[ACPI_TABLE_INDEX_DSDT].signature), | |
118 | ACPI_SIG_DSDT) | |
119 | || | |
7f9fc99c | 120 | ACPI_FAILURE(acpi_tb_validate_table |
d59b8ecd BM |
121 | (&acpi_gbl_root_table_list. |
122 | tables[ACPI_TABLE_INDEX_DSDT]))) { | |
123 | status = AE_NO_ACPI_TABLES; | |
124 | goto unlock_and_exit; | |
125 | } | |
126 | ||
127 | /* | |
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: | |
7f9fc99c | 131 | * .Pointer field is not validated until after call to acpi_tb_validate_table. |
d59b8ecd BM |
132 | */ |
133 | acpi_gbl_DSDT = | |
134 | acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer; | |
135 | ||
136 | /* | |
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 | |
140 | * the DSDT. | |
141 | */ | |
142 | if (acpi_gbl_copy_dsdt_locally) { | |
143 | new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT); | |
144 | if (new_dsdt) { | |
145 | acpi_gbl_DSDT = new_dsdt; | |
146 | } | |
147 | } | |
148 | ||
149 | /* | |
150 | * Save the original DSDT header for detection of table corruption | |
151 | * and/or replacement of the DSDT from outside the OS. | |
152 | */ | |
4fa4616e BM |
153 | memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT, |
154 | sizeof(struct acpi_table_header)); | |
d59b8ecd BM |
155 | |
156 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); | |
157 | ||
158 | /* Load and parse tables */ | |
159 | ||
160 | status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node); | |
161 | if (ACPI_FAILURE(status)) { | |
162 | return_ACPI_STATUS(status); | |
163 | } | |
164 | ||
165 | /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */ | |
166 | ||
167 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | |
168 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { | |
c04e1fb4 LZ |
169 | if (!acpi_gbl_root_table_list.tables[i].address || |
170 | (!ACPI_COMPARE_NAME | |
d59b8ecd BM |
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]. | |
fe536995 BM |
176 | signature), ACPI_SIG_PSDT) |
177 | && | |
178 | !ACPI_COMPARE_NAME(& | |
179 | (acpi_gbl_root_table_list.tables[i]. | |
180 | signature), ACPI_SIG_OSDT)) | |
d59b8ecd | 181 | || |
7f9fc99c | 182 | ACPI_FAILURE(acpi_tb_validate_table |
d59b8ecd BM |
183 | (&acpi_gbl_root_table_list.tables[i]))) { |
184 | continue; | |
185 | } | |
186 | ||
d59b8ecd BM |
187 | /* Ignore errors while loading tables, get as many as possible */ |
188 | ||
189 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); | |
190 | (void)acpi_ns_load_table(i, acpi_gbl_root_node); | |
191 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | |
192 | } | |
193 | ||
3e5621a7 | 194 | ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired")); |
d59b8ecd | 195 | |
10622bf8 | 196 | unlock_and_exit: |
d59b8ecd BM |
197 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
198 | return_ACPI_STATUS(status); | |
199 | } | |
200 | ||
caf4a15c LZ |
201 | /******************************************************************************* |
202 | * | |
203 | * FUNCTION: acpi_install_table | |
204 | * | |
205 | * PARAMETERS: address - Address of the ACPI table to be installed. | |
206 | * physical - Whether the address is a physical table | |
207 | * address or not | |
208 | * | |
209 | * RETURN: Status | |
210 | * | |
211 | * DESCRIPTION: Dynamically install an ACPI table. | |
212 | * Note: This function should only be invoked after | |
213 | * acpi_initialize_tables() and before acpi_load_tables(). | |
214 | * | |
215 | ******************************************************************************/ | |
216 | ||
217 | acpi_status __init | |
218 | acpi_install_table(acpi_physical_address address, u8 physical) | |
219 | { | |
220 | acpi_status status; | |
221 | u8 flags; | |
222 | u32 table_index; | |
223 | ||
224 | ACPI_FUNCTION_TRACE(acpi_install_table); | |
225 | ||
226 | if (physical) { | |
ed6f1d44 | 227 | flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL; |
dc00203b ZR |
228 | } else { |
229 | flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL; | |
caf4a15c LZ |
230 | } |
231 | ||
ed6f1d44 BM |
232 | status = acpi_tb_install_standard_table(address, flags, |
233 | FALSE, FALSE, &table_index); | |
caf4a15c LZ |
234 | |
235 | return_ACPI_STATUS(status); | |
236 | } | |
237 | ||
238 | ACPI_EXPORT_SYMBOL_INIT(acpi_install_table) | |
239 | ||
f60d8181 BM |
240 | /******************************************************************************* |
241 | * | |
242 | * FUNCTION: acpi_load_table | |
243 | * | |
244 | * PARAMETERS: table - Pointer to a buffer containing the ACPI | |
245 | * table to be loaded. | |
246 | * | |
247 | * RETURN: Status | |
248 | * | |
249 | * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must | |
250 | * be a valid ACPI table with a valid ACPI table header. | |
251 | * Note1: Mainly intended to support hotplug addition of SSDTs. | |
691fda50 | 252 | * Note2: Does not copy the incoming table. User is responsible |
f60d8181 BM |
253 | * to ensure that the table is not deleted or unmapped. |
254 | * | |
255 | ******************************************************************************/ | |
f60d8181 BM |
256 | acpi_status acpi_load_table(struct acpi_table_header *table) |
257 | { | |
258 | acpi_status status; | |
f60d8181 BM |
259 | u32 table_index; |
260 | ||
261 | ACPI_FUNCTION_TRACE(acpi_load_table); | |
262 | ||
263 | /* Parameter validation */ | |
264 | ||
265 | if (!table) { | |
266 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
267 | } | |
268 | ||
f60d8181 BM |
269 | /* Must acquire the interpreter lock during this operation */ |
270 | ||
271 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); | |
272 | if (ACPI_FAILURE(status)) { | |
273 | return_ACPI_STATUS(status); | |
274 | } | |
275 | ||
276 | /* Install the table and load it into the namespace */ | |
277 | ||
278 | ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:")); | |
86dfc6f3 | 279 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
ed6f1d44 BM |
280 | |
281 | status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table), | |
282 | ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, | |
283 | TRUE, FALSE, &table_index); | |
284 | ||
86dfc6f3 LZ |
285 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
286 | if (ACPI_FAILURE(status)) { | |
287 | goto unlock_and_exit; | |
288 | } | |
289 | ||
290 | /* | |
291 | * Note: Now table is "INSTALLED", it must be validated before | |
292 | * using. | |
293 | */ | |
294 | status = | |
295 | acpi_tb_validate_table(&acpi_gbl_root_table_list. | |
296 | tables[table_index]); | |
f60d8181 BM |
297 | if (ACPI_FAILURE(status)) { |
298 | goto unlock_and_exit; | |
299 | } | |
300 | ||
301 | status = acpi_ns_load_table(table_index, acpi_gbl_root_node); | |
302 | ||
303 | /* Invoke table handler if present */ | |
304 | ||
305 | if (acpi_gbl_table_handler) { | |
306 | (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table, | |
307 | acpi_gbl_table_handler_context); | |
308 | } | |
309 | ||
10622bf8 | 310 | unlock_and_exit: |
f60d8181 BM |
311 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); |
312 | return_ACPI_STATUS(status); | |
313 | } | |
314 | ||
315 | ACPI_EXPORT_SYMBOL(acpi_load_table) | |
316 | ||
317 | /******************************************************************************* | |
318 | * | |
319 | * FUNCTION: acpi_unload_parent_table | |
320 | * | |
321 | * PARAMETERS: object - Handle to any namespace object owned by | |
322 | * the table to be unloaded | |
323 | * | |
324 | * RETURN: Status | |
325 | * | |
326 | * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads | |
327 | * the table and deletes all namespace objects associated with | |
328 | * that table. Unloading of the DSDT is not allowed. | |
329 | * Note: Mainly intended to support hotplug removal of SSDTs. | |
330 | * | |
331 | ******************************************************************************/ | |
332 | acpi_status acpi_unload_parent_table(acpi_handle object) | |
333 | { | |
334 | struct acpi_namespace_node *node = | |
335 | ACPI_CAST_PTR(struct acpi_namespace_node, object); | |
336 | acpi_status status = AE_NOT_EXIST; | |
337 | acpi_owner_id owner_id; | |
338 | u32 i; | |
339 | ||
340 | ACPI_FUNCTION_TRACE(acpi_unload_parent_table); | |
341 | ||
342 | /* Parameter validation */ | |
343 | ||
344 | if (!object) { | |
345 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
346 | } | |
347 | ||
348 | /* | |
349 | * The node owner_id is currently the same as the parent table ID. | |
350 | * However, this could change in the future. | |
351 | */ | |
352 | owner_id = node->owner_id; | |
353 | if (!owner_id) { | |
354 | ||
355 | /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */ | |
356 | ||
357 | return_ACPI_STATUS(AE_TYPE); | |
358 | } | |
359 | ||
360 | /* Must acquire the interpreter lock during this operation */ | |
361 | ||
362 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); | |
363 | if (ACPI_FAILURE(status)) { | |
364 | return_ACPI_STATUS(status); | |
365 | } | |
366 | ||
367 | /* Find the table in the global table list */ | |
368 | ||
369 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { | |
370 | if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) { | |
371 | continue; | |
372 | } | |
373 | ||
374 | /* | |
375 | * Allow unload of SSDT and OEMx tables only. Do not allow unload | |
376 | * of the DSDT. No other types of tables should get here, since | |
377 | * only these types can contain AML and thus are the only types | |
378 | * that can create namespace objects. | |
379 | */ | |
380 | if (ACPI_COMPARE_NAME | |
381 | (acpi_gbl_root_table_list.tables[i].signature.ascii, | |
382 | ACPI_SIG_DSDT)) { | |
383 | status = AE_TYPE; | |
384 | break; | |
385 | } | |
386 | ||
387 | /* Ensure the table is actually loaded */ | |
388 | ||
389 | if (!acpi_tb_is_table_loaded(i)) { | |
390 | status = AE_NOT_EXIST; | |
391 | break; | |
392 | } | |
393 | ||
394 | /* Invoke table handler if present */ | |
395 | ||
396 | if (acpi_gbl_table_handler) { | |
397 | (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD, | |
398 | acpi_gbl_root_table_list. | |
399 | tables[i].pointer, | |
400 | acpi_gbl_table_handler_context); | |
401 | } | |
402 | ||
403 | /* | |
404 | * Delete all namespace objects owned by this table. Note that | |
405 | * these objects can appear anywhere in the namespace by virtue | |
406 | * of the AML "Scope" operator. Thus, we need to track ownership | |
407 | * by an ID, not simply a position within the hierarchy. | |
408 | */ | |
409 | status = acpi_tb_delete_namespace_by_owner(i); | |
410 | if (ACPI_FAILURE(status)) { | |
411 | break; | |
412 | } | |
413 | ||
414 | status = acpi_tb_release_owner_id(i); | |
415 | acpi_tb_set_table_loaded_flag(i, FALSE); | |
416 | break; | |
417 | } | |
418 | ||
419 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); | |
420 | return_ACPI_STATUS(status); | |
421 | } | |
422 | ||
423 | ACPI_EXPORT_SYMBOL(acpi_unload_parent_table) |