Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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