tbxfload.c 11 KB

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