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 Hack i915_vma.c: rbtree,...



details:   https://anonhg.NetBSD.org/src/rev/7420adbe9414
branches:  trunk
changeset: 1028055:7420adbe9414
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 01:44:57 2021 +0000

description:
Hack i915_vma.c: rbtree, unmap by pa rather than vm object, PRIx64.

diffstat:

 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_shmem.c |    8 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_active.c        |   58 +++++++-
 sys/external/bsd/drm2/dist/drm/i915/i915_vma.c           |  111 ++++++++++-----
 3 files changed, 136 insertions(+), 41 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r 9e95702bbbe7 -r 7420adbe9414 sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_shmem.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_shmem.c  Sun Dec 19 01:44:49 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_shmem.c  Sun Dec 19 01:44:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_gem_shmem.c,v 1.4 2021/12/19 01:34:08 riastradh Exp $     */
+/*     $NetBSD: i915_gem_shmem.c,v 1.5 2021/12/19 01:44:57 riastradh Exp $     */
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_shmem.c,v 1.4 2021/12/19 01:34:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_shmem.c,v 1.5 2021/12/19 01:44:57 riastradh Exp $");
 
 #include <linux/pagevec.h>
 #include <linux/swap.h>
@@ -461,6 +461,9 @@
                          struct drm_gem_object *obj,
                          resource_size_t size)
 {
+#ifdef __NetBSD__
+       return drm_gem_object_init(dev, obj, size);
+#else
        unsigned long flags = VM_NORESERVE;
        struct file *filp;
 
@@ -476,6 +479,7 @@
 
        obj->filp = filp;
        return 0;
+#endif
 }
 
 static struct drm_i915_gem_object *
diff -r 9e95702bbbe7 -r 7420adbe9414 sys/external/bsd/drm2/dist/drm/i915/i915_active.c
--- a/sys/external/bsd/drm2/dist/drm/i915/i915_active.c Sun Dec 19 01:44:49 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/i915_active.c Sun Dec 19 01:44:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_active.c,v 1.2 2021/12/18 23:45:28 riastradh Exp $        */
+/*     $NetBSD: i915_active.c,v 1.3 2021/12/19 01:44:57 riastradh Exp $        */
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_active.c,v 1.2 2021/12/18 23:45:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_active.c,v 1.3 2021/12/19 01:44:57 riastradh Exp $");
 
 #include <linux/debugobjects.h>
 
@@ -246,6 +246,15 @@
        spin_lock_irq(&ref->tree_lock);
        GEM_BUG_ON(i915_active_is_idle(ref));
 
+#ifdef __NetBSD__
+       __USE(parent);
+       __USE(p);
+       node = rb_tree_find_node(&vma->active.rbr_tree, &idx);
+       if (node) {
+               KASSERT(node->timeline == idx);
+               goto out;
+       }
+#else
        parent = NULL;
        p = &ref->tree.rb_node;
        while (*p) {
@@ -262,14 +271,21 @@
                else
                        p = &parent->rb_left;
        }
+#endif
 
        node = prealloc;
        __i915_active_fence_init(&node->base, NULL, node_retire);
        node->ref = ref;
        node->timeline = idx;
 
+#ifdef __NetBSD__
+       struct i915_vma_active *collision __diagused;
+       collision = rb_tree_insert_node(&vma->active.rbr_tree, node);
+       KASSERT(collision == node);
+#else
        rb_link_node(&node->node, parent, p);
        rb_insert_color(&node->node, &ref->tree);
+#endif
 
 out:
        ref->cache = node;
@@ -279,6 +295,40 @@
        return &node->base;
 }
 
+#ifdef __NetBSD__
+static int
+compare_active(void *cookie, const void *va, const void *vb)
+{
+       const struct i915_active *a = va;
+       const struct i915_active *b = vb;
+
+       if (a->timeline < b->timeline)
+               return -1;
+       if (a->timeline > b->timeline)
+               return +1;
+       return 0;
+}
+
+static int
+compare_active_key(void *cookie, const void *vn, const void *vk)
+{
+       const struct i915_active *a = vn;
+       const uint64_t *k = vk;
+
+       if (a->timeline < *k)
+               return -1;
+       if (a->timeline > *k)
+               return +1;
+       return 0;
+}
+
+static const rb_tree_ops_t active_rb_ops = {
+       .rbto_compare_nodes = compare_active,
+       .rbto_compare_key = compare_active_key,
+       .rbto_node_offset = offsetof(struct i915_active, node),
+};
+#endif
+
 void __i915_active_init(struct i915_active *ref,
                        int (*active)(struct i915_active *ref),
                        void (*retire)(struct i915_active *ref),
@@ -296,7 +346,11 @@
                ref->flags |= I915_ACTIVE_RETIRE_SLEEPS;
 
        spin_lock_init(&ref->tree_lock);
+#ifdef __NetBSD__
+       rb_tree_init(&vma->active.rbr_tree, &active_rb_ops);
+#else
        ref->tree = RB_ROOT;
+#endif
        ref->cache = NULL;
 
        init_llist_head(&ref->preallocated_barriers);
diff -r 9e95702bbbe7 -r 7420adbe9414 sys/external/bsd/drm2/dist/drm/i915/i915_vma.c
--- a/sys/external/bsd/drm2/dist/drm/i915/i915_vma.c    Sun Dec 19 01:44:49 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/i915_vma.c    Sun Dec 19 01:44:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_vma.c,v 1.4 2021/12/19 01:35:25 riastradh Exp $   */
+/*     $NetBSD: i915_vma.c,v 1.5 2021/12/19 01:44:57 riastradh Exp $   */
 
 /*
  * Copyright © 2016 Intel Corporation
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_vma.c,v 1.4 2021/12/19 01:35:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_vma.c,v 1.5 2021/12/19 01:44:57 riastradh Exp $");
 
 #include <linux/sched/mm.h>
 #include <drm/drm_gem.h>
@@ -104,6 +104,49 @@
        i915_vma_put(active_to_vma(ref));
 }
 
+#ifdef __NetBSD__
+struct i915_vma_key {
+       struct i915_address_space *vm;
+       const struct i915_ggtt_view *view;
+};
+
+static int
+compare_vma(void *cookie, const void *va, const void *vb)
+{
+       const struct i915_vma *a = va;
+       const struct i915_vma *b = vb;
+       long cmp = i915_vma_compare(__UNCONST(a), b->vm, &b->ggtt_view);
+
+       return (cmp < 0 ? -1 : cmp > 0 ? +1 : 0);
+}
+
+static int
+compare_vma_key(void *cookie, const void *vn, const void *vk)
+{
+       const struct i915_vma *vma = vn;
+       const struct i915_vma_key *key = vk;
+       long cmp = i915_vma_compare(__UNCONST(vma), key->vm, key->view);
+
+       return (cmp < 0 ? -1 : cmp > 0 ? +1 : 0);
+}
+
+static const rb_tree_ops_t vma_tree_rb_ops = {
+       .rbto_compare_nodes = compare_vma,
+       .rbto_compare_key = compare_vma_key,
+       .rbto_node_offset = offsetof(struct i915_vma, obj_node),
+};
+#endif
+
+void
+i915_vma_tree_init(struct drm_i915_gem_object *obj)
+{
+#ifdef __NetBSD__
+       rb_tree_init(&obj->vma_tree.rbr_tree, &vma_tree_rb_ops);
+#else
+       obj->vma_tree = RB_ROOT;
+#endif
+}
+
 static struct i915_vma *
 vma_create(struct drm_i915_gem_object *obj,
           struct i915_address_space *vm,
@@ -186,6 +229,13 @@
                __set_bit(I915_VMA_GGTT_BIT, __i915_vma_flags(vma));
        }
 
+#ifdef __NetBSD__
+       __USE(rb);
+       __USE(p);
+       struct i915_vma *collision __diagused;
+       collision = rb_tree_insert_node(&obj->vma_tree.rbr_tree, vma);
+       KASSERT(collision == vma);
+#else
        spin_lock(&obj->vma.lock);
 
        rb = NULL;
@@ -216,6 +266,7 @@
        }
        rb_link_node(&vma->obj_node, rb, p);
        rb_insert_color(&vma->obj_node, &obj->vma.tree);
+#endif
 
        if (i915_vma_is_ggtt(vma))
                /*
@@ -242,6 +293,11 @@
           struct i915_address_space *vm,
           const struct i915_ggtt_view *view)
 {
+#ifdef __NetBSD__
+       const struct i915_vma_key key = { .vm = vm, .view = view };
+
+       return rb_tree_find_node(&obj->vma_tree.rbr_tree, &key);
+#else
        struct rb_node *rb;
 
        rb = obj->vma.tree.rb_node;
@@ -260,6 +316,7 @@
        }
 
        return NULL;
+#endif
 }
 
 /**
@@ -660,7 +717,7 @@
         * attempt to find space.
         */
        if (size > end) {
-               DRM_DEBUG("Attempting to bind an object larger than the aperture: request=%llu > %s aperture=%llu\n",
+               DRM_DEBUG("Attempting to bind an object larger than the aperture: request=%"PRIu64" > %s aperture=%"PRIu64"\n",
                          size, flags & PIN_MAPPABLE ? "mappable" : "total",
                          end);
                return -ENOSPC;
@@ -1117,7 +1174,11 @@
        if (vma->iomap == NULL)
                return;
 
+#ifdef __NetBSD__
+       io_mapping_unmap(&i915_vm_to_ggtt(vma->vm)->iomap, vma->iomap);
+#else
        io_mapping_unmap(vma->iomap);
+#endif
        vma->iomap = NULL;
 }
 
@@ -1132,12 +1193,22 @@
        GEM_BUG_ON(!i915_vma_is_map_and_fenceable(vma));
        GEM_BUG_ON(!vma->obj->userfault_count);
 
+#ifdef __NetBSD__
+       __USE(vma_offset);
+       __USE(node);
+       struct drm_i915_private *i915 = to_i915(vma->obj->base.dev);
+       paddr_t pa = i915->ggtt.gmadr.start + vma->node.start;
+       vsize_t npgs = vma->size >> PAGE_SHIFT;
+       while (npgs --> 0)
+               pmap_pv_protect(pa = (npgs << PAGE_SHIFT), VM_PROT_NONE);
+#else
        node = &vma->mmo->vma_node;
        vma_offset = vma->ggtt_view.partial.offset << PAGE_SHIFT;
        unmap_mapping_range(vma->vm->i915->drm.anon_inode->i_mapping,
                            drm_vma_node_offset_addr(node) + vma_offset,
                            vma->size,
                            1);
+#endif
 
        i915_vma_unset_userfault(vma);
        if (!--vma->obj->userfault_count)
@@ -1199,40 +1270,6 @@



Home | Main Index | Thread Index | Old Index