hest.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. int 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)
  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. struct ghes_arr {
  106. struct platform_device **ghes_devs;
  107. unsigned int count;
  108. };
  109. static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
  110. {
  111. int *count = data;
  112. if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
  113. (*count)++;
  114. return 0;
  115. }
  116. static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
  117. {
  118. struct platform_device *ghes_dev;
  119. struct ghes_arr *ghes_arr = data;
  120. int rc, i;
  121. if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
  122. return 0;
  123. if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
  124. return 0;
  125. for (i = 0; i < ghes_arr->count; i++) {
  126. struct acpi_hest_header *hdr;
  127. ghes_dev = ghes_arr->ghes_devs[i];
  128. hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data;
  129. if (hdr->source_id == hest_hdr->source_id) {
  130. pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n",
  131. hdr->source_id);
  132. return -EIO;
  133. }
  134. }
  135. ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
  136. if (!ghes_dev)
  137. return -ENOMEM;
  138. rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
  139. if (rc)
  140. goto err;
  141. rc = platform_device_add(ghes_dev);
  142. if (rc)
  143. goto err;
  144. ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
  145. return 0;
  146. err:
  147. platform_device_put(ghes_dev);
  148. return rc;
  149. }
  150. static int __init hest_ghes_dev_register(unsigned int ghes_count)
  151. {
  152. int rc, i;
  153. struct ghes_arr ghes_arr;
  154. ghes_arr.count = 0;
  155. ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
  156. if (!ghes_arr.ghes_devs)
  157. return -ENOMEM;
  158. rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
  159. if (rc)
  160. goto err;
  161. out:
  162. kfree(ghes_arr.ghes_devs);
  163. return rc;
  164. err:
  165. for (i = 0; i < ghes_arr.count; i++)
  166. platform_device_unregister(ghes_arr.ghes_devs[i]);
  167. goto out;
  168. }
  169. static int __init setup_hest_disable(char *str)
  170. {
  171. hest_disable = 1;
  172. return 0;
  173. }
  174. __setup("hest_disable", setup_hest_disable);
  175. void __init acpi_hest_init(void)
  176. {
  177. acpi_status status;
  178. int rc = -ENODEV;
  179. unsigned int ghes_count = 0;
  180. if (hest_disable) {
  181. pr_info(HEST_PFX "Table parsing disabled.\n");
  182. return;
  183. }
  184. if (acpi_disabled)
  185. goto err;
  186. status = acpi_get_table(ACPI_SIG_HEST, 0,
  187. (struct acpi_table_header **)&hest_tab);
  188. if (status == AE_NOT_FOUND) {
  189. pr_info(HEST_PFX "Table not found.\n");
  190. goto err;
  191. } else if (ACPI_FAILURE(status)) {
  192. const char *msg = acpi_format_exception(status);
  193. pr_err(HEST_PFX "Failed to get table, %s\n", msg);
  194. rc = -EINVAL;
  195. goto err;
  196. }
  197. rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
  198. if (rc)
  199. goto err;
  200. rc = hest_ghes_dev_register(ghes_count);
  201. if (!rc) {
  202. pr_info(HEST_PFX "Table parsing has been initialized.\n");
  203. return;
  204. }
  205. err:
  206. hest_disable = 1;
  207. }