From cea7ac75b0485305ef7d58b47c67d4ab82e620a3 Mon Sep 17 00:00:00 2001 From: David Riley Date: Thu, 11 Oct 2018 15:50:09 -0700 Subject: [PATCH] CHROMIUM: drm/virtio: Add interfaces to share dma bufs via virtwl. BUG=chromium:892342 TEST=xeyes repeatedly does not fail Change-Id: Ib74f0992bd9ee2bde10097722c361cdd3e94b64f Signed-off-by: David Riley Reviewed-on: https://chromium-review.googlesource.com/1351815 Reviewed-by: Tomasz Figa Reviewed-by: Zach Reizner Reviewed-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_object.c | 20 ++++++++++++++++++++ include/drm/virtio_drm.h | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 include/drm/virtio_drm.h diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c index eca7655374701f..7aac170e455d18 100644 --- a/drivers/gpu/drm/virtio/virtgpu_object.c +++ b/drivers/gpu/drm/virtio/virtgpu_object.c @@ -23,6 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include "virtgpu_drv.h" static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) @@ -172,3 +173,22 @@ int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait) return r; } +int virtio_gpu_dma_buf_to_handle(struct dma_buf *dma_buf, bool no_wait, + uint32_t *handle) +{ + struct virtio_gpu_object *qobj; + struct virtio_gpu_device *vgdev; + + if (dma_buf->ops != &virtgpu_dmabuf_ops) + return -EINVAL; + + qobj = gem_to_virtio_gpu_obj(dma_buf->priv); + vgdev = (struct virtio_gpu_device *)qobj->gem_base.dev->dev_private; + if (!qobj->create_callback_done && !no_wait) + wait_event(vgdev->resp_wq, qobj->create_callback_done); + if (!qobj->create_callback_done) + return -ETIMEDOUT; + + *handle = qobj->hw_res_handle; + return 0; +} diff --git a/include/drm/virtio_drm.h b/include/drm/virtio_drm.h new file mode 100644 index 00000000000000..409691169b6984 --- /dev/null +++ b/include/drm/virtio_drm.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Virtio GPU interfaces for sharing data. + * + * Copyright (C) 2018 Google, Inc. + */ + +#ifndef _VIRTIO_DRM_H +#define _VIRTIO_DRM_H + +/* + * The following methods are to share dma bufs with a host via the + * virtio Wayland (virtwl) device. + */ + +/* + * Converts the given dma_buf to the virtio-gpu specific resource handle + * backing the dma_buf, waiting for creation to be confirmed by the host + * if necessary. + */ +extern int virtio_gpu_dma_buf_to_handle(struct dma_buf *buf, bool no_wait, + uint32_t *handle); + +#endif /* _VIRTIO_DRM_H */