Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbxfload - Table load/unload external interfaces |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
David E. Box | 82a8094 | 2015-02-05 15:20:45 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2015, Intel Corp. |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 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 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 44 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 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 | |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 54 | /******************************************************************************* |
| 55 | * |
| 56 | * FUNCTION: acpi_load_tables |
| 57 | * |
| 58 | * PARAMETERS: None |
| 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
| 62 | * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT |
| 63 | * |
| 64 | ******************************************************************************/ |
Lv Zheng | 45c9f78 | 2013-10-31 09:31:24 +0800 | [diff] [blame] | 65 | acpi_status __init acpi_load_tables(void) |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 66 | { |
| 67 | acpi_status status; |
| 68 | |
| 69 | ACPI_FUNCTION_TRACE(acpi_load_tables); |
| 70 | |
| 71 | /* Load the namespace from the tables */ |
| 72 | |
| 73 | status = acpi_tb_load_namespace(); |
Bob Moore | 93cdafa | 2015-08-25 10:29:33 +0800 | [diff] [blame] | 74 | |
| 75 | /* Don't let single failures abort the load */ |
| 76 | |
| 77 | if (status == AE_CTRL_TERMINATE) { |
| 78 | status = AE_OK; |
| 79 | } |
| 80 | |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 81 | if (ACPI_FAILURE(status)) { |
| 82 | ACPI_EXCEPTION((AE_INFO, status, |
| 83 | "While loading namespace from ACPI tables")); |
| 84 | } |
| 85 | |
| 86 | return_ACPI_STATUS(status); |
| 87 | } |
| 88 | |
Lv Zheng | d21f600 | 2013-10-29 09:30:10 +0800 | [diff] [blame] | 89 | ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables) |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 90 | |
| 91 | /******************************************************************************* |
| 92 | * |
| 93 | * FUNCTION: acpi_tb_load_namespace |
| 94 | * |
| 95 | * PARAMETERS: None |
| 96 | * |
| 97 | * RETURN: Status |
| 98 | * |
| 99 | * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in |
| 100 | * the RSDT/XSDT. |
| 101 | * |
| 102 | ******************************************************************************/ |
Bob Moore | 93cdafa | 2015-08-25 10:29:33 +0800 | [diff] [blame] | 103 | acpi_status acpi_tb_load_namespace(void) |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 104 | { |
| 105 | acpi_status status; |
| 106 | u32 i; |
| 107 | struct acpi_table_header *new_dsdt; |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 108 | struct acpi_table_desc *table; |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 109 | u32 tables_loaded = 0; |
| 110 | u32 tables_failed = 0; |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 111 | |
| 112 | ACPI_FUNCTION_TRACE(tb_load_namespace); |
| 113 | |
| 114 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 115 | |
| 116 | /* |
| 117 | * Load the namespace. The DSDT is required, but any SSDT and |
| 118 | * PSDT tables are optional. Verify the DSDT. |
| 119 | */ |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 120 | table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index]; |
| 121 | |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 122 | if (!acpi_gbl_root_table_list.current_table_count || |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 123 | !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_DSDT) || |
| 124 | ACPI_FAILURE(acpi_tb_validate_table(table))) { |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 125 | 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 Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame] | 133 | * .Pointer field is not validated until after call to acpi_tb_validate_table. |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 134 | */ |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 135 | acpi_gbl_DSDT = table->pointer; |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 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) { |
Lv Zheng | 8ec3f45 | 2015-08-25 10:29:01 +0800 | [diff] [blame] | 144 | new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index); |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 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 | */ |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 154 | memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT, |
| 155 | sizeof(struct acpi_table_header)); |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 156 | |
| 157 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 158 | |
| 159 | /* Load and parse tables */ |
| 160 | |
Lv Zheng | 8ec3f45 | 2015-08-25 10:29:01 +0800 | [diff] [blame] | 161 | status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node); |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 162 | if (ACPI_FAILURE(status)) { |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 163 | ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed")); |
| 164 | tables_failed++; |
| 165 | } else { |
| 166 | tables_loaded++; |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */ |
| 170 | |
| 171 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 172 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 173 | table = &acpi_gbl_root_table_list.tables[i]; |
| 174 | |
Lv Zheng | c04e1fb | 2015-07-01 14:43:11 +0800 | [diff] [blame] | 175 | if (!acpi_gbl_root_table_list.tables[i].address || |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 176 | (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT) |
| 177 | && !ACPI_COMPARE_NAME(table->signature.ascii, |
| 178 | ACPI_SIG_PSDT) |
| 179 | && !ACPI_COMPARE_NAME(table->signature.ascii, |
| 180 | ACPI_SIG_OSDT)) |
| 181 | || ACPI_FAILURE(acpi_tb_validate_table(table))) { |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 182 | continue; |
| 183 | } |
| 184 | |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 185 | /* Ignore errors while loading tables, get as many as possible */ |
| 186 | |
| 187 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 188 | status = acpi_ns_load_table(i, acpi_gbl_root_node); |
| 189 | if (ACPI_FAILURE(status)) { |
| 190 | ACPI_EXCEPTION((AE_INFO, status, |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 191 | "(%4.4s:%8.8s) while loading table", |
| 192 | table->signature.ascii, |
| 193 | table->pointer->oem_table_id)); |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 194 | |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 195 | tables_failed++; |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 196 | |
| 197 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
| 198 | "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n", |
| 199 | table->signature.ascii, |
| 200 | table->pointer->oem_table_id)); |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 201 | } else { |
| 202 | tables_loaded++; |
| 203 | } |
| 204 | |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 205 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 206 | } |
| 207 | |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 208 | if (!tables_failed) { |
| 209 | ACPI_INFO((AE_INFO, |
Bob Moore | 2ba7379 | 2015-12-29 13:54:58 +0800 | [diff] [blame] | 210 | "%u ACPI AML tables successfully acquired and loaded\n", |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 211 | tables_loaded)); |
| 212 | } else { |
| 213 | ACPI_ERROR((AE_INFO, |
Bob Moore | 3c0503d | 2015-08-25 10:29:39 +0800 | [diff] [blame] | 214 | "%u table load failures, %u successful", |
| 215 | tables_failed, tables_loaded)); |
Bob Moore | 93cdafa | 2015-08-25 10:29:33 +0800 | [diff] [blame] | 216 | |
| 217 | /* Indicate at least one failure */ |
| 218 | |
| 219 | status = AE_CTRL_TERMINATE; |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 220 | } |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 221 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 222 | unlock_and_exit: |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame] | 223 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 224 | return_ACPI_STATUS(status); |
| 225 | } |
| 226 | |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 227 | /******************************************************************************* |
| 228 | * |
Lv Zheng | caf4a15 | 2014-04-04 12:39:18 +0800 | [diff] [blame] | 229 | * FUNCTION: acpi_install_table |
| 230 | * |
| 231 | * PARAMETERS: address - Address of the ACPI table to be installed. |
| 232 | * physical - Whether the address is a physical table |
| 233 | * address or not |
| 234 | * |
| 235 | * RETURN: Status |
| 236 | * |
| 237 | * DESCRIPTION: Dynamically install an ACPI table. |
| 238 | * Note: This function should only be invoked after |
| 239 | * acpi_initialize_tables() and before acpi_load_tables(). |
| 240 | * |
| 241 | ******************************************************************************/ |
| 242 | |
| 243 | acpi_status __init |
| 244 | acpi_install_table(acpi_physical_address address, u8 physical) |
| 245 | { |
| 246 | acpi_status status; |
| 247 | u8 flags; |
| 248 | u32 table_index; |
| 249 | |
| 250 | ACPI_FUNCTION_TRACE(acpi_install_table); |
| 251 | |
| 252 | if (physical) { |
Bob Moore | ed6f1d4 | 2014-04-04 12:39:26 +0800 | [diff] [blame] | 253 | flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL; |
Zhang Rui | dc00203 | 2015-07-01 14:44:37 +0800 | [diff] [blame] | 254 | } else { |
| 255 | flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL; |
Lv Zheng | caf4a15 | 2014-04-04 12:39:18 +0800 | [diff] [blame] | 256 | } |
| 257 | |
Bob Moore | ed6f1d4 | 2014-04-04 12:39:26 +0800 | [diff] [blame] | 258 | status = acpi_tb_install_standard_table(address, flags, |
| 259 | FALSE, FALSE, &table_index); |
Lv Zheng | caf4a15 | 2014-04-04 12:39:18 +0800 | [diff] [blame] | 260 | |
| 261 | return_ACPI_STATUS(status); |
| 262 | } |
| 263 | |
| 264 | ACPI_EXPORT_SYMBOL_INIT(acpi_install_table) |
| 265 | |
| 266 | /******************************************************************************* |
| 267 | * |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 268 | * FUNCTION: acpi_load_table |
| 269 | * |
| 270 | * PARAMETERS: table - Pointer to a buffer containing the ACPI |
| 271 | * table to be loaded. |
| 272 | * |
| 273 | * RETURN: Status |
| 274 | * |
| 275 | * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must |
| 276 | * be a valid ACPI table with a valid ACPI table header. |
| 277 | * Note1: Mainly intended to support hotplug addition of SSDTs. |
Bob Moore | 691fda5 | 2012-10-31 02:26:23 +0000 | [diff] [blame] | 278 | * Note2: Does not copy the incoming table. User is responsible |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 279 | * to ensure that the table is not deleted or unmapped. |
| 280 | * |
| 281 | ******************************************************************************/ |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 282 | acpi_status acpi_load_table(struct acpi_table_header *table) |
| 283 | { |
| 284 | acpi_status status; |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 285 | u32 table_index; |
| 286 | |
| 287 | ACPI_FUNCTION_TRACE(acpi_load_table); |
| 288 | |
| 289 | /* Parameter validation */ |
| 290 | |
| 291 | if (!table) { |
| 292 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 293 | } |
| 294 | |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 295 | /* Must acquire the interpreter lock during this operation */ |
| 296 | |
| 297 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); |
| 298 | if (ACPI_FAILURE(status)) { |
| 299 | return_ACPI_STATUS(status); |
| 300 | } |
| 301 | |
| 302 | /* Install the table and load it into the namespace */ |
| 303 | |
| 304 | ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:")); |
Lv Zheng | 86dfc6f3 | 2014-04-04 12:38:57 +0800 | [diff] [blame] | 305 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Bob Moore | ed6f1d4 | 2014-04-04 12:39:26 +0800 | [diff] [blame] | 306 | |
| 307 | status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table), |
| 308 | ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, |
| 309 | TRUE, FALSE, &table_index); |
| 310 | |
Lv Zheng | 86dfc6f3 | 2014-04-04 12:38:57 +0800 | [diff] [blame] | 311 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 312 | if (ACPI_FAILURE(status)) { |
| 313 | goto unlock_and_exit; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * Note: Now table is "INSTALLED", it must be validated before |
| 318 | * using. |
| 319 | */ |
| 320 | status = |
| 321 | acpi_tb_validate_table(&acpi_gbl_root_table_list. |
| 322 | tables[table_index]); |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 323 | if (ACPI_FAILURE(status)) { |
| 324 | goto unlock_and_exit; |
| 325 | } |
| 326 | |
| 327 | status = acpi_ns_load_table(table_index, acpi_gbl_root_node); |
| 328 | |
| 329 | /* Invoke table handler if present */ |
| 330 | |
| 331 | if (acpi_gbl_table_handler) { |
| 332 | (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table, |
| 333 | acpi_gbl_table_handler_context); |
| 334 | } |
| 335 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 336 | unlock_and_exit: |
Bob Moore | f60d818 | 2012-07-16 10:21:34 +0800 | [diff] [blame] | 337 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); |
| 338 | return_ACPI_STATUS(status); |
| 339 | } |
| 340 | |
| 341 | ACPI_EXPORT_SYMBOL(acpi_load_table) |
| 342 | |
| 343 | /******************************************************************************* |
| 344 | * |
| 345 | * FUNCTION: acpi_unload_parent_table |
| 346 | * |
| 347 | * PARAMETERS: object - Handle to any namespace object owned by |
| 348 | * the table to be unloaded |
| 349 | * |
| 350 | * RETURN: Status |
| 351 | * |
| 352 | * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads |
| 353 | * the table and deletes all namespace objects associated with |
| 354 | * that table. Unloading of the DSDT is not allowed. |
| 355 | * Note: Mainly intended to support hotplug removal of SSDTs. |
| 356 | * |
| 357 | ******************************************************************************/ |
| 358 | acpi_status acpi_unload_parent_table(acpi_handle object) |
| 359 | { |
| 360 | struct acpi_namespace_node *node = |
| 361 | ACPI_CAST_PTR(struct acpi_namespace_node, object); |
| 362 | acpi_status status = AE_NOT_EXIST; |
| 363 | acpi_owner_id owner_id; |
| 364 | u32 i; |
| 365 | |
| 366 | ACPI_FUNCTION_TRACE(acpi_unload_parent_table); |
| 367 | |
| 368 | /* Parameter validation */ |
| 369 | |
| 370 | if (!object) { |
| 371 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * The node owner_id is currently the same as the parent table ID. |
| 376 | * However, this could change in the future. |
| 377 | */ |
| 378 | owner_id = node->owner_id; |
| 379 | if (!owner_id) { |
| 380 | |
| 381 | /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */ |
| 382 | |
| 383 | return_ACPI_STATUS(AE_TYPE); |
| 384 | } |
| 385 | |
| 386 | /* Must acquire the interpreter lock during this operation */ |
| 387 | |
| 388 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); |
| 389 | if (ACPI_FAILURE(status)) { |
| 390 | return_ACPI_STATUS(status); |
| 391 | } |
| 392 | |
| 393 | /* Find the table in the global table list */ |
| 394 | |
| 395 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { |
| 396 | if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) { |
| 397 | continue; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Allow unload of SSDT and OEMx tables only. Do not allow unload |
| 402 | * of the DSDT. No other types of tables should get here, since |
| 403 | * only these types can contain AML and thus are the only types |
| 404 | * that can create namespace objects. |
| 405 | */ |
| 406 | if (ACPI_COMPARE_NAME |
| 407 | (acpi_gbl_root_table_list.tables[i].signature.ascii, |
| 408 | ACPI_SIG_DSDT)) { |
| 409 | status = AE_TYPE; |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | /* Ensure the table is actually loaded */ |
| 414 | |
| 415 | if (!acpi_tb_is_table_loaded(i)) { |
| 416 | status = AE_NOT_EXIST; |
| 417 | break; |
| 418 | } |
| 419 | |
| 420 | /* Invoke table handler if present */ |
| 421 | |
| 422 | if (acpi_gbl_table_handler) { |
| 423 | (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD, |
| 424 | acpi_gbl_root_table_list. |
| 425 | tables[i].pointer, |
| 426 | acpi_gbl_table_handler_context); |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Delete all namespace objects owned by this table. Note that |
| 431 | * these objects can appear anywhere in the namespace by virtue |
| 432 | * of the AML "Scope" operator. Thus, we need to track ownership |
| 433 | * by an ID, not simply a position within the hierarchy. |
| 434 | */ |
| 435 | status = acpi_tb_delete_namespace_by_owner(i); |
| 436 | if (ACPI_FAILURE(status)) { |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | status = acpi_tb_release_owner_id(i); |
| 441 | acpi_tb_set_table_loaded_flag(i, FALSE); |
| 442 | break; |
| 443 | } |
| 444 | |
| 445 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); |
| 446 | return_ACPI_STATUS(status); |
| 447 | } |
| 448 | |
| 449 | ACPI_EXPORT_SYMBOL(acpi_unload_parent_table) |