Skip to contentSkip to conversation

Add module autoloading support for vop and cosm driver

PATCH In review Sherry Sun 2 participants 6 messages Sep 29, 2020 – Oct 13, 2020

Subsystems (2)
lore
Share & tools
lore

Sherry Sun

author
#0 lore raw

v2 cover Add module autoloading support for vop and cosm driver

Changes in V2:
1. Combine patch1 and patch2 in V1 together, as patch1 is a part of autoloading support for vop driver in patch2.

Add module autoloading support for vop and cosm driver, when the vop/cosm device appears, the driver will be autoloaded.

Sherry Sun (2):
mic: vop: module autoprobing support for vop drivers
mic: cosm: module autoprobing support for cosm driver

 drivers/misc/mic/bus/cosm_bus.c   |  8 ++++++++
 drivers/misc/mic/bus/vop_bus.h    |  7 +------
 drivers/misc/mic/cosm/cosm_main.c |  7 +++++++
 drivers/misc/mic/vop/vop_main.c   |  2 +-
 include/linux/mod_devicetable.h   | 15 +++++++++++++++
 scripts/mod/devicetable-offsets.c |  7 +++++++
 scripts/mod/file2alias.c          | 27 +++++++++++++++++++++++++++
 7 files changed, 66 insertions(+), 7 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/2 mic: vop: module autoprobing support for vop drivers

Add vop autoprobing support to MODULE_DEVICE_TABLE() by adding info about struct vop_device_id in devicetable-offsets.c and add a vop entry point in file2alias.c.

The type argument for MODULE_DEVICE_TABLE(type, name) is vop.

---
 drivers/misc/mic/bus/vop_bus.h    |  7 +------
 drivers/misc/mic/vop/vop_main.c   |  2 +-
 include/linux/mod_devicetable.h   |  7 +++++++
 scripts/mod/devicetable-offsets.c |  4 ++++
 scripts/mod/file2alias.c          | 16 ++++++++++++++++
 5 files changed, 29 insertions(+), 7 deletions(-)
drivers/misc/mic/bus/vop_bus.h +1 -6
index d891eacae358..5b4a58757951 100644
@@ -14,16 +14,11 @@
  */
 #include <linux/dmaengine.h>
 #include <linux/interrupt.h>
+#include <linux/mod_devicetable.h>
 
 #include "../common/mic_dev.h"
 
-struct vop_device_id {
-	u32 device;
-	u32 vendor;
-};
-
 #define VOP_DEV_TRNSP 1
-#define VOP_DEV_ANY_ID 0xffffffff
 /*
  * Size of the internal buffer used during DMA's as an intermediate buffer
  * for copy to/from user. Must be an integral number of pages.
drivers/misc/mic/vop/vop_main.c +1 -1
index 1ccc94dfd6ac..f1e908286843 100644
@@ -742,7 +742,7 @@ static struct vop_driver vop_driver = {
 
 module_vop_driver(vop_driver);
 
-MODULE_DEVICE_TABLE(mbus, id_table);
+MODULE_DEVICE_TABLE(vop, id_table);
 MODULE_AUTHOR("Intel Corporation");
 MODULE_DESCRIPTION("Intel(R) Virtio Over PCIe (VOP) driver");
 MODULE_LICENSE("GPL v2");
include/linux/mod_devicetable.h +7 -0
index 5b08a473cdba..736cdc236cf9 100644
@@ -838,4 +838,11 @@ struct mhi_device_id {
 	kernel_ulong_t driver_data;
 };
 
+/* vop */
+struct vop_device_id {
+	__u32 device;
+	__u32 vendor;
+};
+#define VOP_DEV_ANY_ID	0xffffffff
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
scripts/mod/devicetable-offsets.c +4 -0
index 27007c18e754..393acaa5302a 100644
@@ -243,5 +243,9 @@ int main(void)
 	DEVID(mhi_device_id);
 	DEVID_FIELD(mhi_device_id, chan);
 
+	DEVID(vop_device_id);
+	DEVID_FIELD(vop_device_id, device);
+	DEVID_FIELD(vop_device_id, vendor);
+
 	return 0;
 }
scripts/mod/file2alias.c +16 -0
index 2417dd1dee33..8063b778eedf 100644
@@ -1368,6 +1368,21 @@ static int do_mhi_entry(const char *filename, void *symval, char *alias)
 	return 1;
 }
 
+/* Looks like: vop:dNvN */
+static int do_vop_entry(const char *filename, void *symval,
+			   char *alias)
+{
+	DEF_FIELD(symval, vop_device_id, device);
+	DEF_FIELD(symval, vop_device_id, vendor);
+
+	strcpy(alias, "vop:");
+	ADD(alias, "d", device != VOP_DEV_ANY_ID, device);
+	ADD(alias, "v", vendor != VOP_DEV_ANY_ID, vendor);
+
+	add_wildcard(alias);
+	return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1442,6 +1457,7 @@ static const struct devtable devtable[] = {
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
 	{"mhi", SIZE_mhi_device_id, do_mhi_entry},
+	{"vop", SIZE_vop_device_id, do_vop_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/2 mic: cosm: module autoprobing support for cosm driver

In reply to Sherry Sun

Add uevent callback for cosm_bus and add cosm_device_id for cosm driver which is needed for MODULE_DEVICE_TABLE. Also adding struct cosm_device_id in devicetable-offsets.c and the cosm entry point in file2alias.c.

Cosm driver will be autoloaded when cosm device appears.

---
 drivers/misc/mic/bus/cosm_bus.c   |  8 ++++++++
 drivers/misc/mic/cosm/cosm_main.c |  7 +++++++
 include/linux/mod_devicetable.h   |  8 ++++++++
 scripts/mod/devicetable-offsets.c |  3 +++
 scripts/mod/file2alias.c          | 11 +++++++++++
 5 files changed, 37 insertions(+)
drivers/misc/mic/bus/cosm_bus.c +8 -0
index 5f2141c71738..736e27bbc9f9 100644
@@ -14,6 +14,13 @@
 /* Unique numbering for cosm devices. */
 static DEFINE_IDA(cosm_index_ida);
 
+static int cosm_uevent(struct device *d, struct kobj_uevent_env *env)
+{
+	struct cosm_device *dev = dev_to_cosm(d);
+
+	return add_uevent_var(env, "MODALIAS=cosm:cosm-dev%u", dev->index);
+}
+
 static int cosm_dev_probe(struct device *d)
 {
 	struct cosm_device *dev = dev_to_cosm(d);
@@ -33,6 +40,7 @@ static int cosm_dev_remove(struct device *d)
 
 static struct bus_type cosm_bus = {
 	.name  = "cosm_bus",
+	.uevent = cosm_uevent,
 	.probe = cosm_dev_probe,
 	.remove = cosm_dev_remove,
 };
drivers/misc/mic/cosm/cosm_main.c +7 -0
index ebb0eac43754..627e7d5f3a83 100644
@@ -12,6 +12,7 @@
 #include <linux/idr.h>
 #include <linux/slab.h>
 #include <linux/cred.h>
+#include <linux/mod_devicetable.h>
 #include "cosm_main.h"
 
 static const char cosm_driver_name[] = "mic";
@@ -323,6 +324,12 @@ static int cosm_suspend(struct device *dev)
 	return 0;
 }
 
+static struct cosm_device_id __maybe_unused cosm_driver_id_table[] = {
+	{ .name	= "cosm-dev*" },
+	{ },
+};
+MODULE_DEVICE_TABLE(cosm, cosm_driver_id_table);
+
 static const struct dev_pm_ops cosm_pm_ops = {
 	.suspend = cosm_suspend,
 	.freeze = cosm_suspend
include/linux/mod_devicetable.h +8 -0
index 736cdc236cf9..ea6cdfe1a3a3 100644
@@ -845,4 +845,12 @@ struct vop_device_id {
 };
 #define VOP_DEV_ANY_ID	0xffffffff
 
+/* cosm */
+#define COSM_NAME_SIZE			32
+#define COSM_MODULE_PREFIX	"cosm:"
+
+struct cosm_device_id {
+	char name[COSM_NAME_SIZE];
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
scripts/mod/devicetable-offsets.c +3 -0
index 393acaa5302a..499a2832878d 100644
@@ -247,5 +247,8 @@ int main(void)
 	DEVID_FIELD(vop_device_id, device);
 	DEVID_FIELD(vop_device_id, vendor);
 
+	DEVID(cosm_device_id);
+	DEVID_FIELD(cosm_device_id, name);
+
 	return 0;
 }
scripts/mod/file2alias.c +11 -0
index 8063b778eedf..f7c80e4da137 100644
@@ -1383,6 +1383,16 @@ static int do_vop_entry(const char *filename, void *symval,
 	return 1;
 }
 
+/* Looks like: cosm:S */
+static int do_cosm_entry(const char *filename, void *symval,
+			  char *alias)
+{
+	DEF_FIELD_ADDR(symval, cosm_device_id, name);
+	sprintf(alias, COSM_MODULE_PREFIX "%s", *name);
+
+	return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1458,6 +1468,7 @@ static const struct devtable devtable[] = {
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
 	{"mhi", SIZE_mhi_device_id, do_mhi_entry},
 	{"vop", SIZE_vop_device_id, do_vop_entry},
+	{"cosm", SIZE_cosm_device_id, do_cosm_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.17.1
author
#3 lore raw
In reply to Sherry Sun

Gentle ping....

Quoted 25 lines

Subject: [PATCH V2 0/2] Add module autoloading support for vop and cosm driver

Changes in V2:
1. Combine patch1 and patch2 in V1 together, as patch1 is a part of autoloading support for vop driver in patch2.

Add module autoloading support for vop and cosm driver, when the vop/cosm device appears, the driver will be autoloaded.

Sherry Sun (2):
mic: vop: module autoprobing support for vop drivers
mic: cosm: module autoprobing support for cosm driver

 drivers/misc/mic/bus/cosm_bus.c   |  8 ++++++++
 drivers/misc/mic/bus/vop_bus.h    |  7 +------
 drivers/misc/mic/cosm/cosm_main.c |  7 +++++++
 drivers/misc/mic/vop/vop_main.c   |  2 +-
 include/linux/mod_devicetable.h   | 15 +++++++++++++++
 scripts/mod/devicetable-offsets.c |  7 +++++++
 scripts/mod/file2alias.c          | 27 +++++++++++++++++++++++++++
 7 files changed, 66 insertions(+), 7 deletions(-)

--
2.17.1

#4 lore raw
Quoted 1 line · Sherry Sun

Gentle ping....

It's the merge window, sorry, this fell through the cracks before that happened.

Please resubmit once 5.10-rc1 comes out.

thanks,

greg k-h

author
#5 lore raw

Hi Greg,

Quoted 10 lines

Subject: Re: [PATCH V2 0/2] Add module autoloading support for vop and cosm driver

Quoted 1 line · Sherry Sun

Gentle ping....

It's the merge window, sorry, this fell through the cracks before that happened.

Please resubmit once 5.10-rc1 comes out.

Thanks for the information, will resubmit the patches after 5.10-rc1.

Best regards
Sherry

Quoted 4 lines

thanks,

greg k-h