blob: 6c86f6e545587202d3a9f729457ef38314490f70 [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.
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 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
Doug Thompsonfb3fb202007-07-19 01:50:30 -070032/*
33 * called to determine if there is an EDAC driver interested in
34 * knowing an event (such as NMI) occurred
35 */
36int edac_handler_set(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070037{
38 if (edac_op_state == EDAC_OPSTATE_POLL)
39 return 0;
40
41 return atomic_read(&edac_handlers);
42}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070043EXPORT_SYMBOL_GPL(edac_handler_set);
Dave Jiangc0d12172007-07-19 01:49:46 -070044
45/*
46 * handler for NMI type of interrupts to assert error
47 */
Doug Thompsonfb3fb202007-07-19 01:50:30 -070048void edac_atomic_assert_error(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070049{
Dave Jiang66ee2f92007-07-19 01:49:54 -070050 edac_err_assert++;
Dave Jiangc0d12172007-07-19 01:49:46 -070051}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070052EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020053
54/*
55 * sysfs object: /sys/devices/system/edac
56 * need to export to other files
57 */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080058struct bus_type edac_subsys = {
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020059 .name = "edac",
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080060 .dev_name = "edac",
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020061};
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080062EXPORT_SYMBOL_GPL(edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020063
64/* return pointer to the 'edac' node in sysfs */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080065struct bus_type *edac_get_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020066{
67 int err = 0;
68
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080069 if (atomic_read(&edac_subsys_valid))
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020070 goto out;
71
72 /* create the /sys/devices/system/edac directory */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080073 err = subsys_system_register(&edac_subsys, NULL);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020074 if (err) {
75 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
76 return NULL;
77 }
78
79out:
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080080 atomic_inc(&edac_subsys_valid);
81 return &edac_subsys;
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020082}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080083EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020084
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080085void edac_put_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020086{
87 /* last user unregisters it */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080088 if (atomic_dec_and_test(&edac_subsys_valid))
89 bus_unregister(&edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020090}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080091EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);