Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Reorg the virtio(4) config(9) code to be explici...



details:   https://anonhg.NetBSD.org/src/rev/03ddafa04c1f
branches:  trunk
changeset: 825854:03ddafa04c1f
user:      cherry <cherry%NetBSD.org@localhost>
date:      Wed Aug 02 08:39:14 2017 +0000

description:
Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin

diffstat:

 sys/dev/pci/files.pci    |   28 +-----
 sys/dev/pci/files.virtio |   25 +++++
 sys/dev/pci/virtio.c     |  165 +-------------------------------------
 sys/dev/pci/virtio_pci.c |  201 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/virtiovar.h  |    7 +-
 5 files changed, 242 insertions(+), 184 deletions(-)

diffs (truncated from 514 to 300 lines):

diff -r 559320c2e39c -r 03ddafa04c1f sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Wed Aug 02 07:35:47 2017 +0000
+++ b/sys/dev/pci/files.pci     Wed Aug 02 08:39:14 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.388 2017/04/13 10:37:36 knakahara Exp $
+#      $NetBSD: files.pci,v 1.389 2017/08/02 08:39:14 cherry Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -1137,29 +1137,11 @@
 attach  sisfb at pci
 file    dev/pci/sisfb.c                sisfb   needs-flag
 
-# VirtIO
-device virtio {}
-attach virtio at pci
-file   dev/pci/virtio.c        virtio
-
-attach ld at virtio with ld_virtio
-file   dev/pci/ld_virtio.c     ld_virtio
-
-device viomb
-attach viomb at virtio
-file   dev/pci/viomb.c         viomb
+# VirtIO: XXX: move to dev/vmm/virtio
+include "dev/pci/files.virtio"
 
-device vioif: ether, ifnet, arp
-attach vioif at virtio
-file   dev/pci/if_vioif.c      vioif
-
-device viornd
-attach viornd at virtio
-file   dev/pci/viornd.c        viornd
-
-device vioscsi: scsi
-attach vioscsi at virtio
-file   dev/pci/vioscsi.c       vioscsi
+attach virtio at pci with virtio_pci
+file   dev/pci/virtio_pci.c    virtio_pci
 
 # Silicon Motion SM712(LynxEM+) frame buffer
 device lynxfb: wsemuldisplaydev, rasops16
diff -r 559320c2e39c -r 03ddafa04c1f sys/dev/pci/files.virtio
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/files.virtio  Wed Aug 02 08:39:14 2017 +0000
@@ -0,0 +1,25 @@
+#      $NetBSD: files.virtio,v 1.1 2017/08/02 08:39:14 cherry Exp $
+
+# VirtIO
+device virtio {}
+file   dev/pci/virtio.c        virtio
+
+attach ld at virtio with ld_virtio
+file   dev/pci/ld_virtio.c     ld_virtio
+
+device viomb
+attach viomb at virtio
+file   dev/pci/viomb.c         viomb
+
+device vioif: ether, ifnet, arp
+attach vioif at virtio
+file   dev/pci/if_vioif.c      vioif
+
+device viornd
+attach viornd at virtio
+file   dev/pci/viornd.c        viornd
+
+device vioscsi: scsi
+attach vioscsi at virtio
+file   dev/pci/vioscsi.c       vioscsi
+
diff -r 559320c2e39c -r 03ddafa04c1f sys/dev/pci/virtio.c
--- a/sys/dev/pci/virtio.c      Wed Aug 02 07:35:47 2017 +0000
+++ b/sys/dev/pci/virtio.c      Wed Aug 02 08:39:14 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: virtio.c,v 1.28 2017/06/01 02:45:11 chs Exp $  */
+/*     $NetBSD: virtio.c,v 1.29 2017/08/02 08:39:14 cherry Exp $       */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.28 2017/06/01 02:45:11 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.29 2017/08/02 08:39:14 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -43,15 +43,11 @@
 
 #define VIRTIO_PRIVATE
 
-#include <dev/pci/virtioreg.h>
-#include <dev/pci/virtiovar.h>
+#include <dev/pci/virtioreg.h> /* XXX: move to non-pci */
+#include <dev/pci/virtiovar.h> /* XXX: move to non-pci */
 
 #define MINSEG_INDIRECT                2 /* use indirect if nsegs >= this value */
 
-static int     virtio_match(device_t, cfdata_t, void *);
-static void    virtio_attach(device_t, device_t, void *);
-static int     virtio_rescan(device_t, const char *, const int *);
-static int     virtio_detach(device_t, int);
 static int     virtio_intr(void *arg);
 static int     virtio_msix_queue_intr(void *);
 static int     virtio_msix_config_intr(void *);
@@ -66,9 +62,6 @@
 static void    virtio_init_vq(struct virtio_softc *,
                    struct virtqueue *, const bool);
 
-CFATTACH_DECL3_NEW(virtio, sizeof(struct virtio_softc),
-    virtio_match, virtio_attach, virtio_detach, NULL, virtio_rescan, NULL,
-    DVF_DETACH_SHUTDOWN);
 
 /* we use the legacy virtio spec, so the pci registers are host native
  * byte order, not pci (i.e. LE) byte order */
@@ -109,7 +102,7 @@
 #define        REG_LO_OFF      0
 #endif
 
-static void
+void
 virtio_set_status(struct virtio_softc *sc, int status)
 {
        int old = 0;
@@ -121,42 +114,6 @@
                          status|old);
 }
 
-#define virtio_device_reset(sc)        virtio_set_status((sc), 0)
-
-static int
-virtio_match(device_t parent, cfdata_t match, void *aux)
-{
-       struct pci_attach_args *pa;
-
-       pa = (struct pci_attach_args *)aux;
-       switch (PCI_VENDOR(pa->pa_id)) {
-       case PCI_VENDOR_QUMRANET:
-               if ((PCI_PRODUCT_QUMRANET_VIRTIO_1000 <=
-                    PCI_PRODUCT(pa->pa_id)) &&
-                   (PCI_PRODUCT(pa->pa_id) <=
-                    PCI_PRODUCT_QUMRANET_VIRTIO_103F))
-                       return 1;
-               break;
-       }
-
-       return 0;
-}
-
-static const char *virtio_device_name[] = {
-       "Unknown (0)",                  /* 0 */
-       "Network",                      /* 1 */
-       "Block",                        /* 2 */
-       "Console",                      /* 3 */
-       "Entropy",                      /* 4 */
-       "Memory Balloon",               /* 5 */
-       "I/O Memory",                   /* 6 */
-       "Remote Processor Messaging",   /* 7 */
-       "SCSI",                         /* 8 */
-       "9P Transport",                 /* 9 */
-       "mac80211 wlan",                /* 10 */
-};
-#define NDEVNAMES      __arraycount(virtio_device_name)
-
 #define VIRTIO_MSIX_CONFIG_VECTOR_INDEX        0
 #define VIRTIO_MSIX_QUEUE_VECTOR_INDEX 1
 
@@ -383,119 +340,7 @@
        sc->sc_ihs_num = 0;
 }
 
-static void
-virtio_attach(device_t parent, device_t self, void *aux)
-{
-       struct virtio_softc *sc = device_private(self);
-       struct pci_attach_args *pa = (struct pci_attach_args *)aux;
-       pci_chipset_tag_t pc = pa->pa_pc;
-       pcitag_t tag = pa->pa_tag;
-       int revision;
-       pcireg_t id;
 
-       revision = PCI_REVISION(pa->pa_class);
-       if (revision != 0) {
-               aprint_normal(": unknown revision 0x%02x; giving up\n",
-                             revision);
-               return;
-       }
-       aprint_normal("\n");
-       aprint_naive("\n");
-
-       /* subsystem ID shows what I am */
-       id = pci_conf_read(pc, tag, PCI_SUBSYS_ID_REG);
-       aprint_normal_dev(self, "Virtio %s Device (rev. 0x%02x)\n",
-                         (PCI_SUBSYS_ID(id) < NDEVNAMES?
-                          virtio_device_name[PCI_SUBSYS_ID(id)] : "Unknown"),
-                         revision);
-
-       sc->sc_dev = self;
-       sc->sc_pc = pc;
-       sc->sc_tag = tag;
-       sc->sc_iot = pa->pa_iot;
-       if (pci_dma64_available(pa))
-               sc->sc_dmat = pa->pa_dmat64;
-       else
-               sc->sc_dmat = pa->pa_dmat;
-       sc->sc_config_offset = VIRTIO_CONFIG_DEVICE_CONFIG_NOMSI;
-
-       if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
-                          &sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_iosize)) {
-               aprint_error_dev(self, "can't map i/o space\n");
-               return;
-       }
-
-       virtio_device_reset(sc);
-       virtio_set_status(sc, VIRTIO_CONFIG_DEVICE_STATUS_ACK);
-       virtio_set_status(sc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER);
-
-       sc->sc_childdevid = PCI_SUBSYS_ID(id);
-       sc->sc_child = NULL;
-       sc->sc_pa = *pa;
-       virtio_rescan(self, "virtio", 0);
-       return;
-}
-
-/* ARGSUSED */
-static int
-virtio_rescan(device_t self, const char *attr, const int *scan_flags)
-{
-       struct virtio_softc *sc;
-       struct virtio_attach_args va;
-
-       sc = device_private(self);
-       if (sc->sc_child)       /* Child already attached? */
-               return 0;
-
-       memset(&va, 0, sizeof(va));
-       va.sc_childdevid = sc->sc_childdevid;
-
-       config_found_ia(self, attr, &va, NULL);
-
-       if (sc->sc_child == NULL) {
-               aprint_error_dev(self,
-                                "no matching child driver; not configured\n");
-               return 0;
-       }
-       
-       if (sc->sc_child == VIRTIO_CHILD_FAILED) {
-               aprint_error_dev(self,
-                                "virtio configuration failed\n");
-               return 0;
-       }
-
-       /*
-        * Make sure child drivers initialize interrupts via call
-        * to virtio_child_attach_finish().
-        */
-       KASSERT(sc->sc_ihs_num != 0);
-
-       return 0;
-}
-
-static int
-virtio_detach(device_t self, int flags)
-{
-       struct virtio_softc *sc = device_private(self);
-       int r;
-
-       if (sc->sc_child != NULL) {
-               r = config_detach(sc->sc_child, flags);
-               if (r)
-                       return r;
-       }
-
-       /* Check that child detached properly */
-       KASSERT(sc->sc_child == NULL);
-       KASSERT(sc->sc_vqs == NULL);
-       KASSERT(sc->sc_ihs_num == 0);
-
-       if (sc->sc_iosize)
-               bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
-       sc->sc_iosize = 0;
-
-       return 0;
-}
 
 /*
  * Reset the device.
diff -r 559320c2e39c -r 03ddafa04c1f sys/dev/pci/virtio_pci.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/virtio_pci.c  Wed Aug 02 08:39:14 2017 +0000
@@ -0,0 +1,201 @@
+/* $NetBSD: virtio_pci.c,v 1.1 2017/08/02 08:39:14 cherry Exp $ */
+
+/*
+ * Copyright (c) 2010 Minoura Makoto.
+ * All rights reserved.
+ *



Home | Main Index | Thread Index | Old Index