2 #include <linux/freezer.h>
3 #include <linux/kthread.h>
6 #include "edac_module.h"
8 #define EDAC_MC_VERSION "Ver: 2.0.3" __DATE__
10 #ifdef CONFIG_EDAC_DEBUG
11 /* Values of 0 to 4 will generate output */
12 int edac_debug_level = 1;
13 EXPORT_SYMBOL_GPL(edac_debug_level);
16 /* scope is to module level only */
17 struct workqueue_struct *edac_workqueue;
19 /* private to this file */
20 static struct task_struct *edac_thread;
24 * sysfs object: /sys/devices/system/edac
25 * need to export to other files in this modules
27 static struct sysdev_class edac_class = {
28 set_kset_name("edac"),
30 static int edac_class_valid = 0;
33 * edac_get_edac_class()
35 * return pointer to the edac class of 'edac'
37 struct sysdev_class *edac_get_edac_class(void)
39 struct sysdev_class *classptr=NULL;
42 classptr = &edac_class;
48 * edac_register_sysfs_edac_name()
50 * register the 'edac' into /sys/devices/system
56 static int edac_register_sysfs_edac_name(void)
60 /* create the /sys/devices/system/edac directory */
61 err = sysdev_class_register(&edac_class);
64 debugf1("%s() error=%d\n", __func__, err);
73 * sysdev_class_unregister()
75 * unregister the 'edac' from /sys/devices/system
77 static void edac_unregister_sysfs_edac_name(void)
79 /* only if currently registered, then unregister it */
81 sysdev_class_unregister(&edac_class);
88 * Check MC status every edac_get_poll_msec().
89 * Check PCI status every edac_get_poll_msec() as well.
91 * This where the work gets done for edac.
93 * SMP safe, doesn't use NMI, and auto-rate-limits.
95 static void do_edac_check(void)
97 debugf3("%s()\n", __func__);
99 /* perform the poll activities */
100 edac_check_mc_devices();
101 edac_pci_do_parity_check();
105 * Action thread for EDAC to perform the POLL operations
107 static int edac_kernel_thread(void *arg)
111 while (!kthread_should_stop()) {
115 /* goto sleep for the interval */
116 msec = (HZ * edac_get_poll_msec()) / 1000;
117 schedule_timeout_interruptible(msec);
125 * edac_workqueue_setup
126 * initialize the edac work queue for polling operations
128 static int edac_workqueue_setup(void)
130 edac_workqueue = create_singlethread_workqueue("edac-poller");
131 if (edac_workqueue == NULL)
138 * edac_workqueue_teardown
139 * teardown the edac workqueue
141 static void edac_workqueue_teardown(void)
143 if (edac_workqueue) {
144 flush_workqueue(edac_workqueue);
145 destroy_workqueue(edac_workqueue);
146 edac_workqueue = NULL;
153 * module initialization entry point
155 static int __init edac_init(void)
159 edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
162 * Harvest and clear any boot/initialization PCI parity errors
164 * FIXME: This only clears errors logged by devices present at time of
165 * module initialization. We should also do an initial clear
166 * of each newly hotplugged device.
168 edac_pci_clear_parity_errors();
171 * perform the registration of the /sys/devices/system/edac object
173 if (edac_register_sysfs_edac_name()) {
174 edac_printk(KERN_ERR, EDAC_MC,
175 "Error initializing 'edac' kobject\n");
180 /* Create the MC sysfs entries, must be first
182 if (edac_sysfs_memctrl_setup()) {
183 edac_printk(KERN_ERR, EDAC_MC,
184 "Error initializing sysfs code\n");
189 /* Create the PCI parity sysfs entries */
190 if (edac_sysfs_pci_setup()) {
191 edac_printk(KERN_ERR, EDAC_MC,
192 "PCI: Error initializing sysfs code\n");
197 /* Setup/Initialize the edac_device system */
198 err = edac_workqueue_setup();
200 edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
204 /* create our kernel thread */
205 edac_thread = kthread_run(edac_kernel_thread, NULL, "kedac");
207 if (IS_ERR(edac_thread)) {
208 err = PTR_ERR(edac_thread);
214 /* Error teardown stack */
216 edac_workqueue_teardown();
218 edac_sysfs_pci_teardown();
220 edac_sysfs_memctrl_teardown();
222 edac_unregister_sysfs_edac_name();
229 * module exit/termination function
231 static void __exit edac_exit(void)
233 debugf0("%s()\n", __func__);
234 kthread_stop(edac_thread);
236 /* tear down the various subsystems*/
237 edac_workqueue_teardown();
238 edac_sysfs_memctrl_teardown();
239 edac_sysfs_pci_teardown();
240 edac_unregister_sysfs_edac_name();
244 * Inform the kernel of our entry and exit points
246 module_init(edac_init);
247 module_exit(edac_exit);
249 MODULE_LICENSE("GPL");
250 MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
251 MODULE_DESCRIPTION("Core library routines for EDAC reporting");
253 /* refer to *_sysfs.c files for parameters that are exported via sysfs */
255 #ifdef CONFIG_EDAC_DEBUG
256 module_param(edac_debug_level, int, 0644);
257 MODULE_PARM_DESC(edac_debug_level, "Debug level");