xref: /openbmc/linux/drivers/acpi/nfit/mce.c (revision 1491eaf9)
1 /*
2  * NFIT - Machine Check Handler
3  *
4  * Copyright(c) 2013-2016 Intel Corporation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  */
15 #include <linux/notifier.h>
16 #include <linux/acpi.h>
17 #include <asm/mce.h>
18 #include "nfit.h"
19 
20 static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
21 			void *data)
22 {
23 	struct mce *mce = (struct mce *)data;
24 	struct acpi_nfit_desc *acpi_desc;
25 	struct nfit_spa *nfit_spa;
26 
27 	/* We only care about memory errors */
28 	if (!(mce->status & MCACOD))
29 		return NOTIFY_DONE;
30 
31 	/*
32 	 * mce->addr contains the physical addr accessed that caused the
33 	 * machine check. We need to walk through the list of NFITs, and see
34 	 * if any of them matches that address, and only then start a scrub.
35 	 */
36 	mutex_lock(&acpi_desc_lock);
37 	list_for_each_entry(acpi_desc, &acpi_descs, list) {
38 		struct device *dev = acpi_desc->dev;
39 		int found_match = 0;
40 
41 		mutex_lock(&acpi_desc->init_mutex);
42 		list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
43 			struct acpi_nfit_system_address *spa = nfit_spa->spa;
44 
45 			if (nfit_spa_type(spa) != NFIT_SPA_PM)
46 				continue;
47 			/* find the spa that covers the mce addr */
48 			if (spa->address > mce->addr)
49 				continue;
50 			if ((spa->address + spa->length - 1) < mce->addr)
51 				continue;
52 			found_match = 1;
53 			dev_dbg(dev, "%s: addr in SPA %d (0x%llx, 0x%llx)\n",
54 				__func__, spa->range_index, spa->address,
55 				spa->length);
56 			/*
57 			 * We can break at the first match because we're going
58 			 * to rescan all the SPA ranges. There shouldn't be any
59 			 * aliasing anyway.
60 			 */
61 			break;
62 		}
63 		mutex_unlock(&acpi_desc->init_mutex);
64 
65 		/*
66 		 * We can ignore an -EBUSY here because if an ARS is already
67 		 * in progress, just let that be the last authoritative one
68 		 */
69 		if (found_match)
70 			acpi_nfit_ars_rescan(acpi_desc);
71 	}
72 
73 	mutex_unlock(&acpi_desc_lock);
74 	return NOTIFY_DONE;
75 }
76 
77 static struct notifier_block nfit_mce_dec = {
78 	.notifier_call	= nfit_handle_mce,
79 };
80 
81 void nfit_mce_register(void)
82 {
83 	mce_register_decode_chain(&nfit_mce_dec);
84 }
85 
86 void nfit_mce_unregister(void)
87 {
88 	mce_unregister_decode_chain(&nfit_mce_dec);
89 }
90