Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * common EDAC components that must be in kernel |
| 3 | * |
| 4 | * Author: Dave Jiang <djiang@mvista.com> |
| 5 | * |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 6 | * 2007 (c) MontaVista Software, Inc. |
| 7 | * 2010 (c) Advanced Micro Devices Inc. |
Borislav Petkov | 43aff26 | 2012-10-29 18:40:09 +0100 | [diff] [blame] | 8 | * Borislav Petkov <bp@alien8.de> |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 9 | * |
| 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 Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 13 | * |
| 14 | */ |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/edac.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 17 | #include <linux/atomic.h> |
Paul Gortmaker | 51990e8 | 2012-01-22 11:23:42 -0500 | [diff] [blame] | 18 | #include <linux/device.h> |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 19 | #include <asm/edac.h> |
| 20 | |
| 21 | int edac_op_state = EDAC_OPSTATE_INVAL; |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 22 | EXPORT_SYMBOL_GPL(edac_op_state); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 23 | |
| 24 | atomic_t edac_handlers = ATOMIC_INIT(0); |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 25 | EXPORT_SYMBOL_GPL(edac_handlers); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 26 | |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 27 | int edac_err_assert = 0; |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 28 | EXPORT_SYMBOL_GPL(edac_err_assert); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 29 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 30 | static atomic_t edac_subsys_valid = ATOMIC_INIT(0); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 31 | |
Chen, Gong | c700f01 | 2013-12-06 01:17:08 -0500 | [diff] [blame] | 32 | int edac_report_status = EDAC_REPORTING_ENABLED; |
| 33 | EXPORT_SYMBOL_GPL(edac_report_status); |
| 34 | |
| 35 | static 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 Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 51 | /* |
| 52 | * called to determine if there is an EDAC driver interested in |
| 53 | * knowing an event (such as NMI) occurred |
| 54 | */ |
| 55 | int edac_handler_set(void) |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 56 | { |
| 57 | if (edac_op_state == EDAC_OPSTATE_POLL) |
| 58 | return 0; |
| 59 | |
| 60 | return atomic_read(&edac_handlers); |
| 61 | } |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 62 | EXPORT_SYMBOL_GPL(edac_handler_set); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * handler for NMI type of interrupts to assert error |
| 66 | */ |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 67 | void edac_atomic_assert_error(void) |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 68 | { |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 69 | edac_err_assert++; |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 70 | } |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 71 | EXPORT_SYMBOL_GPL(edac_atomic_assert_error); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * sysfs object: /sys/devices/system/edac |
| 75 | * need to export to other files |
| 76 | */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 77 | struct bus_type edac_subsys = { |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 78 | .name = "edac", |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 79 | .dev_name = "edac", |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 80 | }; |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 81 | EXPORT_SYMBOL_GPL(edac_subsys); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 82 | |
| 83 | /* return pointer to the 'edac' node in sysfs */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 84 | struct bus_type *edac_get_sysfs_subsys(void) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 85 | { |
| 86 | int err = 0; |
| 87 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 88 | if (atomic_read(&edac_subsys_valid)) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 89 | goto out; |
| 90 | |
| 91 | /* create the /sys/devices/system/edac directory */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 92 | err = subsys_system_register(&edac_subsys, NULL); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 93 | if (err) { |
| 94 | printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n"); |
| 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | out: |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 99 | atomic_inc(&edac_subsys_valid); |
| 100 | return &edac_subsys; |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 101 | } |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 102 | EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 103 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 104 | void edac_put_sysfs_subsys(void) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 105 | { |
| 106 | /* last user unregisters it */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 107 | if (atomic_dec_and_test(&edac_subsys_valid)) |
| 108 | bus_unregister(&edac_subsys); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 109 | } |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 110 | EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys); |