0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/module.h>
0012 #include <linux/init.h>
0013 #include <linux/slab.h>
0014 #include <linux/interrupt.h>
0015 #include <linux/io.h>
0016 #include <linux/edac.h>
0017
0018 #include "edac_module.h"
0019
0020 #include <asm/octeon/cvmx.h>
0021 #include <asm/mipsregs.h>
0022
0023 extern int register_co_cache_error_notifier(struct notifier_block *nb);
0024 extern int unregister_co_cache_error_notifier(struct notifier_block *nb);
0025
0026 extern unsigned long long cache_err_dcache[NR_CPUS];
0027
0028 struct co_cache_error {
0029 struct notifier_block notifier;
0030 struct edac_device_ctl_info *ed;
0031 };
0032
0033
0034
0035
0036
0037
0038 static int co_cache_error_event(struct notifier_block *this,
0039 unsigned long event, void *ptr)
0040 {
0041 struct co_cache_error *p = container_of(this, struct co_cache_error,
0042 notifier);
0043
0044 unsigned int core = cvmx_get_core_num();
0045 unsigned int cpu = smp_processor_id();
0046 u64 icache_err = read_octeon_c0_icacheerr();
0047 u64 dcache_err;
0048
0049 if (event) {
0050 dcache_err = cache_err_dcache[core];
0051 cache_err_dcache[core] = 0;
0052 } else {
0053 dcache_err = read_octeon_c0_dcacheerr();
0054 }
0055
0056 if (icache_err & 1) {
0057 edac_device_printk(p->ed, KERN_ERR,
0058 "CacheErr (Icache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
0059 (unsigned long long)icache_err, core, cpu,
0060 read_c0_errorepc());
0061 write_octeon_c0_icacheerr(0);
0062 edac_device_handle_ce(p->ed, cpu, 1, "icache");
0063 }
0064 if (dcache_err & 1) {
0065 edac_device_printk(p->ed, KERN_ERR,
0066 "CacheErr (Dcache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
0067 (unsigned long long)dcache_err, core, cpu,
0068 read_c0_errorepc());
0069 if (event)
0070 edac_device_handle_ue(p->ed, cpu, 0, "dcache");
0071 else
0072 edac_device_handle_ce(p->ed, cpu, 0, "dcache");
0073
0074
0075 if (OCTEON_IS_OCTEON2())
0076 write_octeon_c0_dcacheerr(1);
0077 else
0078 write_octeon_c0_dcacheerr(0);
0079 }
0080
0081 return NOTIFY_STOP;
0082 }
0083
0084 static int co_cache_error_probe(struct platform_device *pdev)
0085 {
0086 struct co_cache_error *p = devm_kzalloc(&pdev->dev, sizeof(*p),
0087 GFP_KERNEL);
0088 if (!p)
0089 return -ENOMEM;
0090
0091 p->notifier.notifier_call = co_cache_error_event;
0092 platform_set_drvdata(pdev, p);
0093
0094 p->ed = edac_device_alloc_ctl_info(0, "cpu", num_possible_cpus(),
0095 "cache", 2, 0, NULL, 0,
0096 edac_device_alloc_index());
0097 if (!p->ed)
0098 goto err;
0099
0100 p->ed->dev = &pdev->dev;
0101
0102 p->ed->dev_name = dev_name(&pdev->dev);
0103
0104 p->ed->mod_name = "octeon-cpu";
0105 p->ed->ctl_name = "cache";
0106
0107 if (edac_device_add_device(p->ed)) {
0108 pr_err("%s: edac_device_add_device() failed\n", __func__);
0109 goto err1;
0110 }
0111
0112 register_co_cache_error_notifier(&p->notifier);
0113
0114 return 0;
0115
0116 err1:
0117 edac_device_free_ctl_info(p->ed);
0118 err:
0119 return -ENXIO;
0120 }
0121
0122 static int co_cache_error_remove(struct platform_device *pdev)
0123 {
0124 struct co_cache_error *p = platform_get_drvdata(pdev);
0125
0126 unregister_co_cache_error_notifier(&p->notifier);
0127 edac_device_del_device(&pdev->dev);
0128 edac_device_free_ctl_info(p->ed);
0129 return 0;
0130 }
0131
0132 static struct platform_driver co_cache_error_driver = {
0133 .probe = co_cache_error_probe,
0134 .remove = co_cache_error_remove,
0135 .driver = {
0136 .name = "octeon_pc_edac",
0137 }
0138 };
0139 module_platform_driver(co_cache_error_driver);
0140
0141 MODULE_LICENSE("GPL");
0142 MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");