Linux SOC development
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: "Marek Behún" <kabel@kernel.org>,
	"Gregory CLEMENT" <gregory.clement@bootlin.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	soc@kernel.org, "Hans de Goede" <hdegoede@redhat.com>,
	"Dan Carpenter" <dan.carpenter@linaro.org>
Cc: arm@kernel.org
Subject: Re: [PATCH v6 06/11] devm-helpers: Add resource managed version of irq_create_mapping()
Date: Tue, 23 Apr 2024 15:32:23 +0300	[thread overview]
Message-ID: <aa564814-bf73-4a37-88c3-50738272a85f@gmail.com> (raw)
In-Reply-To: <20240418121116.22184-7-kabel@kernel.org>

On 4/18/24 15:11, Marek Behún wrote:
> Add resource managed version of irq_create_mapping(), to help drivers
> automatically dispose a linux irq mapping when driver is detached.
> 
> Signed-off-by: Marek Behún <kabel@kernel.org>
> ---
>   include/linux/devm-helpers.h | 54 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 54 insertions(+)
> 
> diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h
> index 74891802200d..fe62b28baf03 100644
> --- a/include/linux/devm-helpers.h
> +++ b/include/linux/devm-helpers.h
> @@ -24,6 +24,8 @@
>    */
>   
>   #include <linux/device.h>
> +#include <linux/kconfig.h>
> +#include <linux/irqdomain.h>

I still think stuffing all unrelated APIs in one header will lead to 
problems because of the sheer amount of unrelated stuff which gets 
included when only some APIs from this file are used.

But as I said during V5 review, I don't want to block this if no one 
else thinks it is a real problem.

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

>   #include <linux/workqueue.h>
>   
>   static inline void devm_delayed_work_drop(void *res)
> @@ -76,4 +78,56 @@ static inline int devm_work_autocancel(struct device *dev,
>   	return devm_add_action(dev, devm_work_drop, w);
>   }
>   
> +/**
> + * devm_irq_mapping_drop - devm action for disposing an irq mapping
> + * @res:	linux irq number cast to the void * type
> + *
> + * devm_irq_mapping_drop() can be used as an action parameter for the
> + * devm_add_action_or_reset() function in order to automatically dispose
> + * a linux irq mapping when a device driver is detached.
> + */
> +static inline void devm_irq_mapping_drop(void *res)
> +{
> +	irq_dispose_mapping((unsigned int)(unsigned long)res);
> +}
> +
> +/**
> + * devm_irq_create_mapping - Resource managed version of irq_create_mapping()
> + * @dev:	Device which lifetime the mapping is bound to
> + * @domain:	domain owning this hardware interrupt or NULL for default domain
> + * @hwirq:	hardware irq number in that domain space
> + *
> + * Create an irq mapping to linux irq space which is automatically disposed when
> + * the driver is detached.
> + * devm_irq_create_mapping() can be used to omit the explicit
> + * irq_dispose_mapping() call when driver is detached.
> + *
> + * Returns a linux irq number on success, -ENXIO if the mapping could not be
> + * created, or a negative error number if devm action could not be added.
> + */
> +static inline int devm_irq_create_mapping(struct device *dev,
> +					  struct irq_domain *domain,
> +					  irq_hw_number_t hwirq)
> +{
> +	unsigned int virq = irq_create_mapping(domain, hwirq);
> +
> +	if (!virq)
> +		return -ENXIO;
> +
> +	/*
> +	 * irq_dispose_mapping() is an empty function if CONFIG_IRQ_DOMAIN is
> +	 * disabled. No need to register an action in that case.
> +	 */
> +	if (IS_ENABLED(CONFIG_IRQ_DOMAIN)) {
> +		int err;
> +
> +		err = devm_add_action_or_reset(dev, devm_irq_mapping_drop,
> +					       (void *)(unsigned long)virq);
> +		if (err)
> +			return err;
> +	}
> +
> +	return virq;
> +}
> +
>   #endif

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


  reply	other threads:[~2024-04-23 12:32 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 12:11 [PATCH v6 00/11] Turris Omnia MCU driver Marek Behún
2024-04-18 12:11 ` [PATCH v6 01/11] dt-bindings: arm: add cznic,turris-omnia-mcu binding Marek Behún
2024-04-18 15:43   ` Conor Dooley
2024-04-19  8:23     ` Marek Behún
2024-04-19 11:14       ` Marek Behún
2024-04-19 13:52         ` Conor Dooley
2024-04-18 12:11 ` [PATCH v6 02/11] platform: cznic: Add preliminary support for Turris Omnia MCU Marek Behún
2024-04-18 12:11 ` [PATCH v6 03/11] platform: cznic: turris-omnia-mcu: Add support for MCU connected GPIOs Marek Behún
2024-04-18 12:11 ` [PATCH v6 04/11] platform: cznic: turris-omnia-mcu: Add support for poweroff and wakeup Marek Behún
2024-04-18 12:11 ` [PATCH v6 05/11] platform: cznic: turris-omnia-mcu: Add support for MCU watchdog Marek Behún
2024-04-18 13:26   ` Guenter Roeck
2024-04-18 14:15     ` Marek Behún
2024-04-18 12:11 ` [PATCH v6 06/11] devm-helpers: Add resource managed version of irq_create_mapping() Marek Behún
2024-04-23 12:32   ` Matti Vaittinen [this message]
2024-04-23 12:46   ` Andy Shevchenko
2024-04-23 14:21     ` Marek Behún
2024-04-23 15:14     ` Marek Behún
2024-04-23 15:56       ` Andy Shevchenko
2024-04-18 12:11 ` [PATCH v6 07/11] platform: cznic: turris-omnia-mcu: Add support for MCU provided TRNG Marek Behún
2024-04-23 15:58   ` Andy Shevchenko
2024-04-23 16:32     ` Marek Behún
2024-04-23 16:43       ` Andy Shevchenko
2024-04-23 16:57         ` Marek Behún
2024-04-23 17:25           ` Andy Shevchenko
2024-04-24 16:55             ` Marek Behún
2024-04-18 12:11 ` [PATCH v6 08/11] devm-helpers: Add resource managed version of debugfs directory create function Marek Behún
2024-04-23 12:33   ` Matti Vaittinen
2024-04-23 16:02   ` Andy Shevchenko
2024-04-23 16:20     ` Marek Behún
2024-04-23 16:33       ` Andy Shevchenko
2024-04-23 16:43         ` Marek Behún
2024-04-23 16:21     ` Dan Carpenter
2024-04-18 12:11 ` [PATCH v6 09/11] platform: cznic: turris-omnia-mcu: Add support for digital message signing via debugfs Marek Behún
2024-04-18 12:11 ` [PATCH v6 10/11] ARM: dts: turris-omnia: Add MCU system-controller node Marek Behún
2024-04-18 12:11 ` [PATCH v6 11/11] ARM: dts: turris-omnia: Add GPIO key node for front button Marek Behún
2024-04-23 16:05 ` [PATCH v6 00/11] Turris Omnia MCU driver Andy Shevchenko

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=aa564814-bf73-4a37-88c3-50738272a85f@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=arm@kernel.org \
    --cc=arnd@arndb.de \
    --cc=dan.carpenter@linaro.org \
    --cc=gregory.clement@bootlin.com \
    --cc=hdegoede@redhat.com \
    --cc=kabel@kernel.org \
    --cc=soc@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox