Commit | Line | Data |
---|---|---|
c0d12172 DJ |
1 | /* |
2 | * common EDAC components that must be in kernel | |
3 | * | |
4 | * Author: Dave Jiang <djiang@mvista.com> | |
5 | * | |
30e1f7a8 BP |
6 | * 2007 (c) MontaVista Software, Inc. |
7 | * 2010 (c) Advanced Micro Devices Inc. | |
43aff26c | 8 | * Borislav Petkov <bp@alien8.de> |
30e1f7a8 BP |
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. | |
c0d12172 DJ |
13 | * |
14 | */ | |
15 | #include <linux/module.h> | |
16 | #include <linux/edac.h> | |
60063497 | 17 | #include <linux/atomic.h> |
51990e82 | 18 | #include <linux/device.h> |
c0d12172 DJ |
19 | |
20 | int edac_op_state = EDAC_OPSTATE_INVAL; | |
fb3fb206 | 21 | EXPORT_SYMBOL_GPL(edac_op_state); |
c0d12172 DJ |
22 | |
23 | atomic_t edac_handlers = ATOMIC_INIT(0); | |
fb3fb206 | 24 | EXPORT_SYMBOL_GPL(edac_handlers); |
c0d12172 | 25 | |
66ee2f94 | 26 | int edac_err_assert = 0; |
fb3fb206 | 27 | EXPORT_SYMBOL_GPL(edac_err_assert); |
c0d12172 | 28 | |
fe5ff8b8 | 29 | static atomic_t edac_subsys_valid = ATOMIC_INIT(0); |
30e1f7a8 | 30 | |
c700f013 CG |
31 | int edac_report_status = EDAC_REPORTING_ENABLED; |
32 | EXPORT_SYMBOL_GPL(edac_report_status); | |
33 | ||
34 | static 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 | ||
fb3fb206 DT |
50 | /* |
51 | * called to determine if there is an EDAC driver interested in | |
52 | * knowing an event (such as NMI) occurred | |
53 | */ | |
54 | int edac_handler_set(void) | |
c0d12172 DJ |
55 | { |
56 | if (edac_op_state == EDAC_OPSTATE_POLL) | |
57 | return 0; | |
58 | ||
59 | return atomic_read(&edac_handlers); | |
60 | } | |
fb3fb206 | 61 | EXPORT_SYMBOL_GPL(edac_handler_set); |
c0d12172 DJ |
62 | |
63 | /* | |
64 | * handler for NMI type of interrupts to assert error | |
65 | */ | |
fb3fb206 | 66 | void edac_atomic_assert_error(void) |
c0d12172 | 67 | { |
66ee2f94 | 68 | edac_err_assert++; |
c0d12172 | 69 | } |
fb3fb206 | 70 | EXPORT_SYMBOL_GPL(edac_atomic_assert_error); |
30e1f7a8 BP |
71 | |
72 | /* | |
73 | * sysfs object: /sys/devices/system/edac | |
74 | * need to export to other files | |
75 | */ | |
fe5ff8b8 | 76 | struct bus_type edac_subsys = { |
30e1f7a8 | 77 | .name = "edac", |
fe5ff8b8 | 78 | .dev_name = "edac", |
30e1f7a8 | 79 | }; |
fe5ff8b8 | 80 | EXPORT_SYMBOL_GPL(edac_subsys); |
30e1f7a8 BP |
81 | |
82 | /* return pointer to the 'edac' node in sysfs */ | |
fe5ff8b8 | 83 | struct bus_type *edac_get_sysfs_subsys(void) |
30e1f7a8 BP |
84 | { |
85 | int err = 0; | |
86 | ||
fe5ff8b8 | 87 | if (atomic_read(&edac_subsys_valid)) |
30e1f7a8 BP |
88 | goto out; |
89 | ||
90 | /* create the /sys/devices/system/edac directory */ | |
fe5ff8b8 | 91 | err = subsys_system_register(&edac_subsys, NULL); |
30e1f7a8 BP |
92 | if (err) { |
93 | printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n"); | |
94 | return NULL; | |
95 | } | |
96 | ||
97 | out: | |
fe5ff8b8 KS |
98 | atomic_inc(&edac_subsys_valid); |
99 | return &edac_subsys; | |
30e1f7a8 | 100 | } |
fe5ff8b8 | 101 | EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys); |
30e1f7a8 | 102 | |
fe5ff8b8 | 103 | void edac_put_sysfs_subsys(void) |
30e1f7a8 BP |
104 | { |
105 | /* last user unregisters it */ | |
fe5ff8b8 KS |
106 | if (atomic_dec_and_test(&edac_subsys_valid)) |
107 | bus_unregister(&edac_subsys); | |
30e1f7a8 | 108 | } |
fe5ff8b8 | 109 | EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys); |