[Lkw] [PATCH] nvme-cmb: create an initial stub module
Marco AR
marcoalrey at gmail.com
Fri Sep 15 13:46:12 EDT 2023
This is a minimal nvme+pci Linux kernel module
root at localhost:~/linux# insmod drivers/block/nvme-cmb.ko
[ 1055.897436] loading nvme-cmb module
[ 1055.898441] nvme_cmb 0000:00:04.0: found NVMe device
root at localhost:~/linux# rmmod nvme_cmb
[ 1065.654549] unloading nvme-cmb module
[ 1065.657671] nvme_cmb 0000:00:04.0: unbinding NVMe device
Signed-off-by: Marco AR <marcoalrey at gmail.com>
---
drivers/block/nvme-cmb.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/block/nvme-cmb.c b/drivers/block/nvme-cmb.c
index 644a9bd9a561..2f626a729f03 100644
--- a/drivers/block/nvme-cmb.c
+++ b/drivers/block/nvme-cmb.c
@@ -1,18 +1,43 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/pci.h>
MODULE_LICENSE("Dual BSD/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 0;
+ 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);
--
2.39.2
More information about the LKW
mailing list