drm/virtio: support mapping exported vram
Subsystems (3)
PATCH v2 1/1 drm/virtio: support mapping exported vram
Implement virtgpu specific map_dma_buf callback to support mapping exported vram object dma-bufs. The dma-buf callback is used directly, as vram objects don't have backing pages and thus can't implement the drm_gem_object_funcs.get_sg_table callback.
---
v1 -> v2:
- reflow line to fix strict checkpatch warning
- replace else with return for consistency between functions
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 8 ++++ drivers/gpu/drm/virtio/virtgpu_prime.c | 32 +++++++++++++- drivers/gpu/drm/virtio/virtgpu_vram.c | 61 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +8 -0
@@ -26,6 +26,7 @@#ifndef VIRTIO_DRV_H #define VIRTIO_DRV_H +#include <linux/dma-direction.h> #include <linux/virtio.h> #include <linux/virtio_ids.h> #include <linux/virtio_config.h>
@@ -459,4 +460,11 @@ bool virtio_gpu_is_vram(struct virtio_gpu_object *bo);int virtio_gpu_vram_create (struct virtio_gpu_device *vgdev,struct virtio_gpu_object_params *params,struct virtio_gpu_object **bo_ptr); +struct sg_table *virtio_gpu_vram_map_dma_buf (struct virtio_gpu_object *bo, +struct device *dev, +enum dma_data_direction dir); +void virtio_gpu_vram_unmap_dma_buf (struct device *dev, +struct sg_table *sgt, +enum dma_data_direction dir); +#endif
drivers/gpu/drm/virtio/virtgpu_prime.c +30 -2
@@ -43,13 +43,41 @@ static int virtgpu_virtio_get_uuid(struct dma_buf *buf,return 0 ; } +static struct sg_table * +virtgpu_gem_map_dma_buf (struct dma_buf_attachment *attach, +enum dma_data_direction dir) +{ +struct drm_gem_object *obj = attach->dmabuf->priv; +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); + +if (virtio_gpu_is_vram (bo)) +return virtio_gpu_vram_map_dma_buf (bo, attach->dev, dir); + +return drm_gem_map_dma_buf (attach, dir); +} + +static void virtgpu_gem_unmap_dma_buf (struct dma_buf_attachment *attach, +struct sg_table *sgt, +enum dma_data_direction dir) +{ +struct drm_gem_object *obj = attach->dmabuf->priv; +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); + +if (virtio_gpu_is_vram (bo)) { +virtio_gpu_vram_unmap_dma_buf (attach->dev, sgt, dir); +return ; + } + +drm_gem_unmap_dma_buf (attach, sgt, dir); +} +static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { .ops = { .cache_sgt_mapping = true, .attach = virtio_dma_buf_attach, .detach = drm_gem_map_detach, - .map_dma_buf = drm_gem_map_dma_buf, - .unmap_dma_buf = drm_gem_unmap_dma_buf, + .map_dma_buf = virtgpu_gem_map_dma_buf, + .unmap_dma_buf = virtgpu_gem_unmap_dma_buf, .release = drm_gem_dmabuf_release, .mmap = drm_gem_dmabuf_mmap, .vmap = drm_gem_dmabuf_vmap,
drivers/gpu/drm/virtio/virtgpu_vram.c +61 -0
73 lines not on this page · raw message
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
Quoted 6 lines · David Stevens
Implement virtgpu specific
map_dma_bufcallback to support mapping exported vram object dma-bufs. The dma-buf callback is used directly, as vram objects don't have backing pages and thus can't implement the drm_gem_object_funcs.get_sg_table callback.Signed-off-by David Stevens <[email protected]>
Pushed to drm-misc-next.
thanks,
Gerd