tbinstal.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /******************************************************************************
  2. *
  3. * Module Name: tbinstal - ACPI table installation and removal
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2017, 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 <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "actables.h"
  45. #define _COMPONENT ACPI_TABLES
  46. ACPI_MODULE_NAME("tbinstal")
  47. /* Local prototypes */
  48. static u8
  49. acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_tb_compare_tables
  53. *
  54. * PARAMETERS: table_desc - Table 1 descriptor to be compared
  55. * table_index - Index of table 2 to be compared
  56. *
  57. * RETURN: TRUE if both tables are identical.
  58. *
  59. * DESCRIPTION: This function compares a table with another table that has
  60. * already been installed in the root table list.
  61. *
  62. ******************************************************************************/
  63. static u8
  64. acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
  65. {
  66. acpi_status status = AE_OK;
  67. u8 is_identical;
  68. struct acpi_table_header *table;
  69. u32 table_length;
  70. u8 table_flags;
  71. status =
  72. acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
  73. &table, &table_length, &table_flags);
  74. if (ACPI_FAILURE(status)) {
  75. return (FALSE);
  76. }
  77. /*
  78. * Check for a table match on the entire table length,
  79. * not just the header.
  80. */
  81. is_identical = (u8)((table_desc->length != table_length ||
  82. memcmp(table_desc->pointer, table, table_length)) ?
  83. FALSE : TRUE);
  84. /* Release the acquired table */
  85. acpi_tb_release_table(table, table_length, table_flags);
  86. return (is_identical);
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_tb_install_table_with_override
  91. *
  92. * PARAMETERS: new_table_desc - New table descriptor to install
  93. * override - Whether override should be performed
  94. * table_index - Where the table index is returned
  95. *
  96. * RETURN: None
  97. *
  98. * DESCRIPTION: Install an ACPI table into the global data structure. The
  99. * table override mechanism is called to allow the host
  100. * OS to replace any table before it is installed in the root
  101. * table array.
  102. *
  103. ******************************************************************************/
  104. void
  105. acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
  106. u8 override, u32 *table_index)
  107. {
  108. u32 i;
  109. acpi_status status;
  110. status = acpi_tb_get_next_table_descriptor(&i, NULL);
  111. if (ACPI_FAILURE(status)) {
  112. return;
  113. }
  114. /*
  115. * ACPI Table Override:
  116. *
  117. * Before we install the table, let the host OS override it with a new
  118. * one if desired. Any table within the RSDT/XSDT can be replaced,
  119. * including the DSDT which is pointed to by the FADT.
  120. */
  121. if (override) {
  122. acpi_tb_override_table(new_table_desc);
  123. }
  124. acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
  125. new_table_desc->address,
  126. new_table_desc->flags,
  127. new_table_desc->pointer);
  128. acpi_tb_print_table_header(new_table_desc->address,
  129. new_table_desc->pointer);
  130. /* This synchronizes acpi_gbl_dsdt_index */
  131. *table_index = i;
  132. /* Set the global integer width (based upon revision of the DSDT) */
  133. if (i == acpi_gbl_dsdt_index) {
  134. acpi_ut_set_integer_width(new_table_desc->pointer->revision);
  135. }
  136. }
  137. /*******************************************************************************
  138. *
  139. * FUNCTION: acpi_tb_install_standard_table
  140. *
  141. * PARAMETERS: address - Address of the table (might be a virtual
  142. * address depending on the table_flags)
  143. * flags - Flags for the table
  144. * reload - Whether reload should be performed
  145. * override - Whether override should be performed
  146. * table_index - Where the table index is returned
  147. *
  148. * RETURN: Status
  149. *
  150. * DESCRIPTION: This function is called to verify and install an ACPI table.
  151. * When this function is called by "Load" or "LoadTable" opcodes,
  152. * or by acpi_load_table() API, the "Reload" parameter is set.
  153. * After sucessfully returning from this function, table is
  154. * "INSTALLED" but not "VALIDATED".
  155. *
  156. ******************************************************************************/
  157. acpi_status
  158. acpi_tb_install_standard_table(acpi_physical_address address,
  159. u8 flags,
  160. u8 reload, u8 override, u32 *table_index)
  161. {
  162. u32 i;
  163. acpi_status status = AE_OK;
  164. struct acpi_table_desc new_table_desc;
  165. ACPI_FUNCTION_TRACE(tb_install_standard_table);
  166. /* Acquire a temporary table descriptor for validation */
  167. status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
  168. if (ACPI_FAILURE(status)) {
  169. ACPI_ERROR((AE_INFO,
  170. "Could not acquire table length at %8.8X%8.8X",
  171. ACPI_FORMAT_UINT64(address)));
  172. return_ACPI_STATUS(status);
  173. }
  174. /*
  175. * Optionally do not load any SSDTs from the RSDT/XSDT. This can
  176. * be useful for debugging ACPI problems on some machines.
  177. */
  178. if (!reload &&
  179. acpi_gbl_disable_ssdt_table_install &&
  180. ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
  181. ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
  182. new_table_desc.signature.ascii,
  183. ACPI_FORMAT_UINT64(address)));
  184. goto release_and_exit;
  185. }
  186. /* Validate and verify a table before installation */
  187. status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
  188. if (ACPI_FAILURE(status)) {
  189. goto release_and_exit;
  190. }
  191. /* Acquire the table lock */
  192. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  193. if (reload) {
  194. /*
  195. * Validate the incoming table signature.
  196. *
  197. * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
  198. * 2) We added support for OEMx tables, signature "OEM".
  199. * 3) Valid tables were encountered with a null signature, so we just
  200. * gave up on validating the signature, (05/2008).
  201. * 4) We encountered non-AML tables such as the MADT, which caused
  202. * interpreter errors and kernel faults. So now, we once again allow
  203. * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
  204. */
  205. if ((new_table_desc.signature.ascii[0] != 0x00) &&
  206. (!ACPI_COMPARE_NAME
  207. (&new_table_desc.signature, ACPI_SIG_SSDT))
  208. && (strncmp(new_table_desc.signature.ascii, "OEM", 3))) {
  209. ACPI_BIOS_ERROR((AE_INFO,
  210. "Table has invalid signature [%4.4s] (0x%8.8X), "
  211. "must be SSDT or OEMx",
  212. acpi_ut_valid_nameseg(new_table_desc.
  213. signature.
  214. ascii) ?
  215. new_table_desc.signature.
  216. ascii : "????",
  217. new_table_desc.signature.integer));
  218. status = AE_BAD_SIGNATURE;
  219. goto unlock_and_exit;
  220. }
  221. /* Check if table is already registered */
  222. for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
  223. ++i) {
  224. /*
  225. * Check for a table match on the entire table length,
  226. * not just the header.
  227. */
  228. if (!acpi_tb_compare_tables(&new_table_desc, i)) {
  229. continue;
  230. }
  231. /*
  232. * Note: the current mechanism does not unregister a table if it is
  233. * dynamically unloaded. The related namespace entries are deleted,
  234. * but the table remains in the root table list.
  235. *
  236. * The assumption here is that the number of different tables that
  237. * will be loaded is actually small, and there is minimal overhead
  238. * in just keeping the table in case it is needed again.
  239. *
  240. * If this assumption changes in the future (perhaps on large
  241. * machines with many table load/unload operations), tables will
  242. * need to be unregistered when they are unloaded, and slots in the
  243. * root table list should be reused when empty.
  244. */
  245. if (acpi_gbl_root_table_list.tables[i].flags &
  246. ACPI_TABLE_IS_LOADED) {
  247. /* Table is still loaded, this is an error */
  248. status = AE_ALREADY_EXISTS;
  249. goto unlock_and_exit;
  250. } else {
  251. /*
  252. * Table was unloaded, allow it to be reloaded.
  253. * As we are going to return AE_OK to the caller, we should
  254. * take the responsibility of freeing the input descriptor.
  255. * Refill the input descriptor to ensure
  256. * acpi_tb_install_table_with_override() can be called again to
  257. * indicate the re-installation.
  258. */
  259. acpi_tb_uninstall_table(&new_table_desc);
  260. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  261. *table_index = i;
  262. return_ACPI_STATUS(AE_OK);
  263. }
  264. }
  265. }
  266. /* Add the table to the global root table list */
  267. acpi_tb_install_table_with_override(&new_table_desc, override,
  268. table_index);
  269. /* Invoke table handler if present */
  270. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  271. if (acpi_gbl_table_handler) {
  272. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_INSTALL,
  273. new_table_desc.pointer,
  274. acpi_gbl_table_handler_context);
  275. }
  276. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  277. unlock_and_exit:
  278. /* Release the table lock */
  279. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  280. release_and_exit:
  281. /* Release the temporary table descriptor */
  282. acpi_tb_release_temp_table(&new_table_desc);
  283. return_ACPI_STATUS(status);
  284. }
  285. /*******************************************************************************
  286. *
  287. * FUNCTION: acpi_tb_override_table
  288. *
  289. * PARAMETERS: old_table_desc - Validated table descriptor to be
  290. * overridden
  291. *
  292. * RETURN: None
  293. *
  294. * DESCRIPTION: Attempt table override by calling the OSL override functions.
  295. * Note: If the table is overridden, then the entire new table
  296. * is acquired and returned by this function.
  297. * Before/after invocation, the table descriptor is in a state
  298. * that is "VALIDATED".
  299. *
  300. ******************************************************************************/
  301. void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
  302. {
  303. acpi_status status;
  304. char *override_type;
  305. struct acpi_table_desc new_table_desc;
  306. struct acpi_table_header *table;
  307. acpi_physical_address address;
  308. u32 length;
  309. /* (1) Attempt logical override (returns a logical address) */
  310. status = acpi_os_table_override(old_table_desc->pointer, &table);
  311. if (ACPI_SUCCESS(status) && table) {
  312. acpi_tb_acquire_temp_table(&new_table_desc,
  313. ACPI_PTR_TO_PHYSADDR(table),
  314. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
  315. override_type = "Logical";
  316. goto finish_override;
  317. }
  318. /* (2) Attempt physical override (returns a physical address) */
  319. status = acpi_os_physical_table_override(old_table_desc->pointer,
  320. &address, &length);
  321. if (ACPI_SUCCESS(status) && address && length) {
  322. acpi_tb_acquire_temp_table(&new_table_desc, address,
  323. ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
  324. override_type = "Physical";
  325. goto finish_override;
  326. }
  327. return; /* There was no override */
  328. finish_override:
  329. /* Validate and verify a table before overriding */
  330. status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
  331. if (ACPI_FAILURE(status)) {
  332. return;
  333. }
  334. ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
  335. " %s table override, new table: 0x%8.8X%8.8X",
  336. old_table_desc->signature.ascii,
  337. ACPI_FORMAT_UINT64(old_table_desc->address),
  338. override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
  339. /* We can now uninstall the original table */
  340. acpi_tb_uninstall_table(old_table_desc);
  341. /*
  342. * Replace the original table descriptor and keep its state as
  343. * "VALIDATED".
  344. */
  345. acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
  346. new_table_desc.flags,
  347. new_table_desc.pointer);
  348. acpi_tb_validate_temp_table(old_table_desc);
  349. /* Release the temporary table descriptor */
  350. acpi_tb_release_temp_table(&new_table_desc);
  351. }
  352. /*******************************************************************************
  353. *
  354. * FUNCTION: acpi_tb_uninstall_table
  355. *
  356. * PARAMETERS: table_desc - Table descriptor
  357. *
  358. * RETURN: None
  359. *
  360. * DESCRIPTION: Delete one internal ACPI table
  361. *
  362. ******************************************************************************/
  363. void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
  364. {
  365. ACPI_FUNCTION_TRACE(tb_uninstall_table);
  366. /* Table must be installed */
  367. if (!table_desc->address) {
  368. return_VOID;
  369. }
  370. acpi_tb_invalidate_table(table_desc);
  371. if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
  372. ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
  373. ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
  374. }
  375. table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
  376. return_VOID;
  377. }