linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: declaring DT match tables (2nd take)
@ 2019-06-01 13:52 Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 1/4] mod_devicetable: helper macro for declaring oftree module device table Enrico Weigelt, metux IT consult
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-01 13:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: vireshk, b.zolnierkie, axboe, herbert, davem, linux-ide,
	linux-block, linux-crypto

Hi folks,


few days ago I've posted a RFC for getting rid of many #ifdef CONFIG_OF
cases by using a macro that checks for it on its own.
(see: "RFC: get rid of #ifdef CONFIG_OF's around of match tables")

I've already mentioned I'm working on another approach that not just
cares about adding the table to the module, but the also the declaration
of the table itself. Here it is:

Introducing a macro MODULE_DECLARE_OF_TABLE(foo, entries), which declares
a static struct of_device_id array, fills in the entries (automatically
adds the sentinel) and calls MODULE_DEVICE_TABLE() - if CONFIG_OF is
enabled.

The current version isn't fully noop in absence of CONFIG_OF, but also
declares a static const *pointer* variable, initialized NULL, with the
same name. The idea behind: we don't need to use of_match_ptr() anymore.

I believe, the compiler should be clever enough to find out that this
field is always NULL and can't ever change, so it can be easily optimized
away. (correct me if I'm wrong).


Please have a look at the following example patches and let me know,
whether we can go that way. If you're okay w/ that, I'll continue
w/ converting the whole tree to using this approach. I've already did
most of it, yet needs to be sorted out into easily digestable patches :)
And I'd also do the same w/ the other table types (ACPI, PCI, I2C, ...)

By the way: an interesting question arises: shall that conversion be
done *everywhere*, or just those sites where explicit CONFIG_OF's are
involved ?


have fun,

--mtx

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] mod_devicetable: helper macro for declaring oftree module device table
  2019-06-01 13:52 RFC: declaring DT match tables (2nd take) Enrico Weigelt, metux IT consult
@ 2019-06-01 13:52 ` Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 2/4] drivers: block: xsysace: use MODULE_DECLARE_OF_TABLE() and of_match_ptr() Enrico Weigelt, metux IT consult
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-01 13:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: vireshk, b.zolnierkie, axboe, herbert, davem, linux-ide,
	linux-block, linux-crypto

Little helper macros that declares an oftree module device table,
if CONFIG_OF is enabled. Otherwise it's just noop. Helpful for
reducing the number of #ifdef's.

Instead of:
    MODULE_DEVICE_TABLE(of, foo);
now use:
    MODULE_OF_TABLE(foo);

Or declare the whole table via:
    MODULE_DECLARE_OF_TABLE(foo,
        { .compatible = "foo" },
        { .compatible = "bar" });

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 include/linux/mod_devicetable.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 448621c..5f4f2dc8 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -245,6 +245,19 @@ struct of_device_id {
 	const void *data;
 };
 
+/*
+ * macro for adding the of module device table only if CONFIG_OF enabled
+ */
+#ifdef CONFIG_OF
+#define MODULE_OF_TABLE(name)	MODULE_DEVICE_TABLE(of,name)
+#define MODULE_DECLARE_OF_TABLE(name,entries...) \
+static const struct of_device_id name[] = { entries, {} };
+#else
+#define MODULE_OF_TABLE(name)
+#define MODULE_DECLARE_OF_TABLE(name,entries...) \
+static const struct of_device_id *name = NULL;
+#endif /* CONFIG_OF */
+
 /* VIO */
 struct vio_device_id {
 	char type[32];
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] drivers: block: xsysace: use MODULE_DECLARE_OF_TABLE() and of_match_ptr()
  2019-06-01 13:52 RFC: declaring DT match tables (2nd take) Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 1/4] mod_devicetable: helper macro for declaring oftree module device table Enrico Weigelt, metux IT consult
@ 2019-06-01 13:52 ` Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 3/4] drivers: crypto: picoxcell_crypto: use MODULE_DECLARE_OF_TABLE() Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 4/4] drivers: ata: " Enrico Weigelt, metux IT consult
  3 siblings, 0 replies; 5+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-01 13:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: vireshk, b.zolnierkie, axboe, herbert, davem, linux-ide,
	linux-block, linux-crypto

Using MODULE_DECLARE_OF_TABLE() and of_match_ptr() macros to get
rid of some #ifdef CONFIG_OF and thus make the code a bit slimmer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/block/xsysace.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 464c9092..d8e5dd7 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -1219,26 +1219,18 @@ static int ace_remove(struct platform_device *dev)
 	return 0;
 }
 
-#if defined(CONFIG_OF)
-/* Match table for of_platform binding */
-static const struct of_device_id ace_of_match[] = {
+MODULE_DECLARE_OF_TABLE(ace_of_match,
 	{ .compatible = "xlnx,opb-sysace-1.00.b", },
 	{ .compatible = "xlnx,opb-sysace-1.00.c", },
 	{ .compatible = "xlnx,xps-sysace-1.00.a", },
-	{ .compatible = "xlnx,sysace", },
-	{},
-};
-MODULE_DEVICE_TABLE(of, ace_of_match);
-#else /* CONFIG_OF */
-#define ace_of_match NULL
-#endif /* CONFIG_OF */
+	{ .compatible = "xlnx,sysace", });
 
 static struct platform_driver ace_platform_driver = {
 	.probe = ace_probe,
 	.remove = ace_remove,
 	.driver = {
 		.name = "xsysace",
-		.of_match_table = ace_of_match,
+		.of_match_table = of_match_ptr(ace_of_match),
 	},
 };
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] drivers: crypto: picoxcell_crypto: use MODULE_DECLARE_OF_TABLE()
  2019-06-01 13:52 RFC: declaring DT match tables (2nd take) Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 1/4] mod_devicetable: helper macro for declaring oftree module device table Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 2/4] drivers: block: xsysace: use MODULE_DECLARE_OF_TABLE() and of_match_ptr() Enrico Weigelt, metux IT consult
@ 2019-06-01 13:52 ` Enrico Weigelt, metux IT consult
  2019-06-01 13:52 ` [PATCH 4/4] drivers: ata: " Enrico Weigelt, metux IT consult
  3 siblings, 0 replies; 5+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-01 13:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: vireshk, b.zolnierkie, axboe, herbert, davem, linux-ide,
	linux-block, linux-crypto

Using MODULE_DECLARE_OF_TABLE() macro to get rid of some #ifdef CONFIG_OF
and make the code a bit slimmer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/crypto/picoxcell_crypto.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c
index b985cb85..3c299f2 100644
--- a/drivers/crypto/picoxcell_crypto.c
+++ b/drivers/crypto/picoxcell_crypto.c
@@ -1612,14 +1612,9 @@ static DEVICE_ATTR(stat_irq_thresh, 0644, spacc_stat_irq_thresh_show,
 	},
 };
 
-#ifdef CONFIG_OF
-static const struct of_device_id spacc_of_id_table[] = {
+MODULE_DECLARE_OF_TABLE(spacc_of_id_table,
 	{ .compatible = "picochip,spacc-ipsec" },
-	{ .compatible = "picochip,spacc-l2" },
-	{}
-};
-MODULE_DEVICE_TABLE(of, spacc_of_id_table);
-#endif /* CONFIG_OF */
+	{ .compatible = "picochip,spacc-l2" });
 
 static int spacc_probe(struct platform_device *pdev)
 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] drivers: ata: use MODULE_DECLARE_OF_TABLE()
  2019-06-01 13:52 RFC: declaring DT match tables (2nd take) Enrico Weigelt, metux IT consult
                   ` (2 preceding siblings ...)
  2019-06-01 13:52 ` [PATCH 3/4] drivers: crypto: picoxcell_crypto: use MODULE_DECLARE_OF_TABLE() Enrico Weigelt, metux IT consult
@ 2019-06-01 13:52 ` Enrico Weigelt, metux IT consult
  3 siblings, 0 replies; 5+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-01 13:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: vireshk, b.zolnierkie, axboe, herbert, davem, linux-ide,
	linux-block, linux-crypto

Using MODULE_DECLARE_OF_TABLE() macro to get rid of some #ifdef CONFIG_OF
and make the code a bit slimmer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/ata/pata_arasan_cf.c | 9 ++-------
 drivers/ata/sata_mv.c        | 9 ++-------
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
index ebecab8..22de61f 100644
--- a/drivers/ata/pata_arasan_cf.c
+++ b/drivers/ata/pata_arasan_cf.c
@@ -943,13 +943,8 @@ static int arasan_cf_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(arasan_cf_pm_ops, arasan_cf_suspend, arasan_cf_resume);
 
-#ifdef CONFIG_OF
-static const struct of_device_id arasan_cf_id_table[] = {
-	{ .compatible = "arasan,cf-spear1340" },
-	{}
-};
-MODULE_DEVICE_TABLE(of, arasan_cf_id_table);
-#endif
+MODULE_DECLARE_OF_TABLE(arasan_cf_id_table,
+	{ .compatible = "arasan,cf-spear1340" });
 
 static struct platform_driver arasan_cf_driver = {
 	.probe		= arasan_cf_probe,
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index da585d2..bac48cd 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -4273,14 +4273,9 @@ static int mv_platform_resume(struct platform_device *pdev)
 #define mv_platform_resume NULL
 #endif
 
-#ifdef CONFIG_OF
-static const struct of_device_id mv_sata_dt_ids[] = {
+MODULE_DECLARE_OF_TABLE(mv_sata_dt_ids,
 	{ .compatible = "marvell,armada-370-sata", },
-	{ .compatible = "marvell,orion-sata", },
-	{},
-};
-MODULE_DEVICE_TABLE(of, mv_sata_dt_ids);
-#endif
+	{ .compatible = "marvell,orion-sata", });
 
 static struct platform_driver mv_platform_driver = {
 	.probe		= mv_platform_probe,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-01 13:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-01 13:52 RFC: declaring DT match tables (2nd take) Enrico Weigelt, metux IT consult
2019-06-01 13:52 ` [PATCH 1/4] mod_devicetable: helper macro for declaring oftree module device table Enrico Weigelt, metux IT consult
2019-06-01 13:52 ` [PATCH 2/4] drivers: block: xsysace: use MODULE_DECLARE_OF_TABLE() and of_match_ptr() Enrico Weigelt, metux IT consult
2019-06-01 13:52 ` [PATCH 3/4] drivers: crypto: picoxcell_crypto: use MODULE_DECLARE_OF_TABLE() Enrico Weigelt, metux IT consult
2019-06-01 13:52 ` [PATCH 4/4] drivers: ata: " Enrico Weigelt, metux IT consult

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).