[PATCH V13 4/6] mdev: introduce mediated virtio bus

Jason Wang jasowang at redhat.com
Tue Nov 19 02:40:07 UTC 2019


On 2019/11/18 下午9:41, Jason Gunthorpe wrote:
> On Mon, Nov 18, 2019 at 06:59:21PM +0800, Jason Wang wrote:
>> +struct bus_type mdev_virtio_bus_type;
>> +
>> +struct mdev_virtio_device {
>> +	struct mdev_device mdev;
>> +	const struct mdev_virtio_ops *ops;
>> +	u16 class_id;
>> +};
> This seems to share nothing with mdev (ie mdev-vfio), why is it on the
> same bus?
>
> We went over this recently with Greg and he seemed pretty clear on
> this..


Mdev-vfio is not on this bus. The class_id here is used for distinguish 
userspace virtio driver (vhost-mdev) and kernel virtio driver (virtio-mdev).

Parent can choose to create a type of "vhost" device then vhost-mdev 
driver is matched, or "virtio" device then virtio-mdev driver is matched.


>
>> +struct mdev_virtio_ops {
>> +	/* Virtqueue ops */
>> +	int (*set_vq_address)(struct mdev_device *mdev,
>> +			      u16 idx, u64 desc_area, u64 driver_area,
>> +			      u64 device_area);
>> +	void (*set_vq_num)(struct mdev_device *mdev, u16 idx, u32 num);
>> +	void (*kick_vq)(struct mdev_device *mdev, u16 idx);
>> +	void (*set_vq_cb)(struct mdev_device *mdev, u16 idx,
>> +			  struct virtio_mdev_callback *cb);
>> +	void (*set_vq_ready)(struct mdev_device *mdev, u16 idx, bool ready);
>> +	bool (*get_vq_ready)(struct mdev_device *mdev, u16 idx);
>> +	int (*set_vq_state)(struct mdev_device *mdev, u16 idx, u64 state);
>> +	u64 (*get_vq_state)(struct mdev_device *mdev, u16 idx);
>> +
>> +	/* Device ops */
>> +	u16 (*get_vq_align)(struct mdev_device *mdev);
>> +	u64 (*get_features)(struct mdev_device *mdev);
>> +	int (*set_features)(struct mdev_device *mdev, u64 features);
>> +	void (*set_config_cb)(struct mdev_device *mdev,
>> +			      struct virtio_mdev_callback *cb);
>> +	u16 (*get_vq_num_max)(struct mdev_device *mdev);
>> +	u32 (*get_device_id)(struct mdev_device *mdev);
>> +	u32 (*get_vendor_id)(struct mdev_device *mdev);
>> +	u8 (*get_status)(struct mdev_device *mdev);
>> +	void (*set_status)(struct mdev_device *mdev, u8 status);
>> +	void (*get_config)(struct mdev_device *mdev, unsigned int offset,
>> +			   void *buf, unsigned int len);
>> +	void (*set_config)(struct mdev_device *mdev, unsigned int offset,
>> +			   const void *buf, unsigned int len);
>> +	u32 (*get_generation)(struct mdev_device *mdev);
>> +};
> Why aren't all of these 'struct mdev_device_virtio *' ?
>
> Jason


It can simplify the assignment of those ops in mdev device implementation.

Thanks




More information about the dri-devel mailing list