Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2 Draft support for drm prime.



details:   https://anonhg.NetBSD.org/src/rev/ee9ba119e369
branches:  trunk
changeset: 366396:ee9ba119e369
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 15:22:53 2018 +0000

description:
Draft support for drm prime.

diffstat:

 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_display.c |    6 +-
 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_drv.c     |    6 +-
 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gem.c     |    6 +-
 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_ttm.c     |   15 +-
 sys/external/bsd/drm2/dist/drm/drm_gem.c                   |    8 +-
 sys/external/bsd/drm2/dist/drm/drm_internal.h              |    4 +-
 sys/external/bsd/drm2/dist/drm/drm_ioctl.c                 |    6 +-
 sys/external/bsd/drm2/dist/drm/drm_prime.c                 |  151 ++++++-
 sys/external/bsd/drm2/dist/drm/i915/i915_drv.c             |    6 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_drv.h             |    3 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_gem.c             |    6 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_gem_dmabuf.c      |   78 +++-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_bo.c        |   17 +-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c       |    6 +-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_gem.c       |    6 +-
 sys/external/bsd/drm2/dist/drm/radeon/radeon_display.c     |    6 +-
 sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c         |    6 +-
 sys/external/bsd/drm2/dist/drm/radeon/radeon_gem.c         |    6 +-
 sys/external/bsd/drm2/dist/drm/radeon/radeon_ttm.c         |   15 +-
 sys/external/bsd/drm2/dist/include/drm/drmP.h              |   16 +-
 sys/external/bsd/drm2/dist/include/drm/drm_gem.h           |    4 +-
 sys/external/bsd/drm2/dist/uapi/drm/drm.h                  |    3 +-
 sys/external/bsd/drm2/drm/drm_fops.c                       |   10 +-
 sys/external/bsd/drm2/drm/files.drmkms                     |    4 +-
 sys/external/bsd/drm2/i915drm/files.i915drmkms             |    4 +-
 sys/external/bsd/drm2/include/linux/dma-buf.h              |  113 +++++-
 sys/external/bsd/drm2/include/linux/module.h               |    3 +-
 sys/external/bsd/drm2/linux/files.drmkms_linux             |    3 +-
 sys/external/bsd/drm2/linux/linux_dma_buf.c                |  276 +++++++++++++
 sys/external/bsd/drm2/nouveau/files.nouveau                |    4 +-
 sys/external/bsd/drm2/radeon/files.radeon                  |    4 +-
 31 files changed, 693 insertions(+), 108 deletions(-)

diffs (truncated from 1670 to 300 lines):

diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_display.c
--- a/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_display.c        Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_display.c        Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpu_display.c,v 1.3 2018/08/27 14:04:50 riastradh Exp $     */
+/*     $NetBSD: amdgpu_display.c,v 1.4 2018/08/27 15:22:54 riastradh Exp $     */
 
 /*
  * Copyright 2007-8 Advanced Micro Devices, Inc.
@@ -26,7 +26,7 @@
  *          Alex Deucher
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_display.c,v 1.3 2018/08/27 14:04:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_display.c,v 1.4 2018/08/27 15:22:54 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <drm/amdgpu_drm.h>
@@ -565,13 +565,11 @@
                return ERR_PTR(-ENOENT);
        }
 
-#ifndef __NetBSD__             /* XXX drm prime */
        /* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
        if (obj->import_attach) {
                DRM_DEBUG_KMS("Cannot create framebuffer from imported dma_buf\n");
                return ERR_PTR(-EINVAL);
        }
-#endif
 
        amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
        if (amdgpu_fb == NULL) {
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_drv.c
--- a/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_drv.c    Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_drv.c    Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpu_drv.c,v 1.4 2018/08/27 14:04:50 riastradh Exp $ */
+/*     $NetBSD: amdgpu_drv.c,v 1.5 2018/08/27 15:22:54 riastradh Exp $ */
 
 /**
  * \file amdgpu_drv.c
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_drv.c,v 1.4 2018/08/27 14:04:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_drv.c,v 1.5 2018/08/27 15:22:54 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <drm/amdgpu_drm.h>
@@ -538,7 +538,6 @@
        .fops = &amdgpu_driver_kms_fops,
 #endif
 
-#ifndef __NetBSD__             /* XXX drm prime */
        .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
        .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
        .gem_prime_export = amdgpu_gem_prime_export,
@@ -550,7 +549,6 @@
        .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
        .gem_prime_vmap = amdgpu_gem_prime_vmap,
        .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
-#endif
 
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gem.c
--- a/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gem.c    Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gem.c    Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpu_gem.c,v 1.3 2018/08/27 14:04:50 riastradh Exp $ */
+/*     $NetBSD: amdgpu_gem.c,v 1.4 2018/08/27 15:22:54 riastradh Exp $ */
 
 /*
  * Copyright 2008 Advanced Micro Devices, Inc.
@@ -28,7 +28,7 @@
  *          Jerome Glisse
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_gem.c,v 1.3 2018/08/27 14:04:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_gem.c,v 1.4 2018/08/27 15:22:54 riastradh Exp $");
 
 #include <linux/ktime.h>
 #include <drm/drmP.h>
@@ -40,10 +40,8 @@
        struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
 
        if (robj) {
-#ifndef __NetBSD__             /* XXX drm prime */
                if (robj->gem_base.import_attach)
                        drm_prime_gem_destroy(&robj->gem_base, robj->tbo.sg);
-#endif
                amdgpu_mn_unregister(robj);
                amdgpu_bo_unref(&robj);
        }
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_ttm.c
--- a/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_ttm.c    Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_ttm.c    Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpu_ttm.c,v 1.3 2018/08/27 14:04:50 riastradh Exp $ */
+/*     $NetBSD: amdgpu_ttm.c,v 1.4 2018/08/27 15:22:54 riastradh Exp $ */
 
 /*
  * Copyright 2009 Jerome Glisse.
@@ -32,7 +32,7 @@
  *    Dave Airlie
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_ttm.c,v 1.3 2018/08/27 14:04:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_ttm.c,v 1.4 2018/08/27 15:22:54 riastradh Exp $");
 
 #include <ttm/ttm_bo_api.h>
 #include <ttm/ttm_bo_driver.h>
@@ -687,8 +687,8 @@
        struct amdgpu_ttm_tt *gtt = (void *)ttm;
 #ifndef __NetBSD__
        unsigned i;
+#endif
        int r;
-#endif
        bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
        if (ttm->state != tt_unpopulated)
@@ -709,14 +709,17 @@
        }
 
        if (slave && ttm->sg) {
-#ifdef __NetBSD__              /* XXX drm prime */
-               return -EINVAL;
+#ifdef __NetBSD__
+               r = drm_prime_bus_dmamap_load_sgt(ttm->bdev->dmat,
+                   gtt->ttm.dma_address, ttm->sg);
+               if (r)
+                       return r;
 #else
                drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages,
                                                 gtt->ttm.dma_address, ttm->num_pages);
+#endif
                ttm->state = tt_unbound;
                return 0;
-#endif
        }
 
 #ifdef __NetBSD__
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/drm_gem.c
--- a/sys/external/bsd/drm2/dist/drm/drm_gem.c  Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_gem.c  Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_gem.c,v 1.9 2018/08/27 14:14:29 riastradh Exp $    */
+/*     $NetBSD: drm_gem.c,v 1.10 2018/08/27 15:22:53 riastradh Exp $   */
 
 /*
  * Copyright © 2008 Intel Corporation
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_gem.c,v 1.9 2018/08/27 14:14:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_gem.c,v 1.10 2018/08/27 15:22:53 riastradh Exp $");
 
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -224,7 +224,6 @@
 static void
 drm_gem_remove_prime_handles(struct drm_gem_object *obj, struct drm_file *filp)
 {
-#ifndef __NetBSD__             /* XXX drm prime */
        /*
         * Note: obj->dma_buf can't disappear as long as we still hold a
         * handle reference in obj->handle_count.
@@ -235,7 +234,6 @@
                                                   obj->dma_buf);
        }
        mutex_unlock(&filp->prime.lock);
-#endif
 }
 
 /**
@@ -822,10 +820,8 @@
        if (dev->driver->gem_close_object)
                dev->driver->gem_close_object(obj, file_priv);
 
-#ifndef __NetBSD__                     /* XXX drm prime */
        if (drm_core_check_feature(dev, DRIVER_PRIME))
                drm_gem_remove_prime_handles(obj, file_priv);
-#endif
        drm_vma_node_revoke(&obj->vma_node, file_priv->filp);
 
        drm_gem_object_handle_unreference_unlocked(obj);
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/drm_internal.h
--- a/sys/external/bsd/drm2/dist/drm/drm_internal.h     Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_internal.h     Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_internal.h,v 1.2 2018/08/27 04:58:19 riastradh Exp $       */
+/*     $NetBSD: drm_internal.h,v 1.3 2018/08/27 15:22:53 riastradh Exp $       */
 
 /*
  * Copyright © 2014 Intel Corporation
@@ -50,12 +50,10 @@
 int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
                                 struct drm_file *file_priv);
 
-#ifndef __NetBSD__             /* XXX drm prime */
 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
 void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv,
                                        struct dma_buf *dma_buf);
-#endif
 
 #ifndef __NetBSD__
 /* drm_info.c */
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/drm_ioctl.c
--- a/sys/external/bsd/drm2/dist/drm/drm_ioctl.c        Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_ioctl.c        Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_ioctl.c,v 1.8 2018/08/27 14:45:45 riastradh Exp $  */
+/*     $NetBSD: drm_ioctl.c,v 1.9 2018/08/27 15:22:53 riastradh Exp $  */
 
 /*
  * Created: Fri Jan  8 09:01:26 1999 by faith%valinux.com@localhost
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,v 1.8 2018/08/27 14:45:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,v 1.9 2018/08/27 15:22:53 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <drm/drm_core.h>
@@ -665,10 +665,8 @@
 
        DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 
-#ifndef __NetBSD__             /* XXX drm prime */
        DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
-#endif
 
        DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
        DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
diff -r d8802f2349b5 -r ee9ba119e369 sys/external/bsd/drm2/dist/drm/drm_prime.c
--- a/sys/external/bsd/drm2/dist/drm/drm_prime.c        Mon Aug 27 15:16:49 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_prime.c        Mon Aug 27 15:22:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_prime.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $  */
+/*     $NetBSD: drm_prime.c,v 1.3 2018/08/27 15:22:54 riastradh Exp $  */
 
 /*
  * Copyright © 2012 Red Hat
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_prime.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_prime.c,v 1.3 2018/08/27 15:22:54 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/dma-buf.h>
@@ -38,6 +38,72 @@
 
 #include "drm_internal.h"
 
+struct sg_table {
+       bus_dma_segment_t       *sgt_segs;
+       int                     sgt_nsegs;
+       bus_size_t              sgt_size;
+};
+
+static int
+sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages,
+    unsigned npages, bus_size_t offset, bus_size_t size, gfp_t gfp)
+{
+       unsigned i;
+
+       KASSERT(offset == 0);
+       KASSERT(size == npages << PAGE_SHIFT);
+
+       sgt->sgt_segs = kcalloc(npages, sizeof(sgt->sgt_segs[0]), gfp);
+       if (sgt->sgt_segs == NULL)
+               return -ENOMEM;
+       sgt->sgt_nsegs = npages;
+       sgt->sgt_size = size;
+
+       for (i = 0; i < npages; i++) {
+               sgt->sgt_segs[i].ds_addr = VM_PAGE_TO_PHYS(&pages[i]->p_vmp);
+               sgt->sgt_segs[i].ds_len = PAGE_SIZE;
+       }
+
+       return 0;
+}
+
+static int
+sg_alloc_table_from_pglist(struct sg_table *sgt, struct pglist *pglist,
+    unsigned npages, bus_size_t offset, bus_size_t size, gfp_t gfp)
+{
+       struct vm_page *pg;
+       unsigned i;
+
+       KASSERT(offset == 0);
+       KASSERT(size == npages << PAGE_SHIFT);



Home | Main Index | Thread Index | Old Index