Skip to contentSkip to conversation

AT32AP700X PS/2 controller (PSIF): remove msleep call from atomic context

PATCH In review Marjan Fojkar 3 participants 5 messages Dec 13, 2009 – Dec 19, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 AT32AP700X PS/2 controller (PSIF): remove msleep call from atomic context

From: Marjan Fojkar <[email protected]>

The patch removes msleep call from atomic context. To achieve that, the driver PSIF leaves atomic context before the call in order to enable interrupts to be performed safely. When the call is done, the driver jumps back to atomic context.

The boot logs caused by the call from atomic context inside the driver. atkbd.c: keyboard reset failed on at32psif/serio1

BUG: scheduling while atomic: kseriod/69/0x00000002                            
Modules linked in:                                                             
Call trace:                                                                    
 [<90019128>] __schedule_bug+0x40/0x4c                                         
 [<9019afa6>] __sched_text_start+0x5e/0x220                                    
 [<9019b5a8>] schedule_timeout+0x5c/0x84                                       
 [<90022d84>] process_timeout+0x0/0x8                                          
 [<9019b5e0>] schedule_timeout_uninterruptible+0x10/0x14                       
 [<90023280>] msleep+0x10/0x1c                                                 
 [<90108688>] psif_write+0x20/0x6c                                             
 [<90108868>] ps2_sendbyte+0x44/0xd8                                           
 [<90029d8c>] autoremove_wake_function+0x0/0x1c                                
 [<90108a52>] ps2_command+0xaa/0x2a8                                           
 [<90013e8a>] clk_enable+0x16/0x38                                             
 [<9001d194>] printk+0xc/0x10                                                  
 [<9010b872>] atkbd_probe+0x3a/0xac                                            
 [<9010bb46>] atkbd_connect+0xca/0x188                                         
 [<901077a4>] serio_connect_driver+0x18/0x24                                   
 [<901077bc>] serio_driver_probe+0xc/0x10                                      
 [<900f7f02>] driver_probe_device+0x82/0xf0                                    
 [<900f7f9c>] __driver_attach+0x2c/0x44                                        
 [<900f7946>] bus_for_each_dev+0x2a/0x48                                       
 [<900f7f70>] __driver_attach+0x0/0x44                                         
 [<900f7df0>] driver_attach+0x10/0x14                                          
 [<90108024>] serio_thread+0x180/0x2e4                                         
 [<90029d8c>] autoremove_wake_function+0x0/0x1c                                
 [<90029b3e>] kthread+0x2a/0x44                                                
 [<90107ea4>] serio_thread+0x0/0x2e4                                           
 [<9001ed3c>] do_exit+0x0/0x52e                                                
 [<90029b14>] kthread+0x0/0x44                                                 
 [<9001ed3c>] do_exit+0x0/0x52e

---

drivers/input/serio/at32psif.c renamed from drivers/input/serio/at32psif.c.orig +6 -3
diff -up linux-2.6.32/drivers/input/serio/at32psif.c{.orig,}
@@ -135,9 +135,12 @@ static int psif_write(struct serio *io, 
 	int retval = 0;
 
 	spin_lock_irqsave(&psif->lock, flags);
-
-	while (!(psif_readl(psif, SR) & PSIF_BIT(TXEMPTY)) && timeout--)
-		msleep(10);
+	while (!(psif_readl(psif, SR) & PSIF_BIT(TXEMPTY)) && timeout) {
+		spin_unlock_irqrestore(&psif->lock, flags);
+		while (!(psif_readl(psif, SR) & PSIF_BIT(TXEMPTY)) && timeout--)
+			msleep(10);
+		spin_lock_irqsave(&psif->lock, flags);
+	}
 
 	if (timeout >= 0) {
 		psif_writel(psif, THR, val);
maintainer
#1 lore raw

Hi Martin,

Quoted 6 lines · Marjan Fojkar

From: Marjan Fojkar <[email protected]>

The patch removes msleep call from atomic context. To achieve that, the driver PSIF leaves atomic context before the call in order to enable interrupts to be performed safely. When the call is done, the driver jumps back to atomic context.

Yes, msleep is not allowed in atomic context, however serio's write() method is supposed to be callable from atomic context so msleep is not available there period. I scanned the datasheet quickly and did not see any restriction on the frequency of reading status register so I think we should do what i8042 driver does - udelay(50).

Hans-Christian?

Signature · 1 line
Dmitry
#2 lore raw
Quoted 10 lines · On Sun, 13 Dec 2009 20:49:37 -0800 Dmitry Torokhov <[email protected]>…

Hi Martin,

Quoted 6 lines · Marjan Fojkar

From: Marjan Fojkar <[email protected]>

The patch removes msleep call from atomic context. To achieve that, the driver PSIF leaves atomic context before the call in order to enable interrupts to be performed safely. When the call is done, the driver jumps back to atomic context.

Quoted 6 lines

Yes, msleep is not allowed in atomic context, however serio's write() method is supposed to be callable from atomic context so msleep is not available there period. I scanned the datasheet quickly and did not see any restriction on the frequency of reading status register so I think we should do what i8042 driver does - udelay(50).

Sure udelay(50) will work fine, you can poll the registers as fast as you would like. Only disadvantage with udelay is that it will block all other threads. But I would guess that most of the times a character should be sent to the peripheral, the hardware will be ready since the speed is quite low bandwidth.

Signature · 2 lines
Best regards,
Hans-Christian Egtvedt
#3 lore raw
Quoted 19 lines · Hans-Christian Egtvedt
Quoted 9 lines · On Sun, 13 Dec 2009 20:49:37 -0800 Dmitry Torokhov <[email protected]>…

Hi Martin,

Quoted 6 lines · Marjan Fojkar

From: Marjan Fojkar <[email protected]>

The patch removes msleep call from atomic context. To achieve that, the driver PSIF leaves atomic context before the call in order to enable interrupts to be performed safely. When the call is done, the driver jumps back to atomic context.

Quoted 6 lines

Yes, msleep is not allowed in atomic context, however serio's write() method is supposed to be callable from atomic context so msleep is not available there period. I scanned the datasheet quickly and did not see any restriction on the frequency of reading status register so I think we should do what i8042 driver does - udelay(50).

Quoted 6 lines

Sure udelay(50) will work fine, you can poll the registers as fast as you would like. Only disadvantage with udelay is that it will block all other threads. But I would guess that most of the times a character should be sent to the peripheral, the hardware will be ready since the speed is quite low bandwidth.

So, the final conclusion is udelay(50), I presume? :)

maintainer
#4 lore raw
Quoted 20 lines · Marjan Fojkar
Quoted 19 lines · Hans-Christian Egtvedt
Quoted 15 lines · On Sun, 13 Dec 2009 20:49:37 -0800 Dmitry Torokhov <[email protected]>…

Hi Martin,

Quoted 6 lines · Marjan Fojkar

From: Marjan Fojkar <[email protected]>

The patch removes msleep call from atomic context. To achieve that, the driver PSIF leaves atomic context before the call in order to enable interrupts to be performed safely. When the call is done, the driver jumps back to atomic context.

Yes, msleep is not allowed in atomic context, however serio's write() method is supposed to be callable from atomic context so msleep is not available there period. I scanned the datasheet quickly and did not see any restriction on the frequency of reading status register so I think we should do what i8042 driver does - udelay(50).

Quoted 9 lines
Quoted 6 lines

Sure udelay(50) will work fine, you can poll the registers as fast as you would like. Only disadvantage with udelay is that it will block all other threads. But I would guess that most of the times a character should be sent to the peripheral, the hardware will be ready since the speed is quite low bandwidth.

So, the final conclusion is udelay(50), I presume? :)

Yep, it is upstream now.

Signature · 1 line
Dmitry