blob: 9d9e18aefaaa491e2020d55b503bcbbe862a9032 [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#include <asm/edac.h>
20
21int edac_op_state = EDAC_OPSTATE_INVAL;
Doug Thompsonfb3fb202007-07-19 01:50:30 -070022EXPORT_SYMBOL_GPL(edac_op_state);
Dave Jiangc0d12172007-07-19 01:49:46 -070023
24atomic_t edac_handlers = ATOMIC_INIT(0);
Doug Thompsonfb3fb202007-07-19 01:50:30 -070025EXPORT_SYMBOL_GPL(edac_handlers);
Dave Jiangc0d12172007-07-19 01:49:46 -070026
Dave Jiang66ee2f92007-07-19 01:49:54 -070027int edac_err_assert = 0;
Doug Thompsonfb3fb202007-07-19 01:50:30 -070028EXPORT_SYMBOL_GPL(edac_err_assert);
Dave Jiangc0d12172007-07-19 01:49:46 -070029
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080030static atomic_t edac_subsys_valid = ATOMIC_INIT(0);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020031
Chen, Gongc700f012013-12-06 01:17:08 -050032int edac_report_status = EDAC_REPORTING_ENABLED;
33EXPORT_SYMBOL_GPL(edac_report_status);
34
35static int __init edac_report_setup(char *str)
36{
37 if (!str)
38 return -EINVAL;
39
40 if (!strncmp(str, "on", 2))
41 set_edac_report_status(EDAC_REPORTING_ENABLED);
42 else if (!strncmp(str, "off", 3))
43 set_edac_report_status(EDAC_REPORTING_DISABLED);
44 else if (!strncmp(str, "force", 5))
45 set_edac_report_status(EDAC_REPORTING_FORCE);
46
47 return 0;
48}
49__setup("edac_report=", edac_report_setup);
50
Doug Thompsonfb3fb202007-07-19 01:50:30 -070051/*
52 * called to determine if there is an EDAC driver interested in
53 * knowing an event (such as NMI) occurred
54 */
55int edac_handler_set(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070056{
57 if (edac_op_state == EDAC_OPSTATE_POLL)
58 return 0;
59
60 return atomic_read(&edac_handlers);
61}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070062EXPORT_SYMBOL_GPL(edac_handler_set);
Dave Jiangc0d12172007-07-19 01:49:46 -070063
64/*
65 * handler for NMI type of interrupts to assert error
66 */
Doug Thompsonfb3fb202007-07-19 01:50:30 -070067void edac_atomic_assert_error(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070068{
Dave Jiang66ee2f92007-07-19 01:49:54 -070069 edac_err_assert++;
Dave Jiangc0d12172007-07-19 01:49:46 -070070}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070071EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020072
73/*
74 * sysfs object: /sys/devices/system/edac
75 * need to export to other files
76 */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080077struct bus_type edac_subsys = {
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020078 .name = "edac",
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080079 .dev_name = "edac",
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020080};
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080081EXPORT_SYMBOL_GPL(edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020082
83/* return pointer to the 'edac' node in sysfs */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080084struct bus_type *edac_get_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020085{
86 int err = 0;
87
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080088 if (atomic_read(&edac_subsys_valid))
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020089 goto out;
90
91 /* create the /sys/devices/system/edac directory */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080092 err = subsys_system_register(&edac_subsys, NULL);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020093 if (err) {
94 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
95 return NULL;
96 }
97
98out:
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080099 atomic_inc(&edac_subsys_valid);
100 return &edac_subsys;
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200101}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800102EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200103
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800104void edac_put_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200105{
106 /* last user unregisters it */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800107 if (atomic_dec_and_test(&edac_subsys_valid))
108 bus_unregister(&edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +0200109}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -0800110EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);