Index: apps/debug_menu.c =================================================================== --- apps/debug_menu.c (revision 20283) +++ apps/debug_menu.c (working copy) @@ -2029,7 +2029,7 @@ simplelist_addline(SIMPLELIST_ADD_LINE, "No timing info"); } -#if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) +#if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) || defined (HAVE_ATA_DMA) if (identify_info[63] & (1<<0)) { char mdma0[2], mdma1[2], mdma2[2]; mdma0[1] = mdma1[1] = mdma2[1] = 0; @@ -2047,18 +2047,19 @@ simplelist_addline(SIMPLELIST_ADD_LINE, "No MDMA mode info"); } - if (identify_info[88] & (1<<0)) { - char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2]; - udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0; + if (identify_info[53] & (1<<2)) { + char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2]; + udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0; udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0; udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0; udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0; udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0; udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0; udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0; + udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0; simplelist_addline(SIMPLELIST_ADD_LINE, - "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2, - udma3, udma4, udma5); + "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2, + udma3, udma4, udma5, udma6); } else { simplelist_addline(SIMPLELIST_ADD_LINE, @@ -2079,6 +2080,18 @@ } simplelist_addline(SIMPLELIST_ADD_LINE, "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0))); +#ifdef HAVE_ATA_DMA + i = ata_get_dma_mode(); + if (i == 0) { + simplelist_addline(SIMPLELIST_ADD_LINE, + "DMA not enabled"); + } else { + simplelist_addline(SIMPLELIST_ADD_LINE, + "DMA mode: %s %c", + (i & 0x40) ? "UDMA" : "MDMA", + '0' + (i & 7)); + } +#endif return btn; } #else /* No SD, MMC or ATA */ Index: firmware/drivers/ata.c =================================================================== --- firmware/drivers/ata.c (revision 20283) +++ firmware/drivers/ata.c (working copy) @@ -60,6 +60,12 @@ #define CMD_SLEEP 0xE6 #define CMD_SET_FEATURES 0xEF #define CMD_SECURITY_FREEZE_LOCK 0xF5 +#ifdef HAVE_ATA_DMA +#define CMD_READ_DMA 0xC8 +#define CMD_READ_DMA_EXT 0x25 +#define CMD_WRITE_DMA 0xCA +#define CMD_WRITE_DMA_EXT 0x35 +#endif /* Should all be < 0x100 (which are reserved for control messages) */ #define Q_SLEEP 0 @@ -169,7 +175,12 @@ static bool initialized = false; static long last_user_activity = -1; +#ifdef HAVE_ATA_DMA +/* Needed to allow updating while waiting for DMA to complete */ +long last_disk_activity = -1; +#else static long last_disk_activity = -1; +#endif static unsigned long total_sectors; static int multisectors; /* number of supported multisectors */ @@ -188,6 +199,10 @@ static int phys_sector_mult = 1; #endif +#ifdef HAVE_ATA_DMA +static int dma_mode = 0; +#endif + static int ata_power_on(void); static int perform_soft_reset(void); static int set_multiple_mode(int sectors); @@ -240,7 +255,8 @@ { if (!wait_for_bsy()) return 0; - return (ATA_ALT_STATUS & (STATUS_RDY|STATUS_DRQ)) == STATUS_RDY; + /* See FS#9721 */ + return (ATA_ALT_STATUS & (STATUS_BSY|STATUS_RDY|STATUS_DF|STATUS_DRQ|STATUS_ERR)) == STATUS_RDY; } #if (CONFIG_LED == LED_REAL) @@ -308,6 +324,9 @@ int count; void* buf; long spinup_start; +#ifdef HAVE_ATA_DMA + bool usedma = false; +#endif #ifndef MAX_PHYS_SECTOR_SIZE #ifdef HAVE_MULTIVOLUME @@ -358,6 +377,12 @@ ret = 0; last_disk_activity = current_tick; +#ifdef HAVE_ATA_DMA + /* If DMA is supported and parameters are ok for DMA, use it */ + if (dma_mode && ata_dma_setup(inbuf, incount * SECTOR_SIZE, false)) + usedma = true; +#endif + #ifdef HAVE_LBA48 if (lba48) { @@ -370,7 +395,11 @@ SET_REG(ATA_HCYL, 0); /* 47:40 */ SET_REG(ATA_HCYL, (start >> 16) & 0xff); /* 23:16 */ SET_REG(ATA_SELECT, SELECT_LBA | ata_device); +#ifdef HAVE_ATA_DMA + SET_REG(ATA_COMMAND, usedma ? CMD_READ_DMA_EXT : CMD_READ_MULTIPLE_EXT); +#else SET_REG(ATA_COMMAND, CMD_READ_MULTIPLE_EXT); +#endif } else #endif @@ -380,7 +409,11 @@ SET_REG(ATA_LCYL, (start >> 8) & 0xff); SET_REG(ATA_HCYL, (start >> 16) & 0xff); SET_REG(ATA_SELECT, ((start >> 24) & 0xf) | SELECT_LBA | ata_device); +#ifdef HAVE_ATA_DMA + SET_REG(ATA_COMMAND, usedma ? CMD_READ_DMA : CMD_READ_MULTIPLE); +#else SET_REG(ATA_COMMAND, CMD_READ_MULTIPLE); +#endif } /* wait at least 400ns between writing command and reading status */ @@ -390,6 +423,25 @@ __asm__ volatile ("nop"); __asm__ volatile ("nop"); +#ifdef HAVE_ATA_DMA + if (usedma) { + if (!ata_dma_finish()) + ret = -7; + + if (ret != 0) { + perform_soft_reset(); + goto retry; + } + + if (spinup) { + spinup_time = current_tick - spinup_start; + spinup = false; + sleeping = false; + poweroff = false; + } + } + else +#endif /* HAVE_ATA_DMA */ while (count) { int sectors; int wordcount; @@ -515,6 +567,9 @@ int i; int ret = 0; long spinup_start; +#ifdef HAVE_ATA_DMA + bool usedma = false; +#endif #ifndef MAX_PHYS_SECTOR_SIZE #ifdef HAVE_MULTIVOLUME @@ -554,6 +609,12 @@ goto error; } +#ifdef HAVE_ATA_DMA + /* If DMA is supported and parameters are ok for DMA, use it */ + if (dma_mode && ata_dma_setup((void *)buf, count * SECTOR_SIZE, true)) + usedma = true; +#endif + #ifdef HAVE_LBA48 if (lba48) { @@ -566,7 +627,11 @@ SET_REG(ATA_HCYL, 0); /* 47:40 */ SET_REG(ATA_HCYL, (start >> 16) & 0xff); /* 23:16 */ SET_REG(ATA_SELECT, SELECT_LBA | ata_device); +#ifdef HAVE_ATA_DMA + SET_REG(ATA_COMMAND, usedma ? CMD_WRITE_DMA_EXT : CMD_WRITE_SECTORS_EXT); +#else SET_REG(ATA_COMMAND, CMD_WRITE_SECTORS_EXT); +#endif } else #endif @@ -576,9 +641,26 @@ SET_REG(ATA_LCYL, (start >> 8) & 0xff); SET_REG(ATA_HCYL, (start >> 16) & 0xff); SET_REG(ATA_SELECT, ((start >> 24) & 0xf) | SELECT_LBA | ata_device); +#ifdef HAVE_ATA_DMA + SET_REG(ATA_COMMAND, usedma ? CMD_WRITE_DMA : CMD_WRITE_SECTORS); +#else SET_REG(ATA_COMMAND, CMD_WRITE_SECTORS); +#endif } +#ifdef HAVE_ATA_DMA + if (usedma) { + if (!ata_dma_finish()) + ret = -7; + else if (spinup) { + spinup_time = current_tick - spinup_start; + spinup = false; + sleeping = false; + poweroff = false; + } + } + else +#endif /* HAVE_ATA_DMA */ for (i=0; i= 5us */ +#ifdef HAVE_ATA_DMA + /* DMA requires INTRQ be enabled */ + SET_REG(ATA_CONTROL, 0); +#else SET_REG(ATA_CONTROL, CONTROL_nIEN); +#endif sleep(1); /* >2ms */ /* This little sucker can take up to 30 seconds */ @@ -1179,6 +1266,22 @@ return 0; } +#ifdef HAVE_ATA_DMA +int get_best_mode(unsigned short identword, int max, int modetype) +{ + unsigned short testbit = 1u << max; + + while (1) { + if (identword & testbit) + return max | modetype; + testbit >>= 1; + if (!testbit) + return 0; + max--; + } +} +#endif + static int set_features(void) { static struct { @@ -1191,6 +1294,9 @@ { 83, 3, 0x05, 0x80 }, /* adv. power management: lowest w/o standby */ { 83, 9, 0x42, 0x80 }, /* acoustic management: lowest noise */ { 82, 6, 0xaa, 0 }, /* enable read look-ahead */ +#ifdef HAVE_ATA_DMA + { 0, 0, 0x03, 0 }, /* DMA mode */ +#endif }; int i; int pio_mode = 2; @@ -1204,7 +1310,24 @@ /* Update the table: set highest supported pio mode that we also support */ features[0].parameter = 8 + pio_mode; + +#ifdef HAVE_ATA_DMA + if (identify_info[53] & (1<<2)) + /* Ultra DMA mode info present, find a mode */ + dma_mode = get_best_mode(identify_info[88], ATA_MAX_UDMA, 0x40); + if (!dma_mode) { + /* No UDMA mode found, try to find a multi-word DMA mode */ + dma_mode = get_best_mode(identify_info[63], ATA_MAX_MWDMA, 0x20); + features[4].id_word = 63; + } + else + features[4].id_word = 88; + + features[4].id_bit = dma_mode & 7; + features[4].parameter = dma_mode; +#endif /* HAVE_ATA_DMA */ + SET_REG(ATA_SELECT, ata_device); if (!wait_for_rdy()) { @@ -1237,6 +1360,10 @@ ata_set_pio_timings(pio_mode); #endif +#ifdef HAVE_ATA_DMA + ata_dma_set_mode(dma_mode); +#endif + return 0; } @@ -1305,6 +1432,11 @@ sleep(HZ/4); /* allow voltage to build up */ } +#ifdef HAVE_ATA_DMA + /* DMA requires INTRQ be enabled */ + SET_REG(ATA_CONTROL, 0); +#endif + /* first try, hard reset at cold start only */ rc = init_and_check(coldstart); @@ -1450,3 +1582,11 @@ info->revision=revision; } #endif + +#ifdef HAVE_ATA_DMA +/* Returns last DMA mode as set by set_features() */ +int ata_get_dma_mode(void) +{ + return dma_mode; +} +#endif Index: firmware/export/ata.h =================================================================== --- firmware/export/ata.h (revision 20283) +++ firmware/export/ata.h (working copy) @@ -60,5 +60,10 @@ long ata_last_disk_activity(void); int ata_spinup_time(void); /* ticks */ +#ifdef HAVE_ATA_DMA +/* Needed to allow updating while waiting for DMA to complete */ +extern long last_disk_activity; +int ata_get_dma_mode(void); +#endif #endif