4 * (C) 2007 www.douglaskthompson.com
5 * This file is licensed under the terms of the GNU General Public
6 * License version 2. This program is licensed "as is" without any
7 * warranty of any kind, whether express or implied.
9 * Author: Doug Thompson <norsk5@xmission.com>
12 #include <linux/edac.h>
14 #include "edac_core.h"
15 #include "edac_module.h"
17 #define EDAC_MC_VERSION "Ver: 2.0.4 " __DATE__
19 #ifdef CONFIG_EDAC_DEBUG
20 /* Values of 0 to 4 will generate output */
21 int edac_debug_level = 1;
22 EXPORT_SYMBOL_GPL(edac_debug_level);
25 /* scope is to module level only */
26 struct workqueue_struct *edac_workqueue;
29 * sysfs object: /sys/devices/system/edac
30 * need to export to other files in this modules
32 static struct sysdev_class edac_class = {
33 set_kset_name("edac"),
35 static int edac_class_valid = 0;
38 * edac_get_edac_class()
40 * return pointer to the edac class of 'edac'
42 struct sysdev_class *edac_get_edac_class(void)
44 struct sysdev_class *classptr=NULL;
47 classptr = &edac_class;
53 * edac_register_sysfs_edac_name()
55 * register the 'edac' into /sys/devices/system
61 static int edac_register_sysfs_edac_name(void)
65 /* create the /sys/devices/system/edac directory */
66 err = sysdev_class_register(&edac_class);
69 debugf1("%s() error=%d\n", __func__, err);
78 * sysdev_class_unregister()
80 * unregister the 'edac' from /sys/devices/system
82 static void edac_unregister_sysfs_edac_name(void)
84 /* only if currently registered, then unregister it */
86 sysdev_class_unregister(&edac_class);
92 * edac_workqueue_setup
93 * initialize the edac work queue for polling operations
95 static int edac_workqueue_setup(void)
97 edac_workqueue = create_singlethread_workqueue("edac-poller");
98 if (edac_workqueue == NULL)
105 * edac_workqueue_teardown
106 * teardown the edac workqueue
108 static void edac_workqueue_teardown(void)
110 if (edac_workqueue) {
111 flush_workqueue(edac_workqueue);
112 destroy_workqueue(edac_workqueue);
113 edac_workqueue = NULL;
120 * module initialization entry point
122 static int __init edac_init(void)
126 edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
129 * Harvest and clear any boot/initialization PCI parity errors
131 * FIXME: This only clears errors logged by devices present at time of
132 * module initialization. We should also do an initial clear
133 * of each newly hotplugged device.
135 edac_pci_clear_parity_errors();
138 * perform the registration of the /sys/devices/system/edac object
140 if (edac_register_sysfs_edac_name()) {
141 edac_printk(KERN_ERR, EDAC_MC,
142 "Error initializing 'edac' kobject\n");
147 /* Create the MC sysfs entries, must be first
149 if (edac_sysfs_memctrl_setup()) {
150 edac_printk(KERN_ERR, EDAC_MC,
151 "Error initializing sysfs code\n");
156 /* Create the PCI parity sysfs entries */
157 if (edac_sysfs_pci_setup()) {
158 edac_printk(KERN_ERR, EDAC_MC,
159 "PCI: Error initializing sysfs code\n");
164 /* Setup/Initialize the edac_device system */
165 err = edac_workqueue_setup();
167 edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
173 /* Error teardown stack */
175 edac_sysfs_pci_teardown();
177 edac_sysfs_memctrl_teardown();
179 edac_unregister_sysfs_edac_name();
186 * module exit/termination function
188 static void __exit edac_exit(void)
190 debugf0("%s()\n", __func__);
192 /* tear down the various subsystems*/
193 edac_workqueue_teardown();
194 edac_sysfs_memctrl_teardown();
195 edac_sysfs_pci_teardown();
196 edac_unregister_sysfs_edac_name();
200 * Inform the kernel of our entry and exit points
202 module_init(edac_init);
203 module_exit(edac_exit);
205 MODULE_LICENSE("GPL");
206 MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
207 MODULE_DESCRIPTION("Core library routines for EDAC reporting");
209 /* refer to *_sysfs.c files for parameters that are exported via sysfs */
211 #ifdef CONFIG_EDAC_DEBUG
212 module_param(edac_debug_level, int, 0644);
213 MODULE_PARM_DESC(edac_debug_level, "Debug level");