Re: [PATCH v4 2/8] irqchip: Add Realtek RTD1295 mux driver

From: Marc Zyngier
Date: Wed Nov 20 2019 - 07:23:54 EST


On 2019-11-20 12:12, Andreas FÃrber wrote:
Am 20.11.19 um 11:18 schrieb Marc Zyngier:
On 2019-11-19 23:25, Andreas FÃrber wrote:
Am 19.11.19 um 13:01 schrieb Marc Zyngier:
On 2019-11-19 02:19, Andreas FÃrber wrote:
diff --git a/drivers/irqchip/irq-rtd1195-mux.c
b/drivers/irqchip/irq-rtd1195-mux.c
new file mode 100644
index 000000000000..e6b08438b23c
--- /dev/null
+++ b/drivers/irqchip/irq-rtd1195-mux.c
[...]
+static void rtd1195_mux_irq_handle(struct irq_desc *desc)
+{
+ÂÂÂ struct rtd1195_irq_mux_data *data =
irq_desc_get_handler_data(desc);
+ÂÂÂ struct irq_chip *chip = irq_desc_get_chip(desc);
+ÂÂÂ u32 isr, mask;
+ÂÂÂ int i;
+
+ÂÂÂ chained_irq_enter(chip, desc);
+
+ÂÂÂ isr = readl_relaxed(data->reg_isr);
+
+ÂÂÂ while (isr) {
+ÂÂÂÂÂÂÂ i = __ffs(isr);
+ÂÂÂÂÂÂÂ isr &= ~BIT(i);
+
+ÂÂÂÂÂÂÂ mask = data->info->isr_to_int_en_mask[i];
+ÂÂÂÂÂÂÂ if (mask && !(data->scpu_int_en & mask))
+ÂÂÂÂÂÂÂÂÂÂÂ continue;
+
+ÂÂÂÂÂÂÂ if (!generic_handle_irq(irq_find_mapping(data->domain, i)))
+ÂÂÂÂÂÂÂÂÂÂÂ writel_relaxed(BIT(i), data->reg_isr);

What does this write do exactly? It is the same thing as a 'mask',
which is pretty odd. So either:

- this is not doing anything and your 'mask' callback is bogus
 (otherwise you'd never have more than a single interrupt)

- or this is an ACK operation, and this should be described as
 such (and then fix the mask/unmask/enable/disable mess that
 results from it).

This is supposed to be an ACK, i.e. clear-1-bits operation.

If it is an ACK, model it as such, and do not open-code it.

I have found an .irq_ack callback - moving this there appears to work.

Alternatively there is an irq_eoi callback and an IRQCHIP_EOI_IF_HANDLED
flag.

It would really help me if you spelled out explicitly where you think I
should be moving code, as the documentation in irq.h is not all that
helpful in terms of when are they called and what should be done there.
In case not obvious, this is my first irqchip driver.

Implementing one callback or the other really depends on how the HW
behaves. The irq framework gives you a wide range of flows that allow
you to plug your driver in the stack, but the prerequisite is that you
know *exactly* how the HW behaves. Ack and EOI have very different
meanings, are called from different flows, and correspond to different
states in the interrupt life cycle.

Use the wrong one, and you will lose interrupts. If you don't know how
the HW behaves, then the chances of something bad happening are pretty
high (you'll end-up in deadlock land at some point). I'm afraid I cannot
help you with that, short of being given access to some documentation
that doesn't seem to exist.

M.
--
Jazz is not dead. It just smells funny...