2 * APEI Generic Hardware Error Source support
4 * Generic Hardware Error Source provides a way to report platform
5 * hardware errors (such as that from chipset). It works in so called
6 * "Firmware First" mode, that is, hardware errors are reported to
7 * firmware firstly, then reported to Linux by firmware. This way,
8 * some non-standard hardware error registers or non-standard hardware
9 * link can be checked by firmware to produce more hardware error
10 * information for Linux.
12 * For more information about Generic Hardware Error Source, please
13 * refer to ACPI Specification version 4.0, section 17.3.2.6
15 * Now, only SCI notification type and memory errors are
16 * supported. More notification type and hardware error type will be
19 * Copyright 2010 Intel Corp.
20 * Author: Huang Ying <ying.huang@intel.com>
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License version
24 * 2 as published by the Free Software Foundation;
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/init.h>
39 #include <linux/acpi.h>
41 #include <linux/interrupt.h>
42 #include <linux/cper.h>
43 #include <linux/kdebug.h>
44 #include <linux/platform_device.h>
45 #include <linux/mutex.h>
46 #include <acpi/apei.h>
47 #include <acpi/atomicio.h>
51 #include "apei-internal.h"
53 #define GHES_PFX "GHES: "
55 #define GHES_ESTATUS_MAX_SIZE 65536
58 * One struct ghes is created for each generic hardware error
61 * It provides the context for APEI hardware error timer/IRQ/SCI/NMI
62 * handler. Handler for one generic hardware error source is only
63 * triggered after the previous one is done. So handler can uses
64 * struct ghes without locking.
66 * estatus: memory buffer for error status block, allocated during
69 #define GHES_TO_CLEAR 0x0001
72 struct acpi_hest_generic *generic;
73 struct acpi_hest_generic_status *estatus;
74 struct list_head list;
80 * Error source lists, one list for each notification method. The
81 * members in lists are struct ghes.
83 * The list members are only added in HEST parsing and deleted during
84 * module_exit, that is, single-threaded. So no lock is needed for
87 * But the mutual exclusion is needed between members adding/deleting
88 * and timer/IRQ/SCI/NMI handler, which may traverse the list. RCU is
91 static LIST_HEAD(ghes_sci);
92 static DEFINE_MUTEX(ghes_list_mutex);
94 static struct ghes *ghes_new(struct acpi_hest_generic *generic)
97 unsigned int error_block_length;
100 ghes = kzalloc(sizeof(*ghes), GFP_KERNEL);
102 return ERR_PTR(-ENOMEM);
103 ghes->generic = generic;
104 INIT_LIST_HEAD(&ghes->list);
105 rc = acpi_pre_map_gar(&generic->error_status_address);
108 error_block_length = generic->error_block_length;
109 if (error_block_length > GHES_ESTATUS_MAX_SIZE) {
110 pr_warning(FW_WARN GHES_PFX
111 "Error status block length is too long: %u for "
112 "generic hardware error source: %d.\n",
113 error_block_length, generic->header.source_id);
114 error_block_length = GHES_ESTATUS_MAX_SIZE;
116 ghes->estatus = kmalloc(error_block_length, GFP_KERNEL);
117 if (!ghes->estatus) {
125 acpi_post_unmap_gar(&generic->error_status_address);
131 static void ghes_fini(struct ghes *ghes)
133 kfree(ghes->estatus);
134 acpi_post_unmap_gar(&ghes->generic->error_status_address);
139 GHES_SEV_CORRECTED = 0x1,
140 GHES_SEV_RECOVERABLE = 0x2,
141 GHES_SEV_PANIC = 0x3,
144 static inline int ghes_severity(int severity)
147 case CPER_SEV_INFORMATIONAL:
149 case CPER_SEV_CORRECTED:
150 return GHES_SEV_CORRECTED;
151 case CPER_SEV_RECOVERABLE:
152 return GHES_SEV_RECOVERABLE;
154 return GHES_SEV_PANIC;
156 /* Unkown, go panic */
157 return GHES_SEV_PANIC;
161 /* SCI handler run in work queue, so ioremap can be used here */
162 static int ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len,
167 vaddr = ioremap_cache(paddr, len);
171 memcpy(buffer, vaddr, len);
173 memcpy(vaddr, buffer, len);
179 static int ghes_read_estatus(struct ghes *ghes, int silent)
181 struct acpi_hest_generic *g = ghes->generic;
186 rc = acpi_atomic_read(&buf_paddr, &g->error_status_address);
188 if (!silent && printk_ratelimit())
189 pr_warning(FW_WARN GHES_PFX
190 "Failed to read error status block address for hardware error source: %d.\n",
191 g->header.source_id);
197 rc = ghes_copy_tofrom_phys(ghes->estatus, buf_paddr,
198 sizeof(*ghes->estatus), 1);
201 if (!ghes->estatus->block_status)
204 ghes->buffer_paddr = buf_paddr;
205 ghes->flags |= GHES_TO_CLEAR;
208 len = apei_estatus_len(ghes->estatus);
209 if (len < sizeof(*ghes->estatus))
211 if (len > ghes->generic->error_block_length)
213 if (apei_estatus_check_header(ghes->estatus))
215 rc = ghes_copy_tofrom_phys(ghes->estatus + 1,
216 buf_paddr + sizeof(*ghes->estatus),
217 len - sizeof(*ghes->estatus), 1);
220 if (apei_estatus_check(ghes->estatus))
226 pr_warning(FW_WARN GHES_PFX
227 "Failed to read error status block!\n");
231 static void ghes_clear_estatus(struct ghes *ghes)
233 ghes->estatus->block_status = 0;
234 if (!(ghes->flags & GHES_TO_CLEAR))
236 ghes_copy_tofrom_phys(ghes->estatus, ghes->buffer_paddr,
237 sizeof(ghes->estatus->block_status), 0);
238 ghes->flags &= ~GHES_TO_CLEAR;
241 static void ghes_do_proc(struct ghes *ghes)
243 int sev, processed = 0;
244 struct acpi_hest_generic_data *gdata;
246 sev = ghes_severity(ghes->estatus->error_severity);
247 apei_estatus_for_each_section(ghes->estatus, gdata) {
248 #ifdef CONFIG_X86_MCE
249 if (!uuid_le_cmp(*(uuid_le *)gdata->section_type,
250 CPER_SEC_PLATFORM_MEM)) {
251 apei_mce_report_mem_error(
252 sev == GHES_SEV_CORRECTED,
253 (struct cper_sec_mem_err *)(gdata+1));
259 if (!processed && printk_ratelimit())
261 "Unknown error record from generic hardware error source: %d\n",
262 ghes->generic->header.source_id);
265 static int ghes_proc(struct ghes *ghes)
269 rc = ghes_read_estatus(ghes, 0);
275 ghes_clear_estatus(ghes);
279 static int ghes_notify_sci(struct notifier_block *this,
280 unsigned long event, void *data)
283 int ret = NOTIFY_DONE;
286 list_for_each_entry_rcu(ghes, &ghes_sci, list) {
287 if (!ghes_proc(ghes))
295 static struct notifier_block ghes_notifier_sci = {
296 .notifier_call = ghes_notify_sci,
299 static int __devinit ghes_probe(struct platform_device *ghes_dev)
301 struct acpi_hest_generic *generic;
302 struct ghes *ghes = NULL;
305 generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data;
306 if (!generic->enabled)
309 if (generic->error_block_length <
310 sizeof(struct acpi_hest_generic_status)) {
311 pr_warning(FW_BUG GHES_PFX
312 "Invalid error block length: %u for generic hardware error source: %d\n",
313 generic->error_block_length,
314 generic->header.source_id);
317 if (generic->records_to_preallocate == 0) {
318 pr_warning(FW_BUG GHES_PFX
319 "Invalid records to preallocate: %u for generic hardware error source: %d\n",
320 generic->records_to_preallocate,
321 generic->header.source_id);
324 ghes = ghes_new(generic);
330 if (generic->notify.type == ACPI_HEST_NOTIFY_SCI) {
331 mutex_lock(&ghes_list_mutex);
332 if (list_empty(&ghes_sci))
333 register_acpi_hed_notifier(&ghes_notifier_sci);
334 list_add_rcu(&ghes->list, &ghes_sci);
335 mutex_unlock(&ghes_list_mutex);
337 unsigned char *notify = NULL;
339 switch (generic->notify.type) {
340 case ACPI_HEST_NOTIFY_POLLED:
343 case ACPI_HEST_NOTIFY_EXTERNAL:
344 case ACPI_HEST_NOTIFY_LOCAL:
347 case ACPI_HEST_NOTIFY_NMI:
353 "Generic hardware error source: %d notified via %s is not supported!\n",
354 generic->header.source_id, notify);
356 pr_warning(FW_WARN GHES_PFX
357 "Unknown notification type: %u for generic hardware error source: %d\n",
358 generic->notify.type, generic->header.source_id);
363 platform_set_drvdata(ghes_dev, ghes);
374 static int __devexit ghes_remove(struct platform_device *ghes_dev)
377 struct acpi_hest_generic *generic;
379 ghes = platform_get_drvdata(ghes_dev);
380 generic = ghes->generic;
382 switch (generic->notify.type) {
383 case ACPI_HEST_NOTIFY_SCI:
384 mutex_lock(&ghes_list_mutex);
385 list_del_rcu(&ghes->list);
386 if (list_empty(&ghes_sci))
387 unregister_acpi_hed_notifier(&ghes_notifier_sci);
388 mutex_unlock(&ghes_list_mutex);
399 platform_set_drvdata(ghes_dev, NULL);
404 static struct platform_driver ghes_platform_driver = {
407 .owner = THIS_MODULE,
410 .remove = ghes_remove,
413 static int __init ghes_init(void)
419 pr_info(GHES_PFX "HEST is not enabled!\n");
423 return platform_driver_register(&ghes_platform_driver);
426 static void __exit ghes_exit(void)
428 platform_driver_unregister(&ghes_platform_driver);
431 module_init(ghes_init);
432 module_exit(ghes_exit);
434 MODULE_AUTHOR("Huang Ying");
435 MODULE_DESCRIPTION("APEI Generic Hardware Error Source support");
436 MODULE_LICENSE("GPL");
437 MODULE_ALIAS("platform:GHES");