Module Name: src
Committed By: jdolecek
Date: Fri Sep 16 11:35:07 UTC 2016
Modified Files:
src/sys/dev/pci: nvme_pci.c
src/sys/modules: Makefile
Added Files:
src/sys/modules/nvme: Makefile nvme.ioconf
Log Message:
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'
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/pci/nvme_pci.c
cvs rdiff -u -r1.176 -r1.177 src/sys/modules/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/modules/nvme/Makefile \
src/sys/modules/nvme/nvme.ioconf
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/pci/nvme_pci.c
diff -u src/sys/dev/pci/nvme_pci.c:1.5 src/sys/dev/pci/nvme_pci.c:1.6
--- src/sys/dev/pci/nvme_pci.c:1.5 Fri Sep 16 10:59:28 2016
+++ src/sys/dev/pci/nvme_pci.c Fri Sep 16 11:35:07 2016
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v
#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 @@ retry:
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;
+ }
+}
Index: src/sys/modules/Makefile
diff -u src/sys/modules/Makefile:1.176 src/sys/modules/Makefile:1.177
--- src/sys/modules/Makefile:1.176 Sat Sep 10 02:20:10 2016
+++ src/sys/modules/Makefile Fri Sep 16 11:35:07 2016
@@ -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 @@ SUBDIR+= vmt
.if ${MACHINE_ARCH} == "i386" || \
${MACHINE_ARCH} == "x86_64"
SUBDIR+= ubsec # Builds on architectures with PCI bus
+SUBDIR+= nvme
.endif
.if ${MKSLJIT} != "no"
Added files:
Index: src/sys/modules/nvme/Makefile
diff -u /dev/null src/sys/modules/nvme/Makefile:1.1
--- /dev/null Fri Sep 16 11:35:07 2016
+++ src/sys/modules/nvme/Makefile Fri Sep 16 11:35:07 2016
@@ -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>
Index: src/sys/modules/nvme/nvme.ioconf
diff -u /dev/null src/sys/modules/nvme/nvme.ioconf:1.1
--- /dev/null Fri Sep 16 11:35:07 2016
+++ src/sys/modules/nvme/nvme.ioconf Fri Sep 16 11:35:07 2016
@@ -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 ?