virtio: add vmap support for prime objects
Subsystems (4)
cover virtio: add vmap support for prime objects
Having the support for vmapping dmabuf's is required to share dmabufs to drivers that want CPU access. This is the case of a vivid to virtio-gpu pipeline, where the virtio-gpu driver exports dmabufs to the video4linux vivid driver.
The first patch adds virtio_gpu_object_kunmap() and calls it from the TTM object destroy path. This function will be used to unmap prime objects.
The second patch reworks virtio_gpu_object_kmap(), so it's balanced with virtio_gpu_object_kunmap.
Finally, the third patch uses virtio_gpu_object_k{map,unmap} to support prime v{map,unmap}.
Please review!
Ezequiel Garcia (3):
virtio: Add virtio_gpu_object_kunmap()
virtio: Rework virtio_gpu_object_kmap()
virtio: Support prime objects vmap/vunmap
drivers/gpu/drm/virtio/virtgpu_drv.h | 3 ++- drivers/gpu/drm/virtio/virtgpu_fb.c | 10 ++-------- drivers/gpu/drm/virtio/virtgpu_object.c | 19 +++++++++++-------- drivers/gpu/drm/virtio/virtgpu_prime.c | 11 ++++++++--- 4 files changed, 23 insertions(+), 20 deletions(-)
Signature · 6 lines
2.19.0.rc2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/3 virtio: Add virtio_gpu_object_kunmap()
Implement a virtio_gpu_object_kunmap() to unmap the kernel mapping, and use it in the TTM object destroy path.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_object.c | 8 ++++++++ 2 files changed, 9 insertions(+)
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -0
@@ -356,6 +356,7 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev,int virtio_gpu_object_create (struct virtio_gpu_device *vgdev,unsigned long size,bool kernel,bool pinned,struct virtio_gpu_object **bo_ptr); +void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo);int virtio_gpu_object_kmap (struct virtio_gpu_object *bo,void **ptr);int virtio_gpu_object_get_sg_table (struct virtio_gpu_device *qdev,struct virtio_gpu_object *bo);
drivers/gpu/drm/virtio/virtgpu_object.c +8 -0
@@ -37,6 +37,8 @@ static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)virtio_gpu_cmd_unref_resource (vgdev, bo->hw_res_handle);if (bo->pages)virtio_gpu_object_free_sg_table (bo); +if (bo->vmap) +virtio_gpu_object_kunmap (bo);drm_gem_object_release (&bo->gem_base);kfree (bo); }
@@ -99,6 +101,12 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,return 0 ; } +void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo) +{ + bo->vmap =NULL ; +ttm_bo_kunmap (&bo->kmap); +} +int virtio_gpu_object_kmap (struct virtio_gpu_object *bo,void **ptr) {bool is_iomem;
Signature · 6 lines
2.19.0.rc2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 virtio: Rework virtio_gpu_object_kmap()
In reply to Ezequiel GarciaCurrently, virtio_gpu_object_kmap() is only called by virtio_gpufb_create(), when a DRM framebuffer is created.
Thus, instead of returning the vmap'ed address, emit a warning if virtio_gpu_object_kmap is called on an already mapped object. With this change, kmap/kunmap calls are now balanced.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +- drivers/gpu/drm/virtio/virtgpu_fb.c | 10 ++-------- drivers/gpu/drm/virtio/virtgpu_object.c | 11 +++-------- 3 files changed, 6 insertions(+), 17 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -1
@@ -357,7 +357,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, unsigned long size, bool kernel, bool pinned, struct virtio_gpu_object **bo_ptr);void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo); -int virtio_gpu_object_kmap (struct virtio_gpu_object *bo,void **ptr); +int virtio_gpu_object_kmap (struct virtio_gpu_object *bo);int virtio_gpu_object_get_sg_table (struct virtio_gpu_device *qdev,struct virtio_gpu_object *bo);void virtio_gpu_object_free_sg_table (struct virtio_gpu_object *bo);
drivers/gpu/drm/virtio/virtgpu_fb.c +2 -8
@@ -210,12 +210,6 @@ static struct fb_ops virtio_gpufb_ops = { .fb_imageblit = virtio_gpu_3d_imageblit, }; -static int virtio_gpu_vmap_fb (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *obj) -{ -return virtio_gpu_object_kmap (obj,NULL ); -} -static int virtio_gpufb_create (struct drm_fb_helper *helper,struct drm_fb_helper_surface_size *sizes) {
@@ -248,9 +242,9 @@ static int virtio_gpufb_create(struct drm_fb_helper *helper,virtio_gpu_cmd_create_resource (vgdev, resid, format, mode_cmd.width, mode_cmd.height); - ret =virtio_gpu_vmap_fb (vgdev, obj); + ret =virtio_gpu_object_kmap (obj);if (ret) { -DRM_ERROR ("failed to vmap fb %d\n" , ret); +DRM_ERROR ("failed to kmap fb %d\n" , ret); goto err_obj_vmap; }
drivers/gpu/drm/virtio/virtgpu_object.c +3 -8
@@ -107,22 +107,17 @@ void virtio_gpu_object_kunmap(struct virtio_gpu_object *bo)ttm_bo_kunmap (&bo->kmap); } -int virtio_gpu_object_kmap (struct virtio_gpu_object *bo,void **ptr) +int virtio_gpu_object_kmap (struct virtio_gpu_object *bo) {bool is_iomem;int r; -if (bo->vmap) { -if (ptr) - *ptr = bo->vmap; -return 0 ; - } +WARN_ON (bo->vmap); + r =ttm_bo_kmap (&bo->tbo,0 , bo->tbo.num_pages, &bo->kmap);if (r)return r; bo->vmap =ttm_kmap_obj_virtual (&bo->kmap, &is_iomem); -if (ptr) - *ptr = bo->vmap;return 0 ; }
Signature · 6 lines
2.19.0.rc2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 virtio: Support prime objects vmap/vunmap
In reply to Ezequiel GarciaImplement vmap/vunmap so we can export dmabufs to other drivers, such as video4linux.
Tested with a virtio-gpu / vivid (virtual capture driver) pipeline, where the vivid driver imports the dmabufs exported by virtio-gpu.
Note that dma_buf_vmap() does its own vmap counting, so it's not needed to take care of it in the driver.
--- drivers/gpu/drm/virtio/virtgpu_prime.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_prime.c +8 -3
@@ -55,13 +55,18 @@ struct drm_gem_object *virtgpu_gem_prime_import_sg_table(void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj) { -WARN_ONCE (1 ,"not implemented" ); -return ERR_PTR (-ENODEV ); +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); +int ret; + + ret =virtio_gpu_object_kmap (bo); +if (ret) +return NULL ; +return bo->vmap; }void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr) { -WARN_ONCE (1 ,"not implemented" ); +virtio_gpu_object_kunmap (gem_to_virtio_gpu_obj (obj)); } int virtgpu_gem_prime_mmap(struct drm_gem_object *obj,
Signature · 6 lines
2.19.0.rc2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi,
Quoted 9 lines
Having the support for vmapping dmabuf's is required to share dmabufs to drivers that want CPU access. This is the case of a vivid to virtio-gpu pipeline, where the virtio-gpu driver exports dmabufs to the video4linux vivid driver.
The first patch adds
virtio_gpu_object_kunmap()and calls it from the TTM object destroy path. This function will be used to unmap prime objects.
Quoted 7 lines
The second patch reworks
virtio_gpu_object_kmap(), so it's balanced withvirtio_gpu_object_kunmap.Finally, the third patch uses virtio_gpu_object_k{map,unmap} to support prime v{map,unmap}.
Please review!
Pushed to drm-misc-next.
thanks,
Gerd
Hi,
Quoted 9 lines
Having the support for vmapping dmabuf's is required to share dmabufs to drivers that want CPU access. This is the case of a vivid to virtio-gpu pipeline, where the virtio-gpu driver exports dmabufs to the video4linux vivid driver.
The first patch adds
virtio_gpu_object_kunmap()and calls it from the TTM object destroy path. This function will be used to unmap prime objects.
Quoted 7 lines
The second patch reworks
virtio_gpu_object_kmap(), so it's balanced withvirtio_gpu_object_kunmap.Finally, the third patch uses virtio_gpu_object_k{map,unmap} to support prime v{map,unmap}.
Please review!
Pushed to drm-misc-next.
thanks,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel