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

@ -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];
}