| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbxfload - Table load/unload external interfaces |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2016, 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 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
| 46 | #include <acpi/acpi.h> |
| 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
| 49 | #include "actables.h" |
| 50 | #include "acevents.h" |
| 51 | |
| 52 | #define _COMPONENT ACPI_TABLES |
| 53 | ACPI_MODULE_NAME("tbxfload") |
| 54 | |
| 55 | /******************************************************************************* |
| 56 | * |
| 57 | * FUNCTION: acpi_load_tables |
| 58 | * |
| 59 | * PARAMETERS: None |
| 60 | * |
| 61 | * RETURN: Status |
| 62 | * |
| 63 | * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT |
| 64 | * |
| 65 | ******************************************************************************/ |
| 66 | acpi_status ACPI_INIT_FUNCTION acpi_load_tables(void) |
| 67 | { |
| 68 | acpi_status status; |
| 69 | |
| 70 | ACPI_FUNCTION_TRACE(acpi_load_tables); |
| 71 | |
| 72 | /* |
| 73 | * Install the default operation region handlers. These are the |
| 74 | * handlers that are defined by the ACPI specification to be |
| 75 | * "always accessible" -- namely, system_memory, system_IO, and |
| 76 | * PCI_Config. This also means that no _REG methods need to be |
| 77 | * run for these address spaces. We need to have these handlers |
| 78 | * installed before any AML code can be executed, especially any |
| 79 | * module-level code (11/2015). |
| 80 | * Note that we allow OSPMs to install their own region handlers |
| 81 | * between acpi_initialize_subsystem() and acpi_load_tables() to use |
| 82 | * their customized default region handlers. |
| 83 | */ |
| 84 | status = acpi_ev_install_region_handlers(); |
| 85 | if (ACPI_FAILURE(status)) { |
| 86 | ACPI_EXCEPTION((AE_INFO, status, |
| 87 | "During Region initialization")); |
| 88 | return_ACPI_STATUS(status); |
| 89 | } |
| 90 | |
| 91 | /* Load the namespace from the tables */ |
| 92 | |
| 93 | status = acpi_tb_load_namespace(); |
| 94 | |
| 95 | /* Don't let single failures abort the load */ |
| 96 | |
| 97 | if (status == AE_CTRL_TERMINATE) { |
| 98 | status = AE_OK; |
| 99 | } |
| 100 | |
| 101 | if (ACPI_FAILURE(status)) { |
| 102 | ACPI_EXCEPTION((AE_INFO, status, |
| 103 | "While loading namespace from ACPI tables")); |
| 104 | } |
| 105 | |
| 106 | if (acpi_gbl_parse_table_as_term_list |
| 107 | || !acpi_gbl_group_module_level_code) { |
| 108 | /* |
| 109 | * Initialize the objects that remain uninitialized. This |
| 110 | * runs the executable AML that may be part of the |
| 111 | * declaration of these objects: |
| 112 | * operation_regions, buffer_fields, Buffers, and Packages. |
| 113 | */ |
| 114 | status = acpi_ns_initialize_objects(); |
| 115 | if (ACPI_FAILURE(status)) { |
| 116 | return_ACPI_STATUS(status); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | acpi_gbl_namespace_initialized = TRUE; |
| 121 | return_ACPI_STATUS(status); |
| 122 | } |
| 123 | |
| 124 | ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables) |
| 125 | |
| 126 | /******************************************************************************* |
| 127 | * |
| 128 | * FUNCTION: acpi_tb_load_namespace |
| 129 | * |
| 130 | * PARAMETERS: None |
| 131 | * |
| 132 | * RETURN: Status |
| 133 | * |
| 134 | * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in |
| 135 | * the RSDT/XSDT. |
| 136 | * |
| 137 | ******************************************************************************/ |
| 138 | acpi_status acpi_tb_load_namespace(void) |
| 139 | { |
| 140 | acpi_status status; |
| 141 | u32 i; |
| 142 | struct acpi_table_header *new_dsdt; |
| 143 | struct acpi_table_desc *table; |
| 144 | u32 tables_loaded = 0; |
| 145 | u32 tables_failed = 0; |
| 146 | |
| 147 | ACPI_FUNCTION_TRACE(tb_load_namespace); |
| 148 | |
| 149 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 150 | |
| 151 | /* |
| 152 | * Load the namespace. The DSDT is required, but any SSDT and |
| 153 | * PSDT tables are optional. Verify the DSDT. |
| 154 | */ |
| 155 | table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index]; |
| 156 | |
| 157 | if (!acpi_gbl_root_table_list.current_table_count || |
| 158 | !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_DSDT) || |
| 159 | ACPI_FAILURE(acpi_tb_validate_table(table))) { |
| 160 | status = AE_NO_ACPI_TABLES; |
| 161 | goto unlock_and_exit; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Save the DSDT pointer for simple access. This is the mapped memory |
| 166 | * address. We must take care here because the address of the .Tables |
| 167 | * array can change dynamically as tables are loaded at run-time. Note: |
| 168 | * .Pointer field is not validated until after call to acpi_tb_validate_table. |
| 169 | */ |
| 170 | acpi_gbl_DSDT = table->pointer; |
| 171 | |
| 172 | /* |
| 173 | * Optionally copy the entire DSDT to local memory (instead of simply |
| 174 | * mapping it.) There are some BIOSs that corrupt or replace the original |
| 175 | * DSDT, creating the need for this option. Default is FALSE, do not copy |
| 176 | * the DSDT. |
| 177 | */ |
| 178 | if (acpi_gbl_copy_dsdt_locally) { |
| 179 | new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index); |
| 180 | if (new_dsdt) { |
| 181 | acpi_gbl_DSDT = new_dsdt; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * Save the original DSDT header for detection of table corruption |
| 187 | * and/or replacement of the DSDT from outside the OS. |
| 188 | */ |
| 189 | memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT, |
| 190 | sizeof(struct acpi_table_header)); |
| 191 | |
| 192 | /* Load and parse tables */ |
| 193 | |
| 194 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 195 | status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node); |
| 196 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 197 | if (ACPI_FAILURE(status)) { |
| 198 | ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed")); |
| 199 | tables_failed++; |
| 200 | } else { |
| 201 | tables_loaded++; |
| 202 | } |
| 203 | |
| 204 | /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */ |
| 205 | |
| 206 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { |
| 207 | table = &acpi_gbl_root_table_list.tables[i]; |
| 208 | |
| 209 | if (!acpi_gbl_root_table_list.tables[i].address || |
| 210 | (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT) |
| 211 | && !ACPI_COMPARE_NAME(table->signature.ascii, |
| 212 | ACPI_SIG_PSDT) |
| 213 | && !ACPI_COMPARE_NAME(table->signature.ascii, |
| 214 | ACPI_SIG_OSDT)) |
| 215 | || ACPI_FAILURE(acpi_tb_validate_table(table))) { |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | /* Ignore errors while loading tables, get as many as possible */ |
| 220 | |
| 221 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 222 | status = acpi_ns_load_table(i, acpi_gbl_root_node); |
| 223 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 224 | if (ACPI_FAILURE(status)) { |
| 225 | ACPI_EXCEPTION((AE_INFO, status, |
| 226 | "(%4.4s:%8.8s) while loading table", |
| 227 | table->signature.ascii, |
| 228 | table->pointer->oem_table_id)); |
| 229 | |
| 230 | tables_failed++; |
| 231 | |
| 232 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
| 233 | "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n", |
| 234 | table->signature.ascii, |
| 235 | table->pointer->oem_table_id)); |
| 236 | } else { |
| 237 | tables_loaded++; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if (!tables_failed) { |
| 242 | ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded\n", tables_loaded)); |
| 243 | } else { |
| 244 | ACPI_ERROR((AE_INFO, |
| 245 | "%u table load failures, %u successful", |
| 246 | tables_failed, tables_loaded)); |
| 247 | |
| 248 | /* Indicate at least one failure */ |
| 249 | |
| 250 | status = AE_CTRL_TERMINATE; |
| 251 | } |
| 252 | |
| 253 | unlock_and_exit: |
| 254 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 255 | return_ACPI_STATUS(status); |
| 256 | } |
| 257 | |
| 258 | /******************************************************************************* |
| 259 | * |
| 260 | * FUNCTION: acpi_install_table |
| 261 | * |
| 262 | * PARAMETERS: address - Address of the ACPI table to be installed. |
| 263 | * physical - Whether the address is a physical table |
| 264 | * address or not |
| 265 | * |
| 266 | * RETURN: Status |
| 267 | * |
| 268 | * DESCRIPTION: Dynamically install an ACPI table. |
| 269 | * Note: This function should only be invoked after |
| 270 | * acpi_initialize_tables() and before acpi_load_tables(). |
| 271 | * |
| 272 | ******************************************************************************/ |
| 273 | |
| 274 | acpi_status ACPI_INIT_FUNCTION |
| 275 | acpi_install_table(acpi_physical_address address, u8 physical) |
| 276 | { |
| 277 | acpi_status status; |
| 278 | u8 flags; |
| 279 | u32 table_index; |
| 280 | |
| 281 | ACPI_FUNCTION_TRACE(acpi_install_table); |
| 282 | |
| 283 | if (physical) { |
| 284 | flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL; |
| 285 | } else { |
| 286 | flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL; |
| 287 | } |
| 288 | |
| 289 | status = acpi_tb_install_standard_table(address, flags, |
| 290 | FALSE, FALSE, &table_index); |
| 291 | |
| 292 | return_ACPI_STATUS(status); |
| 293 | } |
| 294 | |
| 295 | ACPI_EXPORT_SYMBOL_INIT(acpi_install_table) |
| 296 | |
| 297 | /******************************************************************************* |
| 298 | * |
| 299 | * FUNCTION: acpi_load_table |
| 300 | * |
| 301 | * PARAMETERS: table - Pointer to a buffer containing the ACPI |
| 302 | * table to be loaded. |
| 303 | * |
| 304 | * RETURN: Status |
| 305 | * |
| 306 | * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must |
| 307 | * be a valid ACPI table with a valid ACPI table header. |
| 308 | * Note1: Mainly intended to support hotplug addition of SSDTs. |
| 309 | * Note2: Does not copy the incoming table. User is responsible |
| 310 | * to ensure that the table is not deleted or unmapped. |
| 311 | * |
| 312 | ******************************************************************************/ |
| 313 | acpi_status acpi_load_table(struct acpi_table_header *table) |
| 314 | { |
| 315 | acpi_status status; |
| 316 | u32 table_index; |
| 317 | |
| 318 | ACPI_FUNCTION_TRACE(acpi_load_table); |
| 319 | |
| 320 | /* Parameter validation */ |
| 321 | |
| 322 | if (!table) { |
| 323 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 324 | } |
| 325 | |
| 326 | /* Install the table and load it into the namespace */ |
| 327 | |
| 328 | ACPI_INFO(("Host-directed Dynamic ACPI Table Load:")); |
| 329 | status = |
| 330 | acpi_tb_install_and_load_table(table, ACPI_PTR_TO_PHYSADDR(table), |
| 331 | ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, |
| 332 | FALSE, &table_index); |
| 333 | return_ACPI_STATUS(status); |
| 334 | } |
| 335 | |
| 336 | ACPI_EXPORT_SYMBOL(acpi_load_table) |
| 337 | |
| 338 | /******************************************************************************* |
| 339 | * |
| 340 | * FUNCTION: acpi_unload_parent_table |
| 341 | * |
| 342 | * PARAMETERS: object - Handle to any namespace object owned by |
| 343 | * the table to be unloaded |
| 344 | * |
| 345 | * RETURN: Status |
| 346 | * |
| 347 | * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads |
| 348 | * the table and deletes all namespace objects associated with |
| 349 | * that table. Unloading of the DSDT is not allowed. |
| 350 | * Note: Mainly intended to support hotplug removal of SSDTs. |
| 351 | * |
| 352 | ******************************************************************************/ |
| 353 | acpi_status acpi_unload_parent_table(acpi_handle object) |
| 354 | { |
| 355 | struct acpi_namespace_node *node = |
| 356 | ACPI_CAST_PTR(struct acpi_namespace_node, object); |
| 357 | acpi_status status = AE_NOT_EXIST; |
| 358 | acpi_owner_id owner_id; |
| 359 | u32 i; |
| 360 | |
| 361 | ACPI_FUNCTION_TRACE(acpi_unload_parent_table); |
| 362 | |
| 363 | /* Parameter validation */ |
| 364 | |
| 365 | if (!object) { |
| 366 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 367 | } |
| 368 | |
| 369 | /* |
| 370 | * The node owner_id is currently the same as the parent table ID. |
| 371 | * However, this could change in the future. |
| 372 | */ |
| 373 | owner_id = node->owner_id; |
| 374 | if (!owner_id) { |
| 375 | |
| 376 | /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */ |
| 377 | |
| 378 | return_ACPI_STATUS(AE_TYPE); |
| 379 | } |
| 380 | |
| 381 | /* Must acquire the interpreter lock during this operation */ |
| 382 | |
| 383 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); |
| 384 | if (ACPI_FAILURE(status)) { |
| 385 | return_ACPI_STATUS(status); |
| 386 | } |
| 387 | |
| 388 | /* Find the table in the global table list */ |
| 389 | |
| 390 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { |
| 391 | if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) { |
| 392 | continue; |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * Allow unload of SSDT and OEMx tables only. Do not allow unload |
| 397 | * of the DSDT. No other types of tables should get here, since |
| 398 | * only these types can contain AML and thus are the only types |
| 399 | * that can create namespace objects. |
| 400 | */ |
| 401 | if (ACPI_COMPARE_NAME |
| 402 | (acpi_gbl_root_table_list.tables[i].signature.ascii, |
| 403 | ACPI_SIG_DSDT)) { |
| 404 | status = AE_TYPE; |
| 405 | break; |
| 406 | } |
| 407 | |
| 408 | /* Ensure the table is actually loaded */ |
| 409 | |
| 410 | if (!acpi_tb_is_table_loaded(i)) { |
| 411 | status = AE_NOT_EXIST; |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | /* Invoke table handler if present */ |
| 416 | |
| 417 | if (acpi_gbl_table_handler) { |
| 418 | (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD, |
| 419 | acpi_gbl_root_table_list. |
| 420 | tables[i].pointer, |
| 421 | acpi_gbl_table_handler_context); |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * Delete all namespace objects owned by this table. Note that |
| 426 | * these objects can appear anywhere in the namespace by virtue |
| 427 | * of the AML "Scope" operator. Thus, we need to track ownership |
| 428 | * by an ID, not simply a position within the hierarchy. |
| 429 | */ |
| 430 | status = acpi_tb_delete_namespace_by_owner(i); |
| 431 | if (ACPI_FAILURE(status)) { |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | status = acpi_tb_release_owner_id(i); |
| 436 | acpi_tb_set_table_loaded_flag(i, FALSE); |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); |
| 441 | return_ACPI_STATUS(status); |
| 442 | } |
| 443 | |
| 444 | ACPI_EXPORT_SYMBOL(acpi_unload_parent_table) |