Re: [PATCH 2/2] irqchip: Add Microchip PIC64-HPSC/HX NVM interrupt controller
From: Charles Perry
Date: Fri Dec 04 2026 - 17:58:48 EST
On Fri, Dec 04, 2026 at 09:40:14PM +0100, Thomas Gleixner wrote:
> On Fri, Dec 04 2026 at 10:54, Charles Perry wrote:
> > On Fri, Dec 04, 2026 at 11:57:00AM +0100, Thomas Gleixner wrote:
> >> So this sequence:
> >>
> >> pending = read(STATUS) & read(ENABLE);
> >>
> >> write(pending, STATUS);
> >>
> >> pending &= read(STATUS);
> >
> > This read() was on VALUE, see my diagram below.
> >>
> >> does not make sense for a sanely designed level type controller which
> >> usually does:
> >>
> >> STATUS = LINESTATE & ENABLED
> >>
> >> and if it has multiple input lines then the output is simply:
> >>
> >> OUTLINE = STATUS(0) | STATUS(1) .... | STATUS(N)
> >>
> >> From your code and comments it seems STATUS is latched which does not
> >> make sense.
> >
> > We have 3 registers, VALUE, STATUS and ENABLE. VALUE is the live output of
> > the device, STATUS reflects a latched value of each input and ENABLE
> > controls which output gets muxed:
> >
> > +----------------------------------------+
> > | nvm-intc |
> > | |
> > | |
> > +--------+ VALUE[0] +------+ STATUS[0] +---+ +---+ |
> > | Device |----|------>| Edge |---------->| | | | |
> > | | | | | | | | | |
> > +--------+ | +------+ |AND| | | |
> > | | |-->| | | +--------+
> > | | | | | | | APLIC |
> > | ENABLE[0]--->| | | | | | |
> > | +---+ | | | | |
> > | | |----->| |
> > +--------+ VALUE[1] +------+ STATUS[1] +---+ |OR | | | |
> > | Device |----------->| Edge |---------->| | | | | | |
> > | | | | | | | | | | | |
> > +--------+ | +------+ |AND|-->| | | +--------+
> > | | | | | |
> > | | | | | |
> > | ENABLE[1]--->| | | | |
> > | +---+ | | |
> > | | | |
> > | ... | | |
> > +----------------------------------+---+-+
> >
> > Is it a problem that ENABLE doesn't prevent VALUE from latching STATUS?
>
> Not if you mask it out with the enabled bits. But ...
>
> >> But even then it does not explain how the status bit stays raised with
> >> the mask_ack() sequence of the level handler.
> >
> > Because ENABLE acts on the output, it doesn't prevent VALUE from latching
> > STATUS. So if another interrupt happens while calling the device handler
> > STATUS will be high, even though ENABLE is 0.
>
> .. you say the input is latched into status on a raising edge, right?
Yes, VALUE needs to make a 0-1 transition for STATUS to latch. If you clear
STATUS while VALUE is 1 you will miss interrupts.
>
> Which means the input logic is edge type. The output is level type.
>
> But you claim the input is level type too. That doesn't make any sense.
I was under the impression that it's the device (and not the interrupt
controller) that decides if an interrupt is level or edge but maybe I'm
wrong.
>
> A strict level type interrupt source in a device is not required to have
> a 1-0-1 transition. The interrupt line can stay asserted even when the
> first interrupt is handled by the device driver. A typical scenario is
> that in the device there is a interrupt status register. So the
> following can happen:
>
> Device dev-irq
> IS == 0 0
> IS == 1 1
> interrupt
> mask_ack()
> handler()
> // Reads 1
> pending = read(IS);
> IS == 3
> // Clears bit(0)
> IS == 2 handle(pending)
> return;
> unmask();
If this happens on an input of nvm-intc, then VALUE=1 and STATUS=0.
The way we would handle this with nvm-intc is to check VALUE after unmask()
and call the interrupt handler again if it is raised. That's not done in
the patch I sent because I never encountered the issue.
>
> That's legit from a device driver POV if the device interrupt is
> strictly level type output because the driver can rely on the interrupt
> being re-raised in the CPU after the unmask.
>
> If your input logic latches on a rising edge, then this case is not
> re-raising the interrupt because the mask_ack() clears the status bit
> and if there is no 1-0-1 transition on the input line, then the
> interrupt line becomes stale.
Yes, that is correct.
Pretty much all of the IP designed in-house for PIC64-HPSC/HX use the same
VALUE, STATUS and ENABLE circuitry.
>
> So none of this adds up.
>
> If the interrupt is latched on a rising edge, then you need to treat it
> as edge interrupt type. The underlying APLIC interrupt can still be
Ok, that should work. IIUC, I should use handle_edge_irq() which
->irq_ack() but does not ->irq_mask().
In our first attempt to support this, we added the STATUS register in all
of the NVM controllers (xSPI, SD, NAND) and each of these drivers would ack
their interrupt bit in the STATUS register without any masking. That worked
fine but is a bit of a hack because you need to map the same register in 3
different drivers.
> level type because that's an independent interrupt.
Yes, that one I know for sure is level.
Thank you for all your detailed explanations, it helps a lot.
--
Thanks,
Charles