tbfadt.c 24 KB

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