[media] v4l2-ctrls/event: remove struct v4l2_ctrl_fh, instead use v4l2_subscribed_event
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / edac / mce_amd_inj.c
bloba4987e03f59e8b26416cc4d9b1559f0d0ea16c06
1 /*
2 * A simple MCE injection facility for testing the MCE decoding code. This
3 * driver should be built as module so that it can be loaded on production
4 * kernels for testing purposes.
6 * This file may be distributed under the terms of the GNU General Public
7 * License version 2.
9 * Copyright (c) 2010: Borislav Petkov <borislav.petkov@amd.com>
10 * Advanced Micro Devices Inc.
13 #include <linux/kobject.h>
14 #include <linux/sysdev.h>
15 #include <linux/edac.h>
16 #include <asm/mce.h>
18 #include "mce_amd.h"
20 struct edac_mce_attr {
21 struct attribute attr;
22 ssize_t (*show) (struct kobject *kobj, struct edac_mce_attr *attr, char *buf);
23 ssize_t (*store)(struct kobject *kobj, struct edac_mce_attr *attr,
24 const char *buf, size_t count);
27 #define EDAC_MCE_ATTR(_name, _mode, _show, _store) \
28 static struct edac_mce_attr mce_attr_##_name = __ATTR(_name, _mode, _show, _store)
30 static struct kobject *mce_kobj;
33 * Collect all the MCi_XXX settings
35 static struct mce i_mce;
37 #define MCE_INJECT_STORE(reg) \
38 static ssize_t edac_inject_##reg##_store(struct kobject *kobj, \
39 struct edac_mce_attr *attr, \
40 const char *data, size_t count)\
41 { \
42 int ret = 0; \
43 unsigned long value; \
45 ret = strict_strtoul(data, 16, &value); \
46 if (ret < 0) \
47 printk(KERN_ERR "Error writing MCE " #reg " field.\n"); \
49 i_mce.reg = value; \
51 return count; \
54 MCE_INJECT_STORE(status);
55 MCE_INJECT_STORE(misc);
56 MCE_INJECT_STORE(addr);
58 #define MCE_INJECT_SHOW(reg) \
59 static ssize_t edac_inject_##reg##_show(struct kobject *kobj, \
60 struct edac_mce_attr *attr, \
61 char *buf) \
62 { \
63 return sprintf(buf, "0x%016llx\n", i_mce.reg); \
66 MCE_INJECT_SHOW(status);
67 MCE_INJECT_SHOW(misc);
68 MCE_INJECT_SHOW(addr);
70 EDAC_MCE_ATTR(status, 0644, edac_inject_status_show, edac_inject_status_store);
71 EDAC_MCE_ATTR(misc, 0644, edac_inject_misc_show, edac_inject_misc_store);
72 EDAC_MCE_ATTR(addr, 0644, edac_inject_addr_show, edac_inject_addr_store);
75 * This denotes into which bank we're injecting and triggers
76 * the injection, at the same time.
78 static ssize_t edac_inject_bank_store(struct kobject *kobj,
79 struct edac_mce_attr *attr,
80 const char *data, size_t count)
82 int ret = 0;
83 unsigned long value;
85 ret = strict_strtoul(data, 10, &value);
86 if (ret < 0) {
87 printk(KERN_ERR "Invalid bank value!\n");
88 return -EINVAL;
91 if (value > 5)
92 if (boot_cpu_data.x86 != 0x15 || value > 6) {
93 printk(KERN_ERR "Non-existent MCE bank: %lu\n", value);
94 return -EINVAL;
97 i_mce.bank = value;
99 amd_decode_mce(NULL, 0, &i_mce);
101 return count;
104 static ssize_t edac_inject_bank_show(struct kobject *kobj,
105 struct edac_mce_attr *attr, char *buf)
107 return sprintf(buf, "%d\n", i_mce.bank);
110 EDAC_MCE_ATTR(bank, 0644, edac_inject_bank_show, edac_inject_bank_store);
112 static struct edac_mce_attr *sysfs_attrs[] = { &mce_attr_status, &mce_attr_misc,
113 &mce_attr_addr, &mce_attr_bank
116 static int __init edac_init_mce_inject(void)
118 struct sysdev_class *edac_class = NULL;
119 int i, err = 0;
121 edac_class = edac_get_sysfs_class();
122 if (!edac_class)
123 return -EINVAL;
125 mce_kobj = kobject_create_and_add("mce", &edac_class->kset.kobj);
126 if (!mce_kobj) {
127 printk(KERN_ERR "Error creating a mce kset.\n");
128 err = -ENOMEM;
129 goto err_mce_kobj;
132 for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) {
133 err = sysfs_create_file(mce_kobj, &sysfs_attrs[i]->attr);
134 if (err) {
135 printk(KERN_ERR "Error creating %s in sysfs.\n",
136 sysfs_attrs[i]->attr.name);
137 goto err_sysfs_create;
140 return 0;
142 err_sysfs_create:
143 while (--i >= 0)
144 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr);
146 kobject_del(mce_kobj);
148 err_mce_kobj:
149 edac_put_sysfs_class();
151 return err;
154 static void __exit edac_exit_mce_inject(void)
156 int i;
158 for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++)
159 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr);
161 kobject_del(mce_kobj);
163 edac_put_sysfs_class();
166 module_init(edac_init_mce_inject);
167 module_exit(edac_exit_mce_inject);
169 MODULE_LICENSE("GPL");
170 MODULE_AUTHOR("Borislav Petkov <borislav.petkov@amd.com>");
171 MODULE_AUTHOR("AMD Inc.");
172 MODULE_DESCRIPTION("MCE injection facility for testing MCE decoding");