tbfadt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /******************************************************************************
  2. *
  3. * Module Name: tbfadt - FADT table utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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 <acpi/actables.h>
  44. #define _COMPONENT ACPI_TABLES
  45. ACPI_MODULE_NAME("tbfadt")
  46. /* Local prototypes */
  47. static void inline
  48. acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
  49. u8 byte_width, u64 address);
  50. static void acpi_tb_convert_fadt(void);
  51. static void acpi_tb_validate_fadt(void);
  52. /* Table for conversion of FADT to common internal format and FADT validation */
  53. typedef struct acpi_fadt_info {
  54. char *name;
  55. u8 target;
  56. u8 source;
  57. u8 length;
  58. u8 type;
  59. } acpi_fadt_info;
  60. #define ACPI_FADT_REQUIRED 1
  61. #define ACPI_FADT_SEPARATE_LENGTH 2
  62. static struct acpi_fadt_info fadt_info_table[] = {
  63. {"Pm1aEventBlock", ACPI_FADT_OFFSET(xpm1a_event_block),
  64. ACPI_FADT_OFFSET(pm1a_event_block),
  65. ACPI_FADT_OFFSET(pm1_event_length), ACPI_FADT_REQUIRED},
  66. {"Pm1bEventBlock", ACPI_FADT_OFFSET(xpm1b_event_block),
  67. ACPI_FADT_OFFSET(pm1b_event_block),
  68. ACPI_FADT_OFFSET(pm1_event_length), 0},
  69. {"Pm1aControlBlock", ACPI_FADT_OFFSET(xpm1a_control_block),
  70. ACPI_FADT_OFFSET(pm1a_control_block),
  71. ACPI_FADT_OFFSET(pm1_control_length), ACPI_FADT_REQUIRED},
  72. {"Pm1bControlBlock", ACPI_FADT_OFFSET(xpm1b_control_block),
  73. ACPI_FADT_OFFSET(pm1b_control_block),
  74. ACPI_FADT_OFFSET(pm1_control_length), 0},
  75. {"Pm2ControlBlock", ACPI_FADT_OFFSET(xpm2_control_block),
  76. ACPI_FADT_OFFSET(pm2_control_block),
  77. ACPI_FADT_OFFSET(pm2_control_length), ACPI_FADT_SEPARATE_LENGTH},
  78. {"PmTimerBlock", ACPI_FADT_OFFSET(xpm_timer_block),
  79. ACPI_FADT_OFFSET(pm_timer_block),
  80. ACPI_FADT_OFFSET(pm_timer_length), ACPI_FADT_REQUIRED},
  81. {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block),
  82. ACPI_FADT_OFFSET(gpe0_block),
  83. ACPI_FADT_OFFSET(gpe0_block_length), ACPI_FADT_SEPARATE_LENGTH},
  84. {"Gpe1Block", ACPI_FADT_OFFSET(xgpe1_block),
  85. ACPI_FADT_OFFSET(gpe1_block),
  86. ACPI_FADT_OFFSET(gpe1_block_length), ACPI_FADT_SEPARATE_LENGTH}
  87. };
  88. #define ACPI_FADT_INFO_ENTRIES (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_tb_init_generic_address
  92. *
  93. * PARAMETERS: generic_address - GAS struct to be initialized
  94. * byte_width - Width of this register
  95. * Address - Address of the register
  96. *
  97. * RETURN: None
  98. *
  99. * DESCRIPTION: Initialize a Generic Address Structure (GAS)
  100. * See the ACPI specification for a full description and
  101. * definition of this structure.
  102. *
  103. ******************************************************************************/
  104. static void inline
  105. acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
  106. u8 byte_width, u64 address)
  107. {
  108. /*
  109. * The 64-bit Address field is non-aligned in the byte packed
  110. * GAS struct.
  111. */
  112. ACPI_MOVE_64_TO_64(&generic_address->address, &address);
  113. /* All other fields are byte-wide */
  114. generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  115. generic_address->bit_width = byte_width << 3;
  116. generic_address->bit_offset = 0;
  117. generic_address->access_width = 0;
  118. }
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_tb_parse_fadt
  122. *
  123. * PARAMETERS: table_index - Index for the FADT
  124. * Flags - Flags
  125. *
  126. * RETURN: None
  127. *
  128. * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
  129. * (FADT contains the addresses of the DSDT and FACS)
  130. *
  131. ******************************************************************************/
  132. void acpi_tb_parse_fadt(u32 table_index, u8 flags)
  133. {
  134. u32 length;
  135. struct acpi_table_header *table;
  136. /*
  137. * The FADT has multiple versions with different lengths,
  138. * and it contains pointers to both the DSDT and FACS tables.
  139. *
  140. * Get a local copy of the FADT and convert it to a common format
  141. * Map entire FADT, assumed to be smaller than one page.
  142. */
  143. length = acpi_gbl_root_table_list.tables[table_index].length;
  144. table =
  145. acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
  146. address, length);
  147. if (!table) {
  148. return;
  149. }
  150. /*
  151. * Validate the FADT checksum before we copy the table. Ignore
  152. * checksum error as we want to try to get the DSDT and FACS.
  153. */
  154. (void)acpi_tb_verify_checksum(table, length);
  155. /* Obtain a local copy of the FADT in common ACPI 2.0+ format */
  156. acpi_tb_create_local_fadt(table, length);
  157. /* All done with the real FADT, unmap it */
  158. acpi_os_unmap_memory(table, length);
  159. /* Obtain the DSDT and FACS tables via their addresses within the FADT */
  160. acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
  161. flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
  162. acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
  163. flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
  164. }
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: acpi_tb_create_local_fadt
  168. *
  169. * PARAMETERS: Table - Pointer to BIOS FADT
  170. * Length - Length of the table
  171. *
  172. * RETURN: None
  173. *
  174. * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
  175. * Performs validation on some important FADT fields.
  176. *
  177. * NOTE: We create a local copy of the FADT regardless of the version.
  178. *
  179. ******************************************************************************/
  180. void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
  181. {
  182. /*
  183. * Check if the FADT is larger than the largest table that we expect
  184. * (the ACPI 2.0/3.0 version). If so, truncate the table, and issue
  185. * a warning.
  186. */
  187. if (length > sizeof(struct acpi_table_fadt)) {
  188. ACPI_WARNING((AE_INFO,
  189. "FADT (revision %u) is longer than ACPI 2.0 version, truncating length 0x%X to 0x%zX",
  190. table->revision, (unsigned)length,
  191. sizeof(struct acpi_table_fadt)));
  192. }
  193. /* Clear the entire local FADT */
  194. ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
  195. /* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */
  196. ACPI_MEMCPY(&acpi_gbl_FADT, table,
  197. ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
  198. /*
  199. * 1) Convert the local copy of the FADT to the common internal format
  200. * 2) Validate some of the important values within the FADT
  201. */
  202. acpi_tb_convert_fadt();
  203. acpi_tb_validate_fadt();
  204. }
  205. /*******************************************************************************
  206. *
  207. * FUNCTION: acpi_tb_convert_fadt
  208. *
  209. * PARAMETERS: None, uses acpi_gbl_FADT
  210. *
  211. * RETURN: None
  212. *
  213. * DESCRIPTION: Converts all versions of the FADT to a common internal format.
  214. * Expand all 32-bit addresses to 64-bit.
  215. *
  216. * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
  217. * and must contain a copy of the actual FADT.
  218. *
  219. * ACPICA will use the "X" fields of the FADT for all addresses.
  220. *
  221. * "X" fields are optional extensions to the original V1.0 fields. Even if
  222. * they are present in the structure, they can be optionally not used by
  223. * setting them to zero. Therefore, we must selectively expand V1.0 fields
  224. * if the corresponding X field is zero.
  225. *
  226. * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
  227. * "X" fields.
  228. *
  229. * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
  230. * expanding the corresponding ACPI 1.0 field.
  231. *
  232. ******************************************************************************/
  233. static void acpi_tb_convert_fadt(void)
  234. {
  235. u8 pm1_register_length;
  236. struct acpi_generic_address *target;
  237. u32 i;
  238. /* Update the local FADT table header length */
  239. acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
  240. /* Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary */
  241. if (!acpi_gbl_FADT.Xfacs) {
  242. acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
  243. }
  244. if (!acpi_gbl_FADT.Xdsdt) {
  245. acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
  246. }
  247. /*
  248. * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
  249. * should be zero are indeed zero. This will workaround BIOSs that
  250. * inadvertently place values in these fields.
  251. *
  252. * The ACPI 1.0 reserved fields that will be zeroed are the bytes located at
  253. * offset 45, 55, 95, and the word located at offset 109, 110.
  254. */
  255. if (acpi_gbl_FADT.header.revision < FADT2_REVISION_ID) {
  256. acpi_gbl_FADT.preferred_profile = 0;
  257. acpi_gbl_FADT.pstate_control = 0;
  258. acpi_gbl_FADT.cst_control = 0;
  259. acpi_gbl_FADT.boot_flags = 0;
  260. }
  261. /*
  262. * Expand the ACPI 1.0 32-bit V1.0 addresses to the ACPI 2.0 64-bit "X"
  263. * generic address structures as necessary.
  264. */
  265. for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
  266. target =
  267. ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
  268. fadt_info_table[i].target);
  269. /* Expand only if the X target is null */
  270. if (!target->address) {
  271. acpi_tb_init_generic_address(target,
  272. *ACPI_ADD_PTR(u8,
  273. &acpi_gbl_FADT,
  274. fadt_info_table
  275. [i].length),
  276. (u64) * ACPI_ADD_PTR(u32,
  277. &acpi_gbl_FADT,
  278. fadt_info_table
  279. [i].
  280. source));
  281. }
  282. }
  283. /*
  284. * Calculate separate GAS structs for the PM1 Enable registers.
  285. * These addresses do not appear (directly) in the FADT, so it is
  286. * useful to calculate them once, here.
  287. *
  288. * The PM event blocks are split into two register blocks, first is the
  289. * PM Status Register block, followed immediately by the PM Enable
  290. * Register block. Each is of length (xpm1x_event_block.bit_width/2).
  291. *
  292. * On various systems the v2 fields (and particularly the bit widths)
  293. * cannot be relied upon, though. Hence resort to using the v1 length
  294. * here (and warn about the inconsistency).
  295. */
  296. if (acpi_gbl_FADT.xpm1a_event_block.bit_width
  297. != acpi_gbl_FADT.pm1_event_length * 8)
  298. printk(KERN_WARNING "FADT: "
  299. "X_PM1a_EVT_BLK.bit_width (%u) does not match"
  300. " PM1_EVT_LEN (%u)\n",
  301. acpi_gbl_FADT.xpm1a_event_block.bit_width,
  302. acpi_gbl_FADT.pm1_event_length);
  303. pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
  304. /* The PM1A register block is required */
  305. acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
  306. pm1_register_length,
  307. (acpi_gbl_FADT.xpm1a_event_block.address +
  308. pm1_register_length));
  309. /* Don't forget to copy space_id of the GAS */
  310. acpi_gbl_xpm1a_enable.space_id =
  311. acpi_gbl_FADT.xpm1a_event_block.space_id;
  312. /* The PM1B register block is optional, ignore if not present */
  313. if (acpi_gbl_FADT.xpm1b_event_block.address) {
  314. if (acpi_gbl_FADT.xpm1b_event_block.bit_width
  315. != acpi_gbl_FADT.pm1_event_length * 8)
  316. printk(KERN_WARNING "FADT: "
  317. "X_PM1b_EVT_BLK.bit_width (%u) does not match"
  318. " PM1_EVT_LEN (%u)\n",
  319. acpi_gbl_FADT.xpm1b_event_block.bit_width,
  320. acpi_gbl_FADT.pm1_event_length);
  321. acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
  322. pm1_register_length,
  323. (acpi_gbl_FADT.xpm1b_event_block.
  324. address + pm1_register_length));
  325. /* Don't forget to copy space_id of the GAS */
  326. acpi_gbl_xpm1b_enable.space_id =
  327. acpi_gbl_FADT.xpm1b_event_block.space_id;
  328. }
  329. }
  330. /******************************************************************************
  331. *
  332. * FUNCTION: acpi_tb_validate_fadt
  333. *
  334. * PARAMETERS: Table - Pointer to the FADT to be validated
  335. *
  336. * RETURN: None
  337. *
  338. * DESCRIPTION: Validate various important fields within the FADT. If a problem
  339. * is found, issue a message, but no status is returned.
  340. * Used by both the table manager and the disassembler.
  341. *
  342. * Possible additional checks:
  343. * (acpi_gbl_FADT.pm1_event_length >= 4)
  344. * (acpi_gbl_FADT.pm1_control_length >= 2)
  345. * (acpi_gbl_FADT.pm_timer_length >= 4)
  346. * Gpe block lengths must be multiple of 2
  347. *
  348. ******************************************************************************/
  349. static void acpi_tb_validate_fadt(void)
  350. {
  351. u32 *address32;
  352. struct acpi_generic_address *address64;
  353. u8 length;
  354. u32 i;
  355. /* Examine all of the 64-bit extended address fields (X fields) */
  356. for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
  357. /* Generate pointers to the 32-bit and 64-bit addresses and get the length */
  358. address64 =
  359. ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
  360. fadt_info_table[i].target);
  361. address32 =
  362. ACPI_ADD_PTR(u32, &acpi_gbl_FADT,
  363. fadt_info_table[i].source);
  364. length =
  365. *ACPI_ADD_PTR(u8, &acpi_gbl_FADT,
  366. fadt_info_table[i].length);
  367. if (fadt_info_table[i].type & ACPI_FADT_REQUIRED) {
  368. /*
  369. * Field is required (Pm1a_event, Pm1a_control, pm_timer).
  370. * Both the address and length must be non-zero.
  371. */
  372. if (!address64->address || !length) {
  373. ACPI_ERROR((AE_INFO,
  374. "Required field \"%s\" has zero address and/or length: %8.8X%8.8X/%X",
  375. fadt_info_table[i].name,
  376. ACPI_FORMAT_UINT64(address64->
  377. address),
  378. length));
  379. }
  380. } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
  381. /*
  382. * Field is optional (PM2Control, GPE0, GPE1) AND has its own
  383. * length field. If present, both the address and length must be valid.
  384. */
  385. if ((address64->address && !length)
  386. || (!address64->address && length)) {
  387. ACPI_WARNING((AE_INFO,
  388. "Optional field \"%s\" has zero address or length: %8.8X%8.8X/%X",
  389. fadt_info_table[i].name,
  390. ACPI_FORMAT_UINT64(address64->
  391. address),
  392. length));
  393. }
  394. }
  395. /* If both 32- and 64-bit addresses are valid (non-zero), they must match */
  396. if (address64->address && *address32 &&
  397. (address64->address != (u64) * address32)) {
  398. ACPI_ERROR((AE_INFO,
  399. "32/64X address mismatch in \"%s\": [%8.8X] [%8.8X%8.8X], using 64X",
  400. fadt_info_table[i].name, *address32,
  401. ACPI_FORMAT_UINT64(address64->address)));
  402. }
  403. }
  404. }