tbxfload.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxfload - Table load/unload external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2014, 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. /* Local prototypes */
  50. static acpi_status acpi_tb_load_namespace(void);
  51. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_load_tables
  54. *
  55. * PARAMETERS: None
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
  60. *
  61. ******************************************************************************/
  62. acpi_status __init acpi_load_tables(void)
  63. {
  64. acpi_status status;
  65. ACPI_FUNCTION_TRACE(acpi_load_tables);
  66. /* Load the namespace from the tables */
  67. status = acpi_tb_load_namespace();
  68. if (ACPI_FAILURE(status)) {
  69. ACPI_EXCEPTION((AE_INFO, status,
  70. "While loading namespace from ACPI tables"));
  71. }
  72. return_ACPI_STATUS(status);
  73. }
  74. ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
  75. /*******************************************************************************
  76. *
  77. * FUNCTION: acpi_tb_load_namespace
  78. *
  79. * PARAMETERS: None
  80. *
  81. * RETURN: Status
  82. *
  83. * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
  84. * the RSDT/XSDT.
  85. *
  86. ******************************************************************************/
  87. static acpi_status acpi_tb_load_namespace(void)
  88. {
  89. acpi_status status;
  90. u32 i;
  91. struct acpi_table_header *new_dsdt;
  92. ACPI_FUNCTION_TRACE(tb_load_namespace);
  93. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  94. /*
  95. * Load the namespace. The DSDT is required, but any SSDT and
  96. * PSDT tables are optional. Verify the DSDT.
  97. */
  98. if (!acpi_gbl_root_table_list.current_table_count ||
  99. !ACPI_COMPARE_NAME(&
  100. (acpi_gbl_root_table_list.
  101. tables[ACPI_TABLE_INDEX_DSDT].signature),
  102. ACPI_SIG_DSDT)
  103. ||
  104. ACPI_FAILURE(acpi_tb_validate_table
  105. (&acpi_gbl_root_table_list.
  106. tables[ACPI_TABLE_INDEX_DSDT]))) {
  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 =
  117. acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer;
  118. /*
  119. * Optionally copy the entire DSDT to local memory (instead of simply
  120. * mapping it.) There are some BIOSs that corrupt or replace the original
  121. * DSDT, creating the need for this option. Default is FALSE, do not copy
  122. * the DSDT.
  123. */
  124. if (acpi_gbl_copy_dsdt_locally) {
  125. new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT);
  126. if (new_dsdt) {
  127. acpi_gbl_DSDT = new_dsdt;
  128. }
  129. }
  130. /*
  131. * Save the original DSDT header for detection of table corruption
  132. * and/or replacement of the DSDT from outside the OS.
  133. */
  134. ACPI_MEMCPY(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
  135. sizeof(struct acpi_table_header));
  136. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  137. /* Load and parse tables */
  138. status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
  139. if (ACPI_FAILURE(status)) {
  140. return_ACPI_STATUS(status);
  141. }
  142. /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
  143. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  144. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  145. if ((!ACPI_COMPARE_NAME
  146. (&(acpi_gbl_root_table_list.tables[i].signature),
  147. ACPI_SIG_SSDT)
  148. &&
  149. !ACPI_COMPARE_NAME(&
  150. (acpi_gbl_root_table_list.tables[i].
  151. signature), ACPI_SIG_PSDT))
  152. ||
  153. ACPI_FAILURE(acpi_tb_validate_table
  154. (&acpi_gbl_root_table_list.tables[i]))) {
  155. continue;
  156. }
  157. /* Ignore errors while loading tables, get as many as possible */
  158. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  159. (void)acpi_ns_load_table(i, acpi_gbl_root_node);
  160. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  161. }
  162. ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired"));
  163. unlock_and_exit:
  164. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  165. return_ACPI_STATUS(status);
  166. }
  167. /*******************************************************************************
  168. *
  169. * FUNCTION: acpi_install_table
  170. *
  171. * PARAMETERS: address - Address of the ACPI table to be installed.
  172. * physical - Whether the address is a physical table
  173. * address or not
  174. *
  175. * RETURN: Status
  176. *
  177. * DESCRIPTION: Dynamically install an ACPI table.
  178. * Note: This function should only be invoked after
  179. * acpi_initialize_tables() and before acpi_load_tables().
  180. *
  181. ******************************************************************************/
  182. acpi_status __init
  183. acpi_install_table(acpi_physical_address address, u8 physical)
  184. {
  185. acpi_status status;
  186. u8 flags;
  187. u32 table_index;
  188. ACPI_FUNCTION_TRACE(acpi_install_table);
  189. if (physical) {
  190. flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
  191. } else {
  192. flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
  193. }
  194. status = acpi_tb_install_standard_table(address, flags,
  195. FALSE, FALSE, &table_index);
  196. return_ACPI_STATUS(status);
  197. }
  198. ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
  199. /*******************************************************************************
  200. *
  201. * FUNCTION: acpi_load_table
  202. *
  203. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  204. * table to be loaded.
  205. *
  206. * RETURN: Status
  207. *
  208. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  209. * be a valid ACPI table with a valid ACPI table header.
  210. * Note1: Mainly intended to support hotplug addition of SSDTs.
  211. * Note2: Does not copy the incoming table. User is responsible
  212. * to ensure that the table is not deleted or unmapped.
  213. *
  214. ******************************************************************************/
  215. acpi_status acpi_load_table(struct acpi_table_header *table)
  216. {
  217. acpi_status status;
  218. u32 table_index;
  219. ACPI_FUNCTION_TRACE(acpi_load_table);
  220. /* Parameter validation */
  221. if (!table) {
  222. return_ACPI_STATUS(AE_BAD_PARAMETER);
  223. }
  224. /* Must acquire the interpreter lock during this operation */
  225. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  226. if (ACPI_FAILURE(status)) {
  227. return_ACPI_STATUS(status);
  228. }
  229. /* Install the table and load it into the namespace */
  230. ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
  231. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  232. status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table),
  233. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  234. TRUE, FALSE, &table_index);
  235. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  236. if (ACPI_FAILURE(status)) {
  237. goto unlock_and_exit;
  238. }
  239. /*
  240. * Note: Now table is "INSTALLED", it must be validated before
  241. * using.
  242. */
  243. status =
  244. acpi_tb_validate_table(&acpi_gbl_root_table_list.
  245. tables[table_index]);
  246. if (ACPI_FAILURE(status)) {
  247. goto unlock_and_exit;
  248. }
  249. status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
  250. /* Invoke table handler if present */
  251. if (acpi_gbl_table_handler) {
  252. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
  253. acpi_gbl_table_handler_context);
  254. }
  255. unlock_and_exit:
  256. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  257. return_ACPI_STATUS(status);
  258. }
  259. ACPI_EXPORT_SYMBOL(acpi_load_table)
  260. /*******************************************************************************
  261. *
  262. * FUNCTION: acpi_unload_parent_table
  263. *
  264. * PARAMETERS: object - Handle to any namespace object owned by
  265. * the table to be unloaded
  266. *
  267. * RETURN: Status
  268. *
  269. * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
  270. * the table and deletes all namespace objects associated with
  271. * that table. Unloading of the DSDT is not allowed.
  272. * Note: Mainly intended to support hotplug removal of SSDTs.
  273. *
  274. ******************************************************************************/
  275. acpi_status acpi_unload_parent_table(acpi_handle object)
  276. {
  277. struct acpi_namespace_node *node =
  278. ACPI_CAST_PTR(struct acpi_namespace_node, object);
  279. acpi_status status = AE_NOT_EXIST;
  280. acpi_owner_id owner_id;
  281. u32 i;
  282. ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
  283. /* Parameter validation */
  284. if (!object) {
  285. return_ACPI_STATUS(AE_BAD_PARAMETER);
  286. }
  287. /*
  288. * The node owner_id is currently the same as the parent table ID.
  289. * However, this could change in the future.
  290. */
  291. owner_id = node->owner_id;
  292. if (!owner_id) {
  293. /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
  294. return_ACPI_STATUS(AE_TYPE);
  295. }
  296. /* Must acquire the interpreter lock during this operation */
  297. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  298. if (ACPI_FAILURE(status)) {
  299. return_ACPI_STATUS(status);
  300. }
  301. /* Find the table in the global table list */
  302. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  303. if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
  304. continue;
  305. }
  306. /*
  307. * Allow unload of SSDT and OEMx tables only. Do not allow unload
  308. * of the DSDT. No other types of tables should get here, since
  309. * only these types can contain AML and thus are the only types
  310. * that can create namespace objects.
  311. */
  312. if (ACPI_COMPARE_NAME
  313. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  314. ACPI_SIG_DSDT)) {
  315. status = AE_TYPE;
  316. break;
  317. }
  318. /* Ensure the table is actually loaded */
  319. if (!acpi_tb_is_table_loaded(i)) {
  320. status = AE_NOT_EXIST;
  321. break;
  322. }
  323. /* Invoke table handler if present */
  324. if (acpi_gbl_table_handler) {
  325. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
  326. acpi_gbl_root_table_list.
  327. tables[i].pointer,
  328. acpi_gbl_table_handler_context);
  329. }
  330. /*
  331. * Delete all namespace objects owned by this table. Note that
  332. * these objects can appear anywhere in the namespace by virtue
  333. * of the AML "Scope" operator. Thus, we need to track ownership
  334. * by an ID, not simply a position within the hierarchy.
  335. */
  336. status = acpi_tb_delete_namespace_by_owner(i);
  337. if (ACPI_FAILURE(status)) {
  338. break;
  339. }
  340. status = acpi_tb_release_owner_id(i);
  341. acpi_tb_set_table_loaded_flag(i, FALSE);
  342. break;
  343. }
  344. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  345. return_ACPI_STATUS(status);
  346. }
  347. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)