]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/edac/edac_module.c
EDAC: Rip out the edac_subsys reference counting
[mirror_ubuntu-bionic-kernel.git] / drivers / edac / edac_module.c
CommitLineData
81d87cb1
DJ
1/*
2 * edac_module.c
3 *
fb3fb206
DT
4 * (C) 2007 www.softwarebitmaker.com
5 *
81d87cb1
DJ
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 *
fb3fb206 10 * Author: Doug Thompson <dougthompson@xmission.com>
81d87cb1
DJ
11 *
12 */
c0d12172 13#include <linux/edac.h>
7c9281d7 14
20bcb7a8 15#include "edac_core.h"
7c9281d7
DT
16#include "edac_module.h"
17
5156a5f4 18#define EDAC_VERSION "Ver: 3.0.0"
7c9281d7
DT
19
20#ifdef CONFIG_EDAC_DEBUG
37929874
BP
21
22static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
23{
24 unsigned long val;
25 int ret;
26
27 ret = kstrtoul(buf, 0, &val);
28 if (ret)
29 return ret;
30
6866b390 31 if (val > 4)
37929874
BP
32 return -EINVAL;
33
34 return param_set_int(buf, kp);
35}
36
7c9281d7 37/* Values of 0 to 4 will generate output */
8096cfaf 38int edac_debug_level = 2;
7c9281d7 39EXPORT_SYMBOL_GPL(edac_debug_level);
37929874
BP
40
41module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
42 &edac_debug_level, 0644);
43MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
7c9281d7
DT
44#endif
45
e27e3dac
DT
46/* scope is to module level only */
47struct workqueue_struct *edac_workqueue;
48
91b99041 49/*
494d0d55 50 * edac_op_state_to_string()
91b99041 51 */
494d0d55 52char *edac_op_state_to_string(int opstate)
91b99041
DJ
53{
54 if (opstate == OP_RUNNING_POLL)
55 return "POLLED";
56 else if (opstate == OP_RUNNING_INTERRUPT)
57 return "INTERRUPT";
58 else if (opstate == OP_RUNNING_POLL_INTR)
59 return "POLL-INTR";
60 else if (opstate == OP_ALLOC)
61 return "ALLOC";
62 else if (opstate == OP_OFFLINE)
63 return "OFFLINE";
64
65 return "UNKNOWN";
66}
67
e27e3dac
DT
68/*
69 * edac_workqueue_setup
70 * initialize the edac work queue for polling operations
71 */
72static int edac_workqueue_setup(void)
73{
74 edac_workqueue = create_singlethread_workqueue("edac-poller");
75 if (edac_workqueue == NULL)
76 return -ENODEV;
77 else
78 return 0;
79}
80
81/*
82 * edac_workqueue_teardown
83 * teardown the edac workqueue
84 */
85static void edac_workqueue_teardown(void)
86{
87 if (edac_workqueue) {
88 flush_workqueue(edac_workqueue);
89 destroy_workqueue(edac_workqueue);
90 edac_workqueue = NULL;
91 }
92}
93
733476cf
BP
94/*
95 * sysfs object: /sys/devices/system/edac
96 * need to export to other files
97 */
98struct bus_type edac_subsys = {
99 .name = "edac",
100 .dev_name = "edac",
101};
102EXPORT_SYMBOL_GPL(edac_subsys);
103
104static int edac_subsys_init(void)
105{
106 int err;
107
108 /* create the /sys/devices/system/edac directory */
109 err = subsys_system_register(&edac_subsys, NULL);
110 if (err)
111 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
112
113 return err;
114}
115
116static void edac_subsys_exit(void)
117{
118 bus_unregister(&edac_subsys);
119}
120
121/* return pointer to the 'edac' node in sysfs */
122struct bus_type *edac_get_sysfs_subsys(void)
123{
124 return &edac_subsys;
125}
126EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
7c9281d7
DT
127/*
128 * edac_init
129 * module initialization entry point
130 */
131static int __init edac_init(void)
132{
e27e3dac
DT
133 int err = 0;
134
fb3fb206 135 edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
7c9281d7 136
733476cf
BP
137 err = edac_subsys_init();
138 if (err)
139 return err;
140
7c9281d7
DT
141 /*
142 * Harvest and clear any boot/initialization PCI parity errors
143 *
144 * FIXME: This only clears errors logged by devices present at time of
079708b9
DT
145 * module initialization. We should also do an initial clear
146 * of each newly hotplugged device.
7c9281d7
DT
147 */
148 edac_pci_clear_parity_errors();
149
7a623c03 150 err = edac_mc_sysfs_init();
8096cfaf 151 if (err)
c6b97bcf 152 goto err_sysfs;
7c9281d7 153
e7930ba4
RH
154 edac_debugfs_init();
155
e27e3dac
DT
156 err = edac_workqueue_setup();
157 if (err) {
c6b97bcf
AK
158 edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
159 goto err_wq;
7c9281d7
DT
160 }
161
7c9281d7 162 return 0;
e27e3dac 163
c6b97bcf
AK
164err_wq:
165 edac_debugfs_exit();
166 edac_mc_sysfs_exit();
167
168err_sysfs:
733476cf
BP
169 edac_subsys_exit();
170
e27e3dac 171 return err;
7c9281d7
DT
172}
173
174/*
175 * edac_exit()
176 * module exit/termination function
177 */
178static void __exit edac_exit(void)
179{
956b9ba1 180 edac_dbg(0, "\n");
7c9281d7 181
079708b9 182 /* tear down the various subsystems */
e27e3dac 183 edac_workqueue_teardown();
7a623c03 184 edac_mc_sysfs_exit();
e7930ba4 185 edac_debugfs_exit();
733476cf 186 edac_subsys_exit();
7c9281d7
DT
187}
188
189/*
190 * Inform the kernel of our entry and exit points
191 */
4ab19b06 192subsys_initcall(edac_init);
7c9281d7
DT
193module_exit(edac_exit);
194
195MODULE_LICENSE("GPL");
196MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
197MODULE_DESCRIPTION("Core library routines for EDAC reporting");