0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/edac.h>
0011 #include <linux/platform_device.h>
0012 #include "edac_module.h"
0013 #include <soc/sifive/sifive_l2_cache.h>
0014
0015 #define DRVNAME "sifive_edac"
0016
0017 struct sifive_edac_priv {
0018 struct notifier_block notifier;
0019 struct edac_device_ctl_info *dci;
0020 };
0021
0022
0023
0024
0025
0026
0027 static
0028 int ecc_err_event(struct notifier_block *this, unsigned long event, void *ptr)
0029 {
0030 const char *msg = (char *)ptr;
0031 struct sifive_edac_priv *p;
0032
0033 p = container_of(this, struct sifive_edac_priv, notifier);
0034
0035 if (event == SIFIVE_L2_ERR_TYPE_UE)
0036 edac_device_handle_ue(p->dci, 0, 0, msg);
0037 else if (event == SIFIVE_L2_ERR_TYPE_CE)
0038 edac_device_handle_ce(p->dci, 0, 0, msg);
0039
0040 return NOTIFY_OK;
0041 }
0042
0043 static int ecc_register(struct platform_device *pdev)
0044 {
0045 struct sifive_edac_priv *p;
0046
0047 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
0048 if (!p)
0049 return -ENOMEM;
0050
0051 p->notifier.notifier_call = ecc_err_event;
0052 platform_set_drvdata(pdev, p);
0053
0054 p->dci = edac_device_alloc_ctl_info(0, "sifive_ecc", 1, "sifive_ecc",
0055 1, 1, NULL, 0,
0056 edac_device_alloc_index());
0057 if (!p->dci)
0058 return -ENOMEM;
0059
0060 p->dci->dev = &pdev->dev;
0061 p->dci->mod_name = "Sifive ECC Manager";
0062 p->dci->ctl_name = dev_name(&pdev->dev);
0063 p->dci->dev_name = dev_name(&pdev->dev);
0064
0065 if (edac_device_add_device(p->dci)) {
0066 dev_err(p->dci->dev, "failed to register with EDAC core\n");
0067 goto err;
0068 }
0069
0070 register_sifive_l2_error_notifier(&p->notifier);
0071
0072 return 0;
0073
0074 err:
0075 edac_device_free_ctl_info(p->dci);
0076
0077 return -ENXIO;
0078 }
0079
0080 static int ecc_unregister(struct platform_device *pdev)
0081 {
0082 struct sifive_edac_priv *p = platform_get_drvdata(pdev);
0083
0084 unregister_sifive_l2_error_notifier(&p->notifier);
0085 edac_device_del_device(&pdev->dev);
0086 edac_device_free_ctl_info(p->dci);
0087
0088 return 0;
0089 }
0090
0091 static struct platform_device *sifive_pdev;
0092
0093 static int __init sifive_edac_init(void)
0094 {
0095 int ret;
0096
0097 sifive_pdev = platform_device_register_simple(DRVNAME, 0, NULL, 0);
0098 if (IS_ERR(sifive_pdev))
0099 return PTR_ERR(sifive_pdev);
0100
0101 ret = ecc_register(sifive_pdev);
0102 if (ret)
0103 platform_device_unregister(sifive_pdev);
0104
0105 return ret;
0106 }
0107
0108 static void __exit sifive_edac_exit(void)
0109 {
0110 ecc_unregister(sifive_pdev);
0111 platform_device_unregister(sifive_pdev);
0112 }
0113
0114 module_init(sifive_edac_init);
0115 module_exit(sifive_edac_exit);
0116
0117 MODULE_AUTHOR("SiFive Inc.");
0118 MODULE_DESCRIPTION("SiFive platform EDAC driver");
0119 MODULE_LICENSE("GPL v2");