[RFC] gpio: about the need to manage irq mapping dynamically.

Linus Walleij linus.walleij at linaro.org
Thu Jun 29 07:14:17 PDT 2017

On Tue, Jun 27, 2017 at 8:25 PM, Jerome Brunet <jbrunet at baylibre.com> wrote:

> At the time Linus strongly rejected the idea of calling  irq_create_mapping (or
> any sleeping functions) in gpio_to_irq: please see the reply from Oct 26, 2016
> (sorry for quoting such an old discussion but this is really the starting point)
> * Me: There is really a *lot* of gpio drivers which use irq_create_mapping in
> the to_irq callback, are these all wrong ?
> * Linus: Yes they are all wrong. They should all be using irq_find_mapping().
> * Me: If this should not be used, what should we all do instead ?
> * Linus: Call irq_create_mapping() in some other place.
> gpio_prepare_irq is a proposition for this 'other place'.

There is a misunderstanding here.

I wrote (at the time):

> Yes, but you want to call irq_create_mapping() in slowpath (irq setup)
> and irq_find_mapping() in fastpath (irq handler). Else the first IRQ
> may result in unwelcomed surprises.

This does not mean that irq_create_mapping() cannot be called
in irq context because I think it can.

What it means is that I think that is suboptimal from a performance
point of view if called from gpio_to_irq(), because nominally, at this
point, the mapping should already exist, since the GPIO and IRQ
frameworks are orthogonal.

But that may not apply to the case with many-to-few interrupt
mappings... so I think I was in some 1-to-1-mapping context
when I wrote this. Sorry :(

So I changed my mind, it is fine for this type of driver to call
irq_create_mapping() in gpio_to_irq(). Preferably with some comment
around the call.

It remains to see what happens if gpio_to_irq() would fail, as can
happen in this case. Like if gpio_to_irq() would return 0 (NO_IRQ)
or something negative. I think many drivers are not equipped for
handling this.

So I guess if you could change the semantics of all drivers
calling gpio_to_irq() to also handle say 0 as an error and bail
out, we can call irq_create_mapping() in gpio_to_irq().

Sorry if I'm confused... or confusing.

Linus Walleij

More information about the linux-amlogic mailing list