blob: ff07aae5b7fbd963b59a72e9fdfed2cc3ad721aa [file] [log] [blame]
Dave Jiangc0d12172007-07-19 01:49:46 -07001/*
2 * common EDAC components that must be in kernel
3 *
4 * Author: Dave Jiang <djiang@mvista.com>
5 *
Borislav Petkov30e1f7a2010-09-02 17:26:48 +02006 * 2007 (c) MontaVista Software, Inc.
7 * 2010 (c) Advanced Micro Devices Inc.
Borislav Petkov43aff262012-10-29 18:40:09 +01008 * Borislav Petkov <bp@alien8.de>
Borislav Petkov30e1f7a2010-09-02 17:26:48 +02009 *
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
Dave Jiangc0d12172007-07-19 01:49:46 -070013 *
14 */
15#include <linux/module.h>
16#include <linux/edac.h>
Arun Sharma600634972011-07-26 16:09:06 -070017#include <linux/atomic.h>
Paul Gortmaker51990e82012-01-22 11:23:42 -050018#include <linux/device.h>
Dave Jiangc0d12172007-07-19 01:49:46 -070019
20int edac_op_state = EDAC_OPSTATE_INVAL;
Doug Thompsonfb3fb202007-07-19 01:50:30 -070021EXPORT_SYMBOL_GPL(edac_op_state);
Dave Jiangc0d12172007-07-19 01:49:46 -070022
23atomic_t edac_handlers = ATOMIC_INIT(0);
Doug Thompsonfb3fb202007-07-19 01:50:30 -070024EXPORT_SYMBOL_GPL(edac_handlers);
Dave Jiangc0d12172007-07-19 01:49:46 -070025
Dave Jiang66ee2f92007-07-19 01:49:54 -070026int edac_err_assert = 0;
Doug Thompsonfb3fb202007-07-19 01:50:30 -070027EXPORT_SYMBOL_GPL(edac_err_assert);
Dave Jiangc0d12172007-07-19 01:49:46 -070028
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080029static atomic_t edac_subsys_valid = ATOMIC_INIT(0);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020030
Chen, Gongc700f012013-12-06 01:17:08 -050031int edac_report_status = EDAC_REPORTING_ENABLED;
32EXPORT_SYMBOL_GPL(edac_report_status);
33
34static int __init edac_report_setup(char *str)
35{
36 if (!str)
37 return -EINVAL;
38
39 if (!strncmp(str, "on", 2))
40 set_edac_report_status(EDAC_REPORTING_ENABLED);
41 else if (!strncmp(str, "off", 3))
42 set_edac_report_status(EDAC_REPORTING_DISABLED);
43 else if (!strncmp(str, "force", 5))
44 set_edac_report_status(EDAC_REPORTING_FORCE);
45
46 return 0;
47}
48__setup("edac_report=", edac_report_setup);
49
Doug Thompsonfb3fb202007-07-19 01:50:30 -070050/*
51 * called to determine if there is an EDAC driver interested in
52 * knowing an event (such as NMI) occurred
53 */
54int edac_handler_set(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070055{
56 if (edac_op_state == EDAC_OPSTATE_POLL)
57 return 0;
58
59 return atomic_read(&edac_handlers);
60}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070061EXPORT_SYMBOL_GPL(edac_handler_set);
Dave Jiangc0d12172007-07-19 01:49:46 -070062
63/*
64 * handler for NMI type of interrupts to assert error
65 */
Doug Thompsonfb3fb202007-07-19 01:50:30 -070066void edac_atomic_assert_error(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070067{
Dave Jiang66ee2f92007-07-19 01:49:54 -070068 edac_err_assert++;
Dave Jiangc0d12172007-07-19 01:49:46 -070069}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070070EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020071
72/*
73 * sysfs object: /sys/devices/system/edac
74 * need to export to other files
75 */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080076struct bus_type edac_subsys = {
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020077 .name = "edac",
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080078 .dev_name = "edac",
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020079};
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080080EXPORT_SYMBOL_GPL(edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020081
82/* return pointer to the 'edac' node in sysfs */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080083struct bus_type *edac_get_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020084{
85 int err = 0;
86
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080087 if (atomic_read(&edac_subsys_valid))
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020088 goto out;
89
90 /* create the /sys/devices/system/edac directory */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080091 err = subsys_system_register(&edac_subsys, NULL);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020092 if (err) {
93 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
94 return NULL;
95 }
96
97out:
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080098 atomic_inc(&edac_subsys_valid);
99 return &edac_subsys;
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200100}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800101EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200102
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800103void edac_put_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200104{
105 /* last user unregisters it */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800106 if (atomic_dec_and_test(&edac_subsys_valid))
107 bus_unregister(&edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200108}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800109EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);