edac_module.c 3.3 KB
Newer Older
1 2 3
/*
 * edac_module.c
 *
4 5
 * (C) 2007 www.softwarebitmaker.com
 *
6 7 8 9
 * This file is licensed under the terms of the GNU General Public
 * License version 2. This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 *
10
 * Author: Doug Thompson <dougthompson@xmission.com>
11 12
 *
 */
D
Dave Jiang 已提交
13
#include <linux/edac.h>
14

15
#include "edac_mc.h"
16 17
#include "edac_module.h"

18
#define EDAC_VERSION "Ver: 3.0.0"
19 20

#ifdef CONFIG_EDAC_DEBUG
21 22 23 24 25 26 27 28 29 30

static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
{
	unsigned long val;
	int ret;

	ret = kstrtoul(buf, 0, &val);
	if (ret)
		return ret;

31
	if (val > 4)
32 33 34 35 36
		return -EINVAL;

	return param_set_int(buf, kp);
}

37
/* Values of 0 to 4 will generate output */
38
int edac_debug_level = 2;
39
EXPORT_SYMBOL_GPL(edac_debug_level);
40 41 42 43

module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
		  &edac_debug_level, 0644);
MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
44 45
#endif

46
/*
47
 * edac_op_state_to_string()
48
 */
49
char *edac_op_state_to_string(int opstate)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
{
	if (opstate == OP_RUNNING_POLL)
		return "POLLED";
	else if (opstate == OP_RUNNING_INTERRUPT)
		return "INTERRUPT";
	else if (opstate == OP_RUNNING_POLL_INTR)
		return "POLL-INTR";
	else if (opstate == OP_ALLOC)
		return "ALLOC";
	else if (opstate == OP_OFFLINE)
		return "OFFLINE";

	return "UNKNOWN";
}

65 66 67 68
/*
 * sysfs object: /sys/devices/system/edac
 *	need to export to other files
 */
69
static struct bus_type edac_subsys = {
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
	.name = "edac",
	.dev_name = "edac",
};

static int edac_subsys_init(void)
{
	int err;

	/* create the /sys/devices/system/edac directory */
	err = subsys_system_register(&edac_subsys, NULL);
	if (err)
		printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");

	return err;
}

static void edac_subsys_exit(void)
{
	bus_unregister(&edac_subsys);
}

/* return pointer to the 'edac' node in sysfs */
struct bus_type *edac_get_sysfs_subsys(void)
{
	return &edac_subsys;
}
EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
97 98 99 100 101 102
/*
 * edac_init
 *      module initialization entry point
 */
static int __init edac_init(void)
{
103 104
	int err = 0;

105
	edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
106

107 108 109 110
	err = edac_subsys_init();
	if (err)
		return err;

111 112 113 114
	/*
	 * Harvest and clear any boot/initialization PCI parity errors
	 *
	 * FIXME: This only clears errors logged by devices present at time of
115 116
	 *      module initialization.  We should also do an initial clear
	 *      of each newly hotplugged device.
117 118 119
	 */
	edac_pci_clear_parity_errors();

120
	err = edac_mc_sysfs_init();
121
	if (err)
122
		goto err_sysfs;
123

124 125
	edac_debugfs_init();

126 127
	err = edac_workqueue_setup();
	if (err) {
128 129
		edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
		goto err_wq;
130 131 132
	}

	return 0;
133

134 135 136 137 138
err_wq:
	edac_debugfs_exit();
	edac_mc_sysfs_exit();

err_sysfs:
139 140
	edac_subsys_exit();

141
	return err;
142 143 144 145 146 147 148 149
}

/*
 * edac_exit()
 *      module exit/termination function
 */
static void __exit edac_exit(void)
{
150
	edac_dbg(0, "\n");
151

152
	/* tear down the various subsystems */
153
	edac_workqueue_teardown();
154
	edac_mc_sysfs_exit();
155
	edac_debugfs_exit();
156
	edac_subsys_exit();
157 158 159 160 161
}

/*
 * Inform the kernel of our entry and exit points
 */
162
subsys_initcall(edac_init);
163 164 165 166 167
module_exit(edac_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
MODULE_DESCRIPTION("Core library routines for EDAC reporting");