Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbinstal - ACPI table installation and removal | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
25f044e6 | 8 | * Copyright (C) 2000 - 2013, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acnamesp.h" | |
47 | #include "actables.h" | |
1da177e4 | 48 | |
1da177e4 | 49 | #define _COMPONENT ACPI_TABLES |
4be44fcd | 50 | ACPI_MODULE_NAME("tbinstal") |
1da177e4 | 51 | |
f3d2e786 | 52 | /****************************************************************************** |
1da177e4 | 53 | * |
f3d2e786 | 54 | * FUNCTION: acpi_tb_verify_table |
1da177e4 | 55 | * |
f3d2e786 | 56 | * PARAMETERS: table_desc - table |
1da177e4 LT |
57 | * |
58 | * RETURN: Status | |
59 | * | |
f3d2e786 | 60 | * DESCRIPTION: this function is called to verify and map table |
1da177e4 | 61 | * |
f3d2e786 BM |
62 | *****************************************************************************/ |
63 | acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc) | |
1da177e4 | 64 | { |
428f2112 | 65 | acpi_status status = AE_OK; |
1da177e4 | 66 | |
f3d2e786 | 67 | ACPI_FUNCTION_TRACE(tb_verify_table); |
1da177e4 | 68 | |
f3d2e786 | 69 | /* Map the table if necessary */ |
44f6c012 | 70 | |
f3d2e786 | 71 | if (!table_desc->pointer) { |
428f2112 AS |
72 | if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) == |
73 | ACPI_TABLE_ORIGIN_MAPPED) { | |
74 | table_desc->pointer = | |
75 | acpi_os_map_memory(table_desc->address, | |
76 | table_desc->length); | |
77 | } | |
f3d2e786 BM |
78 | if (!table_desc->pointer) { |
79 | return_ACPI_STATUS(AE_NO_MEMORY); | |
1da177e4 | 80 | } |
f3d2e786 | 81 | } |
1da177e4 | 82 | |
f3d2e786 | 83 | /* FACS is the odd table, has no standard ACPI header and no checksum */ |
52fc0b02 | 84 | |
428f2112 | 85 | if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) { |
1da177e4 | 86 | |
428f2112 AS |
87 | /* Always calculate checksum, ignore bad checksum if requested */ |
88 | ||
89 | status = | |
90 | acpi_tb_verify_checksum(table_desc->pointer, | |
91 | table_desc->length); | |
92 | } | |
1da177e4 | 93 | |
c5fc42ac | 94 | return_ACPI_STATUS(status); |
1da177e4 LT |
95 | } |
96 | ||
1da177e4 LT |
97 | /******************************************************************************* |
98 | * | |
f3d2e786 | 99 | * FUNCTION: acpi_tb_add_table |
1da177e4 | 100 | * |
428f2112 | 101 | * PARAMETERS: table_desc - Table descriptor |
f3d2e786 | 102 | * table_index - Where the table index is returned |
1da177e4 LT |
103 | * |
104 | * RETURN: Status | |
105 | * | |
d3ccaff8 BM |
106 | * DESCRIPTION: This function is called to add an ACPI table. It is used to |
107 | * dynamically load tables via the Load and load_table AML | |
108 | * operators. | |
1da177e4 LT |
109 | * |
110 | ******************************************************************************/ | |
111 | ||
f3d2e786 | 112 | acpi_status |
67a119f9 | 113 | acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index) |
1da177e4 | 114 | { |
67a119f9 | 115 | u32 i; |
f3d2e786 | 116 | acpi_status status = AE_OK; |
1da177e4 | 117 | |
f3d2e786 | 118 | ACPI_FUNCTION_TRACE(tb_add_table); |
1da177e4 | 119 | |
428f2112 AS |
120 | if (!table_desc->pointer) { |
121 | status = acpi_tb_verify_table(table_desc); | |
122 | if (ACPI_FAILURE(status) || !table_desc->pointer) { | |
123 | return_ACPI_STATUS(status); | |
124 | } | |
125 | } | |
126 | ||
bc45b1d3 | 127 | /* |
c8cefe30 BM |
128 | * Validate the incoming table signature. |
129 | * | |
130 | * 1) Originally, we checked the table signature for "SSDT" or "PSDT". | |
131 | * 2) We added support for OEMx tables, signature "OEM". | |
132 | * 3) Valid tables were encountered with a null signature, so we just | |
133 | * gave up on validating the signature, (05/2008). | |
134 | * 4) We encountered non-AML tables such as the MADT, which caused | |
135 | * interpreter errors and kernel faults. So now, we once again allow | |
136 | * only "SSDT", "OEMx", and now, also a null signature. (05/2011). | |
bc45b1d3 | 137 | */ |
c8cefe30 BM |
138 | if ((table_desc->pointer->signature[0] != 0x00) && |
139 | (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)) | |
140 | && (ACPI_STRNCMP(table_desc->pointer->signature, "OEM", 3))) { | |
3b3ea775 BM |
141 | ACPI_BIOS_ERROR((AE_INFO, |
142 | "Table has invalid signature [%4.4s] (0x%8.8X), " | |
143 | "must be SSDT or OEMx", | |
144 | acpi_ut_valid_acpi_name(*(u32 *)table_desc-> | |
145 | pointer-> | |
146 | signature) ? | |
147 | table_desc->pointer->signature : "????", | |
148 | *(u32 *)table_desc->pointer->signature)); | |
c8cefe30 BM |
149 | |
150 | return_ACPI_STATUS(AE_BAD_SIGNATURE); | |
151 | } | |
428f2112 | 152 | |
f3d2e786 | 153 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
1da177e4 | 154 | |
f3d2e786 BM |
155 | /* Check if table is already registered */ |
156 | ||
b9ee2043 | 157 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { |
f3d2e786 BM |
158 | if (!acpi_gbl_root_table_list.tables[i].pointer) { |
159 | status = | |
160 | acpi_tb_verify_table(&acpi_gbl_root_table_list. | |
161 | tables[i]); | |
162 | if (ACPI_FAILURE(status) | |
163 | || !acpi_gbl_root_table_list.tables[i].pointer) { | |
164 | continue; | |
165 | } | |
166 | } | |
167 | ||
a6f30539 BM |
168 | /* |
169 | * Check for a table match on the entire table length, | |
170 | * not just the header. | |
171 | */ | |
172 | if (table_desc->length != | |
173 | acpi_gbl_root_table_list.tables[i].length) { | |
174 | continue; | |
175 | } | |
e56f5617 | 176 | |
428f2112 AS |
177 | if (ACPI_MEMCMP(table_desc->pointer, |
178 | acpi_gbl_root_table_list.tables[i].pointer, | |
a6f30539 | 179 | acpi_gbl_root_table_list.tables[i].length)) { |
f3d2e786 BM |
180 | continue; |
181 | } | |
182 | ||
e56f5617 BM |
183 | /* |
184 | * Note: the current mechanism does not unregister a table if it is | |
185 | * dynamically unloaded. The related namespace entries are deleted, | |
186 | * but the table remains in the root table list. | |
187 | * | |
188 | * The assumption here is that the number of different tables that | |
189 | * will be loaded is actually small, and there is minimal overhead | |
190 | * in just keeping the table in case it is needed again. | |
191 | * | |
192 | * If this assumption changes in the future (perhaps on large | |
193 | * machines with many table load/unload operations), tables will | |
194 | * need to be unregistered when they are unloaded, and slots in the | |
195 | * root table list should be reused when empty. | |
196 | */ | |
197 | ||
198 | /* | |
199 | * Table is already registered. | |
200 | * We can delete the table that was passed as a parameter. | |
201 | */ | |
428f2112 | 202 | acpi_tb_delete_table(table_desc); |
f3d2e786 | 203 | *table_index = i; |
e56f5617 BM |
204 | |
205 | if (acpi_gbl_root_table_list.tables[i]. | |
206 | flags & ACPI_TABLE_IS_LOADED) { | |
207 | ||
208 | /* Table is still loaded, this is an error */ | |
209 | ||
210 | status = AE_ALREADY_EXISTS; | |
211 | goto release; | |
212 | } else { | |
213 | /* Table was unloaded, allow it to be reloaded */ | |
214 | ||
215 | table_desc->pointer = | |
216 | acpi_gbl_root_table_list.tables[i].pointer; | |
217 | table_desc->address = | |
218 | acpi_gbl_root_table_list.tables[i].address; | |
219 | status = AE_OK; | |
220 | goto print_header; | |
221 | } | |
1da177e4 LT |
222 | } |
223 | ||
d3ccaff8 BM |
224 | /* |
225 | * ACPI Table Override: | |
226 | * Allow the host to override dynamically loaded tables. | |
f7b004a1 BM |
227 | * NOTE: the table is fully mapped at this point, and the mapping will |
228 | * be deleted by tb_table_override if the table is actually overridden. | |
d3ccaff8 | 229 | */ |
f7b004a1 | 230 | (void)acpi_tb_table_override(table_desc->pointer, table_desc); |
d3ccaff8 | 231 | |
e56f5617 BM |
232 | /* Add the table to the global root table list */ |
233 | ||
428f2112 AS |
234 | status = acpi_tb_store_table(table_desc->address, table_desc->pointer, |
235 | table_desc->length, table_desc->flags, | |
236 | table_index); | |
4be44fcd | 237 | if (ACPI_FAILURE(status)) { |
f3d2e786 | 238 | goto release; |
0c9938cc RM |
239 | } |
240 | ||
e56f5617 | 241 | print_header: |
428f2112 | 242 | acpi_tb_print_table_header(table_desc->address, table_desc->pointer); |
1da177e4 | 243 | |
f3d2e786 | 244 | release: |
4be44fcd LB |
245 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
246 | return_ACPI_STATUS(status); | |
1da177e4 LT |
247 | } |
248 | ||
f7b004a1 BM |
249 | /******************************************************************************* |
250 | * | |
251 | * FUNCTION: acpi_tb_table_override | |
252 | * | |
253 | * PARAMETERS: table_header - Header for the original table | |
254 | * table_desc - Table descriptor initialized for the | |
255 | * original table. May or may not be mapped. | |
256 | * | |
257 | * RETURN: Pointer to the entire new table. NULL if table not overridden. | |
258 | * If overridden, installs the new table within the input table | |
259 | * descriptor. | |
260 | * | |
261 | * DESCRIPTION: Attempt table override by calling the OSL override functions. | |
262 | * Note: If the table is overridden, then the entire new table | |
263 | * is mapped and returned by this function. | |
264 | * | |
265 | ******************************************************************************/ | |
266 | ||
267 | struct acpi_table_header *acpi_tb_table_override(struct acpi_table_header | |
268 | *table_header, | |
269 | struct acpi_table_desc | |
270 | *table_desc) | |
271 | { | |
272 | acpi_status status; | |
273 | struct acpi_table_header *new_table = NULL; | |
274 | acpi_physical_address new_address = 0; | |
275 | u32 new_table_length = 0; | |
276 | u8 new_flags; | |
277 | char *override_type; | |
278 | ||
279 | /* (1) Attempt logical override (returns a logical address) */ | |
280 | ||
281 | status = acpi_os_table_override(table_header, &new_table); | |
282 | if (ACPI_SUCCESS(status) && new_table) { | |
283 | new_address = ACPI_PTR_TO_PHYSADDR(new_table); | |
284 | new_table_length = new_table->length; | |
285 | new_flags = ACPI_TABLE_ORIGIN_OVERRIDE; | |
286 | override_type = "Logical"; | |
287 | goto finish_override; | |
288 | } | |
289 | ||
290 | /* (2) Attempt physical override (returns a physical address) */ | |
291 | ||
292 | status = acpi_os_physical_table_override(table_header, | |
293 | &new_address, | |
294 | &new_table_length); | |
295 | if (ACPI_SUCCESS(status) && new_address && new_table_length) { | |
296 | ||
297 | /* Map the entire new table */ | |
298 | ||
299 | new_table = acpi_os_map_memory(new_address, new_table_length); | |
300 | if (!new_table) { | |
301 | ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, | |
302 | "%4.4s %p Attempted physical table override failed", | |
303 | table_header->signature, | |
626d4bdf | 304 | ACPI_PHYSADDR_TO_PTR(table_desc->address))); |
f7b004a1 BM |
305 | return (NULL); |
306 | } | |
307 | ||
308 | override_type = "Physical"; | |
309 | new_flags = ACPI_TABLE_ORIGIN_MAPPED; | |
310 | goto finish_override; | |
311 | } | |
312 | ||
313 | return (NULL); /* There was no override */ | |
314 | ||
315 | finish_override: | |
316 | ||
317 | ACPI_INFO((AE_INFO, | |
318 | "%4.4s %p %s table override, new table: %p", | |
319 | table_header->signature, | |
626d4bdf | 320 | ACPI_PHYSADDR_TO_PTR(table_desc->address), |
f7b004a1 BM |
321 | override_type, new_table)); |
322 | ||
323 | /* We can now unmap/delete the original table (if fully mapped) */ | |
324 | ||
325 | acpi_tb_delete_table(table_desc); | |
326 | ||
327 | /* Setup descriptor for the new table */ | |
328 | ||
329 | table_desc->address = new_address; | |
330 | table_desc->pointer = new_table; | |
331 | table_desc->length = new_table_length; | |
332 | table_desc->flags = new_flags; | |
333 | ||
334 | return (new_table); | |
335 | } | |
336 | ||
1da177e4 LT |
337 | /******************************************************************************* |
338 | * | |
f3d2e786 | 339 | * FUNCTION: acpi_tb_resize_root_table_list |
1da177e4 | 340 | * |
f3d2e786 | 341 | * PARAMETERS: None |
1da177e4 LT |
342 | * |
343 | * RETURN: Status | |
344 | * | |
f3d2e786 | 345 | * DESCRIPTION: Expand the size of global table array |
1da177e4 LT |
346 | * |
347 | ******************************************************************************/ | |
348 | ||
f3d2e786 | 349 | acpi_status acpi_tb_resize_root_table_list(void) |
1da177e4 | 350 | { |
f3d2e786 | 351 | struct acpi_table_desc *tables; |
2bc198c1 | 352 | u32 table_count; |
1da177e4 | 353 | |
f3d2e786 | 354 | ACPI_FUNCTION_TRACE(tb_resize_root_table_list); |
1da177e4 | 355 | |
f3d2e786 | 356 | /* allow_resize flag is a parameter to acpi_initialize_tables */ |
1da177e4 | 357 | |
c5fc42ac | 358 | if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) { |
f3d2e786 BM |
359 | ACPI_ERROR((AE_INFO, |
360 | "Resize of Root Table Array is not allowed")); | |
361 | return_ACPI_STATUS(AE_SUPPORT); | |
1da177e4 LT |
362 | } |
363 | ||
f3d2e786 BM |
364 | /* Increase the Table Array size */ |
365 | ||
2bc198c1 LZ |
366 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
367 | table_count = acpi_gbl_root_table_list.max_table_count; | |
368 | } else { | |
369 | table_count = acpi_gbl_root_table_list.current_table_count; | |
370 | } | |
371 | ||
372 | tables = ACPI_ALLOCATE_ZEROED(((acpi_size) table_count + | |
ec41f193 BM |
373 | ACPI_ROOT_TABLE_SIZE_INCREMENT) * |
374 | sizeof(struct acpi_table_desc)); | |
f3d2e786 BM |
375 | if (!tables) { |
376 | ACPI_ERROR((AE_INFO, | |
377 | "Could not allocate new root table array")); | |
378 | return_ACPI_STATUS(AE_NO_MEMORY); | |
1da177e4 LT |
379 | } |
380 | ||
f3d2e786 BM |
381 | /* Copy and free the previous table array */ |
382 | ||
383 | if (acpi_gbl_root_table_list.tables) { | |
384 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, | |
2bc198c1 LZ |
385 | (acpi_size) table_count * |
386 | sizeof(struct acpi_table_desc)); | |
f3d2e786 | 387 | |
c5fc42ac | 388 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
f3d2e786 BM |
389 | ACPI_FREE(acpi_gbl_root_table_list.tables); |
390 | } | |
1da177e4 LT |
391 | } |
392 | ||
f3d2e786 | 393 | acpi_gbl_root_table_list.tables = tables; |
2bc198c1 LZ |
394 | acpi_gbl_root_table_list.max_table_count = |
395 | table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT; | |
396 | acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; | |
1da177e4 | 397 | |
f3d2e786 | 398 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
399 | } |
400 | ||
1da177e4 LT |
401 | /******************************************************************************* |
402 | * | |
f3d2e786 | 403 | * FUNCTION: acpi_tb_store_table |
1da177e4 | 404 | * |
ba494bee BM |
405 | * PARAMETERS: address - Table address |
406 | * table - Table header | |
407 | * length - Table length | |
408 | * flags - flags | |
1da177e4 | 409 | * |
f3d2e786 | 410 | * RETURN: Status and table index. |
1da177e4 | 411 | * |
f3d2e786 | 412 | * DESCRIPTION: Add an ACPI table to the global table list |
1da177e4 LT |
413 | * |
414 | ******************************************************************************/ | |
415 | ||
416 | acpi_status | |
f3d2e786 BM |
417 | acpi_tb_store_table(acpi_physical_address address, |
418 | struct acpi_table_header *table, | |
67a119f9 | 419 | u32 length, u8 flags, u32 *table_index) |
1da177e4 | 420 | { |
b9ee2043 BM |
421 | acpi_status status; |
422 | struct acpi_table_desc *new_table; | |
1da177e4 | 423 | |
f3d2e786 | 424 | /* Ensure that there is room for the table in the Root Table List */ |
f9f4601f | 425 | |
b9ee2043 BM |
426 | if (acpi_gbl_root_table_list.current_table_count >= |
427 | acpi_gbl_root_table_list.max_table_count) { | |
f3d2e786 BM |
428 | status = acpi_tb_resize_root_table_list(); |
429 | if (ACPI_FAILURE(status)) { | |
430 | return (status); | |
431 | } | |
f9f4601f RM |
432 | } |
433 | ||
b9ee2043 BM |
434 | new_table = |
435 | &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list. | |
436 | current_table_count]; | |
437 | ||
f3d2e786 BM |
438 | /* Initialize added table */ |
439 | ||
b9ee2043 BM |
440 | new_table->address = address; |
441 | new_table->pointer = table; | |
442 | new_table->length = length; | |
443 | new_table->owner_id = 0; | |
444 | new_table->flags = flags; | |
445 | ||
446 | ACPI_MOVE_32_TO_32(&new_table->signature, table->signature); | |
447 | ||
448 | *table_index = acpi_gbl_root_table_list.current_table_count; | |
449 | acpi_gbl_root_table_list.current_table_count++; | |
450 | return (AE_OK); | |
f3d2e786 | 451 | } |
1da177e4 | 452 | |
f3d2e786 BM |
453 | /******************************************************************************* |
454 | * | |
455 | * FUNCTION: acpi_tb_delete_table | |
456 | * | |
457 | * PARAMETERS: table_index - Table index | |
458 | * | |
459 | * RETURN: None | |
460 | * | |
461 | * DESCRIPTION: Delete one internal ACPI table | |
462 | * | |
463 | ******************************************************************************/ | |
1da177e4 | 464 | |
428f2112 | 465 | void acpi_tb_delete_table(struct acpi_table_desc *table_desc) |
f3d2e786 | 466 | { |
f3d2e786 | 467 | /* Table must be mapped or allocated */ |
f3d2e786 BM |
468 | if (!table_desc->pointer) { |
469 | return; | |
1da177e4 | 470 | } |
428f2112 AS |
471 | switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { |
472 | case ACPI_TABLE_ORIGIN_MAPPED: | |
473 | acpi_os_unmap_memory(table_desc->pointer, table_desc->length); | |
474 | break; | |
475 | case ACPI_TABLE_ORIGIN_ALLOCATED: | |
f3d2e786 | 476 | ACPI_FREE(table_desc->pointer); |
428f2112 | 477 | break; |
f7b004a1 BM |
478 | |
479 | /* Not mapped or allocated, there is nothing we can do */ | |
480 | ||
481 | default: | |
482 | return; | |
1da177e4 LT |
483 | } |
484 | ||
f3d2e786 | 485 | table_desc->pointer = NULL; |
1da177e4 LT |
486 | } |
487 | ||
1da177e4 LT |
488 | /******************************************************************************* |
489 | * | |
f3d2e786 | 490 | * FUNCTION: acpi_tb_terminate |
1da177e4 | 491 | * |
f3d2e786 | 492 | * PARAMETERS: None |
1da177e4 | 493 | * |
f3d2e786 | 494 | * RETURN: None |
1da177e4 LT |
495 | * |
496 | * DESCRIPTION: Delete all internal ACPI tables | |
497 | * | |
498 | ******************************************************************************/ | |
499 | ||
f3d2e786 | 500 | void acpi_tb_terminate(void) |
1da177e4 | 501 | { |
67a119f9 | 502 | u32 i; |
f3d2e786 BM |
503 | |
504 | ACPI_FUNCTION_TRACE(tb_terminate); | |
505 | ||
506 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | |
507 | ||
508 | /* Delete the individual tables */ | |
509 | ||
b9ee2043 | 510 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { |
428f2112 | 511 | acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]); |
f3d2e786 | 512 | } |
1da177e4 LT |
513 | |
514 | /* | |
f3d2e786 BM |
515 | * Delete the root table array if allocated locally. Array cannot be |
516 | * mapped, so we don't need to check for that flag. | |
1da177e4 | 517 | */ |
c5fc42ac | 518 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
f3d2e786 | 519 | ACPI_FREE(acpi_gbl_root_table_list.tables); |
1da177e4 | 520 | } |
f3d2e786 BM |
521 | |
522 | acpi_gbl_root_table_list.tables = NULL; | |
523 | acpi_gbl_root_table_list.flags = 0; | |
b9ee2043 | 524 | acpi_gbl_root_table_list.current_table_count = 0; |
f3d2e786 BM |
525 | |
526 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n")); | |
527 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); | |
68aafc35 BM |
528 | |
529 | return_VOID; | |
1da177e4 LT |
530 | } |
531 | ||
1da177e4 LT |
532 | /******************************************************************************* |
533 | * | |
f3d2e786 | 534 | * FUNCTION: acpi_tb_delete_namespace_by_owner |
1da177e4 | 535 | * |
f3d2e786 | 536 | * PARAMETERS: table_index - Table index |
1da177e4 | 537 | * |
8a335a23 | 538 | * RETURN: Status |
1da177e4 | 539 | * |
f3d2e786 | 540 | * DESCRIPTION: Delete all namespace objects created when this table was loaded. |
1da177e4 LT |
541 | * |
542 | ******************************************************************************/ | |
543 | ||
8a335a23 | 544 | acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index) |
1da177e4 | 545 | { |
f3d2e786 | 546 | acpi_owner_id owner_id; |
8a335a23 BM |
547 | acpi_status status; |
548 | ||
549 | ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner); | |
550 | ||
551 | status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | |
552 | if (ACPI_FAILURE(status)) { | |
553 | return_ACPI_STATUS(status); | |
554 | } | |
555 | ||
b9ee2043 | 556 | if (table_index >= acpi_gbl_root_table_list.current_table_count) { |
8a335a23 BM |
557 | |
558 | /* The table index does not exist */ | |
1da177e4 | 559 | |
f3d2e786 | 560 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
8a335a23 | 561 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
562 | } |
563 | ||
8a335a23 BM |
564 | /* Get the owner ID for this table, used to delete namespace nodes */ |
565 | ||
566 | owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id; | |
f3d2e786 | 567 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
8a335a23 BM |
568 | |
569 | /* | |
570 | * Need to acquire the namespace writer lock to prevent interference | |
571 | * with any concurrent namespace walks. The interpreter must be | |
572 | * released during the deletion since the acquisition of the deletion | |
573 | * lock may block, and also since the execution of a namespace walk | |
574 | * must be allowed to use the interpreter. | |
575 | */ | |
e4c1ebfc | 576 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); |
8a335a23 BM |
577 | status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock); |
578 | ||
f3d2e786 | 579 | acpi_ns_delete_namespace_by_owner(owner_id); |
8a335a23 BM |
580 | if (ACPI_FAILURE(status)) { |
581 | return_ACPI_STATUS(status); | |
582 | } | |
583 | ||
584 | acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock); | |
585 | ||
586 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); | |
587 | return_ACPI_STATUS(status); | |
f3d2e786 | 588 | } |
1da177e4 | 589 | |
f3d2e786 BM |
590 | /******************************************************************************* |
591 | * | |
592 | * FUNCTION: acpi_tb_allocate_owner_id | |
593 | * | |
594 | * PARAMETERS: table_index - Table index | |
595 | * | |
596 | * RETURN: Status | |
597 | * | |
598 | * DESCRIPTION: Allocates owner_id in table_desc | |
599 | * | |
600 | ******************************************************************************/ | |
1da177e4 | 601 | |
67a119f9 | 602 | acpi_status acpi_tb_allocate_owner_id(u32 table_index) |
f3d2e786 BM |
603 | { |
604 | acpi_status status = AE_BAD_PARAMETER; | |
1da177e4 | 605 | |
f3d2e786 | 606 | ACPI_FUNCTION_TRACE(tb_allocate_owner_id); |
1da177e4 | 607 | |
f3d2e786 | 608 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
b9ee2043 | 609 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
f3d2e786 BM |
610 | status = acpi_ut_allocate_owner_id |
611 | (&(acpi_gbl_root_table_list.tables[table_index].owner_id)); | |
1da177e4 LT |
612 | } |
613 | ||
4be44fcd | 614 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
f3d2e786 | 615 | return_ACPI_STATUS(status); |
1da177e4 LT |
616 | } |
617 | ||
1da177e4 LT |
618 | /******************************************************************************* |
619 | * | |
f3d2e786 | 620 | * FUNCTION: acpi_tb_release_owner_id |
1da177e4 | 621 | * |
f3d2e786 | 622 | * PARAMETERS: table_index - Table index |
1da177e4 | 623 | * |
f3d2e786 | 624 | * RETURN: Status |
1da177e4 | 625 | * |
f3d2e786 | 626 | * DESCRIPTION: Releases owner_id in table_desc |
1da177e4 LT |
627 | * |
628 | ******************************************************************************/ | |
629 | ||
67a119f9 | 630 | acpi_status acpi_tb_release_owner_id(u32 table_index) |
1da177e4 | 631 | { |
f3d2e786 | 632 | acpi_status status = AE_BAD_PARAMETER; |
1da177e4 | 633 | |
f3d2e786 | 634 | ACPI_FUNCTION_TRACE(tb_release_owner_id); |
1da177e4 | 635 | |
f3d2e786 | 636 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
b9ee2043 | 637 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
f3d2e786 BM |
638 | acpi_ut_release_owner_id(& |
639 | (acpi_gbl_root_table_list. | |
640 | tables[table_index].owner_id)); | |
641 | status = AE_OK; | |
1da177e4 LT |
642 | } |
643 | ||
f3d2e786 BM |
644 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
645 | return_ACPI_STATUS(status); | |
1da177e4 LT |
646 | } |
647 | ||
1da177e4 LT |
648 | /******************************************************************************* |
649 | * | |
f3d2e786 | 650 | * FUNCTION: acpi_tb_get_owner_id |
1da177e4 | 651 | * |
f3d2e786 BM |
652 | * PARAMETERS: table_index - Table index |
653 | * owner_id - Where the table owner_id is returned | |
1da177e4 | 654 | * |
f3d2e786 | 655 | * RETURN: Status |
1da177e4 | 656 | * |
f3d2e786 | 657 | * DESCRIPTION: returns owner_id for the ACPI table |
1da177e4 LT |
658 | * |
659 | ******************************************************************************/ | |
660 | ||
67a119f9 | 661 | acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id) |
1da177e4 | 662 | { |
f3d2e786 | 663 | acpi_status status = AE_BAD_PARAMETER; |
1da177e4 | 664 | |
f3d2e786 | 665 | ACPI_FUNCTION_TRACE(tb_get_owner_id); |
1da177e4 | 666 | |
f3d2e786 | 667 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
b9ee2043 | 668 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
f3d2e786 BM |
669 | *owner_id = |
670 | acpi_gbl_root_table_list.tables[table_index].owner_id; | |
671 | status = AE_OK; | |
1da177e4 LT |
672 | } |
673 | ||
f3d2e786 BM |
674 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
675 | return_ACPI_STATUS(status); | |
676 | } | |
1da177e4 | 677 | |
f3d2e786 BM |
678 | /******************************************************************************* |
679 | * | |
680 | * FUNCTION: acpi_tb_is_table_loaded | |
681 | * | |
682 | * PARAMETERS: table_index - Table index | |
683 | * | |
684 | * RETURN: Table Loaded Flag | |
685 | * | |
686 | ******************************************************************************/ | |
1da177e4 | 687 | |
67a119f9 | 688 | u8 acpi_tb_is_table_loaded(u32 table_index) |
f3d2e786 BM |
689 | { |
690 | u8 is_loaded = FALSE; | |
1da177e4 | 691 | |
f3d2e786 | 692 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
b9ee2043 | 693 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
f3d2e786 | 694 | is_loaded = (u8) |
ec41f193 BM |
695 | (acpi_gbl_root_table_list.tables[table_index].flags & |
696 | ACPI_TABLE_IS_LOADED); | |
1da177e4 LT |
697 | } |
698 | ||
f3d2e786 BM |
699 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
700 | return (is_loaded); | |
701 | } | |
f6dd9221 | 702 | |
f3d2e786 BM |
703 | /******************************************************************************* |
704 | * | |
705 | * FUNCTION: acpi_tb_set_table_loaded_flag | |
706 | * | |
707 | * PARAMETERS: table_index - Table index | |
708 | * is_loaded - TRUE if table is loaded, FALSE otherwise | |
709 | * | |
710 | * RETURN: None | |
711 | * | |
712 | * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE. | |
713 | * | |
714 | ******************************************************************************/ | |
1da177e4 | 715 | |
67a119f9 | 716 | void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded) |
f3d2e786 | 717 | { |
1da177e4 | 718 | |
f3d2e786 | 719 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
b9ee2043 | 720 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
f3d2e786 BM |
721 | if (is_loaded) { |
722 | acpi_gbl_root_table_list.tables[table_index].flags |= | |
c5fc42ac | 723 | ACPI_TABLE_IS_LOADED; |
f3d2e786 BM |
724 | } else { |
725 | acpi_gbl_root_table_list.tables[table_index].flags &= | |
c5fc42ac | 726 | ~ACPI_TABLE_IS_LOADED; |
f3d2e786 BM |
727 | } |
728 | } | |
1da177e4 | 729 | |
f3d2e786 | 730 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
1da177e4 | 731 | } |