tbxfload.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: tbxfload - Table load/unload external interfaces
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #define EXPORT_ACPI_INTERFACES
  10. #include <acpi/acpi.h>
  11. #include "accommon.h"
  12. #include "acnamesp.h"
  13. #include "actables.h"
  14. #include "acevents.h"
  15. #define _COMPONENT ACPI_TABLES
  16. ACPI_MODULE_NAME("tbxfload")
  17. /*******************************************************************************
  18. *
  19. * FUNCTION: acpi_load_tables
  20. *
  21. * PARAMETERS: None
  22. *
  23. * RETURN: Status
  24. *
  25. * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
  26. *
  27. ******************************************************************************/
  28. acpi_status ACPI_INIT_FUNCTION acpi_load_tables(void)
  29. {
  30. acpi_status status;
  31. ACPI_FUNCTION_TRACE(acpi_load_tables);
  32. /*
  33. * Install the default operation region handlers. These are the
  34. * handlers that are defined by the ACPI specification to be
  35. * "always accessible" -- namely, system_memory, system_IO, and
  36. * PCI_Config. This also means that no _REG methods need to be
  37. * run for these address spaces. We need to have these handlers
  38. * installed before any AML code can be executed, especially any
  39. * module-level code (11/2015).
  40. * Note that we allow OSPMs to install their own region handlers
  41. * between acpi_initialize_subsystem() and acpi_load_tables() to use
  42. * their customized default region handlers.
  43. */
  44. status = acpi_ev_install_region_handlers();
  45. if (ACPI_FAILURE(status)) {
  46. ACPI_EXCEPTION((AE_INFO, status,
  47. "During Region initialization"));
  48. return_ACPI_STATUS(status);
  49. }
  50. /* Load the namespace from the tables */
  51. status = acpi_tb_load_namespace();
  52. /* Don't let single failures abort the load */
  53. if (status == AE_CTRL_TERMINATE) {
  54. status = AE_OK;
  55. }
  56. if (ACPI_FAILURE(status)) {
  57. ACPI_EXCEPTION((AE_INFO, status,
  58. "While loading namespace from ACPI tables"));
  59. }
  60. if (acpi_gbl_execute_tables_as_methods) {
  61. /*
  62. * If the module-level code support is enabled, initialize the objects
  63. * in the namespace that remain uninitialized. This runs the executable
  64. * AML that may be part of the declaration of these name objects:
  65. * operation_regions, buffer_fields, Buffers, and Packages.
  66. *
  67. * Note: The module-level code is optional at this time, but will
  68. * become the default in the future.
  69. */
  70. status = acpi_ns_initialize_objects();
  71. if (ACPI_FAILURE(status)) {
  72. return_ACPI_STATUS(status);
  73. }
  74. }
  75. acpi_gbl_namespace_initialized = TRUE;
  76. return_ACPI_STATUS(status);
  77. }
  78. ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
  79. /*******************************************************************************
  80. *
  81. * FUNCTION: acpi_tb_load_namespace
  82. *
  83. * PARAMETERS: None
  84. *
  85. * RETURN: Status
  86. *
  87. * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
  88. * the RSDT/XSDT.
  89. *
  90. ******************************************************************************/
  91. acpi_status acpi_tb_load_namespace(void)
  92. {
  93. acpi_status status;
  94. u32 i;
  95. struct acpi_table_header *new_dsdt;
  96. struct acpi_table_desc *table;
  97. u32 tables_loaded = 0;
  98. u32 tables_failed = 0;
  99. ACPI_FUNCTION_TRACE(tb_load_namespace);
  100. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  101. /*
  102. * Load the namespace. The DSDT is required, but any SSDT and
  103. * PSDT tables are optional. Verify the DSDT.
  104. */
  105. table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index];
  106. if (!acpi_gbl_root_table_list.current_table_count ||
  107. !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_DSDT) ||
  108. ACPI_FAILURE(acpi_tb_validate_table(table))) {
  109. status = AE_NO_ACPI_TABLES;
  110. goto unlock_and_exit;
  111. }
  112. /*
  113. * Save the DSDT pointer for simple access. This is the mapped memory
  114. * address. We must take care here because the address of the .Tables
  115. * array can change dynamically as tables are loaded at run-time. Note:
  116. * .Pointer field is not validated until after call to acpi_tb_validate_table.
  117. */
  118. acpi_gbl_DSDT = table->pointer;
  119. /*
  120. * Optionally copy the entire DSDT to local memory (instead of simply
  121. * mapping it.) There are some BIOSs that corrupt or replace the original
  122. * DSDT, creating the need for this option. Default is FALSE, do not copy
  123. * the DSDT.
  124. */
  125. if (acpi_gbl_copy_dsdt_locally) {
  126. new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
  127. if (new_dsdt) {
  128. acpi_gbl_DSDT = new_dsdt;
  129. }
  130. }
  131. /*
  132. * Save the original DSDT header for detection of table corruption
  133. * and/or replacement of the DSDT from outside the OS.
  134. */
  135. memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
  136. sizeof(struct acpi_table_header));
  137. /* Load and parse tables */
  138. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  139. status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
  140. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  141. if (ACPI_FAILURE(status)) {
  142. ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
  143. tables_failed++;
  144. } else {
  145. tables_loaded++;
  146. }
  147. /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
  148. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  149. table = &acpi_gbl_root_table_list.tables[i];
  150. if (!table->address ||
  151. (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT)
  152. && !ACPI_COMPARE_NAME(table->signature.ascii,
  153. ACPI_SIG_PSDT)
  154. && !ACPI_COMPARE_NAME(table->signature.ascii,
  155. ACPI_SIG_OSDT))
  156. || ACPI_FAILURE(acpi_tb_validate_table(table))) {
  157. continue;
  158. }
  159. /* Ignore errors while loading tables, get as many as possible */
  160. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  161. status = acpi_ns_load_table(i, acpi_gbl_root_node);
  162. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  163. if (ACPI_FAILURE(status)) {
  164. ACPI_EXCEPTION((AE_INFO, status,
  165. "(%4.4s:%8.8s) while loading table",
  166. table->signature.ascii,
  167. table->pointer->oem_table_id));
  168. tables_failed++;
  169. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  170. "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
  171. table->signature.ascii,
  172. table->pointer->oem_table_id));
  173. } else {
  174. tables_loaded++;
  175. }
  176. }
  177. if (!tables_failed) {
  178. ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded", tables_loaded));
  179. } else {
  180. ACPI_ERROR((AE_INFO,
  181. "%u table load failures, %u successful",
  182. tables_failed, tables_loaded));
  183. /* Indicate at least one failure */
  184. status = AE_CTRL_TERMINATE;
  185. }
  186. #ifdef ACPI_APPLICATION
  187. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "\n"));
  188. #endif
  189. unlock_and_exit:
  190. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  191. return_ACPI_STATUS(status);
  192. }
  193. /*******************************************************************************
  194. *
  195. * FUNCTION: acpi_install_table
  196. *
  197. * PARAMETERS: address - Address of the ACPI table to be installed.
  198. * physical - Whether the address is a physical table
  199. * address or not
  200. *
  201. * RETURN: Status
  202. *
  203. * DESCRIPTION: Dynamically install an ACPI table.
  204. * Note: This function should only be invoked after
  205. * acpi_initialize_tables() and before acpi_load_tables().
  206. *
  207. ******************************************************************************/
  208. acpi_status ACPI_INIT_FUNCTION
  209. acpi_install_table(acpi_physical_address address, u8 physical)
  210. {
  211. acpi_status status;
  212. u8 flags;
  213. u32 table_index;
  214. ACPI_FUNCTION_TRACE(acpi_install_table);
  215. if (physical) {
  216. flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
  217. } else {
  218. flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
  219. }
  220. status = acpi_tb_install_standard_table(address, flags,
  221. FALSE, FALSE, &table_index);
  222. return_ACPI_STATUS(status);
  223. }
  224. ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
  225. /*******************************************************************************
  226. *
  227. * FUNCTION: acpi_load_table
  228. *
  229. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  230. * table to be loaded.
  231. *
  232. * RETURN: Status
  233. *
  234. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  235. * be a valid ACPI table with a valid ACPI table header.
  236. * Note1: Mainly intended to support hotplug addition of SSDTs.
  237. * Note2: Does not copy the incoming table. User is responsible
  238. * to ensure that the table is not deleted or unmapped.
  239. *
  240. ******************************************************************************/
  241. acpi_status acpi_load_table(struct acpi_table_header *table)
  242. {
  243. acpi_status status;
  244. u32 table_index;
  245. ACPI_FUNCTION_TRACE(acpi_load_table);
  246. /* Parameter validation */
  247. if (!table) {
  248. return_ACPI_STATUS(AE_BAD_PARAMETER);
  249. }
  250. /* Install the table and load it into the namespace */
  251. ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
  252. status = acpi_tb_install_and_load_table(ACPI_PTR_TO_PHYSADDR(table),
  253. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  254. FALSE, &table_index);
  255. return_ACPI_STATUS(status);
  256. }
  257. ACPI_EXPORT_SYMBOL(acpi_load_table)
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_unload_parent_table
  261. *
  262. * PARAMETERS: object - Handle to any namespace object owned by
  263. * the table to be unloaded
  264. *
  265. * RETURN: Status
  266. *
  267. * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
  268. * the table and deletes all namespace objects associated with
  269. * that table. Unloading of the DSDT is not allowed.
  270. * Note: Mainly intended to support hotplug removal of SSDTs.
  271. *
  272. ******************************************************************************/
  273. acpi_status acpi_unload_parent_table(acpi_handle object)
  274. {
  275. struct acpi_namespace_node *node =
  276. ACPI_CAST_PTR(struct acpi_namespace_node, object);
  277. acpi_status status = AE_NOT_EXIST;
  278. acpi_owner_id owner_id;
  279. u32 i;
  280. ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
  281. /* Parameter validation */
  282. if (!object) {
  283. return_ACPI_STATUS(AE_BAD_PARAMETER);
  284. }
  285. /*
  286. * The node owner_id is currently the same as the parent table ID.
  287. * However, this could change in the future.
  288. */
  289. owner_id = node->owner_id;
  290. if (!owner_id) {
  291. /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
  292. return_ACPI_STATUS(AE_TYPE);
  293. }
  294. /* Must acquire the table lock during this operation */
  295. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  296. if (ACPI_FAILURE(status)) {
  297. return_ACPI_STATUS(status);
  298. }
  299. /* Find the table in the global table list */
  300. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  301. if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
  302. continue;
  303. }
  304. /*
  305. * Allow unload of SSDT and OEMx tables only. Do not allow unload
  306. * of the DSDT. No other types of tables should get here, since
  307. * only these types can contain AML and thus are the only types
  308. * that can create namespace objects.
  309. */
  310. if (ACPI_COMPARE_NAME
  311. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  312. ACPI_SIG_DSDT)) {
  313. status = AE_TYPE;
  314. break;
  315. }
  316. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  317. status = acpi_tb_unload_table(i);
  318. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  319. break;
  320. }
  321. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  322. return_ACPI_STATUS(status);
  323. }
  324. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)