Re: [PATCH V2 4/4] irq: imx: irqsteer: add multi output interrupts support

From: Lucas Stach
Date: Wed Jan 30 2019 - 09:11:33 EST


Am Mittwoch, den 30.01.2019, 22:03 +0800 schrieb Dong Aisheng:
> > On Wed, Jan 30, 2019 at 9:33 PM Lucas Stach <l.stach@xxxxxxxxxxxxxx> wrote:
> >
> > Am Mittwoch, den 30.01.2019, 13:06 +0000 schrieb Aisheng Dong:
> > > One irqsteer channel can support up to 8 output interrupts.
> > >
> > > > > > > > Cc: Marc Zyngier <marc.zyngier@xxxxxxx>
> > > > > > > > Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> > > > > > > > Cc: Shawn Guo <shawnguo@xxxxxxxxxx>
> > > > Signed-off-by: Dong Aisheng <aisheng.dong@xxxxxxx>
> > >
> > > ---
> > > ChangeLog:
> > > v1->v2:
> > > Â* calculate irq_count by fsl,num-irqs instead of parsing interrupts
> > > ÂÂÂproperty from devicetree to match the input interrupts and outputs
> > > Â* improve output interrupt handler by searching only two registers
> > > ÂÂÂwithint the same group
> > > ---
> > > Âdrivers/irqchip/irq-imx-irqsteer.c | 76 +++++++++++++++++++++++++++++---------
> > > Â1 file changed, 59 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/drivers/irqchip/irq-imx-irqsteer.c b/drivers/irqchip/irq-imx-irqsteer.c
> > > index 67ed862..cc40039 100644
> > > --- a/drivers/irqchip/irq-imx-irqsteer.c
> > > +++ b/drivers/irqchip/irq-imx-irqsteer.c
> > > @@ -10,6 +10,7 @@
> > > Â#include <linux/irqchip/chained_irq.h>
> > > Â#include <linux/irqdomain.h>
> > > Â#include <linux/kernel.h>
> > > +#include <linux/of_irq.h>
> > > Â#include <linux/of_platform.h>
> > > Â#include <linux/spinlock.h>
> > >
> > > @@ -21,10 +22,13 @@
> > > > Â#define CHAN_MINTDIS(t)ÂÂÂÂÂÂÂÂÂÂÂÂ(CTRL_STRIDE_OFF(t, 3) + 0x4)
> > > > Â#define CHAN_MASTRSTAT(t)ÂÂ(CTRL_STRIDE_OFF(t, 3) + 0x8)
> > > > +#define CHAN_MAX_OUTPUT_INTÂÂÂÂÂÂÂÂ0x8
> > >
> > > +
> > > Âstruct irqsteer_data {
> > > > > Â void __iomemÂÂÂÂÂÂÂÂÂÂÂÂ*regs;
> > > > > Â struct clkÂÂÂÂÂÂÂÂÂÂÂÂÂÂ*ipg_clk;
> > > > > - intÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂirq;
> > > > > + intÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂirq[CHAN_MAX_OUTPUT_INT];
> > > > > + intÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂirq_count;
> > > > > Â raw_spinlock_tÂÂÂÂÂÂÂÂÂÂlock;
> > > > > Â intÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreg_num;
> > > > > Â intÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂchannel;
> > >
> > > @@ -87,26 +91,45 @@ static const struct irq_domain_ops imx_irqsteer_domain_ops = {
> > > > > Â .xlateÂÂÂÂÂÂÂÂÂÂ= irq_domain_xlate_onecell,
> > >
> > > Â};
> > >
> > > +static int imx_irqsteer_get_hwirq_base(struct irqsteer_data *data, u32 irq)
> > > +{
> > > > +ÂÂÂint i;
> > >
> > > +
> > > > +ÂÂÂfor (i = 0; i < data->irq_count; i++) {
> > > > +ÂÂÂÂÂÂÂÂÂÂÂif (data->irq[i] == irq)
> > >
> > > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
> >
> > return i * 64; here...
> > > +ÂÂÂÂÂ}
> > > +
> > > +ÂÂÂÂÂreturn i * 64;
> >
> > ... and -EINVAL or something here, so we don't return a out of bounds
> > hwirq base if the loop ever doesn't match something?
> >
>
> Good suggestion, will add it.
>
> > > +}
> > > +
> > > Âstatic void imx_irqsteer_irq_handler(struct irq_desc *desc)
> > > Â{
> > > > ÂÂÂÂstruct irqsteer_data *data = irq_desc_get_handler_data(desc);
> > > > +ÂÂÂint hwirq;
> > > > ÂÂÂÂint i;
> > > > ÂÂÂÂchained_irq_enter(irq_desc_get_chip(desc), desc);
> > > > -ÂÂÂfor (i = 0; i < data->reg_num * 32; i += 32) {
> > > > -ÂÂÂÂÂÂÂÂÂÂÂint idx = imx_irqsteer_get_reg_index(data, i);
> > > > +ÂÂÂhwirq = imx_irqsteer_get_hwirq_base(data, irq_desc_get_irq(desc));
> > >
> > > +
> > > > +ÂÂÂfor (i = 0; i < 2; i++) {
> > > > +ÂÂÂÂÂÂÂÂÂÂÂint idx = imx_irqsteer_get_reg_index(data, hwirq);
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂunsigned long irqmap;
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂint pos, virq;
> > > > +ÂÂÂÂÂÂÂÂÂÂÂif (hwirq >= data->reg_num * 32)
> > > > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
> > >
> > > +
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂirqmap = readl_relaxed(data->regs +
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂCHANSTATUS(idx, data->reg_num));
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂfor_each_set_bit(pos, &irqmap, 32) {
> > > > -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvirq = irq_find_mapping(data->domain, pos + i);
> > >
> > > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvirq = irq_find_mapping(data->domain, pos + hwirq);
> >
> > The irq index calculation need to be "pos + i * 32 + hwirq", otherwise
> > this will map to the wrong virqs for the second register in each group.
> >
>
> For second register map, hwirq will plus 32 in next round.
> So i can't see this will map a wrong virqs.
> And it looks to me ""pos + i * 32 + hwirq" is equal to "hwirq + 32".
> Am i missed something?

You are right, I forgot about the hwirq being incremented in the loop
when writing this comment.

> > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂif (virq)
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgeneric_handle_irq(virq);
> > > > ÂÂÂÂÂÂÂÂÂÂÂÂ}
> > >
> > > +ÂÂÂÂÂÂÂÂÂÂÂÂÂhwirq += 32;
> >
> > Could be folded into the loop head.
> >
>
> You mean âfor (i = 0; i < 2; i++, hwirq +=32)â ?
> I feel that's not quite necessary.

I personally find that quite a bit clearer than incrementing the loop
variables at different spots. And I probably wouldn't have missed hwirq
being incremented in the loop if I had seen it in the head.

Regards,
Lucas