hest.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * APEI Hardware Error Souce Table support
  3. *
  4. * HEST describes error sources in detail; communicates operational
  5. * parameters (i.e. severity levels, masking bits, and threshold
  6. * values) to Linux as necessary. It also allows the BIOS to report
  7. * non-standard error sources to Linux (for example, chipset-specific
  8. * error registers).
  9. *
  10. * For more information about HEST, please refer to ACPI Specification
  11. * version 4.0, section 17.3.2.
  12. *
  13. * Copyright 2009 Intel Corp.
  14. * Author: Huang Ying <ying.huang@intel.com>
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License version
  18. * 2 as published by the Free Software Foundation;
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/acpi.h>
  33. #include <linux/kdebug.h>
  34. #include <linux/highmem.h>
  35. #include <linux/io.h>
  36. #include <linux/platform_device.h>
  37. #include <acpi/apei.h>
  38. #include "apei-internal.h"
  39. #define HEST_PFX "HEST: "
  40. bool hest_disable;
  41. EXPORT_SYMBOL_GPL(hest_disable);
  42. /* HEST table parsing */
  43. static struct acpi_table_hest *__read_mostly hest_tab;
  44. static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
  45. [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */
  46. [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
  47. [ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi),
  48. [ACPI_HEST_TYPE_AER_ROOT_PORT] = sizeof(struct acpi_hest_aer_root),
  49. [ACPI_HEST_TYPE_AER_ENDPOINT] = sizeof(struct acpi_hest_aer),
  50. [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
  51. [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
  52. };
  53. static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
  54. {
  55. u16 hest_type = hest_hdr->type;
  56. int len;
  57. if (hest_type >= ACPI_HEST_TYPE_RESERVED)
  58. return 0;
  59. len = hest_esrc_len_tab[hest_type];
  60. if (hest_type == ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) {
  61. struct acpi_hest_ia_corrected *cmc;
  62. cmc = (struct acpi_hest_ia_corrected *)hest_hdr;
  63. len = sizeof(*cmc) + cmc->num_hardware_banks *
  64. sizeof(struct acpi_hest_ia_error_bank);
  65. } else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) {
  66. struct acpi_hest_ia_machine_check *mc;
  67. mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
  68. len = sizeof(*mc) + mc->num_hardware_banks *
  69. sizeof(struct acpi_hest_ia_error_bank);
  70. }
  71. BUG_ON(len == -1);
  72. return len;
  73. };
  74. int apei_hest_parse(apei_hest_func_t func, void *data)
  75. {
  76. struct acpi_hest_header *hest_hdr;
  77. int i, rc, len;
  78. if (hest_disable || !hest_tab)
  79. return -EINVAL;
  80. hest_hdr = (struct acpi_hest_header *)(hest_tab + 1);
  81. for (i = 0; i < hest_tab->error_source_count; i++) {
  82. len = hest_esrc_len(hest_hdr);
  83. if (!len) {
  84. pr_warning(FW_WARN HEST_PFX
  85. "Unknown or unused hardware error source "
  86. "type: %d for hardware error source: %d.\n",
  87. hest_hdr->type, hest_hdr->source_id);
  88. return -EINVAL;
  89. }
  90. if ((void *)hest_hdr + len >
  91. (void *)hest_tab + hest_tab->header.length) {
  92. pr_warning(FW_BUG HEST_PFX
  93. "Table contents overflow for hardware error source: %d.\n",
  94. hest_hdr->source_id);
  95. return -EINVAL;
  96. }
  97. rc = func(hest_hdr, data);
  98. if (rc)
  99. return rc;
  100. hest_hdr = (void *)hest_hdr + len;
  101. }
  102. return 0;
  103. }
  104. EXPORT_SYMBOL_GPL(apei_hest_parse);
  105. /*
  106. * Check if firmware advertises firmware first mode. We need FF bit to be set
  107. * along with a set of MC banks which work in FF mode.
  108. */
  109. static int __init hest_parse_cmc(struct acpi_hest_header *hest_hdr, void *data)
  110. {
  111. return arch_apei_enable_cmcff(hest_hdr, data);
  112. }
  113. struct ghes_arr {
  114. struct platform_device **ghes_devs;
  115. unsigned int count;
  116. };
  117. static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
  118. {
  119. int *count = data;
  120. if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
  121. (*count)++;
  122. return 0;
  123. }
  124. static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
  125. {
  126. struct platform_device *ghes_dev;
  127. struct ghes_arr *ghes_arr = data;
  128. int rc, i;
  129. if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
  130. return 0;
  131. if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
  132. return 0;
  133. for (i = 0; i < ghes_arr->count; i++) {
  134. struct acpi_hest_header *hdr;
  135. ghes_dev = ghes_arr->ghes_devs[i];
  136. hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data;
  137. if (hdr->source_id == hest_hdr->source_id) {
  138. pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n",
  139. hdr->source_id);
  140. return -EIO;
  141. }
  142. }
  143. ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
  144. if (!ghes_dev)
  145. return -ENOMEM;
  146. rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
  147. if (rc)
  148. goto err;
  149. rc = platform_device_add(ghes_dev);
  150. if (rc)
  151. goto err;
  152. ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
  153. return 0;
  154. err:
  155. platform_device_put(ghes_dev);
  156. return rc;
  157. }
  158. static int __init hest_ghes_dev_register(unsigned int ghes_count)
  159. {
  160. int rc, i;
  161. struct ghes_arr ghes_arr;
  162. ghes_arr.count = 0;
  163. ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
  164. if (!ghes_arr.ghes_devs)
  165. return -ENOMEM;
  166. rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
  167. if (rc)
  168. goto err;
  169. out:
  170. kfree(ghes_arr.ghes_devs);
  171. return rc;
  172. err:
  173. for (i = 0; i < ghes_arr.count; i++)
  174. platform_device_unregister(ghes_arr.ghes_devs[i]);
  175. goto out;
  176. }
  177. static int __init setup_hest_disable(char *str)
  178. {
  179. hest_disable = 1;
  180. return 0;
  181. }
  182. __setup("hest_disable", setup_hest_disable);
  183. void __init acpi_hest_init(void)
  184. {
  185. acpi_status status;
  186. int rc = -ENODEV;
  187. unsigned int ghes_count = 0;
  188. if (hest_disable) {
  189. pr_info(HEST_PFX "Table parsing disabled.\n");
  190. return;
  191. }
  192. status = acpi_get_table(ACPI_SIG_HEST, 0,
  193. (struct acpi_table_header **)&hest_tab);
  194. if (status == AE_NOT_FOUND)
  195. goto err;
  196. else if (ACPI_FAILURE(status)) {
  197. const char *msg = acpi_format_exception(status);
  198. pr_err(HEST_PFX "Failed to get table, %s\n", msg);
  199. rc = -EINVAL;
  200. goto err;
  201. }
  202. if (!acpi_disable_cmcff)
  203. apei_hest_parse(hest_parse_cmc, NULL);
  204. if (!ghes_disable) {
  205. rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
  206. if (rc)
  207. goto err;
  208. rc = hest_ghes_dev_register(ghes_count);
  209. if (rc)
  210. goto err;
  211. }
  212. pr_info(HEST_PFX "Table parsing has been initialized.\n");
  213. return;
  214. err:
  215. hest_disable = 1;
  216. }