tbinstal.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 - 2018, 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. * reload - Whether reload should be performed
  71. * override - Whether override should be performed
  72. * table_index - Where the table index is returned
  73. *
  74. * RETURN: Status
  75. *
  76. * DESCRIPTION: This function is called to verify and install an ACPI table.
  77. * When this function is called by "Load" or "LoadTable" opcodes,
  78. * or by acpi_load_table() API, the "Reload" parameter is set.
  79. * After successfully returning from this function, table is
  80. * "INSTALLED" but not "VALIDATED".
  81. *
  82. ******************************************************************************/
  83. acpi_status
  84. acpi_tb_install_standard_table(acpi_physical_address address,
  85. u8 flags,
  86. u8 reload, u8 override, u32 *table_index)
  87. {
  88. u32 i;
  89. acpi_status status = AE_OK;
  90. struct acpi_table_desc new_table_desc;
  91. ACPI_FUNCTION_TRACE(tb_install_standard_table);
  92. /* Acquire a temporary table descriptor for validation */
  93. status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
  94. if (ACPI_FAILURE(status)) {
  95. ACPI_ERROR((AE_INFO,
  96. "Could not acquire table length at %8.8X%8.8X",
  97. ACPI_FORMAT_UINT64(address)));
  98. return_ACPI_STATUS(status);
  99. }
  100. /*
  101. * Optionally do not load any SSDTs from the RSDT/XSDT. This can
  102. * be useful for debugging ACPI problems on some machines.
  103. */
  104. if (!reload &&
  105. acpi_gbl_disable_ssdt_table_install &&
  106. ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
  107. ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
  108. new_table_desc.signature.ascii,
  109. ACPI_FORMAT_UINT64(address)));
  110. goto release_and_exit;
  111. }
  112. /* Acquire the table lock */
  113. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  114. /* Validate and verify a table before installation */
  115. status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i);
  116. if (ACPI_FAILURE(status)) {
  117. if (status == AE_CTRL_TERMINATE) {
  118. /*
  119. * Table was unloaded, allow it to be reloaded.
  120. * As we are going to return AE_OK to the caller, we should
  121. * take the responsibility of freeing the input descriptor.
  122. * Refill the input descriptor to ensure
  123. * acpi_tb_install_table_with_override() can be called again to
  124. * indicate the re-installation.
  125. */
  126. acpi_tb_uninstall_table(&new_table_desc);
  127. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  128. *table_index = i;
  129. return_ACPI_STATUS(AE_OK);
  130. }
  131. goto unlock_and_exit;
  132. }
  133. /* Add the table to the global root table list */
  134. acpi_tb_install_table_with_override(&new_table_desc, override,
  135. table_index);
  136. /* Invoke table handler */
  137. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  138. acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
  139. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  140. unlock_and_exit:
  141. /* Release the table lock */
  142. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  143. release_and_exit:
  144. /* Release the temporary table descriptor */
  145. acpi_tb_release_temp_table(&new_table_desc);
  146. return_ACPI_STATUS(status);
  147. }
  148. /*******************************************************************************
  149. *
  150. * FUNCTION: acpi_tb_override_table
  151. *
  152. * PARAMETERS: old_table_desc - Validated table descriptor to be
  153. * overridden
  154. *
  155. * RETURN: None
  156. *
  157. * DESCRIPTION: Attempt table override by calling the OSL override functions.
  158. * Note: If the table is overridden, then the entire new table
  159. * is acquired and returned by this function.
  160. * Before/after invocation, the table descriptor is in a state
  161. * that is "VALIDATED".
  162. *
  163. ******************************************************************************/
  164. void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
  165. {
  166. acpi_status status;
  167. struct acpi_table_desc new_table_desc;
  168. struct acpi_table_header *table;
  169. acpi_physical_address address;
  170. u32 length;
  171. ACPI_ERROR_ONLY(char *override_type);
  172. /* (1) Attempt logical override (returns a logical address) */
  173. status = acpi_os_table_override(old_table_desc->pointer, &table);
  174. if (ACPI_SUCCESS(status) && table) {
  175. acpi_tb_acquire_temp_table(&new_table_desc,
  176. ACPI_PTR_TO_PHYSADDR(table),
  177. ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
  178. ACPI_ERROR_ONLY(override_type = "Logical");
  179. goto finish_override;
  180. }
  181. /* (2) Attempt physical override (returns a physical address) */
  182. status = acpi_os_physical_table_override(old_table_desc->pointer,
  183. &address, &length);
  184. if (ACPI_SUCCESS(status) && address && length) {
  185. acpi_tb_acquire_temp_table(&new_table_desc, address,
  186. ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
  187. ACPI_ERROR_ONLY(override_type = "Physical");
  188. goto finish_override;
  189. }
  190. return; /* There was no override */
  191. finish_override:
  192. /*
  193. * Validate and verify a table before overriding, no nested table
  194. * duplication check as it's too complicated and unnecessary.
  195. */
  196. status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL);
  197. if (ACPI_FAILURE(status)) {
  198. return;
  199. }
  200. ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
  201. " %s table override, new table: 0x%8.8X%8.8X",
  202. old_table_desc->signature.ascii,
  203. ACPI_FORMAT_UINT64(old_table_desc->address),
  204. override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
  205. /* We can now uninstall the original table */
  206. acpi_tb_uninstall_table(old_table_desc);
  207. /*
  208. * Replace the original table descriptor and keep its state as
  209. * "VALIDATED".
  210. */
  211. acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
  212. new_table_desc.flags,
  213. new_table_desc.pointer);
  214. acpi_tb_validate_temp_table(old_table_desc);
  215. /* Release the temporary table descriptor */
  216. acpi_tb_release_temp_table(&new_table_desc);
  217. }
  218. /*******************************************************************************
  219. *
  220. * FUNCTION: acpi_tb_uninstall_table
  221. *
  222. * PARAMETERS: table_desc - Table descriptor
  223. *
  224. * RETURN: None
  225. *
  226. * DESCRIPTION: Delete one internal ACPI table
  227. *
  228. ******************************************************************************/
  229. void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
  230. {
  231. ACPI_FUNCTION_TRACE(tb_uninstall_table);
  232. /* Table must be installed */
  233. if (!table_desc->address) {
  234. return_VOID;
  235. }
  236. acpi_tb_invalidate_table(table_desc);
  237. if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
  238. ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
  239. ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
  240. }
  241. table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
  242. return_VOID;
  243. }