[Lkw] [PATCH] nvme-cmb: create an initial nvme pcie module

felipx felipemonterobruni at unc.edu.ar
Fri Sep 15 14:03:58 EDT 2023


This is the absolute minimal viable nvme pci Linux kernel module.

Signed-off-by: Felipe Montero Bruni <felipemonterobruni at unc.edu.ar>
---
 drivers/block/Makefile   |  2 ++
 drivers/block/nvme-cmb.c | 43 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 drivers/block/nvme-cmb.c

diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 101612cba..3ad5dcb18 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -40,3 +40,5 @@ obj-$(CONFIG_BLK_DEV_NULL_BLK)	+= null_blk/
 obj-$(CONFIG_BLK_DEV_UBLK)			+= ublk_drv.o
 
 swim_mod-y	:= swim.o swim_asm.o
+
+obj-m += nvme-cmb.o
diff --git a/drivers/block/nvme-cmb.c b/drivers/block/nvme-cmb.c
new file mode 100644
index 000000000..61302f473
--- /dev/null
+++ b/drivers/block/nvme-cmb.c
@@ -0,0 +1,43 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+
+MODULE_LICENSE("GPL");
+
+static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id){
+    dev_info(&pdev->dev, "found NVMe device\n");
+    return 0;
+}
+
+static void nvme_cmb_remove(struct pci_dev *pdev)
+{
+    dev_info(&pdev->dev, "unbinding NVMe device\n");
+}
+
+static const struct pci_device_id nvme_cmb_id_table[] = {
+    { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },
+    { 0, }
+};
+
+static struct pci_driver nvme_cmb_driver = {
+    .name = "nvme_cmb",
+    .id_table = nvme_cmb_id_table,
+    .probe = nvme_cmb_probe,
+    .remove = nvme_cmb_remove,
+};
+
+static int __init nvme_cmb_init(void)
+{
+    pr_info("loading nvme-cmb module\n");
+    return pci_register_driver(&nvme_cmb_driver);
+}
+ 
+static void __exit nvme_cmb_exit(void)
+{
+    pr_info("unloading nvme-cmb module\n");
+    pci_unregister_driver(&nvme_cmb_driver);
+}
+
+module_init(nvme_cmb_init);
+module_exit(nvme_cmb_exit);
-- 
2.39.2




More information about the LKW mailing list