Commit 290aac5d authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson
Browse files

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: default avatarJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarTony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarKirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: default avatarEric Farman <farman@linux.ibm.com>
Link: https://lore.kernel.org/r/20220923092652.100656-11-hch@lst.de


Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent c7c1f38f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -202,7 +202,7 @@ Directories and files under the sysfs for Each Physical Device

* device_api

  This attribute should show which device API is being created, for example,
  This attribute shows which device API is being created, for example,
  "vfio-pci" for a PCI device.

* available_instances
+1 −8
Original line number Diff line number Diff line
@@ -123,12 +123,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
	return sprintf(buf, "%u\n", type->avail_instance);
}

static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
}

static ssize_t description_show(struct mdev_type *mtype,
				struct mdev_type_attribute *attr, char *buf)
{
@@ -151,13 +145,11 @@ static ssize_t name_show(struct mdev_type *mtype,
}

static MDEV_TYPE_ATTR_RO(available_instances);
static MDEV_TYPE_ATTR_RO(device_api);
static MDEV_TYPE_ATTR_RO(description);
static MDEV_TYPE_ATTR_RO(name);

static const struct attribute *gvt_type_attrs[] = {
	&mdev_type_attr_available_instances.attr,
	&mdev_type_attr_device_api.attr,
	&mdev_type_attr_description.attr,
	&mdev_type_attr_name.attr,
	NULL,
@@ -1550,6 +1542,7 @@ static void intel_vgpu_remove(struct mdev_device *mdev)
}

static struct mdev_driver intel_vgpu_mdev_driver = {
	.device_api	= VFIO_DEVICE_API_PCI_STRING,
	.driver = {
		.name		= "intel_vgpu_mdev",
		.owner		= THIS_MODULE,
+1 −8
Original line number Diff line number Diff line
@@ -51,13 +51,6 @@ static ssize_t name_show(struct mdev_type *mtype,
}
static MDEV_TYPE_ATTR_RO(name);

static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING);
}
static MDEV_TYPE_ATTR_RO(device_api);

static ssize_t available_instances_show(struct mdev_type *mtype,
					struct mdev_type_attribute *attr,
					char *buf)
@@ -70,7 +63,6 @@ static MDEV_TYPE_ATTR_RO(available_instances);

static const struct attribute *mdev_types_attrs[] = {
	&mdev_type_attr_name.attr,
	&mdev_type_attr_device_api.attr,
	&mdev_type_attr_available_instances.attr,
	NULL,
};
@@ -628,6 +620,7 @@ static const struct vfio_device_ops vfio_ccw_dev_ops = {
};

struct mdev_driver vfio_ccw_mdev_driver = {
	.device_api = VFIO_DEVICE_API_CCW_STRING,
	.driver = {
		.name = "vfio_ccw_mdev",
		.owner = THIS_MODULE,
+1 −9
Original line number Diff line number Diff line
@@ -808,17 +808,8 @@ static ssize_t available_instances_show(struct mdev_type *mtype,

static MDEV_TYPE_ATTR_RO(available_instances);

static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING);
}

static MDEV_TYPE_ATTR_RO(device_api);

static const struct attribute *vfio_ap_mdev_type_attrs[] = {
	&mdev_type_attr_name.attr,
	&mdev_type_attr_device_api.attr,
	&mdev_type_attr_available_instances.attr,
	NULL,
};
@@ -1799,6 +1790,7 @@ static const struct vfio_device_ops vfio_ap_matrix_dev_ops = {
};

static struct mdev_driver vfio_ap_matrix_driver = {
	.device_api = VFIO_DEVICE_API_AP_STRING,
	.driver = {
		.name = "vfio_ap_mdev",
		.owner = THIS_MODULE,
+3 −1
Original line number Diff line number Diff line
@@ -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);
}
Loading