tbxfload.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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", 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. #ifdef ACPI_APPLICATION
  218. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "\n"));
  219. #endif
  220. unlock_and_exit:
  221. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  222. return_ACPI_STATUS(status);
  223. }
  224. /*******************************************************************************
  225. *
  226. * FUNCTION: acpi_install_table
  227. *
  228. * PARAMETERS: address - Address of the ACPI table to be installed.
  229. * physical - Whether the address is a physical table
  230. * address or not
  231. *
  232. * RETURN: Status
  233. *
  234. * DESCRIPTION: Dynamically install an ACPI table.
  235. * Note: This function should only be invoked after
  236. * acpi_initialize_tables() and before acpi_load_tables().
  237. *
  238. ******************************************************************************/
  239. acpi_status ACPI_INIT_FUNCTION
  240. acpi_install_table(acpi_physical_address address, u8 physical)
  241. {
  242. acpi_status status;
  243. u8 flags;
  244. u32 table_index;
  245. ACPI_FUNCTION_TRACE(acpi_install_table);
  246. if (physical) {
  247. flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
  248. } else {
  249. flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
  250. }
  251. status = acpi_tb_install_standard_table(address, flags,
  252. FALSE, FALSE, &table_index);
  253. return_ACPI_STATUS(status);
  254. }
  255. ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
  256. /*******************************************************************************
  257. *
  258. * FUNCTION: acpi_load_table
  259. *
  260. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  261. * table to be loaded.
  262. *
  263. * RETURN: Status
  264. *
  265. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  266. * be a valid ACPI table with a valid ACPI table header.
  267. * Note1: Mainly intended to support hotplug addition of SSDTs.
  268. * Note2: Does not copy the incoming table. User is responsible
  269. * to ensure that the table is not deleted or unmapped.
  270. *
  271. ******************************************************************************/
  272. acpi_status acpi_load_table(struct acpi_table_header *table)
  273. {
  274. acpi_status status;
  275. u32 table_index;
  276. ACPI_FUNCTION_TRACE(acpi_load_table);
  277. /* Parameter validation */
  278. if (!table) {
  279. return_ACPI_STATUS(AE_BAD_PARAMETER);
  280. }
  281. /* Install the table and load it into the namespace */
  282. ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
  283. status = acpi_tb_install_and_load_table(ACPI_PTR_TO_PHYSADDR(table),
  284. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  285. FALSE, &table_index);
  286. return_ACPI_STATUS(status);
  287. }
  288. ACPI_EXPORT_SYMBOL(acpi_load_table)
  289. /*******************************************************************************
  290. *
  291. * FUNCTION: acpi_unload_parent_table
  292. *
  293. * PARAMETERS: object - Handle to any namespace object owned by
  294. * the table to be unloaded
  295. *
  296. * RETURN: Status
  297. *
  298. * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
  299. * the table and deletes all namespace objects associated with
  300. * that table. Unloading of the DSDT is not allowed.
  301. * Note: Mainly intended to support hotplug removal of SSDTs.
  302. *
  303. ******************************************************************************/
  304. acpi_status acpi_unload_parent_table(acpi_handle object)
  305. {
  306. struct acpi_namespace_node *node =
  307. ACPI_CAST_PTR(struct acpi_namespace_node, object);
  308. acpi_status status = AE_NOT_EXIST;
  309. acpi_owner_id owner_id;
  310. u32 i;
  311. ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
  312. /* Parameter validation */
  313. if (!object) {
  314. return_ACPI_STATUS(AE_BAD_PARAMETER);
  315. }
  316. /*
  317. * The node owner_id is currently the same as the parent table ID.
  318. * However, this could change in the future.
  319. */
  320. owner_id = node->owner_id;
  321. if (!owner_id) {
  322. /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
  323. return_ACPI_STATUS(AE_TYPE);
  324. }
  325. /* Must acquire the table lock during this operation */
  326. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  327. if (ACPI_FAILURE(status)) {
  328. return_ACPI_STATUS(status);
  329. }
  330. /* Find the table in the global table list */
  331. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  332. if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
  333. continue;
  334. }
  335. /*
  336. * Allow unload of SSDT and OEMx tables only. Do not allow unload
  337. * of the DSDT. No other types of tables should get here, since
  338. * only these types can contain AML and thus are the only types
  339. * that can create namespace objects.
  340. */
  341. if (ACPI_COMPARE_NAME
  342. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  343. ACPI_SIG_DSDT)) {
  344. status = AE_TYPE;
  345. break;
  346. }
  347. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  348. status = acpi_tb_unload_table(i);
  349. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  350. break;
  351. }
  352. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  353. return_ACPI_STATUS(status);
  354. }
  355. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)