tbfadt.c 22 KB

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