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 void __init edac_debugfs_init(void) 45 { 46 edac_debugfs = debugfs_create_dir("edac", NULL); 47 } 48 49 void edac_debugfs_exit(void) 50 { 51 debugfs_remove_recursive(edac_debugfs); 52 } 53 54 void edac_create_debugfs_nodes(struct mem_ctl_info *mci) 55 { 56 struct dentry *parent; 57 char name[80]; 58 int i; 59 60 parent = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs); 61 62 for (i = 0; i < mci->n_layers; i++) { 63 sprintf(name, "fake_inject_%s", 64 edac_layer_name[mci->layers[i].type]); 65 debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent, 66 &mci->fake_inject_layer[i]); 67 } 68 69 debugfs_create_bool("fake_inject_ue", S_IRUGO | S_IWUSR, parent, 70 &mci->fake_inject_ue); 71 72 debugfs_create_u16("fake_inject_count", S_IRUGO | S_IWUSR, parent, 73 &mci->fake_inject_count); 74 75 debugfs_create_file("fake_inject", S_IWUSR, parent, &mci->dev, 76 &debug_fake_inject_fops); 77 78 mci->debugfs = parent; 79 } 80 81 /* Create a toplevel dir under EDAC's debugfs hierarchy */ 82 struct dentry *edac_debugfs_create_dir(const char *dirname) 83 { 84 if (!edac_debugfs) 85 return NULL; 86 87 return debugfs_create_dir(dirname, edac_debugfs); 88 } 89 EXPORT_SYMBOL_GPL(edac_debugfs_create_dir); 90 91 /* Create a toplevel dir under EDAC's debugfs hierarchy with parent @parent */ 92 struct dentry * 93 edac_debugfs_create_dir_at(const char *dirname, struct dentry *parent) 94 { 95 return debugfs_create_dir(dirname, parent); 96 } 97 EXPORT_SYMBOL_GPL(edac_debugfs_create_dir_at); 98 99 /* 100 * Create a file under EDAC's hierarchy or a sub-hierarchy: 101 * 102 * @name: file name 103 * @mode: file permissions 104 * @parent: parent dentry. If NULL, it becomes the toplevel EDAC dir 105 * @data: private data of caller 106 * @fops: file operations of this file 107 */ 108 struct dentry * 109 edac_debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, 110 void *data, const struct file_operations *fops) 111 { 112 if (!parent) 113 parent = edac_debugfs; 114 115 return debugfs_create_file(name, mode, parent, data, fops); 116 } 117 EXPORT_SYMBOL_GPL(edac_debugfs_create_file); 118 119 /* Wrapper for debugfs_create_x8() */ 120 struct dentry *edac_debugfs_create_x8(const char *name, umode_t mode, 121 struct dentry *parent, u8 *value) 122 { 123 if (!parent) 124 parent = edac_debugfs; 125 126 return debugfs_create_x8(name, mode, parent, value); 127 } 128 EXPORT_SYMBOL_GPL(edac_debugfs_create_x8); 129 130 /* Wrapper for debugfs_create_x16() */ 131 struct dentry *edac_debugfs_create_x16(const char *name, umode_t mode, 132 struct dentry *parent, u16 *value) 133 { 134 if (!parent) 135 parent = edac_debugfs; 136 137 return debugfs_create_x16(name, mode, parent, value); 138 } 139 EXPORT_SYMBOL_GPL(edac_debugfs_create_x16); 140