diff mbox series

[RFC,3/8] drm/virtio: add virtio_gpu_get_handle function

Message ID 20200227002601.745-4-gurchetansingh@chromium.org (mailing list archive)
State New, archived
Headers show
Series *** Refactor struct virtgpu_object *** | expand

Commit Message

Gurchetan Singh Feb. 27, 2020, 12:25 a.m. UTC
Whether the resource is a shmem based resource or a (planned)
vram based resource, it will have a resource handle associated
with it. Since the hypercall interface works on resource handles,
add a function that returns the handle given a GEM object.

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
---
 drivers/gpu/drm/virtio/virtgpu_drv.h    |  1 +
 drivers/gpu/drm/virtio/virtgpu_object.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
index ce73895cf74b..48ca1316ef7b 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -367,6 +367,7 @@  int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 			     struct virtio_gpu_fence *fence);
 
 bool virtio_gpu_is_shmem(struct drm_gem_object *obj);
+uint32_t virtio_gpu_get_handle(struct drm_gem_object *obj);
 
 /* virtgpu_prime.c */
 struct drm_gem_object *virtgpu_gem_prime_import_sg_table(
diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
index c5cad949eb8d..283b6dadd7c8 100644
--- a/drivers/gpu/drm/virtio/virtgpu_object.c
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
@@ -62,6 +62,19 @@  static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t
 	}
 }
 
+uint32_t virtio_gpu_get_handle(struct drm_gem_object *obj)
+{
+	if (virtio_gpu_is_shmem(obj)) {
+		struct virtio_gpu_object *bo;
+
+		bo = gem_to_virtio_gpu_obj(obj);
+		return bo->hw_res_handle;
+	}
+
+	DRM_ERROR("resource handle not found\n");
+	return 0;
+}
+
 void virtio_gpu_cleanup_object(struct virtio_gpu_object *bo)
 {
 	struct virtio_gpu_device *vgdev = bo->base.base.dev->dev_private;