2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2009 Wind River Systems,
7 * written by Ralf Baechle <ralf@linux-mips.org>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/interrupt.h>
14 #include <linux/edac.h>
16 #include "edac_core.h"
17 #include "edac_module.h"
19 #include <asm/octeon/cvmx.h>
20 #include <asm/mipsregs.h>
22 #define EDAC_MOD_STR "octeon"
24 extern int register_co_cache_error_notifier(struct notifier_block
*nb
);
25 extern int unregister_co_cache_error_notifier(struct notifier_block
*nb
);
27 extern unsigned long long cache_err_dcache
[NR_CPUS
];
29 static struct edac_device_ctl_info
*ed_cavium
;
32 * EDAC CPU cache error callback
36 static int co_cache_error_event(struct notifier_block
*this,
37 unsigned long event
, void *ptr
)
39 unsigned int core
= cvmx_get_core_num();
40 unsigned int cpu
= smp_processor_id();
41 uint64_t icache_err
= read_octeon_c0_icacheerr();
42 struct edac_device_ctl_info
*ed
= ed_cavium
;
44 edac_device_printk(ed
, KERN_ERR
,
45 "Cache error exception on core %d / processor %d:\n",
47 edac_device_printk(ed
, KERN_ERR
,
48 "cp0_errorepc == %lx\n", read_c0_errorepc());
50 edac_device_printk(ed
, KERN_ERR
, "CacheErr (Icache) == %llx\n",
51 (unsigned long long)icache_err
);
52 write_octeon_c0_icacheerr(0);
53 edac_device_handle_ce(ed
, 0, 0, ed
->ctl_name
);
55 if (cache_err_dcache
[core
] & 1) {
56 edac_device_printk(ed
, KERN_ERR
, "CacheErr (Dcache) == %llx\n",
57 (unsigned long long)cache_err_dcache
[core
]);
58 cache_err_dcache
[core
] = 0;
59 edac_device_handle_ue(ed
, 0, 0, ed
->ctl_name
);
65 static struct notifier_block co_cache_error_notifier
= {
66 .notifier_call
= co_cache_error_event
,
69 static int __devinit
co_cache_error_probe(struct platform_device
*pdev
)
71 struct edac_device_ctl_info
*ed
;
74 ed
= edac_device_alloc_ctl_info(0, "cpu", 1, NULL
, 0, 0, NULL
, 0,
75 edac_device_alloc_index());
78 platform_set_drvdata(pdev
, ed
);
79 ed
->dev_name
= dev_name(&pdev
->dev
);
81 ed
->mod_name
= "octeon-cpu";
82 ed
->ctl_name
= "co_cpu_err";
84 if (edac_device_add_device(ed
) > 0) {
85 pr_err("%s: edac_device_add_device() failed\n", __func__
);
89 register_co_cache_error_notifier(&co_cache_error_notifier
);
95 edac_device_free_ctl_info(ed
);
100 static int co_cache_error_remove(struct platform_device
*pdev
)
102 struct edac_device_ctl_info
*ed
= platform_get_drvdata(pdev
);
104 unregister_co_cache_error_notifier(&co_cache_error_notifier
);
106 edac_device_del_device(&pdev
->dev
);
107 edac_device_free_ctl_info(ed
);
112 static struct platform_driver co_cache_error_driver
= {
113 .probe
= co_cache_error_probe
,
114 .remove
= co_cache_error_remove
,
116 .name
= "co_pc_edac",
120 static int __init
co_edac_init(void)
124 ret
= platform_driver_register(&co_cache_error_driver
);
126 pr_warning(EDAC_MOD_STR
"CPU err failed to register\n");
131 static void __exit
co_edac_exit(void)
133 platform_driver_unregister(&co_cache_error_driver
);
136 module_init(co_edac_init
);
137 module_exit(co_edac_exit
);
139 MODULE_LICENSE("GPL");
140 MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");