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 Tread carefully around DMA subregions.



details:   https://anonhg.NetBSD.org/src/rev/328eceb6dc4b
branches:  trunk
changeset: 366426:328eceb6dc4b
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 15:32:06 2018 +0000

description:
Tread carefully around DMA subregions.

Not all platforms support it.

- If we want to limit to 32-bit DMA, just use a known 32-bit DMA tag.
- If we want to limit to >32-bit DMA, but the host only has a known
  32-bit DMA tag, then just use that anyway.
- If we want to limit to >32-bit DMA, but the host doesn't support
  bus_dmatag_subregion, then just use the 32-bit DMA tag anyway.

Gives powerpc, sparc a chance of working.

diffstat:

 sys/external/bsd/drm2/dist/include/drm/drmP.h |   3 +-
 sys/external/bsd/drm2/drm/drm_memory.c        |  30 +++++++++++++++++++++++++-
 sys/external/bsd/drm2/pci/drm_pci.c           |   8 ++++--
 3 files changed, 35 insertions(+), 6 deletions(-)

diffs (109 lines):

diff -r b5cb13443e99 -r 328eceb6dc4b sys/external/bsd/drm2/dist/include/drm/drmP.h
--- a/sys/external/bsd/drm2/dist/include/drm/drmP.h     Mon Aug 27 15:31:51 2018 +0000
+++ b/sys/external/bsd/drm2/dist/include/drm/drmP.h     Mon Aug 27 15:32:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drmP.h,v 1.30 2018/08/27 15:28:03 riastradh Exp $      */
+/*     $NetBSD: drmP.h,v 1.31 2018/08/27 15:32:06 riastradh Exp $      */
 
 /*
  * Internal Header for the Direct Rendering Manager
@@ -920,6 +920,7 @@
        struct drm_bus_map *bus_maps;
        unsigned bus_nmaps;
        bus_dma_tag_t bus_dmat; /* bus's full DMA tag, for internal use */
+       bus_dma_tag_t bus_dmat32;       /* bus's 32-bit DMA tag */
        bus_dma_tag_t dmat;     /* DMA tag for driver, may be subregion */
        bool dmat_subregion_p;
        bus_addr_t dmat_subregion_min;
diff -r b5cb13443e99 -r 328eceb6dc4b sys/external/bsd/drm2/drm/drm_memory.c
--- a/sys/external/bsd/drm2/drm/drm_memory.c    Mon Aug 27 15:31:51 2018 +0000
+++ b/sys/external/bsd/drm2/drm/drm_memory.c    Mon Aug 27 15:32:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_memory.c,v 1.12 2018/08/27 06:58:20 riastradh Exp $        */
+/*     $NetBSD: drm_memory.c,v 1.13 2018/08/27 15:32:06 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.12 2018/08/27 06:58:20 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.13 2018/08/27 15:32:06 riastradh Exp $");
 
 #if defined(__i386__) || defined(__x86_64__)
 
@@ -290,6 +290,21 @@
        }
 
        /*
+        * If our limit contains the 32-bit space but for some reason
+        * we can't use a subregion, either because the bus doesn't
+        * support >32-bit DMA or because bus_dma(9) on this platform
+        * lacks bus_dmatag_subregion, just use the 32-bit space.
+        */
+       if (min_addr == 0 && max_addr >= UINT32_C(0xffffffff) &&
+           dev->bus_dmat == dev->bus_dmat32) {
+dma32:         dev->dmat = dev->bus_dmat32;
+               dev->dmat_subregion_p = false;
+               dev->dmat_subregion_min = 0;
+               dev->dmat_subregion_max = UINT32_C(0xffffffff);
+               return 0;
+       }
+
+       /*
         * Create a DMA tag for a subregion from the bus's DMA tag.  If
         * that fails, restore dev->dmat to the whole region so that we
         * need not worry about dev->dmat being uninitialized (not that
@@ -300,8 +315,19 @@
        ret = -bus_dmatag_subregion(dev->bus_dmat, min_addr, max_addr,
            &dev->dmat, BUS_DMA_WAITOK);
        if (ret) {
+               /*
+                * bus_dmatag_subregion may fail.  If so, and if the
+                * subregion contains the 32-bit space, just use the
+                * 32-bit DMA tag.
+                */
+               if (ret == -EOPNOTSUPP && dev->bus_dmat32 &&
+                   min_addr == 0 && max_addr >= UINT32_C(0xffffffff))
+                       goto dma32;
+               /* XXX Back out?  */
                dev->dmat = dev->bus_dmat;
                dev->dmat_subregion_p = false;
+               dev->dmat_subregion_min = 0;
+               dev->dmat_subregion_max = __type_max(bus_addr_t);
                return ret;
        }
 
diff -r b5cb13443e99 -r 328eceb6dc4b sys/external/bsd/drm2/pci/drm_pci.c
--- a/sys/external/bsd/drm2/pci/drm_pci.c       Mon Aug 27 15:31:51 2018 +0000
+++ b/sys/external/bsd/drm2/pci/drm_pci.c       Mon Aug 27 15:32:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_pci.c,v 1.28 2018/08/27 15:31:27 riastradh Exp $   */
+/*     $NetBSD: drm_pci.c,v 1.29 2018/08/27 15:32:06 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.28 2018/08/27 15:31:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.29 2018/08/27 15:32:06 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/errno.h>
@@ -96,10 +96,12 @@
 
        /* Set up the bus space and bus DMA tags.  */
        dev->bst = pa->pa_memt;
-       /* XXX Let the driver say something about 32-bit vs 64-bit DMA?  */
        dev->bus_dmat = (pci_dma64_available(pa)? pa->pa_dmat64 : pa->pa_dmat);
+       dev->bus_dmat32 = pa->pa_dmat;
        dev->dmat = dev->bus_dmat;
        dev->dmat_subregion_p = false;
+       dev->dmat_subregion_min = 0;
+       dev->dmat_subregion_max = __type_max(bus_addr_t);
 
        /* Find all the memory maps.  */
        CTASSERT(PCI_NUM_RESOURCES < (SIZE_MAX / sizeof(dev->bus_maps[0])));



Home | Main Index | Thread Index | Old Index