tbxfload.c 11 KB

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