tbxfload.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxfload - Table load/unload external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #define EXPORT_ACPI_INTERFACES
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acnamesp.h"
  46. #include "actables.h"
  47. #include "acevents.h"
  48. #define _COMPONENT ACPI_TABLES
  49. ACPI_MODULE_NAME("tbxfload")
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_load_tables
  53. *
  54. * PARAMETERS: None
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
  59. *
  60. ******************************************************************************/
  61. acpi_status __init acpi_load_tables(void)
  62. {
  63. acpi_status status;
  64. ACPI_FUNCTION_TRACE(acpi_load_tables);
  65. /*
  66. * Install the default operation region handlers. These are the
  67. * handlers that are defined by the ACPI specification to be
  68. * "always accessible" -- namely, system_memory, system_IO, and
  69. * PCI_Config. This also means that no _REG methods need to be
  70. * run for these address spaces. We need to have these handlers
  71. * installed before any AML code can be executed, especially any
  72. * module-level code (11/2015).
  73. * Note that we allow OSPMs to install their own region handlers
  74. * between acpi_initialize_subsystem() and acpi_load_tables() to use
  75. * their customized default region handlers.
  76. */
  77. status = acpi_ev_install_region_handlers();
  78. if (ACPI_FAILURE(status)) {
  79. ACPI_EXCEPTION((AE_INFO, status,
  80. "During Region initialization"));
  81. return_ACPI_STATUS(status);
  82. }
  83. /* Load the namespace from the tables */
  84. status = acpi_tb_load_namespace();
  85. /* Don't let single failures abort the load */
  86. if (status == AE_CTRL_TERMINATE) {
  87. status = AE_OK;
  88. }
  89. if (ACPI_FAILURE(status)) {
  90. ACPI_EXCEPTION((AE_INFO, status,
  91. "While loading namespace from ACPI tables"));
  92. }
  93. if (!acpi_gbl_group_module_level_code) {
  94. /*
  95. * Initialize the objects that remain uninitialized. This
  96. * runs the executable AML that may be part of the
  97. * declaration of these objects:
  98. * operation_regions, buffer_fields, Buffers, and Packages.
  99. */
  100. status = acpi_ns_initialize_objects();
  101. if (ACPI_FAILURE(status)) {
  102. return_ACPI_STATUS(status);
  103. }
  104. }
  105. acpi_gbl_namespace_initialized = TRUE;
  106. return_ACPI_STATUS(status);
  107. }
  108. ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_tb_load_namespace
  112. *
  113. * PARAMETERS: None
  114. *
  115. * RETURN: Status
  116. *
  117. * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
  118. * the RSDT/XSDT.
  119. *
  120. ******************************************************************************/
  121. acpi_status acpi_tb_load_namespace(void)
  122. {
  123. acpi_status status;
  124. u32 i;
  125. struct acpi_table_header *new_dsdt;
  126. struct acpi_table_desc *table;
  127. u32 tables_loaded = 0;
  128. u32 tables_failed = 0;
  129. ACPI_FUNCTION_TRACE(tb_load_namespace);
  130. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  131. /*
  132. * Load the namespace. The DSDT is required, but any SSDT and
  133. * PSDT tables are optional. Verify the DSDT.
  134. */
  135. table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index];
  136. if (!acpi_gbl_root_table_list.current_table_count ||
  137. !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_DSDT) ||
  138. ACPI_FAILURE(acpi_tb_validate_table(table))) {
  139. status = AE_NO_ACPI_TABLES;
  140. goto unlock_and_exit;
  141. }
  142. /*
  143. * Save the DSDT pointer for simple access. This is the mapped memory
  144. * address. We must take care here because the address of the .Tables
  145. * array can change dynamically as tables are loaded at run-time. Note:
  146. * .Pointer field is not validated until after call to acpi_tb_validate_table.
  147. */
  148. acpi_gbl_DSDT = table->pointer;
  149. /*
  150. * Optionally copy the entire DSDT to local memory (instead of simply
  151. * mapping it.) There are some BIOSs that corrupt or replace the original
  152. * DSDT, creating the need for this option. Default is FALSE, do not copy
  153. * the DSDT.
  154. */
  155. if (acpi_gbl_copy_dsdt_locally) {
  156. new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
  157. if (new_dsdt) {
  158. acpi_gbl_DSDT = new_dsdt;
  159. }
  160. }
  161. /*
  162. * Save the original DSDT header for detection of table corruption
  163. * and/or replacement of the DSDT from outside the OS.
  164. */
  165. memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
  166. sizeof(struct acpi_table_header));
  167. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  168. /* Load and parse tables */
  169. status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
  170. if (ACPI_FAILURE(status)) {
  171. ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
  172. tables_failed++;
  173. } else {
  174. tables_loaded++;
  175. }
  176. /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
  177. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  178. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  179. table = &acpi_gbl_root_table_list.tables[i];
  180. if (!acpi_gbl_root_table_list.tables[i].address ||
  181. (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT)
  182. && !ACPI_COMPARE_NAME(table->signature.ascii,
  183. ACPI_SIG_PSDT)
  184. && !ACPI_COMPARE_NAME(table->signature.ascii,
  185. ACPI_SIG_OSDT))
  186. || ACPI_FAILURE(acpi_tb_validate_table(table))) {
  187. continue;
  188. }
  189. /* Ignore errors while loading tables, get as many as possible */
  190. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  191. status = acpi_ns_load_table(i, acpi_gbl_root_node);
  192. if (ACPI_FAILURE(status)) {
  193. ACPI_EXCEPTION((AE_INFO, status,
  194. "(%4.4s:%8.8s) while loading table",
  195. table->signature.ascii,
  196. table->pointer->oem_table_id));
  197. tables_failed++;
  198. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  199. "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
  200. table->signature.ascii,
  201. table->pointer->oem_table_id));
  202. } else {
  203. tables_loaded++;
  204. }
  205. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  206. }
  207. if (!tables_failed) {
  208. ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded\n", tables_loaded));
  209. } else {
  210. ACPI_ERROR((AE_INFO,
  211. "%u table load failures, %u successful",
  212. tables_failed, tables_loaded));
  213. /* Indicate at least one failure */
  214. status = AE_CTRL_TERMINATE;
  215. }
  216. unlock_and_exit:
  217. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  218. return_ACPI_STATUS(status);
  219. }
  220. /*******************************************************************************
  221. *
  222. * FUNCTION: acpi_install_table
  223. *
  224. * PARAMETERS: address - Address of the ACPI table to be installed.
  225. * physical - Whether the address is a physical table
  226. * address or not
  227. *
  228. * RETURN: Status
  229. *
  230. * DESCRIPTION: Dynamically install an ACPI table.
  231. * Note: This function should only be invoked after
  232. * acpi_initialize_tables() and before acpi_load_tables().
  233. *
  234. ******************************************************************************/
  235. acpi_status __init
  236. acpi_install_table(acpi_physical_address address, u8 physical)
  237. {
  238. acpi_status status;
  239. u8 flags;
  240. u32 table_index;
  241. ACPI_FUNCTION_TRACE(acpi_install_table);
  242. if (physical) {
  243. flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
  244. } else {
  245. flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
  246. }
  247. status = acpi_tb_install_standard_table(address, flags,
  248. FALSE, FALSE, &table_index);
  249. return_ACPI_STATUS(status);
  250. }
  251. ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
  252. /*******************************************************************************
  253. *
  254. * FUNCTION: acpi_load_table
  255. *
  256. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  257. * table to be loaded.
  258. *
  259. * RETURN: Status
  260. *
  261. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  262. * be a valid ACPI table with a valid ACPI table header.
  263. * Note1: Mainly intended to support hotplug addition of SSDTs.
  264. * Note2: Does not copy the incoming table. User is responsible
  265. * to ensure that the table is not deleted or unmapped.
  266. *
  267. ******************************************************************************/
  268. acpi_status acpi_load_table(struct acpi_table_header *table)
  269. {
  270. acpi_status status;
  271. u32 table_index;
  272. ACPI_FUNCTION_TRACE(acpi_load_table);
  273. /* Parameter validation */
  274. if (!table) {
  275. return_ACPI_STATUS(AE_BAD_PARAMETER);
  276. }
  277. /* Must acquire the interpreter lock during this operation */
  278. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  279. if (ACPI_FAILURE(status)) {
  280. return_ACPI_STATUS(status);
  281. }
  282. /* Install the table and load it into the namespace */
  283. ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
  284. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  285. status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table),
  286. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  287. TRUE, FALSE, &table_index);
  288. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  289. if (ACPI_FAILURE(status)) {
  290. goto unlock_and_exit;
  291. }
  292. /*
  293. * Note: Now table is "INSTALLED", it must be validated before
  294. * using.
  295. */
  296. status =
  297. acpi_tb_validate_table(&acpi_gbl_root_table_list.
  298. tables[table_index]);
  299. if (ACPI_FAILURE(status)) {
  300. goto unlock_and_exit;
  301. }
  302. status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
  303. /* Invoke table handler if present */
  304. if (acpi_gbl_table_handler) {
  305. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
  306. acpi_gbl_table_handler_context);
  307. }
  308. unlock_and_exit:
  309. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  310. return_ACPI_STATUS(status);
  311. }
  312. ACPI_EXPORT_SYMBOL(acpi_load_table)
  313. /*******************************************************************************
  314. *
  315. * FUNCTION: acpi_unload_parent_table
  316. *
  317. * PARAMETERS: object - Handle to any namespace object owned by
  318. * the table to be unloaded
  319. *
  320. * RETURN: Status
  321. *
  322. * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
  323. * the table and deletes all namespace objects associated with
  324. * that table. Unloading of the DSDT is not allowed.
  325. * Note: Mainly intended to support hotplug removal of SSDTs.
  326. *
  327. ******************************************************************************/
  328. acpi_status acpi_unload_parent_table(acpi_handle object)
  329. {
  330. struct acpi_namespace_node *node =
  331. ACPI_CAST_PTR(struct acpi_namespace_node, object);
  332. acpi_status status = AE_NOT_EXIST;
  333. acpi_owner_id owner_id;
  334. u32 i;
  335. ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
  336. /* Parameter validation */
  337. if (!object) {
  338. return_ACPI_STATUS(AE_BAD_PARAMETER);
  339. }
  340. /*
  341. * The node owner_id is currently the same as the parent table ID.
  342. * However, this could change in the future.
  343. */
  344. owner_id = node->owner_id;
  345. if (!owner_id) {
  346. /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
  347. return_ACPI_STATUS(AE_TYPE);
  348. }
  349. /* Must acquire the interpreter lock during this operation */
  350. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  351. if (ACPI_FAILURE(status)) {
  352. return_ACPI_STATUS(status);
  353. }
  354. /* Find the table in the global table list */
  355. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  356. if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
  357. continue;
  358. }
  359. /*
  360. * Allow unload of SSDT and OEMx tables only. Do not allow unload
  361. * of the DSDT. No other types of tables should get here, since
  362. * only these types can contain AML and thus are the only types
  363. * that can create namespace objects.
  364. */
  365. if (ACPI_COMPARE_NAME
  366. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  367. ACPI_SIG_DSDT)) {
  368. status = AE_TYPE;
  369. break;
  370. }
  371. /* Ensure the table is actually loaded */
  372. if (!acpi_tb_is_table_loaded(i)) {
  373. status = AE_NOT_EXIST;
  374. break;
  375. }
  376. /* Invoke table handler if present */
  377. if (acpi_gbl_table_handler) {
  378. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
  379. acpi_gbl_root_table_list.
  380. tables[i].pointer,
  381. acpi_gbl_table_handler_context);
  382. }
  383. /*
  384. * Delete all namespace objects owned by this table. Note that
  385. * these objects can appear anywhere in the namespace by virtue
  386. * of the AML "Scope" operator. Thus, we need to track ownership
  387. * by an ID, not simply a position within the hierarchy.
  388. */
  389. status = acpi_tb_delete_namespace_by_owner(i);
  390. if (ACPI_FAILURE(status)) {
  391. break;
  392. }
  393. status = acpi_tb_release_owner_id(i);
  394. acpi_tb_set_table_loaded_flag(i, FALSE);
  395. break;
  396. }
  397. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  398. return_ACPI_STATUS(status);
  399. }
  400. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)