From: Dave Jiang <dave.jiang@xxxxxxxxx> Enable sysfs attribute emission of the number of features supported by the driver/device. This is useful for userspace to determine the number of features to query for. Signed-off-by: Dave Jiang <dave.jiang@xxxxxxxxx> --- drivers/cxl/features.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/cxl/features.c b/drivers/cxl/features.c index 2cdf5ed0a771..2f0fb072921e 100644 --- a/drivers/cxl/features.c +++ b/drivers/cxl/features.c @@ -173,11 +173,38 @@ static void cxl_features_remove(struct device *dev) kfree(cfs); } +static ssize_t features_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct cxl_features_state *cfs = dev_get_drvdata(dev); + + if (!cfs) + return -ENOENT; + + return sysfs_emit(buf, "%d\n", cfs->num_features); +} + +static DEVICE_ATTR_RO(features); + +static struct attribute *cxl_features_attrs[] = { + &dev_attr_features.attr, + NULL +}; + +static struct attribute_group cxl_features_group = { + .attrs = cxl_features_attrs, +}; + +__ATTRIBUTE_GROUPS(cxl_features); + static struct cxl_driver cxl_features_driver = { .name = "cxl_features", .probe = cxl_features_probe, .remove = cxl_features_remove, .id = CXL_DEVICE_FEATURES, + .drv = { + .dev_groups = cxl_features_groups, + }, }; module_cxl_driver(cxl_features_driver); -- 2.43.0