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/i915drm i915: Disentangle uabi engines...



details:   https://anonhg.NetBSD.org/src/rev/0c2d4fd860fa
branches:  trunk
changeset: 1028724:0c2d4fd860fa
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 11:51:59 2021 +0000

description:
i915: Disentangle uabi engines rb/llist/list spaghetti.

diffstat:

 sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_types.h |   8 +-
 sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_user.c  |  92 +++++++++++-
 sys/external/bsd/drm2/dist/drm/i915/i915_drv.h              |   7 +-
 sys/external/bsd/drm2/i915drm/files.i915drmkms              |   4 +-
 4 files changed, 91 insertions(+), 20 deletions(-)

diffs (260 lines):

diff -r af42e783a7a7 -r 0c2d4fd860fa sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_types.h
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_types.h       Sun Dec 19 11:51:51 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_types.h       Sun Dec 19 11:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_engine_types.h,v 1.6 2021/12/19 11:46:47 riastradh Exp $ */
+/*     $NetBSD: intel_engine_types.h,v 1.7 2021/12/19 11:51:59 riastradh Exp $ */
 
 /*
  * SPDX-License-Identifier: MIT
@@ -299,7 +299,11 @@
        unsigned int context_tag;
 #define NUM_CONTEXT_TAG roundup_pow_of_two(2 * EXECLIST_MAX_PORTS)
 
-       struct rb_node uabi_node;
+       union {
+               struct rb_node rbtree;
+               struct llist_node llist;
+               struct list_head list;
+       } uabi_node;
 
        struct intel_sseu sseu;
 
diff -r af42e783a7a7 -r 0c2d4fd860fa sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_user.c
--- a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_user.c        Sun Dec 19 11:51:51 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/gt/intel_engine_user.c        Sun Dec 19 11:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_engine_user.c,v 1.3 2021/12/19 11:38:37 riastradh Exp $  */
+/*     $NetBSD: intel_engine_user.c,v 1.4 2021/12/19 11:51:59 riastradh Exp $  */
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intel_engine_user.c,v 1.3 2021/12/19 11:38:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intel_engine_user.c,v 1.4 2021/12/19 11:51:59 riastradh Exp $");
 
 #include <linux/list.h>
 #include <linux/list_sort.h>
@@ -20,9 +20,57 @@
 
 #include <linux/nbsd-namespace.h>
 
+#ifdef __NetBSD__
+
+static int
+compare_engines(void *cookie, const void *va, const void *vb)
+{
+       const struct intel_engine_cs *csa = va;
+       const struct intel_engine_cs *csb = vb;
+
+       if (csa->class < csb->class)
+               return -1;
+       if (csa->class > csb->class)
+               return +1;
+       if (csa->instance < csb->instance)
+               return -1;
+       if (csa->instance > csb->instance)
+               return +1;
+       return 0;
+}
+
+static int
+compare_engine_key(void *cookie, const void *vn, const void *vk)
+{
+       const struct intel_engine_cs *cs = vn;
+       const u8 *k = vk;
+
+       if (cs->class < k[0])
+               return -1;
+       if (cs->class > k[0])
+               return +1;
+       if (cs->instance < k[1])
+               return -1;
+       if (cs->instance > k[1])
+               return +1;
+       return 0;
+}
+
+static const rb_tree_ops_t engine_ops = {
+       .rbto_compare_nodes = compare_engines,
+       .rbto_compare_key = compare_engine_key,
+       .rbto_node_offset = offsetof(struct intel_engine_cs, uabi_node.rbtree),
+};
+
+#endif
+
 struct intel_engine_cs *
 intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)
 {
+#ifdef __NetBSD__
+       const u8 key[2] = {class, instance};
+       return rb_tree_find_node(&i915->uabi_engines.rbr_tree, key);
+#else
        struct rb_node *p = i915->uabi_engines.rb_node;
 
        while (p) {
@@ -41,12 +89,12 @@
        }
 
        return NULL;
+#endif
 }
 
 void intel_engine_add_user(struct intel_engine_cs *engine)
 {
-       llist_add((struct llist_node *)&engine->uabi_node,
-                 (struct llist_head *)&engine->i915->uabi_engines);
+       llist_add(&engine->uabi_node.llist, &engine->i915->uabi_engines_llist);
 }
 
 static const u8 uabi_classes[] = {
@@ -59,9 +107,9 @@
 static int engine_cmp(void *priv, struct list_head *A, struct list_head *B)
 {
        const struct intel_engine_cs *a =
-               container_of((struct rb_node *)A, typeof(*a), uabi_node);
+               container_of(A, typeof(*a), uabi_node.list);
        const struct intel_engine_cs *b =
-               container_of((struct rb_node *)B, typeof(*b), uabi_node);
+               container_of(B, typeof(*b), uabi_node.list);
 
        if (uabi_classes[a->class] < uabi_classes[b->class])
                return -1;
@@ -78,7 +126,7 @@
 
 static struct llist_node *get_engines(struct drm_i915_private *i915)
 {
-       return llist_del_all((struct llist_head *)&i915->uabi_engines);
+       return llist_del_all(&i915->uabi_engines_llist);
 }
 
 static void sort_engines(struct drm_i915_private *i915,
@@ -88,9 +136,8 @@
 
        llist_for_each_safe(pos, next, get_engines(i915)) {
                struct intel_engine_cs *engine =
-                       container_of((struct rb_node *)pos, typeof(*engine),
-                                    uabi_node);
-               list_add((struct list_head *)&engine->uabi_node, engines);
+                       llist_entry(pos, typeof(*engine), uabi_node.llist);
+               list_add(&engine->uabi_node.list, engines);
        }
        list_sort(NULL, engines, engine_cmp);
 }
@@ -200,12 +247,17 @@
 
        sort_engines(i915, &engines);
 
+#ifdef __NetBSD__
+       __USE(prev);
+       __USE(p);
+       rb_tree_init(&i915->uabi_engines.rbr_tree, &engine_ops);
+#else
        prev = NULL;
        p = &i915->uabi_engines.rb_node;
+#endif
        list_for_each_safe(it, next, &engines) {
                struct intel_engine_cs *engine =
-                       container_of((struct rb_node *)it, typeof(*engine),
-                                    uabi_node);
+                       container_of(it, typeof(*engine), uabi_node.list);
                char old[sizeof(engine->name)];
 
                if (intel_gt_has_init_error(engine->gt))
@@ -224,8 +276,15 @@
                          engine->uabi_instance);
                DRM_DEBUG_DRIVER("renamed %s to %s\n", old, engine->name);
 
+#ifdef __NetBSD__
+               struct intel_engine_cs *collision __diagused;
+               collision = rb_tree_insert_node(&i915->uabi_engines.rbr_tree,
+                   engine);
+               KASSERT(collision == engine);
+#else
                rb_link_node(&engine->uabi_node, prev, p);
                rb_insert_color(&engine->uabi_node, &i915->uabi_engines);
+#endif
 
                GEM_BUG_ON(intel_engine_lookup_user(i915,
                                                    engine->uabi_class,
@@ -234,11 +293,13 @@
                /* Fix up the mapping to match default execbuf::user_map[] */
                add_legacy_ring(&ring, engine);
 
+#ifndef __NetBSD__
                prev = &engine->uabi_node;
                p = &prev->rb_right;
+#endif
        }
 
-       if (IS_ENABLED(CONFIG_DRM_I915_SELFTESTS) &&
+       if (IS_ENABLED(CONFIG_DRM_I915_SELFTEST) &&
            IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) {
                struct intel_engine_cs *engine;
                unsigned int isolation;
@@ -286,7 +347,12 @@
                }
 
                if (WARN(errors, "Invalid UABI engine mapping found"))
+#ifdef __NetBSD__
+                       rb_tree_init(&i915->uabi_engines.rbr_tree,
+                           &engine_ops);
+#else
                        i915->uabi_engines = RB_ROOT;
+#endif
        }
 
        set_scheduler_caps(i915);
diff -r af42e783a7a7 -r 0c2d4fd860fa sys/external/bsd/drm2/dist/drm/i915/i915_drv.h
--- a/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h    Sun Dec 19 11:51:51 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h    Sun Dec 19 11:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_drv.h,v 1.44 2021/12/19 11:33:49 riastradh Exp $  */
+/*     $NetBSD: i915_drv.h,v 1.45 2021/12/19 11:51:59 riastradh Exp $  */
 
 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
  */
@@ -987,6 +987,7 @@
 
        struct intel_engine_cs *engine[I915_NUM_ENGINES];
        struct rb_root uabi_engines;
+       struct llist_head uabi_engines_llist;
 
        struct resource mch_res;
 
@@ -1381,12 +1382,12 @@
             0;)
 
 #define rb_to_uabi_engine(rb) \
-       rb_entry_safe(rb, struct intel_engine_cs, uabi_node)
+       rb_entry_safe(rb, struct intel_engine_cs, uabi_node.rbtree)
 
 #define for_each_uabi_engine(engine__, i915__) \
        for ((engine__) = rb_to_uabi_engine(rb_first(&(i915__)->uabi_engines));\
             (engine__); \
-            (engine__) = rb_to_uabi_engine(rb_next2(&(i915__)->uabi_engines, &(engine__)->uabi_node)))
+            (engine__) = rb_to_uabi_engine(rb_next2(&(i915__)->uabi_engines, &(engine__)->uabi_node.rbtree)))
 
 #define I915_GTT_OFFSET_NONE ((u32)-1)
 
diff -r af42e783a7a7 -r 0c2d4fd860fa sys/external/bsd/drm2/i915drm/files.i915drmkms
--- a/sys/external/bsd/drm2/i915drm/files.i915drmkms    Sun Dec 19 11:51:51 2021 +0000
+++ b/sys/external/bsd/drm2/i915drm/files.i915drmkms    Sun Dec 19 11:51:59 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i915drmkms,v 1.81 2021/12/19 11:50:31 riastradh Exp $
+#      $NetBSD: files.i915drmkms,v 1.82 2021/12/19 11:51:59 riastradh Exp $
 
 version        20180827
 
@@ -171,7 +171,7 @@
 file   external/bsd/drm2/dist/drm/i915/gt/intel_engine_heartbeat.c     i915drmkms
 #file  external/bsd/drm2/dist/drm/i915/gt/intel_engine_pm.c    i915drmkms
 file   external/bsd/drm2/dist/drm/i915/gt/intel_engine_pool.c  i915drmkms
-#file  external/bsd/drm2/dist/drm/i915/gt/intel_engine_user.c  i915drmkms
+file   external/bsd/drm2/dist/drm/i915/gt/intel_engine_user.c  i915drmkms
 file   external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c i915drmkms
 file   external/bsd/drm2/dist/drm/i915/gt/intel_gt.c   i915drmkms
 file   external/bsd/drm2/dist/drm/i915/gt/intel_gt_irq.c       i915drmkms



Home | Main Index | Thread Index | Old Index