Source-Changes-HG archive

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

[src/trunk]: src/sys make it possible to load nvme(4) as module to ease testi...



details:   https://anonhg.NetBSD.org/src/rev/9b4828234722
branches:  trunk
changeset: 347779:9b4828234722
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Fri Sep 16 11:35:07 2016 +0000

description:
make it possible to load nvme(4) as module to ease testing; currently somewhat
non-optimal, since it includes the ld(4) code also and hence requires the
kernel config to have 'no ld'

diffstat:

 sys/dev/pci/nvme_pci.c       |  61 ++++++++++++++++++++++++++++++++++++++++++-
 sys/modules/Makefile         |   3 +-
 sys/modules/nvme/Makefile    |  14 ++++++++++
 sys/modules/nvme/nvme.ioconf |  11 +++++++
 4 files changed, 86 insertions(+), 3 deletions(-)

diffs (136 lines):

diff -r 67e8d6a4c773 -r 9b4828234722 sys/dev/pci/nvme_pci.c
--- a/sys/dev/pci/nvme_pci.c    Fri Sep 16 11:13:47 2016 +0000
+++ b/sys/dev/pci/nvme_pci.c    Fri Sep 16 11:35:07 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvme_pci.c,v 1.5 2016/09/16 10:59:28 jdolecek Exp $    */
+/*     $NetBSD: nvme_pci.c,v 1.6 2016/09/16 11:35:07 jdolecek Exp $    */
 /*     $OpenBSD: nvme_pci.c,v 1.3 2016/04/14 11:18:32 dlg Exp $ */
 
 /*
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.5 2016/09/16 10:59:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.6 2016/09/16 11:35:07 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -55,6 +55,9 @@
 #include <sys/interrupt.h>
 #include <sys/kmem.h>
 #include <sys/pmf.h>
+#ifdef _MODULE
+#include <sys/module.h>
+#endif
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
@@ -415,3 +418,57 @@
        sc->sc_nq = sc->sc_use_mq ? alloced_counts[intr_type] - 1 : 1;
        return 0;
 }
+
+MODULE(MODULE_CLASS_DRIVER, nvme, "pci");
+
+#ifdef _MODULE
+#include "ioconf.c"
+
+extern const struct bdevsw ld_bdevsw;
+extern const struct cdevsw ld_cdevsw;
+#endif
+
+static int
+nvme_modcmd(modcmd_t cmd, void *opaque)
+{
+#ifdef _MODULE
+       devmajor_t cmajor, bmajor;
+#endif
+       int error = 0;
+
+       switch (cmd) {
+       case MODULE_CMD_INIT:
+#ifdef _MODULE
+               /* devsw must be done before configuring the pci device,
+                * otherwise ldattach() fails
+                */
+               bmajor = cmajor = NODEVMAJOR;
+               error = devsw_attach(ld_cd.cd_name, &ld_bdevsw, &bmajor,
+                   &ld_cdevsw, &cmajor);
+               if (error && error != EEXIST) {
+                       aprint_error("%s: unable to register devsw\n",
+                           ld_cd.cd_name);
+                       return error;
+               }
+
+               error = config_init_component(cfdriver_ioconf_nvme_pci,
+                   cfattach_ioconf_nvme_pci, cfdata_ioconf_nvme_pci);
+               if (error)
+                       return error;
+
+#endif
+               return error;
+       case MODULE_CMD_FINI:
+#ifdef _MODULE
+               error = config_fini_component(cfdriver_ioconf_nvme_pci,
+                   cfattach_ioconf_nvme_pci, cfdata_ioconf_nvme_pci);
+               if (error)
+                       return error;
+
+               /* devsw not detached, it's static data and fine to stay */
+#endif
+               return error;
+       default:
+               return ENOTTY;
+       }
+}
diff -r 67e8d6a4c773 -r 9b4828234722 sys/modules/Makefile
--- a/sys/modules/Makefile      Fri Sep 16 11:13:47 2016 +0000
+++ b/sys/modules/Makefile      Fri Sep 16 11:35:07 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.176 2016/09/10 02:20:10 pgoyette Exp $
+#      $NetBSD: Makefile,v 1.177 2016/09/16 11:35:07 jdolecek Exp $
 
 .include <bsd.own.mk>
 
@@ -183,6 +183,7 @@
 .if ${MACHINE_ARCH} == "i386" || \
     ${MACHINE_ARCH} == "x86_64"
 SUBDIR+=       ubsec           # Builds on architectures with PCI bus
+SUBDIR+=       nvme
 .endif
 
 .if ${MKSLJIT} != "no"
diff -r 67e8d6a4c773 -r 9b4828234722 sys/modules/nvme/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/nvme/Makefile Fri Sep 16 11:35:07 2016 +0000
@@ -0,0 +1,14 @@
+#      $NetBSD: Makefile,v 1.1 2016/09/16 11:35:07 jdolecek Exp $
+
+.include "../Makefile.inc"
+
+.PATH: ${S}/dev/pci ${S}/dev/ic ${S}/dev
+
+KMOD=  nvme
+IOCONF=        nvme.ioconf
+SRCS=  nvme.c nvme_pci.c
+
+# move to separate module?
+SRCS+= ld_nvme.c ld.c
+
+.include <bsd.kmodule.mk>
diff -r 67e8d6a4c773 -r 9b4828234722 sys/modules/nvme/nvme.ioconf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/nvme/nvme.ioconf      Fri Sep 16 11:35:07 2016 +0000
@@ -0,0 +1,11 @@
+#       $NetBSD: nvme.ioconf,v 1.1 2016/09/16 11:35:07 jdolecek Exp $
+
+ioconf nvme_pci
+
+include "conf/files"
+include "dev/pci/files.pci"
+
+pseudo-root pci*
+
+nvme* at pci? dev ? function ?
+ld* at nvme? nsid ?



Home | Main Index | Thread Index | Old Index