1 #include "edac_module.h" 2 3 static struct dentry *edac_debugfs; 4 5 static ssize_t edac_fake_inject_write(struct file *file, 6 const char __user *data, 7 size_t count, loff_t *ppos) 8 { 9 struct device *dev = file->private_data; 10 struct mem_ctl_info *mci = to_mci(dev); 11 static enum hw_event_mc_err_type type; 12 u16 errcount = mci->fake_inject_count; 13 14 if (!errcount) 15 errcount = 1; 16 17 type = mci->fake_inject_ue ? HW_EVENT_ERR_UNCORRECTED 18 : HW_EVENT_ERR_CORRECTED; 19 20 printk(KERN_DEBUG 21 "Generating %d %s fake error%s to %d.%d.%d to test core handling. NOTE: this won't test the driver-specific decoding logic.\n", 22 errcount, 23 (type == HW_EVENT_ERR_UNCORRECTED) ? "UE" : "CE", 24 errcount > 1 ? "s" : "", 25 mci->fake_inject_layer[0], 26 mci->fake_inject_layer[1], 27 mci->fake_inject_layer[2] 28 ); 29 edac_mc_handle_error(type, mci, errcount, 0, 0, 0, 30 mci->fake_inject_layer[0], 31 mci->fake_inject_layer[1], 32 mci->fake_inject_layer[2], 33 "FAKE ERROR", "for EDAC testing only"); 34 35 return count; 36 } 37 38 static const struct file_operations debug_fake_inject_fops = { 39 .open = simple_open, 40 .write = edac_fake_inject_write, 41 .llseek = generic_file_llseek, 42 }; 43 44 int __init edac_debugfs_init(void) 45 { 46 edac_debugfs = debugfs_create_dir("edac", NULL); 47 if (IS_ERR(edac_debugfs)) { 48 edac_debugfs = NULL; 49 return -ENOMEM; 50 } 51 return 0; 52 } 53 54 void edac_debugfs_exit(void) 55 { 56 debugfs_remove(edac_debugfs); 57 } 58 59 int edac_create_debugfs_nodes(struct mem_ctl_info *mci) 60 { 61 struct dentry *d, *parent; 62 char name[80]; 63 int i; 64 65 if (!edac_debugfs) 66 return -ENODEV; 67 68 d = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs); 69 if (!d) 70 return -ENOMEM; 71 parent = d; 72 73 for (i = 0; i < mci->n_layers; i++) { 74 sprintf(name, "fake_inject_%s", 75 edac_layer_name[mci->layers[i].type]); 76 d = debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent, 77 &mci->fake_inject_layer[i]); 78 if (!d) 79 goto nomem; 80 } 81 82 d = debugfs_create_bool("fake_inject_ue", S_IRUGO | S_IWUSR, parent, 83 &mci->fake_inject_ue); 84 if (!d) 85 goto nomem; 86 87 d = debugfs_create_u16("fake_inject_count", S_IRUGO | S_IWUSR, parent, 88 &mci->fake_inject_count); 89 if (!d) 90 goto nomem; 91 92 d = debugfs_create_file("fake_inject", S_IWUSR, parent, 93 &mci->dev, 94 &debug_fake_inject_fops); 95 if (!d) 96 goto nomem; 97 98 mci->debugfs = parent; 99 return 0; 100 nomem: 101 edac_debugfs_remove_recursive(mci->debugfs); 102 return -ENOMEM; 103 } 104 105 /* Create a toplevel dir under EDAC's debugfs hierarchy */ 106 struct dentry *edac_debugfs_create_dir(const char *dirname) 107 { 108 if (!edac_debugfs) 109 return NULL; 110 111 return debugfs_create_dir(dirname, edac_debugfs); 112 } 113 EXPORT_SYMBOL_GPL(edac_debugfs_create_dir); 114 115 /* Create a toplevel dir under EDAC's debugfs hierarchy with parent @parent */ 116 struct dentry * 117 edac_debugfs_create_dir_at(const char *dirname, struct dentry *parent) 118 { 119 return debugfs_create_dir(dirname, parent); 120 } 121 EXPORT_SYMBOL_GPL(edac_debugfs_create_dir_at); 122 123 /* 124 * Create a file under EDAC's hierarchy or a sub-hierarchy: 125 * 126 * @name: file name 127 * @mode: file permissions 128 * @parent: parent dentry. If NULL, it becomes the toplevel EDAC dir 129 * @data: private data of caller 130 * @fops: file operations of this file 131 */ 132 struct dentry * 133 edac_debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, 134 void *data, const struct file_operations *fops) 135 { 136 if (!parent) 137 parent = edac_debugfs; 138 139 return debugfs_create_file(name, mode, parent, data, fops); 140 } 141 EXPORT_SYMBOL_GPL(edac_debugfs_create_file); 142 143 /* Wrapper for debugfs_create_x8() */ 144 struct dentry *edac_debugfs_create_x8(const char *name, umode_t mode, 145 struct dentry *parent, u8 *value) 146 { 147 if (!parent) 148 parent = edac_debugfs; 149 150 return debugfs_create_x8(name, mode, parent, value); 151 } 152 EXPORT_SYMBOL_GPL(edac_debugfs_create_x8); 153 154 /* Wrapper for debugfs_create_x16() */ 155 struct dentry *edac_debugfs_create_x16(const char *name, umode_t mode, 156 struct dentry *parent, u16 *value) 157 { 158 if (!parent) 159 parent = edac_debugfs; 160 161 return debugfs_create_x16(name, mode, parent, value); 162 } 163 EXPORT_SYMBOL_GPL(edac_debugfs_create_x16); 164