tbinstal.c 15 KB

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