Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/dmover dmover(9) -- an interface to hardware-assiste...
details: https://anonhg.NetBSD.org/src/rev/4cb0a362b84d
branches: trunk
changeset: 534693:4cb0a362b84d
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Aug 02 00:30:37 2002 +0000
description:
dmover(9) -- an interface to hardware-assisted data movers. This allows
clients to use a hardware-assisted data mover to clear a region of memory,
fill a region of memory with a specific value, copy a region of memory,
and perform simple boolean operations such as XOR on multiple regions
of memory.
Included here is a software back-end which can serve as an example of
how to write a back-end (and also provides a fall-back in case hardware
for a given function is not available), as well as a dmoverio(4) pseudo-
device which provides access to dmover(9) to userland via a message
passing interface.
dmover(9) is still a work-in-progress -- a few minor changes to the
interface are expected.
diffstat:
sys/dev/dmover/Makefile | 9 +
sys/dev/dmover/dmover_backend.c | 269 ++++++++++++++
sys/dev/dmover/dmover_io.c | 733 ++++++++++++++++++++++++++++++++++++++++
sys/dev/dmover/dmover_io.h | 92 +++++
sys/dev/dmover/dmover_process.c | 199 ++++++++++
sys/dev/dmover/dmover_request.c | 145 +++++++
sys/dev/dmover/dmover_session.c | 137 +++++++
sys/dev/dmover/dmover_util.c | 78 ++++
sys/dev/dmover/dmovervar.h | 265 ++++++++++++++
sys/dev/dmover/files.dmover | 19 +
sys/dev/dmover/swdmover.c | 385 +++++++++++++++++++++
11 files changed, 2331 insertions(+), 0 deletions(-)
diffs (truncated from 2375 to 300 lines):
diff -r b5a892b05101 -r 4cb0a362b84d sys/dev/dmover/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/dmover/Makefile Fri Aug 02 00:30:37 2002 +0000
@@ -0,0 +1,9 @@
+# $NetBSD: Makefile,v 1.1 2002/08/02 00:30:37 thorpej Exp $
+
+KDIR= /sys/dev/dmover
+INCSDIR= /usr/include/dev/dmover
+
+# Only install includes which are used by userland
+INCS= dmover_io.h
+
+.include <bsd.kinc.mk>
diff -r b5a892b05101 -r 4cb0a362b84d sys/dev/dmover/dmover_backend.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/dmover/dmover_backend.c Fri Aug 02 00:30:37 2002 +0000
@@ -0,0 +1,269 @@
+/* $NetBSD: dmover_backend.c,v 1.1 2002/08/02 00:30:38 thorpej Exp $ */
+
+/*
+ * Copyright (c) 2002 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
+ * 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.
+ */
+
+/*
+ * dmover_backend.c: Backend management functions for dmover-api.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD");
+
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/systm.h>
+
+#include <dev/dmover/dmovervar.h>
+
+TAILQ_HEAD(, dmover_backend) dmover_backend_list;
+struct lock dmover_backend_list_lock;
+
+#define BACKEND_LIST_LOCK_READ() \
+do { \
+ (void) spinlockmgr(&dmover_backend_list_lock, LK_SHRED, NULL); \
+} while (/*CONSTCOND*/0)
+
+#define BACKEND_LIST_UNLOCK_READ() \
+do { \
+ (void) spinlockmgr(&dmover_backend_list_lock, LK_RELEASE, NULL);\
+} while (/*CONSTCOND*/0)
+
+#define BACKEND_LIST_LOCK_WRITE(s) \
+do { \
+ (s) = splbio(); \
+ (void) spinlockmgr(&dmover_backend_list_lock, LK_EXCLUSIVE, NULL); \
+} while (/*CONSTCOND*/0)
+
+#define BACKEND_LIST_UNLOCK_WRITE(s) \
+do { \
+ (void) spinlockmgr(&dmover_backend_list_lock, LK_RELEASE, NULL);\
+ splx((s)); \
+} while (/*CONSTCOND*/0)
+
+static int initialized;
+static struct simplelock initialized_slock = SIMPLELOCK_INITIALIZER;
+
+static void
+initialize(void)
+{
+
+ simple_lock(&initialized_slock);
+ if (__predict_true(initialized == 0)) {
+ TAILQ_INIT(&dmover_backend_list);
+ spinlockinit(&dmover_backend_list_lock, "dmbelk", 0);
+
+ /* Initialize the other bits of dmover. */
+ dmover_session_initialize();
+ dmover_request_initialize();
+ dmover_process_initialize();
+
+ initialized = 1;
+ }
+ simple_unlock(&initialized_slock);
+}
+
+/*
+ * dmover_backend_register: [back-end interface function]
+ *
+ * Register a back-end with dmover-api.
+ */
+void
+dmover_backend_register(struct dmover_backend *dmb)
+{
+ int s;
+
+ if (__predict_false(initialized == 0))
+ initialize();
+
+ LIST_INIT(&dmb->dmb_sessions);
+ dmb->dmb_nsessions = 0;
+
+ TAILQ_INIT(&dmb->dmb_pendreqs);
+ dmb->dmb_npendreqs = 0;
+
+ BACKEND_LIST_LOCK_WRITE(s);
+ TAILQ_INSERT_TAIL(&dmover_backend_list, dmb, dmb_list);
+ BACKEND_LIST_UNLOCK_WRITE(s);
+}
+
+/*
+ * dmover_backend_unregister: [back-end interface function]
+ *
+ * Un-register a back-end from dmover-api.
+ */
+void
+dmover_backend_unregister(struct dmover_backend *dmb)
+{
+ int s;
+
+#ifdef DIAGNOSTIC
+ if (__predict_false(initialized == 0)) {
+ int croak;
+
+ simple_lock(&initialized_slock);
+ croak = (initialized == 0);
+ simple_unlock(&initialized_slock);
+
+ if (croak)
+ panic("dmover_backend_unregister: not initialized");
+ }
+#endif
+
+ /* XXX */
+ if (dmb->dmb_nsessions)
+ panic("dmover_backend_unregister");
+
+ BACKEND_LIST_LOCK_WRITE(s);
+ TAILQ_REMOVE(&dmover_backend_list, dmb, dmb_list);
+ BACKEND_LIST_UNLOCK_WRITE(s);
+}
+
+/*
+ * dmover_backend_alloc:
+ *
+ * Allocate and return a back-end on behalf of a session.
+ */
+int
+dmover_backend_alloc(struct dmover_session *dses, const char *type)
+{
+ struct dmover_backend *dmb, *best_dmb = NULL;
+ const struct dmover_algdesc *algdesc, *best_algdesc = NULL;
+
+ if (__predict_false(initialized == 0)) {
+ int fail;
+
+ simple_lock(&initialized_slock);
+ fail = (initialized == 0);
+ simple_unlock(&initialized_slock);
+
+ if (fail)
+ return (ESRCH);
+ }
+
+ BACKEND_LIST_LOCK_READ();
+
+ /* First, find a back-end that can handle the session parts. */
+ for (dmb = TAILQ_FIRST(&dmover_backend_list); dmb != NULL;
+ dmb = TAILQ_NEXT(dmb, dmb_list)) {
+ /*
+ * First, check to see if the back-end supports the
+ * function we wish to perform.
+ */
+ algdesc = dmover_algdesc_lookup(dmb->dmb_algdescs,
+ dmb->dmb_nalgdescs, type);
+ if (algdesc == NULL)
+ continue;
+
+ if (best_dmb == NULL) {
+ best_dmb = dmb;
+ best_algdesc = algdesc;
+ continue;
+ }
+
+ /*
+ * XXX All the stuff from here on should be shot in
+ * XXX the head. Instead, we should build a list
+ * XXX of candidates, and select the best back-end
+ * XXX when a request is scheduled for processing.
+ */
+
+ if (dmb->dmb_speed >= best_dmb->dmb_speed) {
+ /*
+ * If the current best match is slower than
+ * this back-end, then this one is the new
+ * best match.
+ */
+ if (dmb->dmb_speed > best_dmb->dmb_speed) {
+ best_dmb = dmb;
+ best_algdesc = algdesc;
+ continue;
+ }
+
+ /*
+ * If this back-end has fewer sessions allocated
+ * to it than the current best match, then this
+ * one is now the best match.
+ */
+ if (best_dmb->dmb_nsessions > dmb->dmb_nsessions) {
+ best_dmb = dmb;
+ best_algdesc = algdesc;
+ continue;
+ }
+ }
+ }
+ if (best_dmb == NULL) {
+ BACKEND_LIST_UNLOCK_READ();
+ return (ESRCH);
+ }
+
+ KASSERT(best_algdesc != NULL);
+
+ /* Plug the back-end into the static (XXX) assignment. */
+ dses->__dses_assignment.das_backend = best_dmb;
+ dses->__dses_assignment.das_algdesc = best_algdesc;
+
+ dses->dses_ninputs = algdesc->dad_ninputs;
+
+ LIST_INSERT_HEAD(&best_dmb->dmb_sessions, dses, __dses_list);
+ best_dmb->dmb_nsessions++;
+
+ BACKEND_LIST_UNLOCK_READ();
+
+ return (0);
+}
+
+/*
+ * dmover_backend_release:
+ *
+ * Release the back-end from the specified session.
+ */
+void
+dmover_backend_release(struct dmover_session *dses)
+{
+ struct dmover_backend *dmb;
+
+ BACKEND_LIST_UNLOCK_READ();
+
+ /* XXX Clear out the static assignment. */
+ dmb = dses->__dses_assignment.das_backend;
+ dses->__dses_assignment.das_backend = NULL;
+ dses->__dses_assignment.das_algdesc = NULL;
+
+ LIST_REMOVE(dses, __dses_list);
+ dmb->dmb_nsessions--;
+
+ BACKEND_LIST_UNLOCK_READ();
+}
diff -r b5a892b05101 -r 4cb0a362b84d sys/dev/dmover/dmover_io.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/dmover/dmover_io.c Fri Aug 02 00:30:37 2002 +0000
@@ -0,0 +1,733 @@
+/* $NetBSD: dmover_io.c,v 1.1 2002/08/02 00:30:38 thorpej Exp $ */
+
+/*
+ * Copyright (c) 2002 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
Home |
Main Index |
Thread Index |
Old Index