summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-10-16 01:25:17 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-10-16 01:25:17 +0000
commita9b2fb5ee3114fe835f6515b6aeae7454f66d821 (patch)
treefc4e96d0c1f215565918406c8827b16b806c1345 /firmware/drivers/ata.c
parenta3fbbc9fa7e12fd3fce122bbd235dc362050e024 (diff)
downloadrockbox-a9b2fb5ee3114fe835f6515b6aeae7454f66d821.tar.gz
rockbox-a9b2fb5ee3114fe835f6515b6aeae7454f66d821.zip
Finally full multicore support for PortalPlayer 502x targets with an eye towards the possibility of other types. All SVN targets the low-lag code to speed up blocking operations. Most files are modified here simple due to a name change to actually support a real event object and a param change to create_thread. Add some use of new features but just sit on things for a bit and leave full integration for later. Work will continue on to address size on sensitive targets and simplify things if possible. Any PP target having problems with SWP can easily be changed to sw corelocks with one #define change in config.h though only PP5020 has shown an issue and seems to work without any difficulties.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15134 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/ata.c')
-rw-r--r--firmware/drivers/ata.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 2c8033a533..2119216234 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
69static struct mutex ata_mtx; 69static struct spinlock ata_spinlock NOCACHEBSS_ATTR;
70int ata_device; /* device 0 (master) or 1 (slave) */ 70int ata_device; /* device 0 (master) or 1 (slave) */
71 71
72int ata_spinup_time = 0; 72int ata_spinup_time = 0;
@@ -83,7 +83,7 @@ static bool lba48 = false; /* set for 48 bit addressing */
83#endif 83#endif
84static long ata_stack[(DEFAULT_STACK_SIZE*3)/sizeof(long)]; 84static long ata_stack[(DEFAULT_STACK_SIZE*3)/sizeof(long)];
85static const char ata_thread_name[] = "ata"; 85static const char ata_thread_name[] = "ata";
86static struct event_queue ata_queue; 86static struct event_queue ata_queue NOCACHEBSS_ATTR;
87static bool initialized = false; 87static bool initialized = false;
88 88
89static long last_user_activity = -1; 89static long last_user_activity = -1;
@@ -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_mtx); 237 spinlock_lock(&ata_spinlock);
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_mtx); 249 spinlock_unlock(&ata_spinlock);
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_mtx); 256 spinlock_unlock(&ata_spinlock);
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_mtx); 268 spinlock_unlock(&ata_spinlock);
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_mtx); 379 spinlock_unlock(&ata_spinlock);
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_mtx); 445 spinlock_lock(&ata_spinlock);
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_mtx); 457 spinlock_unlock(&ata_spinlock);
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_mtx); 464 spinlock_unlock(&ata_spinlock);
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_mtx); 474 spinlock_unlock(&ata_spinlock);
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_mtx); 537 spinlock_unlock(&ata_spinlock);
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_mtx); 583 spinlock_lock(&ata_spinlock);
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_mtx); 633 spinlock_unlock(&ata_spinlock);
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_mtx); 649 spinlock_lock(&ata_spinlock);
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_mtx); 710 spinlock_unlock(&ata_spinlock);
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_mtx); 770 spinlock_lock(&ata_spinlock);
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_mtx); 776 spinlock_unlock(&ata_spinlock);
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_mtx); 789 spinlock_unlock(&ata_spinlock);
790 return ret; 790 return ret;
791} 791}
792 792
@@ -797,7 +797,7 @@ void ata_sleep(void)
797 797
798void ata_sleepnow(void) 798void ata_sleepnow(void)
799{ 799{
800 if (!spinup && !sleeping && !ata_mtx.locked && initialized) 800 if (!spinup && !sleeping && !ata_spinlock.locked && initialized)
801 { 801 {
802 call_ata_idle_notifys(false); 802 call_ata_idle_notifys(false);
803 ata_perform_sleep(); 803 ata_perform_sleep();
@@ -812,14 +812,14 @@ void ata_spin(void)
812static void ata_thread(void) 812static void ata_thread(void)
813{ 813{
814 static long last_sleep = 0; 814 static long last_sleep = 0;
815 struct event ev; 815 struct queue_event ev;
816 static long last_seen_mtx_unlock = 0; 816 static long last_seen_mtx_unlock = 0;
817 817
818 while (1) { 818 while (1) {
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_mtx.locked) 822 if (!ata_spinlock.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_mtx); 847 spinlock_lock(&ata_spinlock);
848 ide_power_enable(false); 848 ide_power_enable(false);
849 spinlock_unlock(&ata_mtx); 849 spinlock_unlock(&ata_spinlock);
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_mtx); 861 spinlock_lock(&ata_spinlock);
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_mtx); 865 spinlock_unlock(&ata_spinlock);
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_mtx); 939 spinlock_lock(&ata_spinlock);
940 940
941 ret = perform_soft_reset(); 941 ret = perform_soft_reset();
942 942
943 spinlock_unlock(&ata_mtx); 943 spinlock_unlock(&ata_spinlock);
944 return ret; 944 return ret;
945} 945}
946 946
@@ -1131,7 +1131,7 @@ int ata_init(void)
1131 bool coldstart = ata_is_coldstart(); 1131 bool coldstart = ata_is_coldstart();
1132 /* must be called before ata_device_init() */ 1132 /* must be called before ata_device_init() */
1133 1133
1134 spinlock_init(&ata_mtx); 1134 spinlock_init(&ata_spinlock IF_COP(, SPINLOCK_TASK_SWITCH));
1135 1135
1136 ata_led(false); 1136 ata_led(false);
1137 ata_device_init(); 1137 ata_device_init();
@@ -1205,9 +1205,9 @@ int ata_init(void)
1205 1205
1206 last_disk_activity = current_tick; 1206 last_disk_activity = current_tick;
1207 create_thread(ata_thread, ata_stack, 1207 create_thread(ata_thread, ata_stack,
1208 sizeof(ata_stack), ata_thread_name 1208 sizeof(ata_stack), 0, ata_thread_name
1209 IF_PRIO(, PRIORITY_SYSTEM) 1209 IF_PRIO(, PRIORITY_SYSTEM)
1210 IF_COP(, CPU, false)); 1210 IF_COP(, CPU));
1211 initialized = true; 1211 initialized = true;
1212 1212
1213 } 1213 }