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. |
| 8 | * Borislav Petkov <borislav.petkov@amd.com> |
| 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 | 6006349 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 17 | #include <linux/atomic.h> |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 18 | #include <asm/edac.h> |
| 19 | |
| 20 | int edac_op_state = EDAC_OPSTATE_INVAL; |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 21 | EXPORT_SYMBOL_GPL(edac_op_state); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 22 | |
| 23 | atomic_t edac_handlers = ATOMIC_INIT(0); |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 24 | EXPORT_SYMBOL_GPL(edac_handlers); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 25 | |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 26 | int edac_err_assert = 0; |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 27 | EXPORT_SYMBOL_GPL(edac_err_assert); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 28 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 29 | static atomic_t edac_subsys_valid = ATOMIC_INIT(0); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 30 | |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 31 | /* |
| 32 | * called to determine if there is an EDAC driver interested in |
| 33 | * knowing an event (such as NMI) occurred |
| 34 | */ |
| 35 | int edac_handler_set(void) |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 36 | { |
| 37 | if (edac_op_state == EDAC_OPSTATE_POLL) |
| 38 | return 0; |
| 39 | |
| 40 | return atomic_read(&edac_handlers); |
| 41 | } |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 42 | EXPORT_SYMBOL_GPL(edac_handler_set); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * handler for NMI type of interrupts to assert error |
| 46 | */ |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 47 | void edac_atomic_assert_error(void) |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 48 | { |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 49 | edac_err_assert++; |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 50 | } |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 51 | EXPORT_SYMBOL_GPL(edac_atomic_assert_error); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * sysfs object: /sys/devices/system/edac |
| 55 | * need to export to other files |
| 56 | */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 57 | struct bus_type edac_subsys = { |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 58 | .name = "edac", |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 59 | .dev_name = "edac", |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 60 | }; |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 61 | EXPORT_SYMBOL_GPL(edac_subsys); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 62 | |
| 63 | /* return pointer to the 'edac' node in sysfs */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 64 | struct bus_type *edac_get_sysfs_subsys(void) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 65 | { |
| 66 | int err = 0; |
| 67 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 68 | if (atomic_read(&edac_subsys_valid)) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 69 | goto out; |
| 70 | |
| 71 | /* create the /sys/devices/system/edac directory */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 72 | err = subsys_system_register(&edac_subsys, NULL); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 73 | if (err) { |
| 74 | printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n"); |
| 75 | return NULL; |
| 76 | } |
| 77 | |
| 78 | out: |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 79 | atomic_inc(&edac_subsys_valid); |
| 80 | return &edac_subsys; |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 81 | } |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 82 | EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 83 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 84 | void edac_put_sysfs_subsys(void) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 85 | { |
| 86 | /* last user unregisters it */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 87 | if (atomic_dec_and_test(&edac_subsys_valid)) |
| 88 | bus_unregister(&edac_subsys); |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 89 | } |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 90 | EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys); |