From: Thomas Gleixner <tglx@linutronix.de>
To: Yixun Lan <dlan@gentoo.org>, Alex Elder <elder@riscstar.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Inochi Amaoto <inochiama@gmail.com>,
linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH 1/2] irqdomain: support three-cell scheme interrupts
Date: Fri, 28 Feb 2025 14:44:36 +0100 [thread overview]
Message-ID: <871pvidvzv.ffs@tglx> (raw)
In-Reply-To: <20250227204155-GYA51171@gentoo>
On Thu, Feb 27 2025 at 20:41, Yixun Lan wrote:
> On 10:12 Thu 27 Feb , Alex Elder wrote:
>> On 2/27/25 5:24 AM, Yixun Lan wrote:
>> >
>> > diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
>> > index ec6d8e72d980f604ded2bfa2143420e0e0095920..cb874ab5e54a4763d601122becd63b6d759e55d2 100644
>> > --- a/kernel/irq/irqdomain.c
>> > +++ b/kernel/irq/irqdomain.c
>> > @@ -1208,10 +1208,17 @@ int irq_domain_translate_twocell(struct irq_domain *d,
>> > unsigned long *out_hwirq,
>> > unsigned int *out_type)
>> > {
>>
>> This function is meant for "twocell". There is also another function
>> irq_domain_translate_onecell(). Why don't you just create
>> irq_domain_translate_threecell" instead?
>>
> good question!
>
> it's too many changes for adding "threecell" which I thought not worth
> the effort, or maybe we can rename the function to *twothreecell()?
>
> I'm not sure which way to go is the best, ideas from maintainer are
> welcome
We really want to have explicit functions for two and three cells.
>> > + u32 irq, type;
>> > +
>> > if (WARN_ON(fwspec->param_count < 2))
>> > return -EINVAL;
>> > - *out_hwirq = fwspec->param[0];
>> > - *out_type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
>> > +
>> > + irq = fwspec->param_count - 2;
>> > + type = fwspec->param_count - 1;
> no matter two or three cell, it's always parse the last two cells,
> virtually they are same syntax, which can reuse the *_translate_twocell()
> function perfectly..
Yes, that works but the code is completely non-obvious. So what you
really want is something like this:
int irq_domain_translate_cells(struct irq_domain *d, unsigned long *hwirq,
unsigned int *type)
{
unsigned int cells = fwspec->param_count;
switch (cells) {
case 1:
*hwirq = fwspec->param[0];
*type = IRQ_TYPE_NONE;
return 0;
case 2..3:
/*
* For multi cell translations the hardware interrupt number and type
* are in the last two cells.
*/
*hwirq = fwspec->param[cells - 2];
*type = fwspec->param[cells - 1] & IRQ_TYPE_SENSE_MASK;
return 0;
default:
return -EINVAL;
}
}
Then have inline helpers:
static inline int irq_domain_translate_XXXcell(struct irq_domain *d, unsigned long *hwirq,
unsigned int *type)
{
return irq_domain_translate_cells(d, hwirq, type);
}
That avoids changing all call sites at once and merges the one cell
translation into it.
You get the idea....
Thanks,
tglx
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Gleixner <tglx@linutronix.de>
To: Yixun Lan <dlan@gentoo.org>, Alex Elder <elder@riscstar.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Inochi Amaoto <inochiama@gmail.com>,
linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH 1/2] irqdomain: support three-cell scheme interrupts
Date: Fri, 28 Feb 2025 14:44:36 +0100 [thread overview]
Message-ID: <871pvidvzv.ffs@tglx> (raw)
In-Reply-To: <20250227204155-GYA51171@gentoo>
On Thu, Feb 27 2025 at 20:41, Yixun Lan wrote:
> On 10:12 Thu 27 Feb , Alex Elder wrote:
>> On 2/27/25 5:24 AM, Yixun Lan wrote:
>> >
>> > diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
>> > index ec6d8e72d980f604ded2bfa2143420e0e0095920..cb874ab5e54a4763d601122becd63b6d759e55d2 100644
>> > --- a/kernel/irq/irqdomain.c
>> > +++ b/kernel/irq/irqdomain.c
>> > @@ -1208,10 +1208,17 @@ int irq_domain_translate_twocell(struct irq_domain *d,
>> > unsigned long *out_hwirq,
>> > unsigned int *out_type)
>> > {
>>
>> This function is meant for "twocell". There is also another function
>> irq_domain_translate_onecell(). Why don't you just create
>> irq_domain_translate_threecell" instead?
>>
> good question!
>
> it's too many changes for adding "threecell" which I thought not worth
> the effort, or maybe we can rename the function to *twothreecell()?
>
> I'm not sure which way to go is the best, ideas from maintainer are
> welcome
We really want to have explicit functions for two and three cells.
>> > + u32 irq, type;
>> > +
>> > if (WARN_ON(fwspec->param_count < 2))
>> > return -EINVAL;
>> > - *out_hwirq = fwspec->param[0];
>> > - *out_type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
>> > +
>> > + irq = fwspec->param_count - 2;
>> > + type = fwspec->param_count - 1;
> no matter two or three cell, it's always parse the last two cells,
> virtually they are same syntax, which can reuse the *_translate_twocell()
> function perfectly..
Yes, that works but the code is completely non-obvious. So what you
really want is something like this:
int irq_domain_translate_cells(struct irq_domain *d, unsigned long *hwirq,
unsigned int *type)
{
unsigned int cells = fwspec->param_count;
switch (cells) {
case 1:
*hwirq = fwspec->param[0];
*type = IRQ_TYPE_NONE;
return 0;
case 2..3:
/*
* For multi cell translations the hardware interrupt number and type
* are in the last two cells.
*/
*hwirq = fwspec->param[cells - 2];
*type = fwspec->param[cells - 1] & IRQ_TYPE_SENSE_MASK;
return 0;
default:
return -EINVAL;
}
}
Then have inline helpers:
static inline int irq_domain_translate_XXXcell(struct irq_domain *d, unsigned long *hwirq,
unsigned int *type)
{
return irq_domain_translate_cells(d, hwirq, type);
}
That avoids changing all call sites at once and merges the one cell
translation into it.
You get the idea....
Thanks,
tglx
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-02-28 13:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 11:24 [PATCH 0/2] gpio: irq: support describing three-cell interrupts Yixun Lan
2025-02-27 11:24 ` Yixun Lan
2025-02-27 11:24 ` [PATCH 1/2] irqdomain: support three-cell scheme interrupts Yixun Lan
2025-02-27 11:24 ` Yixun Lan
2025-02-27 16:12 ` Alex Elder
2025-02-27 16:12 ` Alex Elder
2025-02-27 20:41 ` Yixun Lan
2025-02-27 20:41 ` Yixun Lan
2025-02-28 8:44 ` Linus Walleij
2025-02-28 8:44 ` Linus Walleij
2025-02-28 10:52 ` Yixun Lan
2025-02-28 10:52 ` Yixun Lan
2025-02-28 13:44 ` Thomas Gleixner [this message]
2025-02-28 13:44 ` Thomas Gleixner
2025-02-27 11:25 ` [PATCH 2/2] gpiolib: support parsing gpio three-cell interrupts scheme Yixun Lan
2025-02-27 11:25 ` Yixun Lan
2025-02-28 9:11 ` Linus Walleij
2025-02-28 9:11 ` Linus Walleij
2025-02-28 10:10 ` Yixun Lan
2025-02-28 10:10 ` Yixun Lan
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=871pvidvzv.ffs@tglx \
--to=tglx@linutronix.de \
--cc=brgl@bgdev.pl \
--cc=dlan@gentoo.org \
--cc=elder@riscstar.com \
--cc=inochiama@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=spacemit@lists.linux.dev \
/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.