All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Saravana Kannan <saravanak@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Jason Cooper <jason@lakedaemon.net>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	CC Hwang <cc.hwang@mediatek.com>,
	Loda Chou <loda.chou@mediatek.com>,
	Hanks Chen <hanks.chen@mediatek.com>,
	kernel-team@android.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v2] irqchip: Add IRQCHIP_PLATFORM_DRIVER_BEGIN/END and IRQCHIP_MATCH helper macros
Date: Fri, 17 Jul 2020 11:49:41 +0100	[thread overview]
Message-ID: <87k0z2xvp6.wl-maz@kernel.org> (raw)
In-Reply-To: <20200717024447.3128361-1-saravanak@google.com>

Hi Saravana,

Thanks for re-spinning this one.

On Fri, 17 Jul 2020 03:44:47 +0100,
Saravana Kannan <saravanak@google.com> wrote:
> 
> Compiling an irqchip driver as a platform driver needs to bunch of
> things to be done right:
> - Making sure the parent domain is initialized first
> - Making sure the device can't be unbound from sysfs
> - Disallowing module unload if it's built as a module
> - Finding the parent node
> - Etc.
> 
> Instead of trying to make sure all future irqchip platform drivers get
> this right, provide boilerplate macros that take care of all of this.
> 
> An example use would look something like this. Where acme_foo_init and
> acme_bar_init are similar to what would be passed to IRQCHIP_DECLARE.
> 
> IRQCHIP_PLATFORM_DRIVER_BEGIN

I think there is some value in having the BEGIN statement containing
the driver name, see below.

> IRQCHIP_MATCH(foo, "acme,foo", acme_foo_init)
> IRQCHIP_MATCH(bar, "acme,bar", acme_bar_init)
> IRQCHIP_PLATFORM_DRIVER_END(acme_irq)
> 
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> ---
>  drivers/irqchip/irqchip.c | 22 ++++++++++++++++++++++
>  include/linux/irqchip.h   | 23 +++++++++++++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c
> index 2b35e68bea82..236ea793f01c 100644
> --- a/drivers/irqchip/irqchip.c
> +++ b/drivers/irqchip/irqchip.c
> @@ -10,8 +10,10 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/init.h>
> +#include <linux/of_device.h>
>  #include <linux/of_irq.h>
>  #include <linux/irqchip.h>
> +#include <linux/platform_device.h>
>  
>  /*
>   * This special of_device_id is the sentinel at the end of the
> @@ -29,3 +31,23 @@ void __init irqchip_init(void)
>  	of_irq_init(__irqchip_of_table);
>  	acpi_probe_device_table(irqchip);
>  }
> +
> +int platform_irqchip_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *par_np = of_irq_find_parent(np);
> +	of_irq_init_cb_t irq_init_cb = of_device_get_match_data(&pdev->dev);
> +
> +	if (!irq_init_cb)
> +		return -EINVAL;
> +
> +	if (par_np == np)
> +		par_np = NULL;
> +
> +	/* If there's a parent irqchip, make sure it has been initialized. */
> +	if (par_np && !irq_find_matching_host(np, DOMAIN_BUS_ANY))

There is no guarantee that the calling driver wants BUS_ANY as a token
for its parent. It may work for now, if you only have dependencies to
drivers that only expose a single domain, but that's not a general
purpose check..

At least, please add a comment saying that the new driver may want to
check that the irqdomain it depends on may not be available.

> +		return -EPROBE_DEFER;
> +
> +	return irq_init_cb(np, par_np);
> +}
> +EXPORT_SYMBOL_GPL(platform_irqchip_probe);
> diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h
> index 950e4b2458f0..6d5eba7cbbb7 100644
> --- a/include/linux/irqchip.h
> +++ b/include/linux/irqchip.h
> @@ -13,6 +13,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/of.h>
> +#include <linux/platform_device.h>
>  
>  /*
>   * This macro must be used by the different irqchip drivers to declare
> @@ -26,6 +27,28 @@
>   */
>  #define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn)
>  
> +extern int platform_irqchip_probe(struct platform_device *pdev);
> +
> +#define IRQCHIP_PLATFORM_DRIVER_BEGIN \
> +static const struct of_device_id __irqchip_match_table[] = {

How about:

#define IRQCHIP_PLATFORM_DRIVER_BEGIN(drv_name)	\
static const struct of_device_id __irqchip_match_table_##drv_name = {

which makes it easier to debug when you want to identify specific
structures in an object (otherwise, they all have the same
name...). it is also much more pleasing aesthetically ;-).

> +
> +#define IRQCHIP_MATCH(compat, fn) { .compatible = compat, .data = fn },
> +
> +#define IRQCHIP_PLATFORM_DRIVER_END(drv_name)		\
> +	{},						\
> +};							\
> +MODULE_DEVICE_TABLE(of, __irqchip_match_table);		\
> +static struct platform_driver drv_name##_driver = {	\

const?

> +	.probe  = platform_irqchip_probe,		\
> +	.driver = {					\
> +		.name = #drv_name,			\
> +		.owner = THIS_MODULE,			\
> +		.of_match_table = __irqchip_match_table,\
> +		.suppress_bind_attrs = true,		\
> +	},						\
> +};							\
> +builtin_platform_driver(drv_name##_driver)
> +
>  /*
>   * This macro must be used by the different irqchip drivers to declare
>   * the association between their version and their initialization function.
> -- 
> 2.28.0.rc0.105.gf9edc3c819-goog
> 
> 

Otherwise looks good. When you respin it, it would be good to also
submit one user of this API by converting an existing driver, as I'd
hate to merge something that has no user.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Saravana Kannan <saravanak@google.com>
Cc: CC Hwang <cc.hwang@mediatek.com>,
	Jason Cooper <jason@lakedaemon.net>,
	Hanks Chen <hanks.chen@mediatek.com>,
	Loda Chou <loda.chou@mediatek.com>,
	linux-kernel@vger.kernel.org,
	John Stultz <john.stultz@linaro.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-mediatek@lists.infradead.org,
	Thomas Gleixner <tglx@linutronix.de>,
	kernel-team@android.com, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2] irqchip: Add IRQCHIP_PLATFORM_DRIVER_BEGIN/END and IRQCHIP_MATCH helper macros
Date: Fri, 17 Jul 2020 11:49:41 +0100	[thread overview]
Message-ID: <87k0z2xvp6.wl-maz@kernel.org> (raw)
In-Reply-To: <20200717024447.3128361-1-saravanak@google.com>

Hi Saravana,

Thanks for re-spinning this one.

On Fri, 17 Jul 2020 03:44:47 +0100,
Saravana Kannan <saravanak@google.com> wrote:
> 
> Compiling an irqchip driver as a platform driver needs to bunch of
> things to be done right:
> - Making sure the parent domain is initialized first
> - Making sure the device can't be unbound from sysfs
> - Disallowing module unload if it's built as a module
> - Finding the parent node
> - Etc.
> 
> Instead of trying to make sure all future irqchip platform drivers get
> this right, provide boilerplate macros that take care of all of this.
> 
> An example use would look something like this. Where acme_foo_init and
> acme_bar_init are similar to what would be passed to IRQCHIP_DECLARE.
> 
> IRQCHIP_PLATFORM_DRIVER_BEGIN

I think there is some value in having the BEGIN statement containing
the driver name, see below.

> IRQCHIP_MATCH(foo, "acme,foo", acme_foo_init)
> IRQCHIP_MATCH(bar, "acme,bar", acme_bar_init)
> IRQCHIP_PLATFORM_DRIVER_END(acme_irq)
> 
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> ---
>  drivers/irqchip/irqchip.c | 22 ++++++++++++++++++++++
>  include/linux/irqchip.h   | 23 +++++++++++++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c
> index 2b35e68bea82..236ea793f01c 100644
> --- a/drivers/irqchip/irqchip.c
> +++ b/drivers/irqchip/irqchip.c
> @@ -10,8 +10,10 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/init.h>
> +#include <linux/of_device.h>
>  #include <linux/of_irq.h>
>  #include <linux/irqchip.h>
> +#include <linux/platform_device.h>
>  
>  /*
>   * This special of_device_id is the sentinel at the end of the
> @@ -29,3 +31,23 @@ void __init irqchip_init(void)
>  	of_irq_init(__irqchip_of_table);
>  	acpi_probe_device_table(irqchip);
>  }
> +
> +int platform_irqchip_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *par_np = of_irq_find_parent(np);
> +	of_irq_init_cb_t irq_init_cb = of_device_get_match_data(&pdev->dev);
> +
> +	if (!irq_init_cb)
> +		return -EINVAL;
> +
> +	if (par_np == np)
> +		par_np = NULL;
> +
> +	/* If there's a parent irqchip, make sure it has been initialized. */
> +	if (par_np && !irq_find_matching_host(np, DOMAIN_BUS_ANY))

There is no guarantee that the calling driver wants BUS_ANY as a token
for its parent. It may work for now, if you only have dependencies to
drivers that only expose a single domain, but that's not a general
purpose check..

At least, please add a comment saying that the new driver may want to
check that the irqdomain it depends on may not be available.

> +		return -EPROBE_DEFER;
> +
> +	return irq_init_cb(np, par_np);
> +}
> +EXPORT_SYMBOL_GPL(platform_irqchip_probe);
> diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h
> index 950e4b2458f0..6d5eba7cbbb7 100644
> --- a/include/linux/irqchip.h
> +++ b/include/linux/irqchip.h
> @@ -13,6 +13,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/of.h>
> +#include <linux/platform_device.h>
>  
>  /*
>   * This macro must be used by the different irqchip drivers to declare
> @@ -26,6 +27,28 @@
>   */
>  #define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn)
>  
> +extern int platform_irqchip_probe(struct platform_device *pdev);
> +
> +#define IRQCHIP_PLATFORM_DRIVER_BEGIN \
> +static const struct of_device_id __irqchip_match_table[] = {

How about:

#define IRQCHIP_PLATFORM_DRIVER_BEGIN(drv_name)	\
static const struct of_device_id __irqchip_match_table_##drv_name = {

which makes it easier to debug when you want to identify specific
structures in an object (otherwise, they all have the same
name...). it is also much more pleasing aesthetically ;-).

> +
> +#define IRQCHIP_MATCH(compat, fn) { .compatible = compat, .data = fn },
> +
> +#define IRQCHIP_PLATFORM_DRIVER_END(drv_name)		\
> +	{},						\
> +};							\
> +MODULE_DEVICE_TABLE(of, __irqchip_match_table);		\
> +static struct platform_driver drv_name##_driver = {	\

const?

> +	.probe  = platform_irqchip_probe,		\
> +	.driver = {					\
> +		.name = #drv_name,			\
> +		.owner = THIS_MODULE,			\
> +		.of_match_table = __irqchip_match_table,\
> +		.suppress_bind_attrs = true,		\
> +	},						\
> +};							\
> +builtin_platform_driver(drv_name##_driver)
> +
>  /*
>   * This macro must be used by the different irqchip drivers to declare
>   * the association between their version and their initialization function.
> -- 
> 2.28.0.rc0.105.gf9edc3c819-goog
> 
> 

Otherwise looks good. When you respin it, it would be good to also
submit one user of this API by converting an existing driver, as I'd
hate to merge something that has no user.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Saravana Kannan <saravanak@google.com>
Cc: CC Hwang <cc.hwang@mediatek.com>,
	Jason Cooper <jason@lakedaemon.net>,
	Hanks Chen <hanks.chen@mediatek.com>,
	Loda Chou <loda.chou@mediatek.com>,
	linux-kernel@vger.kernel.org,
	John Stultz <john.stultz@linaro.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-mediatek@lists.infradead.org,
	Thomas Gleixner <tglx@linutronix.de>,
	kernel-team@android.com, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2] irqchip: Add IRQCHIP_PLATFORM_DRIVER_BEGIN/END and IRQCHIP_MATCH helper macros
Date: Fri, 17 Jul 2020 11:49:41 +0100	[thread overview]
Message-ID: <87k0z2xvp6.wl-maz@kernel.org> (raw)
In-Reply-To: <20200717024447.3128361-1-saravanak@google.com>

Hi Saravana,

Thanks for re-spinning this one.

On Fri, 17 Jul 2020 03:44:47 +0100,
Saravana Kannan <saravanak@google.com> wrote:
> 
> Compiling an irqchip driver as a platform driver needs to bunch of
> things to be done right:
> - Making sure the parent domain is initialized first
> - Making sure the device can't be unbound from sysfs
> - Disallowing module unload if it's built as a module
> - Finding the parent node
> - Etc.
> 
> Instead of trying to make sure all future irqchip platform drivers get
> this right, provide boilerplate macros that take care of all of this.
> 
> An example use would look something like this. Where acme_foo_init and
> acme_bar_init are similar to what would be passed to IRQCHIP_DECLARE.
> 
> IRQCHIP_PLATFORM_DRIVER_BEGIN

I think there is some value in having the BEGIN statement containing
the driver name, see below.

> IRQCHIP_MATCH(foo, "acme,foo", acme_foo_init)
> IRQCHIP_MATCH(bar, "acme,bar", acme_bar_init)
> IRQCHIP_PLATFORM_DRIVER_END(acme_irq)
> 
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> ---
>  drivers/irqchip/irqchip.c | 22 ++++++++++++++++++++++
>  include/linux/irqchip.h   | 23 +++++++++++++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c
> index 2b35e68bea82..236ea793f01c 100644
> --- a/drivers/irqchip/irqchip.c
> +++ b/drivers/irqchip/irqchip.c
> @@ -10,8 +10,10 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/init.h>
> +#include <linux/of_device.h>
>  #include <linux/of_irq.h>
>  #include <linux/irqchip.h>
> +#include <linux/platform_device.h>
>  
>  /*
>   * This special of_device_id is the sentinel at the end of the
> @@ -29,3 +31,23 @@ void __init irqchip_init(void)
>  	of_irq_init(__irqchip_of_table);
>  	acpi_probe_device_table(irqchip);
>  }
> +
> +int platform_irqchip_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *par_np = of_irq_find_parent(np);
> +	of_irq_init_cb_t irq_init_cb = of_device_get_match_data(&pdev->dev);
> +
> +	if (!irq_init_cb)
> +		return -EINVAL;
> +
> +	if (par_np == np)
> +		par_np = NULL;
> +
> +	/* If there's a parent irqchip, make sure it has been initialized. */
> +	if (par_np && !irq_find_matching_host(np, DOMAIN_BUS_ANY))

There is no guarantee that the calling driver wants BUS_ANY as a token
for its parent. It may work for now, if you only have dependencies to
drivers that only expose a single domain, but that's not a general
purpose check..

At least, please add a comment saying that the new driver may want to
check that the irqdomain it depends on may not be available.

> +		return -EPROBE_DEFER;
> +
> +	return irq_init_cb(np, par_np);
> +}
> +EXPORT_SYMBOL_GPL(platform_irqchip_probe);
> diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h
> index 950e4b2458f0..6d5eba7cbbb7 100644
> --- a/include/linux/irqchip.h
> +++ b/include/linux/irqchip.h
> @@ -13,6 +13,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/of.h>
> +#include <linux/platform_device.h>
>  
>  /*
>   * This macro must be used by the different irqchip drivers to declare
> @@ -26,6 +27,28 @@
>   */
>  #define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn)
>  
> +extern int platform_irqchip_probe(struct platform_device *pdev);
> +
> +#define IRQCHIP_PLATFORM_DRIVER_BEGIN \
> +static const struct of_device_id __irqchip_match_table[] = {

How about:

#define IRQCHIP_PLATFORM_DRIVER_BEGIN(drv_name)	\
static const struct of_device_id __irqchip_match_table_##drv_name = {

which makes it easier to debug when you want to identify specific
structures in an object (otherwise, they all have the same
name...). it is also much more pleasing aesthetically ;-).

> +
> +#define IRQCHIP_MATCH(compat, fn) { .compatible = compat, .data = fn },
> +
> +#define IRQCHIP_PLATFORM_DRIVER_END(drv_name)		\
> +	{},						\
> +};							\
> +MODULE_DEVICE_TABLE(of, __irqchip_match_table);		\
> +static struct platform_driver drv_name##_driver = {	\

const?

> +	.probe  = platform_irqchip_probe,		\
> +	.driver = {					\
> +		.name = #drv_name,			\
> +		.owner = THIS_MODULE,			\
> +		.of_match_table = __irqchip_match_table,\
> +		.suppress_bind_attrs = true,		\
> +	},						\
> +};							\
> +builtin_platform_driver(drv_name##_driver)
> +
>  /*
>   * This macro must be used by the different irqchip drivers to declare
>   * the association between their version and their initialization function.
> -- 
> 2.28.0.rc0.105.gf9edc3c819-goog
> 
> 

Otherwise looks good. When you respin it, it would be good to also
submit one user of this API by converting an existing driver, as I'd
hate to merge something that has no user.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-07-17 10:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  2:44 [PATCH v2] irqchip: Add IRQCHIP_PLATFORM_DRIVER_BEGIN/END and IRQCHIP_MATCH helper macros Saravana Kannan
2020-07-17  2:44 ` Saravana Kannan
2020-07-17  2:44 ` Saravana Kannan
2020-07-17 10:49 ` Marc Zyngier [this message]
2020-07-17 10:49   ` Marc Zyngier
2020-07-17 10:49   ` Marc Zyngier
2020-07-17 17:50   ` Saravana Kannan
2020-07-17 17:50     ` Saravana Kannan
2020-07-17 17:50     ` Saravana Kannan
2020-07-17 18:04     ` Marc Zyngier
2020-07-17 18:04       ` Marc Zyngier
2020-07-17 18:04       ` Marc Zyngier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0z2xvp6.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=cc.hwang@mediatek.com \
    --cc=hanks.chen@mediatek.com \
    --cc=jason@lakedaemon.net \
    --cc=john.stultz@linaro.org \
    --cc=kernel-team@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=loda.chou@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=saravanak@google.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.