0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <linux/kernel.h>
0023 #include <linux/module.h>
0024 #include <linux/init.h>
0025 #include <linux/acpi.h>
0026 #include <linux/io.h>
0027
0028 #include "apei-internal.h"
0029
0030 #undef pr_fmt
0031 #define pr_fmt(fmt) "BERT: " fmt
0032
0033 #define ACPI_BERT_PRINT_MAX_RECORDS 5
0034 #define ACPI_BERT_PRINT_MAX_LEN 1024
0035
0036 static int bert_disable;
0037
0038
0039
0040
0041
0042
0043
0044
0045 static void __init bert_print_all(struct acpi_bert_region *region,
0046 unsigned int region_len)
0047 {
0048 struct acpi_hest_generic_status *estatus =
0049 (struct acpi_hest_generic_status *)region;
0050 int remain = region_len;
0051 int printed = 0, skipped = 0;
0052 u32 estatus_len;
0053
0054 while (remain >= sizeof(struct acpi_bert_region)) {
0055 estatus_len = cper_estatus_len(estatus);
0056 if (remain < estatus_len) {
0057 pr_err(FW_BUG "Truncated status block (length: %u).\n",
0058 estatus_len);
0059 break;
0060 }
0061
0062
0063 if (!estatus->block_status)
0064 break;
0065
0066 if (cper_estatus_check(estatus)) {
0067 pr_err(FW_BUG "Invalid error record.\n");
0068 break;
0069 }
0070
0071 if (estatus_len < ACPI_BERT_PRINT_MAX_LEN &&
0072 printed < ACPI_BERT_PRINT_MAX_RECORDS) {
0073 pr_info_once("Error records from previous boot:\n");
0074 cper_estatus_print(KERN_INFO HW_ERR, estatus);
0075 printed++;
0076 } else {
0077 skipped++;
0078 }
0079
0080
0081
0082
0083
0084
0085 estatus->block_status = 0;
0086
0087 estatus = (void *)estatus + estatus_len;
0088 remain -= estatus_len;
0089 }
0090
0091 if (skipped)
0092 pr_info(HW_ERR "Skipped %d error records\n", skipped);
0093 }
0094
0095 static int __init setup_bert_disable(char *str)
0096 {
0097 bert_disable = 1;
0098
0099 return 1;
0100 }
0101 __setup("bert_disable", setup_bert_disable);
0102
0103 static int __init bert_check_table(struct acpi_table_bert *bert_tab)
0104 {
0105 if (bert_tab->header.length < sizeof(struct acpi_table_bert) ||
0106 bert_tab->region_length < sizeof(struct acpi_bert_region))
0107 return -EINVAL;
0108
0109 return 0;
0110 }
0111
0112 static int __init bert_init(void)
0113 {
0114 struct apei_resources bert_resources;
0115 struct acpi_bert_region *boot_error_region;
0116 struct acpi_table_bert *bert_tab;
0117 unsigned int region_len;
0118 acpi_status status;
0119 int rc = 0;
0120
0121 if (acpi_disabled)
0122 return 0;
0123
0124 if (bert_disable) {
0125 pr_info("Boot Error Record Table support is disabled.\n");
0126 return 0;
0127 }
0128
0129 status = acpi_get_table(ACPI_SIG_BERT, 0, (struct acpi_table_header **)&bert_tab);
0130 if (status == AE_NOT_FOUND)
0131 return 0;
0132
0133 if (ACPI_FAILURE(status)) {
0134 pr_err("get table failed, %s.\n", acpi_format_exception(status));
0135 return -EINVAL;
0136 }
0137
0138 rc = bert_check_table(bert_tab);
0139 if (rc) {
0140 pr_err(FW_BUG "table invalid.\n");
0141 goto out_put_bert_tab;
0142 }
0143
0144 region_len = bert_tab->region_length;
0145 apei_resources_init(&bert_resources);
0146 rc = apei_resources_add(&bert_resources, bert_tab->address,
0147 region_len, true);
0148 if (rc)
0149 goto out_put_bert_tab;
0150 rc = apei_resources_request(&bert_resources, "APEI BERT");
0151 if (rc)
0152 goto out_fini;
0153 boot_error_region = ioremap_cache(bert_tab->address, region_len);
0154 if (boot_error_region) {
0155 bert_print_all(boot_error_region, region_len);
0156 iounmap(boot_error_region);
0157 } else {
0158 rc = -ENOMEM;
0159 }
0160
0161 apei_resources_release(&bert_resources);
0162 out_fini:
0163 apei_resources_fini(&bert_resources);
0164 out_put_bert_tab:
0165 acpi_put_table((struct acpi_table_header *)bert_tab);
0166
0167 return rc;
0168 }
0169
0170 late_initcall(bert_init);