tbfadt.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /******************************************************************************
  2. *
  3. * Module Name: tbfadt - FADT table utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, 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("tbfadt")
  47. /* Local prototypes */
  48. static void
  49. acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
  50. u8 space_id,
  51. u8 byte_width, u64 address, char *register_name);
  52. static void acpi_tb_convert_fadt(void);
  53. static void acpi_tb_validate_fadt(void);
  54. static void acpi_tb_setup_fadt_registers(void);
  55. /* Table for conversion of FADT to common internal format and FADT validation */
  56. typedef struct acpi_fadt_info {
  57. char *name;
  58. u16 address64;
  59. u16 address32;
  60. u16 length;
  61. u8 default_length;
  62. u8 type;
  63. } acpi_fadt_info;
  64. #define ACPI_FADT_OPTIONAL 0
  65. #define ACPI_FADT_REQUIRED 1
  66. #define ACPI_FADT_SEPARATE_LENGTH 2
  67. static struct acpi_fadt_info fadt_info_table[] = {
  68. {"Pm1aEventBlock",
  69. ACPI_FADT_OFFSET(xpm1a_event_block),
  70. ACPI_FADT_OFFSET(pm1a_event_block),
  71. ACPI_FADT_OFFSET(pm1_event_length),
  72. ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
  73. ACPI_FADT_REQUIRED},
  74. {"Pm1bEventBlock",
  75. ACPI_FADT_OFFSET(xpm1b_event_block),
  76. ACPI_FADT_OFFSET(pm1b_event_block),
  77. ACPI_FADT_OFFSET(pm1_event_length),
  78. ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
  79. ACPI_FADT_OPTIONAL},
  80. {"Pm1aControlBlock",
  81. ACPI_FADT_OFFSET(xpm1a_control_block),
  82. ACPI_FADT_OFFSET(pm1a_control_block),
  83. ACPI_FADT_OFFSET(pm1_control_length),
  84. ACPI_PM1_REGISTER_WIDTH,
  85. ACPI_FADT_REQUIRED},
  86. {"Pm1bControlBlock",
  87. ACPI_FADT_OFFSET(xpm1b_control_block),
  88. ACPI_FADT_OFFSET(pm1b_control_block),
  89. ACPI_FADT_OFFSET(pm1_control_length),
  90. ACPI_PM1_REGISTER_WIDTH,
  91. ACPI_FADT_OPTIONAL},
  92. {"Pm2ControlBlock",
  93. ACPI_FADT_OFFSET(xpm2_control_block),
  94. ACPI_FADT_OFFSET(pm2_control_block),
  95. ACPI_FADT_OFFSET(pm2_control_length),
  96. ACPI_PM2_REGISTER_WIDTH,
  97. ACPI_FADT_SEPARATE_LENGTH},
  98. {"PmTimerBlock",
  99. ACPI_FADT_OFFSET(xpm_timer_block),
  100. ACPI_FADT_OFFSET(pm_timer_block),
  101. ACPI_FADT_OFFSET(pm_timer_length),
  102. ACPI_PM_TIMER_WIDTH,
  103. ACPI_FADT_REQUIRED},
  104. {"Gpe0Block",
  105. ACPI_FADT_OFFSET(xgpe0_block),
  106. ACPI_FADT_OFFSET(gpe0_block),
  107. ACPI_FADT_OFFSET(gpe0_block_length),
  108. 0,
  109. ACPI_FADT_SEPARATE_LENGTH},
  110. {"Gpe1Block",
  111. ACPI_FADT_OFFSET(xgpe1_block),
  112. ACPI_FADT_OFFSET(gpe1_block),
  113. ACPI_FADT_OFFSET(gpe1_block_length),
  114. 0,
  115. ACPI_FADT_SEPARATE_LENGTH}
  116. };
  117. #define ACPI_FADT_INFO_ENTRIES \
  118. (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
  119. /* Table used to split Event Blocks into separate status/enable registers */
  120. typedef struct acpi_fadt_pm_info {
  121. struct acpi_generic_address *target;
  122. u16 source;
  123. u8 register_num;
  124. } acpi_fadt_pm_info;
  125. static struct acpi_fadt_pm_info fadt_pm_info_table[] = {
  126. {&acpi_gbl_xpm1a_status,
  127. ACPI_FADT_OFFSET(xpm1a_event_block),
  128. 0},
  129. {&acpi_gbl_xpm1a_enable,
  130. ACPI_FADT_OFFSET(xpm1a_event_block),
  131. 1},
  132. {&acpi_gbl_xpm1b_status,
  133. ACPI_FADT_OFFSET(xpm1b_event_block),
  134. 0},
  135. {&acpi_gbl_xpm1b_enable,
  136. ACPI_FADT_OFFSET(xpm1b_event_block),
  137. 1}
  138. };
  139. #define ACPI_FADT_PM_INFO_ENTRIES \
  140. (sizeof (fadt_pm_info_table) / sizeof (struct acpi_fadt_pm_info))
  141. /*******************************************************************************
  142. *
  143. * FUNCTION: acpi_tb_init_generic_address
  144. *
  145. * PARAMETERS: generic_address - GAS struct to be initialized
  146. * byte_width - Width of this register
  147. * address - Address of the register
  148. *
  149. * RETURN: None
  150. *
  151. * DESCRIPTION: Initialize a Generic Address Structure (GAS)
  152. * See the ACPI specification for a full description and
  153. * definition of this structure.
  154. *
  155. ******************************************************************************/
  156. static void
  157. acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
  158. u8 space_id,
  159. u8 byte_width, u64 address, char *register_name)
  160. {
  161. u8 bit_width;
  162. /* Bit width field in the GAS is only one byte long, 255 max */
  163. bit_width = (u8)(byte_width * 8);
  164. if (byte_width > 31) { /* (31*8)=248 */
  165. ACPI_ERROR((AE_INFO,
  166. "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
  167. "to convert to GAS struct - 255 bits max, truncating",
  168. register_name, byte_width, (byte_width * 8)));
  169. bit_width = 255;
  170. }
  171. /*
  172. * The 64-bit Address field is non-aligned in the byte packed
  173. * GAS struct.
  174. */
  175. ACPI_MOVE_64_TO_64(&generic_address->address, &address);
  176. /* All other fields are byte-wide */
  177. generic_address->space_id = space_id;
  178. generic_address->bit_width = bit_width;
  179. generic_address->bit_offset = 0;
  180. generic_address->access_width = 0; /* Access width ANY */
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_tb_parse_fadt
  185. *
  186. * PARAMETERS: table_index - Index for the FADT
  187. *
  188. * RETURN: None
  189. *
  190. * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
  191. * (FADT contains the addresses of the DSDT and FACS)
  192. *
  193. ******************************************************************************/
  194. void acpi_tb_parse_fadt(u32 table_index)
  195. {
  196. u32 length;
  197. struct acpi_table_header *table;
  198. /*
  199. * The FADT has multiple versions with different lengths,
  200. * and it contains pointers to both the DSDT and FACS tables.
  201. *
  202. * Get a local copy of the FADT and convert it to a common format
  203. * Map entire FADT, assumed to be smaller than one page.
  204. */
  205. length = acpi_gbl_root_table_list.tables[table_index].length;
  206. table =
  207. acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
  208. address, length);
  209. if (!table) {
  210. return;
  211. }
  212. /*
  213. * Validate the FADT checksum before we copy the table. Ignore
  214. * checksum error as we want to try to get the DSDT and FACS.
  215. */
  216. (void)acpi_tb_verify_checksum(table, length);
  217. /* Create a local copy of the FADT in common ACPI 2.0+ format */
  218. acpi_tb_create_local_fadt(table, length);
  219. /* All done with the real FADT, unmap it */
  220. acpi_os_unmap_memory(table, length);
  221. /* Obtain the DSDT and FACS tables via their addresses within the FADT */
  222. acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
  223. ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
  224. /* If Hardware Reduced flag is set, there is no FACS */
  225. if (!acpi_gbl_reduced_hardware) {
  226. acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.
  227. Xfacs, ACPI_SIG_FACS,
  228. ACPI_TABLE_INDEX_FACS);
  229. }
  230. }
  231. /*******************************************************************************
  232. *
  233. * FUNCTION: acpi_tb_create_local_fadt
  234. *
  235. * PARAMETERS: table - Pointer to BIOS FADT
  236. * length - Length of the table
  237. *
  238. * RETURN: None
  239. *
  240. * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
  241. * Performs validation on some important FADT fields.
  242. *
  243. * NOTE: We create a local copy of the FADT regardless of the version.
  244. *
  245. ******************************************************************************/
  246. void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
  247. {
  248. /*
  249. * Check if the FADT is larger than the largest table that we expect
  250. * (the ACPI 5.0 version). If so, truncate the table, and issue
  251. * a warning.
  252. */
  253. if (length > sizeof(struct acpi_table_fadt)) {
  254. ACPI_BIOS_WARNING((AE_INFO,
  255. "FADT (revision %u) is longer than ACPI 5.0 version, "
  256. "truncating length %u to %u",
  257. table->revision, length,
  258. (u32)sizeof(struct acpi_table_fadt)));
  259. }
  260. /* Clear the entire local FADT */
  261. ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
  262. /* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */
  263. ACPI_MEMCPY(&acpi_gbl_FADT, table,
  264. ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
  265. /* Take a copy of the Hardware Reduced flag */
  266. acpi_gbl_reduced_hardware = FALSE;
  267. if (acpi_gbl_FADT.flags & ACPI_FADT_HW_REDUCED) {
  268. acpi_gbl_reduced_hardware = TRUE;
  269. }
  270. /* Convert the local copy of the FADT to the common internal format */
  271. acpi_tb_convert_fadt();
  272. /* Validate FADT values now, before we make any changes */
  273. acpi_tb_validate_fadt();
  274. /* Initialize the global ACPI register structures */
  275. acpi_tb_setup_fadt_registers();
  276. }
  277. /*******************************************************************************
  278. *
  279. * FUNCTION: acpi_tb_convert_fadt
  280. *
  281. * PARAMETERS: None, uses acpi_gbl_FADT
  282. *
  283. * RETURN: None
  284. *
  285. * DESCRIPTION: Converts all versions of the FADT to a common internal format.
  286. * Expand 32-bit addresses to 64-bit as necessary.
  287. *
  288. * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
  289. * and must contain a copy of the actual FADT.
  290. *
  291. * Notes on 64-bit register addresses:
  292. *
  293. * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
  294. * fields of the FADT for all ACPI register addresses.
  295. *
  296. * The 64-bit "X" fields are optional extensions to the original 32-bit FADT
  297. * V1.0 fields. Even if they are present in the FADT, they are optional and
  298. * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
  299. * 32-bit V1.0 fields if the corresponding X field is zero.
  300. *
  301. * For ACPI 1.0 FADTs, all 32-bit address fields are expanded to the
  302. * corresponding "X" fields in the internal FADT.
  303. *
  304. * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
  305. * to the corresponding 64-bit X fields. For compatibility with other ACPI
  306. * implementations, we ignore the 64-bit field if the 32-bit field is valid,
  307. * regardless of whether the host OS is 32-bit or 64-bit.
  308. *
  309. ******************************************************************************/
  310. static void acpi_tb_convert_fadt(void)
  311. {
  312. struct acpi_generic_address *address64;
  313. u32 address32;
  314. u32 i;
  315. /*
  316. * Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary.
  317. * Later code will always use the X 64-bit field. Also, check for an
  318. * address mismatch between the 32-bit and 64-bit address fields
  319. * (FIRMWARE_CTRL/X_FIRMWARE_CTRL, DSDT/X_DSDT) which would indicate
  320. * the presence of two FACS or two DSDT tables.
  321. */
  322. if (!acpi_gbl_FADT.Xfacs) {
  323. acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
  324. } else if (acpi_gbl_FADT.facs &&
  325. (acpi_gbl_FADT.Xfacs != (u64) acpi_gbl_FADT.facs)) {
  326. ACPI_WARNING((AE_INFO,
  327. "32/64 FACS address mismatch in FADT - two FACS tables!"));
  328. }
  329. if (!acpi_gbl_FADT.Xdsdt) {
  330. acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
  331. } else if (acpi_gbl_FADT.dsdt &&
  332. (acpi_gbl_FADT.Xdsdt != (u64) acpi_gbl_FADT.dsdt)) {
  333. ACPI_WARNING((AE_INFO,
  334. "32/64 DSDT address mismatch in FADT - two DSDT tables!"));
  335. }
  336. /*
  337. * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
  338. * should be zero are indeed zero. This will workaround BIOSs that
  339. * inadvertently place values in these fields.
  340. *
  341. * The ACPI 1.0 reserved fields that will be zeroed are the bytes located at
  342. * offset 45, 55, 95, and the word located at offset 109, 110.
  343. *
  344. * Note: The FADT revision value is unreliable. Only the length can be
  345. * trusted.
  346. */
  347. if (acpi_gbl_FADT.header.length <= ACPI_FADT_V2_SIZE) {
  348. acpi_gbl_FADT.preferred_profile = 0;
  349. acpi_gbl_FADT.pstate_control = 0;
  350. acpi_gbl_FADT.cst_control = 0;
  351. acpi_gbl_FADT.boot_flags = 0;
  352. }
  353. /* Update the local FADT table header length */
  354. acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
  355. /*
  356. * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
  357. * generic address structures as necessary. Later code will always use
  358. * the 64-bit address structures.
  359. *
  360. * March 2009:
  361. * We now always use the 32-bit address if it is valid (non-null). This
  362. * is not in accordance with the ACPI specification which states that
  363. * the 64-bit address supersedes the 32-bit version, but we do this for
  364. * compatibility with other ACPI implementations. Most notably, in the
  365. * case where both the 32 and 64 versions are non-null, we use the 32-bit
  366. * version. This is the only address that is guaranteed to have been
  367. * tested by the BIOS manufacturer.
  368. */
  369. for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
  370. address32 = *ACPI_ADD_PTR(u32,
  371. &acpi_gbl_FADT,
  372. fadt_info_table[i].address32);
  373. address64 = ACPI_ADD_PTR(struct acpi_generic_address,
  374. &acpi_gbl_FADT,
  375. fadt_info_table[i].address64);
  376. /*
  377. * If both 32- and 64-bit addresses are valid (non-zero),
  378. * they must match.
  379. */
  380. if (address64->address && address32 &&
  381. (address64->address != (u64)address32)) {
  382. ACPI_BIOS_ERROR((AE_INFO,
  383. "32/64X address mismatch in FADT/%s: "
  384. "0x%8.8X/0x%8.8X%8.8X, using 32",
  385. fadt_info_table[i].name, address32,
  386. ACPI_FORMAT_UINT64(address64->
  387. address)));
  388. }
  389. /* Always use 32-bit address if it is valid (non-null) */
  390. if (address32) {
  391. /*
  392. * Copy the 32-bit address to the 64-bit GAS structure. The
  393. * Space ID is always I/O for 32-bit legacy address fields
  394. */
  395. acpi_tb_init_generic_address(address64,
  396. ACPI_ADR_SPACE_SYSTEM_IO,
  397. *ACPI_ADD_PTR(u8,
  398. &acpi_gbl_FADT,
  399. fadt_info_table
  400. [i].length),
  401. (u64) address32,
  402. fadt_info_table[i].name);
  403. }
  404. }
  405. }
  406. /*******************************************************************************
  407. *
  408. * FUNCTION: acpi_tb_validate_fadt
  409. *
  410. * PARAMETERS: table - Pointer to the FADT to be validated
  411. *
  412. * RETURN: None
  413. *
  414. * DESCRIPTION: Validate various important fields within the FADT. If a problem
  415. * is found, issue a message, but no status is returned.
  416. * Used by both the table manager and the disassembler.
  417. *
  418. * Possible additional checks:
  419. * (acpi_gbl_FADT.pm1_event_length >= 4)
  420. * (acpi_gbl_FADT.pm1_control_length >= 2)
  421. * (acpi_gbl_FADT.pm_timer_length >= 4)
  422. * Gpe block lengths must be multiple of 2
  423. *
  424. ******************************************************************************/
  425. static void acpi_tb_validate_fadt(void)
  426. {
  427. char *name;
  428. struct acpi_generic_address *address64;
  429. u8 length;
  430. u32 i;
  431. /*
  432. * Check for FACS and DSDT address mismatches. An address mismatch between
  433. * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
  434. * DSDT/X_DSDT) would indicate the presence of two FACS or two DSDT tables.
  435. */
  436. if (acpi_gbl_FADT.facs &&
  437. (acpi_gbl_FADT.Xfacs != (u64)acpi_gbl_FADT.facs)) {
  438. ACPI_BIOS_WARNING((AE_INFO,
  439. "32/64X FACS address mismatch in FADT - "
  440. "0x%8.8X/0x%8.8X%8.8X, using 32",
  441. acpi_gbl_FADT.facs,
  442. ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xfacs)));
  443. acpi_gbl_FADT.Xfacs = (u64)acpi_gbl_FADT.facs;
  444. }
  445. if (acpi_gbl_FADT.dsdt &&
  446. (acpi_gbl_FADT.Xdsdt != (u64)acpi_gbl_FADT.dsdt)) {
  447. ACPI_BIOS_WARNING((AE_INFO,
  448. "32/64X DSDT address mismatch in FADT - "
  449. "0x%8.8X/0x%8.8X%8.8X, using 32",
  450. acpi_gbl_FADT.dsdt,
  451. ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xdsdt)));
  452. acpi_gbl_FADT.Xdsdt = (u64)acpi_gbl_FADT.dsdt;
  453. }
  454. /* If Hardware Reduced flag is set, we are all done */
  455. if (acpi_gbl_reduced_hardware) {
  456. return;
  457. }
  458. /* Examine all of the 64-bit extended address fields (X fields) */
  459. for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
  460. /*
  461. * Generate pointer to the 64-bit address, get the register
  462. * length (width) and the register name
  463. */
  464. address64 = ACPI_ADD_PTR(struct acpi_generic_address,
  465. &acpi_gbl_FADT,
  466. fadt_info_table[i].address64);
  467. length =
  468. *ACPI_ADD_PTR(u8, &acpi_gbl_FADT,
  469. fadt_info_table[i].length);
  470. name = fadt_info_table[i].name;
  471. /*
  472. * For each extended field, check for length mismatch between the
  473. * legacy length field and the corresponding 64-bit X length field.
  474. */
  475. if (address64->address &&
  476. (address64->bit_width != ACPI_MUL_8(length))) {
  477. ACPI_BIOS_WARNING((AE_INFO,
  478. "32/64X length mismatch in FADT/%s: %u/%u",
  479. name, ACPI_MUL_8(length),
  480. address64->bit_width));
  481. }
  482. if (fadt_info_table[i].type & ACPI_FADT_REQUIRED) {
  483. /*
  484. * Field is required (Pm1a_event, Pm1a_control, pm_timer).
  485. * Both the address and length must be non-zero.
  486. */
  487. if (!address64->address || !length) {
  488. ACPI_BIOS_ERROR((AE_INFO,
  489. "Required FADT field %s has zero address and/or length: "
  490. "0x%8.8X%8.8X/0x%X",
  491. name,
  492. ACPI_FORMAT_UINT64(address64->
  493. address),
  494. length));
  495. }
  496. } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
  497. /*
  498. * Field is optional (Pm2_control, GPE0, GPE1) AND has its own
  499. * length field. If present, both the address and length must
  500. * be valid.
  501. */
  502. if ((address64->address && !length) ||
  503. (!address64->address && length)) {
  504. ACPI_BIOS_WARNING((AE_INFO,
  505. "Optional FADT field %s has zero address or length: "
  506. "0x%8.8X%8.8X/0x%X",
  507. name,
  508. ACPI_FORMAT_UINT64
  509. (address64->address),
  510. length));
  511. }
  512. }
  513. }
  514. }
  515. /*******************************************************************************
  516. *
  517. * FUNCTION: acpi_tb_setup_fadt_registers
  518. *
  519. * PARAMETERS: None, uses acpi_gbl_FADT.
  520. *
  521. * RETURN: None
  522. *
  523. * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
  524. * force FADT register definitions to their default lengths.
  525. *
  526. ******************************************************************************/
  527. static void acpi_tb_setup_fadt_registers(void)
  528. {
  529. struct acpi_generic_address *target64;
  530. struct acpi_generic_address *source64;
  531. u8 pm1_register_byte_width;
  532. u32 i;
  533. /*
  534. * Optionally check all register lengths against the default values and
  535. * update them if they are incorrect.
  536. */
  537. if (acpi_gbl_use_default_register_widths) {
  538. for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
  539. target64 =
  540. ACPI_ADD_PTR(struct acpi_generic_address,
  541. &acpi_gbl_FADT,
  542. fadt_info_table[i].address64);
  543. /*
  544. * If a valid register (Address != 0) and the (default_length > 0)
  545. * (Not a GPE register), then check the width against the default.
  546. */
  547. if ((target64->address) &&
  548. (fadt_info_table[i].default_length > 0) &&
  549. (fadt_info_table[i].default_length !=
  550. target64->bit_width)) {
  551. ACPI_BIOS_WARNING((AE_INFO,
  552. "Invalid length for FADT/%s: %u, using default %u",
  553. fadt_info_table[i].name,
  554. target64->bit_width,
  555. fadt_info_table[i].
  556. default_length));
  557. /* Incorrect size, set width to the default */
  558. target64->bit_width =
  559. fadt_info_table[i].default_length;
  560. }
  561. }
  562. }
  563. /*
  564. * Get the length of the individual PM1 registers (enable and status).
  565. * Each register is defined to be (event block length / 2). Extra divide
  566. * by 8 converts bits to bytes.
  567. */
  568. pm1_register_byte_width = (u8)
  569. ACPI_DIV_16(acpi_gbl_FADT.xpm1a_event_block.bit_width);
  570. /*
  571. * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
  572. * registers. These addresses do not appear (directly) in the FADT, so it
  573. * is useful to pre-calculate them from the PM1 Event Block definitions.
  574. *
  575. * The PM event blocks are split into two register blocks, first is the
  576. * PM Status Register block, followed immediately by the PM Enable
  577. * Register block. Each is of length (pm1_event_length/2)
  578. *
  579. * Note: The PM1A event block is required by the ACPI specification.
  580. * However, the PM1B event block is optional and is rarely, if ever,
  581. * used.
  582. */
  583. for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++) {
  584. source64 =
  585. ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
  586. fadt_pm_info_table[i].source);
  587. if (source64->address) {
  588. acpi_tb_init_generic_address(fadt_pm_info_table[i].
  589. target, source64->space_id,
  590. pm1_register_byte_width,
  591. source64->address +
  592. (fadt_pm_info_table[i].
  593. register_num *
  594. pm1_register_byte_width),
  595. "PmRegisters");
  596. }
  597. }
  598. }