diff --git a/Documentation/vfio-mdev/Makefile b/Documentation/vfio-mdev/Makefile index ff6f8a3..721daf0 100644 --- a/Documentation/vfio-mdev/Makefile +++ b/Documentation/vfio-mdev/Makefile @@ -8,6 +8,9 @@ obj-m:=mtty.o default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules +modules_install: + $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules_install + clean: @rm -rf .*.cmd *.mod.c *.o *.ko .tmp* @rm -rf Module.* Modules.* modules.* .tmp_versions diff --git a/Documentation/vfio-mdev/mtty.c b/Documentation/vfio-mdev/mtty.c index 497c90e..05ab40d 100644 --- a/Documentation/vfio-mdev/mtty.c +++ b/Documentation/vfio-mdev/mtty.c @@ -141,8 +141,11 @@ struct mdev_state { struct serial_port s[2]; struct mutex rxtx_lock; struct vfio_device_info dev_info; + int nr_ports; }; +#define MAX_MTTYS 24 + struct mutex mdev_list_lock; struct list_head mdev_devices_list; @@ -723,6 +726,11 @@ int mtty_create(struct kobject *kobj, struct mdev_device *mdev) if (mdev_state == NULL) return -ENOMEM; + if (!strcmp(kobj->name, "mtty1")) + mdev_state->nr_ports = 1; + else if (!strcmp(kobj->name, "mtty2")) + mdev_state->nr_ports = 2; + mdev_state->irq_index = -1; mdev_state->s[0].max_fifo_size = MAX_FIFO_SIZE; mdev_state->s[1].max_fifo_size = MAX_FIFO_SIZE; @@ -1224,7 +1232,12 @@ const struct attribute_group *mdev_dev_groups[] = { static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) { - return sprintf(buf, "Dual-port-serial\n"); + if (!strcmp(kobj->name, "mtty1")) + return sprintf(buf, "Single-port-serial\n"); + if (!strcmp(kobj->name, "mtty2")) + return sprintf(buf, "Dual-port-serial\n"); + + return -EINVAL; } MDEV_TYPE_ATTR_RO(name); @@ -1232,7 +1245,20 @@ MDEV_TYPE_ATTR_RO(name); static ssize_t available_instances_show(struct kobject *kobj, struct device *dev, char *buf) { - return sprintf(buf, "1\n"); + struct mdev_state *mds; + int ports, used = 0; + + if (!strcmp(kobj->name, "mtty1")) + ports = 1; + else if (!strcmp(kobj->name, "mtty2")) + ports = 2; + else + return -EINVAL; + + list_for_each_entry(mds, &mdev_devices_list, next) { + used += mds->nr_ports; + } + return sprintf(buf, "%d\n", (MAX_MTTYS - used)/ports); } MDEV_TYPE_ATTR_RO(available_instances); @@ -1243,13 +1269,19 @@ static struct attribute *mdev_types_attrs[] = { NULL, }; -static struct attribute_group mdev_type_group = { +static struct attribute_group mdev_type_group1 = { .name = "mtty1", .attrs = mdev_types_attrs, }; +static struct attribute_group mdev_type_group2 = { + .name = "mtty2", + .attrs = mdev_types_attrs, +}; + struct attribute_group *mdev_type_groups[] = { - &mdev_type_group, + &mdev_type_group1, + &mdev_type_group2, NULL, };