Commit dc749a09 authored by Grygorii Strashko's avatar Grygorii Strashko Committed by Linus Walleij

gpiolib: allow gpio irqchip to map irqs dynamically

Now IRQ mappings are always created for all (allowed) GPIOs in gpiochip in
gpiochip_irqchip_add_key() which goes against the idea of SPARSE_IRQ and,
as result, leads to:
 - increasing of memory consumption for IRQ descriptors most of which will
never ever be used (espessially on platform with a high number of GPIOs).
(sizeof(struct irq_desc) == 256 on my tested platforms)
 - imposibility to use GPIO irqchip APIs by gpio drivers when HW implements
GPIO IRQ functionality as IRQ crossbar/router 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
  Mem savings 267*256 = 68352 (66kB)
- am335x-evm: number of created irq mappings decreased from 188 -> 63
  Mem savings 125*256 = 32000 (31kB)

[1] https://lkml.org/lkml/2017/6/15/428Signed-off-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 108d23e3
...@@ -1615,6 +1615,9 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, ...@@ -1615,6 +1615,9 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
{ {
struct gpio_chip *chip = d->host_data; struct gpio_chip *chip = d->host_data;
if (!gpiochip_irqchip_irq_valid(chip, hwirq))
return -ENXIO;
irq_set_chip_data(irq, chip); irq_set_chip_data(irq, chip);
/* /*
* This lock class tells lockdep that GPIO irqs are in a different * This lock class tells lockdep that GPIO irqs are in a different
...@@ -1681,7 +1684,9 @@ static void gpiochip_irq_relres(struct irq_data *d) ...@@ -1681,7 +1684,9 @@ static void gpiochip_irq_relres(struct irq_data *d)
static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) 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);
} }
/** /**
...@@ -1757,9 +1762,6 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, ...@@ -1757,9 +1762,6 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
struct lock_class_key *lock_key) struct lock_class_key *lock_key)
{ {
struct device_node *of_node; struct device_node *of_node;
bool irq_base_set = false;
unsigned int offset;
unsigned irq_base = 0;
if (!gpiochip || !irqchip) if (!gpiochip || !irqchip)
return -EINVAL; return -EINVAL;
...@@ -1816,25 +1818,6 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, ...@@ -1816,25 +1818,6 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
irqchip->irq_release_resources = gpiochip_irq_relres; 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); acpi_gpiochip_request_interrupts(gpiochip);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment