aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/amiflop.c
diff options
context:
space:
mode:
authorAndreas Bombe <aeb@debian.org>2008-12-09 20:02:19 -0500
committerGeert Uytterhoeven <geert@linux-m68k.org>2009-01-12 14:56:33 -0500
commit6d0be946e150ac17da7381b27fd40603ca40b58f (patch)
tree4795a77c5f43f44441aa7692e25a7ced6e73e0c1 /drivers/block/amiflop.c
parentdc8ee69c760317be0bb4eac2bd2fd81eb663627a (diff)
m68k: amiflop - Get rid of sleep_on calls
Apart from sleep_on() calls that could be easily converted to wait_event() and completion calls amiflop also used a flag in ms_delay() and ms_isr() as a custom mutex for ms_delay() without a need for explicit unlocking. I converted that to a standard mutex. The replacement for the unconditional sleep_on() in fd_motor_on() is a complete_all() together with a INIT_COMPLETION() before the mod_timer() call. It appears to me that fd_motor_on() might be called concurrently and fd_select() does not guarantee mutual exclusivity in the case the same drive gets selected again. Signed-off-by: Andreas Bombe <aeb@debian.org> Acked-by: Jörg Dorchain <joerg@dorchain.net> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Diffstat (limited to 'drivers/block/amiflop.c')
-rw-r--r--drivers/block/amiflop.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 4b1d4ac960f1..8df436ff7068 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -156,7 +156,7 @@ static volatile int fdc_busy = -1;
156static volatile int fdc_nested; 156static volatile int fdc_nested;
157static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); 157static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
158 158
159static DECLARE_WAIT_QUEUE_HEAD(motor_wait); 159static DECLARE_COMPLETION(motor_on_completion);
160 160
161static volatile int selected = -1; /* currently selected drive */ 161static volatile int selected = -1; /* currently selected drive */
162 162
@@ -184,8 +184,7 @@ static unsigned char mfmencode[16]={
184static unsigned char mfmdecode[128]; 184static unsigned char mfmdecode[128];
185 185
186/* floppy internal millisecond timer stuff */ 186/* floppy internal millisecond timer stuff */
187static volatile int ms_busy = -1; 187static DECLARE_COMPLETION(ms_wait_completion);
188static DECLARE_WAIT_QUEUE_HEAD(ms_wait);
189#define MS_TICKS ((amiga_eclock+50)/1000) 188#define MS_TICKS ((amiga_eclock+50)/1000)
190 189
191/* 190/*
@@ -211,8 +210,7 @@ static int fd_device[4] = { 0, 0, 0, 0 };
211 210
212static irqreturn_t ms_isr(int irq, void *dummy) 211static irqreturn_t ms_isr(int irq, void *dummy)
213{ 212{
214 ms_busy = -1; 213 complete(&ms_wait_completion);
215 wake_up(&ms_wait);
216 return IRQ_HANDLED; 214 return IRQ_HANDLED;
217} 215}
218 216
@@ -220,19 +218,17 @@ static irqreturn_t ms_isr(int irq, void *dummy)
220 A more generic routine would do a schedule a la timer.device */ 218 A more generic routine would do a schedule a la timer.device */
221static void ms_delay(int ms) 219static void ms_delay(int ms)
222{ 220{
223 unsigned long flags;
224 int ticks; 221 int ticks;
222 static DEFINE_MUTEX(mutex);
223
225 if (ms > 0) { 224 if (ms > 0) {
226 local_irq_save(flags); 225 mutex_lock(&mutex);
227 while (ms_busy == 0)
228 sleep_on(&ms_wait);
229 ms_busy = 0;
230 local_irq_restore(flags);
231 ticks = MS_TICKS*ms-1; 226 ticks = MS_TICKS*ms-1;
232 ciaa.tblo=ticks%256; 227 ciaa.tblo=ticks%256;
233 ciaa.tbhi=ticks/256; 228 ciaa.tbhi=ticks/256;
234 ciaa.crb=0x19; /*count eclock, force load, one-shoot, start */ 229 ciaa.crb=0x19; /*count eclock, force load, one-shoot, start */
235 sleep_on(&ms_wait); 230 wait_for_completion(&ms_wait_completion);
231 mutex_unlock(&mutex);
236 } 232 }
237} 233}
238 234
@@ -254,8 +250,7 @@ static void get_fdc(int drive)
254 printk("get_fdc: drive %d fdc_busy %d fdc_nested %d\n",drive,fdc_busy,fdc_nested); 250 printk("get_fdc: drive %d fdc_busy %d fdc_nested %d\n",drive,fdc_busy,fdc_nested);
255#endif 251#endif
256 local_irq_save(flags); 252 local_irq_save(flags);
257 while (!try_fdc(drive)) 253 wait_event(fdc_wait, try_fdc(drive));
258 sleep_on(&fdc_wait);
259 fdc_busy = drive; 254 fdc_busy = drive;
260 fdc_nested++; 255 fdc_nested++;
261 local_irq_restore(flags); 256 local_irq_restore(flags);
@@ -330,7 +325,7 @@ static void fd_deselect (int drive)
330static void motor_on_callback(unsigned long nr) 325static void motor_on_callback(unsigned long nr)
331{ 326{
332 if (!(ciaa.pra & DSKRDY) || --on_attempts == 0) { 327 if (!(ciaa.pra & DSKRDY) || --on_attempts == 0) {
333 wake_up (&motor_wait); 328 complete_all(&motor_on_completion);
334 } else { 329 } else {
335 motor_on_timer.expires = jiffies + HZ/10; 330 motor_on_timer.expires = jiffies + HZ/10;
336 add_timer(&motor_on_timer); 331 add_timer(&motor_on_timer);
@@ -347,11 +342,12 @@ static int fd_motor_on(int nr)
347 unit[nr].motor = 1; 342 unit[nr].motor = 1;
348 fd_select(nr); 343 fd_select(nr);
349 344
345 INIT_COMPLETION(motor_on_completion);
350 motor_on_timer.data = nr; 346 motor_on_timer.data = nr;
351 mod_timer(&motor_on_timer, jiffies + HZ/2); 347 mod_timer(&motor_on_timer, jiffies + HZ/2);
352 348
353 on_attempts = 10; 349 on_attempts = 10;
354 sleep_on (&motor_wait); 350 wait_for_completion(&motor_on_completion);
355 fd_deselect(nr); 351 fd_deselect(nr);
356 } 352 }
357 353
@@ -582,8 +578,7 @@ static void raw_read(int drive)
582{ 578{
583 drive&=3; 579 drive&=3;
584 get_fdc(drive); 580 get_fdc(drive);
585 while (block_flag) 581 wait_event(wait_fd_block, !block_flag);
586 sleep_on(&wait_fd_block);
587 fd_select(drive); 582 fd_select(drive);
588 /* setup adkcon bits correctly */ 583 /* setup adkcon bits correctly */
589 custom.adkcon = ADK_MSBSYNC; 584 custom.adkcon = ADK_MSBSYNC;
@@ -598,8 +593,7 @@ static void raw_read(int drive)
598 593
599 block_flag = 1; 594 block_flag = 1;
600 595
601 while (block_flag) 596 wait_event(wait_fd_block, !block_flag);
602 sleep_on (&wait_fd_block);
603 597
604 custom.dsklen = 0; 598 custom.dsklen = 0;
605 fd_deselect(drive); 599 fd_deselect(drive);
@@ -616,8 +610,7 @@ static int raw_write(int drive)
616 rel_fdc(); 610 rel_fdc();
617 return 0; 611 return 0;
618 } 612 }
619 while (block_flag) 613 wait_event(wait_fd_block, !block_flag);
620 sleep_on(&wait_fd_block);
621 fd_select(drive); 614 fd_select(drive);
622 /* clear adkcon bits */ 615 /* clear adkcon bits */
623 custom.adkcon = ADK_PRECOMP1|ADK_PRECOMP0|ADK_WORDSYNC|ADK_MSBSYNC; 616 custom.adkcon = ADK_PRECOMP1|ADK_PRECOMP0|ADK_WORDSYNC|ADK_MSBSYNC;
@@ -1294,8 +1287,7 @@ static int non_int_flush_track (unsigned long nr)
1294 writepending = 0; 1287 writepending = 0;
1295 return 0; 1288 return 0;
1296 } 1289 }
1297 while (block_flag == 2) 1290 wait_event(wait_fd_block, block_flag != 2);
1298 sleep_on (&wait_fd_block);
1299 } 1291 }
1300 else { 1292 else {
1301 local_irq_restore(flags); 1293 local_irq_restore(flags);