* [RFC/RFT PATCH 0/3] gpiolib: make gpio irqchip compatible with sparse_irq
@ 2017-07-08 22:44 Grygorii Strashko
2017-07-08 22:44 ` [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers Grygorii Strashko
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Grygorii Strashko @ 2017-07-08 22:44 UTC (permalink / raw)
To: Robert Jarzmik, Linus Walleij, Thierry Reding, Jonathan Hunter,
linux-gpio-u79uwXL29TY76Z2rM5mHXA
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA, Jerome Brunet,
Grygorii Strashko
The idea of this changes was inspired by discussion [1].
Now IRQ mappings are always created for all (allowed) GPIOs in GPIO irqchip in
gpiochip_irqchip_add_key() and this goes against the idea of SPARSE_IRQ and,
as result, leads to:
- increasing of memory consumption because of allocated IRQ descriptors most
of which will never ever be used (especially on platform with a
high number of GPIOs).
- imposibility to use GPIO irqchip APIs by gpio drivers when HW implements
GPIO IRQ functionality as IRQ crossbar/multiplexer which has only limited
number of IRQ outputs (example from [1], all GPIOs can be mapped on only 8
IRQs).
Hence, remove static IRQ mapping code from gpiochip_irqchip_add_key() and
instead replace irq_find_mapping() with irq_create_mapping() in
gpiochip_to_irq(). Also add additional gpiochip_irqchip_irq_valid() calls
in gpiochip_to_irq() and gpiochip_irq_map().
After this change gpio2irq mapping will happen the following way when GPIO
irqchip APIs are used by gpio driver:
- IRQ mappings will be created statically if driver passes first_irq>0
vlaue in gpiochip_irqchip_add_key().
- IRQ mappings will be created dynamically from gpio_to_irq() or
of_irq_get().
Tested on am335x-evm and dra72-evm-revc.
- dra72-evm-revc: number of created irq mappings decreased from 402 -> 135
- am335x-evm: number of created irq mappings decreased from 188 -> 63
It's good to have more testing feedbacks for these patches
(personally I do not expect regressions, but who knows). One possible side
effect is "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n" message
during boot, but in this case it might be good to take a look on such GPIO
drivers to understand why they need to allocate IRQ descriptors.
[1] https://www.mail-archive.com/linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org/msg1435847.html
Grygorii Strashko (3):
gpio: tegra: remove gpio_to_irq() from hw irq handlers
gpio: pxa: remove gpio_to_irq() from hw irq handlers
gpiolib: make gpio irqchip compatible with sparse_irq
drivers/gpio/gpio-pxa.c | 8 +++++---
drivers/gpio/gpio-tegra.c | 3 ++-
drivers/gpio/gpiolib.c | 29 ++++++-----------------------
include/linux/gpio/driver.h | 1 -
4 files changed, 13 insertions(+), 28 deletions(-)
--
2.10.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers 2017-07-08 22:44 [RFC/RFT PATCH 0/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko @ 2017-07-08 22:44 ` Grygorii Strashko 2017-08-01 7:49 ` Linus Walleij 2017-07-08 22:44 ` [RFC/RFT PATCH 2/3] gpio: pxa: " Grygorii Strashko 2017-07-08 22:44 ` [RFC/RFT PATCH 3/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko 2 siblings, 1 reply; 8+ messages in thread From: Grygorii Strashko @ 2017-07-08 22:44 UTC (permalink / raw) To: Robert Jarzmik, Linus Walleij, Thierry Reding, Jonathan Hunter, linux-gpio Cc: linux-kernel, linux-tegra, Jerome Brunet, Grygorii Strashko gpio_to_irq() API expected to be used by GPIO consumers and not drivers and there are no guarantee that its gpiolib implementation is irq safe. Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> --- drivers/gpio/gpio-tegra.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index 88529d3..31b9a86 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c @@ -389,7 +389,8 @@ static void tegra_gpio_irq_handler(struct irq_desc *desc) chained_irq_exit(chip, desc); } - generic_handle_irq(gpio_to_irq(gpio + pin)); + generic_handle_irq(irq_find_mapping(tgi->irq_domain, + gpio + pin)); } } -- 2.10.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers 2017-07-08 22:44 ` [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers Grygorii Strashko @ 2017-08-01 7:49 ` Linus Walleij 0 siblings, 0 replies; 8+ messages in thread From: Linus Walleij @ 2017-08-01 7:49 UTC (permalink / raw) To: Grygorii Strashko Cc: Robert Jarzmik, Thierry Reding, Jonathan Hunter, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Jerome Brunet On Sun, Jul 9, 2017 at 12:44 AM, Grygorii Strashko <grygorii.strashko@ti.com> wrote: > gpio_to_irq() API expected to be used by GPIO consumers and > not drivers and there are no guarantee that its gpiolib implementation > is irq safe. > > Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> Patch applied. This is obviously the right way to do it. Tegra people: please test. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC/RFT PATCH 2/3] gpio: pxa: remove gpio_to_irq() from hw irq handlers 2017-07-08 22:44 [RFC/RFT PATCH 0/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko 2017-07-08 22:44 ` [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers Grygorii Strashko @ 2017-07-08 22:44 ` Grygorii Strashko [not found] ` <20170708224413.18281-3-grygorii.strashko-l0cyMroinI0@public.gmane.org> 2017-07-08 22:44 ` [RFC/RFT PATCH 3/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko 2 siblings, 1 reply; 8+ messages in thread From: Grygorii Strashko @ 2017-07-08 22:44 UTC (permalink / raw) To: Robert Jarzmik, Linus Walleij, Thierry Reding, Jonathan Hunter, linux-gpio Cc: linux-kernel, linux-tegra, Jerome Brunet, Grygorii Strashko gpio_to_irq() API expected to be used by GPIO consumers and not drivers and there are no guarantee that its gpiolib implementation is irq safe. Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> --- drivers/gpio/gpio-pxa.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c index 832f3e4..6029899 100644 --- a/drivers/gpio/gpio-pxa.c +++ b/drivers/gpio/gpio-pxa.c @@ -451,7 +451,9 @@ static irqreturn_t pxa_gpio_demux_handler(int in_irq, void *d) for_each_set_bit(n, &gedr, BITS_PER_LONG) { loop = 1; - generic_handle_irq(gpio_to_irq(gpio + n)); + generic_handle_irq( + irq_find_mapping(pchip->irqdomain, + gpio + n)); } } handled += loop; @@ -465,9 +467,9 @@ static irqreturn_t pxa_gpio_direct_handler(int in_irq, void *d) struct pxa_gpio_chip *pchip = d; if (in_irq == pchip->irq0) { - generic_handle_irq(gpio_to_irq(0)); + generic_handle_irq(irq_find_mapping(pchip->irqdomain, 0)); } else if (in_irq == pchip->irq1) { - generic_handle_irq(gpio_to_irq(1)); + generic_handle_irq(irq_find_mapping(pchip->irqdomain, 1)); } else { pr_err("%s() unknown irq %d\n", __func__, in_irq); return IRQ_NONE; -- 2.10.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
[parent not found: <20170708224413.18281-3-grygorii.strashko-l0cyMroinI0@public.gmane.org>]
* Re: [RFC/RFT PATCH 2/3] gpio: pxa: remove gpio_to_irq() from hw irq handlers [not found] ` <20170708224413.18281-3-grygorii.strashko-l0cyMroinI0@public.gmane.org> @ 2017-08-01 7:47 ` Linus Walleij [not found] ` <CACRpkdZMgd7hSc6LwO5MbPb3vetd+qZ_5mXB1P9SM-HR+h_Pqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Linus Walleij @ 2017-08-01 7:47 UTC (permalink / raw) To: Grygorii Strashko Cc: Robert Jarzmik, Thierry Reding, Jonathan Hunter, linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jerome Brunet On Sun, Jul 9, 2017 at 12:44 AM, Grygorii Strashko <grygorii.strashko-l0cyMroinI0@public.gmane.org> wrote: > gpio_to_irq() API expected to be used by GPIO consumers and > not drivers and there are no guarantee that its gpiolib implementation > is irq safe. > > Signed-off-by: Grygorii Strashko <grygorii.strashko-l0cyMroinI0@public.gmane.org> Patch applied. This is the right thing to do. PXA developers: please test. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <CACRpkdZMgd7hSc6LwO5MbPb3vetd+qZ_5mXB1P9SM-HR+h_Pqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [RFC/RFT PATCH 2/3] gpio: pxa: remove gpio_to_irq() from hw irq handlers [not found] ` <CACRpkdZMgd7hSc6LwO5MbPb3vetd+qZ_5mXB1P9SM-HR+h_Pqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2017-08-01 18:41 ` Robert Jarzmik 0 siblings, 0 replies; 8+ messages in thread From: Robert Jarzmik @ 2017-08-01 18:41 UTC (permalink / raw) To: Linus Walleij Cc: Grygorii Strashko, Thierry Reding, Jonathan Hunter, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Jerome Brunet Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> writes: > On Sun, Jul 9, 2017 at 12:44 AM, Grygorii Strashko > <grygorii.strashko-l0cyMroinI0@public.gmane.org> wrote: > >> gpio_to_irq() API expected to be used by GPIO consumers and >> not drivers and there are no guarantee that its gpiolib implementation >> is irq safe. >> >> Signed-off-by: Grygorii Strashko <grygorii.strashko-l0cyMroinI0@public.gmane.org> > > Patch applied. > > This is the right thing to do. > > PXA developers: please test. Hi Linus, Currently pxa25x and pxa27x are broken because of a .data section misalignment (issue cross arm architectures), so testing is a bit hard for me right now. I'll wait to have a working again tree to test, and then report. Cheers. -- Robert ^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC/RFT PATCH 3/3] gpiolib: make gpio irqchip compatible with sparse_irq 2017-07-08 22:44 [RFC/RFT PATCH 0/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko 2017-07-08 22:44 ` [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers Grygorii Strashko 2017-07-08 22:44 ` [RFC/RFT PATCH 2/3] gpio: pxa: " Grygorii Strashko @ 2017-07-08 22:44 ` Grygorii Strashko 2017-08-01 7:46 ` Linus Walleij 2 siblings, 1 reply; 8+ messages in thread From: Grygorii Strashko @ 2017-07-08 22:44 UTC (permalink / raw) To: Robert Jarzmik, Linus Walleij, Thierry Reding, Jonathan Hunter, linux-gpio Cc: linux-kernel, linux-tegra, Jerome Brunet, Grygorii Strashko Now IRQ mappings are always created for all (allowed) GPIOs in gpio irqchip in gpiochip_irqchip_add_key() which goes against the idea of SPARSE_IRQ and, as result, leads to: - increasing of memory consumption because of allocated IRQ descriptors most of which will never ever be used (especially on platform with a high number of GPIOs) - imposibility to use GPIO irqchip APIs by gpio drivers when HW implements GPIO IRQ functionality as IRQ crossbar/multiplexer which has only limited number of IRQ outputs (example from [1], all GPIOs can be mapped on only 8 IRQs). Hence, remove static IRQ mapping code from gpiochip_irqchip_add_key() and instead replace irq_find_mapping() with irq_create_mapping() in gpiochip_to_irq(). Also add additional gpiochip_irqchip_irq_valid() calls in gpiochip_to_irq() and gpiochip_irq_map(). After this change gpio2irq mapping will happen the following way when GPIO irqchip APIs are used by gpio driver: - IRQ mappings will be created statically if driver passes first_irq>0 vlaue in gpiochip_irqchip_add_key(). - IRQ mappings will be created dynamically from gpio_to_irq() or of_irq_get(). [1] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1435847.html Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> --- drivers/gpio/gpiolib.c | 29 ++++++----------------------- include/linux/gpio/driver.h | 1 - 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9568708..ee6ba07 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1605,6 +1605,9 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, { struct gpio_chip *chip = d->host_data; + if (!gpiochip_irqchip_irq_valid(chip, hwirq)) + return -ENXIO; + irq_set_chip_data(irq, chip); /* * This lock class tells lockdep that GPIO irqs are in a different @@ -1671,7 +1674,9 @@ static void gpiochip_irq_relres(struct irq_data *d) static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) { - return irq_find_mapping(chip->irqdomain, offset); + if (!gpiochip_irqchip_irq_valid(chip, offset)) + return -ENXIO; + return irq_create_mapping(chip->irqdomain, offset); } /** @@ -1747,9 +1752,6 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, struct lock_class_key *lock_key) { struct device_node *of_node; - bool irq_base_set = false; - unsigned int offset; - unsigned irq_base = 0; if (!gpiochip || !irqchip) return -EINVAL; @@ -1806,25 +1808,6 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, irqchip->irq_release_resources = gpiochip_irq_relres; } - /* - * Prepare the mapping since the irqchip shall be orthogonal to - * any gpiochip calls. If the first_irq was zero, this is - * necessary to allocate descriptors for all IRQs. - */ - for (offset = 0; offset < gpiochip->ngpio; offset++) { - if (!gpiochip_irqchip_irq_valid(gpiochip, offset)) - continue; - irq_base = irq_create_mapping(gpiochip->irqdomain, offset); - if (!irq_base_set) { - /* - * Store the base into the gpiochip to be used when - * unmapping the irqs. - */ - gpiochip->irq_base = irq_base; - irq_base_set = true; - } - } - acpi_gpiochip_request_interrupts(gpiochip); return 0; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index af20369..a3e2e3e 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -165,7 +165,6 @@ struct gpio_chip { */ struct irq_chip *irqchip; struct irq_domain *irqdomain; - unsigned int irq_base; irq_flow_handler_t irq_handler; unsigned int irq_default_type; unsigned int irq_chained_parent; -- 2.10.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RFC/RFT PATCH 3/3] gpiolib: make gpio irqchip compatible with sparse_irq 2017-07-08 22:44 ` [RFC/RFT PATCH 3/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko @ 2017-08-01 7:46 ` Linus Walleij 0 siblings, 0 replies; 8+ messages in thread From: Linus Walleij @ 2017-08-01 7:46 UTC (permalink / raw) To: Grygorii Strashko Cc: Robert Jarzmik, Thierry Reding, Jonathan Hunter, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Jerome Brunet On Sun, Jul 9, 2017 at 12:44 AM, Grygorii Strashko <grygorii.strashko@ti.com> wrote: > Now IRQ mappings are always created for all (allowed) GPIOs in gpio irqchip in > gpiochip_irqchip_add_key() which goes against the idea of SPARSE_IRQ and, > as result, leads to: > - increasing of memory consumption because of allocated IRQ descriptors most > of which will never ever be used (especially on platform with a > high number of GPIOs) > - imposibility to use GPIO irqchip APIs by gpio drivers when HW implements > GPIO IRQ functionality as IRQ crossbar/multiplexer which has only limited > number of IRQ outputs (example from [1], all GPIOs can be mapped on only 8 > IRQs). > > Hence, remove static IRQ mapping code from gpiochip_irqchip_add_key() and > instead replace irq_find_mapping() with irq_create_mapping() in > gpiochip_to_irq(). Also add additional gpiochip_irqchip_irq_valid() calls > in gpiochip_to_irq() and gpiochip_irq_map(). > > After this change gpio2irq mapping will happen the following way when GPIO > irqchip APIs are used by gpio driver: > - IRQ mappings will be created statically if driver passes first_irq>0 > vlaue in gpiochip_irqchip_add_key(). > - IRQ mappings will be created dynamically from gpio_to_irq() or > of_irq_get(). > > [1] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1435847.html > Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> This is obviously better and what I should have done from the beginning had I only been smart enough, so what better to do than to throw this in now for -next and see what happens :) Patch applied. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-08-01 18:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-08 22:44 [RFC/RFT PATCH 0/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko
2017-07-08 22:44 ` [RFC/RFT PATCH 1/3] gpio: tegra: remove gpio_to_irq() from hw irq handlers Grygorii Strashko
2017-08-01 7:49 ` Linus Walleij
2017-07-08 22:44 ` [RFC/RFT PATCH 2/3] gpio: pxa: " Grygorii Strashko
[not found] ` <20170708224413.18281-3-grygorii.strashko-l0cyMroinI0@public.gmane.org>
2017-08-01 7:47 ` Linus Walleij
[not found] ` <CACRpkdZMgd7hSc6LwO5MbPb3vetd+qZ_5mXB1P9SM-HR+h_Pqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-08-01 18:41 ` Robert Jarzmik
2017-07-08 22:44 ` [RFC/RFT PATCH 3/3] gpiolib: make gpio irqchip compatible with sparse_irq Grygorii Strashko
2017-08-01 7:46 ` Linus Walleij
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).