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/dist/drm/i915 Work over i915_gem_gtt.c...



details:   https://anonhg.NetBSD.org/src/rev/f8adbc0159d0
branches:  trunk
changeset: 1028009:f8adbc0159d0
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 01:35:35 2021 +0000

description:
Work over i915_gem_gtt.c enough to make it build.

diffstat:

 sys/external/bsd/drm2/dist/drm/i915/gt/gen6_ppgtt.h |  17 ++++-
 sys/external/bsd/drm2/dist/drm/i915/gt/gen8_ppgtt.c |   6 +-
 sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c |  10 ++-
 sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.c  |  69 +++++++++++++++++++-
 sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.h  |  52 +++++++++++++++-
 sys/external/bsd/drm2/dist/drm/i915/i915_gem_gtt.c  |   9 +-
 6 files changed, 146 insertions(+), 17 deletions(-)

diffs (truncated from 415 to 300 lines):

diff -r 0c32b5018ff9 -r f8adbc0159d0 sys/external/bsd/drm2/dist/drm/i915/gt/gen6_ppgtt.h
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/gen6_ppgtt.h       Sun Dec 19 01:35:25 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/gen6_ppgtt.h       Sun Dec 19 01:35:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gen6_ppgtt.h,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */
+/*     $NetBSD: gen6_ppgtt.h,v 1.3 2021/12/19 01:35:35 riastradh Exp $ */
 
 /* SPDX-License-Identifier: MIT */
 /*
@@ -15,7 +15,12 @@
 
        struct mutex flush;
        struct i915_vma *vma;
+#ifdef __NetBSD__
+       bus_space_tag_t pd_bst;
+       bus_space_handle_t pd_bsh;
+#else
        gen6_pte_t __iomem *pd_addr;
+#endif
 
        atomic_t pin_count;
        struct mutex pin_mutex;
@@ -54,6 +59,15 @@
  * so each of the other parameters should preferably be a simple variable, or
  * at most an lvalue with no side-effects!
  */
+#ifdef __NetBSD__              /* XXX ALIGN means something else.  */
+#define gen6_for_each_pde(pt, pd, start, length, iter)                 \
+       for (iter = gen6_pde_index(start);                              \
+            length > 0 && iter < I915_PDES &&                          \
+               (pt = (pd)->page_table[iter], true);                    \
+            ({ u32 temp = round_up(start+1, 1 << GEN6_PDE_SHIFT);      \
+                   temp = min(temp - start, length);                   \
+                   start += temp, length -= temp; }), ++iter)
+#else
 #define gen6_for_each_pde(pt, pd, start, length, iter)                 \
        for (iter = gen6_pde_index(start);                              \
             length > 0 && iter < I915_PDES &&                          \
@@ -61,6 +75,7 @@
             ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT);         \
                    temp = min(temp - start, length);                   \
                    start += temp, length -= temp; }), ++iter)
+#endif
 
 #define gen6_for_all_pdes(pt, pd, iter)                                        \
        for (iter = 0;                                                  \
diff -r 0c32b5018ff9 -r f8adbc0159d0 sys/external/bsd/drm2/dist/drm/i915/gt/gen8_ppgtt.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/gen8_ppgtt.c       Sun Dec 19 01:35:25 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/gen8_ppgtt.c       Sun Dec 19 01:35:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gen8_ppgtt.c,v 1.3 2021/12/19 01:24:25 riastradh Exp $ */
+/*     $NetBSD: gen8_ppgtt.c,v 1.4 2021/12/19 01:35:35 riastradh Exp $ */
 
 // SPDX-License-Identifier: MIT
 /*
@@ -6,7 +6,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gen8_ppgtt.c,v 1.3 2021/12/19 01:24:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gen8_ppgtt.c,v 1.4 2021/12/19 01:35:35 riastradh Exp $");
 
 #include <linux/log2.h>
 
@@ -503,7 +503,7 @@
 
                do {
 #ifdef __NetBSD__
-                       GEM_BUG_ON((iter->map->ds_seg[iter->seg].ds_len -
+                       GEM_BUG_ON((iter->map->ds_segs[iter->seg].ds_len -
                                iter->off) < page_size);
 #else
                        GEM_BUG_ON(iter->sg->length < page_size);
diff -r 0c32b5018ff9 -r f8adbc0159d0 sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c       Sun Dec 19 01:35:25 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c       Sun Dec 19 01:35:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_ggtt.c,v 1.3 2021/12/19 01:24:25 riastradh Exp $ */
+/*     $NetBSD: intel_ggtt.c,v 1.4 2021/12/19 01:35:35 riastradh Exp $ */
 
 // SPDX-License-Identifier: MIT
 /*
@@ -6,7 +6,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intel_ggtt.c,v 1.3 2021/12/19 01:24:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intel_ggtt.c,v 1.4 2021/12/19 01:35:35 riastradh Exp $");
 
 #include <linux/stop_machine.h>
 
@@ -308,7 +308,7 @@
 #ifdef __NetBSD__
        pgno = vma->node.start >> PAGE_SHIFT;
        for (seg = 0; seg < map->dm_nsegs; seg++) {
-               bus_addr_t addr = map->dm_segs[seg].ds_addr;
+               addr = map->dm_segs[seg].ds_addr;
                bus_size_t len = map->dm_segs[seg].ds_len;
                KASSERT((addr & (PAGE_SIZE - 1)) == 0);
                KASSERT((len & (PAGE_SIZE - 1)) == 0);
@@ -1259,7 +1259,11 @@
 
        ggtt->vm.gt = gt;
        ggtt->vm.i915 = i915;
+#ifdef __NetBSD__
+       ggtt->vm.dmat = i915->drm.dmat;
+#else
        ggtt->vm.dma = &i915->drm.pdev->dev;
+#endif
 
        if (INTEL_GEN(i915) <= 5)
                ret = i915_gmch_probe(ggtt);
diff -r 0c32b5018ff9 -r f8adbc0159d0 sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.c        Sun Dec 19 01:35:25 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.c        Sun Dec 19 01:35:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_gtt.c,v 1.3 2021/12/19 01:24:25 riastradh Exp $  */
+/*     $NetBSD: intel_gtt.c,v 1.4 2021/12/19 01:35:35 riastradh Exp $  */
 
 // SPDX-License-Identifier: MIT
 /*
@@ -6,7 +6,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intel_gtt.c,v 1.3 2021/12/19 01:24:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intel_gtt.c,v 1.4 2021/12/19 01:35:35 riastradh Exp $");
 
 #include <linux/slab.h> /* fault-inject.h is not standalone! */
 
@@ -265,10 +265,14 @@
 {
        GEM_BUG_ON(!vma->pages);
 
+#ifdef __NetBSD__              /* XXX rotate pages */
+       GEM_BUG_ON(vma->pages != vma->obj->mm.pages);
+#else
        if (vma->pages != vma->obj->mm.pages) {
                sg_free_table(vma->pages);
                kfree(vma->pages);
        }
+#endif
        vma->pages = NULL;
 
        memset(&vma->page_sizes, 0, sizeof(vma->page_sizes));
@@ -283,7 +287,7 @@
        int error;
        int nseg = 1;
 
-       if (flags & __GFP_WAIT)
+       if (gfp & __GFP_WAIT)
                busdmaflags |= BUS_DMA_WAITOK;
        else
                busdmaflags |= BUS_DMA_NOWAIT;
@@ -312,7 +316,7 @@
        p->page = container_of(PHYS_TO_VM_PAGE(p->seg.ds_addr), struct page,
            p_vmp);
 
-       if (flags & __GFP_ZERO) {
+       if (gfp & __GFP_ZERO) {
                void *va = kmap_atomic(p->page);
                memset(va, 0, PAGE_SIZE);
                kunmap_atomic(va);
@@ -383,6 +387,48 @@
        gfp |= __GFP_ZERO | __GFP_RETRY_MAYFAIL;
 
        do {
+#ifdef __NetBSD__
+               struct vm_page *vm_page;
+               void *kva;
+               int nseg;
+               int ret;
+
+               /* Allocate a scratch page.  */
+               /* XXX errno NetBSD->Linux */
+               ret = -bus_dmamem_alloc(vm->dmat, size, size, 0,
+                   &vm->scratch_page.seg, 1, &nseg, BUS_DMA_NOWAIT);
+               if (ret)
+                       goto skip;
+               KASSERT(nseg == 1);
+               KASSERT(vm->scratch_page.seg.ds_len == size);
+
+               /* Create a DMA map.  */
+               ret = -bus_dmamap_create(vm->dmat, size, 1, size, 0,
+                   BUS_DMA_NOWAIT, &vm->scratch_page.map);
+               if (ret)
+                       goto free_dmamem;
+
+               /* Load the segment into the DMA map.  */
+               ret = -bus_dmamap_load_raw(vm->dmat, vm->scratch_page.map,
+                   &vm->scratch_page.seg, 1, size, BUS_DMA_NOWAIT);
+               if (ret)
+                       goto destroy_dmamap;
+               KASSERT(vm->scratch_page.map->dm_nsegs == 1);
+               KASSERT(vm->scratch_page.map->dm_segs[0].ds_len == size);
+
+               /* Zero the page.  */
+               ret = -bus_dmamem_map(vm->dmat, &vm->scratch_page.seg, 1,
+                   size, &kva, BUS_DMA_NOWAIT);
+               if (ret)
+                       goto unload_dmamap;
+               memset(kva, 0, size);
+               bus_dmamem_unmap(vm->dmat, kva, size);
+
+               /* XXX Is this page guaranteed to work as a huge page?  */
+               vm_page = PHYS_TO_VM_PAGE(vm->scratch_page.seg.ds_addr);
+               vm->scratch_page.page = container_of(vm_page, struct page,
+                   p_vmp);
+#else
                unsigned int order = get_order(size);
                struct page *page;
                dma_addr_t addr;
@@ -405,12 +451,20 @@
                vm->scratch[0].base.page = page;
                vm->scratch[0].base.daddr = addr;
                vm->scratch_order = order;
+#endif
                return 0;
 
+#ifdef __NetBSD__
+unload_dmamap: bus_dmamap_unload(vm->dmat, vm->scratch_page.map);
+destroy_dmamap:        bus_dmamap_destroy(vm->dmat, vm->scratch_page.map);
+               vm->scratch_page.map = NULL; /* paranoia */
+free_dmamem:   bus_dmamem_free(vm->dmat, &vm->scratch_page.seg, 1);
+#else
 unmap_page:
                dma_unmap_page(vm->dma, addr, size, PCI_DMA_BIDIRECTIONAL);
 free_page:
                __free_pages(page, order);
+#endif
 skip:
                if (size == I915_GTT_PAGE_SIZE_4K)
                        return -ENOMEM;
@@ -423,11 +477,18 @@
 void cleanup_scratch_page(struct i915_address_space *vm)
 {
        struct i915_page_dma *p = px_base(&vm->scratch[0]);
+#ifdef __NetBSD__
+       bus_dmamap_unload(vm->dmat, p->map);
+       bus_dmamap_destroy(vm->dmat, p->map);
+       vm->scratch_page.map = NULL; /* paranoia */
+       bus_dmamem_free(vm->dmat, &p->seg, 1);
+#else
        unsigned int order = vm->scratch_order;
 
        dma_unmap_page(vm->dma, p->daddr, BIT(order) << PAGE_SHIFT,
                       PCI_DMA_BIDIRECTIONAL);
        __free_pages(p->page, order);
+#endif
 }
 
 void free_scratch(struct i915_address_space *vm)
diff -r 0c32b5018ff9 -r f8adbc0159d0 sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.h
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.h        Sun Dec 19 01:35:25 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/intel_gtt.h        Sun Dec 19 01:35:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_gtt.h,v 1.3 2021/12/19 01:24:25 riastradh Exp $  */
+/*     $NetBSD: intel_gtt.h,v 1.4 2021/12/19 01:35:35 riastradh Exp $  */
 
 /* SPDX-License-Identifier: MIT */
 /*
@@ -142,6 +142,13 @@
 
 struct i915_page_dma {
        struct page *page;
+#ifdef __NetBSD__
+       union {
+               bus_dma_segment_t seg;
+               uint32_t ggtt_offset;
+       };
+       bus_dmamap_t map;
+#else
        union {
                dma_addr_t daddr;
 
@@ -151,6 +158,7 @@
                 */
                u32 ggtt_offset;
        };
+#endif
 };
 
 struct i915_page_scratch {
@@ -182,7 +190,11 @@
        __px_choose_expr(px, struct i915_page_table *, &__x->base, \
        __px_choose_expr(px, struct i915_page_directory *, &__x->pt.base, \
        (void)0))))
+#ifdef __NetBSD__
+#define px_dma(px) (px_base(px)->map->dm_segs[0].ds_addr)
+#else
 #define px_dma(px) (px_base(px)->daddr)
+#endif
 
 #define px_pt(px) \
        __px_choose_expr(px, struct i915_page_table *, __x, \
@@ -213,8 +225,10 @@
 };
 
 struct pagestash {
+#ifndef __NetBSD__



Home | Main Index | Thread Index | Old Index