bert.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * APEI Boot Error Record Table (BERT) support
  3. *
  4. * Copyright 2011 Intel Corp.
  5. * Author: Huang Ying <ying.huang@intel.com>
  6. *
  7. * Under normal circumstances, when a hardware error occurs, the error
  8. * handler receives control and processes the error. This gives OSPM a
  9. * chance to process the error condition, report it, and optionally attempt
  10. * recovery. In some cases, the system is unable to process an error.
  11. * For example, system firmware or a management controller may choose to
  12. * reset the system or the system might experience an uncontrolled crash
  13. * or reset.The boot error source is used to report unhandled errors that
  14. * occurred in a previous boot. This mechanism is described in the BERT
  15. * table.
  16. *
  17. * For more information about BERT, please refer to ACPI Specification
  18. * version 4.0, section 17.3.1
  19. *
  20. * This file is licensed under GPLv2.
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/acpi.h>
  27. #include <linux/io.h>
  28. #include "apei-internal.h"
  29. #undef pr_fmt
  30. #define pr_fmt(fmt) "BERT: " fmt
  31. static int bert_disable;
  32. static void __init bert_print_all(struct acpi_bert_region *region,
  33. unsigned int region_len)
  34. {
  35. struct acpi_hest_generic_status *estatus =
  36. (struct acpi_hest_generic_status *)region;
  37. int remain = region_len;
  38. u32 estatus_len;
  39. if (!estatus->block_status)
  40. return;
  41. while (remain > sizeof(struct acpi_bert_region)) {
  42. if (cper_estatus_check(estatus)) {
  43. pr_err(FW_BUG "Invalid error record.\n");
  44. return;
  45. }
  46. estatus_len = cper_estatus_len(estatus);
  47. if (remain < estatus_len) {
  48. pr_err(FW_BUG "Truncated status block (length: %u).\n",
  49. estatus_len);
  50. return;
  51. }
  52. pr_info_once("Error records from previous boot:\n");
  53. cper_estatus_print(KERN_INFO HW_ERR, estatus);
  54. /*
  55. * Because the boot error source is "one-time polled" type,
  56. * clear Block Status of current Generic Error Status Block,
  57. * once it's printed.
  58. */
  59. estatus->block_status = 0;
  60. estatus = (void *)estatus + estatus_len;
  61. /* No more error records. */
  62. if (!estatus->block_status)
  63. return;
  64. remain -= estatus_len;
  65. }
  66. }
  67. static int __init setup_bert_disable(char *str)
  68. {
  69. bert_disable = 1;
  70. return 0;
  71. }
  72. __setup("bert_disable", setup_bert_disable);
  73. static int __init bert_check_table(struct acpi_table_bert *bert_tab)
  74. {
  75. if (bert_tab->header.length < sizeof(struct acpi_table_bert) ||
  76. bert_tab->region_length < sizeof(struct acpi_bert_region))
  77. return -EINVAL;
  78. return 0;
  79. }
  80. static int __init bert_init(void)
  81. {
  82. struct acpi_bert_region *boot_error_region;
  83. struct acpi_table_bert *bert_tab;
  84. unsigned int region_len;
  85. acpi_status status;
  86. int rc = 0;
  87. if (acpi_disabled)
  88. return 0;
  89. if (bert_disable) {
  90. pr_info("Boot Error Record Table support is disabled.\n");
  91. return 0;
  92. }
  93. status = acpi_get_table(ACPI_SIG_BERT, 0, (struct acpi_table_header **)&bert_tab);
  94. if (status == AE_NOT_FOUND)
  95. return 0;
  96. if (ACPI_FAILURE(status)) {
  97. pr_err("get table failed, %s.\n", acpi_format_exception(status));
  98. return -EINVAL;
  99. }
  100. rc = bert_check_table(bert_tab);
  101. if (rc) {
  102. pr_err(FW_BUG "table invalid.\n");
  103. return rc;
  104. }
  105. region_len = bert_tab->region_length;
  106. if (!request_mem_region(bert_tab->address, region_len, "APEI BERT")) {
  107. pr_err("Can't request iomem region <%016llx-%016llx>.\n",
  108. (unsigned long long)bert_tab->address,
  109. (unsigned long long)bert_tab->address + region_len - 1);
  110. return -EIO;
  111. }
  112. boot_error_region = ioremap_cache(bert_tab->address, region_len);
  113. if (boot_error_region) {
  114. bert_print_all(boot_error_region, region_len);
  115. iounmap(boot_error_region);
  116. } else {
  117. rc = -ENOMEM;
  118. }
  119. release_mem_region(bert_tab->address, region_len);
  120. return rc;
  121. }
  122. late_initcall(bert_init);