Commit 0bc79069 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Alex Williamson

vfio/mdev: consolidate all the name sysfs into the core code

Every driver just emits a static string, simply add a field to the
mdev_type for the driver to fill out or fall back to the sysfs name and
provide a standard sysfs show function.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.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-12-hch@lst.deSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 290aac5d
...@@ -217,7 +217,7 @@ Directories and files under the sysfs for Each Physical Device ...@@ -217,7 +217,7 @@ Directories and files under the sysfs for Each Physical Device
* name * name
This attribute should show human readable name. This is optional attribute. This attribute shows a human readable name.
* description * description
......
...@@ -138,20 +138,12 @@ static ssize_t description_show(struct mdev_type *mtype, ...@@ -138,20 +138,12 @@ static ssize_t description_show(struct mdev_type *mtype,
type->conf->weight); type->conf->weight);
} }
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", mtype->sysfs_name);
}
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
static MDEV_TYPE_ATTR_RO(description); static MDEV_TYPE_ATTR_RO(description);
static MDEV_TYPE_ATTR_RO(name);
static const struct attribute *gvt_type_attrs[] = { static const struct attribute *gvt_type_attrs[] = {
&mdev_type_attr_available_instances.attr, &mdev_type_attr_available_instances.attr,
&mdev_type_attr_description.attr, &mdev_type_attr_description.attr,
&mdev_type_attr_name.attr,
NULL, NULL,
}; };
......
...@@ -221,6 +221,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) ...@@ -221,6 +221,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
dev_set_drvdata(&sch->dev, private); dev_set_drvdata(&sch->dev, private);
private->mdev_type.sysfs_name = "io"; private->mdev_type.sysfs_name = "io";
private->mdev_type.pretty_name = "I/O subchannel (Non-QDIO)";
private->mdev_types[0] = &private->mdev_type; private->mdev_types[0] = &private->mdev_type;
ret = mdev_register_parent(&private->parent, &sch->dev, ret = mdev_register_parent(&private->parent, &sch->dev,
&vfio_ccw_mdev_driver, &vfio_ccw_mdev_driver,
......
...@@ -44,13 +44,6 @@ static void vfio_ccw_dma_unmap(struct vfio_device *vdev, u64 iova, u64 length) ...@@ -44,13 +44,6 @@ static void vfio_ccw_dma_unmap(struct vfio_device *vdev, u64 iova, u64 length)
vfio_ccw_mdev_reset(private); vfio_ccw_mdev_reset(private);
} }
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
return sprintf(buf, "I/O subchannel (Non-QDIO)\n");
}
static MDEV_TYPE_ATTR_RO(name);
static ssize_t available_instances_show(struct mdev_type *mtype, static ssize_t available_instances_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, struct mdev_type_attribute *attr,
char *buf) char *buf)
...@@ -62,7 +55,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype, ...@@ -62,7 +55,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
static const struct attribute *mdev_types_attrs[] = { static const struct attribute *mdev_types_attrs[] = {
&mdev_type_attr_name.attr,
&mdev_type_attr_available_instances.attr, &mdev_type_attr_available_instances.attr,
NULL, NULL,
}; };
......
...@@ -790,14 +790,6 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev) ...@@ -790,14 +790,6 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)
vfio_put_device(&matrix_mdev->vdev); vfio_put_device(&matrix_mdev->vdev);
} }
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT);
}
static MDEV_TYPE_ATTR_RO(name);
static ssize_t available_instances_show(struct mdev_type *mtype, static ssize_t available_instances_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, struct mdev_type_attribute *attr,
char *buf) char *buf)
...@@ -809,7 +801,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype, ...@@ -809,7 +801,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
static const struct attribute *vfio_ap_mdev_type_attrs[] = { static const struct attribute *vfio_ap_mdev_type_attrs[] = {
&mdev_type_attr_name.attr,
&mdev_type_attr_available_instances.attr, &mdev_type_attr_available_instances.attr,
NULL, NULL,
}; };
...@@ -1813,6 +1804,7 @@ int vfio_ap_mdev_register(void) ...@@ -1813,6 +1804,7 @@ int vfio_ap_mdev_register(void)
return ret; return ret;
matrix_dev->mdev_type.sysfs_name = VFIO_AP_MDEV_TYPE_HWVIRT; matrix_dev->mdev_type.sysfs_name = VFIO_AP_MDEV_TYPE_HWVIRT;
matrix_dev->mdev_type.pretty_name = VFIO_AP_MDEV_NAME_HWVIRT;
matrix_dev->mdev_types[0] = &matrix_dev->mdev_type; matrix_dev->mdev_types[0] = &matrix_dev->mdev_type;
ret = mdev_register_parent(&matrix_dev->parent, &matrix_dev->device, ret = mdev_register_parent(&matrix_dev->parent, &matrix_dev->device,
&vfio_ap_matrix_driver, &vfio_ap_matrix_driver,
......
...@@ -81,9 +81,19 @@ static ssize_t device_api_show(struct mdev_type *mtype, ...@@ -81,9 +81,19 @@ static ssize_t device_api_show(struct mdev_type *mtype,
} }
static MDEV_TYPE_ATTR_RO(device_api); static MDEV_TYPE_ATTR_RO(device_api);
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n",
mtype->pretty_name ? mtype->pretty_name : mtype->sysfs_name);
}
static MDEV_TYPE_ATTR_RO(name);
static struct attribute *mdev_types_core_attrs[] = { static struct attribute *mdev_types_core_attrs[] = {
&mdev_type_attr_create.attr, &mdev_type_attr_create.attr,
&mdev_type_attr_device_api.attr, &mdev_type_attr_device_api.attr,
&mdev_type_attr_name.attr,
NULL, NULL,
}; };
......
...@@ -26,6 +26,7 @@ struct mdev_device { ...@@ -26,6 +26,7 @@ struct mdev_device {
struct mdev_type { struct mdev_type {
/* set by the driver before calling mdev_register parent: */ /* set by the driver before calling mdev_register parent: */
const char *sysfs_name; const char *sysfs_name;
const char *pretty_name;
/* set by the core, can be used drivers */ /* set by the core, can be used drivers */
struct mdev_parent *parent; struct mdev_parent *parent;
......
...@@ -101,26 +101,25 @@ MODULE_PARM_DESC(mem, "megabytes available to " MBOCHS_NAME " devices"); ...@@ -101,26 +101,25 @@ MODULE_PARM_DESC(mem, "megabytes available to " MBOCHS_NAME " devices");
static struct mbochs_type { static struct mbochs_type {
struct mdev_type type; struct mdev_type type;
const char *name;
u32 mbytes; u32 mbytes;
u32 max_x; u32 max_x;
u32 max_y; u32 max_y;
} mbochs_types[] = { } mbochs_types[] = {
{ {
.type.sysfs_name = MBOCHS_TYPE_1, .type.sysfs_name = MBOCHS_TYPE_1,
.name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_1, .type.pretty_name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_1,
.mbytes = 4, .mbytes = 4,
.max_x = 800, .max_x = 800,
.max_y = 600, .max_y = 600,
}, { }, {
.type.sysfs_name = MBOCHS_TYPE_2, .type.sysfs_name = MBOCHS_TYPE_2,
.name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_2, .type.pretty_name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_2,
.mbytes = 16, .mbytes = 16,
.max_x = 1920, .max_x = 1920,
.max_y = 1440, .max_y = 1440,
}, { }, {
.type.sysfs_name = MBOCHS_TYPE_3, .type.sysfs_name = MBOCHS_TYPE_3,
.name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_3, .type.pretty_name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_3,
.mbytes = 64, .mbytes = 64,
.max_x = 0, .max_x = 0,
.max_y = 0, .max_y = 0,
...@@ -556,7 +555,7 @@ static int mbochs_init_dev(struct vfio_device *vdev) ...@@ -556,7 +555,7 @@ static int mbochs_init_dev(struct vfio_device *vdev)
mbochs_reset(mdev_state); mbochs_reset(mdev_state);
dev_info(vdev->dev, "%s: %s, %d MB, %ld pages\n", __func__, dev_info(vdev->dev, "%s: %s, %d MB, %ld pages\n", __func__,
type->name, type->mbytes, mdev_state->pagecount); type->type.pretty_name, type->mbytes, mdev_state->pagecount);
return 0; return 0;
err_vconfig: err_vconfig:
...@@ -1351,16 +1350,6 @@ static const struct attribute_group *mdev_dev_groups[] = { ...@@ -1351,16 +1350,6 @@ static const struct attribute_group *mdev_dev_groups[] = {
NULL, NULL,
}; };
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
struct mbochs_type *type =
container_of(mtype, struct mbochs_type, type);
return sprintf(buf, "%s\n", type->name);
}
static MDEV_TYPE_ATTR_RO(name);
static ssize_t description_show(struct mdev_type *mtype, static ssize_t description_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf) struct mdev_type_attribute *attr, char *buf)
{ {
...@@ -1385,7 +1374,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype, ...@@ -1385,7 +1374,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
static const struct attribute *mdev_types_attrs[] = { static const struct attribute *mdev_types_attrs[] = {
&mdev_type_attr_name.attr,
&mdev_type_attr_description.attr, &mdev_type_attr_description.attr,
&mdev_type_attr_available_instances.attr, &mdev_type_attr_available_instances.attr,
NULL, NULL,
......
...@@ -53,7 +53,6 @@ MODULE_PARM_DESC(count, "number of " MDPY_NAME " devices"); ...@@ -53,7 +53,6 @@ MODULE_PARM_DESC(count, "number of " MDPY_NAME " devices");
static struct mdpy_type { static struct mdpy_type {
struct mdev_type type; struct mdev_type type;
const char *name;
u32 format; u32 format;
u32 bytepp; u32 bytepp;
u32 width; u32 width;
...@@ -61,21 +60,21 @@ static struct mdpy_type { ...@@ -61,21 +60,21 @@ static struct mdpy_type {
} mdpy_types[] = { } mdpy_types[] = {
{ {
.type.sysfs_name = MDPY_TYPE_1, .type.sysfs_name = MDPY_TYPE_1,
.name = MDPY_CLASS_NAME "-" MDPY_TYPE_1, .type.pretty_name = MDPY_CLASS_NAME "-" MDPY_TYPE_1,
.format = DRM_FORMAT_XRGB8888, .format = DRM_FORMAT_XRGB8888,
.bytepp = 4, .bytepp = 4,
.width = 640, .width = 640,
.height = 480, .height = 480,
}, { }, {
.type.sysfs_name = MDPY_TYPE_2, .type.sysfs_name = MDPY_TYPE_2,
.name = MDPY_CLASS_NAME "-" MDPY_TYPE_2, .type.pretty_name = MDPY_CLASS_NAME "-" MDPY_TYPE_2,
.format = DRM_FORMAT_XRGB8888, .format = DRM_FORMAT_XRGB8888,
.bytepp = 4, .bytepp = 4,
.width = 1024, .width = 1024,
.height = 768, .height = 768,
}, { }, {
.type.sysfs_name = MDPY_TYPE_3, .type.sysfs_name = MDPY_TYPE_3,
.name = MDPY_CLASS_NAME "-" MDPY_TYPE_3, .type.pretty_name = MDPY_CLASS_NAME "-" MDPY_TYPE_3,
.format = DRM_FORMAT_XRGB8888, .format = DRM_FORMAT_XRGB8888,
.bytepp = 4, .bytepp = 4,
.width = 1920, .width = 1920,
...@@ -256,8 +255,8 @@ static int mdpy_init_dev(struct vfio_device *vdev) ...@@ -256,8 +255,8 @@ static int mdpy_init_dev(struct vfio_device *vdev)
mdpy_create_config_space(mdev_state); mdpy_create_config_space(mdev_state);
mdpy_reset(mdev_state); mdpy_reset(mdev_state);
dev_info(vdev->dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width, dev_info(vdev->dev, "%s: %s (%dx%d)\n", __func__, type->type.pretty_name,
type->height); type->width, type->height);
mdpy_count++; mdpy_count++;
return 0; return 0;
...@@ -662,15 +661,6 @@ static const struct attribute_group *mdev_dev_groups[] = { ...@@ -662,15 +661,6 @@ static const struct attribute_group *mdev_dev_groups[] = {
NULL, NULL,
}; };
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
struct mdpy_type *type = container_of(mtype, struct mdpy_type, type);
return sprintf(buf, "%s\n", type->name);
}
static MDEV_TYPE_ATTR_RO(name);
static ssize_t description_show(struct mdev_type *mtype, static ssize_t description_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf) struct mdev_type_attribute *attr, char *buf)
{ {
...@@ -690,7 +680,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype, ...@@ -690,7 +680,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
static const struct attribute *mdev_types_attrs[] = { static const struct attribute *mdev_types_attrs[] = {
&mdev_type_attr_name.attr,
&mdev_type_attr_description.attr, &mdev_type_attr_description.attr,
&mdev_type_attr_available_instances.attr, &mdev_type_attr_available_instances.attr,
NULL, NULL,
......
...@@ -146,10 +146,11 @@ struct mdev_state { ...@@ -146,10 +146,11 @@ struct mdev_state {
static struct mtty_type { static struct mtty_type {
struct mdev_type type; struct mdev_type type;
int nr_ports; int nr_ports;
const char *name;
} mtty_types[2] = { } mtty_types[2] = {
{ .nr_ports = 1, .type.sysfs_name = "1", .name = "Single port serial" }, { .nr_ports = 1, .type.sysfs_name = "1",
{ .nr_ports = 2, .type.sysfs_name = "2", .name = "Dual port serial" }, .type.pretty_name = "Single port serial" },
{ .nr_ports = 2, .type.sysfs_name = "2",
.type.pretty_name = "Dual port serial" },
}; };
static struct mdev_type *mtty_mdev_types[] = { static struct mdev_type *mtty_mdev_types[] = {
...@@ -1255,16 +1256,6 @@ static const struct attribute_group *mdev_dev_groups[] = { ...@@ -1255,16 +1256,6 @@ static const struct attribute_group *mdev_dev_groups[] = {
NULL, NULL,
}; };
static ssize_t name_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, char *buf)
{
struct mtty_type *type = container_of(mtype, struct mtty_type, type);
return sysfs_emit(buf, "%s\n", type->name);
}
static MDEV_TYPE_ATTR_RO(name);
static ssize_t available_instances_show(struct mdev_type *mtype, static ssize_t available_instances_show(struct mdev_type *mtype,
struct mdev_type_attribute *attr, struct mdev_type_attribute *attr,
char *buf) char *buf)
...@@ -1278,7 +1269,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype, ...@@ -1278,7 +1269,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(available_instances);
static const struct attribute *mdev_types_attrs[] = { static const struct attribute *mdev_types_attrs[] = {
&mdev_type_attr_name.attr,
&mdev_type_attr_available_instances.attr, &mdev_type_attr_available_instances.attr,
NULL, NULL,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment