diff options
| author | David Stevens <stevensd@chromium.org> | 2021-08-13 03:54:41 +0300 | 
|---|---|---|
| committer | Gerd Hoffmann <kraxel@redhat.com> | 2021-08-16 15:09:40 +0300 | 
| commit | ea5ea3d8a117517a75c2af30faa399671444a1ea (patch) | |
| tree | 1bbca8681e58404ba3f066e8d3218d2b42699b48 /drivers/gpu/drm/virtio/virtgpu_prime.c | |
| parent | f492283b157053e9555787262f058ae33096f568 (diff) | |
| download | linux-ea5ea3d8a117517a75c2af30faa399671444a1ea.tar.xz | |
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.
Signed-off-by: David Stevens <stevensd@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20210813005441.608293-1-stevensd@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/virtio/virtgpu_prime.c')
| -rw-r--r-- | drivers/gpu/drm/virtio/virtgpu_prime.c | 32 | 
1 files changed, 30 insertions, 2 deletions
diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c index e45dbf14b307..55d80b77d9b0 100644 --- a/drivers/gpu/drm/virtio/virtgpu_prime.c +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c @@ -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,  | 
