tbxfload.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 ACPI_INIT_FUNCTION 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_parse_table_as_term_list
  94. || !acpi_gbl_group_module_level_code) {
  95. /*
  96. * Initialize the objects that remain uninitialized. This
  97. * runs the executable AML that may be part of the
  98. * declaration of these objects:
  99. * operation_regions, buffer_fields, Buffers, and Packages.
  100. */
  101. status = acpi_ns_initialize_objects();
  102. if (ACPI_FAILURE(status)) {
  103. return_ACPI_STATUS(status);
  104. }
  105. }
  106. acpi_gbl_namespace_initialized = TRUE;
  107. return_ACPI_STATUS(status);
  108. }
  109. ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
  110. /*******************************************************************************
  111. *
  112. * FUNCTION: acpi_tb_load_namespace
  113. *
  114. * PARAMETERS: None
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
  119. * the RSDT/XSDT.
  120. *
  121. ******************************************************************************/
  122. acpi_status acpi_tb_load_namespace(void)
  123. {
  124. acpi_status status;
  125. u32 i;
  126. struct acpi_table_header *new_dsdt;
  127. struct acpi_table_desc *table;
  128. u32 tables_loaded = 0;
  129. u32 tables_failed = 0;
  130. ACPI_FUNCTION_TRACE(tb_load_namespace);
  131. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  132. /*
  133. * Load the namespace. The DSDT is required, but any SSDT and
  134. * PSDT tables are optional. Verify the DSDT.
  135. */
  136. table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index];
  137. if (!acpi_gbl_root_table_list.current_table_count ||
  138. !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_DSDT) ||
  139. ACPI_FAILURE(acpi_tb_validate_table(table))) {
  140. status = AE_NO_ACPI_TABLES;
  141. goto unlock_and_exit;
  142. }
  143. /*
  144. * Save the DSDT pointer for simple access. This is the mapped memory
  145. * address. We must take care here because the address of the .Tables
  146. * array can change dynamically as tables are loaded at run-time. Note:
  147. * .Pointer field is not validated until after call to acpi_tb_validate_table.
  148. */
  149. acpi_gbl_DSDT = table->pointer;
  150. /*
  151. * Optionally copy the entire DSDT to local memory (instead of simply
  152. * mapping it.) There are some BIOSs that corrupt or replace the original
  153. * DSDT, creating the need for this option. Default is FALSE, do not copy
  154. * the DSDT.
  155. */
  156. if (acpi_gbl_copy_dsdt_locally) {
  157. new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
  158. if (new_dsdt) {
  159. acpi_gbl_DSDT = new_dsdt;
  160. }
  161. }
  162. /*
  163. * Save the original DSDT header for detection of table corruption
  164. * and/or replacement of the DSDT from outside the OS.
  165. */
  166. memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
  167. sizeof(struct acpi_table_header));
  168. /* Load and parse tables */
  169. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  170. status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
  171. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  172. if (ACPI_FAILURE(status)) {
  173. ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
  174. tables_failed++;
  175. } else {
  176. tables_loaded++;
  177. }
  178. /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
  179. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  180. table = &acpi_gbl_root_table_list.tables[i];
  181. if (!acpi_gbl_root_table_list.tables[i].address ||
  182. (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT)
  183. && !ACPI_COMPARE_NAME(table->signature.ascii,
  184. ACPI_SIG_PSDT)
  185. && !ACPI_COMPARE_NAME(table->signature.ascii,
  186. ACPI_SIG_OSDT))
  187. || ACPI_FAILURE(acpi_tb_validate_table(table))) {
  188. continue;
  189. }
  190. /* Ignore errors while loading tables, get as many as possible */
  191. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  192. status = acpi_ns_load_table(i, acpi_gbl_root_node);
  193. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  194. if (ACPI_FAILURE(status)) {
  195. ACPI_EXCEPTION((AE_INFO, status,
  196. "(%4.4s:%8.8s) while loading table",
  197. table->signature.ascii,
  198. table->pointer->oem_table_id));
  199. tables_failed++;
  200. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  201. "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
  202. table->signature.ascii,
  203. table->pointer->oem_table_id));
  204. } else {
  205. tables_loaded++;
  206. }
  207. }
  208. if (!tables_failed) {
  209. ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded\n", tables_loaded));
  210. } else {
  211. ACPI_ERROR((AE_INFO,
  212. "%u table load failures, %u successful",
  213. tables_failed, tables_loaded));
  214. /* Indicate at least one failure */
  215. status = AE_CTRL_TERMINATE;
  216. }
  217. unlock_and_exit:
  218. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  219. return_ACPI_STATUS(status);
  220. }
  221. /*******************************************************************************
  222. *
  223. * FUNCTION: acpi_install_table
  224. *
  225. * PARAMETERS: address - Address of the ACPI table to be installed.
  226. * physical - Whether the address is a physical table
  227. * address or not
  228. *
  229. * RETURN: Status
  230. *
  231. * DESCRIPTION: Dynamically install an ACPI table.
  232. * Note: This function should only be invoked after
  233. * acpi_initialize_tables() and before acpi_load_tables().
  234. *
  235. ******************************************************************************/
  236. acpi_status ACPI_INIT_FUNCTION
  237. acpi_install_table(acpi_physical_address address, u8 physical)
  238. {
  239. acpi_status status;
  240. u8 flags;
  241. u32 table_index;
  242. ACPI_FUNCTION_TRACE(acpi_install_table);
  243. if (physical) {
  244. flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
  245. } else {
  246. flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
  247. }
  248. status = acpi_tb_install_standard_table(address, flags,
  249. FALSE, FALSE, &table_index);
  250. return_ACPI_STATUS(status);
  251. }
  252. ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
  253. /*******************************************************************************
  254. *
  255. * FUNCTION: acpi_load_table
  256. *
  257. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  258. * table to be loaded.
  259. *
  260. * RETURN: Status
  261. *
  262. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  263. * be a valid ACPI table with a valid ACPI table header.
  264. * Note1: Mainly intended to support hotplug addition of SSDTs.
  265. * Note2: Does not copy the incoming table. User is responsible
  266. * to ensure that the table is not deleted or unmapped.
  267. *
  268. ******************************************************************************/
  269. acpi_status acpi_load_table(struct acpi_table_header *table)
  270. {
  271. acpi_status status;
  272. u32 table_index;
  273. ACPI_FUNCTION_TRACE(acpi_load_table);
  274. /* Parameter validation */
  275. if (!table) {
  276. return_ACPI_STATUS(AE_BAD_PARAMETER);
  277. }
  278. /* Install the table and load it into the namespace */
  279. ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
  280. status =
  281. acpi_tb_install_and_load_table(table, ACPI_PTR_TO_PHYSADDR(table),
  282. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  283. FALSE, &table_index);
  284. return_ACPI_STATUS(status);
  285. }
  286. ACPI_EXPORT_SYMBOL(acpi_load_table)
  287. /*******************************************************************************
  288. *
  289. * FUNCTION: acpi_unload_parent_table
  290. *
  291. * PARAMETERS: object - Handle to any namespace object owned by
  292. * the table to be unloaded
  293. *
  294. * RETURN: Status
  295. *
  296. * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
  297. * the table and deletes all namespace objects associated with
  298. * that table. Unloading of the DSDT is not allowed.
  299. * Note: Mainly intended to support hotplug removal of SSDTs.
  300. *
  301. ******************************************************************************/
  302. acpi_status acpi_unload_parent_table(acpi_handle object)
  303. {
  304. struct acpi_namespace_node *node =
  305. ACPI_CAST_PTR(struct acpi_namespace_node, object);
  306. acpi_status status = AE_NOT_EXIST;
  307. acpi_owner_id owner_id;
  308. u32 i;
  309. ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
  310. /* Parameter validation */
  311. if (!object) {
  312. return_ACPI_STATUS(AE_BAD_PARAMETER);
  313. }
  314. /*
  315. * The node owner_id is currently the same as the parent table ID.
  316. * However, this could change in the future.
  317. */
  318. owner_id = node->owner_id;
  319. if (!owner_id) {
  320. /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
  321. return_ACPI_STATUS(AE_TYPE);
  322. }
  323. /* Must acquire the table lock during this operation */
  324. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  325. if (ACPI_FAILURE(status)) {
  326. return_ACPI_STATUS(status);
  327. }
  328. /* Find the table in the global table list */
  329. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  330. if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
  331. continue;
  332. }
  333. /*
  334. * Allow unload of SSDT and OEMx tables only. Do not allow unload
  335. * of the DSDT. No other types of tables should get here, since
  336. * only these types can contain AML and thus are the only types
  337. * that can create namespace objects.
  338. */
  339. if (ACPI_COMPARE_NAME
  340. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  341. ACPI_SIG_DSDT)) {
  342. status = AE_TYPE;
  343. break;
  344. }
  345. /* Ensure the table is actually loaded */
  346. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  347. if (!acpi_tb_is_table_loaded(i)) {
  348. status = AE_NOT_EXIST;
  349. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  350. break;
  351. }
  352. /* Invoke table handler if present */
  353. if (acpi_gbl_table_handler) {
  354. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
  355. acpi_gbl_root_table_list.
  356. tables[i].pointer,
  357. acpi_gbl_table_handler_context);
  358. }
  359. /*
  360. * Delete all namespace objects owned by this table. Note that
  361. * these objects can appear anywhere in the namespace by virtue
  362. * of the AML "Scope" operator. Thus, we need to track ownership
  363. * by an ID, not simply a position within the hierarchy.
  364. */
  365. status = acpi_tb_delete_namespace_by_owner(i);
  366. if (ACPI_FAILURE(status)) {
  367. break;
  368. }
  369. status = acpi_tb_release_owner_id(i);
  370. acpi_tb_set_table_loaded_flag(i, FALSE);
  371. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  372. break;
  373. }
  374. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  375. return_ACPI_STATUS(status);
  376. }
  377. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)