public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 7/7] gpio/tegra: convert to use linear irqdomain
@ 2012-10-16 19:23 Linus Walleij
  2012-10-16 22:33 ` Stephen Warren
  2012-10-18  6:29 ` Shawn Guo
  0 siblings, 2 replies; 5+ messages in thread
From: Linus Walleij @ 2012-10-16 19:23 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rob Herring, Grant Likely, Linus Walleij, Stephen Warren

The MXS driver tries to do the work of irq_domain_add_linear()
by reserving a bunch of descriptors somewhere and keeping track
of the base offset, then calling irq_domain_add_legacy(). Let's
stop doing that and simply use the linear IRQ domain.

Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpio-tegra.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index d982593..0234162 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -380,7 +380,6 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match;
 	struct tegra_gpio_soc_config *config;
-	int irq_base;
 	struct resource *res;
 	struct tegra_gpio_bank *bank;
 	int gpio;
@@ -417,14 +416,11 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	irq_base = irq_alloc_descs(-1, 0, tegra_gpio_chip.ngpio, 0);
-	if (irq_base < 0) {
-		dev_err(&pdev->dev, "Couldn't allocate IRQ numbers\n");
-		return -ENODEV;
-	}
-	irq_domain = irq_domain_add_legacy(pdev->dev.of_node,
-					   tegra_gpio_chip.ngpio, irq_base, 0,
+	irq_domain = irq_domain_add_linear(pdev->dev.of_node,
+					   tegra_gpio_chip.ngpio,
 					   &irq_domain_simple_ops, NULL);
+	if (!irq_domain)
+		return -ENODEV;
 
 	for (i = 0; i < tegra_gpio_bank_count; i++) {
 		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 7/7] gpio/tegra: convert to use linear irqdomain
  2012-10-16 19:23 [PATCH 7/7] gpio/tegra: convert to use linear irqdomain Linus Walleij
@ 2012-10-16 22:33 ` Stephen Warren
  2012-10-17 18:32   ` Stephen Warren
  2012-10-18  6:29 ` Shawn Guo
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2012-10-16 22:33 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-kernel, Rob Herring, Grant Likely, Stephen Warren

On 10/16/2012 01:23 PM, Linus Walleij wrote:
> The MXS driver tries to do the work of irq_domain_add_linear()
> by reserving a bunch of descriptors somewhere and keeping track
> of the base offset, then calling irq_domain_add_legacy(). Let's
> stop doing that and simply use the linear IRQ domain.

This /looks/ fine, but appears to break users of GPIOs from this module,
and causes a backtrace when cat /sys/kernel/debug/gpio:

> root@localhost:/sys/kernel/debug# cat gpio
> [   79.141308] Unable to handle kernel paging request at virtual address 5a5a5aaa
> [   79.148701] pgd = eea70000
> [   79.151401] [5a5a5aaa] *pgd=00000000
> [   79.154979] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
> [   79.160277] Modules linked in:
> [   79.163329] CPU: 1    Not tainted  (3.7.0-rc1-next-20121016-00016-g0f3bc78 #17)
> [   79.170639] PC is at gpiolib_seq_show+0x3c/0x1b0
> [   79.175245] LR is at gpiolib_seq_show+0x30/0x1b0
> [   79.179851] pc : [<c01fde7c>]    lr : [<c01fde70>]    psr: 20000013
> [   79.179851] sp : ee54fee0  ip : 00000039  fp : 00008000
> [   79.191303] r10: 000002e9  r9 : ee8140dc  r8 : ee54ff28
> [   79.196513] r7 : ee8a9c40  r6 : ee8140dc  r5 : ee54ff80  r4 : ee8a9c40
> [   79.203024] r3 : 5a5a5a5a  r2 : ee40e2e9  r1 : 00001000  r0 : 00000000
> [   79.209535] Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
> [   79.216653] Control: 10c5387d  Table: aea7004a  DAC: 00000015
> [   79.222383] Process cat (pid: 417, stack limit = 0xee54e238)
> [   79.228029] Stack: (0xee54fee0 to 0xee550000)
> [   79.232376] fee0: 5a5ab4b3 c05ca22c c00e6ac4 ee8a9c40 ee54ff80 ee48aef0 00000000 ee54ff28
> [   79.240536] ff00: ee8140dc 000002e9 00008000 c00e6b34 00000000 00019000 ee8a9c68 00000000
> [   79.248696] ff20: 00000000 00000000 00000001 00000000 00000000 00000000 00000000 ee48aef0
> [   79.256857] ff40: 00008000 00019000 ee54ff80 ee54ff80 00008000 00019000 00000000 c00c8b10
> [   79.265017] ff60: 00000000 00000000 00000000 00000000 ee48aef0 00000000 ee54ff80 c00c8be8
> [   79.273176] ff80: 00000000 00000000 00008000 00019000 00000003 00000003 c000f044 ee54e000
> [   79.281338] ffa0: 00000000 c000eec0 00008000 00019000 00000003 00019000 00008000 00019000
> [   79.289497] ffc0: 00008000 00019000 00000003 00000003 00000000 00000000 b6fe5000 00000000
> [   79.297658] ffe0: 00000000 beb645b4 0000b40d b6f621cc 40000010 00000003 00000000 00000000
> [   79.305845] [<c01fde7c>] (gpiolib_seq_show+0x3c/0x1b0) from [<c00e6b34>] (seq_read+0x32c/0x4a0)
> [   79.314533] [<c00e6b34>] (seq_read+0x32c/0x4a0) from [<c00c8b10>] (vfs_read+0xb0/0x144)
> [   79.322523] [<c00c8b10>] (vfs_read+0xb0/0x144) from [<c00c8be8>] (sys_read+0x44/0x70)
> [   79.330352] [<c00c8be8>] (sys_read+0x44/0x70) from [<c000eec0>] (ret_fast_syscall+0x0/0x30)
> [   79.338688] Code: ebfba211 e5963004 e3530000 0a00000a (e5932050) 
> [   79.344790] ---[ end trace 6fb7238d59ff2ea0 ]---

Do you have any quick ideas? If not, I'll go investigate.

I wonder if this has anything to do with drivers/pinctrl/pinctrl-tegra.c
hard-coding the GPIO base in tegra_pinctrl_gpio_range.

I've had fixing those in my mental TODO list for a while, but you got
around to it first!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 7/7] gpio/tegra: convert to use linear irqdomain
  2012-10-16 22:33 ` Stephen Warren
@ 2012-10-17 18:32   ` Stephen Warren
  2012-10-19 10:17     ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2012-10-17 18:32 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-kernel, Rob Herring, Grant Likely, Stephen Warren

On 10/16/2012 04:33 PM, Stephen Warren wrote:
> On 10/16/2012 01:23 PM, Linus Walleij wrote:
>> The MXS driver tries to do the work of irq_domain_add_linear()
>> by reserving a bunch of descriptors somewhere and keeping track
>> of the base offset, then calling irq_domain_add_legacy(). Let's
>> stop doing that and simply use the linear IRQ domain.
> 
> This /looks/ fine, but appears to break users of GPIOs from this module,
> and causes a backtrace when cat /sys/kernel/debug/gpio:
...

The following additional diff makes it work:

> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 0234162..c7c175a 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -460,7 +460,7 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
>         gpiochip_add(&tegra_gpio_chip);
>  
>         for (gpio = 0; gpio < tegra_gpio_chip.ngpio; gpio++) {
> -               int irq = irq_find_mapping(irq_domain, gpio);
> +               int irq = irq_create_mapping(irq_domain, gpio);
>                 /* No validity check; all Tegra GPIOs are valid IRQs */
>  
>                 bank = &tegra_gpio_banks[GPIO_BANK(gpio)];

I wonder if perhaps the entirety of that loop and perhaps the one after
it should be in the IRQ domain's map op - is that how all this is
intended to work?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 7/7] gpio/tegra: convert to use linear irqdomain
  2012-10-16 19:23 [PATCH 7/7] gpio/tegra: convert to use linear irqdomain Linus Walleij
  2012-10-16 22:33 ` Stephen Warren
@ 2012-10-18  6:29 ` Shawn Guo
  1 sibling, 0 replies; 5+ messages in thread
From: Shawn Guo @ 2012-10-18  6:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-kernel, Rob Herring, Grant Likely, Stephen Warren

On Tue, Oct 16, 2012 at 09:23:33PM +0200, Linus Walleij wrote:
> The MXS driver tries to do the work of irq_domain_add_linear()

s/MXS/tegra

> by reserving a bunch of descriptors somewhere and keeping track
> of the base offset, then calling irq_domain_add_legacy(). Let's
> stop doing that and simply use the linear IRQ domain.
> 
> Cc: Rob Herring <rob.herring@calxeda.com>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Cc: Stephen Warren <swarren@nvidia.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/gpio/gpio-tegra.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 7/7] gpio/tegra: convert to use linear irqdomain
  2012-10-17 18:32   ` Stephen Warren
@ 2012-10-19 10:17     ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2012-10-19 10:17 UTC (permalink / raw)
  To: Stephen Warren, Rob Herring, Grant Likely; +Cc: linux-kernel, Stephen Warren

On Wed, Oct 17, 2012 at 8:32 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> On 10/16/2012 04:33 PM, Stephen Warren wrote:
>> On 10/16/2012 01:23 PM, Linus Walleij wrote:
>>> The MXS driver tries to do the work of irq_domain_add_linear()
>>> by reserving a bunch of descriptors somewhere and keeping track
>>> of the base offset, then calling irq_domain_add_legacy(). Let's
>>> stop doing that and simply use the linear IRQ domain.
>>
>> This /looks/ fine, but appears to break users of GPIOs from this module,
>> and causes a backtrace when cat /sys/kernel/debug/gpio:
> ...
>
> The following additional diff makes it work:
>
>> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
>> index 0234162..c7c175a 100644
>> --- a/drivers/gpio/gpio-tegra.c
>> +++ b/drivers/gpio/gpio-tegra.c
>> @@ -460,7 +460,7 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
>>         gpiochip_add(&tegra_gpio_chip);
>>
>>         for (gpio = 0; gpio < tegra_gpio_chip.ngpio; gpio++) {
>> -               int irq = irq_find_mapping(irq_domain, gpio);
>> +               int irq = irq_create_mapping(irq_domain, gpio);
>>                 /* No validity check; all Tegra GPIOs are valid IRQs */
>>
>>                 bank = &tegra_gpio_banks[GPIO_BANK(gpio)];
>
> I wonder if perhaps the entirety of that loop and perhaps the one after
> it should be in the IRQ domain's map op - is that how all this is
> intended to work?

I've been asking the same kind of question...

Basically as far as I understand:

- If you use a linear IRQ domain you need to call irq_create_mapping()
 atleast once, and at that point the IRQ descriptor will be dynamically
 allocated. On subsequent calls, irq_find_mapping() can be used.

- If using legacy IRQ domains, descriptors are supposed to be
 allocated elsewhere, and you can just use irq_find_mapping(),
 but irq_create_mapping() does not hurt, because that call will
 check if a descriptor is already available.

- With the simple domain (as augmented by myself) the mappins
  will be dynamically created if the passed IRQ base is <= 0
  else it falls through to creating a linear domain, so in this case
  to be certain irq_create_mapping() should also be called at
  least once.

I'm not overly happy with these semantics :-(

Basically irq_find_mapping() may be a fragile and dangerous
optimization path.

I've folded the above into my patch.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-19 10:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-16 19:23 [PATCH 7/7] gpio/tegra: convert to use linear irqdomain Linus Walleij
2012-10-16 22:33 ` Stephen Warren
2012-10-17 18:32   ` Stephen Warren
2012-10-19 10:17     ` Linus Walleij
2012-10-18  6:29 ` Shawn Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox