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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * file for managing the edac_device subsystem of devices for EDAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * (C) 2007 SoftwareBitMaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This file may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Written Doug Thompson <norsk5@xmission.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/edac.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "edac_device.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "edac_module.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define EDAC_DEVICE_SYMLINK	"device"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define to_edacdev(k) container_of(k, struct edac_device_ctl_info, kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define to_edacdev_attr(a) container_of(a, struct edacdev_attribute, attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * Set of edac_device_ctl_info attribute store/show functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* 'log_ue' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static ssize_t edac_device_ctl_log_ue_show(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 					*ctl_info, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return sprintf(data, "%u\n", ctl_info->log_ue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static ssize_t edac_device_ctl_log_ue_store(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 					*ctl_info, const char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 					size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	/* if parameter is zero, turn off flag, if non-zero turn on flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	ctl_info->log_ue = (simple_strtoul(data, NULL, 0) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* 'log_ce' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static ssize_t edac_device_ctl_log_ce_show(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 					*ctl_info, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return sprintf(data, "%u\n", ctl_info->log_ce);
^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) static ssize_t edac_device_ctl_log_ce_store(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 					*ctl_info, const char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 					size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* if parameter is zero, turn off flag, if non-zero turn on flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	ctl_info->log_ce = (simple_strtoul(data, NULL, 0) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /* 'panic_on_ue' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static ssize_t edac_device_ctl_panic_on_ue_show(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 						*ctl_info, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return sprintf(data, "%u\n", ctl_info->panic_on_ue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static ssize_t edac_device_ctl_panic_on_ue_store(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 						 *ctl_info, const char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 						 size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* if parameter is zero, turn off flag, if non-zero turn on flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ctl_info->panic_on_ue = (simple_strtoul(data, NULL, 0) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return count;
^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) /* 'poll_msec' show and store functions*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static ssize_t edac_device_ctl_poll_msec_show(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 					*ctl_info, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return sprintf(data, "%u\n", ctl_info->poll_msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static ssize_t edac_device_ctl_poll_msec_store(struct edac_device_ctl_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 					*ctl_info, const char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 					size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* get the value and enforce that it is non-zero, must be at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 * one millisecond for the delay period, between scans
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * Then cancel last outstanding delay for the work request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 * and set a new one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	value = simple_strtoul(data, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	edac_device_reset_delay_period(ctl_info, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* edac_device_ctl_info specific attribute structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct ctl_info_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ssize_t(*show) (struct edac_device_ctl_info *, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	ssize_t(*store) (struct edac_device_ctl_info *, const char *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define to_ctl_info(k) container_of(k, struct edac_device_ctl_info, kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define to_ctl_info_attr(a) container_of(a,struct ctl_info_attribute,attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* Function to 'show' fields from the edac_dev 'ctl_info' structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static ssize_t edac_dev_ctl_info_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				struct attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (ctl_info_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return ctl_info_attr->show(edac_dev, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* Function to 'store' fields into the edac_dev 'ctl_info' structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (ctl_info_attr->store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return ctl_info_attr->store(edac_dev, buffer, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* edac_dev file operations for an 'ctl_info' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static const struct sysfs_ops device_ctl_info_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	.show = edac_dev_ctl_info_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	.store = edac_dev_ctl_info_store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define CTL_INFO_ATTR(_name,_mode,_show,_store)        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static struct ctl_info_attribute attr_ctl_info_##_name = {      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	.attr = {.name = __stringify(_name), .mode = _mode },   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.show   = _show,                                        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.store  = _store,                                       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* Declare the various ctl_info attributes here and their respective ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) CTL_INFO_ATTR(log_ue, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	edac_device_ctl_log_ue_show, edac_device_ctl_log_ue_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) CTL_INFO_ATTR(log_ce, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	edac_device_ctl_log_ce_show, edac_device_ctl_log_ce_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) CTL_INFO_ATTR(panic_on_ue, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	edac_device_ctl_panic_on_ue_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	edac_device_ctl_panic_on_ue_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) CTL_INFO_ATTR(poll_msec, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	edac_device_ctl_poll_msec_show, edac_device_ctl_poll_msec_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* Base Attributes of the EDAC_DEVICE ECC object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static struct ctl_info_attribute *device_ctrl_attr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	&attr_ctl_info_panic_on_ue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	&attr_ctl_info_log_ue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	&attr_ctl_info_log_ce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	&attr_ctl_info_poll_msec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * edac_device_ctrl_master_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  *	called when the reference count for the 'main' kobj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *	for a edac_device control struct reaches zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *	Reference count model:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *		One 'main' kobject for each control structure allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *		That main kobj is initially set to one AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *		the reference count for the EDAC 'core' module is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *		bumped by one, thus added 'keep in memory' dependency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *		Each new internal kobj (in instances and blocks) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *		bumps the 'main' kobject.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *		When they are released their release functions decrement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  *		the 'main' kobj.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  *		When the main kobj reaches zero (0) then THIS function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  *		is called which then decrements the EDAC 'core' module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *		When the module reference count reaches zero then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  *		module no longer has dependency on keeping the release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *		function code in memory and module can be unloaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *		This will support several control objects as well, each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  *		with its own 'main' kobj.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static void edac_device_ctrl_master_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct edac_device_ctl_info *edac_dev = to_edacdev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	edac_dbg(4, "control index=%d\n", edac_dev->dev_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* decrement the EDAC CORE module ref count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	module_put(edac_dev->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/* free the control struct containing the 'main' kobj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	 * passed in to this routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	kfree(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* ktype for the main (master) kobject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static struct kobj_type ktype_device_ctrl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	.release = edac_device_ctrl_master_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	.sysfs_ops = &device_ctl_info_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	.default_attrs = (struct attribute **)device_ctrl_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * edac_device_register_sysfs_main_kobj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  *	perform the high level setup for the new edac_device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Return:  0 SUCCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *         !0 FAILURE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct bus_type *edac_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	edac_dbg(1, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* get the /sys/devices/system/edac reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	edac_subsys = edac_get_sysfs_subsys();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/* Point to the 'edac_subsys' this instance 'reports' to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	edac_dev->edac_subsys = edac_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* Init the devices's kobject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	memset(&edac_dev->kobj, 0, sizeof(struct kobject));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* Record which module 'owns' this control structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * and bump the ref count of the module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	edac_dev->owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (!try_module_get(edac_dev->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				   &edac_subsys->dev_root->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				   "%s", edac_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		edac_dbg(1, "Failed to register '.../edac/%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			 edac_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		goto err_kobj_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	kobject_uevent(&edac_dev->kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* At this point, to 'free' the control struct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	 * edac_device_unregister_sysfs_main_kobj() must be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	edac_dbg(4, "Registered '.../edac/%s' kobject\n", edac_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	/* Error exit stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err_kobj_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	kobject_put(&edac_dev->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	module_put(edac_dev->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * edac_device_unregister_sysfs_main_kobj:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  *	the '..../edac/<name>' kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	edac_dbg(0, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	edac_dbg(4, "name of kobject is: %s\n", kobject_name(&dev->kobj));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * Unregister the edac device's kobject and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 * allow for reference count to reach 0 at which point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 * the callback will be called to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 *   a) module_put() this module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	 *   b) 'kfree' the memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	kobject_put(&dev->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* edac_dev -> instance information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * Set of low-level instance attribute show functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static ssize_t instance_ue_count_show(struct edac_device_instance *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 				char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return sprintf(data, "%u\n", instance->counters.ue_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static ssize_t instance_ce_count_show(struct edac_device_instance *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return sprintf(data, "%u\n", instance->counters.ce_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define to_instance(k) container_of(k, struct edac_device_instance, kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #define to_instance_attr(a) container_of(a,struct instance_attribute,attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* DEVICE instance kobject release() function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static void edac_device_ctrl_instance_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	struct edac_device_instance *instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	edac_dbg(1, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	/* map from this kobj to the main control struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	 * and then dec the main kobj count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	instance = to_instance(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	kobject_put(&instance->ctl->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* instance specific attribute structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct instance_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	ssize_t(*show) (struct edac_device_instance *, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	ssize_t(*store) (struct edac_device_instance *, const char *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /* Function to 'show' fields from the edac_dev 'instance' structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static ssize_t edac_dev_instance_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				struct attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	struct edac_device_instance *instance = to_instance(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct instance_attribute *instance_attr = to_instance_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (instance_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		return instance_attr->show(instance, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /* Function to 'store' fields into the edac_dev 'instance' structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static ssize_t edac_dev_instance_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 				struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 				const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct edac_device_instance *instance = to_instance(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct instance_attribute *instance_attr = to_instance_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (instance_attr->store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return instance_attr->store(instance, buffer, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /* edac_dev file operations for an 'instance' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static const struct sysfs_ops device_instance_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.show = edac_dev_instance_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.store = edac_dev_instance_store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define INSTANCE_ATTR(_name,_mode,_show,_store)        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static struct instance_attribute attr_instance_##_name = {      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.attr = {.name = __stringify(_name), .mode = _mode },   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	.show   = _show,                                        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	.store  = _store,                                       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * Define attributes visible for the edac_device instance object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  *	Each contains a pointer to a show and an optional set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  *	function pointer that does the low level output/input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) INSTANCE_ATTR(ce_count, S_IRUGO, instance_ce_count_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) INSTANCE_ATTR(ue_count, S_IRUGO, instance_ue_count_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* list of edac_dev 'instance' attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static struct instance_attribute *device_instance_attr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	&attr_instance_ce_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	&attr_instance_ue_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* The 'ktype' for each edac_dev 'instance' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static struct kobj_type ktype_instance_ctrl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	.release = edac_device_ctrl_instance_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	.sysfs_ops = &device_instance_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	.default_attrs = (struct attribute **)device_instance_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* edac_dev -> instance -> block information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #define to_block(k) container_of(k, struct edac_device_block, kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #define to_block_attr(a) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	container_of(a, struct edac_dev_sysfs_block_attribute, attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  * Set of low-level block attribute show functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static ssize_t block_ue_count_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 					struct attribute *attr, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct edac_device_block *block = to_block(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return sprintf(data, "%u\n", block->counters.ue_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static ssize_t block_ce_count_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 					struct attribute *attr, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	struct edac_device_block *block = to_block(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return sprintf(data, "%u\n", block->counters.ce_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* DEVICE block kobject release() function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static void edac_device_ctrl_block_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct edac_device_block *block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	edac_dbg(1, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	/* get the container of the kobj */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	block = to_block(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	/* map from 'block kobj' to 'block->instance->controller->main_kobj'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	 * now 'release' the block kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	kobject_put(&block->instance->ctl->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /* Function to 'show' fields from the edac_dev 'block' structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static ssize_t edac_dev_block_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				struct attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct edac_dev_sysfs_block_attribute *block_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 						to_block_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (block_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		return block_attr->show(kobj, attr, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* Function to 'store' fields into the edac_dev 'block' structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static ssize_t edac_dev_block_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	struct edac_dev_sysfs_block_attribute *block_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	block_attr = to_block_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (block_attr->store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return block_attr->store(kobj, attr, buffer, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* edac_dev file operations for a 'block' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static const struct sysfs_ops device_block_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	.show = edac_dev_block_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	.store = edac_dev_block_store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #define BLOCK_ATTR(_name,_mode,_show,_store)        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static struct edac_dev_sysfs_block_attribute attr_block_##_name = {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	.attr = {.name = __stringify(_name), .mode = _mode },   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	.show   = _show,                                        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	.store  = _store,                                       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) BLOCK_ATTR(ce_count, S_IRUGO, block_ce_count_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) BLOCK_ATTR(ue_count, S_IRUGO, block_ue_count_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* list of edac_dev 'block' attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static struct edac_dev_sysfs_block_attribute *device_block_attr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	&attr_block_ce_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	&attr_block_ue_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* The 'ktype' for each edac_dev 'block' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static struct kobj_type ktype_block_ctrl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	.release = edac_device_ctrl_block_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	.sysfs_ops = &device_block_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	.default_attrs = (struct attribute **)device_block_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /* block ctor/dtor  code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * edac_device_create_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 				struct edac_device_instance *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 				struct edac_device_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	struct edac_dev_sysfs_block_attribute *sysfs_attrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	struct kobject *main_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	edac_dbg(4, "Instance '%s' inst_p=%p  block '%s'  block_p=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		 instance->name, instance, block->name, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	edac_dbg(4, "block kobj=%p  block kobj->parent=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		 &block->kobj, &block->kobj.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	/* init this block's kobject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	memset(&block->kobj, 0, sizeof(struct kobject));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	/* bump the main kobject's reference count for this controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	 * and this instance is dependent on the main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	main_kobj = kobject_get(&edac_dev->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (!main_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	/* Add this block's kobject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 				   &instance->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 				   "%s", block->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		edac_dbg(1, "Failed to register instance '%s'\n", block->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		kobject_put(main_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	/* If there are driver level block attributes, then added them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	 * to the block kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	sysfs_attrib = block->block_attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	if (sysfs_attrib && block->nr_attribs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			edac_dbg(4, "creating block attrib='%s' attrib->%p to kobj=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 				 sysfs_attrib->attr.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 				 sysfs_attrib, &block->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			/* Create each block_attribute file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			err = sysfs_create_file(&block->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 				&sysfs_attrib->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 				goto err_on_attrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	kobject_uevent(&block->kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	/* Error unwind stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) err_on_attrib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	kobject_put(&block->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)  * edac_device_delete_block(edac_dev,block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 				struct edac_device_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	struct edac_dev_sysfs_block_attribute *sysfs_attrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	/* if this block has 'attributes' then we need to iterate over the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	 * and 'remove' the attributes on this block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	sysfs_attrib = block->block_attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (sysfs_attrib && block->nr_attribs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 			/* remove each block_attrib file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 			sysfs_remove_file(&block->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 				(struct attribute *) sysfs_attrib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	/* unregister this block's kobject, SEE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	 *	edac_device_ctrl_block_release() callback operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	kobject_put(&block->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* instance ctor/dtor code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)  * edac_device_create_instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)  *	create just one instance of an edac_device 'instance'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 				int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	struct edac_device_instance *instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	struct kobject *main_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	instance = &edac_dev->instances[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	/* Init the instance's kobject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	memset(&instance->kobj, 0, sizeof(struct kobject));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	instance->ctl = edac_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	/* bump the main kobject's reference count for this controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	 * and this instance is dependent on the main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	main_kobj = kobject_get(&edac_dev->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (!main_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	/* Formally register this instance's kobject under the edac_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 				   &edac_dev->kobj, "%s", instance->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		edac_dbg(2, "Failed to register instance '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 			 instance->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		kobject_put(main_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	edac_dbg(4, "now register '%d' blocks for instance %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		 instance->nr_blocks, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	/* register all blocks of this instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	for (i = 0; i < instance->nr_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		err = edac_device_create_block(edac_dev, instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 						&instance->blocks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 			/* If any fail, remove all previous ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 			for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 				edac_device_delete_block(edac_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 							&instance->blocks[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 			goto err_release_instance_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	kobject_uevent(&instance->kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	edac_dbg(4, "Registered instance %d '%s' kobject\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		 idx, instance->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	/* error unwind stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) err_release_instance_kobj:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	kobject_put(&instance->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)  * edac_device_remove_instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)  *	remove an edac_device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 					int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct edac_device_instance *instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	instance = &edac_dev->instances[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* unregister all blocks in this instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	for (i = 0; i < instance->nr_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		edac_device_delete_block(edac_dev, &instance->blocks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	/* unregister this instance's kobject, SEE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	 *	edac_device_ctrl_instance_release() for callback operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	kobject_put(&instance->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)  * edac_device_create_instances
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)  *	create the first level of 'instances' for this device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  *	(ie  'cache' might have 'cache0', 'cache1', 'cache2', etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static int edac_device_create_instances(struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	edac_dbg(0, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	/* iterate over creation of the instances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	for (i = 0; i < edac_dev->nr_instances; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		err = edac_device_create_instance(edac_dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 			/* unwind previous instances on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 				edac_device_delete_instance(edac_dev, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)  * edac_device_delete_instances(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)  *	unregister all the kobjects of the instances
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static void edac_device_delete_instances(struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	/* iterate over creation of the instances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	for (i = 0; i < edac_dev->nr_instances; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		edac_device_delete_instance(edac_dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /* edac_dev sysfs ctor/dtor  code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)  * edac_device_add_main_sysfs_attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)  *	add some attributes to this instance's main kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) static int edac_device_add_main_sysfs_attributes(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	struct edac_dev_sysfs_attribute *sysfs_attrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	sysfs_attrib = edac_dev->sysfs_attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	if (sysfs_attrib) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 		/* iterate over the array and create an attribute for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		 * entry in the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		while (sysfs_attrib->attr.name != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 			err = sysfs_create_file(&edac_dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 				(struct attribute*) sysfs_attrib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 			sysfs_attrib++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)  * edac_device_remove_main_sysfs_attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)  *	remove any attributes to this instance's main kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) static void edac_device_remove_main_sysfs_attributes(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 			struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	struct edac_dev_sysfs_attribute *sysfs_attrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	/* if there are main attributes, defined, remove them. First,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	 * point to the start of the array and iterate over it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	 * removing each attribute listed from this device's instance's kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	sysfs_attrib = edac_dev->sysfs_attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	if (sysfs_attrib) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		while (sysfs_attrib->attr.name != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			sysfs_remove_file(&edac_dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 					(struct attribute *) sysfs_attrib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 			sysfs_attrib++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)  * edac_device_create_sysfs() Constructor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)  * accept a created edac_device control structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)  * and 'export' it to sysfs. The 'main' kobj should already have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)  * created. 'instance' and 'block' kobjects should be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)  * along with any 'block' attributes from the low driver. In addition,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)  * the main attributes (if any) are connected to the main kobject of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)  * the control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)  *	0	Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)  *	!0	Failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	struct kobject *edac_kobj = &edac_dev->kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	edac_dbg(0, "idx=%d\n", edac_dev->dev_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	/*  go create any main attributes callers wants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	err = edac_device_add_main_sysfs_attributes(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 		edac_dbg(0, "failed to add sysfs attribs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	/* create a symlink from the edac device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	 * to the platform 'device' being used for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	err = sysfs_create_link(edac_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 				&edac_dev->dev->kobj, EDAC_DEVICE_SYMLINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		edac_dbg(0, "sysfs_create_link() returned err= %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		goto err_remove_main_attribs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	/* Create the first level instance directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	 * In turn, the nested blocks beneath the instances will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	 * be registered as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	err = edac_device_create_instances(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 		edac_dbg(0, "edac_device_create_instances() returned err= %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 			 err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		goto err_remove_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	edac_dbg(4, "create-instances done, idx=%d\n", edac_dev->dev_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	/* Error unwind stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) err_remove_link:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	/* remove the sym link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) err_remove_main_attribs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	edac_device_remove_main_sysfs_attributes(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)  * edac_device_remove_sysfs() destructor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)  * given an edac_device struct, tear down the kobject resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	edac_dbg(0, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	/* remove any main attributes for this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	edac_device_remove_main_sysfs_attributes(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	/* remove the device sym link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	/* walk the instance/block kobject tree, deconstructing it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	edac_device_delete_instances(edac_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }