tbinstal.c 15 KB

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