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 Implement remainder of drm_gem_cma_hel...



details:   https://anonhg.NetBSD.org/src/rev/1bda90625647
branches:  trunk
changeset: 366407:1bda90625647
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 15:26:15 2018 +0000

description:
Implement remainder of drm_gem_cma_helper API.

diffstat:

 sys/external/bsd/drm2/dist/include/drm/drm_gem_cma_helper.h |  11 +-
 sys/external/bsd/drm2/drm/drm_gem_cma_helper.c              |  70 ++++++++++++-
 2 files changed, 74 insertions(+), 7 deletions(-)

diffs (139 lines):

diff -r 07727a5c137c -r 1bda90625647 sys/external/bsd/drm2/dist/include/drm/drm_gem_cma_helper.h
--- a/sys/external/bsd/drm2/dist/include/drm/drm_gem_cma_helper.h       Mon Aug 27 15:26:00 2018 +0000
+++ b/sys/external/bsd/drm2/dist/include/drm/drm_gem_cma_helper.h       Mon Aug 27 15:26:15 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_gem_cma_helper.h,v 1.4 2018/08/27 06:57:00 riastradh Exp $ */
+/*     $NetBSD: drm_gem_cma_helper.h,v 1.5 2018/08/27 15:26:15 riastradh Exp $ */
 
 #ifndef __DRM_GEM_CMA_HELPER_H__
 #define __DRM_GEM_CMA_HELPER_H__
@@ -22,8 +22,8 @@
        bus_dmamap_t dmamap;
 #else
        dma_addr_t paddr;
+#endif
        struct sg_table *sgt;
-#endif
 
        /* For objects with DMA memory allocated by GEM CMA */
        void *vaddr;
@@ -72,16 +72,19 @@
 void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
 #endif
 
-#ifndef __NetBSD__             /* XXX drm prime */
 struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj);
 struct drm_gem_object *
 drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
                                  struct dma_buf_attachment *attach,
                                  struct sg_table *sgt);
+#ifdef __NetBSD__
+int drm_gem_cma_prime_mmap(struct drm_gem_object *, off_t *, size_t, int,
+    int *, int *, struct uvm_object **, int *);
+#else
 int drm_gem_cma_prime_mmap(struct drm_gem_object *obj,
                           struct vm_area_struct *vma);
+#endif
 void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj);
 void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
-#endif
 
 #endif /* __DRM_GEM_CMA_HELPER_H__ */
diff -r 07727a5c137c -r 1bda90625647 sys/external/bsd/drm2/drm/drm_gem_cma_helper.c
--- a/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c    Mon Aug 27 15:26:00 2018 +0000
+++ b/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c    Mon Aug 27 15:26:15 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: drm_gem_cma_helper.c,v 1.2 2018/08/27 06:57:00 riastradh Exp $ */
+/* $NetBSD: drm_gem_cma_helper.c,v 1.3 2018/08/27 15:26:16 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_gem_cma_helper.c,v 1.2 2018/08/27 06:57:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_gem_cma_helper.c,v 1.3 2018/08/27 15:26:16 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <drm/drm_gem_cma_helper.h>
@@ -82,10 +82,14 @@
 static void
 drm_gem_cma_obj_free(struct drm_gem_cma_object *obj)
 {
+
        bus_dmamap_unload(obj->dmat, obj->dmamap);
        bus_dmamap_destroy(obj->dmat, obj->dmamap);
        bus_dmamem_unmap(obj->dmat, obj->vaddr, obj->dmasize);
-       bus_dmamem_free(obj->dmat, obj->dmasegs, 1);
+       if (obj->sgt)
+               drm_prime_sg_free(obj->sgt);
+       else
+               bus_dmamem_free(obj->dmat, obj->dmasegs, 1);
        kmem_free(obj, sizeof(*obj));
 }
 
@@ -219,3 +223,63 @@
        .pgo_detach = drm_gem_pager_detach,
        .pgo_fault = drm_gem_cma_fault,
 };
+
+struct sg_table *
+drm_gem_cma_prime_get_sg_table(struct drm_gem_object *gem_obj)
+{
+       struct drm_gem_cma_object *obj = to_drm_gem_cma_obj(gem_obj);
+
+       return drm_prime_bus_dmamem_to_sg(obj->dmasegs, 1);
+}
+
+struct drm_gem_object *
+drm_gem_cma_prime_import_sg_table(struct drm_device *ddev,
+    struct dma_buf_attachment *attach, struct sg_table *sgt)
+{
+       struct drm_gem_cma_object *obj;
+       int error;
+
+       obj = kmem_zalloc(sizeof(*obj), KM_SLEEP);
+       obj->dmat = ddev->dmat;
+       obj->dmasize = drm_prime_sg_size(sgt);
+
+       error = bus_dmamap_create(obj->dmat, obj->dmasize, 1, obj->dmasize, 0,
+           BUS_DMA_WAITOK, &obj->dmamap);
+       if (error)
+               goto failed;
+       /* XXX errno Linux->NetBSD */
+       error = -drm_prime_bus_dmamap_load_sgt(obj->dmat, obj->dmamap, sgt);
+       if (error)
+               goto destroy;
+       error = -drm_prime_bus_dmamem_map(obj->dmat, sgt, &obj->vaddr,
+           BUS_DMA_WAITOK | BUS_DMA_COHERENT);
+       if (error)
+               goto unload;
+
+       return &obj->base;
+
+unload:
+       bus_dmamap_unload(obj->dmat, obj->dmamap);
+destroy:
+       bus_dmamap_destroy(obj->dmat, obj->dmamap);
+failed:
+       kmem_free(obj, sizeof(*obj));
+       return ERR_PTR(-error); /* XXX errno NetBSD->Linux */
+}
+
+void *
+drm_gem_cma_prime_vmap(struct drm_gem_object *gem_obj)
+{
+       struct drm_gem_cma_object *obj = to_drm_gem_cma_obj(gem_obj);
+
+       return obj->vaddr;
+}
+
+void
+drm_gem_cma_prime_vunmap(struct drm_gem_object *gem_obj, void *vaddr)
+{
+       struct drm_gem_cma_object *obj __diagused =
+           to_drm_gem_cma_obj(gem_obj);
+
+       KASSERT(vaddr == obj->vaddr);
+}



Home | Main Index | Thread Index | Old Index