tbxfload.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxfload - Table load/unload external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, 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. #include <linux/export.h>
  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 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(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_verify_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_verify_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_verify_table
  154. (&acpi_gbl_root_table_list.tables[i]))) {
  155. continue;
  156. }
  157. /*
  158. * Optionally do not load any SSDTs from the RSDT/XSDT. This can
  159. * be useful for debugging ACPI problems on some machines.
  160. */
  161. if (acpi_gbl_disable_ssdt_table_load) {
  162. ACPI_INFO((AE_INFO, "Ignoring %4.4s at %p",
  163. acpi_gbl_root_table_list.tables[i].signature.
  164. ascii, ACPI_CAST_PTR(void,
  165. acpi_gbl_root_table_list.
  166. tables[i].address)));
  167. continue;
  168. }
  169. /* Ignore errors while loading tables, get as many as possible */
  170. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  171. (void)acpi_ns_load_table(i, acpi_gbl_root_node);
  172. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  173. }
  174. ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired"));
  175. unlock_and_exit:
  176. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  177. return_ACPI_STATUS(status);
  178. }
  179. /*******************************************************************************
  180. *
  181. * FUNCTION: acpi_load_table
  182. *
  183. * PARAMETERS: table - Pointer to a buffer containing the ACPI
  184. * table to be loaded.
  185. *
  186. * RETURN: Status
  187. *
  188. * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
  189. * be a valid ACPI table with a valid ACPI table header.
  190. * Note1: Mainly intended to support hotplug addition of SSDTs.
  191. * Note2: Does not copy the incoming table. User is responsible
  192. * to ensure that the table is not deleted or unmapped.
  193. *
  194. ******************************************************************************/
  195. acpi_status acpi_load_table(struct acpi_table_header *table)
  196. {
  197. acpi_status status;
  198. struct acpi_table_desc table_desc;
  199. u32 table_index;
  200. ACPI_FUNCTION_TRACE(acpi_load_table);
  201. /* Parameter validation */
  202. if (!table) {
  203. return_ACPI_STATUS(AE_BAD_PARAMETER);
  204. }
  205. /* Init local table descriptor */
  206. ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
  207. table_desc.address = ACPI_PTR_TO_PHYSADDR(table);
  208. table_desc.pointer = table;
  209. table_desc.length = table->length;
  210. table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
  211. /* Must acquire the interpreter lock during this operation */
  212. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  213. if (ACPI_FAILURE(status)) {
  214. return_ACPI_STATUS(status);
  215. }
  216. /* Install the table and load it into the namespace */
  217. ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
  218. status = acpi_tb_add_table(&table_desc, &table_index);
  219. if (ACPI_FAILURE(status)) {
  220. goto unlock_and_exit;
  221. }
  222. status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
  223. /* Invoke table handler if present */
  224. if (acpi_gbl_table_handler) {
  225. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
  226. acpi_gbl_table_handler_context);
  227. }
  228. unlock_and_exit:
  229. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  230. return_ACPI_STATUS(status);
  231. }
  232. ACPI_EXPORT_SYMBOL(acpi_load_table)
  233. /*******************************************************************************
  234. *
  235. * FUNCTION: acpi_unload_parent_table
  236. *
  237. * PARAMETERS: object - Handle to any namespace object owned by
  238. * the table to be unloaded
  239. *
  240. * RETURN: Status
  241. *
  242. * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
  243. * the table and deletes all namespace objects associated with
  244. * that table. Unloading of the DSDT is not allowed.
  245. * Note: Mainly intended to support hotplug removal of SSDTs.
  246. *
  247. ******************************************************************************/
  248. acpi_status acpi_unload_parent_table(acpi_handle object)
  249. {
  250. struct acpi_namespace_node *node =
  251. ACPI_CAST_PTR(struct acpi_namespace_node, object);
  252. acpi_status status = AE_NOT_EXIST;
  253. acpi_owner_id owner_id;
  254. u32 i;
  255. ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
  256. /* Parameter validation */
  257. if (!object) {
  258. return_ACPI_STATUS(AE_BAD_PARAMETER);
  259. }
  260. /*
  261. * The node owner_id is currently the same as the parent table ID.
  262. * However, this could change in the future.
  263. */
  264. owner_id = node->owner_id;
  265. if (!owner_id) {
  266. /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
  267. return_ACPI_STATUS(AE_TYPE);
  268. }
  269. /* Must acquire the interpreter lock during this operation */
  270. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  271. if (ACPI_FAILURE(status)) {
  272. return_ACPI_STATUS(status);
  273. }
  274. /* Find the table in the global table list */
  275. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  276. if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
  277. continue;
  278. }
  279. /*
  280. * Allow unload of SSDT and OEMx tables only. Do not allow unload
  281. * of the DSDT. No other types of tables should get here, since
  282. * only these types can contain AML and thus are the only types
  283. * that can create namespace objects.
  284. */
  285. if (ACPI_COMPARE_NAME
  286. (acpi_gbl_root_table_list.tables[i].signature.ascii,
  287. ACPI_SIG_DSDT)) {
  288. status = AE_TYPE;
  289. break;
  290. }
  291. /* Ensure the table is actually loaded */
  292. if (!acpi_tb_is_table_loaded(i)) {
  293. status = AE_NOT_EXIST;
  294. break;
  295. }
  296. /* Invoke table handler if present */
  297. if (acpi_gbl_table_handler) {
  298. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
  299. acpi_gbl_root_table_list.
  300. tables[i].pointer,
  301. acpi_gbl_table_handler_context);
  302. }
  303. /*
  304. * Delete all namespace objects owned by this table. Note that
  305. * these objects can appear anywhere in the namespace by virtue
  306. * of the AML "Scope" operator. Thus, we need to track ownership
  307. * by an ID, not simply a position within the hierarchy.
  308. */
  309. status = acpi_tb_delete_namespace_by_owner(i);
  310. if (ACPI_FAILURE(status)) {
  311. break;
  312. }
  313. status = acpi_tb_release_owner_id(i);
  314. acpi_tb_set_table_loaded_flag(i, FALSE);
  315. break;
  316. }
  317. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  318. return_ACPI_STATUS(status);
  319. }
  320. ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)