1 /****************************************************************************** 2 * 3 * Module Name: tbxfload - Table load/unload external interfaces 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, 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 51 #define _COMPONENT ACPI_TABLES 52 ACPI_MODULE_NAME("tbxfload") 53 54 /* Local prototypes */ 55 static acpi_status acpi_tb_load_namespace(void); 56 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 69 acpi_status __init acpi_load_tables(void) 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 86 ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables) 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 || 120 ACPI_FAILURE(acpi_tb_verify_table 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: 131 * .Pointer field is not validated until after call to acpi_tb_verify_table. 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 */ 153 ACPI_MEMCPY(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT, 154 sizeof(struct acpi_table_header)); 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) { 169 if ((!ACPI_COMPARE_NAME 170 (&(acpi_gbl_root_table_list.tables[i].signature), 171 ACPI_SIG_SSDT) 172 && 173 !ACPI_COMPARE_NAME(& 174 (acpi_gbl_root_table_list.tables[i]. 175 signature), ACPI_SIG_PSDT)) 176 || 177 ACPI_FAILURE(acpi_tb_verify_table 178 (&acpi_gbl_root_table_list.tables[i]))) { 179 continue; 180 } 181 182 /* 183 * Optionally do not load any SSDTs from the RSDT/XSDT. This can 184 * be useful for debugging ACPI problems on some machines. 185 */ 186 if (acpi_gbl_disable_ssdt_table_load) { 187 ACPI_INFO((AE_INFO, "Ignoring %4.4s at %p", 188 acpi_gbl_root_table_list.tables[i].signature. 189 ascii, ACPI_CAST_PTR(void, 190 acpi_gbl_root_table_list. 191 tables[i].address))); 192 continue; 193 } 194 195 /* Ignore errors while loading tables, get as many as possible */ 196 197 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 198 (void)acpi_ns_load_table(i, acpi_gbl_root_node); 199 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 200 } 201 202 ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired")); 203 204 unlock_and_exit: 205 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 206 return_ACPI_STATUS(status); 207 } 208 209 /******************************************************************************* 210 * 211 * FUNCTION: acpi_load_table 212 * 213 * PARAMETERS: table - Pointer to a buffer containing the ACPI 214 * table to be loaded. 215 * 216 * RETURN: Status 217 * 218 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must 219 * be a valid ACPI table with a valid ACPI table header. 220 * Note1: Mainly intended to support hotplug addition of SSDTs. 221 * Note2: Does not copy the incoming table. User is responsible 222 * to ensure that the table is not deleted or unmapped. 223 * 224 ******************************************************************************/ 225 226 acpi_status acpi_load_table(struct acpi_table_header *table) 227 { 228 acpi_status status; 229 struct acpi_table_desc table_desc; 230 u32 table_index; 231 232 ACPI_FUNCTION_TRACE(acpi_load_table); 233 234 /* Parameter validation */ 235 236 if (!table) { 237 return_ACPI_STATUS(AE_BAD_PARAMETER); 238 } 239 240 /* Init local table descriptor */ 241 242 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc)); 243 table_desc.address = ACPI_PTR_TO_PHYSADDR(table); 244 table_desc.pointer = table; 245 table_desc.length = table->length; 246 table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN; 247 248 /* Must acquire the interpreter lock during this operation */ 249 250 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); 251 if (ACPI_FAILURE(status)) { 252 return_ACPI_STATUS(status); 253 } 254 255 /* Install the table and load it into the namespace */ 256 257 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:")); 258 status = acpi_tb_add_table(&table_desc, &table_index); 259 if (ACPI_FAILURE(status)) { 260 goto unlock_and_exit; 261 } 262 263 status = acpi_ns_load_table(table_index, acpi_gbl_root_node); 264 265 /* Invoke table handler if present */ 266 267 if (acpi_gbl_table_handler) { 268 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table, 269 acpi_gbl_table_handler_context); 270 } 271 272 unlock_and_exit: 273 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); 274 return_ACPI_STATUS(status); 275 } 276 277 ACPI_EXPORT_SYMBOL(acpi_load_table) 278 279 /******************************************************************************* 280 * 281 * FUNCTION: acpi_unload_parent_table 282 * 283 * PARAMETERS: object - Handle to any namespace object owned by 284 * the table to be unloaded 285 * 286 * RETURN: Status 287 * 288 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads 289 * the table and deletes all namespace objects associated with 290 * that table. Unloading of the DSDT is not allowed. 291 * Note: Mainly intended to support hotplug removal of SSDTs. 292 * 293 ******************************************************************************/ 294 acpi_status acpi_unload_parent_table(acpi_handle object) 295 { 296 struct acpi_namespace_node *node = 297 ACPI_CAST_PTR(struct acpi_namespace_node, object); 298 acpi_status status = AE_NOT_EXIST; 299 acpi_owner_id owner_id; 300 u32 i; 301 302 ACPI_FUNCTION_TRACE(acpi_unload_parent_table); 303 304 /* Parameter validation */ 305 306 if (!object) { 307 return_ACPI_STATUS(AE_BAD_PARAMETER); 308 } 309 310 /* 311 * The node owner_id is currently the same as the parent table ID. 312 * However, this could change in the future. 313 */ 314 owner_id = node->owner_id; 315 if (!owner_id) { 316 317 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */ 318 319 return_ACPI_STATUS(AE_TYPE); 320 } 321 322 /* Must acquire the interpreter lock during this operation */ 323 324 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); 325 if (ACPI_FAILURE(status)) { 326 return_ACPI_STATUS(status); 327 } 328 329 /* Find the table in the global table list */ 330 331 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { 332 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) { 333 continue; 334 } 335 336 /* 337 * Allow unload of SSDT and OEMx tables only. Do not allow unload 338 * of the DSDT. No other types of tables should get here, since 339 * only these types can contain AML and thus are the only types 340 * that can create namespace objects. 341 */ 342 if (ACPI_COMPARE_NAME 343 (acpi_gbl_root_table_list.tables[i].signature.ascii, 344 ACPI_SIG_DSDT)) { 345 status = AE_TYPE; 346 break; 347 } 348 349 /* Ensure the table is actually loaded */ 350 351 if (!acpi_tb_is_table_loaded(i)) { 352 status = AE_NOT_EXIST; 353 break; 354 } 355 356 /* Invoke table handler if present */ 357 358 if (acpi_gbl_table_handler) { 359 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD, 360 acpi_gbl_root_table_list. 361 tables[i].pointer, 362 acpi_gbl_table_handler_context); 363 } 364 365 /* 366 * Delete all namespace objects owned by this table. Note that 367 * these objects can appear anywhere in the namespace by virtue 368 * of the AML "Scope" operator. Thus, we need to track ownership 369 * by an ID, not simply a position within the hierarchy. 370 */ 371 status = acpi_tb_delete_namespace_by_owner(i); 372 if (ACPI_FAILURE(status)) { 373 break; 374 } 375 376 status = acpi_tb_release_owner_id(i); 377 acpi_tb_set_table_loaded_flag(i, FALSE); 378 break; 379 } 380 381 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); 382 return_ACPI_STATUS(status); 383 } 384 385 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table) 386