]>
Commit | Line | Data |
---|---|---|
9dc96664 HY |
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. | |
9dc96664 HY |
24 | */ |
25 | ||
26 | #include <linux/kernel.h> | |
27 | #include <linux/module.h> | |
28 | #include <linux/init.h> | |
29 | #include <linux/acpi.h> | |
30 | #include <linux/kdebug.h> | |
31 | #include <linux/highmem.h> | |
32 | #include <linux/io.h> | |
7ad6e943 | 33 | #include <linux/platform_device.h> |
9dc96664 HY |
34 | #include <acpi/apei.h> |
35 | ||
36 | #include "apei-internal.h" | |
37 | ||
38 | #define HEST_PFX "HEST: " | |
39 | ||
e931d0da | 40 | int hest_disable; |
9dc96664 HY |
41 | EXPORT_SYMBOL_GPL(hest_disable); |
42 | ||
43 | /* HEST table parsing */ | |
44 | ||
bec4f22a | 45 | static struct acpi_table_hest *__read_mostly hest_tab; |
9dc96664 | 46 | |
bec4f22a | 47 | static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { |
9dc96664 HY |
48 | [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */ |
49 | [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1, | |
50 | [ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi), | |
51 | [ACPI_HEST_TYPE_AER_ROOT_PORT] = sizeof(struct acpi_hest_aer_root), | |
52 | [ACPI_HEST_TYPE_AER_ENDPOINT] = sizeof(struct acpi_hest_aer), | |
53 | [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge), | |
54 | [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic), | |
42aa5604 | 55 | [ACPI_HEST_TYPE_GENERIC_ERROR_V2] = sizeof(struct acpi_hest_generic_v2), |
9dc96664 HY |
56 | }; |
57 | ||
58 | static int hest_esrc_len(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 | struct acpi_hest_ia_corrected *cmc; | |
70 | cmc = (struct acpi_hest_ia_corrected *)hest_hdr; | |
71 | len = sizeof(*cmc) + cmc->num_hardware_banks * | |
72 | sizeof(struct acpi_hest_ia_error_bank); | |
73 | } else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) { | |
74 | struct acpi_hest_ia_machine_check *mc; | |
75 | mc = (struct acpi_hest_ia_machine_check *)hest_hdr; | |
76 | len = sizeof(*mc) + mc->num_hardware_banks * | |
77 | sizeof(struct acpi_hest_ia_error_bank); | |
78 | } | |
79 | BUG_ON(len == -1); | |
80 | ||
81 | return len; | |
82 | }; | |
83 | ||
84 | int apei_hest_parse(apei_hest_func_t func, void *data) | |
85 | { | |
86 | struct acpi_hest_header *hest_hdr; | |
87 | int i, rc, len; | |
88 | ||
a84363d6 | 89 | if (hest_disable || !hest_tab) |
9dc96664 HY |
90 | return -EINVAL; |
91 | ||
92 | hest_hdr = (struct acpi_hest_header *)(hest_tab + 1); | |
93 | for (i = 0; i < hest_tab->error_source_count; i++) { | |
94 | len = hest_esrc_len(hest_hdr); | |
95 | if (!len) { | |
96 | pr_warning(FW_WARN HEST_PFX | |
97 | "Unknown or unused hardware error source " | |
98 | "type: %d for hardware error source: %d.\n", | |
99 | hest_hdr->type, hest_hdr->source_id); | |
100 | return -EINVAL; | |
101 | } | |
102 | if ((void *)hest_hdr + len > | |
103 | (void *)hest_tab + hest_tab->header.length) { | |
104 | pr_warning(FW_BUG HEST_PFX | |
105 | "Table contents overflow for hardware error source: %d.\n", | |
106 | hest_hdr->source_id); | |
107 | return -EINVAL; | |
108 | } | |
109 | ||
110 | rc = func(hest_hdr, data); | |
111 | if (rc) | |
112 | return rc; | |
113 | ||
114 | hest_hdr = (void *)hest_hdr + len; | |
115 | } | |
116 | ||
117 | return 0; | |
118 | } | |
119 | EXPORT_SYMBOL_GPL(apei_hest_parse); | |
120 | ||
c3d1fb56 NR |
121 | /* |
122 | * Check if firmware advertises firmware first mode. We need FF bit to be set | |
123 | * along with a set of MC banks which work in FF mode. | |
124 | */ | |
125 | static int __init hest_parse_cmc(struct acpi_hest_header *hest_hdr, void *data) | |
126 | { | |
9f9a35a7 TN |
127 | if (hest_hdr->type != ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) |
128 | return 0; | |
129 | ||
130 | if (!acpi_disable_cmcff) | |
131 | return !arch_apei_enable_cmcff(hest_hdr, data); | |
132 | ||
133 | return 0; | |
c3d1fb56 NR |
134 | } |
135 | ||
7ad6e943 HY |
136 | struct ghes_arr { |
137 | struct platform_device **ghes_devs; | |
138 | unsigned int count; | |
139 | }; | |
140 | ||
bec4f22a | 141 | static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) |
7ad6e943 HY |
142 | { |
143 | int *count = data; | |
144 | ||
42aa5604 TB |
145 | if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR || |
146 | hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR_V2) | |
7ad6e943 HY |
147 | (*count)++; |
148 | return 0; | |
149 | } | |
150 | ||
bec4f22a | 151 | static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data) |
7ad6e943 | 152 | { |
7ad6e943 HY |
153 | struct platform_device *ghes_dev; |
154 | struct ghes_arr *ghes_arr = data; | |
4d2b2956 | 155 | int rc, i; |
7ad6e943 | 156 | |
42aa5604 TB |
157 | if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR && |
158 | hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR_V2) | |
7ad6e943 | 159 | return 0; |
1dd6b20e JD |
160 | |
161 | if (!((struct acpi_hest_generic *)hest_hdr)->enabled) | |
7ad6e943 | 162 | return 0; |
4d2b2956 HY |
163 | for (i = 0; i < ghes_arr->count; i++) { |
164 | struct acpi_hest_header *hdr; | |
165 | ghes_dev = ghes_arr->ghes_devs[i]; | |
166 | hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data; | |
167 | if (hdr->source_id == hest_hdr->source_id) { | |
168 | pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n", | |
169 | hdr->source_id); | |
170 | return -EIO; | |
171 | } | |
172 | } | |
7ad6e943 HY |
173 | ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id); |
174 | if (!ghes_dev) | |
175 | return -ENOMEM; | |
1dd6b20e JD |
176 | |
177 | rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *)); | |
178 | if (rc) | |
179 | goto err; | |
180 | ||
7ad6e943 HY |
181 | rc = platform_device_add(ghes_dev); |
182 | if (rc) | |
183 | goto err; | |
184 | ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev; | |
185 | ||
186 | return 0; | |
187 | err: | |
188 | platform_device_put(ghes_dev); | |
189 | return rc; | |
190 | } | |
191 | ||
bec4f22a | 192 | static int __init hest_ghes_dev_register(unsigned int ghes_count) |
7ad6e943 HY |
193 | { |
194 | int rc, i; | |
195 | struct ghes_arr ghes_arr; | |
196 | ||
197 | ghes_arr.count = 0; | |
6da2ec56 KC |
198 | ghes_arr.ghes_devs = kmalloc_array(ghes_count, sizeof(void *), |
199 | GFP_KERNEL); | |
7ad6e943 HY |
200 | if (!ghes_arr.ghes_devs) |
201 | return -ENOMEM; | |
202 | ||
203 | rc = apei_hest_parse(hest_parse_ghes, &ghes_arr); | |
204 | if (rc) | |
205 | goto err; | |
206 | out: | |
207 | kfree(ghes_arr.ghes_devs); | |
208 | return rc; | |
209 | err: | |
210 | for (i = 0; i < ghes_arr.count; i++) | |
211 | platform_device_unregister(ghes_arr.ghes_devs[i]); | |
212 | goto out; | |
213 | } | |
214 | ||
9dc96664 HY |
215 | static int __init setup_hest_disable(char *str) |
216 | { | |
e931d0da | 217 | hest_disable = HEST_DISABLED; |
9dc96664 HY |
218 | return 0; |
219 | } | |
220 | ||
221 | __setup("hest_disable", setup_hest_disable); | |
222 | ||
415e12b2 | 223 | void __init acpi_hest_init(void) |
9dc96664 HY |
224 | { |
225 | acpi_status status; | |
226 | int rc = -ENODEV; | |
7ad6e943 | 227 | unsigned int ghes_count = 0; |
9dc96664 | 228 | |
9dc96664 | 229 | if (hest_disable) { |
415e12b2 RW |
230 | pr_info(HEST_PFX "Table parsing disabled.\n"); |
231 | return; | |
9dc96664 HY |
232 | } |
233 | ||
234 | status = acpi_get_table(ACPI_SIG_HEST, 0, | |
235 | (struct acpi_table_header **)&hest_tab); | |
e931d0da PA |
236 | if (status == AE_NOT_FOUND) { |
237 | hest_disable = HEST_NOT_FOUND; | |
238 | return; | |
239 | } else if (ACPI_FAILURE(status)) { | |
9dc96664 HY |
240 | const char *msg = acpi_format_exception(status); |
241 | pr_err(HEST_PFX "Failed to get table, %s\n", msg); | |
242 | rc = -EINVAL; | |
243 | goto err; | |
244 | } | |
245 | ||
9f9a35a7 TN |
246 | rc = apei_hest_parse(hest_parse_cmc, NULL); |
247 | if (rc) | |
248 | goto err; | |
c3d1fb56 | 249 | |
b6a95016 HY |
250 | if (!ghes_disable) { |
251 | rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count); | |
252 | if (rc) | |
253 | goto err; | |
254 | rc = hest_ghes_dev_register(ghes_count); | |
255 | if (rc) | |
256 | goto err; | |
415e12b2 | 257 | } |
9dc96664 | 258 | |
b6a95016 HY |
259 | pr_info(HEST_PFX "Table parsing has been initialized.\n"); |
260 | return; | |
9dc96664 | 261 | err: |
e931d0da | 262 | hest_disable = HEST_DISABLED; |
9dc96664 | 263 | } |