blob: 670c4481453bc2ba7dc690bb505097cfdfa1dca4 [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>
Dave Jiangc0d12172007-07-19 01:49:46 -070018#include <asm/edac.h>
19
20int edac_op_state = EDAC_OPSTATE_INVAL;
Doug Thompsonfb3fb202007-07-19 01:50:30 -070021EXPORT_SYMBOL_GPL(edac_op_state);
Dave Jiangc0d12172007-07-19 01:49:46 -070022
23atomic_t edac_handlers = ATOMIC_INIT(0);
Doug Thompsonfb3fb202007-07-19 01:50:30 -070024EXPORT_SYMBOL_GPL(edac_handlers);
Dave Jiangc0d12172007-07-19 01:49:46 -070025
Dave Jiang66ee2f92007-07-19 01:49:54 -070026int edac_err_assert = 0;
Doug Thompsonfb3fb202007-07-19 01:50:30 -070027EXPORT_SYMBOL_GPL(edac_err_assert);
Dave Jiangc0d12172007-07-19 01:49:46 -070028
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080029static atomic_t edac_subsys_valid = ATOMIC_INIT(0);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020030
Doug Thompsonfb3fb202007-07-19 01:50:30 -070031/*
32 * called to determine if there is an EDAC driver interested in
33 * knowing an event (such as NMI) occurred
34 */
35int edac_handler_set(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070036{
37 if (edac_op_state == EDAC_OPSTATE_POLL)
38 return 0;
39
40 return atomic_read(&edac_handlers);
41}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070042EXPORT_SYMBOL_GPL(edac_handler_set);
Dave Jiangc0d12172007-07-19 01:49:46 -070043
44/*
45 * handler for NMI type of interrupts to assert error
46 */
Doug Thompsonfb3fb202007-07-19 01:50:30 -070047void edac_atomic_assert_error(void)
Dave Jiangc0d12172007-07-19 01:49:46 -070048{
Dave Jiang66ee2f92007-07-19 01:49:54 -070049 edac_err_assert++;
Dave Jiangc0d12172007-07-19 01:49:46 -070050}
Doug Thompsonfb3fb202007-07-19 01:50:30 -070051EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020052
53/*
54 * sysfs object: /sys/devices/system/edac
55 * need to export to other files
56 */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080057struct bus_type edac_subsys = {
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020058 .name = "edac",
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080059 .dev_name = "edac",
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020060};
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080061EXPORT_SYMBOL_GPL(edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020062
63/* return pointer to the 'edac' node in sysfs */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080064struct bus_type *edac_get_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020065{
66 int err = 0;
67
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080068 if (atomic_read(&edac_subsys_valid))
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020069 goto out;
70
71 /* create the /sys/devices/system/edac directory */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080072 err = subsys_system_register(&edac_subsys, NULL);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020073 if (err) {
74 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
75 return NULL;
76 }
77
78out:
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080079 atomic_inc(&edac_subsys_valid);
80 return &edac_subsys;
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020081}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080082EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020083
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080084void edac_put_sysfs_subsys(void)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020085{
86 /* last user unregisters it */
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080087 if (atomic_dec_and_test(&edac_subsys_valid))
88 bus_unregister(&edac_subsys);
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020089}
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080090EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);