summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sd-as3525v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/sd-as3525v2.c')
-rw-r--r--firmware/target/arm/as3525/sd-as3525v2.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index 386b76e758..238cd7a5eb 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -789,6 +789,8 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
789#ifndef HAVE_MULTIDRIVE 789#ifndef HAVE_MULTIDRIVE
790 const int drive = 0; 790 const int drive = 0;
791#endif 791#endif
792 bool aligned = !((uintptr_t)buf & (CACHEALIGN_SIZE - 1));
793
792 794
793 mutex_lock(&sd_mtx); 795 mutex_lock(&sd_mtx);
794#ifndef BOOTLOADER 796#ifndef BOOTLOADER
@@ -828,17 +830,34 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
828 last_disk_activity = current_tick; 830 last_disk_activity = current_tick;
829 dma_retain(); 831 dma_retain();
830 832
833 if(aligned)
834 {
835 if(write)
836 clean_dcache_range(buf, count * SECTOR_SIZE);
837 else
838 dump_dcache_range(buf, count * SECTOR_SIZE);
839 }
840
831 const int cmd = write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK; 841 const int cmd = write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK;
832 842
833 do 843 do
834 { 844 {
835 void *dma_buf = aligned_buffer; 845 void *dma_buf;
836 unsigned int transfer = count; 846 unsigned int transfer = count;
837 if(transfer > UNALIGNED_NUM_SECTORS)
838 transfer = UNALIGNED_NUM_SECTORS;
839 847
840 if(write) 848 if(aligned)
841 memcpy(uncached_buffer, buf, transfer * SD_BLOCK_SIZE); 849 {
850 dma_buf = AS3525_PHYSICAL_ADDR(buf);
851 }
852 else
853 {
854 dma_buf = aligned_buffer;
855 if(transfer > UNALIGNED_NUM_SECTORS)
856 transfer = UNALIGNED_NUM_SECTORS;
857
858 if(write)
859 memcpy(uncached_buffer, buf, transfer * SD_BLOCK_SIZE);
860 }
842 861
843 /* Interrupt handler might set this to true during transfer */ 862 /* Interrupt handler might set this to true during transfer */
844 retry = false; 863 retry = false;
@@ -893,7 +912,7 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
893 912
894 if(!retry) 913 if(!retry)
895 { 914 {
896 if(!write) 915 if(!write && !aligned)
897 memcpy(buf, uncached_buffer, transfer * SD_BLOCK_SIZE); 916 memcpy(buf, uncached_buffer, transfer * SD_BLOCK_SIZE);
898 buf += transfer * SD_BLOCK_SIZE; 917 buf += transfer * SD_BLOCK_SIZE;
899 start += transfer; 918 start += transfer;