tbinstal.c 11 KB

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