tbinstal.c 17 KB

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