tbxfload.c 13 KB

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