tbfadt.c 22 KB

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