drivers/edac: mod PCI poll names
[deliverable/linux.git] / drivers / edac / edac_module.c
CommitLineData
81d87cb1
DJ
1/*
2 * edac_module.c
3 *
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.
8 *
9 * Author: Doug Thompson <norsk5@xmission.com>
10 *
11 */
c0d12172 12#include <linux/edac.h>
7c9281d7 13
20bcb7a8 14#include "edac_core.h"
7c9281d7
DT
15#include "edac_module.h"
16
20bcb7a8 17#define EDAC_MC_VERSION "Ver: 2.0.4 " __DATE__
7c9281d7
DT
18
19#ifdef CONFIG_EDAC_DEBUG
20/* Values of 0 to 4 will generate output */
21int edac_debug_level = 1;
22EXPORT_SYMBOL_GPL(edac_debug_level);
23#endif
24
e27e3dac
DT
25/* scope is to module level only */
26struct workqueue_struct *edac_workqueue;
27
e27e3dac
DT
28/*
29 * sysfs object: /sys/devices/system/edac
30 * need to export to other files in this modules
31 */
32static struct sysdev_class edac_class = {
33 set_kset_name("edac"),
34};
35static int edac_class_valid = 0;
36
91b99041
DJ
37/*
38 * edac_op_state_toString()
39 */
40char * edac_op_state_toString(int opstate)
41{
42 if (opstate == OP_RUNNING_POLL)
43 return "POLLED";
44 else if (opstate == OP_RUNNING_INTERRUPT)
45 return "INTERRUPT";
46 else if (opstate == OP_RUNNING_POLL_INTR)
47 return "POLL-INTR";
48 else if (opstate == OP_ALLOC)
49 return "ALLOC";
50 else if (opstate == OP_OFFLINE)
51 return "OFFLINE";
52
53 return "UNKNOWN";
54}
55
e27e3dac
DT
56/*
57 * edac_get_edac_class()
58 *
59 * return pointer to the edac class of 'edac'
60 */
61struct sysdev_class *edac_get_edac_class(void)
62{
63 struct sysdev_class *classptr=NULL;
64
65 if (edac_class_valid)
66 classptr = &edac_class;
67
68 return classptr;
69}
70
71/*
72 * edac_register_sysfs_edac_name()
73 *
74 * register the 'edac' into /sys/devices/system
75 *
76 * return:
77 * 0 success
78 * !0 error
79 */
80static int edac_register_sysfs_edac_name(void)
81{
82 int err;
83
84 /* create the /sys/devices/system/edac directory */
85 err = sysdev_class_register(&edac_class);
86
87 if (err) {
88 debugf1("%s() error=%d\n", __func__, err);
89 return err;
90 }
91
92 edac_class_valid = 1;
93 return 0;
94}
95
96/*
97 * sysdev_class_unregister()
98 *
99 * unregister the 'edac' from /sys/devices/system
100 */
101static void edac_unregister_sysfs_edac_name(void)
102{
103 /* only if currently registered, then unregister it */
104 if (edac_class_valid)
105 sysdev_class_unregister(&edac_class);
106
107 edac_class_valid = 0;
108}
109
e27e3dac
DT
110/*
111 * edac_workqueue_setup
112 * initialize the edac work queue for polling operations
113 */
114static int edac_workqueue_setup(void)
115{
116 edac_workqueue = create_singlethread_workqueue("edac-poller");
117 if (edac_workqueue == NULL)
118 return -ENODEV;
119 else
120 return 0;
121}
122
123/*
124 * edac_workqueue_teardown
125 * teardown the edac workqueue
126 */
127static void edac_workqueue_teardown(void)
128{
129 if (edac_workqueue) {
130 flush_workqueue(edac_workqueue);
131 destroy_workqueue(edac_workqueue);
132 edac_workqueue = NULL;
133 }
134}
135
136
7c9281d7
DT
137/*
138 * edac_init
139 * module initialization entry point
140 */
141static int __init edac_init(void)
142{
e27e3dac
DT
143 int err = 0;
144
7c9281d7
DT
145 edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
146
147 /*
148 * Harvest and clear any boot/initialization PCI parity errors
149 *
150 * FIXME: This only clears errors logged by devices present at time of
151 * module initialization. We should also do an initial clear
152 * of each newly hotplugged device.
153 */
154 edac_pci_clear_parity_errors();
155
e27e3dac
DT
156 /*
157 * perform the registration of the /sys/devices/system/edac object
158 */
159 if (edac_register_sysfs_edac_name()) {
160 edac_printk(KERN_ERR, EDAC_MC,
161 "Error initializing 'edac' kobject\n");
162 err = -ENODEV;
163 goto error;
164 }
165
166 /* Create the MC sysfs entries, must be first
167 */
7c9281d7
DT
168 if (edac_sysfs_memctrl_setup()) {
169 edac_printk(KERN_ERR, EDAC_MC,
170 "Error initializing sysfs code\n");
e27e3dac
DT
171 err = -ENODEV;
172 goto error_sysfs;
7c9281d7
DT
173 }
174
e27e3dac
DT
175 /* Setup/Initialize the edac_device system */
176 err = edac_workqueue_setup();
177 if (err) {
178 edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
91b99041 179 goto error_mem;
7c9281d7
DT
180 }
181
7c9281d7 182 return 0;
e27e3dac
DT
183
184 /* Error teardown stack */
e27e3dac
DT
185error_mem:
186 edac_sysfs_memctrl_teardown();
187error_sysfs:
188 edac_unregister_sysfs_edac_name();
189error:
190 return err;
7c9281d7
DT
191}
192
193/*
194 * edac_exit()
195 * module exit/termination function
196 */
197static void __exit edac_exit(void)
198{
199 debugf0("%s()\n", __func__);
7c9281d7 200
e27e3dac
DT
201 /* tear down the various subsystems*/
202 edac_workqueue_teardown();
7c9281d7 203 edac_sysfs_memctrl_teardown();
e27e3dac 204 edac_unregister_sysfs_edac_name();
7c9281d7
DT
205}
206
207/*
208 * Inform the kernel of our entry and exit points
209 */
210module_init(edac_init);
211module_exit(edac_exit);
212
213MODULE_LICENSE("GPL");
214MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
215MODULE_DESCRIPTION("Core library routines for EDAC reporting");
216
217/* refer to *_sysfs.c files for parameters that are exported via sysfs */
218
219#ifdef CONFIG_EDAC_DEBUG
220module_param(edac_debug_level, int, 0644);
221MODULE_PARM_DESC(edac_debug_level, "Debug level");
222#endif
223
This page took 0.034014 seconds and 5 git commands to generate.