hest.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/acpi.h>
  29. #include <linux/kdebug.h>
  30. #include <linux/highmem.h>
  31. #include <linux/io.h>
  32. #include <linux/platform_device.h>
  33. #include <acpi/apei.h>
  34. #include "apei-internal.h"
  35. #define HEST_PFX "HEST: "
  36. bool hest_disable;
  37. EXPORT_SYMBOL_GPL(hest_disable);
  38. /* HEST table parsing */
  39. static struct acpi_table_hest *__read_mostly hest_tab;
  40. static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
  41. [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */
  42. [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
  43. [ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi),
  44. [ACPI_HEST_TYPE_AER_ROOT_PORT] = sizeof(struct acpi_hest_aer_root),
  45. [ACPI_HEST_TYPE_AER_ENDPOINT] = sizeof(struct acpi_hest_aer),
  46. [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
  47. [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
  48. };
  49. static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
  50. {
  51. u16 hest_type = hest_hdr->type;
  52. int len;
  53. if (hest_type >= ACPI_HEST_TYPE_RESERVED)
  54. return 0;
  55. len = hest_esrc_len_tab[hest_type];
  56. if (hest_type == ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) {
  57. struct acpi_hest_ia_corrected *cmc;
  58. cmc = (struct acpi_hest_ia_corrected *)hest_hdr;
  59. len = sizeof(*cmc) + cmc->num_hardware_banks *
  60. sizeof(struct acpi_hest_ia_error_bank);
  61. } else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) {
  62. struct acpi_hest_ia_machine_check *mc;
  63. mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
  64. len = sizeof(*mc) + mc->num_hardware_banks *
  65. sizeof(struct acpi_hest_ia_error_bank);
  66. }
  67. BUG_ON(len == -1);
  68. return len;
  69. };
  70. int apei_hest_parse(apei_hest_func_t func, void *data)
  71. {
  72. struct acpi_hest_header *hest_hdr;
  73. int i, rc, len;
  74. if (hest_disable || !hest_tab)
  75. return -EINVAL;
  76. hest_hdr = (struct acpi_hest_header *)(hest_tab + 1);
  77. for (i = 0; i < hest_tab->error_source_count; i++) {
  78. len = hest_esrc_len(hest_hdr);
  79. if (!len) {
  80. pr_warning(FW_WARN HEST_PFX
  81. "Unknown or unused hardware error source "
  82. "type: %d for hardware error source: %d.\n",
  83. hest_hdr->type, hest_hdr->source_id);
  84. return -EINVAL;
  85. }
  86. if ((void *)hest_hdr + len >
  87. (void *)hest_tab + hest_tab->header.length) {
  88. pr_warning(FW_BUG HEST_PFX
  89. "Table contents overflow for hardware error source: %d.\n",
  90. hest_hdr->source_id);
  91. return -EINVAL;
  92. }
  93. rc = func(hest_hdr, data);
  94. if (rc)
  95. return rc;
  96. hest_hdr = (void *)hest_hdr + len;
  97. }
  98. return 0;
  99. }
  100. EXPORT_SYMBOL_GPL(apei_hest_parse);
  101. /*
  102. * Check if firmware advertises firmware first mode. We need FF bit to be set
  103. * along with a set of MC banks which work in FF mode.
  104. */
  105. static int __init hest_parse_cmc(struct acpi_hest_header *hest_hdr, void *data)
  106. {
  107. return arch_apei_enable_cmcff(hest_hdr, data);
  108. }
  109. struct ghes_arr {
  110. struct platform_device **ghes_devs;
  111. unsigned int count;
  112. };
  113. static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
  114. {
  115. int *count = data;
  116. if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
  117. (*count)++;
  118. return 0;
  119. }
  120. static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
  121. {
  122. struct platform_device *ghes_dev;
  123. struct ghes_arr *ghes_arr = data;
  124. int rc, i;
  125. if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
  126. return 0;
  127. if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
  128. return 0;
  129. for (i = 0; i < ghes_arr->count; i++) {
  130. struct acpi_hest_header *hdr;
  131. ghes_dev = ghes_arr->ghes_devs[i];
  132. hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data;
  133. if (hdr->source_id == hest_hdr->source_id) {
  134. pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n",
  135. hdr->source_id);
  136. return -EIO;
  137. }
  138. }
  139. ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
  140. if (!ghes_dev)
  141. return -ENOMEM;
  142. rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
  143. if (rc)
  144. goto err;
  145. rc = platform_device_add(ghes_dev);
  146. if (rc)
  147. goto err;
  148. ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
  149. return 0;
  150. err:
  151. platform_device_put(ghes_dev);
  152. return rc;
  153. }
  154. static int __init hest_ghes_dev_register(unsigned int ghes_count)
  155. {
  156. int rc, i;
  157. struct ghes_arr ghes_arr;
  158. ghes_arr.count = 0;
  159. ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
  160. if (!ghes_arr.ghes_devs)
  161. return -ENOMEM;
  162. rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
  163. if (rc)
  164. goto err;
  165. out:
  166. kfree(ghes_arr.ghes_devs);
  167. return rc;
  168. err:
  169. for (i = 0; i < ghes_arr.count; i++)
  170. platform_device_unregister(ghes_arr.ghes_devs[i]);
  171. goto out;
  172. }
  173. static int __init setup_hest_disable(char *str)
  174. {
  175. hest_disable = 1;
  176. return 0;
  177. }
  178. __setup("hest_disable", setup_hest_disable);
  179. void __init acpi_hest_init(void)
  180. {
  181. acpi_status status;
  182. int rc = -ENODEV;
  183. unsigned int ghes_count = 0;
  184. if (hest_disable) {
  185. pr_info(HEST_PFX "Table parsing disabled.\n");
  186. return;
  187. }
  188. status = acpi_get_table(ACPI_SIG_HEST, 0,
  189. (struct acpi_table_header **)&hest_tab);
  190. if (status == AE_NOT_FOUND)
  191. goto err;
  192. else if (ACPI_FAILURE(status)) {
  193. const char *msg = acpi_format_exception(status);
  194. pr_err(HEST_PFX "Failed to get table, %s\n", msg);
  195. rc = -EINVAL;
  196. goto err;
  197. }
  198. if (!acpi_disable_cmcff)
  199. apei_hest_parse(hest_parse_cmc, NULL);
  200. if (!ghes_disable) {
  201. rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
  202. if (rc)
  203. goto err;
  204. rc = hest_ghes_dev_register(ghes_count);
  205. if (rc)
  206. goto err;
  207. }
  208. pr_info(HEST_PFX "Table parsing has been initialized.\n");
  209. return;
  210. err:
  211. hest_disable = 1;
  212. }