Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode Add ATAPI passtrough support giving the Ne...



details:   https://anonhg.NetBSD.org/src/rev/0c4b114e87e6
branches:  trunk
changeset: 323250:0c4b114e87e6
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Tue Jun 05 20:02:42 2018 +0000

description:
Add ATAPI passtrough support giving the NetBSD/usermode kernel full control of
an ATAPI device. All ATAPI/SCSI commands are passed trough.

Note that ATAPI/SCSI calls are made in the foreground still. Lengthy calls
will still hug the CPU until completion. Making it asynchronous is in the
pipeline

diffstat:

 sys/arch/usermode/conf/GENERIC.common |   16 +-
 sys/arch/usermode/conf/files.usermode |   12 +-
 sys/arch/usermode/dev/mainbus.c       |   13 +-
 sys/arch/usermode/dev/vatapi.c        |  345 ++++++++++++++++++++++++++++++++++
 sys/arch/usermode/include/mainbus.h   |    7 +-
 sys/arch/usermode/usermode/machdep.c  |   61 +++++-
 6 files changed, 442 insertions(+), 12 deletions(-)

diffs (truncated from 605 to 300 lines):

diff -r 32896622e698 -r 0c4b114e87e6 sys/arch/usermode/conf/GENERIC.common
--- a/sys/arch/usermode/conf/GENERIC.common     Tue Jun 05 15:37:52 2018 +0000
+++ b/sys/arch/usermode/conf/GENERIC.common     Tue Jun 05 20:02:42 2018 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: GENERIC.common,v 1.27 2018/01/13 16:20:33 reinoud Exp $
+# $NetBSD: GENERIC.common,v 1.28 2018/06/05 20:02:42 reinoud Exp $
 
 include "arch/usermode/conf/std.usermode"
 
 options        INCLUDE_CONFIG_FILE
-#ident                 "GENERIC-$Revision: 1.27 $"
+#ident                 "GENERIC-$Revision: 1.28 $"
 maxusers       32
 
 makeoptions    DEBUG="-O1 -g3"
@@ -64,7 +64,6 @@
 veth0          at mainbus?
 vaudio0                at mainbus?
 audio0         at vaudio0
-
 spkr*          at audio?               # PC speaker (synthesized)
 
 vncfb0         at mainbus?
@@ -77,6 +76,17 @@
 options        WSKBD_DEFAULT_KEYREPEAT_DELN=200
 options        WSDISPLAY_COMPAT_USL            # wsconscfg VT handling
 
+# virtual devices */
+vatapi*                at mainbus?
+atapibus*      at vatapi?
+
+# cd, sd, and the like
+cd*            at atapibus?
+sd*            at atapibus?
+st*            at atapibus?
+uk*            at atapibus?
+
+# pseudo devices
 pseudo-device  loop
 pseudo-device  pty
 pseudo-device  bpfilter
diff -r 32896622e698 -r 0c4b114e87e6 sys/arch/usermode/conf/files.usermode
--- a/sys/arch/usermode/conf/files.usermode     Tue Jun 05 15:37:52 2018 +0000
+++ b/sys/arch/usermode/conf/files.usermode     Tue Jun 05 20:02:42 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.usermode,v 1.16 2011/12/30 20:08:36 jmcneill Exp $
+# $NetBSD: files.usermode,v 1.17 2018/06/05 20:02:42 reinoud Exp $
 
 maxpartitions 8
 maxusers 8 16 64
@@ -42,6 +42,16 @@
 file   arch/usermode/dev/vncfb.c               vncfb
 file   arch/usermode/dev/vnckbdmap.c           vncfb
 
+include "dev/scsipi/files.scsipi"
+#device        vscsi: scsi
+#file  arch/usermode/dev/vscsi.c               vscsi needs-flag
+#attach        vscsi at thunkbus with vscsi_thunkbus
+#file  atch/usermode/dev/vscsi_thunkbus.c      vscsi_thunkbus
+
+device vatapi { } : atapi, atapibus
+attach vatapi at thunkbus with vatapi_thunkbus
+file   arch/usermode/dev/vatapi.c              vatapi_thunkbus
+
 file   arch/usermode/usermode/copy.c
 file   arch/usermode/usermode/intr.c
 file   arch/usermode/usermode/machdep.c
diff -r 32896622e698 -r 0c4b114e87e6 sys/arch/usermode/dev/mainbus.c
--- a/sys/arch/usermode/dev/mainbus.c   Tue Jun 05 15:37:52 2018 +0000
+++ b/sys/arch/usermode/dev/mainbus.c   Tue Jun 05 20:02:42 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.9 2012/01/07 18:10:18 jmcneill Exp $ */
+/* $NetBSD: mainbus.c,v 1.10 2018/06/05 20:02:43 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.9 2012/01/07 18:10:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.10 2018/06/05 20:02:43 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -52,6 +52,9 @@
 
 extern char *usermode_disk_image_path[];
 extern int usermode_disk_image_path_count;
+extern int   usermode_vdev_type[];
+extern char *usermode_vdev_path[];
+extern int usermode_vdev_count;
 extern char *usermode_tap_device;
 extern char *usermode_tap_eaddr;
 extern char *usermode_audio_device;
@@ -111,6 +114,12 @@
                taa.u.diskimage.path = usermode_disk_image_path[i];
                config_found_ia(self, "thunkbus", &taa, mainbus_print);
        }
+
+       for (i = 0; i < usermode_vdev_count; i++) {
+               taa.taa_type = usermode_vdev_type[i];
+               taa.u.vdev.path = usermode_vdev_path[i];
+               config_found_ia(self, "thunkbus", &taa, mainbus_print);
+       }
 }
 
 static int
diff -r 32896622e698 -r 0c4b114e87e6 sys/arch/usermode/dev/vatapi.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/usermode/dev/vatapi.c    Tue Jun 05 20:02:42 2018 +0000
@@ -0,0 +1,345 @@
+/* $NetBSD: vatapi.c,v 1.1 2018/06/05 20:02:43 reinoud Exp $ */
+
+/*-
+ * Copyright (c) 2018 Reinoud Zandijk <reinoud%NetBSD.org@localhost>
+ * All rights reserved.
+ *
+ * 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: vatapi.c,v 1.1 2018/06/05 20:02:43 reinoud Exp $");
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/buf.h>
+#include <sys/disk.h>
+#include <sys/kmem.h>
+#include <sys/malloc.h>
+#include <sys/scsiio.h>
+
+#include <machine/mainbus.h>
+#include <machine/thunk.h>
+#include <machine/intr.h>
+
+#include <dev/scsipi/scsi_all.h>       /* for SCSI status */
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsipiconf.h>
+#include <dev/scsipi/atapiconf.h>
+
+/* parameter? */
+#define VDEV_ATAPI_DRIVE       0
+#define MAX_SIZE               ((1<<16))
+
+/* forwards */
+struct vatapi_softc;
+
+static int     vatapi_match(device_t, cfdata_t, void *);
+static void    vatapi_attach(device_t, device_t, void *);
+static void    vatapi_callback(device_t self);
+
+static void    vatapi_minphys(struct buf *bp);
+static void    vatapi_kill_pending(struct scsipi_periph *periph);
+static void    vatapi_scsipi_request(struct scsipi_channel *chan,
+       scsipi_adapter_req_t req, void *arg);
+static void    vatapi_probe_device(struct atapibus_softc *, int);
+
+static void    vatapi_complete(void *arg);
+
+/* for debugging */
+void   scsipi_print_sense_data_real(struct scsi_sense_data *sense, int verbosity);
+
+
+/* Note its one vdev, one adapter, one channel for now */
+struct vatapi_softc {
+       device_t        sc_dev;
+       device_t        sc_pdev;
+
+       int             sc_flags;
+#define VATAPI_FLAG_POLLING    1
+#define VATAPI_FLAG_INTR       2
+       /* backing `device' with its active command */
+       int             sc_fd;
+       void            *sc_ih;
+       struct scsipi_xfer *sc_xs;
+
+       /* atapibus */
+       device_t        sc_vatapibus;
+       struct atapi_adapter    sc_atapi_adapter;
+#define sc_adapter sc_atapi_adapter._generic
+       struct scsipi_channel sc_channel;
+};
+
+CFATTACH_DECL_NEW(vatapi_thunkbus, sizeof(struct vatapi_softc),
+    vatapi_match, vatapi_attach, NULL, NULL);
+
+
+static const struct scsipi_bustype vatapi_bustype = {
+       SCSIPI_BUSTYPE_ATAPI,
+       atapi_scsipi_cmd,
+       atapi_interpret_sense,
+       atapi_print_addr,
+       vatapi_kill_pending,
+       NULL
+};
+
+int
+vatapi_match(device_t parent, cfdata_t match, void *opaque)
+{
+       struct thunkbus_attach_args *taa = opaque;
+
+       if (taa->taa_type != THUNKBUS_TYPE_VATAPI)
+               return 0;
+
+       return 1;
+}
+
+static void
+vatapi_attach(device_t parent, device_t self, void *opaque)
+{
+       struct vatapi_softc *sc = device_private(self);
+       struct thunkbus_attach_args *taa = opaque;
+
+       sc->sc_dev = self;
+       sc->sc_pdev = parent;
+
+       /* open device */
+       sc->sc_fd = thunk_open(taa->u.vdev.path, O_RDWR, 0);
+       if (sc->sc_fd < 0) {
+               aprint_error(": error %d opening path\n", thunk_geterrno());
+               return;
+       }
+
+       aprint_naive("\n");
+       aprint_normal("\n");
+
+       sc->sc_ih = softint_establish(SOFTINT_BIO,
+               vatapi_complete, sc);
+
+       /* rest of the configuration is deferred */
+       config_interrupts(self, vatapi_callback);
+}
+
+static void
+vatapi_callback(device_t self)
+{
+       struct vatapi_softc *sc = device_private(self);
+       struct scsipi_adapter *adapt = &sc->sc_adapter;
+       struct scsipi_channel *chan  = &sc->sc_channel;
+
+       /* set up the scsipi adapter and channel */
+       memset(adapt, 0, sizeof(*adapt));
+       adapt->adapt_dev = sc->sc_dev;
+       adapt->adapt_nchannels = 1;
+       adapt->adapt_request   = vatapi_scsipi_request;
+       adapt->adapt_minphys   = vatapi_minphys;
+       adapt->adapt_flags     = 0; //SCSIPI_ADAPT_POLL_ONLY;
+       sc->sc_atapi_adapter.atapi_probe_device = vatapi_probe_device;
+
+       memset(chan,  0, sizeof(*chan));
+       chan->chan_adapter    = adapt;
+       chan->chan_bustype    = &vatapi_bustype;
+       chan->chan_channel    = 0;      /* location */
+       chan->chan_flags      = SCSIPI_CHAN_OPENINGS;
+       chan->chan_openings   = 1;
+       chan->chan_max_periph = 1;
+       chan->chan_ntargets   = 1;
+       chan->chan_nluns      = 1;
+
+       /* set polling */
+       //sc->sc_flags = VATAPI_FLAG_POLLING;
+
+       /* we `discovered' an atapi adapter */
+       sc->sc_vatapibus = config_found_ia(sc->sc_dev, "atapi", chan,
+               atapiprint);
+}
+
+
+/* XXX why is it be called minphys, when it enforces maxphys? */
+static void
+vatapi_minphys(struct buf *bp)
+{
+       if (bp->b_bcount > MAX_SIZE)
+               bp->b_bcount = MAX_SIZE;
+       minphys(bp);
+}
+
+/*



Home | Main Index | Thread Index | Old Index