tbinstal.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: tbinstal - ACPI table installation and removal
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "actables.h"
  12. #define _COMPONENT ACPI_TABLES
  13. ACPI_MODULE_NAME("tbinstal")
  14. /*******************************************************************************
  15. *
  16. * FUNCTION: acpi_tb_install_table_with_override
  17. *
  18. * PARAMETERS: new_table_desc - New table descriptor to install
  19. * override - Whether override should be performed
  20. * table_index - Where the table index is returned
  21. *
  22. * RETURN: None
  23. *
  24. * DESCRIPTION: Install an ACPI table into the global data structure. The
  25. * table override mechanism is called to allow the host
  26. * OS to replace any table before it is installed in the root
  27. * table array.
  28. *
  29. ******************************************************************************/
  30. void
  31. acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
  32. u8 override, u32 *table_index)
  33. {
  34. u32 i;
  35. acpi_status status;
  36. status = acpi_tb_get_next_table_descriptor(&i, NULL);
  37. if (ACPI_FAILURE(status)) {
  38. return;
  39. }
  40. /*
  41. * ACPI Table Override:
  42. *
  43. * Before we install the table, let the host OS override it with a new
  44. * one if desired. Any table within the RSDT/XSDT can be replaced,
  45. * including the DSDT which is pointed to by the FADT.
  46. */
  47. if (override) {
  48. acpi_tb_override_table(new_table_desc);
  49. }
  50. acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
  51. new_table_desc->address,
  52. new_table_desc->flags,
  53. new_table_desc->pointer);
  54. acpi_tb_print_table_header(new_table_desc->address,
  55. new_table_desc->pointer);
  56. /* This synchronizes acpi_gbl_dsdt_index */
  57. *table_index = i;
  58. /* Set the global integer width (based upon revision of the DSDT) */
  59. if (i == acpi_gbl_dsdt_index) {
  60. acpi_ut_set_integer_width(new_table_desc->pointer->revision);
  61. }
  62. }
  63. /*******************************************************************************
  64. *
  65. * FUNCTION: acpi_tb_install_standard_table
  66. *
  67. * PARAMETERS: address - Address of the table (might be a virtual
  68. * address depending on the table_flags)
  69. * flags - Flags for the table
  70. * table - Pointer to the table (required for virtual
  71. * origins, optional for physical)
  72. * reload - Whether reload should be performed
  73. * override - Whether override should be performed
  74. * table_index - Where the table index is returned
  75. *
  76. * RETURN: Status
  77. *
  78. * DESCRIPTION: This function is called to verify and install an ACPI table.
  79. * When this function is called by "Load" or "LoadTable" opcodes,
  80. * or by acpi_load_table() API, the "Reload" parameter is set.
  81. * After successfully returning from this function, table is
  82. * "INSTALLED" but not "VALIDATED".
  83. *
  84. ******************************************************************************/
  85. acpi_status
  86. acpi_tb_install_standard_table(acpi_physical_address address,
  87. u8 flags,
  88. struct acpi_table_header *table,
  89. u8 reload, u8 override, u32 *table_index)
  90. {
  91. u32 i;
  92. acpi_status status = AE_OK;
  93. struct acpi_table_desc new_table_desc;
  94. ACPI_FUNCTION_TRACE(tb_install_standard_table);
  95. /* Acquire a temporary table descriptor for validation */
  96. status =
  97. acpi_tb_acquire_temp_table(&new_table_desc, address, flags, table);
  98. if (ACPI_FAILURE(status)) {
  99. ACPI_ERROR((AE_INFO,
  100. "Could not acquire table length at %8.8X%8.8X",
  101. ACPI_FORMAT_UINT64(address)));
  102. return_ACPI_STATUS(status);
  103. }
  104. /*
  105. * Optionally do not load any SSDTs from the RSDT/XSDT. This can
  106. * be useful for debugging ACPI problems on some machines.
  107. */
  108. if (!reload &&
  109. acpi_gbl_disable_ssdt_table_install &&
  110. ACPI_COMPARE_NAMESEG(&new_table_desc.signature, ACPI_SIG_SSDT)) {
  111. ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
  112. new_table_desc.signature.ascii,
  113. ACPI_FORMAT_UINT64(address)));
  114. goto release_and_exit;
  115. }
  116. /* Acquire the table lock */
  117. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  118. /* Validate and verify a table before installation */
  119. status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i);
  120. if (ACPI_FAILURE(status)) {
  121. if (status == AE_CTRL_TERMINATE) {
  122. /*
  123. * Table was unloaded, allow it to be reloaded.
  124. * As we are going to return AE_OK to the caller, we should
  125. * take the responsibility of freeing the input descriptor.
  126. * Refill the input descriptor to ensure
  127. * acpi_tb_install_table_with_override() can be called again to
  128. * indicate the re-installation.
  129. */
  130. acpi_tb_uninstall_table(&new_table_desc);
  131. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  132. *table_index = i;
  133. return_ACPI_STATUS(AE_OK);
  134. }
  135. goto unlock_and_exit;
  136. }
  137. /* Add the table to the global root table list */
  138. acpi_tb_install_table_with_override(&new_table_desc, override,
  139. table_index);
  140. /* Invoke table handler */
  141. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  142. acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
  143. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  144. unlock_and_exit:
  145. /* Release the table lock */
  146. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  147. release_and_exit:
  148. /* Release the temporary table descriptor */
  149. acpi_tb_release_temp_table(&new_table_desc);
  150. return_ACPI_STATUS(status);
  151. }
  152. /*******************************************************************************
  153. *
  154. * FUNCTION: acpi_tb_override_table
  155. *
  156. * PARAMETERS: old_table_desc - Validated table descriptor to be
  157. * overridden
  158. *
  159. * RETURN: None
  160. *
  161. * DESCRIPTION: Attempt table override by calling the OSL override functions.
  162. * Note: If the table is overridden, then the entire new table
  163. * is acquired and returned by this function.
  164. * Before/after invocation, the table descriptor is in a state
  165. * that is "VALIDATED".
  166. *
  167. ******************************************************************************/
  168. void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
  169. {
  170. acpi_status status;
  171. struct acpi_table_desc new_table_desc;
  172. struct acpi_table_header *table;
  173. acpi_physical_address address;
  174. u32 length;
  175. ACPI_ERROR_ONLY(char *override_type);
  176. /* (1) Attempt logical override (returns a logical address) */
  177. status = acpi_os_table_override(old_table_desc->pointer, &table);
  178. if (ACPI_SUCCESS(status) && table) {
  179. acpi_tb_acquire_temp_table(&new_table_desc,
  180. ACPI_PTR_TO_PHYSADDR(table),
  181. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
  182. table);
  183. ACPI_ERROR_ONLY(override_type = "Logical");
  184. goto finish_override;
  185. }
  186. /* (2) Attempt physical override (returns a physical address) */
  187. status = acpi_os_physical_table_override(old_table_desc->pointer,
  188. &address, &length);
  189. if (ACPI_SUCCESS(status) && address && length) {
  190. acpi_tb_acquire_temp_table(&new_table_desc, address,
  191. ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
  192. NULL);
  193. ACPI_ERROR_ONLY(override_type = "Physical");
  194. goto finish_override;
  195. }
  196. return; /* There was no override */
  197. finish_override:
  198. /*
  199. * Validate and verify a table before overriding, no nested table
  200. * duplication check as it's too complicated and unnecessary.
  201. */
  202. status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL);
  203. if (ACPI_FAILURE(status)) {
  204. return;
  205. }
  206. ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
  207. " %s table override, new table: 0x%8.8X%8.8X",
  208. old_table_desc->signature.ascii,
  209. ACPI_FORMAT_UINT64(old_table_desc->address),
  210. override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
  211. /* We can now uninstall the original table */
  212. acpi_tb_uninstall_table(old_table_desc);
  213. /*
  214. * Replace the original table descriptor and keep its state as
  215. * "VALIDATED".
  216. */
  217. acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
  218. new_table_desc.flags,
  219. new_table_desc.pointer);
  220. acpi_tb_validate_temp_table(old_table_desc);
  221. /* Release the temporary table descriptor */
  222. acpi_tb_release_temp_table(&new_table_desc);
  223. }
  224. /*******************************************************************************
  225. *
  226. * FUNCTION: acpi_tb_uninstall_table
  227. *
  228. * PARAMETERS: table_desc - Table descriptor
  229. *
  230. * RETURN: None
  231. *
  232. * DESCRIPTION: Delete one internal ACPI table
  233. *
  234. ******************************************************************************/
  235. void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
  236. {
  237. ACPI_FUNCTION_TRACE(tb_uninstall_table);
  238. /* Table must be installed */
  239. if (!table_desc->address) {
  240. return_VOID;
  241. }
  242. acpi_tb_invalidate_table(table_desc);
  243. if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
  244. ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
  245. ACPI_FREE(table_desc->pointer);
  246. table_desc->pointer = NULL;
  247. }
  248. table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
  249. return_VOID;
  250. }