drivers/edac/ecs.c

Source file repositories/reference/linux-study-clean/drivers/edac/ecs.c

File Facts

System
Linux kernel
Corpus path
drivers/edac/ecs.c
Extension
.c
Size
5865 bytes
Lines
208
Domain
Driver Families
Bucket
drivers/edac
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct edac_ecs_dev_attr {
	struct device_attribute dev_attr;
	int fru_id;
};

struct edac_ecs_fru_context {
	char name[EDAC_FEAT_NAME_LEN];
	struct edac_ecs_dev_attr dev_attr[ECS_MAX_ATTRS];
	struct attribute *ecs_attrs[ECS_MAX_ATTRS + 1];
	struct attribute_group group;
};

struct edac_ecs_context {
	u16 num_media_frus;
	struct edac_ecs_fru_context *fru_ctxs;
};

#define TO_ECS_DEV_ATTR(_dev_attr)	\
	container_of(_dev_attr, struct edac_ecs_dev_attr, dev_attr)

#define EDAC_ECS_ATTR_SHOW(attrib, cb, type, format)				\
static ssize_t attrib##_show(struct device *ras_feat_dev,			\
			     struct device_attribute *attr, char *buf)		\
{										\
	struct edac_ecs_dev_attr *dev_attr = TO_ECS_DEV_ATTR(attr);		\
	struct edac_dev_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev);		\
	const struct edac_ecs_ops *ops = ctx->ecs.ecs_ops;			\
	type data;								\
	int ret;								\
										\
	ret = ops->cb(ras_feat_dev->parent, ctx->ecs.private,			\
		      dev_attr->fru_id, &data);					\
	if (ret)								\
		return ret;							\
										\
	return sysfs_emit(buf, format, data);					\
}

EDAC_ECS_ATTR_SHOW(log_entry_type, get_log_entry_type, u32, "%u\n")
EDAC_ECS_ATTR_SHOW(mode, get_mode, u32, "%u\n")
EDAC_ECS_ATTR_SHOW(threshold, get_threshold, u32, "%u\n")

#define EDAC_ECS_ATTR_STORE(attrib, cb, type, conv_func)			\
static ssize_t attrib##_store(struct device *ras_feat_dev,			\
			      struct device_attribute *attr,			\
			      const char *buf, size_t len)			\
{										\
	struct edac_ecs_dev_attr *dev_attr = TO_ECS_DEV_ATTR(attr);		\
	struct edac_dev_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev);		\
	const struct edac_ecs_ops *ops = ctx->ecs.ecs_ops;			\
	type data;								\
	int ret;								\
										\
	ret = conv_func(buf, 0, &data);						\
	if (ret < 0)								\
		return ret;							\
										\
	ret = ops->cb(ras_feat_dev->parent, ctx->ecs.private,			\
		      dev_attr->fru_id, data);					\
	if (ret)								\
		return ret;							\
										\
	return len;								\
}

EDAC_ECS_ATTR_STORE(log_entry_type, set_log_entry_type, unsigned long, kstrtoul)
EDAC_ECS_ATTR_STORE(mode, set_mode, unsigned long, kstrtoul)
EDAC_ECS_ATTR_STORE(reset, reset, unsigned long, kstrtoul)
EDAC_ECS_ATTR_STORE(threshold, set_threshold, unsigned long, kstrtoul)

static umode_t ecs_attr_visible(struct kobject *kobj, struct attribute *a, int attr_id)
{
	struct device *ras_feat_dev = kobj_to_dev(kobj);
	struct edac_dev_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev);
	const struct edac_ecs_ops *ops = ctx->ecs.ecs_ops;

	switch (attr_id) {
	case ECS_LOG_ENTRY_TYPE:
		if (ops->get_log_entry_type)  {
			if (ops->set_log_entry_type)
				return a->mode;
			else
				return 0444;
		}
		break;
	case ECS_MODE:
		if (ops->get_mode) {
			if (ops->set_mode)
				return a->mode;
			else

Annotation

Implementation Notes