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 Draft implementation of the Linux rese...



details:   https://anonhg.NetBSD.org/src/rev/e4323c67aa37
branches:  trunk
changeset: 835231:e4323c67aa37
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 13:33:59 2018 +0000

description:
Draft implementation of the Linux reservation and fence APIs.

diffstat:

 sys/external/bsd/drm2/include/linux/fence.h       |   29 +-
 sys/external/bsd/drm2/include/linux/reservation.h |   86 +-
 sys/external/bsd/drm2/linux/files.drmkms_linux    |    4 +-
 sys/external/bsd/drm2/linux/linux_fence.c         |  537 ++++++++++++++++++
 sys/external/bsd/drm2/linux/linux_module.c        |    7 +-
 sys/external/bsd/drm2/linux/linux_reservation.c   |  638 ++++++++++++++++++++++
 6 files changed, 1232 insertions(+), 69 deletions(-)

diffs (truncated from 1457 to 300 lines):

diff -r cd3d9b99ff22 -r e4323c67aa37 sys/external/bsd/drm2/include/linux/fence.h
--- a/sys/external/bsd/drm2/include/linux/fence.h       Mon Aug 27 13:31:36 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/fence.h       Mon Aug 27 13:33:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fence.h,v 1.10 2018/08/27 07:53:05 riastradh Exp $     */
+/*     $NetBSD: fence.h,v 1.11 2018/08/27 13:33:59 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -33,9 +33,13 @@
 #define        _LINUX_FENCE_H_
 
 #include <sys/types.h>
+#include <sys/condvar.h>
+#include <sys/kernel.h>
+#include <sys/queue.h>
 
-#include <linux/mutex.h>
+#include <linux/kref.h>
 #include <linux/rcupdate.h>
+#include <linux/spinlock.h>
 
 struct fence_cb;
 
@@ -46,10 +50,15 @@
        unsigned                context;
        unsigned                seqno;
        const struct fence_ops  *ops;
+
+       TAILQ_HEAD(, fence_cb)  f_callbacks;
+       kcondvar_t              f_cv;
+       struct rcu_head         f_rcu;
 };
 
-#define        FENCE_FLAG_SIGNALED_BIT __BIT(0)
-#define        FENCE_FLAG_USER_BITS    __BIT(1)
+#define        FENCE_FLAG_ENABLE_SIGNAL_BIT    0
+#define        FENCE_FLAG_SIGNALED_BIT         1
+#define        FENCE_FLAG_USER_BITS            2
 
 struct fence_ops {
        const char      *(*get_driver_name)(struct fence *);
@@ -63,14 +72,19 @@
 typedef void (*fence_func_t)(struct fence *, struct fence_cb *);
 
 struct fence_cb {
-       fence_func_t    fcb_func;
+       fence_func_t            fcb_func;
+       TAILQ_ENTRY(fence_cb)   fcb_entry;
+       bool                    fcb_onqueue;
 };
 
 #define        fence_add_callback      linux_fence_add_callback
 #define        fence_context_alloc     linux_fence_context_alloc
+#define        fence_destroy           linux_fence_destroy
 #define        fence_enable_sw_signaling linux_fence_enable_sw_signaling
 #define        fence_get               linux_fence_get
 #define        fence_init              linux_fence_init
+#define        fence_is_signaled       linux_fence_is_signaled
+#define        fence_is_signaled_locked linux_fence_is_signaled_locked
 #define        fence_put               linux_fence_put
 #define        fence_remove_callback   linux_fence_remove_callback
 #define        fence_signal            linux_fence_signal
@@ -80,6 +94,7 @@
 
 void   fence_init(struct fence *, const struct fence_ops *, spinlock_t *,
            unsigned, unsigned);
+void   fence_destroy(struct fence *);
 void   fence_free(struct fence *);
 
 unsigned
@@ -87,6 +102,8 @@
 
 struct fence *
        fence_get(struct fence *);
+struct fence *
+       fence_get_rcu(struct fence *);
 void   fence_put(struct fence *);
 
 int    fence_add_callback(struct fence *, struct fence_cb *, fence_func_t);
@@ -99,7 +116,7 @@
 int    fence_signal_locked(struct fence *);
 long   fence_default_wait(struct fence *, bool, long);
 long   fence_wait(struct fence *, bool);
-long   fence_wait_timeout(struct fence *, bool, int);
+long   fence_wait_timeout(struct fence *, bool, long);
 
 static inline void
 FENCE_TRACE(struct fence *f, const char *fmt, ...)
diff -r cd3d9b99ff22 -r e4323c67aa37 sys/external/bsd/drm2/include/linux/reservation.h
--- a/sys/external/bsd/drm2/include/linux/reservation.h Mon Aug 27 13:31:36 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/reservation.h Mon Aug 27 13:33:59 2018 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: reservation.h,v 1.4 2018/08/27 07:34:41 riastradh Exp $        */
+/*     $NetBSD: reservation.h,v 1.5 2018/08/27 13:33:59 riastradh Exp $        */
 
 /*-
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -29,89 +29,61 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _LINUX_RESERVATION_H_
-#define _LINUX_RESERVATION_H_
-
-#include <sys/atomic.h>
+#ifndef        _LINUX_RESERVATION_H_
+#define        _LINUX_RESERVATION_H_
 
 #include <linux/rcupdate.h>
 #include <linux/ww_mutex.h>
 
 struct fence;
 
-extern struct ww_class reservation_ww_class;
-
 struct reservation_object {
        struct ww_mutex         lock;
 
-       struct reservation_object_list __rcu    *robj_objlist;
-       struct fence __rcu                      *robj_fence_excl;
+       unsigned                                robj_version;
+       struct fence __rcu                      *robj_fence;
+       struct reservation_object_list __rcu    *robj_list;
+       struct reservation_object_list __rcu    *robj_prealloc;
+       uint32_t                                robj_nreserved;
 };
 
 struct reservation_object_list {
+       struct rcu_head         rol_rcu;
+
        uint32_t                shared_count;
+       uint32_t                shared_max;
        struct fence __rcu      *shared[];
 };
 
 #define        reservation_object_add_excl_fence       linux_reservation_object_add_excl_fence
 #define        reservation_object_add_shared_fence     linux_reservation_object_add_shared_fence
+#define        reservation_object_fini                 linux_reservation_object_fini
+#define        reservation_object_get_excl             linux_reservation_object_get_excl
+#define        reservation_object_get_list             linux_reservation_object_get_list
+#define        reservation_object_held                 linux_reservation_object_held
+#define        reservation_object_init                 linux_reservation_object_init
 #define        reservation_object_reserve_shared       linux_reservation_object_reserve_shared
 #define        reservation_object_test_signaled_rcu    linux_reservation_object_test_signaled_rcu
 #define        reservation_object_wait_timeout_rcu     linux_reservation_object_wait_timeout_rcu
+#define        reservation_ww_class                    linux_reservation_ww_class
 
+extern struct ww_class reservation_ww_class;
+
+void   reservation_object_init(struct reservation_object *);
+void   reservation_object_fini(struct reservation_object *);
+bool   reservation_object_held(struct reservation_object *);
+struct fence *
+       reservation_object_get_excl(struct reservation_object *);
+struct reservation_object_list *
+       reservation_object_get_list(struct reservation_object *);
+int    reservation_object_reserve_shared(struct reservation_object *);
 void   reservation_object_add_excl_fence(struct reservation_object *,
            struct fence *);
 void   reservation_object_add_shared_fence(struct reservation_object *,
            struct fence *);
-int    reservation_object_reserve_shared(struct reservation_object *);
 bool   reservation_object_test_signaled_rcu(struct reservation_object *,
            bool);
 long   reservation_object_wait_timeout_rcu(struct reservation_object *,
            bool, bool, unsigned long);
 
-static inline void
-reservation_object_init(struct reservation_object *reservation)
-{
-
-       ww_mutex_init(&reservation->lock, &reservation_ww_class);
-}
-
-static inline void
-reservation_object_fini(struct reservation_object *reservation)
-{
-
-       ww_mutex_destroy(&reservation->lock);
-}
-
-static inline bool
-reservation_object_held(struct reservation_object *reservation)
-{
-
-       return ww_mutex_is_locked(&reservation->lock);
-}
-
-static inline struct fence *
-reservation_object_get_excl(struct reservation_object *reservation)
-{
-       struct fence *fence;
-
-       KASSERT(reservation_object_held(reservation));
-       fence = reservation->robj_fence_excl;
-       membar_datadep_consumer();
-
-       return fence;
-}
-
-static inline struct reservation_object_list *
-reservation_object_get_list(struct reservation_object *reservation)
-{
-       struct reservation_object_list *objlist;
-
-       KASSERT(reservation_object_held(reservation));
-       objlist = reservation->robj_objlist;
-       membar_datadep_consumer();
-
-       return objlist;
-}
-
-#endif  /* _LINUX_RESERVATION_H_ */
+#endif /* _LINUX_RESERVATION_H_ */
diff -r cd3d9b99ff22 -r e4323c67aa37 sys/external/bsd/drm2/linux/files.drmkms_linux
--- a/sys/external/bsd/drm2/linux/files.drmkms_linux    Mon Aug 27 13:31:36 2018 +0000
+++ b/sys/external/bsd/drm2/linux/files.drmkms_linux    Mon Aug 27 13:33:59 2018 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: files.drmkms_linux,v 1.12 2018/08/27 13:31:37 riastradh Exp $
+#       $NetBSD: files.drmkms_linux,v 1.13 2018/08/27 13:33:59 riastradh Exp $
 
 define drmkms_linux: i2cexec, i2c_bitbang
 
@@ -6,11 +6,13 @@
 makeoptions    drmkms_linux    CPPFLAGS+="-I$S/external/bsd/common/include"
 
 file   external/bsd/drm2/linux/linux_dmi.c             drmkms_linux
+file   external/bsd/drm2/linux/linux_fence.c           drmkms_linux
 file   external/bsd/drm2/linux/linux_i2c.c             drmkms_linux
 file   external/bsd/drm2/linux/linux_idr.c             drmkms_linux
 file   external/bsd/drm2/linux/linux_kmap.c            drmkms_linux
 file   external/bsd/drm2/linux/linux_list_sort.c       drmkms_linux
 file   external/bsd/drm2/linux/linux_module.c          drmkms_linux
 file   external/bsd/drm2/linux/linux_rcu.c             drmkms_linux
+file   external/bsd/drm2/linux/linux_reservation.c     drmkms_linux
 file   external/bsd/drm2/linux/linux_writecomb.c       drmkms_linux
 file   external/bsd/drm2/linux/linux_ww_mutex.c        drmkms_linux
diff -r cd3d9b99ff22 -r e4323c67aa37 sys/external/bsd/drm2/linux/linux_fence.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/linux/linux_fence.c Mon Aug 27 13:33:59 2018 +0000
@@ -0,0 +1,537 @@
+/*     $NetBSD: linux_fence.c,v 1.1 2018/08/27 13:33:59 riastradh Exp $        */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.1 2018/08/27 13:33:59 riastradh Exp $");
+
+#include <sys/atomic.h>
+#include <sys/condvar.h>
+#include <sys/queue.h>
+
+#include <linux/errno.h>
+#include <linux/kref.h>
+#include <linux/fence.h>
+#include <linux/sched.h>
+#include <linux/spinlock.h>
+
+/*
+ * fence_init(fence, ops, lock, context, seqno)
+ *
+ *     Initialize fence.  Caller should call fence_destroy when done,
+ *     after all references have been released.
+ */
+void
+fence_init(struct fence *fence, const struct fence_ops *ops, spinlock_t *lock,
+    unsigned context, unsigned seqno)
+{



Home | Main Index | Thread Index | Old Index