1 #include "edac_module.h"
3 static struct dentry
*edac_debugfs
;
5 static ssize_t
edac_fake_inject_write(struct file
*file
,
6 const char __user
*data
,
7 size_t count
, loff_t
*ppos
)
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
;
17 type
= mci
->fake_inject_ue
? HW_EVENT_ERR_UNCORRECTED
18 : HW_EVENT_ERR_CORRECTED
;
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",
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]
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");
38 static const struct file_operations debug_fake_inject_fops
= {
40 .write
= edac_fake_inject_write
,
41 .llseek
= generic_file_llseek
,
44 int __init
edac_debugfs_init(void)
46 edac_debugfs
= debugfs_create_dir("edac", NULL
);
47 if (IS_ERR(edac_debugfs
)) {
54 void edac_debugfs_exit(void)
56 debugfs_remove_recursive(edac_debugfs
);
59 int edac_create_debugfs_nodes(struct mem_ctl_info
*mci
)
61 struct dentry
*d
, *parent
;
68 d
= debugfs_create_dir(mci
->dev
.kobj
.name
, edac_debugfs
);
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
]);
82 d
= debugfs_create_bool("fake_inject_ue", S_IRUGO
| S_IWUSR
, parent
,
83 &mci
->fake_inject_ue
);
87 d
= debugfs_create_u16("fake_inject_count", S_IRUGO
| S_IWUSR
, parent
,
88 &mci
->fake_inject_count
);
92 d
= debugfs_create_file("fake_inject", S_IWUSR
, parent
,
94 &debug_fake_inject_fops
);
98 mci
->debugfs
= parent
;
101 edac_debugfs_remove_recursive(mci
->debugfs
);
105 /* Create a toplevel dir under EDAC's debugfs hierarchy */
106 struct dentry
*edac_debugfs_create_dir(const char *dirname
)
111 return debugfs_create_dir(dirname
, edac_debugfs
);
113 EXPORT_SYMBOL_GPL(edac_debugfs_create_dir
);
115 /* Create a toplevel dir under EDAC's debugfs hierarchy with parent @parent */
117 edac_debugfs_create_dir_at(const char *dirname
, struct dentry
*parent
)
119 return debugfs_create_dir(dirname
, parent
);
121 EXPORT_SYMBOL_GPL(edac_debugfs_create_dir_at
);
124 * Create a file under EDAC's hierarchy or a sub-hierarchy:
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
133 edac_debugfs_create_file(const char *name
, umode_t mode
, struct dentry
*parent
,
134 void *data
, const struct file_operations
*fops
)
137 parent
= edac_debugfs
;
139 return debugfs_create_file(name
, mode
, parent
, data
, fops
);
141 EXPORT_SYMBOL_GPL(edac_debugfs_create_file
);
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
)
148 parent
= edac_debugfs
;
150 return debugfs_create_x8(name
, mode
, parent
, value
);
152 EXPORT_SYMBOL_GPL(edac_debugfs_create_x8
);
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
)
159 parent
= edac_debugfs
;
161 return debugfs_create_x16(name
, mode
, parent
, value
);
163 EXPORT_SYMBOL_GPL(edac_debugfs_create_x16
);