diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2002-08-27 21:06:48 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2002-08-27 21:06:48 +0000 |
commit | 22e09a3fb8e669145e5bfb519e3b6bdffe438031 (patch) | |
tree | 4c4e2f94c49fb7af4ba16481edee5522078b0436 /firmware | |
parent | d4d71d1698ed15cff1141b1dcb211f0519d9c9cb (diff) | |
download | rockbox-22e09a3fb8e669145e5bfb519e3b6bdffe438031.tar.gz rockbox-22e09a3fb8e669145e5bfb519e3b6bdffe438031.zip |
Fixed some nasty mutex glitches
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2012 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/ata.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index ec0fe3567c..e843c263aa 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -100,6 +100,8 @@ static long last_disk_activity = -1; | |||
100 | static int ata_power_on(void); | 100 | static int ata_power_on(void); |
101 | #endif | 101 | #endif |
102 | 102 | ||
103 | static int perform_soft_reset(void); | ||
104 | |||
103 | static int wait_for_bsy(void) __attribute__ ((section (".icode"))); | 105 | static int wait_for_bsy(void) __attribute__ ((section (".icode"))); |
104 | static int wait_for_bsy(void) | 106 | static int wait_for_bsy(void) |
105 | { | 107 | { |
@@ -152,21 +154,25 @@ int ata_read_sectors(unsigned long start, | |||
152 | int ret = 0; | 154 | int ret = 0; |
153 | 155 | ||
154 | last_disk_activity = current_tick; | 156 | last_disk_activity = current_tick; |
157 | |||
158 | mutex_lock(&ata_mtx); | ||
159 | |||
155 | #ifndef USE_STANDBY | 160 | #ifndef USE_STANDBY |
156 | if ( sleeping ) { | 161 | if ( sleeping ) { |
157 | #ifdef USE_POWEROFF | 162 | #ifdef USE_POWEROFF |
158 | if (ata_power_on()) { | 163 | if (ata_power_on()) { |
164 | mutex_unlock(&ata_mtx); | ||
159 | return -1; | 165 | return -1; |
160 | } | 166 | } |
161 | #else | 167 | #else |
162 | if (ata_soft_reset()) { | 168 | if (perform_soft_reset()) { |
169 | mutex_unlock(&ata_mtx); | ||
163 | return -1; | 170 | return -1; |
164 | } | 171 | } |
165 | #endif | 172 | #endif |
166 | sleeping = false; | 173 | sleeping = false; |
167 | } | 174 | } |
168 | #endif | 175 | #endif |
169 | mutex_lock(&ata_mtx); | ||
170 | 176 | ||
171 | if (!wait_for_rdy()) | 177 | if (!wait_for_rdy()) |
172 | { | 178 | { |
@@ -239,21 +245,24 @@ int ata_write_sectors(unsigned long start, | |||
239 | 245 | ||
240 | last_disk_activity = current_tick; | 246 | last_disk_activity = current_tick; |
241 | 247 | ||
248 | mutex_lock(&ata_mtx); | ||
249 | |||
242 | #ifndef USE_STANDBY | 250 | #ifndef USE_STANDBY |
243 | if ( sleeping ) { | 251 | if ( sleeping ) { |
244 | #ifdef USE_POWEROFF | 252 | #ifdef USE_POWEROFF |
245 | if (ata_power_on()) { | 253 | if (ata_power_on()) { |
254 | mutex_unlock(&ata_mtx); | ||
246 | return -1; | 255 | return -1; |
247 | } | 256 | } |
248 | #else | 257 | #else |
249 | if (ata_soft_reset()) { | 258 | if (perform_soft_reset()) { |
259 | mutex_unlock(&ata_mtx); | ||
250 | return -1; | 260 | return -1; |
251 | } | 261 | } |
252 | #endif | 262 | #endif |
253 | sleeping = false; | 263 | sleeping = false; |
254 | } | 264 | } |
255 | #endif | 265 | #endif |
256 | mutex_lock(&ata_mtx); | ||
257 | 266 | ||
258 | if (!wait_for_rdy()) | 267 | if (!wait_for_rdy()) |
259 | { | 268 | { |
@@ -370,7 +379,7 @@ static int ata_perform_sleep(void) | |||
370 | int ret = 0; | 379 | int ret = 0; |
371 | 380 | ||
372 | mutex_lock(&ata_mtx); | 381 | mutex_lock(&ata_mtx); |
373 | 382 | ||
374 | if(!wait_for_rdy()) { | 383 | if(!wait_for_rdy()) { |
375 | mutex_unlock(&ata_mtx); | 384 | mutex_unlock(&ata_mtx); |
376 | return -1; | 385 | return -1; |
@@ -460,13 +469,11 @@ int ata_hard_reset(void) | |||
460 | return ret; | 469 | return ret; |
461 | } | 470 | } |
462 | 471 | ||
463 | int ata_soft_reset(void) | 472 | static int perform_soft_reset(void) |
464 | { | 473 | { |
465 | int ret; | 474 | int ret; |
466 | int retry_count; | 475 | int retry_count; |
467 | 476 | ||
468 | mutex_lock(&ata_mtx); | ||
469 | |||
470 | ATA_SELECT = SELECT_LBA | ata_device; | 477 | ATA_SELECT = SELECT_LBA | ata_device; |
471 | ATA_CONTROL = CONTROL_nIEN|CONTROL_SRST; | 478 | ATA_CONTROL = CONTROL_nIEN|CONTROL_SRST; |
472 | sleep(HZ/20000); /* >= 5us */ | 479 | sleep(HZ/20000); /* >= 5us */ |
@@ -489,14 +496,24 @@ int ata_soft_reset(void) | |||
489 | return ret; | 496 | return ret; |
490 | } | 497 | } |
491 | 498 | ||
499 | int ata_soft_reset(void) | ||
500 | { | ||
501 | int ret; | ||
502 | |||
503 | mutex_lock(&ata_mtx); | ||
504 | |||
505 | ret = perform_soft_reset(); | ||
506 | |||
507 | mutex_unlock(&ata_mtx); | ||
508 | return ret; | ||
509 | } | ||
510 | |||
492 | #ifdef USE_POWEROFF | 511 | #ifdef USE_POWEROFF |
493 | static int ata_power_on(void) | 512 | static int ata_power_on(void) |
494 | { | 513 | { |
495 | int ret; | 514 | int ret; |
496 | int retry_count; | 515 | int retry_count; |
497 | 516 | ||
498 | mutex_lock(&ata_mtx); | ||
499 | |||
500 | ide_power_enable(true); | 517 | ide_power_enable(true); |
501 | sleep(HZ/2); | 518 | sleep(HZ/2); |
502 | 519 | ||
@@ -513,7 +530,6 @@ static int ata_power_on(void) | |||
513 | ret = ret?0:-1; | 530 | ret = ret?0:-1; |
514 | 531 | ||
515 | sleeping = false; | 532 | sleeping = false; |
516 | mutex_unlock(&ata_mtx); | ||
517 | return ret; | 533 | return ret; |
518 | } | 534 | } |
519 | #endif | 535 | #endif |