tbxfload.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxfload - Table load/unload external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. #define _COMPONENT ACPI_TABLES
  48. ACPI_MODULE_NAME("tbxfload")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_load_tables
  52. *
  53. * PARAMETERS: None
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
  58. *
  59. ******************************************************************************/
  60. acpi_status __init acpi_load_tables(void)
  61. {
  62. acpi_status status;
  63. ACPI_FUNCTION_TRACE(acpi_load_tables);
  64. /* Load the namespace from the tables */
  65. status = acpi_tb_load_namespace();
  66. /* Don't let single failures abort the load */
  67. if (status == AE_CTRL_TERMINATE) {
  68. status = AE_OK;
  69. }
  70. if (ACPI_FAILURE(status)) {
  71. ACPI_EXCEPTION((AE_INFO, status,
  72. "While loading namespace from ACPI tables"));
  73. }
  74. return_ACPI_STATUS(status);
  75. }
  76. ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
  77. /*******************************************************************************
  78. *
  79. * FUNCTION: acpi_tb_load_namespace
  80. *
  81. * PARAMETERS: None
  82. *
  83. * RETURN: Status
  84. *
  85. * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
  86. * the RSDT/XSDT.
  87. *
  88. ******************************************************************************/
  89. acpi_status acpi_tb_load_namespace(void)
  90. {
  91. acpi_status status;
  92. u32 i;
  93. struct acpi_table_header *new_dsdt;
  94. struct acpi_table_desc *table;
  95. u32 tables_loaded = 0;
  96. u32 tables_failed = 0;
  97. ACPI_FUNCTION_TRACE(tb_load_namespace);
  98. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  99. /*
  100. * Load the namespace. The DSDT is required, but any SSDT and
  101. * PSDT tables are optional. Verify the DSDT.
  102. */
  103. table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index];
  104. if (!acpi_gbl_root_table_list.current_table_count ||
  105. !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_DSDT) ||
  106. ACPI_FAILURE(acpi_tb_validate_table(table))) {
  107. status = AE_NO_ACPI_TABLES;
  108. goto unlock_and_exit;
  109. }
  110. /*
  111. * Save the DSDT pointer for simple access. This is the mapped memory
  112. * address. We must take care here because the address of the .Tables
  113. * array can change dynamically as tables are loaded at run-time. Note:
  114. * .Pointer field is not validated until after call to acpi_tb_validate_table.
  115. */
  116. acpi_gbl_DSDT = table->pointer;
  117. /*
  118. * Optionally copy the entire DSDT to local memory (instead of simply
  119. * mapping it.) There are some BIOSs that corrupt or replace the original
  120. * DSDT, creating the need for this option. Default is FALSE, do not copy
  121. * the DSDT.
  122. */
  123. if (acpi_gbl_copy_dsdt_locally) {
  124. new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
  125. if (new_dsdt) {
  126. acpi_gbl_DSDT = new_dsdt;
  127. }
  128. }
  129. /*
  130. * Save the original DSDT header for detection of table corruption
  131. * and/or replacement of the DSDT from outside the OS.
  132. */
  133. memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
  134. sizeof(struct acpi_table_header));
  135. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  136. /* Load and parse tables */
  137. status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
  138. if (ACPI_FAILURE(status)) {
  139. ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
  140. tables_failed++;
  141. } else {
  142. tables_loaded++;
  143. }
  144. /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
  145. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  146. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  147. table = &acpi_gbl_root_table_list.tables[i];
  148. if (!acpi_gbl_root_table_list.tables[i].address ||
  149. (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT)
  150. && !ACPI_COMPARE_NAME(table->signature.ascii,
  151. ACPI_SIG_PSDT)
  152. && !ACPI_COMPARE_NAME(table->signature.ascii,
  153. ACPI_SIG_OSDT))
  154. || ACPI_FAILURE(acpi_tb_validate_table(table))) {
  155. continue;
  156. }
  157. /* Ignore errors while loading tables, get as many as possible */
  158. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  159. status = acpi_ns_load_table(i, acpi_gbl_root_node);
  160. if (ACPI_FAILURE(status)) {
  161. ACPI_EXCEPTION((AE_INFO, status,
  162. "(%4.4s:%8.8s) while loading table",
  163. table->signature.ascii,
  164. table->pointer->oem_table_id));
  165. tables_failed++;
  166. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  167. "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
  168. table->signature.ascii,
  169. table->pointer->oem_table_id));
  170. } else {
  171. tables_loaded++;
  172. }
  173. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  174. }
  175. if (!tables_failed) {
  176. ACPI_INFO((AE_INFO,
  177. "%u ACPI AML tables successfully acquired and loaded",
  178. 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. unlock_and_exit:
  187. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  188. return_ACPI_STATUS(status);
  189. }
  190. /*******************************************************************************
  191. *
  192. * FUNCTION: acpi_install_table
  193. *
  194. * PARAMETERS: address - Address of the ACPI table to be installed.
  195. * physical - Whether the address is a physical table
  196. * address or not
  197. *
  198. * RETURN: Status
  199. *
  200. * DESCRIPTION: Dynamically install an ACPI table.
  201. * Note: This function should only be invoked after
  202. * acpi_initialize_tables() and before acpi_load_tables().
  203. *
  204. ******************************************************************************/
  205. acpi_status __init
  206. acpi_install_table(acpi_physical_address address, u8 physical)
  207. {
  208. acpi_status status;
  209. u8 flags;
  210. u32 table_index;
  211. ACPI_FUNCTION_TRACE(acpi_install_table);
  212. if (physical) {
  213. flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
  214. } else {
  215. flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
  216. }
  217. status = acpi_tb_install_standard_table(address, flags,
  218. FALSE, FALSE, &table_index);
  219. return_ACPI_STATUS(status);
  220. }
  221. ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
  222. /*******************************************************************************
  223. *
  224. * FUNCTION: acpi_load_table
  225. *
  226. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  227. * table to be loaded.
  228. *
  229. * RETURN: Status
  230. *
  231. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  232. * be a valid ACPI table with a valid ACPI table header.
  233. * Note1: Mainly intended to support hotplug addition of SSDTs.
  234. * Note2: Does not copy the incoming table. User is responsible
  235. * to ensure that the table is not deleted or unmapped.
  236. *
  237. ******************************************************************************/
  238. acpi_status acpi_load_table(struct acpi_table_header *table)
  239. {
  240. acpi_status status;
  241. u32 table_index;
  242. ACPI_FUNCTION_TRACE(acpi_load_table);
  243. /* Parameter validation */
  244. if (!table) {
  245. return_ACPI_STATUS(AE_BAD_PARAMETER);
  246. }
  247. /* Must acquire the interpreter lock during this operation */
  248. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  249. if (ACPI_FAILURE(status)) {
  250. return_ACPI_STATUS(status);
  251. }
  252. /* Install the table and load it into the namespace */
  253. ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
  254. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  255. status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table),
  256. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  257. TRUE, FALSE, &table_index);
  258. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  259. if (ACPI_FAILURE(status)) {
  260. goto unlock_and_exit;
  261. }
  262. /*
  263. * Note: Now table is "INSTALLED", it must be validated before
  264. * using.
  265. */
  266. status =
  267. acpi_tb_validate_table(&acpi_gbl_root_table_list.
  268. tables[table_index]);
  269. if (ACPI_FAILURE(status)) {
  270. goto unlock_and_exit;
  271. }
  272. status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
  273. /* Invoke table handler if present */
  274. if (acpi_gbl_table_handler) {
  275. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
  276. acpi_gbl_table_handler_context);
  277. }
  278. unlock_and_exit:
  279. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  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 interpreter lock during this operation */
  320. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  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_NAME
  336. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  337. ACPI_SIG_DSDT)) {
  338. status = AE_TYPE;
  339. break;
  340. }
  341. /* Ensure the table is actually loaded */
  342. if (!acpi_tb_is_table_loaded(i)) {
  343. status = AE_NOT_EXIST;
  344. break;
  345. }
  346. /* Invoke table handler if present */
  347. if (acpi_gbl_table_handler) {
  348. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
  349. acpi_gbl_root_table_list.
  350. tables[i].pointer,
  351. acpi_gbl_table_handler_context);
  352. }
  353. /*
  354. * Delete all namespace objects owned by this table. Note that
  355. * these objects can appear anywhere in the namespace by virtue
  356. * of the AML "Scope" operator. Thus, we need to track ownership
  357. * by an ID, not simply a position within the hierarchy.
  358. */
  359. status = acpi_tb_delete_namespace_by_owner(i);
  360. if (ACPI_FAILURE(status)) {
  361. break;
  362. }
  363. status = acpi_tb_release_owner_id(i);
  364. acpi_tb_set_table_loaded_flag(i, FALSE);
  365. break;
  366. }
  367. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  368. return_ACPI_STATUS(status);
  369. }
  370. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)