On 2020/2/21 下午3:57, Jason Wang wrote:
On 2020/2/20 下午11:12, Jason Gunthorpe wrote:
On Thu, Feb 20, 2020 at 02:11:41PM +0800, Jason Wang wrote:
+static void vdpasim_device_release(struct device *dev)
+{
+ struct vdpasim *vdpasim = dev_to_sim(dev);
+
+ cancel_work_sync(&vdpasim->work);
+ kfree(vdpasim->buffer);
+ vhost_iotlb_free(vdpasim->iommu);
+ kfree(vdpasim);
+}
+
+static struct vdpasim *vdpasim_create(void)
+{
+ struct virtio_net_config *config;
+ struct vhost_iotlb *iommu;
+ struct vdpasim *vdpasim;
+ struct device *dev;
+ void *buffer;
+ int ret = -ENOMEM;
+
+ iommu = vhost_iotlb_alloc(2048, 0);
+ if (!iommu)
+ goto err;
+
+ buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!buffer)
+ goto err_buffer;
+
+ vdpasim = kzalloc(sizeof(*vdpasim), GFP_KERNEL);
+ if (!vdpasim)
+ goto err_alloc;
+
+ vdpasim->buffer = buffer;
+ vdpasim->iommu = iommu;
+
+ config = &vdpasim->config;
+ config->mtu = 1500;
+ config->status = VIRTIO_NET_S_LINK_UP;
+ eth_random_addr(config->mac);
+
+ INIT_WORK(&vdpasim->work, vdpasim_work);
+ spin_lock_init(&vdpasim->lock);
+
+ vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
+ vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);
+
+ dev = &vdpasim->dev;
+ dev->release = vdpasim_device_release;
+ dev->coherent_dma_mask = DMA_BIT_MASK(64);
+ set_dma_ops(dev, &vdpasim_dma_ops);
+ dev_set_name(dev, "%s", VDPASIM_NAME);
+
+ ret = device_register(&vdpasim->dev);
+ if (ret)
+ goto err_init;
It is a bit weird to be creating this dummy parent, couldn't this be
done by just passing a NULL parent to vdpa_alloc_device, doing
set_dma_ops() on the vdpasim->vdpa->dev and setting dma_device to
vdpasim->vdpa->dev ?
I think it works.
Rethink about this, since most hardware vDPA driver will have a parent
and will use it to find the parent structure e.g
dev_get_drvdata(vdpa->dev->parent)
So I keep this dummy parent in V5.
Thanks
_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization