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, see <http://www.gnu.org/licenses/>.
27 */
28
29 #include <xen/errno.h>
30 #include <xen/init.h>
31 #include <xen/kernel.h>
32 #include <xen/mm.h>
33 #include <xen/pfn.h>
34 #include <acpi/acpi.h>
35 #include <acpi/apei.h>
36
37 #include "apei-internal.h"
38
39 #define HEST_PFX "HEST: "
40
41 static bool_t hest_disable;
42 boolean_param("hest_disable", hest_disable);
43
44 /* HEST table parsing */
45
46 static struct acpi_table_hest *__read_mostly hest_tab;
47
48 static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
49 [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */
50 [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
51 [ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi),
52 [ACPI_HEST_TYPE_AER_ROOT_PORT] = sizeof(struct acpi_hest_aer_root),
53 [ACPI_HEST_TYPE_AER_ENDPOINT] = sizeof(struct acpi_hest_aer),
54 [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
55 [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
56 };
57
hest_esrc_len(const struct acpi_hest_header * hest_hdr)58 static int hest_esrc_len(const struct acpi_hest_header *hest_hdr)
59 {
60 u16 hest_type = hest_hdr->type;
61 int len;
62
63 if (hest_type >= ACPI_HEST_TYPE_RESERVED)
64 return 0;
65
66 len = hest_esrc_len_tab[hest_type];
67
68 if (hest_type == ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) {
69 const struct acpi_hest_ia_corrected *cmc =
70 container_of(hest_hdr,
71 const struct acpi_hest_ia_corrected,
72 header);
73
74 len = sizeof(*cmc) + cmc->num_hardware_banks *
75 sizeof(struct acpi_hest_ia_error_bank);
76 } else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) {
77 const struct acpi_hest_ia_machine_check *mc =
78 container_of(hest_hdr,
79 const struct acpi_hest_ia_machine_check,
80 header);
81
82 len = sizeof(*mc) + mc->num_hardware_banks *
83 sizeof(struct acpi_hest_ia_error_bank);
84 }
85 BUG_ON(len == -1);
86
87 return len;
88 };
89
apei_hest_parse(apei_hest_func_t func,void * data)90 int apei_hest_parse(apei_hest_func_t func, void *data)
91 {
92 struct acpi_hest_header *hest_hdr;
93 int i, rc, len;
94
95 if (hest_disable || !hest_tab)
96 return -EINVAL;
97
98 hest_hdr = (struct acpi_hest_header *)(hest_tab + 1);
99 for (i = 0; i < hest_tab->error_source_count; i++) {
100 len = hest_esrc_len(hest_hdr);
101 if (!len) {
102 printk(XENLOG_WARNING HEST_PFX
103 "Unknown or unused hardware error source "
104 "type: %d for hardware error source: %d\n",
105 hest_hdr->type, hest_hdr->source_id);
106 return -EINVAL;
107 }
108 if ((void *)hest_hdr + len >
109 (void *)hest_tab + hest_tab->header.length) {
110 printk(XENLOG_WARNING HEST_PFX
111 "Table contents overflow for hardware error source: %d\n",
112 hest_hdr->source_id);
113 return -EINVAL;
114 }
115
116 rc = func(hest_hdr, data);
117 if (rc)
118 return rc;
119
120 hest_hdr = (void *)hest_hdr + len;
121 }
122
123 return 0;
124 }
125
126 /*
127 * Check if firmware advertises firmware first mode. We need FF bit to be set
128 * along with a set of MC banks which work in FF mode.
129 */
hest_parse_cmc(const struct acpi_hest_header * hest_hdr,void * data)130 static int __init hest_parse_cmc(const struct acpi_hest_header *hest_hdr,
131 void *data)
132 {
133 #ifdef CONFIG_X86_MCE
134 unsigned int i;
135 const struct acpi_hest_ia_corrected *cmc;
136 const struct acpi_hest_ia_error_bank *mc_bank;
137
138 if (hest_hdr->type != ACPI_HEST_TYPE_IA32_CORRECTED_CHECK)
139 return 0;
140
141 cmc = container_of(hest_hdr, const struct acpi_hest_ia_corrected, header);
142 if (!cmc->enabled)
143 return 0;
144
145 /*
146 * We expect HEST to provide a list of MC banks that report errors
147 * in firmware first mode. Otherwise, return non-zero value to
148 * indicate that we are done parsing HEST.
149 */
150 if (!(cmc->flags & ACPI_HEST_FIRMWARE_FIRST) || !cmc->num_hardware_banks)
151 return 1;
152
153 printk(XENLOG_INFO HEST_PFX "Enabling Firmware First mode for corrected errors.\n");
154
155 mc_bank = (const struct acpi_hest_ia_error_bank *)(cmc + 1);
156 for (i = 0; i < cmc->num_hardware_banks; i++, mc_bank++)
157 mce_disable_bank(mc_bank->bank_number);
158 #else
159 # define acpi_disable_cmcff 1
160 #endif
161
162 return 1;
163 }
164
acpi_hest_init(void)165 void __init acpi_hest_init(void)
166 {
167 acpi_status status;
168 acpi_physical_address hest_addr;
169 acpi_native_uint hest_len;
170
171 if (acpi_disabled)
172 return;
173
174 if (hest_disable) {
175 printk(XENLOG_INFO HEST_PFX "Table parsing disabled.\n");
176 return;
177 }
178
179 status = acpi_get_table_phys(ACPI_SIG_HEST, 0, &hest_addr, &hest_len);
180 if (status == AE_NOT_FOUND)
181 goto err;
182 if (ACPI_FAILURE(status)) {
183 printk(XENLOG_ERR HEST_PFX "Failed to get table, %s\n",
184 acpi_format_exception(status));
185 goto err;
186 }
187 map_pages_to_xen((unsigned long)__va(hest_addr), PFN_DOWN(hest_addr),
188 PFN_UP(hest_addr + hest_len) - PFN_DOWN(hest_addr),
189 PAGE_HYPERVISOR);
190 hest_tab = __va(hest_addr);
191
192 if (!acpi_disable_cmcff)
193 apei_hest_parse(hest_parse_cmc, NULL);
194
195 printk(XENLOG_INFO HEST_PFX "Table parsing has been initialized\n");
196 return;
197 err:
198 hest_disable = 1;
199 }
200