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/linux drm: Another pass over i915 and ...



details:   https://anonhg.NetBSD.org/src/rev/811a1cd769f7
branches:  trunk
changeset: 1028637:811a1cd769f7
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 11:33:30 2021 +0000

description:
drm: Another pass over i915 and some supporting logic.

This makes a shim around sg_table, which essentially represents two
things:

1. an array of pages (roughly corresponding to bus_dma_segment_t[])
2. an array of DMA addresses stored in a bus_dmamap_t

Both parts are optional; different parts of i915 use sg_tables to
pass around one or both of the two parts.  This helps to reduce the
ifdefs by quite a bit, although it's not always clear which part of
an sg_table any particular interface is actually using which is why I
was reluctant to do this before.

diffstat:

 sys/external/bsd/drm2/dist/drm/drm_prime.c                      |  101 +----
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_clflush.c      |    8 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_dmabuf.c       |   32 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_execbuffer.c   |   14 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_internal.c     |  119 +++--
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c         |   19 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.h         |    3 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_object.c       |   32 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_object.h       |   13 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_object_types.h |   24 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c        |  109 +++-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c         |  143 ++++++-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pm.c           |    6 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_shmem.c        |   27 +-
 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c       |  122 +++---
 sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.h              |    4 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_gem_gtt.c              |   31 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_gem_gtt.h              |    9 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_scatterlist.h          |   30 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_vma.h                  |   30 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_vma_types.h            |    8 +-
 sys/external/bsd/drm2/dist/include/drm/drm_cache.h              |    7 +-
 sys/external/bsd/drm2/dist/include/drm/drm_prime.h              |    8 +-
 sys/external/bsd/drm2/drm/drm_cache.c                           |   18 +-
 sys/external/bsd/drm2/include/asm/uaccess.h                     |    4 +-
 sys/external/bsd/drm2/include/drm/bus_dma_hacks.h               |   11 +-
 sys/external/bsd/drm2/include/linux/bitmap.h                    |    9 +-
 sys/external/bsd/drm2/include/linux/dma-buf.h                   |   15 +-
 sys/external/bsd/drm2/include/linux/dma-mapping.h               |   19 +-
 sys/external/bsd/drm2/include/linux/mutex.h                     |    9 +-
 sys/external/bsd/drm2/include/linux/radix-tree.h                |    3 +-
 sys/external/bsd/drm2/include/linux/scatterlist.h               |   39 ++-
 sys/external/bsd/drm2/linux/files.drmkms_linux                  |    3 +-
 sys/external/bsd/drm2/linux/linux_dma_buf.c                     |    8 +-
 sys/external/bsd/drm2/linux/linux_sg.c                          |  187 ++++++++++
 35 files changed, 800 insertions(+), 424 deletions(-)

diffs (truncated from 2469 to 300 lines):

diff -r 5020ce2fe6c6 -r 811a1cd769f7 sys/external/bsd/drm2/dist/drm/drm_prime.c
--- a/sys/external/bsd/drm2/dist/drm/drm_prime.c        Sun Dec 19 11:33:17 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_prime.c        Sun Dec 19 11:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_prime.c,v 1.15 2021/12/19 11:32:53 riastradh Exp $ */
+/*     $NetBSD: drm_prime.c,v 1.16 2021/12/19 11:33:30 riastradh Exp $ */
 
 /*
  * Copyright © 2012 Red Hat
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_prime.c,v 1.15 2021/12/19 11:32:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_prime.c,v 1.16 2021/12/19 11:33:30 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/dma-buf.h>
@@ -52,72 +52,6 @@
 
 #include <linux/nbsd-namespace.h>
 
-/*
- * We use struct sg_table just to pass around an array of pages from
- * one device to another in drm prime.  Since this is _not_ a complete
- * implementation of Linux's sg table abstraction (e.g., it does not
- * remember DMA addresses and RAM pages separately, and it doesn't
- * support the nested chained iteration of Linux scatterlists), we
- * isolate it to this file and make all callers go through a few extra
- * subroutines (drm_prime_sg_size, drm_prime_sg_free, &c.) to use it.
- * Don't use this outside drm prime!
- */
-
-struct sg_table {
-       paddr_t         *sgt_pgs;
-       unsigned        sgt_npgs;
-};
-
-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_pgs = kcalloc(npages, sizeof(sgt->sgt_pgs[0]), gfp);
-       if (sgt->sgt_pgs == NULL)
-               return -ENOMEM;
-       sgt->sgt_npgs = npages;
-
-       for (i = 0; i < npages; i++)
-               sgt->sgt_pgs[i] = VM_PAGE_TO_PHYS(&pages[i]->p_vmp);
-
-       return 0;
-}
-
-static int
-sg_alloc_table_from_bus_dmamem(struct sg_table *sgt, bus_dma_tag_t dmat,
-    const bus_dma_segment_t *segs, int nsegs, gfp_t gfp)
-{
-       int ret;
-
-       KASSERT(nsegs > 0);
-       sgt->sgt_pgs = kcalloc(nsegs, sizeof(sgt->sgt_pgs[0]), gfp);
-       if (sgt->sgt_pgs == NULL)
-               return -ENOMEM;
-       sgt->sgt_npgs = nsegs;
-
-       /* XXX errno NetBSD->Linux */
-       ret = -bus_dmamem_export_pages(dmat, segs, nsegs, sgt->sgt_pgs,
-           sgt->sgt_npgs);
-       if (ret)
-               return ret;
-
-       return 0;
-}
-
-static void
-sg_free_table(struct sg_table *sgt)
-{
-
-       kfree(sgt->sgt_pgs);
-       sgt->sgt_pgs = NULL;
-       sgt->sgt_npgs = 0;
-}
-
 #endif /* __NetBSD__ */
 
 /**
@@ -827,14 +761,12 @@
        else
                sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
 
-#ifndef __NetBSD__             /* We map/unmap elsewhere.  */
        if (!dma_map_sg_attrs(attach->dev, sgt->sgl, sgt->nents, dir,
                              DMA_ATTR_SKIP_CPU_SYNC)) {
                sg_free_table(sgt);
                kfree(sgt);
                sgt = ERR_PTR(-ENOMEM);
        }
-#endif
 
        return sgt;
 }
@@ -855,10 +787,8 @@
        if (!sgt)
                return;
 
-#ifndef __NetBSD__             /* We map/unmap elsewhere.  */
        dma_unmap_sg_attrs(attach->dev, sgt->sgl, sgt->nents, dir,
                           DMA_ATTR_SKIP_CPU_SYNC);
-#endif
        sg_free_table(sgt);
        kfree(sgt);
 }
@@ -1111,9 +1041,15 @@
  * Drivers must arrange to call drm_prime_gem_destroy() from their
  * &drm_gem_object_funcs.free hook when using this function.
  */
+#ifdef __NetBSD__
+struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
+                                           struct dma_buf *dma_buf,
+                                           bus_dma_tag_t attach_dev)
+#else
 struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
                                            struct dma_buf *dma_buf,
                                            struct device *attach_dev)
+#endif
 {
        struct dma_buf_attachment *attach;
        struct sg_table *sgt;
@@ -1184,7 +1120,11 @@
 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
                                            struct dma_buf *dma_buf)
 {
+#ifdef __NetBSD__
+       return drm_gem_prime_import_dev(dev, dma_buf, dev->dmat);
+#else
        return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+#endif
 }
 EXPORT_SYMBOL(drm_gem_prime_import);
 
@@ -1218,7 +1158,7 @@
 drm_prime_sg_size(struct sg_table *sg)
 {
 
-       return sg->sgt_npgs << PAGE_SHIFT;
+       return sg->sgl->sg_npgs << PAGE_SHIFT;
 }
 
 void
@@ -1235,8 +1175,8 @@
 {
 
        /* XXX errno NetBSD->Linux */
-       return -bus_dmamem_import_pages(dmat, segs, nsegs, rsegs, sgt->sgt_pgs,
-           sgt->sgt_npgs);
+       return -bus_dmamem_import_pages(dmat, segs, nsegs, rsegs,
+           sgt->sgl->sg_pgs, sgt->sgl->sg_npgs);
 }
 
 int
@@ -1245,10 +1185,10 @@
 {
        bus_dma_segment_t *segs;
        bus_size_t size = drm_prime_sg_size(sgt);
-       int nsegs = sgt->sgt_npgs;
+       int nsegs = sgt->sgl->sg_npgs;
        int ret;
 
-       segs = kcalloc(sgt->sgt_npgs, sizeof(segs[0]), GFP_KERNEL);
+       segs = kcalloc(sgt->sgl->sg_npgs, sizeof(segs[0]), GFP_KERNEL);
        if (segs == NULL) {
                ret = -ENOMEM;
                goto out0;
@@ -1257,7 +1197,7 @@
        ret = drm_prime_sg_to_bus_dmamem(dmat, segs, nsegs, &nsegs, sgt);
        if (ret)
                goto out1;
-       KASSERT(nsegs <= sgt->sgt_npgs);
+       KASSERT(nsegs <= sgt->sgl->sg_npgs);
 
        /* XXX errno NetBSD->Linux */
        ret = -bus_dmamap_load_raw(dmat, map, segs, nsegs, size,
@@ -1274,8 +1214,9 @@
 {
        unsigned i;
 
-       for (i = 0; i < sgt->sgt_npgs; i++) {
-               if (bus_dmatag_bounces_paddr(dmat, sgt->sgt_pgs[i]))
+       for (i = 0; i < sgt->sgl->sg_npgs; i++) {
+               if (bus_dmatag_bounces_paddr(dmat,
+                       VM_PAGE_TO_PHYS(&sgt->sgl->sg_pgs[i]->p_vmp)))
                        return false;
        }
        return true;
diff -r 5020ce2fe6c6 -r 811a1cd769f7 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_clflush.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_clflush.c        Sun Dec 19 11:33:17 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_clflush.c        Sun Dec 19 11:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_gem_clflush.c,v 1.4 2021/12/19 11:32:53 riastradh Exp $   */
+/*     $NetBSD: i915_gem_clflush.c,v 1.5 2021/12/19 11:33:30 riastradh Exp $   */
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_clflush.c,v 1.4 2021/12/19 11:32:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_clflush.c,v 1.5 2021/12/19 11:33:30 riastradh Exp $");
 
 #include "display/intel_frontbuffer.h"
 
@@ -24,11 +24,7 @@
 static void __do_clflush(struct drm_i915_gem_object *obj)
 {
        GEM_BUG_ON(!i915_gem_object_has_pages(obj));
-#ifdef __NetBSD__
-       drm_clflush_pages(obj->mm.pagearray, obj->base.size >> PAGE_SHIFT);
-#else
        drm_clflush_sg(obj->mm.pages);
-#endif
 
        i915_gem_object_flush_frontbuffer(obj, ORIGIN_CPU);
 }
diff -r 5020ce2fe6c6 -r 811a1cd769f7 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_dmabuf.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_dmabuf.c Sun Dec 19 11:33:17 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_dmabuf.c Sun Dec 19 11:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_gem_dmabuf.c,v 1.5 2021/12/19 11:32:53 riastradh Exp $    */
+/*     $NetBSD: i915_gem_dmabuf.c,v 1.6 2021/12/19 11:33:30 riastradh Exp $    */
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_dmabuf.c,v 1.5 2021/12/19 11:32:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_dmabuf.c,v 1.6 2021/12/19 11:33:30 riastradh Exp $");
 
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
@@ -29,23 +29,13 @@
 {
        struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf);
        struct sg_table *st;
-#ifdef __NetBSD__
-       int ret;
-#else
        struct scatterlist *src, *dst;
        int ret, i;
-#endif
 
        ret = i915_gem_object_pin_pages(obj);
        if (ret)
                goto err;
 
-#ifdef __NetBSD__
-       st = drm_prime_pages_to_sg(obj->mm.pagearray,
-           obj->base.size >> PAGE_SHIFT);
-       if (IS_ERR(st))
-               goto err_unpin_pages;
-#else
        /* Copy sg so that we make an independent mapping */
        st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
        if (st == NULL) {
@@ -57,6 +47,14 @@
        if (ret)
                goto err_free;
 
+#ifdef __NetBSD__
+       __USE(i);
+       __USE(src);
+       __USE(dst);
+       memcpy(st->sgl->sg_pgs, obj->mm.pages->sgl->sg_pgs,
+           obj->mm.pages->nents * sizeof(st->sgl->sg_pgs[0]));
+#else
+
        src = obj->mm.pages->sgl;
        dst = st->sgl;
        for (i = 0; i < obj->mm.pages->nents; i++) {
@@ -64,21 +62,19 @@
                dst = sg_next(dst);
                src = sg_next(src);
        }
+#endif
 
        if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) {
                ret = -ENOMEM;
                goto err_free_sg;
        }
-#endif
 
        return st;
 



Home | Main Index | Thread Index | Old Index