tbfadt.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /******************************************************************************
  2. *
  3. * Module Name: tbfadt - FADT table utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/actables.h>
  44. #define _COMPONENT ACPI_TABLES
  45. ACPI_MODULE_NAME("tbfadt")
  46. /* Local prototypes */
  47. static void inline
  48. acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
  49. u8 bit_width, u64 address);
  50. static void acpi_tb_fadt_register_error(char *register_name, u32 value);
  51. static void acpi_tb_convert_fadt(void);
  52. static void acpi_tb_validate_fadt(void);
  53. /* Table used for conversion of FADT to common format */
  54. typedef struct acpi_fadt_conversion {
  55. u8 target;
  56. u8 source;
  57. u8 length;
  58. } acpi_fadt_conversion;
  59. static struct acpi_fadt_conversion fadt_conversion_table[] = {
  60. {ACPI_FADT_OFFSET(xpm1a_event_block),
  61. ACPI_FADT_OFFSET(pm1a_event_block),
  62. ACPI_FADT_OFFSET(pm1_event_length)},
  63. {ACPI_FADT_OFFSET(xpm1b_event_block),
  64. ACPI_FADT_OFFSET(pm1b_event_block),
  65. ACPI_FADT_OFFSET(pm1_event_length)},
  66. {ACPI_FADT_OFFSET(xpm1a_control_block),
  67. ACPI_FADT_OFFSET(pm1a_control_block),
  68. ACPI_FADT_OFFSET(pm1_control_length)},
  69. {ACPI_FADT_OFFSET(xpm1b_control_block),
  70. ACPI_FADT_OFFSET(pm1b_control_block),
  71. ACPI_FADT_OFFSET(pm1_control_length)},
  72. {ACPI_FADT_OFFSET(xpm2_control_block),
  73. ACPI_FADT_OFFSET(pm2_control_block),
  74. ACPI_FADT_OFFSET(pm2_control_length)},
  75. {ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block),
  76. ACPI_FADT_OFFSET(pm_timer_length)},
  77. {ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block),
  78. ACPI_FADT_OFFSET(gpe0_block_length)},
  79. {ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block),
  80. ACPI_FADT_OFFSET(gpe1_block_length)}
  81. };
  82. #define ACPI_FADT_CONVERSION_ENTRIES (sizeof (fadt_conversion_table) / sizeof (struct acpi_fadt_conversion))
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_tb_init_generic_address
  86. *
  87. * PARAMETERS: new_gas_struct - GAS struct to be initialized
  88. * bit_width - Width of this register
  89. * Address - Address of the register
  90. *
  91. * RETURN: None
  92. *
  93. * DESCRIPTION: Initialize a GAS structure.
  94. *
  95. ******************************************************************************/
  96. static void inline
  97. acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
  98. u8 bit_width, u64 address)
  99. {
  100. ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address);
  101. new_gas_struct->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  102. new_gas_struct->bit_width = bit_width;
  103. new_gas_struct->bit_offset = 0;
  104. new_gas_struct->access_width = 0;
  105. }
  106. /*******************************************************************************
  107. *
  108. * FUNCTION: acpi_tb_parse_fadt
  109. *
  110. * PARAMETERS: table_index - Index for the FADT
  111. * Flags - Flags
  112. *
  113. * RETURN: None
  114. *
  115. * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
  116. * (FADT contains the addresses of the DSDT and FACS)
  117. *
  118. ******************************************************************************/
  119. void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
  120. {
  121. u32 length;
  122. struct acpi_table_header *table;
  123. /*
  124. * Special case for the FADT because of multiple versions and the fact
  125. * that it contains pointers to both the DSDT and FACS tables.
  126. *
  127. * Get a local copy of the FADT and convert it to a common format
  128. * Map entire FADT, assumed to be smaller than one page.
  129. */
  130. length = acpi_gbl_root_table_list.tables[table_index].length;
  131. table =
  132. acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
  133. address, length);
  134. if (!table) {
  135. return;
  136. }
  137. /*
  138. * Validate the FADT checksum before we copy the table. Ignore
  139. * checksum error as we want to try to get the DSDT and FACS.
  140. */
  141. (void)acpi_tb_verify_checksum(table, length);
  142. /* Copy the entire FADT locally */
  143. ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
  144. ACPI_MEMCPY(&acpi_gbl_FADT, table,
  145. ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
  146. acpi_os_unmap_memory(table, length);
  147. /* Convert local FADT to the common internal format */
  148. acpi_tb_convert_fadt();
  149. /* Extract the DSDT and FACS tables from the FADT */
  150. acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
  151. flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
  152. acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
  153. flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
  154. /* Validate important FADT values */
  155. acpi_tb_validate_fadt();
  156. }
  157. /*******************************************************************************
  158. *
  159. * FUNCTION: acpi_tb_convert_fadt
  160. *
  161. * PARAMETERS: None, uses acpi_gbl_FADT
  162. *
  163. * RETURN: None
  164. *
  165. * DESCRIPTION: Converts all versions of the FADT to a common internal format.
  166. *
  167. * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
  168. * and must contain a copy of the actual FADT.
  169. *
  170. * ACPICA will use the "X" fields of the FADT for all addresses.
  171. *
  172. * "X" fields are optional extensions to the original V1.0 fields. Even if
  173. * they are present in the structure, they can be optionally not used by
  174. * setting them to zero. Therefore, we must selectively expand V1.0 fields
  175. * if the corresponding X field is zero.
  176. *
  177. * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
  178. * "X" fields.
  179. *
  180. * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
  181. * expanding the corresponding ACPI 1.0 field.
  182. *
  183. ******************************************************************************/
  184. static void acpi_tb_convert_fadt(void)
  185. {
  186. u8 pm1_register_length;
  187. struct acpi_generic_address *target;
  188. acpi_native_uint i;
  189. /* Expand the FACS and DSDT addresses as necessary */
  190. if (!acpi_gbl_FADT.Xfacs) {
  191. acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
  192. }
  193. if (!acpi_gbl_FADT.Xdsdt) {
  194. acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
  195. }
  196. /*
  197. * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
  198. * structures as necessary.
  199. */
  200. for (i = 0; i < ACPI_FADT_CONVERSION_ENTRIES; i++) {
  201. target =
  202. ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
  203. fadt_conversion_table[i].target);
  204. /* Expand only if the X target is null */
  205. if (!target->address) {
  206. acpi_tb_init_generic_address(target,
  207. *ACPI_ADD_PTR(u8,
  208. &acpi_gbl_FADT,
  209. fadt_conversion_table
  210. [i].length),
  211. (u64) * ACPI_ADD_PTR(u32,
  212. &acpi_gbl_FADT,
  213. fadt_conversion_table
  214. [i].
  215. source));
  216. }
  217. }
  218. /*
  219. * Calculate separate GAS structs for the PM1 Enable registers.
  220. * These addresses do not appear (directly) in the FADT, so it is
  221. * useful to calculate them once, here.
  222. *
  223. * The PM event blocks are split into two register blocks, first is the
  224. * PM Status Register block, followed immediately by the PM Enable Register
  225. * block. Each is of length (pm1_event_length/2)
  226. */
  227. pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
  228. /* PM1A is required */
  229. acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
  230. pm1_register_length,
  231. (acpi_gbl_FADT.xpm1a_event_block.address +
  232. pm1_register_length));
  233. /* PM1B is optional; leave null if not present */
  234. if (acpi_gbl_FADT.xpm1b_event_block.address) {
  235. acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
  236. pm1_register_length,
  237. (acpi_gbl_FADT.xpm1b_event_block.
  238. address + pm1_register_length));
  239. }
  240. /* Global FADT is the new common V2.0 FADT */
  241. acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
  242. }
  243. /******************************************************************************
  244. *
  245. * FUNCTION: acpi_tb_validate_fadt
  246. *
  247. * PARAMETERS: None
  248. *
  249. * RETURN: None
  250. *
  251. * DESCRIPTION: Validate various ACPI registers in the FADT. For problems,
  252. * issue a message, but no status is returned.
  253. *
  254. ******************************************************************************/
  255. static void acpi_tb_validate_fadt(void)
  256. {
  257. /* These length fields have a minimum value */
  258. if (acpi_gbl_FADT.pm1_event_length < 4) {
  259. acpi_tb_fadt_register_error("Pm1EventLength",
  260. (u32) acpi_gbl_FADT.
  261. pm1_event_length);
  262. }
  263. if (acpi_gbl_FADT.pm_timer_length < 4) {
  264. acpi_tb_fadt_register_error("PmTimerLength",
  265. (u32) acpi_gbl_FADT.
  266. pm_timer_length);
  267. }
  268. /* These length and address fields must be non-zero */
  269. if (!acpi_gbl_FADT.pm1_control_length) {
  270. acpi_tb_fadt_register_error("Pm1ControlLength", 0);
  271. }
  272. if (!acpi_gbl_FADT.xpm1a_event_block.address) {
  273. acpi_tb_fadt_register_error("XPm1aEventBlock.Address", 0);
  274. }
  275. if (!acpi_gbl_FADT.xpm1a_control_block.address) {
  276. acpi_tb_fadt_register_error("XPm1aControlBlock.Address", 0);
  277. }
  278. if (!acpi_gbl_FADT.xpm_timer_block.address) {
  279. acpi_tb_fadt_register_error("XPmTimerBlock.Address", 0);
  280. }
  281. /* If PM2 block is present, must have non-zero length */
  282. if ((acpi_gbl_FADT.xpm2_control_block.address &&
  283. !acpi_gbl_FADT.pm2_control_length)) {
  284. acpi_tb_fadt_register_error("Pm2ControlLength",
  285. (u32) acpi_gbl_FADT.
  286. pm2_control_length);
  287. }
  288. /* Length of any valid GPE blocks must be a multiple of 2 */
  289. if (acpi_gbl_FADT.xgpe0_block.address &&
  290. (acpi_gbl_FADT.gpe0_block_length & 1)) {
  291. acpi_tb_fadt_register_error("Gpe0BlockLength",
  292. (u32) acpi_gbl_FADT.
  293. gpe0_block_length);
  294. }
  295. if (acpi_gbl_FADT.xgpe1_block.address &&
  296. (acpi_gbl_FADT.gpe1_block_length & 1)) {
  297. acpi_tb_fadt_register_error("Gpe1BlockLength",
  298. (u32) acpi_gbl_FADT.
  299. gpe1_block_length);
  300. }
  301. }
  302. /*******************************************************************************
  303. *
  304. * FUNCTION: acpi_tb_fadt_register_error
  305. *
  306. * PARAMETERS: register_name - Pointer to string identifying register
  307. * Value - Actual register contents value
  308. *
  309. * RETURN: None
  310. *
  311. * DESCRIPTION: Display FADT warning message
  312. *
  313. ******************************************************************************/
  314. static void acpi_tb_fadt_register_error(char *register_name, u32 value)
  315. {
  316. ACPI_WARNING((AE_INFO, "Invalid FADT value in field \"%s\" = %X",
  317. register_name, value));
  318. }