linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: bcm63xx: move bcm63xx_gpio_init() to bcm63xx_register_devices().
@ 2015-03-12 16:00 Nicolas Schichan
  2015-03-16 14:53 ` Maxime Bizon
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Schichan @ 2015-03-12 16:00 UTC (permalink / raw)
  To: Ralf Baechle, Nicolas Schichan, linux-mips, linux-kernel,
	Alexandre Courbot

When called from prom init code, bcm63xx_gpio_init() will fail as it
will call gpiochip_add() which relies on a working kmalloc() to alloc
the gpio_desc array and kmalloc is not useable yet at prom init time.

Move bcm63xx_gpio_init() to bcm63xx_register_devices() (an
arch_initcall) where kmalloc works.

Fixes: 14e85c0e69d5 ("gpio: remove gpio_descs global array")

Signed-off-by: Nicolas Schichan <nschichan@freebox.fr>
---
 arch/mips/bcm63xx/prom.c  | 4 ----
 arch/mips/bcm63xx/setup.c | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/mips/bcm63xx/prom.c b/arch/mips/bcm63xx/prom.c
index e1f27d6..7019e29 100644
--- a/arch/mips/bcm63xx/prom.c
+++ b/arch/mips/bcm63xx/prom.c
@@ -17,7 +17,6 @@
 #include <bcm63xx_cpu.h>
 #include <bcm63xx_io.h>
 #include <bcm63xx_regs.h>
-#include <bcm63xx_gpio.h>
 
 void __init prom_init(void)
 {
@@ -53,9 +52,6 @@ void __init prom_init(void)
 	reg &= ~mask;
 	bcm_perf_writel(reg, PERF_CKCTL_REG);
 
-	/* register gpiochip */
-	bcm63xx_gpio_init();
-
 	/* do low level board init */
 	board_prom_init();
 
diff --git a/arch/mips/bcm63xx/setup.c b/arch/mips/bcm63xx/setup.c
index 6660c7d..240fb4f 100644
--- a/arch/mips/bcm63xx/setup.c
+++ b/arch/mips/bcm63xx/setup.c
@@ -20,6 +20,7 @@
 #include <bcm63xx_cpu.h>
 #include <bcm63xx_regs.h>
 #include <bcm63xx_io.h>
+#include <bcm63xx_gpio.h>
 
 void bcm63xx_machine_halt(void)
 {
@@ -160,6 +161,9 @@ void __init plat_mem_setup(void)
 
 int __init bcm63xx_register_devices(void)
 {
+	/* register gpiochip */
+	bcm63xx_gpio_init();
+
 	return board_register_devices();
 }
 
-- 
1.9.1


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

* Re: [PATCH] MIPS: bcm63xx: move bcm63xx_gpio_init() to bcm63xx_register_devices().
  2015-03-12 16:00 [PATCH] MIPS: bcm63xx: move bcm63xx_gpio_init() to bcm63xx_register_devices() Nicolas Schichan
@ 2015-03-16 14:53 ` Maxime Bizon
  2015-03-16 15:54   ` Jonas Gorski
  0 siblings, 1 reply; 4+ messages in thread
From: Maxime Bizon @ 2015-03-16 14:53 UTC (permalink / raw)
  To: Nicolas Schichan
  Cc: Ralf Baechle, linux-mips, linux-kernel, Alexandre Courbot


On Thu, 2015-03-12 at 17:00 +0100, Nicolas Schichan wrote:

> When called from prom init code, bcm63xx_gpio_init() will fail as it
> will call gpiochip_add() which relies on a working kmalloc() to alloc
> the gpio_desc array and kmalloc is not useable yet at prom init time.
> 
> Move bcm63xx_gpio_init() to bcm63xx_register_devices() (an
> arch_initcall) where kmalloc works.

no that patch is completely bogus:

1) bcm63xx_gpio_init() does more than registering the gpio_chip: look at
bcm63xx_gpio_out_low_reg_init().

We want at least the low lever helpers bcm_gpio_readl()/writel() to work
early.

2) look at board_register_devices() in board_bcm963xx.c, it uses the
gpio API, but is called during arch_initcall() (there was an attempt to
move it later, but it has been reverted)

so you cannot move that gpiochip registration later as-is, more
refactoring and *testing* is required.

-- 
Maxime



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

* Re: [PATCH] MIPS: bcm63xx: move bcm63xx_gpio_init() to bcm63xx_register_devices().
  2015-03-16 14:53 ` Maxime Bizon
@ 2015-03-16 15:54   ` Jonas Gorski
  2015-03-17  1:33     ` Maxime Bizon
  0 siblings, 1 reply; 4+ messages in thread
From: Jonas Gorski @ 2015-03-16 15:54 UTC (permalink / raw)
  To: Maxime Bizon
  Cc: Nicolas Schichan, Ralf Baechle, MIPS Mailing List, linux-kernel,
	Alexandre Courbot

On Mon, Mar 16, 2015 at 3:53 PM, Maxime Bizon <mbizon@freebox.fr> wrote:
>
> On Thu, 2015-03-12 at 17:00 +0100, Nicolas Schichan wrote:
>
>> When called from prom init code, bcm63xx_gpio_init() will fail as it
>> will call gpiochip_add() which relies on a working kmalloc() to alloc
>> the gpio_desc array and kmalloc is not useable yet at prom init time.
>>
>> Move bcm63xx_gpio_init() to bcm63xx_register_devices() (an
>> arch_initcall) where kmalloc works.
>
> no that patch is completely bogus:
>
> 1) bcm63xx_gpio_init() does more than registering the gpio_chip: look at
> bcm63xx_gpio_out_low_reg_init().
>
> We want at least the low lever helpers bcm_gpio_readl()/writel() to work
> early.

bcm_gpio_readl/bcm_gpio_writel() are completely unaffected by anything
done by bcm63xx_gpio_out_low_reg_init(), all they do is access the
gpio register space.

And all of the functions using the gpio_out_low_reg are static and
only accessible through the registered gpio chip, so there can't be
any rouge accesses before the chip is registered.

> 2) look at board_register_devices() in board_bcm963xx.c, it uses the
> gpio API, but is called during arch_initcall() (there was an attempt to
> move it later, but it has been reverted)
>
> so you cannot move that gpiochip registration later as-is, more
> refactoring and *testing* is required.

The only access done in board_register_devices() is the ephy-reset
gpio, and that is still done *after* moving bcm63xx_gpio_init() to
register_devices().

So I don't see how this breaks anything. But for the sake of the
argument, let's give it a spin:

root@OpenWrt:/# uname -a
Linux OpenWrt 4.0.0-rc1+ #383 SMP Mon Mar 16 16:46:49 CET 2015 mips GNU/Linux
root@OpenWrt:/# cat /sys/kernel/debug/gpio
GPIOs 0-39, bcm63xx-gpio:
 gpio-4   (power               ) out hi
 gpio-5   (stop                ) out lo
 gpio-15  (adsl-fail           ) out hi
 gpio-22  (ppp                 ) out hi
 gpio-23  (ppp-fail            ) out hi
 gpio-36  (ephy-reset          ) out hi

Everything seems to work fine.


Jonas

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

* Re: [PATCH] MIPS: bcm63xx: move bcm63xx_gpio_init() to bcm63xx_register_devices().
  2015-03-16 15:54   ` Jonas Gorski
@ 2015-03-17  1:33     ` Maxime Bizon
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Bizon @ 2015-03-17  1:33 UTC (permalink / raw)
  To: Jonas Gorski
  Cc: Nicolas Schichan, Ralf Baechle, MIPS Mailing List, linux-kernel,
	Alexandre Courbot


On Monday 16 Mar 2015 à 16:54:54 (+0100), Jonas Gorski wrote:

> So I don't see how this breaks anything. But for the sake of the
> argument, let's give it a spin:

my mistake, you are right, I completely misread the patch.

-- 
Maxime

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

end of thread, other threads:[~2015-03-17  1:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 16:00 [PATCH] MIPS: bcm63xx: move bcm63xx_gpio_init() to bcm63xx_register_devices() Nicolas Schichan
2015-03-16 14:53 ` Maxime Bizon
2015-03-16 15:54   ` Jonas Gorski
2015-03-17  1:33     ` Maxime Bizon

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).