summaryrefslogtreecommitdiffstats
path: root/drivers/vfio/mdev
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2022-09-23 11:26:48 +0200
committerAlex Williamson <alex.williamson@redhat.com>2022-10-04 12:06:58 -0600
commit290aac5df88a83e264b3a73ec146e5e5b3c45793 (patch)
tree1bd20e1885ecb3ec8913fc63116b771580d0b4ab /drivers/vfio/mdev
parentc7c1f38f6cba7e3249866c06639ea62755f0a24e (diff)
downloadlinux-290aac5df88a83e264b3a73ec146e5e5b3c45793.tar.gz
linux-290aac5df88a83e264b3a73ec146e5e5b3c45793.tar.bz2
linux-290aac5df88a83e264b3a73ec146e5e5b3c45793.zip
vfio/mdev: consolidate all the device_api sysfs into the core code
Every driver just emits a static string, simply feed it through the ops and provide a standard sysfs show function. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> Link: https://lore.kernel.org/r/20220923092652.100656-11-hch@lst.de Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio/mdev')
-rw-r--r--drivers/vfio/mdev/mdev_driver.c4
-rw-r--r--drivers/vfio/mdev/mdev_sysfs.c35
2 files changed, 28 insertions, 11 deletions
diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c
index 5b3c94f4fb13..60e8b9f6474e 100644
--- a/drivers/vfio/mdev/mdev_driver.c
+++ b/drivers/vfio/mdev/mdev_driver.c
@@ -55,8 +55,10 @@ struct bus_type mdev_bus_type = {
**/
int mdev_register_driver(struct mdev_driver *drv)
{
- if (!drv->types_attrs)
+ if (!drv->types_attrs || !drv->device_api)
return -EINVAL;
+
+ /* initialize common driver fields */
drv->driver.bus = &mdev_bus_type;
return driver_register(&drv->driver);
}
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 38b4c2466ec4..60fc52ff9244 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -72,9 +72,30 @@ static ssize_t create_store(struct mdev_type *mtype,
return count;
}
-
static MDEV_TYPE_ATTR_WO(create);
+static ssize_t device_api_show(struct mdev_type *mtype,
+ struct mdev_type_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%s\n", mtype->parent->mdev_driver->device_api);
+}
+static MDEV_TYPE_ATTR_RO(device_api);
+
+static struct attribute *mdev_types_core_attrs[] = {
+ &mdev_type_attr_create.attr,
+ &mdev_type_attr_device_api.attr,
+ NULL,
+};
+
+static struct attribute_group mdev_type_core_group = {
+ .attrs = mdev_types_core_attrs,
+};
+
+static const struct attribute_group *mdev_type_groups[] = {
+ &mdev_type_core_group,
+ NULL,
+};
+
static void mdev_type_release(struct kobject *kobj)
{
struct mdev_type *type = to_mdev_type(kobj);
@@ -85,8 +106,9 @@ static void mdev_type_release(struct kobject *kobj)
}
static struct kobj_type mdev_type_ktype = {
- .sysfs_ops = &mdev_type_sysfs_ops,
- .release = mdev_type_release,
+ .sysfs_ops = &mdev_type_sysfs_ops,
+ .release = mdev_type_release,
+ .default_groups = mdev_type_groups,
};
static int mdev_type_add(struct mdev_parent *parent, struct mdev_type *type)
@@ -106,10 +128,6 @@ static int mdev_type_add(struct mdev_parent *parent, struct mdev_type *type)
return ret;
}
- ret = sysfs_create_file(&type->kobj, &mdev_type_attr_create.attr);
- if (ret)
- goto attr_create_failed;
-
type->devices_kobj = kobject_create_and_add("devices", &type->kobj);
if (!type->devices_kobj) {
ret = -ENOMEM;
@@ -124,8 +142,6 @@ static int mdev_type_add(struct mdev_parent *parent, struct mdev_type *type)
attrs_failed:
kobject_put(type->devices_kobj);
attr_devices_failed:
- sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr);
-attr_create_failed:
kobject_del(&type->kobj);
kobject_put(&type->kobj);
return ret;
@@ -136,7 +152,6 @@ static void mdev_type_remove(struct mdev_type *type)
sysfs_remove_files(&type->kobj, type->parent->mdev_driver->types_attrs);
kobject_put(type->devices_kobj);
- sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr);
kobject_del(&type->kobj);
kobject_put(&type->kobj);
}