diff --git a/firmware/drivers/ata-common.c b/firmware/drivers/ata-common.c index 45efd23478..0f8672caf1 100644 --- a/firmware/drivers/ata-common.c +++ b/firmware/drivers/ata-common.c @@ -20,6 +20,57 @@ /* This is intended to be #included into the ATA driver */ +static sector_t total_sectors; +static uint32_t log_sector_size; +static uint16_t identify_info[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR; +#ifdef HAVE_LBA48 +static bool ata_lba48 = false; /* set for 48 bit addressing */ +#endif +static bool canflush = true; +static int spinup_time = 0; +static struct mutex ata_mutex SHAREDBSS_ATTR; + +int ata_spinup_time(void) +{ + return spinup_time; +} + +#ifdef STORAGE_GET_INFO +void ata_get_info(IF_MD(int drive,)struct storage_info *info) +{ + unsigned short *src,*dest; + static char vendor[8]; + static char product[16]; + static char revision[4]; +#ifdef HAVE_MULTIDRIVE + (void)drive; /* unused for now */ +#endif + int i; + + info->sector_size = log_sector_size; + info->num_sectors = total_sectors; + + src = (unsigned short*)&identify_info[27]; + dest = (unsigned short*)vendor; + for (i=0;i<4;i++) + dest[i] = htobe16(src[i]); + info->vendor=vendor; + + src = (unsigned short*)&identify_info[31]; + dest = (unsigned short*)product; + for (i=0;i<8;i++) + dest[i] = htobe16(src[i]); + info->product=product; + + src = (unsigned short*)&identify_info[23]; + dest = (unsigned short*)revision; + for (i=0;i<2;i++) + dest[i] = htobe16(src[i]); + info->revision=revision; +} +#endif + + #ifdef MAX_PHYS_SECTOR_SIZE #ifdef MAX_VARIABLE_LOG_SECTOR @@ -41,6 +92,11 @@ struct sector_cache_entry { static struct sector_cache_entry sector_cache STORAGE_ALIGN_ATTR; static uint16_t phys_sector_mult = 1; +static int ata_transfer_sectors(uint64_t start, + int incount, + void* inbuf, + int write); + static int cache_sector(sector_t sector) { int rc; diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 9c7b8cb974..9d89f8d3dd 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -90,32 +90,22 @@ enum { static int ata_state = ATA_BOOT; -static struct mutex ata_mutex SHAREDBSS_ATTR; static int ata_device; /* device 0 (master) or 1 (slave) */ -static int spinup_time = 0; #if (CONFIG_LED == LED_REAL) static bool ata_led_enabled = true; static bool ata_led_on = false; #endif static long sleep_timeout = 5*HZ; -#ifdef HAVE_LBA48 -static bool ata_lba48 = false; /* set for 48 bit addressing */ -#endif -static bool canflush = true; static long last_disk_activity = -1; #ifdef HAVE_ATA_POWER_OFF static long power_off_tick = 0; #endif -static sector_t total_sectors; -static uint32_t log_sector_size; static uint8_t multisectors; /* number of supported multisectors */ -static unsigned short identify_info[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR; - #ifdef HAVE_ATA_DMA static int dma_mode = 0; #endif @@ -147,6 +137,8 @@ static inline bool ata_power_off_timed_out(void) #endif } +#include "ata-common.c" + #ifndef ATA_TARGET_POLLING static ICODE_ATTR int wait_for_bsy(void) { @@ -594,8 +586,6 @@ static int ata_transfer_sectors(uint64_t start, return ret; } -#include "ata-common.c" - #ifndef MAX_PHYS_SECTOR_SIZE int ata_read_sectors(IF_MD(int drive,) sector_t start, @@ -1218,46 +1208,6 @@ long ata_last_disk_activity(void) return last_disk_activity; } -int ata_spinup_time(void) -{ - return spinup_time; -} - -#ifdef STORAGE_GET_INFO -void ata_get_info(IF_MD(int drive,)struct storage_info *info) -{ - unsigned short *src,*dest; - static char vendor[8]; - static char product[16]; - static char revision[4]; -#ifdef HAVE_MULTIDRIVE - (void)drive; /* unused for now */ -#endif - int i; - - info->sector_size = log_sector_size; - info->num_sectors = total_sectors; - - src = (unsigned short*)&identify_info[27]; - dest = (unsigned short*)vendor; - for (i=0;i<4;i++) - dest[i] = htobe16(src[i]); - info->vendor=vendor; - - src = (unsigned short*)&identify_info[31]; - dest = (unsigned short*)product; - for (i=0;i<8;i++) - dest[i] = htobe16(src[i]); - info->product=product; - - src = (unsigned short*)&identify_info[23]; - dest = (unsigned short*)revision; - for (i=0;i<2;i++) - dest[i] = htobe16(src[i]); - info->revision=revision; -} -#endif - #ifdef HAVE_ATA_DMA /* Returns last DMA mode as set by set_features() */ int ata_get_dma_mode(void) diff --git a/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c b/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c index 05d347cbc4..0fd741df4a 100644 --- a/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c +++ b/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c @@ -65,21 +65,14 @@ /** static, private data **/ static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR; -static uint16_t identify_info[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR; static bool ceata; -static bool ata_lba48; static bool ata_dma; -static uint64_t ata_total_sectors; -static uint32_t log_sector_size; -static struct mutex ata_mutex; static struct semaphore ata_wakeup; static long ata_last_activity_value = -1; static long ata_sleep_timeout = 7 * HZ; static bool ata_powered; -static bool canflush = true; static struct semaphore mmc_wakeup; static struct semaphore mmc_comp_wakeup; -static int spinup_time = 0; #ifdef HAVE_ATA_DMA static int dma_mode = 0; static uint32_t ata_dma_flags; @@ -90,6 +83,8 @@ static const bool ata_error_srst = true; static int ata_reset(void); +#include "ata-common.c" + static uint16_t ata_read_cbr(uint32_t volatile* reg) { while (!(ATA_PIO_READY & 2)); @@ -758,10 +753,10 @@ static int ata_power_up(void) spinup_time = current_tick - spinup_start; - ata_total_sectors = (identify_info[61] << 16) | identify_info[60]; - if (ceata || (identify_info[83] & BIT(10) && ata_total_sectors == 0x0FFFFFFF)) + total_sectors = (identify_info[61] << 16) | identify_info[60]; + if (ceata || (identify_info[83] & BIT(10) && total_sectors == 0x0FFFFFFF)) { - ata_total_sectors = ((uint64_t)identify_info[103] << 48) | + total_sectors = ((uint64_t)identify_info[103] << 48) | ((uint64_t)identify_info[102] << 32) | ((uint64_t)identify_info[101] << 16) | identify_info[100]; @@ -902,11 +897,11 @@ static int ata_rw_chunk(uint64_t sector, uint32_t cnt, void* buffer, bool write) return rc; } -static int ata_transfer_sectors(uint64_t sector, uint32_t count, void* buffer, bool write) +static int ata_transfer_sectors(uint64_t sector, int count, void* buffer, int write) { if (!ata_powered) ata_power_up(); - if (sector + count > ata_total_sectors) + if (sector + count > total_sectors) RET_ERR(0); ata_set_active(); if (ata_dma && write) @@ -1014,8 +1009,6 @@ static int ata_reset(void) return rc; } -#include "ata-common.c" - #ifndef MAX_PHYS_SECTOR_SIZE int ata_read_sectors(IF_MD(int drive,) sector_t start, int incount, void* inbuf) @@ -1134,17 +1127,6 @@ void ata_spin(void) ata_set_active(); } -#ifdef STORAGE_GET_INFO -void ata_get_info(IF_MD(int drive,) struct storage_info *info) -{ - info->sector_size = log_sector_size; - info->num_sectors = ata_total_sectors; - info->vendor = "Apple"; - info->product = "iPod Classic"; - info->revision = "1.0"; -} -#endif - long ata_last_disk_activity(void) { return ata_last_activity_value; @@ -1158,7 +1140,7 @@ int ata_init(void) semaphore_init(&mmc_comp_wakeup, 1, 0); ceata = PDAT(11) & BIT(1); ata_powered = false; - ata_total_sectors = 0; + total_sectors = 0; /* get identify_info */ mutex_lock(&ata_mutex); @@ -1255,11 +1237,6 @@ unsigned short* ata_get_identify(void) return identify_info; } -int ata_spinup_time(void) -{ - return spinup_time; -} - #ifdef HAVE_ATA_DMA int ata_get_dma_mode(void) {