diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2008-01-18 13:12:33 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2008-01-18 13:12:33 +0000 |
commit | 6a8379674c43103c008f841968b84287b8fdaf89 (patch) | |
tree | 39003a711cfff5cdf5ad00a56c70ae34f34d5100 | |
parent | 3b36b98ff8dea187bd6c25174978da4f7b5e3231 (diff) | |
download | rockbox-6a8379674c43103c008f841968b84287b8fdaf89.tar.gz rockbox-6a8379674c43103c008f841968b84287b8fdaf89.zip |
Finally, out goes struct spinlock for anything but mutiprocessor targets where it becomes a reenterable corelock.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16105 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/drivers/ata.c | 60 | ||||
-rw-r--r-- | firmware/export/kernel.h | 15 | ||||
-rw-r--r-- | firmware/kernel.c | 45 | ||||
-rw-r--r-- | firmware/system.c | 2 | ||||
-rw-r--r-- | firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c | 8 | ||||
-rw-r--r-- | firmware/target/arm/sandisk/ata-c200_e200.c | 20 | ||||
-rw-r--r-- | firmware/target/arm/tms320dm320/spi-dm320.c | 8 | ||||
-rw-r--r-- | uisimulator/sdl/kernel.c | 48 |
8 files changed, 61 insertions, 145 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 1b917686c5..cacf4583ae 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -66,7 +66,7 @@ | |||
66 | #define ATA_POWER_OFF_TIMEOUT 2*HZ | 66 | #define ATA_POWER_OFF_TIMEOUT 2*HZ |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | static struct spinlock ata_spinlock NOCACHEBSS_ATTR; | 69 | static struct mutex ata_mtx NOCACHEBSS_ATTR; |
70 | int ata_device; /* device 0 (master) or 1 (slave) */ | 70 | int ata_device; /* device 0 (master) or 1 (slave) */ |
71 | 71 | ||
72 | int ata_spinup_time = 0; | 72 | int ata_spinup_time = 0; |
@@ -234,7 +234,7 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
234 | #ifdef HAVE_MULTIVOLUME | 234 | #ifdef HAVE_MULTIVOLUME |
235 | (void)drive; /* unused for now */ | 235 | (void)drive; /* unused for now */ |
236 | #endif | 236 | #endif |
237 | spinlock_lock(&ata_spinlock); | 237 | mutex_lock(&ata_mtx); |
238 | #endif | 238 | #endif |
239 | 239 | ||
240 | last_disk_activity = current_tick; | 240 | last_disk_activity = current_tick; |
@@ -246,14 +246,14 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
246 | spinup = true; | 246 | spinup = true; |
247 | if (poweroff) { | 247 | if (poweroff) { |
248 | if (ata_power_on()) { | 248 | if (ata_power_on()) { |
249 | spinlock_unlock(&ata_spinlock); | 249 | mutex_unlock(&ata_mtx); |
250 | ata_led(false); | 250 | ata_led(false); |
251 | return -1; | 251 | return -1; |
252 | } | 252 | } |
253 | } | 253 | } |
254 | else { | 254 | else { |
255 | if (perform_soft_reset()) { | 255 | if (perform_soft_reset()) { |
256 | spinlock_unlock(&ata_spinlock); | 256 | mutex_unlock(&ata_mtx); |
257 | ata_led(false); | 257 | ata_led(false); |
258 | return -1; | 258 | return -1; |
259 | } | 259 | } |
@@ -265,7 +265,7 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
265 | SET_REG(ATA_SELECT, ata_device); | 265 | SET_REG(ATA_SELECT, ata_device); |
266 | if (!wait_for_rdy()) | 266 | if (!wait_for_rdy()) |
267 | { | 267 | { |
268 | spinlock_unlock(&ata_spinlock); | 268 | mutex_unlock(&ata_mtx); |
269 | ata_led(false); | 269 | ata_led(false); |
270 | return -2; | 270 | return -2; |
271 | } | 271 | } |
@@ -376,7 +376,7 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
376 | ata_led(false); | 376 | ata_led(false); |
377 | 377 | ||
378 | #ifndef MAX_PHYS_SECTOR_SIZE | 378 | #ifndef MAX_PHYS_SECTOR_SIZE |
379 | spinlock_unlock(&ata_spinlock); | 379 | mutex_unlock(&ata_mtx); |
380 | #endif | 380 | #endif |
381 | 381 | ||
382 | return ret; | 382 | return ret; |
@@ -442,7 +442,7 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
442 | #ifdef HAVE_MULTIVOLUME | 442 | #ifdef HAVE_MULTIVOLUME |
443 | (void)drive; /* unused for now */ | 443 | (void)drive; /* unused for now */ |
444 | #endif | 444 | #endif |
445 | spinlock_lock(&ata_spinlock); | 445 | mutex_lock(&ata_mtx); |
446 | #endif | 446 | #endif |
447 | 447 | ||
448 | last_disk_activity = current_tick; | 448 | last_disk_activity = current_tick; |
@@ -454,14 +454,14 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
454 | spinup = true; | 454 | spinup = true; |
455 | if (poweroff) { | 455 | if (poweroff) { |
456 | if (ata_power_on()) { | 456 | if (ata_power_on()) { |
457 | spinlock_unlock(&ata_spinlock); | 457 | mutex_unlock(&ata_mtx); |
458 | ata_led(false); | 458 | ata_led(false); |
459 | return -1; | 459 | return -1; |
460 | } | 460 | } |
461 | } | 461 | } |
462 | else { | 462 | else { |
463 | if (perform_soft_reset()) { | 463 | if (perform_soft_reset()) { |
464 | spinlock_unlock(&ata_spinlock); | 464 | mutex_unlock(&ata_mtx); |
465 | ata_led(false); | 465 | ata_led(false); |
466 | return -1; | 466 | return -1; |
467 | } | 467 | } |
@@ -471,7 +471,7 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
471 | SET_REG(ATA_SELECT, ata_device); | 471 | SET_REG(ATA_SELECT, ata_device); |
472 | if (!wait_for_rdy()) | 472 | if (!wait_for_rdy()) |
473 | { | 473 | { |
474 | spinlock_unlock(&ata_spinlock); | 474 | mutex_unlock(&ata_mtx); |
475 | ata_led(false); | 475 | ata_led(false); |
476 | return -2; | 476 | return -2; |
477 | } | 477 | } |
@@ -534,7 +534,7 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
534 | ata_led(false); | 534 | ata_led(false); |
535 | 535 | ||
536 | #ifndef MAX_PHYS_SECTOR_SIZE | 536 | #ifndef MAX_PHYS_SECTOR_SIZE |
537 | spinlock_unlock(&ata_spinlock); | 537 | mutex_unlock(&ata_mtx); |
538 | #endif | 538 | #endif |
539 | 539 | ||
540 | return ret; | 540 | return ret; |
@@ -580,7 +580,7 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
580 | #ifdef HAVE_MULTIVOLUME | 580 | #ifdef HAVE_MULTIVOLUME |
581 | (void)drive; /* unused for now */ | 581 | (void)drive; /* unused for now */ |
582 | #endif | 582 | #endif |
583 | spinlock_lock(&ata_spinlock); | 583 | mutex_lock(&ata_mtx); |
584 | 584 | ||
585 | offset = start & (phys_sector_mult - 1); | 585 | offset = start & (phys_sector_mult - 1); |
586 | 586 | ||
@@ -630,7 +630,7 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
630 | } | 630 | } |
631 | 631 | ||
632 | error: | 632 | error: |
633 | spinlock_unlock(&ata_spinlock); | 633 | mutex_unlock(&ata_mtx); |
634 | 634 | ||
635 | return rc; | 635 | return rc; |
636 | } | 636 | } |
@@ -646,7 +646,7 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
646 | #ifdef HAVE_MULTIVOLUME | 646 | #ifdef HAVE_MULTIVOLUME |
647 | (void)drive; /* unused for now */ | 647 | (void)drive; /* unused for now */ |
648 | #endif | 648 | #endif |
649 | spinlock_lock(&ata_spinlock); | 649 | mutex_lock(&ata_mtx); |
650 | 650 | ||
651 | offset = start & (phys_sector_mult - 1); | 651 | offset = start & (phys_sector_mult - 1); |
652 | 652 | ||
@@ -707,7 +707,7 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
707 | } | 707 | } |
708 | 708 | ||
709 | error: | 709 | error: |
710 | spinlock_unlock(&ata_spinlock); | 710 | mutex_unlock(&ata_mtx); |
711 | 711 | ||
712 | return rc; | 712 | return rc; |
713 | } | 713 | } |
@@ -767,13 +767,13 @@ static int ata_perform_sleep(void) | |||
767 | { | 767 | { |
768 | int ret = 0; | 768 | int ret = 0; |
769 | 769 | ||
770 | spinlock_lock(&ata_spinlock); | 770 | mutex_lock(&ata_mtx); |
771 | 771 | ||
772 | SET_REG(ATA_SELECT, ata_device); | 772 | SET_REG(ATA_SELECT, ata_device); |
773 | 773 | ||
774 | if(!wait_for_rdy()) { | 774 | if(!wait_for_rdy()) { |
775 | DEBUGF("ata_perform_sleep() - not RDY\n"); | 775 | DEBUGF("ata_perform_sleep() - not RDY\n"); |
776 | spinlock_unlock(&ata_spinlock); | 776 | mutex_unlock(&ata_mtx); |
777 | return -1; | 777 | return -1; |
778 | } | 778 | } |
779 | 779 | ||
@@ -786,7 +786,7 @@ static int ata_perform_sleep(void) | |||
786 | } | 786 | } |
787 | 787 | ||
788 | sleeping = true; | 788 | sleeping = true; |
789 | spinlock_unlock(&ata_spinlock); | 789 | mutex_unlock(&ata_mtx); |
790 | return ret; | 790 | return ret; |
791 | } | 791 | } |
792 | 792 | ||
@@ -797,7 +797,7 @@ void ata_sleep(void) | |||
797 | 797 | ||
798 | void ata_sleepnow(void) | 798 | void ata_sleepnow(void) |
799 | { | 799 | { |
800 | if (!spinup && !sleeping && !ata_spinlock.locked && initialized) | 800 | if (!spinup && !sleeping && !ata_mtx.locked && initialized) |
801 | { | 801 | { |
802 | call_ata_idle_notifys(false); | 802 | call_ata_idle_notifys(false); |
803 | ata_perform_sleep(); | 803 | ata_perform_sleep(); |
@@ -819,7 +819,7 @@ static void ata_thread(void) | |||
819 | while ( queue_empty( &ata_queue ) ) { | 819 | while ( queue_empty( &ata_queue ) ) { |
820 | if (!spinup && !sleeping) | 820 | if (!spinup && !sleeping) |
821 | { | 821 | { |
822 | if (!ata_spinlock.locked) | 822 | if (!ata_mtx.locked) |
823 | { | 823 | { |
824 | if (!last_seen_mtx_unlock) | 824 | if (!last_seen_mtx_unlock) |
825 | last_seen_mtx_unlock = current_tick; | 825 | last_seen_mtx_unlock = current_tick; |
@@ -844,9 +844,9 @@ static void ata_thread(void) | |||
844 | if ( !spinup && sleeping && !poweroff && | 844 | if ( !spinup && sleeping && !poweroff && |
845 | TIME_AFTER( current_tick, last_sleep + ATA_POWER_OFF_TIMEOUT )) | 845 | TIME_AFTER( current_tick, last_sleep + ATA_POWER_OFF_TIMEOUT )) |
846 | { | 846 | { |
847 | spinlock_lock(&ata_spinlock); | 847 | mutex_lock(&ata_mtx); |
848 | ide_power_enable(false); | 848 | ide_power_enable(false); |
849 | spinlock_unlock(&ata_spinlock); | 849 | mutex_unlock(&ata_mtx); |
850 | poweroff = true; | 850 | poweroff = true; |
851 | } | 851 | } |
852 | #endif | 852 | #endif |
@@ -858,11 +858,11 @@ static void ata_thread(void) | |||
858 | #ifndef USB_NONE | 858 | #ifndef USB_NONE |
859 | case SYS_USB_CONNECTED: | 859 | case SYS_USB_CONNECTED: |
860 | if (poweroff) { | 860 | if (poweroff) { |
861 | spinlock_lock(&ata_spinlock); | 861 | mutex_lock(&ata_mtx); |
862 | ata_led(true); | 862 | ata_led(true); |
863 | ata_power_on(); | 863 | ata_power_on(); |
864 | ata_led(false); | 864 | ata_led(false); |
865 | spinlock_unlock(&ata_spinlock); | 865 | mutex_unlock(&ata_mtx); |
866 | } | 866 | } |
867 | 867 | ||
868 | /* Tell the USB thread that we are safe */ | 868 | /* Tell the USB thread that we are safe */ |
@@ -936,11 +936,11 @@ int ata_soft_reset(void) | |||
936 | { | 936 | { |
937 | int ret; | 937 | int ret; |
938 | 938 | ||
939 | spinlock_lock(&ata_spinlock); | 939 | mutex_lock(&ata_mtx); |
940 | 940 | ||
941 | ret = perform_soft_reset(); | 941 | ret = perform_soft_reset(); |
942 | 942 | ||
943 | spinlock_unlock(&ata_spinlock); | 943 | mutex_unlock(&ata_mtx); |
944 | return ret; | 944 | return ret; |
945 | } | 945 | } |
946 | 946 | ||
@@ -1132,11 +1132,11 @@ int ata_init(void) | |||
1132 | bool coldstart; | 1132 | bool coldstart; |
1133 | 1133 | ||
1134 | if ( !initialized ) { | 1134 | if ( !initialized ) { |
1135 | spinlock_init(&ata_spinlock IF_COP(, SPINLOCK_TASK_SWITCH)); | 1135 | mutex_init(&ata_mtx); |
1136 | queue_init(&ata_queue, true); | 1136 | queue_init(&ata_queue, true); |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | spinlock_lock(&ata_spinlock); | 1139 | mutex_lock(&ata_mtx); |
1140 | 1140 | ||
1141 | /* must be called before ata_device_init() */ | 1141 | /* must be called before ata_device_init() */ |
1142 | coldstart = ata_is_coldstart(); | 1142 | coldstart = ata_is_coldstart(); |
@@ -1150,7 +1150,7 @@ int ata_init(void) | |||
1150 | 1150 | ||
1151 | if ( !initialized ) { | 1151 | if ( !initialized ) { |
1152 | /* First call won't have multiple thread contention */ | 1152 | /* First call won't have multiple thread contention */ |
1153 | spinlock_unlock(&ata_spinlock); | 1153 | mutex_unlock(&ata_mtx); |
1154 | 1154 | ||
1155 | if (!ide_powered()) /* somebody has switched it off */ | 1155 | if (!ide_powered()) /* somebody has switched it off */ |
1156 | { | 1156 | { |
@@ -1223,7 +1223,7 @@ int ata_init(void) | |||
1223 | if (rc) | 1223 | if (rc) |
1224 | rc = -70 + rc; | 1224 | rc = -70 + rc; |
1225 | 1225 | ||
1226 | spinlock_unlock(&ata_spinlock); | 1226 | mutex_unlock(&ata_mtx); |
1227 | return rc; | 1227 | return rc; |
1228 | } | 1228 | } |
1229 | 1229 | ||
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index 96a7752017..be5041f6c2 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h | |||
@@ -119,18 +119,14 @@ struct mutex | |||
119 | unsigned char locked; /* locked semaphore */ | 119 | unsigned char locked; /* locked semaphore */ |
120 | }; | 120 | }; |
121 | 121 | ||
122 | #if NUM_CORES > 1 | ||
122 | struct spinlock | 123 | struct spinlock |
123 | { | 124 | { |
124 | #if NUM_CORES > 1 | ||
125 | struct corelock cl; /* inter-core sync */ | 125 | struct corelock cl; /* inter-core sync */ |
126 | #endif | ||
127 | struct thread_entry *thread; /* lock owner */ | 126 | struct thread_entry *thread; /* lock owner */ |
128 | int count; /* lock owner recursion count */ | 127 | int count; /* lock owner recursion count */ |
129 | unsigned char locked; /* is locked if nonzero */ | ||
130 | #if NUM_CORES > 1 | ||
131 | unsigned char task_switch; /* can task switch? */ | ||
132 | #endif | ||
133 | }; | 128 | }; |
129 | #endif | ||
134 | 130 | ||
135 | #ifdef HAVE_SEMAPHORE_OBJECTS | 131 | #ifdef HAVE_SEMAPHORE_OBJECTS |
136 | struct semaphore | 132 | struct semaphore |
@@ -229,12 +225,11 @@ extern int queue_broadcast(long id, intptr_t data); | |||
229 | extern void mutex_init(struct mutex *m); | 225 | extern void mutex_init(struct mutex *m); |
230 | extern void mutex_lock(struct mutex *m); | 226 | extern void mutex_lock(struct mutex *m); |
231 | extern void mutex_unlock(struct mutex *m); | 227 | extern void mutex_unlock(struct mutex *m); |
232 | #define SPINLOCK_TASK_SWITCH 0x10 | 228 | #if NUM_CORES > 1 |
233 | #define SPINLOCK_NO_TASK_SWITCH 0x00 | 229 | extern void spinlock_init(struct spinlock *l); |
234 | extern void spinlock_init(struct spinlock *l IF_COP(, unsigned int flags)); | ||
235 | extern void spinlock_lock(struct spinlock *l); | 230 | extern void spinlock_lock(struct spinlock *l); |
236 | extern void spinlock_unlock(struct spinlock *l); | 231 | extern void spinlock_unlock(struct spinlock *l); |
237 | extern int spinlock_lock_w_tmo(struct spinlock *l, int ticks); | 232 | #endif |
238 | #ifdef HAVE_SEMAPHORE_OBJECTS | 233 | #ifdef HAVE_SEMAPHORE_OBJECTS |
239 | extern void semaphore_init(struct semaphore *s, int max, int start); | 234 | extern void semaphore_init(struct semaphore *s, int max, int start); |
240 | extern void semaphore_wait(struct semaphore *s); | 235 | extern void semaphore_wait(struct semaphore *s); |
diff --git a/firmware/kernel.c b/firmware/kernel.c index 803c224640..204f3e8141 100644 --- a/firmware/kernel.c +++ b/firmware/kernel.c | |||
@@ -1127,15 +1127,12 @@ void mutex_unlock(struct mutex *m) | |||
1127 | /**************************************************************************** | 1127 | /**************************************************************************** |
1128 | * Simpl-er mutex functions ;) | 1128 | * Simpl-er mutex functions ;) |
1129 | ****************************************************************************/ | 1129 | ****************************************************************************/ |
1130 | void spinlock_init(struct spinlock *l IF_COP(, unsigned int flags)) | 1130 | #if NUM_CORES > 1 |
1131 | void spinlock_init(struct spinlock *l) | ||
1131 | { | 1132 | { |
1132 | l->locked = 0; | 1133 | corelock_init(&l->cl); |
1133 | l->thread = NULL; | 1134 | l->thread = NULL; |
1134 | l->count = 0; | 1135 | l->count = 0; |
1135 | #if NUM_CORES > 1 | ||
1136 | l->task_switch = flags & SPINLOCK_TASK_SWITCH; | ||
1137 | corelock_init(&l->cl); | ||
1138 | #endif | ||
1139 | } | 1136 | } |
1140 | 1137 | ||
1141 | void spinlock_lock(struct spinlock *l) | 1138 | void spinlock_lock(struct spinlock *l) |
@@ -1148,24 +1145,7 @@ void spinlock_lock(struct spinlock *l) | |||
1148 | return; | 1145 | return; |
1149 | } | 1146 | } |
1150 | 1147 | ||
1151 | #if NUM_CORES > 1 | 1148 | corelock_lock(&l->cl); |
1152 | if (l->task_switch != 0) | ||
1153 | #endif | ||
1154 | { | ||
1155 | /* Let other threads run until the lock is free */ | ||
1156 | while(test_and_set(&l->locked, 1, &l->cl) != 0) | ||
1157 | { | ||
1158 | /* spin and switch until the lock is open... */ | ||
1159 | switch_thread(NULL); | ||
1160 | } | ||
1161 | } | ||
1162 | #if NUM_CORES > 1 | ||
1163 | else | ||
1164 | { | ||
1165 | /* Use the corelock purely */ | ||
1166 | corelock_lock(&l->cl); | ||
1167 | } | ||
1168 | #endif | ||
1169 | 1149 | ||
1170 | l->thread = thread; | 1150 | l->thread = thread; |
1171 | } | 1151 | } |
@@ -1186,23 +1166,10 @@ void spinlock_unlock(struct spinlock *l) | |||
1186 | /* clear owner */ | 1166 | /* clear owner */ |
1187 | l->thread = NULL; | 1167 | l->thread = NULL; |
1188 | 1168 | ||
1189 | #if NUM_CORES > 1 | 1169 | /* release lock */ |
1190 | if (l->task_switch != 0) | ||
1191 | #endif | ||
1192 | { | ||
1193 | /* release lock */ | ||
1194 | #if CONFIG_CORELOCK == SW_CORELOCK | ||
1195 | /* This must be done since our unlock could be missed by the | ||
1196 | test_and_set and leave the object locked permanently */ | ||
1197 | corelock_lock(&l->cl); | ||
1198 | #endif | ||
1199 | l->locked = 0; | ||
1200 | } | ||
1201 | |||
1202 | #if NUM_CORES > 1 | ||
1203 | corelock_unlock(&l->cl); | 1170 | corelock_unlock(&l->cl); |
1204 | #endif | ||
1205 | } | 1171 | } |
1172 | #endif /* NUM_CORES > 1 */ | ||
1206 | 1173 | ||
1207 | /**************************************************************************** | 1174 | /**************************************************************************** |
1208 | * Simple semaphore functions ;) | 1175 | * Simple semaphore functions ;) |
diff --git a/firmware/system.c b/firmware/system.c index c186163cf6..2ba31f254f 100644 --- a/firmware/system.c +++ b/firmware/system.c | |||
@@ -39,7 +39,7 @@ static bool cpu_idle NOCACHEBSS_ATTR = false; | |||
39 | struct spinlock boostctrl_spin NOCACHEBSS_ATTR; | 39 | struct spinlock boostctrl_spin NOCACHEBSS_ATTR; |
40 | void cpu_boost_init(void) | 40 | void cpu_boost_init(void) |
41 | { | 41 | { |
42 | spinlock_init(&boostctrl_spin, SPINLOCK_NO_TASK_SWITCH); | 42 | spinlock_init(&boostctrl_spin); |
43 | } | 43 | } |
44 | #endif | 44 | #endif |
45 | 45 | ||
diff --git a/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c b/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c index 3a854afcdc..f80412023d 100644 --- a/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c +++ b/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include "hwcompat.h" | 22 | #include "hwcompat.h" |
23 | #include "kernel.h" | 23 | #include "kernel.h" |
24 | 24 | ||
25 | static struct spinlock adc_spin NOCACHEBSS_ATTR; | 25 | static struct mutex adc_mtx NOCACHEBSS_ATTR; |
26 | 26 | ||
27 | /* used in the 2nd gen ADC interrupt */ | 27 | /* used in the 2nd gen ADC interrupt */ |
28 | static unsigned int_data; | 28 | static unsigned int_data; |
@@ -33,7 +33,7 @@ unsigned short adc_scan(int channel) | |||
33 | unsigned short data = 0; | 33 | unsigned short data = 0; |
34 | 34 | ||
35 | (void)channel; /* there is only one */ | 35 | (void)channel; /* there is only one */ |
36 | spinlock_lock(&adc_spin); | 36 | mutex_lock(&adc_mtx); |
37 | 37 | ||
38 | if ((IPOD_HW_REVISION >> 16) == 1) | 38 | if ((IPOD_HW_REVISION >> 16) == 1) |
39 | { | 39 | { |
@@ -69,7 +69,7 @@ unsigned short adc_scan(int channel) | |||
69 | 69 | ||
70 | data = int_data & 0xff; | 70 | data = int_data & 0xff; |
71 | } | 71 | } |
72 | spinlock_unlock(&adc_spin); | 72 | mutex_unlock(&adc_mtx); |
73 | return data; | 73 | return data; |
74 | } | 74 | } |
75 | 75 | ||
@@ -100,7 +100,7 @@ void ipod_2g_adc_int(void) | |||
100 | 100 | ||
101 | void adc_init(void) | 101 | void adc_init(void) |
102 | { | 102 | { |
103 | spinlock_init(&adc_spin IF_COP(, SPINLOCK_TASK_SWITCH)); | 103 | mutex_init(&adc_mtx); |
104 | 104 | ||
105 | GPIOB_ENABLE |= 0x1e; /* enable B1..B4 */ | 105 | GPIOB_ENABLE |= 0x1e; /* enable B1..B4 */ |
106 | 106 | ||
diff --git a/firmware/target/arm/sandisk/ata-c200_e200.c b/firmware/target/arm/sandisk/ata-c200_e200.c index ef2bad387b..9a5301884f 100644 --- a/firmware/target/arm/sandisk/ata-c200_e200.c +++ b/firmware/target/arm/sandisk/ata-c200_e200.c | |||
@@ -162,7 +162,7 @@ static struct sd_card_status sd_status[NUM_VOLUMES] = | |||
162 | /* Shoot for around 75% usage */ | 162 | /* Shoot for around 75% usage */ |
163 | static long sd_stack [(DEFAULT_STACK_SIZE*2 + 0x1c0)/sizeof(long)]; | 163 | static long sd_stack [(DEFAULT_STACK_SIZE*2 + 0x1c0)/sizeof(long)]; |
164 | static const char sd_thread_name[] = "ata/sd"; | 164 | static const char sd_thread_name[] = "ata/sd"; |
165 | static struct spinlock sd_spin NOCACHEBSS_ATTR; | 165 | static struct mutex sd_mtx NOCACHEBSS_ATTR; |
166 | static struct event_queue sd_queue; | 166 | static struct event_queue sd_queue; |
167 | 167 | ||
168 | /* Posted when card plugged status has changed */ | 168 | /* Posted when card plugged status has changed */ |
@@ -801,7 +801,7 @@ int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, | |||
801 | 801 | ||
802 | /* TODO: Add DMA support. */ | 802 | /* TODO: Add DMA support. */ |
803 | 803 | ||
804 | spinlock_lock(&sd_spin); | 804 | mutex_lock(&sd_mtx); |
805 | 805 | ||
806 | ata_led(true); | 806 | ata_led(true); |
807 | 807 | ||
@@ -888,7 +888,7 @@ ata_read_retry: | |||
888 | while (1) | 888 | while (1) |
889 | { | 889 | { |
890 | ata_led(false); | 890 | ata_led(false); |
891 | spinlock_unlock(&sd_spin); | 891 | mutex_unlock(&sd_mtx); |
892 | 892 | ||
893 | return ret; | 893 | return ret; |
894 | 894 | ||
@@ -916,7 +916,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, | |||
916 | const unsigned char *buf, *buf_end; | 916 | const unsigned char *buf, *buf_end; |
917 | int bank; | 917 | int bank; |
918 | 918 | ||
919 | spinlock_lock(&sd_spin); | 919 | mutex_lock(&sd_mtx); |
920 | 920 | ||
921 | ata_led(true); | 921 | ata_led(true); |
922 | 922 | ||
@@ -1016,7 +1016,7 @@ ata_write_retry: | |||
1016 | while (1) | 1016 | while (1) |
1017 | { | 1017 | { |
1018 | ata_led(false); | 1018 | ata_led(false); |
1019 | spinlock_unlock(&sd_spin); | 1019 | mutex_unlock(&sd_mtx); |
1020 | 1020 | ||
1021 | return ret; | 1021 | return ret; |
1022 | 1022 | ||
@@ -1050,7 +1050,7 @@ static void sd_thread(void) | |||
1050 | 1050 | ||
1051 | /* Lock to keep us from messing with this variable while an init | 1051 | /* Lock to keep us from messing with this variable while an init |
1052 | may be in progress */ | 1052 | may be in progress */ |
1053 | spinlock_lock(&sd_spin); | 1053 | mutex_lock(&sd_mtx); |
1054 | card_info[1].initialized = 0; | 1054 | card_info[1].initialized = 0; |
1055 | sd_status[1].retry = 0; | 1055 | sd_status[1].retry = 0; |
1056 | 1056 | ||
@@ -1073,7 +1073,7 @@ static void sd_thread(void) | |||
1073 | if (action != SDA_NONE) | 1073 | if (action != SDA_NONE) |
1074 | queue_broadcast(SYS_FS_CHANGED, 0); | 1074 | queue_broadcast(SYS_FS_CHANGED, 0); |
1075 | 1075 | ||
1076 | spinlock_unlock(&sd_spin); | 1076 | mutex_unlock(&sd_mtx); |
1077 | break; | 1077 | break; |
1078 | } /* SD_HOTSWAP */ | 1078 | } /* SD_HOTSWAP */ |
1079 | #endif /* HAVE_HOTSWAP */ | 1079 | #endif /* HAVE_HOTSWAP */ |
@@ -1150,9 +1150,9 @@ int ata_init(void) | |||
1150 | int ret = 0; | 1150 | int ret = 0; |
1151 | 1151 | ||
1152 | if (!initialized) | 1152 | if (!initialized) |
1153 | spinlock_init(&sd_spin IF_COP(, SPINLOCK_TASK_SWITCH)); | 1153 | mutex_init(&sd_mtx); |
1154 | 1154 | ||
1155 | spinlock_lock(&sd_spin); | 1155 | mutex_lock(&sd_mtx); |
1156 | 1156 | ||
1157 | ata_led(false); | 1157 | ata_led(false); |
1158 | 1158 | ||
@@ -1215,7 +1215,7 @@ int ata_init(void) | |||
1215 | #endif | 1215 | #endif |
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | spinlock_unlock(&sd_spin); | 1218 | mutex_unlock(&sd_mtx); |
1219 | 1219 | ||
1220 | return ret; | 1220 | return ret; |
1221 | } | 1221 | } |
diff --git a/firmware/target/arm/tms320dm320/spi-dm320.c b/firmware/target/arm/tms320dm320/spi-dm320.c index f3b41add54..d8f338f592 100644 --- a/firmware/target/arm/tms320dm320/spi-dm320.c +++ b/firmware/target/arm/tms320dm320/spi-dm320.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #define GIO_RTC_ENABLE (1<<12) | 32 | #define GIO_RTC_ENABLE (1<<12) |
33 | #define GIO_BL_ENABLE (1<<13) | 33 | #define GIO_BL_ENABLE (1<<13) |
34 | 34 | ||
35 | struct spinlock spi_lock; | 35 | struct mutex spi_mtx; |
36 | 36 | ||
37 | struct SPI_info { | 37 | struct SPI_info { |
38 | volatile unsigned short *setreg; | 38 | volatile unsigned short *setreg; |
@@ -60,7 +60,7 @@ int spi_block_transfer(enum SPI_target target, | |||
60 | const uint8_t *tx_bytes, unsigned int tx_size, | 60 | const uint8_t *tx_bytes, unsigned int tx_size, |
61 | uint8_t *rx_bytes, unsigned int rx_size) | 61 | uint8_t *rx_bytes, unsigned int rx_size) |
62 | { | 62 | { |
63 | spinlock_lock(&spi_lock); | 63 | mutex_lock(&spi_mtx); |
64 | /* Activate the slave select pin */ | 64 | /* Activate the slave select pin */ |
65 | *spi_targets[target].setreg = spi_targets[target].bit; | 65 | *spi_targets[target].setreg = spi_targets[target].bit; |
66 | 66 | ||
@@ -87,13 +87,13 @@ int spi_block_transfer(enum SPI_target target, | |||
87 | 87 | ||
88 | *spi_targets[target].clrreg = spi_targets[target].bit; | 88 | *spi_targets[target].clrreg = spi_targets[target].bit; |
89 | 89 | ||
90 | spinlock_unlock(&spi_lock); | 90 | mutex_unlock(&spi_mtx); |
91 | return 0; | 91 | return 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | void spi_init(void) | 94 | void spi_init(void) |
95 | { | 95 | { |
96 | spinlock_init(&spi_lock); | 96 | mutex_init(&spi_mtx); |
97 | /* Set SCLK idle level = 0 */ | 97 | /* Set SCLK idle level = 0 */ |
98 | IO_SERIAL0_MODE |= 1<<10; | 98 | IO_SERIAL0_MODE |= 1<<10; |
99 | /* Enable TX */ | 99 | /* Enable TX */ |
diff --git a/uisimulator/sdl/kernel.c b/uisimulator/sdl/kernel.c index 7126b82072..17ca55a694 100644 --- a/uisimulator/sdl/kernel.c +++ b/uisimulator/sdl/kernel.c | |||
@@ -597,7 +597,7 @@ void mutex_unlock(struct mutex *m) | |||
597 | /* unlocker not being the owner is an unlocking violation */ | 597 | /* unlocker not being the owner is an unlocking violation */ |
598 | if(m->thread != thread_get_current()) | 598 | if(m->thread != thread_get_current()) |
599 | { | 599 | { |
600 | fprintf(stderr, "spinlock_unlock->wrong thread"); | 600 | fprintf(stderr, "mutex_unlock->wrong thread"); |
601 | exit(-1); | 601 | exit(-1); |
602 | } | 602 | } |
603 | 603 | ||
@@ -617,52 +617,6 @@ void mutex_unlock(struct mutex *m) | |||
617 | } | 617 | } |
618 | } | 618 | } |
619 | 619 | ||
620 | void spinlock_init(struct spinlock *l) | ||
621 | { | ||
622 | l->locked = 0; | ||
623 | l->thread = NULL; | ||
624 | l->count = 0; | ||
625 | } | ||
626 | |||
627 | void spinlock_lock(struct spinlock *l) | ||
628 | { | ||
629 | struct thread_entry *const thread = thread_get_current(); | ||
630 | |||
631 | if (l->thread == thread) | ||
632 | { | ||
633 | l->count++; | ||
634 | return; | ||
635 | } | ||
636 | |||
637 | while(test_and_set(&l->locked, 1)) | ||
638 | { | ||
639 | switch_thread(NULL); | ||
640 | } | ||
641 | |||
642 | l->thread = thread; | ||
643 | } | ||
644 | |||
645 | void spinlock_unlock(struct spinlock *l) | ||
646 | { | ||
647 | /* unlocker not being the owner is an unlocking violation */ | ||
648 | if(l->thread != thread_get_current()) | ||
649 | { | ||
650 | fprintf(stderr, "spinlock_unlock->wrong thread"); | ||
651 | exit(-1); | ||
652 | } | ||
653 | |||
654 | if (l->count > 0) | ||
655 | { | ||
656 | /* this thread still owns lock */ | ||
657 | l->count--; | ||
658 | return; | ||
659 | } | ||
660 | |||
661 | /* clear owner */ | ||
662 | l->thread = NULL; | ||
663 | l->locked = 0; | ||
664 | } | ||
665 | |||
666 | #ifdef HAVE_SEMAPHORE_OBJECTS | 620 | #ifdef HAVE_SEMAPHORE_OBJECTS |
667 | void semaphore_init(struct semaphore *s, int max, int start) | 621 | void semaphore_init(struct semaphore *s, int max, int start) |
668 | { | 622 | { |