1
0
Fork 0
forked from len0rd/rockbox

storage: 64-bit sector offsets

* Create new 'sector_t' type alias:
    * uint64_t for all targets with HAVE_LBA48 or HAVE_SDUC
    * unsigned long for the everything else
 * Alter all storage APIs to use sector_t instead of 'unsigned long'
 * Alter Volume/Partition/storage info structures to use sector_t
 * Disk cache converted to sector_t
 * ATA Core:
    * convert to using sector_t for sector addresses and drive sizes
    * Always fill out upper 16 bits of LBA48 addresses
    * IDENTIFY INFO is fixed at 512 bytes, not SECTOR_SIZE
 * USB mass storage:
    * convert to using sector_t for sector addesses and drive sizes
    * Implement READ_16/WRITE_16 for LBA48 addresses
 * Convert FAT code to use sector_t for all sector references
 * output_dyn_value() now accepts int64_t instead of 'int'
 * Corrected "rockbox info" to work for (MULTIVOLUME & !MULTIDRIVE)
 * Better reporting of disk and (logical+physical) sector sizes in debug info
 * Detect SDUC cards and report on storage debug_info screen

To-do: SDUC

 * Refactor SD core to remove duplicate code in every driver
   * Card probe and init state machine
 * Implement core SDUC support
   * SD2.0 needs to be 2.0+ (fixed for jz47xx and x1000)
   * Host and Card ID (ACMD41)
   * 32-bit addressing for all read/write/erase operations (CMD22)
 * ADD SDUC to target device drivers, defining HAVE_SDUC as appropriate

Change-Id: Ib0138781a0081664d11511037685503df1b93608
This commit is contained in:
Solomon Peachy 2024-07-05 16:00:30 -04:00
parent 9ff308a589
commit 15e5237469
49 changed files with 629 additions and 435 deletions

View file

@ -446,7 +446,7 @@ static int sd_init_card(const int drive)
sd_parse_csd(&card_info[drive]);
#if defined(HAVE_MULTIDRIVE)
hs_card = (card_info[drive].speed == 50000000);
hs_card = (card_info[drive].speed >= 50000000);
#endif
/* Boost MCICLK to operating speed */
@ -455,7 +455,7 @@ static int sd_init_card(const int drive)
#if defined(HAVE_MULTIDRIVE)
else
/* MCICLK = PCLK/2 = 31MHz(HS) or PCLK/4 = 15.5 Mhz (STD)*/
MCI_CLOCK(drive) = (hs_card ? MCI_HALFSPEED : MCI_QUARTERSPEED) |
MCI_CLOCK(drive) = (hs_card ? MCI_HALFSPEED : MCI_QUARTERSPEED) |
MCI_CLOCK_POWERSAVE; /* SD supports powersave */
#endif
@ -680,7 +680,7 @@ static int sd_select_bank(signed char bank)
return 0;
}
static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
static int sd_transfer_sectors(IF_MD(int drive,) sector_t start,
int count, void* buf, const bool write)
{
#ifndef HAVE_MULTIDRIVE
@ -735,7 +735,8 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */
void *dma_buf;
unsigned long bank_start = start;
sector_t bank_start = start;
// XXX 64-bit sectors?
/* Only switch banks for internal storage */
if(drive == INTERNAL_AS3525)
@ -869,7 +870,7 @@ sd_transfer_error_nodma:
return ret;
}
int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_read_sectors(IF_MD(int drive,) sector_t start, int count,
void* buf)
{
int ret;
@ -881,11 +882,11 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
return ret;
}
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* buf)
{
#ifdef VERIFY_WRITE
unsigned long saved_start = start;
sector_t saved_start = start;
int saved_count = count;
void *saved_buf = (void*)buf;
#endif

View file

@ -677,7 +677,7 @@ int sd_init(void)
return 0;
}
static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
static int sd_transfer_sectors(IF_MD(int drive,) sector_t start,
int count, void* buf, bool write)
{
unsigned long response;
@ -776,7 +776,7 @@ retry_with_reinit:
MCI_BYTCNT = transfer * SD_BLOCK_SIZE;
int arg = start;
sector_t arg = start; // XXX 64-bit
if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */
arg *= SD_BLOCK_SIZE;
@ -858,13 +858,13 @@ exit:
return ret;
}
int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_read_sectors(IF_MD(int drive,) sector_t start, int count,
void* buf)
{
return sd_transfer_sectors(IF_MD(drive,) start, count, buf, false);
}
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* buf)
{
return sd_transfer_sectors(IF_MD(drive,) start, count, (void*)buf, true);

View file

@ -179,7 +179,7 @@ static int phys_segment_to_page_addr(int phys_segment, int page_in_seg)
break;
}
}
page_addr += (page_in_seg / nand_data->planes);
return page_addr;
@ -222,7 +222,7 @@ static void nand_chip_select(int bank)
static void nand_read_id(int bank, unsigned char* id_buf)
{
int i;
/* Enable NFC bus clock */
BCLKCTR |= DEV_NAND;
@ -358,7 +358,7 @@ static void nand_setup_read(int bank, int row, int column)
static void nand_end_read(void)
{
nand_chip_select(-1);
/* Disable NFC bus clock */
BCLKCTR &= ~DEV_NAND;
}
@ -367,7 +367,7 @@ static void nand_end_read(void)
static void nand_read_raw(int bank, int row, int column, int size, void* buf)
{
int i;
nand_setup_read(bank, row, column);
/* Read data into page buffer */
@ -388,7 +388,7 @@ static void nand_read_raw(int bank, int row, int column, int size, void* buf)
((unsigned int*)buf)[i] = NFC_WDATA;
}
}
nand_end_read();
}
@ -422,7 +422,7 @@ static void nand_get_chip_info(void)
sectors_per_page = nand_data->page_size / SECTOR_SIZE;
sectors_per_segment = bytes_per_segment / SECTOR_SIZE;
pages_per_segment = sectors_per_segment / sectors_per_page;
/* Establish how many banks are present */
@ -494,7 +494,7 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
#ifdef USE_ECC_CORRECTION
unsigned long spare_buf[4];
/* Set up the ECC controller to monitor reads from NFC_WDATA */
BCLKCTR |= DEV_ECC;
ECC_BASE = (unsigned long)&NFC_WDATA;
@ -514,27 +514,27 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
This way, reads are always done through NFC_WDATA - otherwise they
would not be 'seen' by the ECC controller. */
static char temp_buf[SECTOR_SIZE];
unsigned int* ptr = (unsigned int*) temp_buf;
for (i = 0; i < (SECTOR_SIZE/4); i++)
{
*ptr++ = NFC_WDATA;
}
memcpy(buf, temp_buf, SECTOR_SIZE);
}
else
{
/* Use straight word copy as buffer and size are both word-aligned */
unsigned int* ptr = (unsigned int*) buf;
for (i = 0; i < (SECTOR_SIZE/4); i++)
{
*ptr++ = NFC_WDATA;
}
}
#ifdef USE_ECC_CORRECTION
/* Stop monitoring before we read the OOB data */
ECC_CTRL &= ~ECC_M4EN;
@ -549,29 +549,29 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
/* Calculate MLC4 ECC using bytes 0,1,8-15 */
BCLKCTR |= DEV_ECC;
ECC_CTRL |= ECC_M4EN;
MLC_ECC0W = *(unsigned short*)spare_buf;
MLC_ECC1W = spare_buf[2];
MLC_ECC2W = spare_buf[3];
while (!(ECC_CTRL & ECC_READY)) {};
int errors = ECC_ERR_NUM & 7;
switch (errors)
{
case 4: /* nothing to correct */
break;
case 7: /* fail, can't correct */
ret = false;
break;
default: /* between 1 and 4 errors */
{
int i;
unsigned char* char_buf = (unsigned char*)buf;
for (i = 0; i < errors + 1; i++)
{
int offset = 0x207 - ECC_ERRADDR(i);
@ -584,7 +584,7 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
ECC_CTRL &= ~ECC_M4EN;
BCLKCTR &= ~DEV_ECC;
#endif
nand_end_read();
return ret;
@ -619,7 +619,7 @@ static bool nand_read_sector_of_logical_segment(int log_segment, int sector,
int cache_num = 0;
bool found = false;
while (!found && cache_num < write_caches_in_use)
{
if (write_caches[cache_num].log_segment == log_segment)
@ -628,10 +628,10 @@ static bool nand_read_sector_of_logical_segment(int log_segment, int sector,
{
/* data is located in random pages cache */
found = true;
bank = write_caches[cache_num].random_bank;
phys_segment = write_caches[cache_num].random_phys_segment;
page_in_segment =
write_caches[cache_num].page_map[page_in_segment];
}
@ -640,7 +640,7 @@ static bool nand_read_sector_of_logical_segment(int log_segment, int sector,
{
/* data is located in in-place pages cache */
found = true;
bank = write_caches[cache_num].inplace_bank;
phys_segment = write_caches[cache_num].inplace_phys_segment;
}
@ -664,7 +664,7 @@ static inline unsigned char get_sector_type(char* spare_buf)
static inline unsigned short get_log_segment_id(int phys_seg, char* spare_buf)
{
(void)phys_seg;
return ((spare_buf[OFF_LOG_SEG_HIBYTE] << 8) |
spare_buf[OFF_LOG_SEG_LOBYTE])
#if defined(FTL_V1)
@ -702,7 +702,7 @@ static void read_random_writes_cache(int bank, int phys_segment)
16, spare_buf);
log_segment = get_log_segment_id(phys_segment, spare_buf);
if (log_segment == -1)
return;
@ -734,13 +734,13 @@ static void read_random_writes_cache(int bank, int phys_segment)
page++)
{
unsigned short cached_page;
nand_read_raw(bank, phys_segment_to_page_addr(phys_segment, page),
SECTOR_SIZE, /* offset to first sector's spare */
16, spare_buf);
cached_page = get_cached_page_id(spare_buf);
if (cached_page != 0xFFFF)
write_caches[cache_no].page_map[cached_page] = page;
}
@ -759,10 +759,10 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
16, spare_buf);
log_segment = get_log_segment_id(phys_segment, spare_buf);
if (log_segment == -1)
return;
/* Find which cache this is related to */
int cache_no = find_write_cache(log_segment);
@ -780,7 +780,7 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
}
write_caches[cache_no].log_segment = log_segment;
/* Find how many pages have been written to the new segment */
while (log_segment != -1 &&
page < (nand_data->pages_per_block * nand_data->planes) - 1)
@ -791,7 +791,7 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
log_segment = get_log_segment_id(phys_segment, spare_buf);
}
if (page != 0)
{
write_caches[cache_no].inplace_bank = bank;
@ -801,7 +801,7 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
}
int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
int nand_read_sectors(IF_MD(int drive,) sector_t start, int incount,
void* inbuf)
{
#ifdef HAVE_MULTIDRIVE
@ -809,15 +809,15 @@ int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
#endif
int ret = 0;
mutex_lock(&ata_mtx);
led(true);
while (incount > 0)
{
int done = 0;
int segment = start / sectors_per_segment;
sector_t segment = start / sectors_per_segment;
int secmod = start % sectors_per_segment;
while (incount > 0 && secmod < sectors_per_segment)
@ -839,7 +839,7 @@ int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
secmod++;
done++;
}
if (done < 0)
{
ret = -1;
@ -852,11 +852,11 @@ nand_read_error:
mutex_unlock(&ata_mtx);
led(false);
return ret;
}
int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* outbuf)
{
#ifdef HAVE_MULTIDRIVE
@ -903,7 +903,7 @@ int nand_init(void)
unsigned char spare_buf[16];
if (initialized) return 0;
mutex_init(&ata_mtx);
/* Set GPIO direction for chip select & write protect */
@ -924,7 +924,7 @@ int nand_init(void)
memset(lpt_lookup, 0xff, lptbuf_size);
memset(write_caches, 0xff, sizeof(write_caches));
write_caches_in_use = 0;
/* Scan banks to build up block translation table */
@ -936,7 +936,7 @@ int nand_init(void)
nand_read_raw(bank, phys_segment_to_page_addr(phys_segment, 0),
SECTOR_SIZE, /* offset */
16, spare_buf);
int type = get_sector_type(spare_buf);
#ifdef FTL_V2
@ -948,7 +948,7 @@ int nand_init(void)
nand_read_raw(bank, phys_segment_to_page_addr
(phys_segment, pages_per_segment - 1),
SECTOR_SIZE, 16, spare_buf);
if (get_sector_type(spare_buf) != 0xff)
{
type = SECTYPE_MAIN_DATA;
@ -982,14 +982,14 @@ int nand_init(void)
}
break;
}
case SECTYPE_MAIN_RANDOM_CACHE:
{
/* Newly-written random page data (Main data area) */
read_random_writes_cache(bank, phys_segment);
break;
}
case SECTYPE_MAIN_INPLACE_CACHE:
{
/* Newly-written sequential page data (Main data area) */
@ -999,7 +999,7 @@ int nand_init(void)
}
}
}
initialized = true;
return 0;
@ -1029,7 +1029,7 @@ int nand_num_drives(int first_drive)
{
/* We don't care which logical drive number we have been assigned */
(void)first_drive;
return 1;
}

View file

@ -36,13 +36,13 @@ int nand_init(void)
{
return -1;
}
int nand_read_sectors(IF_MD(int drive,) unsigned long start, int count,
int nand_read_sectors(IF_MD(int drive,) sector_t start, int count,
void* buf)
{
return -1;
}
int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* buf)
{
return -1;

View file

@ -71,7 +71,7 @@ static const char *creative_part_name(enum imx233_part_t part)
}
static int compute_window_creative(intptr_t user, part_read_fn_t read_fn,
enum imx233_part_t part, unsigned *start, unsigned *end)
enum imx233_part_t part, sector_t *start, unsigned *end)
{
uint8_t mblk[512];
int ret = read_fn(user, MBLK_ADDR / 512, 1, mblk);

View file

@ -45,7 +45,7 @@ enum imx233_part_t
/** The computation function can be called very early in the boot, at which point
* usual storage read/write function may not be available. To workaround this
* issue, one must provide a read function. */
typedef int (*part_read_fn_t)(intptr_t user, unsigned long start, int count, void* buf);
typedef int (*part_read_fn_t)(intptr_t user, sector_t start, int count, void* buf);
/* Enable/Disable window computations for internal storage following the
* Freescale/Creative convention */
void imx233_partitions_enable_window(bool enable);
@ -55,6 +55,6 @@ bool imx233_partitions_is_window_enabled(void);
* for a whole disk, *end should be the size of the disk when the function is
* called */
int imx233_partitions_compute_window(intptr_t user, part_read_fn_t read_fn,
enum imx233_part_t part, unsigned *start, unsigned *end);
enum imx233_part_t part, sector_t *start, unsigned *end);
#endif /* __PARTITIONS_IMX233__ */
#endif /* __PARTITIONS_IMX233__ */

View file

@ -648,7 +648,7 @@ int mmc_event(long id, intptr_t data)
#endif /* CONFIG_STORAGE & STORAGE_MMC */
/* low-level function, don't call directly! */
static int __xfer_sectors(int drive, unsigned long start, int count, void *buf, bool read)
static int __xfer_sectors(int drive, sector_t start, int count, void *buf, bool read)
{
uint32_t resp;
int ret = 0;
@ -660,7 +660,7 @@ static int __xfer_sectors(int drive, unsigned long start, int count, void *buf,
need_stop = false;
/* Set bank_start to the correct unit (blocks or bytes).
* MMC drives use block addressing, SD cards bytes or blocks */
int bank_start = start;
sector_t bank_start = start;
if(SDMMC_MODE(drive) == SD_MODE && !(SDMMC_INFO(drive).ocr & (1<<30))) /* not SDHC */
bank_start *= SD_BLOCK_SIZE;
/* issue read/write
@ -686,7 +686,7 @@ static int __xfer_sectors(int drive, unsigned long start, int count, void *buf,
return ret;
}
static int transfer_sectors(int drive, unsigned long start, int count, void *buf, bool read)
static int transfer_sectors(int drive, sector_t start, int count, void *buf, bool read)
{
int ret = 0;
/* the function doesn't work when count is 0 */
@ -806,7 +806,7 @@ static int transfer_sectors(int drive, unsigned long start, int count, void *buf
}
/* user specifies the sdmmc drive */
static int part_read_fn(intptr_t user, unsigned long start, int count, void* buf)
static int part_read_fn(intptr_t user, sector_t start, int count, void* buf)
{
return transfer_sectors(user, start, count, buf, true);
}
@ -917,7 +917,7 @@ void sd_enable(bool on)
(void) on;
}
int sd_read_sectors(IF_MD(int sd_drive,) unsigned long start, int count, void *buf)
int sd_read_sectors(IF_MD(int sd_drive,) sector_t start, int count, void *buf)
{
#ifndef HAVE_MULTIDRIVE
int sd_drive = 0;
@ -925,7 +925,7 @@ int sd_read_sectors(IF_MD(int sd_drive,) unsigned long start, int count, void *b
return transfer_sectors(sd_map[sd_drive], start, count, buf, true);
}
int sd_write_sectors(IF_MD(int sd_drive,) unsigned long start, int count, const void* buf)
int sd_write_sectors(IF_MD(int sd_drive,) sector_t start, int count, const void* buf)
{
#ifndef HAVE_MULTIDRIVE
int sd_drive = 0;
@ -1039,7 +1039,7 @@ int mmc_spinup_time(void)
return 0;
}
int mmc_read_sectors(IF_MD(int mmc_drive,) unsigned long start, int count, void *buf)
int mmc_read_sectors(IF_MD(int mmc_drive,) sector_t start, int count, void *buf)
{
#ifndef HAVE_MULTIDRIVE
int mmc_drive = 0;
@ -1047,7 +1047,7 @@ int mmc_read_sectors(IF_MD(int mmc_drive,) unsigned long start, int count, void
return transfer_sectors(mmc_map[mmc_drive], start, count, buf, true);
}
int mmc_write_sectors(IF_MD(int mmc_drive,) unsigned long start, int count, const void* buf)
int mmc_write_sectors(IF_MD(int mmc_drive,) sector_t start, int count, const void* buf)
{
#ifndef HAVE_MULTIDRIVE
int mmc_drive = 0;

View file

@ -82,7 +82,7 @@
#define STAT_TIME_OUT_RES (1 << 1)
#define STAT_TIME_OUT_READ (1)
#define STAT_ERROR_BITS (0x3f)
/* MMC_CMDAT bits */
/* Some of the bits used by the OF don't make much sense with these */
/* definitions. So they're probably different between PXA and PP502x */
@ -101,7 +101,7 @@
#define CMDAT_RES_TYPE3 (3)
#define CMDAT_RES_TYPE2 (2)
#define CMDAT_RES_TYPE1 (1)
/* MMC_I_MASK bits */
/* PP502x apparently only has bits 0-3 */
#define I_MASK_SDIO_SUSPEND_ACK (1 << 12)
@ -499,18 +499,18 @@ static inline void copy_write_sectors(const unsigned char** buf)
{
asm volatile (
"ldmia %[buf]!, { r3, r5, r7, r9 } \r\n"
"mov r4, r3, lsr #16 \r\n"
"mov r6, r5, lsr #16 \r\n"
"mov r8, r7, lsr #16 \r\n"
"mov r10, r9, lsr #16 \r\n"
"mov r4, r3, lsr #16 \r\n"
"mov r6, r5, lsr #16 \r\n"
"mov r8, r7, lsr #16 \r\n"
"mov r10, r9, lsr #16 \r\n"
"stmia %[data], { r3-r10 } \r\n"
"ldmia %[buf]!, { r3, r5, r7, r9 } \r\n"
"mov r4, r3, lsr #16 \r\n"
"mov r6, r5, lsr #16 \r\n"
"mov r8, r7, lsr #16 \r\n"
"mov %[t], r9, lsr #16 \r\n"
"mov r4, r3, lsr #16 \r\n"
"mov r6, r5, lsr #16 \r\n"
"mov r8, r7, lsr #16 \r\n"
"mov %[t], r9, lsr #16 \r\n"
"stmia %[data], { r3-r9 } \r\n"
: [buf]"+&r"(*buf), [t]"=&r"(t)
: [buf]"+&r"(*buf), [t]"=&r"(t)
: [data]"r"(&MMC_DATA_FIFO)
: "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"
);
@ -760,7 +760,7 @@ static void sd_init_device(int card_no)
currcard->csd[i] = temp_reg[3-i];
sd_parse_csd(currcard);
MMC_CLKRT = 0; /* switch to highest clock rate */
ret = sd_command(SD_SELECT_CARD, currcard->rca, NULL,
@ -849,7 +849,7 @@ static void sd_select_device(int card_no)
/* API Functions */
int sd_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
int sd_read_sectors(IF_MD(int drive,) sector_t start, int incount,
void* inbuf)
{
#ifndef HAVE_MULTIDRIVE
@ -857,8 +857,8 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
#endif
int ret;
unsigned char *buf, *buf_end;
unsigned int bank;
sector_t bank;
/* TODO: Add DMA support. */
mutex_lock(&sd_mtx);
@ -894,7 +894,7 @@ sd_read_retry:
if (ret < 0)
goto sd_read_error;
}
start -= bank * BLOCKS_PER_BANK;
}
@ -904,6 +904,8 @@ sd_read_retry:
MMC_NUMBLK = incount;
// XXX 64-bit addresses..
#ifdef HAVE_HOTSWAP
if(currcard->ocr & (1<<30) )
{
@ -966,7 +968,7 @@ sd_read_error:
}
}
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* outbuf)
{
/* Write support is not finished yet */
@ -1010,7 +1012,7 @@ sd_write_retry:
if (ret < 0)
goto sd_write_error;
}
start -= bank * BLOCKS_PER_BANK;
}
@ -1250,7 +1252,7 @@ int sd_num_drives(int first_drive)
#else
(void)first_drive;
#endif
#ifdef HAVE_MULTIDRIVE
return 2;
#else

View file

@ -31,18 +31,18 @@
/* This file provides only STUBS for now */
/** static, private data **/
/** static, private data **/
static bool initialized = false;
/* API Functions */
int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
int nand_read_sectors(IF_MD(int drive,) sector_t start, int incount,
void* inbuf)
{
(void)drive;
return ftl_read(start, incount, inbuf);
}
int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* outbuf)
{
(void)drive;
@ -112,7 +112,7 @@ int nand_num_drives(int first_drive)
{
/* We don't care which logical drive number(s) we have been assigned */
(void)first_drive;
return 1;
}
#endif

View file

@ -453,7 +453,7 @@ static inline void write_sd_data(unsigned char **src)
*src += 512;
}
int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_read_sectors(IF_MD(int drive,) sector_t start, int count,
void* buf)
{
#ifdef HAVE_MULTIDRIVE
@ -498,6 +498,8 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
DATA_XFER_MULTI;
}
// XXX 64-bit
/* issue read command to the card */
if (!send_cmd(SD_READ_MULTIPLE_BLOCK, start, RES_R1, &response))
{
@ -576,7 +578,7 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
}
/* Not tested */
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* buf)
{
#ifdef HAVE_MULTIDRIVE
@ -620,6 +622,7 @@ int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
write_sd_data(&src); /* put data into transfer buffer */
// XXX 64-bit
if (!send_cmd(SD_WRITE_MULTIPLE_BLOCK, start, RES_R1, &response))
{
ret = -3;

View file

@ -18,7 +18,7 @@
* KIND, either express or implied.
*
****************************************************************************/
//#define SD_DEBUG
#include "system.h"
@ -33,7 +33,7 @@
#include "sdmmc.h"
#endif
#include "storage.h"
#include "dma-target.h"
#include "dma-target.h"
#include "system-target.h"
#include "led-mini2440.h"
@ -83,7 +83,7 @@ struct sd_card_status
int retry_max;
};
/** static, private data **/
/** static, private data **/
/* for compatibility */
static long last_disk_activity = -1;
@ -117,13 +117,13 @@ static struct mutex sd_mtx SHAREDBSS_ATTR;
static struct semaphore transfer_completion_signal;
static volatile unsigned int transfer_error[NUM_DRIVES];
/* align on cache line size */
static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
__attribute__((aligned(32)));
static unsigned char * uncached_buffer;
static inline void mci_delay(void)
{
int i = 0xffff;
static inline void mci_delay(void)
{
int i = 0xffff;
while (i--)
asm volatile ("nop\n");
}
@ -146,7 +146,7 @@ static void get_regs (unsigned *regs)
{
unsigned j;
volatile unsigned long *sdi_reg = &SDICON;
for (j=0; j < 16;j++)
{
*regs++ = *sdi_reg++;
@ -158,7 +158,7 @@ static void dump_regs (unsigned *regs1, unsigned *regs2)
unsigned j;
volatile unsigned long*sdi_reg = &SDICON;
unsigned long diff;
for (j=0; j < 16;j++)
{
diff = *regs1 ^ *regs2;
@ -174,23 +174,23 @@ static void dump_regs (unsigned *regs1, unsigned *regs2)
static void debug_r1(int cmd)
{
#if defined(SD_DEBUG)
dbgprintf("CMD%2.2d:SDICSTA=%04x [%c%c%c%c%c-%c%c%c%c%c%c%c] SDIRSP0=%08x [%d %s] \n",
cmd,
SDICSTA,
(SDICSTA & S3C2410_SDICMDSTAT_CRCFAIL) ? 'C' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_CMDSENT) ? 'S' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_CMDTIMEOUT) ? 'T' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_RSPFIN) ? 'R' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_XFERING) ? 'X' : ' ',
(SDICSTA & 0x40) ? 'P' : ' ',
(SDICSTA & 0x20) ? 'A' : ' ',
(SDICSTA & 0x10) ? 'E' : ' ',
(SDICSTA & 0x08) ? 'C' : ' ',
(SDICSTA & 0x04) ? 'I' : ' ',
(SDICSTA & 0x02) ? 'R' : ' ',
(SDICSTA & 0x01) ? 'Z' : ' ',
dbgprintf("CMD%2.2d:SDICSTA=%04x [%c%c%c%c%c-%c%c%c%c%c%c%c] SDIRSP0=%08x [%d %s] \n",
cmd,
SDICSTA,
(SDICSTA & S3C2410_SDICMDSTAT_CRCFAIL) ? 'C' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_CMDSENT) ? 'S' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_CMDTIMEOUT) ? 'T' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_RSPFIN) ? 'R' : ' ',
(SDICSTA & S3C2410_SDICMDSTAT_XFERING) ? 'X' : ' ',
(SDICSTA & 0x40) ? 'P' : ' ',
(SDICSTA & 0x20) ? 'A' : ' ',
(SDICSTA & 0x10) ? 'E' : ' ',
(SDICSTA & 0x08) ? 'C' : ' ',
(SDICSTA & 0x04) ? 'I' : ' ',
(SDICSTA & 0x02) ? 'R' : ' ',
(SDICSTA & 0x01) ? 'Z' : ' ',
SDIRSP0,
SD_R1_CURRENT_STATE(SDIRSP0),
(SDIRSP0 & SD_R1_READY_FOR_DATA) ? "RDY " : " "
@ -205,8 +205,8 @@ void SDI (void)
int status = SDIDSTA;
#ifndef HAVE_MULTIDRIVE
const int curr_card = 0;
#endif
#endif
transfer_error[curr_card] = status
#if 0
& ( S3C2410_SDIDSTA_CRCFAIL | S3C2410_SDIDSTA_RXCRCFAIL |
@ -217,7 +217,7 @@ void SDI (void)
SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; /* needed to clear int */
dbgprintf ("SDI %x\n", transfer_error[curr_card]);
semaphore_release(&transfer_completion_signal);
/* Ack the interrupt */
@ -229,13 +229,13 @@ void SDI (void)
void dma_callback (void)
{
const int status = SDIDSTA;
transfer_error[0] = status & (S3C2410_SDIDSTA_CRCFAIL |
S3C2410_SDIDSTA_RXCRCFAIL |
S3C2410_SDIDSTA_DATATIMEOUT );
SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; /* needed to clear int */
dbgprintf ("dma_cb\n");
semaphore_release(&transfer_completion_signal);
}
@ -248,14 +248,14 @@ static void init_sdi_controller(const int card_no)
/*****************************************************************************/
#ifdef MINI2440
/* Specific to Mini2440 */
/* Enable pullups on SDCMD and SDDAT pins */
S3C2440_GPIO_PULLUP (GPEUP, 6, GPIO_PULLUP_ENABLE);
S3C2440_GPIO_PULLUP (GPEUP, 7, GPIO_PULLUP_ENABLE);
S3C2440_GPIO_PULLUP (GPEUP, 8, GPIO_PULLUP_ENABLE);
S3C2440_GPIO_PULLUP (GPEUP, 9, GPIO_PULLUP_ENABLE);
S3C2440_GPIO_PULLUP (GPEUP, 10, GPIO_PULLUP_ENABLE);
/* Enable special function for SDCMD, SDCLK and SDDAT pins */
S3C2440_GPIO_CONFIG (GPECON, 5, GPIO_FUNCTION);
S3C2440_GPIO_CONFIG (GPECON, 6, GPIO_FUNCTION);
@ -263,15 +263,15 @@ static void init_sdi_controller(const int card_no)
S3C2440_GPIO_CONFIG (GPECON, 8, GPIO_FUNCTION);
S3C2440_GPIO_CONFIG (GPECON, 9, GPIO_FUNCTION);
S3C2440_GPIO_CONFIG (GPECON, 10, GPIO_FUNCTION);
/* Card Detect input */
S3C2440_GPIO_CONFIG (GPGCON, 8, GPIO_INPUT);
/* enable external irq 8-23 on the internal interrupt controller */
INTMSK &= ~1<<5;
/* enable GPG8 IRQ on the external interrupt controller */
EINTMASK &= ~(1<<16);
/* Write Protect input */
S3C2440_GPIO_CONFIG (GPHCON, 8, GPIO_INPUT);
/*****************************************************************************/
@ -279,11 +279,11 @@ static void init_sdi_controller(const int card_no)
#error Unsupported target
#endif
/*****************************************************************************/
/* About 400KHz for initial comms with card */
SDIPRE = PCLK / INITIAL_CLK - 1;
/* Byte order=Type A (Little Endian), clock enable */
SDICON = S3C2410_SDICON_CLOCKTYPE;
SDICON = S3C2410_SDICON_CLOCKTYPE;
SDIFSTA |= S3C2440_SDIFSTA_FIFORESET;
SDIBSIZE = SD_BLOCK_SIZE;
SDIDTIMER= 0x7fffff; /* Set timeout count - max value */
@ -297,11 +297,11 @@ static void init_sdi_controller(const int card_no)
/* Enable interrupt in controller */
bitclr32(&INTMOD, SDI_MASK);
bitclr32(&INTMSK, SDI_MASK);
SDIIMSK |= S3C2410_SDIIMSK_DATAFINISH
SDIIMSK |= S3C2410_SDIIMSK_DATAFINISH
| S3C2410_SDIIMSK_DATATIMEOUT
| S3C2410_SDIIMSK_DATACRC
| S3C2410_SDIIMSK_CRCSTATUS
| S3C2410_SDIIMSK_DATACRC
| S3C2410_SDIIMSK_CRCSTATUS
| S3C2410_SDIIMSK_FIFOFAIL
;
#endif
@ -325,18 +325,18 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
get_regs (reg_copy2);
dump_regs (reg_copy, reg_copy2);
#endif
#if 0
while (SDICSTA & S3C2410_SDICMDSTAT_XFERING)
; /* wait ?? */
#endif
#endif
/* set up new command */
if (flags & MCI_ARG)
SDICARG = arg;
else
SDICARG = 0;
val = cmd | S3C2410_SDICMDCON_CMDSTART | S3C2410_SDICMDCON_SENDERHOST;
if(flags & MCI_RESP)
{
@ -344,27 +344,27 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
if(flags & MCI_LONG_RESP)
val |= S3C2410_SDICMDCON_LONGRSP;
}
/* Clear command/data status flags */
SDICSTA |= 0x0f << 9;
SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS;
/* Initiate the command */
SDICCON = val;
if (flags & MCI_RESP)
{
/* wait for response or timeout */
do
do
{
status = SDICSTA;
} while ( (status & (S3C2410_SDICMDSTAT_RSPFIN |
} while ( (status & (S3C2410_SDICMDSTAT_RSPFIN |
S3C2410_SDICMDSTAT_CMDTIMEOUT) ) == 0);
debug_r1(cmd);
if (status & S3C2410_SDICMDSTAT_CMDTIMEOUT)
ret = false;
else if (status & (S3C2410_SDICMDSTAT_RSPFIN))
{
{
/* resp received */
if(flags & MCI_LONG_RESP)
{
@ -381,10 +381,10 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
else
ret = true;
}
else
else
{
/* wait for command completion or timeout */
do
do
{
status = SDICSTA;
} while ( (status & (S3C2410_SDICMDSTAT_CMDSENT |
@ -395,12 +395,12 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
else
ret = true;
}
/* Clear Command status flags */
SDICSTA |= 0x0f << 9;
mci_delay();
return ret;
}
@ -558,7 +558,7 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
const int card_no = 0;
#endif
(void)card_no;
/* not applicable */
dbgprintf ("sd_remov");
return false;
@ -596,7 +596,7 @@ static int sd_wait_for_state(const int card_no, unsigned int state)
}
}
static int sd_transfer_sectors(int card_no, unsigned long start,
static int sd_transfer_sectors(int card_no, sector_t start,
int count, void* buf, const bool write)
{
int ret = EC_OK;
@ -636,7 +636,7 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
void *dma_buf;
const int cmd =
write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK;
unsigned long start_addr = start;
sector_t start_addr = start;
dma_buf = aligned_buffer;
if(transfer > UNALIGNED_NUM_SECTORS)
@ -650,10 +650,10 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
/* TODO? */
SDIFSTA = SDIFSTA | S3C2440_SDIFSTA_FIFORESET;
SDIDCON = S3C2440_SDIDCON_DS_WORD |
SDIDCON = S3C2440_SDIDCON_DS_WORD |
S3C2410_SDIDCON_BLOCKMODE | S3C2410_SDIDCON_WIDEBUS |
S3C2410_SDIDCON_DMAEN |
S3C2440_SDIDCON_DATSTART |
S3C2440_SDIDCON_DATSTART |
( transfer << 0);
if (write)
SDIDCON |= S3C2410_SDIDCON_TXAFTERRESP | S3C2410_SDIDCON_XFER_TXSTART;
@ -665,6 +665,7 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
INTPND = SDI_MASK;
/* Initiate read/write command */
// XXX 64-bit
if(!send_cmd(card_no, cmd, start_addr, MCI_ARG | MCI_RESP, NULL))
{
ret -= 3*20;
@ -674,32 +675,32 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
if(write)
{
request.source_addr = dma_buf;
request.source_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO;
request.source_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO;
request.dest_addr = &SDIDAT_LLE;
request.dest_control = DISRCC_LOC_APB | DISRCC_INC_FIXED;
request.dest_control = DISRCC_LOC_APB | DISRCC_INC_FIXED;
request.count = transfer * SD_BLOCK_SIZE / sizeof(long);
request.source_map = DMA_SRC_MAP_SDI;
request.control = DCON_DMD_HS | DCON_SYNC_APB |
request.control = DCON_DMD_HS | DCON_SYNC_APB |
DCON_HW_SEL |
DCON_NO_RELOAD | DCON_DSZ_WORD;
request.callback = NULL;
request.callback = NULL;
dma_enable_channel(0, &request);
}
else
{
request.source_addr = &SDIDAT_LLE;
request.source_control = DISRCC_LOC_APB | DISRCC_INC_FIXED;
request.source_control = DISRCC_LOC_APB | DISRCC_INC_FIXED;
request.dest_addr = dma_buf;
request.dest_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO;
request.dest_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO;
request.count = transfer * SD_BLOCK_SIZE / sizeof(long);
request.source_map = DMA_SRC_MAP_SDI;
request.control = DCON_DMD_HS | DCON_SYNC_APB |
request.control = DCON_DMD_HS | DCON_SYNC_APB |
DCON_HW_SEL |
DCON_NO_RELOAD | DCON_DSZ_WORD;
request.callback = NULL;
dma_enable_channel(0, &request);
request.callback = NULL;
dma_enable_channel(0, &request);
}
#if 0
@ -716,12 +717,12 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
#endif
semaphore_wait(&transfer_completion_signal, 100 /*TIMEOUT_BLOCK*/);
/* wait for DMA to finish */
while (DSTAT0 & DSTAT_STAT_BUSY)
;
#if 0
#if 0
status = SDIDSTA;
while ((status & (S3C2410_SDIDSTA_DATATIMEOUT|S3C2410_SDIDSTA_XFERFINISH)) == 0)
{
@ -738,10 +739,10 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
count -= transfer;
loops = 0; /* reset errors counter */
}
else
else
{
dbgprintf ("SD transfer error : 0x%x\n", transfer_error[card_no]);
if(loops++ > MAX_TRANSFER_ERRORS)
{
led_flash(LED1|LED2, LED3|LED4);
@ -783,11 +784,11 @@ sd_transfer_error:
return ret;
}
int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
int sd_read_sectors(IF_MD(int card_no,) sector_t start, int incount,
void* inbuf)
{
int ret;
#ifdef HAVE_MULTIDRIVE
dbgprintf ("sd_read %d %x %d\n", card_no, start, incount);
#else
@ -804,7 +805,7 @@ int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
}
/*****************************************************************************/
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* outbuf)
{
#ifdef BOOTLOADER /* we don't need write support in bootloader */
@ -835,7 +836,7 @@ void sd_enable(bool on)
{
dbgprintf ("sd_enable %d\n", on);
/* TODO: enable/disable SDI clock */
if (sd_enabled == on)
return; /* nothing to do */
if (on)
@ -847,14 +848,14 @@ void sd_enable(bool on)
sd_enabled = false;
}
}
int sd_init(void)
{
int ret = EC_OK;
dbgprintf ("\n==============================\n");
dbgprintf (" sd_init\n");
dbgprintf ("==============================\n");
init_sdi_controller (0);
#ifndef BOOTLOADER
sd_enabled = true;
@ -893,7 +894,7 @@ long sd_last_disk_activity(void)
}
tCardInfo *card_get_info_target(int card_no)
{
{
return &card_info[card_no];
}

View file

@ -29,17 +29,17 @@
#include "ftl-target.h"
#include "nand-target.h"
/** static, private data **/
/** static, private data **/
static bool initialized = false;
/* API Functions */
int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
int nand_read_sectors(IF_MD(int drive,) sector_t start, int incount,
void* inbuf)
{
return ftl_read(start, incount, inbuf);
}
int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* outbuf)
{
return ftl_write(start, count, outbuf);
@ -106,7 +106,7 @@ int nand_num_drives(int first_drive)
{
/* We don't care which logical drive number(s) we have been assigned */
(void)first_drive;
return 1;
}
#endif

View file

@ -58,10 +58,9 @@
#define CEATA_DAT_NONBUSY_TIMEOUT 5000000
#define CEATA_MMC_RCA 1
/** static, private data **/
static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR;
static uint16_t ata_identify_data[0x100] STORAGE_ALIGN_ATTR;
static uint16_t ata_identify_data[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR;
static bool ceata;
static bool ata_lba48;
static bool ata_dma;
@ -510,7 +509,7 @@ static int ata_identify(uint16_t* buf)
ata_write_cbr(&ATA_PIO_DVR, 0);
ata_write_cbr(&ATA_PIO_CSD, CMD_IDENTIFY);
PASS_RC(ata_wait_for_start_of_transfer(10000000), 1, 1);
for (i = 0; i < 0x100; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR);
for (i = 0; i < ATA_IDENTIFY_WORDS; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR);
}
return 0;
}
@ -701,7 +700,7 @@ static int ata_power_up(void)
| (((uint64_t)ata_identify_data[103]) << 48);
else
ata_total_sectors = ata_identify_data[60] | (((uint32_t)ata_identify_data[61]) << 16);
ata_total_sectors >>= 3;
ata_total_sectors >>= 3; /* ie SECTOR_SIZE/512. */
ata_powered = true;
ata_set_active();
return 0;
@ -966,7 +965,7 @@ static int ata_reset(void)
return rc;
}
int ata_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
int ata_read_sectors(IF_MD(int drive,) sector_t start, int incount,
void* inbuf)
{
mutex_lock(&ata_mutex);
@ -975,7 +974,7 @@ int ata_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
return rc;
}
int ata_write_sectors(IF_MD(int drive,) unsigned long start, int count,
int ata_write_sectors(IF_MD(int drive,) sector_t start, int count,
const void* outbuf)
{
mutex_lock(&ata_mutex);

View file

@ -104,19 +104,19 @@ static bool sd_poll_status(unsigned int trigger, long timeout)
return true;
}
static int sd_command(unsigned int cmd, unsigned int arg,
static int sd_command(unsigned int cmd, unsigned int arg,
unsigned long* response, unsigned int resp_type)
{
int sdi_cmd = cmd;
sdi_cmd |= (127<<12) | (1<<11); /* max wait time | enable */
if (resp_type)
{
/* response type & response required flag */
sdi_cmd |= (resp_type<<7) | (1<<6);
}
if (cmd == SD_READ_SINGLE_BLOCK ||
cmd == SD_READ_MULTIPLE_BLOCK ||
cmd == SD_WRITE_BLOCK ||
@ -124,18 +124,18 @@ static int sd_command(unsigned int cmd, unsigned int arg,
{
sdi_cmd |= (1<<10); /* request data transfer */
}
if (!sd_poll_status(SDISTATUS_CMD_PATH_RDY, 100000))
return -EC_COMMAND;
SDIARGU = arg;
SDICMD = sdi_cmd;
udelay(10);
if (response == NULL)
return 0;
if (!sd_poll_status(SDISTATUS_RESP_RCVD, 100000))
return -EC_COMMAND;
@ -150,7 +150,7 @@ static int sd_command(unsigned int cmd, unsigned int arg,
{
response[0] = SDIRSPARGU0;
}
return 0;
}
@ -220,7 +220,7 @@ static int sd1_oneshot_callback(struct timeout *tmo)
void EXT0(void)
{
static struct timeout sd1_oneshot;
timeout_register(&sd1_oneshot, sd1_oneshot_callback, (3*HZ/10), 0);
}
@ -248,7 +248,7 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
const int card_no = 0;
#endif
(void)card_no;
return false;
}
@ -259,7 +259,7 @@ static void sd_init_device(int card_no)
{
int ret;
unsigned long response;
/* Initialise card data as blank */
memset(currcard, 0, sizeof(*currcard));
@ -282,7 +282,7 @@ static void sd_init_device(int card_no)
#endif
ret = sd_command(SD_GO_IDLE_STATE, 0, NULL, SDICMD_RES_TYPE1);
if (ret < 0)
goto card_init_error;
@ -290,30 +290,30 @@ static void sd_init_device(int card_no)
SDICLK = (1<<12) | 59;
sd_command(SD_SEND_IF_COND, 0x1aa, &response, SDICMD_RES_TYPE3);
if (!sd_poll_status(SDISTATUS_CMD_PATH_RDY, 100000))
goto card_init_error;
currcard->ocr = 0;
long start_tick = current_tick;
while ((currcard->ocr & (1<<31)) == 0
&& TIME_BEFORE(current_tick, start_tick + HZ))
{
udelay(100);
sd_command(SD_APP_CMD, 0, NULL, SDICMD_RES_TYPE1);
int arg = 0x100000 | ((response == 0x1aa) ? (1<<30):0);
sd_command(SD_APP_OP_COND, arg, &currcard->ocr, SDICMD_RES_TYPE3);
}
if ((currcard->ocr & (1<<31)) == 0)
{
ret = -EC_POWER_UP;
goto card_init_error;
}
ret = sd_command
(SD_ALL_SEND_CID, 0, currcard->cid, SDICMD_RES_TYPE2);
@ -322,39 +322,39 @@ static void sd_init_device(int card_no)
ret = sd_command
(SD_SEND_RELATIVE_ADDR, 0, &currcard->rca, SDICMD_RES_TYPE1);
if (ret < 0)
goto card_init_error;
ret = sd_command
(SD_SEND_CSD, currcard->rca, currcard->csd, SDICMD_RES_TYPE2);
if (ret < 0)
goto card_init_error;
sd_parse_csd(currcard);
ret = sd_command
(SD_SELECT_CARD, currcard->rca, NULL, SDICMD_RES_TYPE1);
if (ret < 0)
goto card_init_error;
ret = sd_command
(SD_APP_CMD, currcard->rca, NULL, SDICMD_RES_TYPE1);
if (ret < 0)
goto card_init_error;
ret = sd_command /* 4 bit */
(SD_SET_BUS_WIDTH, currcard->rca | 2, NULL, SDICMD_RES_TYPE1);
if (ret < 0)
goto card_init_error;
ret = sd_command
(SD_SET_BLOCKLEN, currcard->blocksize, NULL, SDICMD_RES_TYPE1);
if (ret < 0)
goto card_init_error;
@ -386,7 +386,7 @@ static void sd_select_device(int card_no)
}
}
int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
int sd_read_sectors(IF_MD(int card_no,) sector_t start, int incount,
void* inbuf)
{
#ifndef HAVE_MULTIDRIVE
@ -416,23 +416,24 @@ sd_read_retry:
ret = currcard->initialized;
goto sd_read_error;
}
last_disk_activity = current_tick;
ret = sd_wait_for_state(SD_TRAN, EC_TRAN_READ_ENTRY);
if (ret < 0)
goto sd_read_error;
/* Use full SD clock for data transfer (PCK_SDMMC) */
SDICLK = (1<<13) | (1<<12); /* bypass divider | enable */
/* Block count | FIFO count | Block size (2^9) | 4-bit bus */
SDIDCTRL = (incount << 13) | (4<<8) | (9<<4) | (1<<2);
SDIDCTRL |= (1<<12); /* nReset */
SDIDCTRL2 = (1<<2); /* multi block, read */
// XXX 64-bit
if (currcard->ocr & (1<<30))
ret = sd_command(SD_READ_MULTIPLE_BLOCK, start, NULL, SDICMD_RES_TYPE1);
else
@ -500,7 +501,7 @@ sd_read_error:
}
}
int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int card_no,) sector_t start, int count,
const void* outbuf)
{
/* Write support is not finished yet */
@ -538,21 +539,22 @@ sd_write_retry:
ret = currcard->initialized;
goto sd_write_error;
}
ret = sd_wait_for_state(SD_TRAN, EC_TRAN_WRITE_ENTRY);
if (ret < 0)
goto sd_write_error;
/* Use full SD clock for data transfer (PCK_SDMMC) */
SDICLK = (1<<13) | (1<<12); /* bypass divider | enable */
/* Block count | FIFO count | Block size (2^9) | 4-bit bus */
SDIDCTRL = (count<<13) | (4<<8) | (9<<4) | (1<<2);
SDIDCTRL |= (1<<12); /* nReset */
SDIDCTRL2 = (1<<2) | (1<<1); /* multi block, write */
// XXX 64-bit
if (currcard->ocr & (1<<30))
ret = sd_command(SD_WRITE_MULTIPLE_BLOCK, start, NULL, SDICMD_RES_TYPE1);
else
@ -578,7 +580,7 @@ sd_write_retry:
else
{
int tmp_buf[4];
memcpy(tmp_buf, outbuf, 16);
SDIWDATA = tmp_buf[0];
@ -646,12 +648,12 @@ void sd_enable(bool on)
PCLK_SDMMC &= ~PCK_EN;
}
}
int sd_init(void)
{
static bool initialized = false;
int ret = 0;
if (!initialized)
mutex_init(&sd_mtx);
@ -678,7 +680,7 @@ int sd_init(void)
GPIOC_DIR |= (1<<24);
sleep(HZ/10);
#ifdef HAVE_HOTSWAP
/* Configure interrupts for the card slot */
TMODE &= ~EXT0_IRQ_MASK; /* edge-triggered */
@ -696,7 +698,7 @@ long sd_last_disk_activity(void)
}
tCardInfo *card_get_info_target(int card_no)
{
{
return &card_info[card_no];
}
@ -706,7 +708,7 @@ int sd_num_drives(int first_drive)
{
/* Store which logical drive number(s) we have been assigned */
sd_first_drive = first_drive;
#if defined(HAVE_INTERNAL_SD) && defined(HAVE_HOTSWAP)
return 2;
#else

View file

@ -126,8 +126,10 @@ void GIO2(void)
#define VFAT_SECTOR_SIZE(x) ( (x)/0x8000 ) /* 1GB array requires 80kB of RAM */
extern int ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf);
extern int ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf);
extern int ata_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf);
extern int ata_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf);
// XXX 64-bit: Due to this it's not likely that this target will ever handle 64-bit storage.
struct main_header
{
@ -253,9 +255,9 @@ static void cfs_init(void)
/* Read root inode */
_ata_read_sectors(CFS_CLUSTER2CLUSTER(cfs->first_inode), 64, &sector2);
root_inode = (struct cfs_inode*)&sector2;
logf("Root inode = 0x%x", root_inode);
logf("0x%x 0x%x", CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), root_inode->first_class_chain[0]);
/* Read root inode's first sector */
@ -277,9 +279,9 @@ static void cfs_init(void)
vfat_inode_nr = root_direntry_items[i].inode_number;
}
}
logf("VFAT inode = 0x%x", vfat_inode_nr);
if(vfat_inode_nr != 0)
{
/* Read VFAT inode */
@ -384,19 +386,19 @@ static void cfs_init(void)
cfs_inited = true;
}
static inline unsigned long map_sector(unsigned long sector)
static inline sector_t map_sector(sector_t sector)
{
/*
* Sector mapping: start of CFS + FAT_SECTOR2CFS_SECTOR(sector) + missing part
* FAT works with sectors of 0x200 bytes, CFS with sectors of 0x8000 bytes.
*/
#ifndef BOOTLOADER
unsigned long *sectors = core_get_data(sectors_handle);
sector_t *sectors = core_get_data(sectors_handle);
#endif
return cfs_start+sectors[sector/64]*64+sector%64;
}
int ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
int ata_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf)
{
if(!cfs_inited)
cfs_init();
@ -423,7 +425,7 @@ int ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf
}
}
int ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf)
int ata_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf)
{
if(!cfs_inited)
cfs_init();

View file

@ -36,8 +36,8 @@
/* Nasty hack, but Creative is nasty... */
#define ata_read_sectors _ata_read_sectors
#define ata_write_sectors _ata_write_sectors
extern int _ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf);
extern int _ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf);
extern int _ata_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf);
extern int _ata_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf);
/* General purpose memory region #1 */
#define ATA_IOBASE 0x50FEE000

View file

@ -18,7 +18,7 @@
* KIND, either express or implied.
*
****************************************************************************/
#include "system.h"
#include <string.h>
#include "gcc_extensions.h"
@ -97,7 +97,7 @@ struct sd_card_status
int retry_max;
};
/** static, private data **/
/** static, private data **/
/* for compatibility */
static long last_disk_activity = -1;
@ -123,7 +123,7 @@ static struct mutex sd_mtx SHAREDBSS_ATTR;
static struct semaphore data_done SHAREDBSS_ATTR;
static volatile unsigned int transfer_error[NUM_DRIVES];
/* align on cache line size */
static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
__attribute__((aligned(32)));
static void sd_card_mux(int card_no)
@ -397,7 +397,7 @@ static int sd_init_card(const int card_no)
SDHC_RESP_FMT_1, &currcard->rca);
if (ret < 0)
{
dbgprintf("SD_SEND_RELATIVE_ADDR failed");
dbgprintf("SD_SEND_RELATIVE_ADDR failed");
return -1;
}
@ -559,7 +559,7 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
#ifdef HAVE_MULTIDRIVE
(void)card_no;
#endif
/* not applicable */
return false;
}
@ -597,17 +597,17 @@ static int sd_wait_for_state(unsigned int state)
}
}
static int sd_transfer_sectors(int card_no, unsigned long start,
static int sd_transfer_sectors(int card_no, sector_t start,
int count, void *buffer, bool write)
{
int ret;
unsigned long start_addr;
sector_t start_addr;
int dma_channel = -1;
bool use_direct_dma;
int count_per_dma;
unsigned long rel_addr;
dbgprintf("transfer %d %d %d", card_no, start, count);
dbgprintf("transfer %d %lu %d", card_no, start, count);
mutex_lock(&sd_mtx);
enable_controller(true);
@ -673,6 +673,7 @@ sd_transfer_retry:
if (!(card_info[card_no].ocr & SD_OCR_CARD_CAPACITY_STATUS))
start_addr *= SD_BLOCK_SIZE; /* not SDHC */
// XXX 64-bit
ret = sd_command(write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK,
start_addr, MMC_CMD_DCLR | MMC_CMD_DATA |
SDHC_RESP_FMT_1 | (write ? MMC_CMD_WRITE : 0),
@ -765,7 +766,7 @@ sd_transfer_error:
}
}
int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
int sd_read_sectors(IF_MD(int card_no,) sector_t start, int incount,
void* inbuf)
{
#ifndef HAVE_MULTIDRIVE
@ -774,7 +775,7 @@ int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
return sd_transfer_sectors(card_no, start, incount, inbuf, false);
}
int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count,
int sd_write_sectors(IF_MD(int card_no,) sector_t start, int count,
const void* outbuf)
{
#ifndef HAVE_MULTIDRIVE
@ -862,7 +863,7 @@ long sd_last_disk_activity(void)
}
tCardInfo *card_get_info_target(int card_no)
{
{
return &card_info[card_no];
}

View file

@ -209,9 +209,9 @@ int os_opendir_and_fd(const char *osdirname, DIR **osdirpp, int *osfdp)
}
/* do we really need this in the app? (in the sim, yes) */
void volume_size(IF_MV(int volume,) unsigned long *sizep, unsigned long *freep)
void volume_size(IF_MV(int volume,) sector_t *sizep, sector_t *freep)
{
unsigned long size = 0, free = 0;
sector_t size = 0, free = 0;
char volpath[MAX_PATH];
struct statfs fs;

View file

@ -472,7 +472,7 @@ int os_modtime(const char *path, time_t modtime)
int os_volume_path(IF_MV(int volume, ) char *buffer, size_t bufsize);
void volume_size(IF_MV(int volume,) unsigned long *sizep, unsigned long *freep)
void volume_size(IF_MV(int volume,) sector_t *sizep, sector_t *freep)
{
ULARGE_INTEGER free = { .QuadPart = 0 },
size = { .QuadPart = 0 };

View file

@ -84,7 +84,7 @@ struct nand_param
*
*/
static volatile unsigned long nand_address;
static volatile sector_t nand_address;
#define NAND_DATAPORT (nand_address)
#define NAND_ADDRPORT (nand_address+0x10000)
#define NAND_COMMPORT (nand_address+0x08000)
@ -111,7 +111,7 @@ static volatile unsigned long nand_address;
static struct nand_info* chip_info = NULL;
static struct nand_info* banks[4];
static unsigned int nr_banks = 1;
static unsigned long bank_size;
static sector_t bank_size;
static struct nand_param internal_param;
static struct mutex nand_mtx;
#ifdef USE_DMA
@ -282,7 +282,7 @@ static void jz_rs_correct(unsigned char *dat, int idx, int mask)
/*
* Read oob
*/
static int jz_nand_read_oob(unsigned long page_addr, unsigned char *buf, int size)
static int jz_nand_read_oob(sector_t page_addr, unsigned char *buf, int size)
{
struct nand_param *nandp = &internal_param;
int page_size, row_cycle, bus_width;
@ -338,7 +338,7 @@ static int jz_nand_read_oob(unsigned long page_addr, unsigned char *buf, int siz
* page - page number within a block: 0, 1, 2, ...
* dst - pointer to target buffer
*/
static int jz_nand_read_page(unsigned long page_addr, unsigned char *dst)
static int jz_nand_read_page(sector_t page_addr, unsigned char *dst)
{
struct nand_param *nandp = &internal_param;
int page_size, oob_size;
@ -611,7 +611,7 @@ int nand_init(void)
return res;
}
static inline int read_sector(unsigned long start, unsigned int count,
static inline int read_sector(sector_t start, unsigned int count,
void* buf, unsigned int chip_size)
{
register int ret;
@ -627,14 +627,14 @@ static inline int read_sector(unsigned long start, unsigned int count,
return ret;
}
int nand_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
int nand_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf)
{
#ifdef HAVE_MULTIDRIVE
(void)drive;
#endif
int ret = 0;
unsigned int i, _count, chip_size = chip_info->page_size;
unsigned long _start;
sector_t _start;
logf("start");
mutex_lock(&nand_mtx);
@ -670,7 +670,7 @@ int nand_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* bu
}
/* TODO */
int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf)
int nand_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf)
{
(void)start;
(void)count;

View file

@ -110,7 +110,7 @@ struct nand_param {
static struct nand_info* chip_info = NULL;
static struct nand_info* bank;
static unsigned long nand_size;
static sector_t nand_size;
static struct nand_param internal_param;
static struct mutex nand_mtx;
#ifdef USE_DMA
@ -281,7 +281,7 @@ static void jz_rs_correct(unsigned char *dat, int idx, int mask)
/*
* Read oob
*/
static int jz_nand_read_oob(unsigned long page_addr, unsigned char *buf, int size)
static int jz_nand_read_oob(sector_t page_addr, unsigned char *buf, int size)
{
struct nand_param *nandp = &internal_param;
int page_size, row_cycle, bus_width;
@ -337,7 +337,7 @@ static int jz_nand_read_oob(unsigned long page_addr, unsigned char *buf, int siz
* page - page number within a block: 0, 1, 2, ...
* dst - pointer to target buffer
*/
static int jz_nand_read_page(unsigned long page_addr, unsigned char *dst)
static int jz_nand_read_page(sector_t page_addr, unsigned char *dst)
{
struct nand_param *nandp = &internal_param;
int page_size, oob_size;
@ -532,7 +532,7 @@ int nand_init(void)
return res;
}
static inline int read_sector(unsigned long start, unsigned int count,
static inline int read_sector(sector_t start, unsigned int count,
void* buf, unsigned int chip_size)
{
register int ret;
@ -548,7 +548,7 @@ static inline int read_sector(unsigned long start, unsigned int count,
return ret;
}
static inline int write_sector(unsigned long start, unsigned int count,
static inline int write_sector(sector_t start, unsigned int count,
const void* buf, unsigned int chip_size)
{
int ret = 0;
@ -563,14 +563,14 @@ static inline int write_sector(unsigned long start, unsigned int count,
return ret;
}
int nand_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
int nand_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf)
{
#ifdef HAVE_MULTIDRIVE
(void)drive;
#endif
int ret = 0;
unsigned int _count, chip_size = chip_info->page_size;
unsigned long _start;
sector_t _start;
logf("start");
mutex_lock(&nand_mtx);
@ -590,14 +590,14 @@ int nand_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* bu
return ret;
}
int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf)
int nand_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf)
{
#ifdef HAVE_MULTIDRIVE
(void)drive;
#endif
int ret = 0;
unsigned int _count, chip_size = chip_info->page_size;
unsigned long _start;
sector_t _start;
logf("start");
mutex_lock(&nand_mtx);

View file

@ -42,7 +42,6 @@ static struct mutex sd_mtx;
static int use_4bit;
static int num_6;
static int sd2_0;
//#define SD_DMA_ENABLE
#define SD_DMA_INTERRUPT 0
@ -598,7 +597,7 @@ static int jz_sd_transmit_data(struct sd_request *req)
static inline unsigned int jz_sd_calc_clkrt(unsigned int rate)
{
unsigned int clkrt;
unsigned int clk_src = sd2_0 ? SD_CLOCK_HIGH : SD_CLOCK_FAST;
unsigned int clk_src = card.sd2plus ? SD_CLOCK_HIGH : SD_CLOCK_FAST;
clkrt = 0;
while (rate < clk_src)
@ -716,7 +715,7 @@ static int jz_sd_exec_cmd(struct sd_request *request)
events = SD_EVENT_RX_DATA_DONE;
break;
case 6:
case SD_SWITCH_FUNC:
if (num_6 < 2)
{
#if defined(SD_DMA_ENABLE)
@ -1086,7 +1085,6 @@ static int sd_init_card_state(struct sd_request *request)
(request->response[3+i*4]<< 8) | request->response[4+i*4]);
sd_parse_csd(&card);
sd2_0 = (card_extract_bits(card.csd, 127, 2) == 1);
logf("CSD: %08lx%08lx%08lx%08lx", card.csd[0], card.csd[1], card.csd[2], card.csd[3]);
DEBUG("SD card is ready");
@ -1155,7 +1153,7 @@ static int sd_select_card(void)
if (retval)
return retval;
if (sd2_0)
if (card.sd2plus)
{
retval = sd_read_switch(&request);
if (!retval)
@ -1188,7 +1186,6 @@ static int __sd_init_device(void)
/* Initialise card data as blank */
memset(&card, 0, sizeof(tCardInfo));
sd2_0 = 0;
num_6 = 0;
use_4bit = 0;
@ -1250,7 +1247,7 @@ static inline void sd_stop_transfer(void)
mutex_unlock(&sd_mtx);
}
int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
int sd_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf)
{
#ifdef HAVE_MULTIDRIVE
(void)drive;
@ -1276,7 +1273,8 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
if ((retval = sd_unpack_r1(&request, &r1)))
goto err;
if (sd2_0)
// XXX 64-bit
if (card.sd2plus)
{
sd_send_cmd(&request, SD_READ_MULTIPLE_BLOCK, start,
count, SD_BLOCK_SIZE, RESPONSE_R1, buf);
@ -1292,19 +1290,18 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
goto err;
}
last_disk_activity = current_tick;
sd_simple_cmd(&request, SD_STOP_TRANSMISSION, 0, RESPONSE_R1B);
if ((retval = sd_unpack_r1(&request, &r1)))
goto err;
err:
last_disk_activity = current_tick;
sd_stop_transfer();
return retval;
}
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf)
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf)
{
#ifdef HAVE_MULTIDRIVE
(void)drive;
@ -1330,7 +1327,8 @@ int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, const voi
if ((retval = sd_unpack_r1(&request, &r1)))
goto err;
if (sd2_0)
// XXX 64-bit
if (card.sd2plus)
{
sd_send_cmd(&request, SD_WRITE_MULTIPLE_BLOCK, start,
count, SD_BLOCK_SIZE, RESPONSE_R1,

View file

@ -57,8 +57,6 @@ static struct semaphore sd_wakeup[NUM_DRIVES];
static int use_4bit[NUM_DRIVES];
static int num_6[NUM_DRIVES];
static int sd2_0[NUM_DRIVES];
//#define DEBUG(x...) logf(x)
#define DEBUG(x, ...)
@ -698,7 +696,7 @@ static inline unsigned int jz_sd_calc_clkrt(const int drive, unsigned int rate)
unsigned int clkrt = 0;
unsigned int clk_src = cpu_frequency / __cpm_get_mscdiv(); /* MSC_CLK */
if (!sd2_0[drive] && rate > SD_CLOCK_FAST)
if (!card[drive].sd2plus && rate > SD_CLOCK_FAST)
rate = SD_CLOCK_FAST;
while (rate < clk_src)
@ -1192,7 +1190,6 @@ static int sd_init_card_state(const int drive, struct sd_request *request)
(request->response[3+i*4]<< 8) | request->response[4+i*4]);
sd_parse_csd(&card[drive]);
sd2_0[drive] = (card_extract_bits(card[drive].csd, 127, 2) == 1);
logf("CSD: %08lx%08lx%08lx%08lx", card[drive].csd[0], card[drive].csd[1], card[drive].csd[2], card[drive].csd[3]);
DEBUG("SD card is ready");
@ -1261,7 +1258,7 @@ static int sd_select_card(const int drive)
if (retval)
return retval;
if (sd2_0[drive])
if (card[drive].sd2plus)
{
retval = sd_read_switch(drive, &request);
if (!retval)
@ -1292,7 +1289,6 @@ static int __sd_init_device(const int drive)
/* Initialise card data as blank */
memset(&card[drive], 0, sizeof(tCardInfo));
sd2_0[drive] = 0;
num_6[drive] = 0;
use_4bit[drive] = 0;
active[drive] = 0;
@ -1402,7 +1398,7 @@ static inline void sd_stop_transfer(const int drive)
mutex_unlock(&sd_mtx[drive]);
}
int sd_transfer_sectors(IF_MD(const int drive,) unsigned long start, int count, void* buf, bool write)
int sd_transfer_sectors(IF_MD(const int drive,) sector_t start, int count, void* buf, bool write)
{
struct sd_request request;
struct sd_response_r1 r1;
@ -1427,11 +1423,12 @@ int sd_transfer_sectors(IF_MD(const int drive,) unsigned long start, int count,
if ((retval = sd_unpack_r1(&request, &r1)))
goto err;
// XXX 64-bit
sd_send_cmd(drive, &request,
(count > 1) ?
(write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK) :
(write ? SD_WRITE_BLOCK : SD_READ_SINGLE_BLOCK),
sd2_0[drive] ? start : (start * SD_BLOCK_SIZE),
card[drive].sd2plus ? start : (start * SD_BLOCK_SIZE),
count, SD_BLOCK_SIZE, RESPONSE_R1, buf);
if ((retval = sd_unpack_r1(&request, &r1)))
goto err;
@ -1451,12 +1448,12 @@ err:
return retval;
}
int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
int sd_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf)
{
return sd_transfer_sectors(IF_MD(drive,) start, count, buf, false);
}
int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf)
int sd_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf)
{
return sd_transfer_sectors(IF_MD(drive,) start, count, (void*)buf, true);
}

View file

@ -844,7 +844,7 @@ int msc_cmd_send_csd(msc_drv* d)
d->cardinfo.csd[i] = req.response[i];
sd_parse_csd(&d->cardinfo);
if((req.response[0] >> 30) == 1)
if(d->cardinfo.sd2plus)
d->driver_flags |= MSC_DF_V2_CARD;
return 0;

View file

@ -51,7 +51,7 @@ static int sd_init_card(msc_drv* d)
}
static int sd_transfer(msc_drv* d, bool write,
unsigned long start, int count, void* buf)
sector_t start, int count, void* buf)
{
int status = -1;
@ -114,6 +114,7 @@ static int sd_transfer(msc_drv* d, bool write,
: SD_READ_MULTIPLE_BLOCK;
}
// XXX 64-bit
if(d->driver_flags & MSC_DF_V2_CARD)
req.argument = start;
else
@ -142,14 +143,14 @@ static int sd_transfer(msc_drv* d, bool write,
return status;
}
int sd_read_sectors(IF_MD(int drive,) unsigned long start,
int sd_read_sectors(IF_MD(int drive,) sector_t start,
int count, void* buf)
{
return sd_transfer(sd_to_msc[IF_MD_DRV(drive)], false,
start, count, buf);
}
int sd_write_sectors(IF_MD(int drive,) unsigned long start,
int sd_write_sectors(IF_MD(int drive,) sector_t start,
int count, const void* buf)
{
return sd_transfer(sd_to_msc[IF_MD_DRV(drive)], true,