drm/virtio: implement prime export
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 27 Feb 2019 14:44:41 +0000 (15:44 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Thu, 28 Feb 2019 08:09:02 +0000 (09:09 +0100)
Just run drm_prime_pages_to_sg() on the ttm pages list to get an
sg_table for export.  The pages list is created at object initialization
time, so there should be no need to handle an unpopulated page list.
Add a sanity check nevertheless.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190227144441.6755-4-kraxel@redhat.com
drivers/gpu/drm/virtio/virtgpu_drv.c
drivers/gpu/drm/virtio/virtgpu_drv.h
drivers/gpu/drm/virtio/virtgpu_prime.c

index 40e7ce000505e474d31e85d76a58ca7738ae40aa..7c2893181ba44efd41053f7ade90c0368bcce584 100644 (file)
@@ -205,8 +205,10 @@ static struct drm_driver driver = {
 #if defined(CONFIG_DEBUG_FS)
        .debugfs_init = virtio_gpu_debugfs_init,
 #endif
+       .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
        .gem_prime_export = drm_gem_prime_export,
        .gem_prime_import = drm_gem_prime_import,
+       .gem_prime_get_sg_table = virtgpu_gem_prime_get_sg_table,
        .gem_prime_vmap = virtgpu_gem_prime_vmap,
        .gem_prime_vunmap = virtgpu_gem_prime_vunmap,
        .gem_prime_mmap = virtgpu_gem_prime_mmap,
index 80eab6e3169c1df3893875955cc4e5afb6874e7c..86a264cee3621fbbaa939f23bba8451d34ba9779 100644 (file)
@@ -352,6 +352,7 @@ void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo);
 int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait);
 
 /* virtgpu_prime.c */
+struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
 void *virtgpu_gem_prime_vmap(struct drm_gem_object *obj);
 void virtgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
 int virtgpu_gem_prime_mmap(struct drm_gem_object *obj,
index 4352f95064402cd0b98f37eb54c62c84b67ff281..22ef151410e078c1dfa325716a975e1145f27a4f 100644 (file)
  * device that might share buffers with virtgpu
  */
 
+struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj)
+{
+       struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
+
+       if (!bo->tbo.ttm->pages || !bo->tbo.ttm->num_pages)
+               /* should not happen */
+               return ERR_PTR(-EINVAL);
+
+       return drm_prime_pages_to_sg(bo->tbo.ttm->pages,
+                                    bo->tbo.ttm->num_pages);
+}
+
 void *virtgpu_gem_prime_vmap(struct drm_gem_object *obj)
 {
        struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);