mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 14:41:31 +00:00
mmc: Add multi-block read support to the generic mmc driver
This patch adds multi-block read support for the generic MMC driver. Large reads are broken into chunks of 65535 blocks to ensure that the code works with controllers having a 16 bit block counter. This patch results in a significant performance improvement. Time to read a 45 MB file went from 36 seconds to 9 seconds on Overo Signed-off-by: Steve Sakoman <steve.sakoman@linaro.org> Tested-by: Steve Sakoman <steve.sakoman@linaro.org> Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>
This commit is contained in:
parent
def412b661
commit
4a1a06bc8b
1 changed files with 39 additions and 71 deletions
|
@ -154,110 +154,78 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
|
||||||
return blkcnt;
|
return blkcnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mmc_read_block(struct mmc *mmc, void *dst, uint blocknum)
|
int mmc_read_blocks(struct mmc *mmc, void *dst, ulong start, lbaint_t blkcnt)
|
||||||
{
|
{
|
||||||
struct mmc_cmd cmd;
|
struct mmc_cmd cmd;
|
||||||
struct mmc_data data;
|
struct mmc_data data;
|
||||||
|
|
||||||
cmd.cmdidx = MMC_CMD_READ_SINGLE_BLOCK;
|
if (blkcnt > 1)
|
||||||
|
cmd.cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK;
|
||||||
|
else
|
||||||
|
cmd.cmdidx = MMC_CMD_READ_SINGLE_BLOCK;
|
||||||
|
|
||||||
if (mmc->high_capacity)
|
if (mmc->high_capacity)
|
||||||
cmd.cmdarg = blocknum;
|
cmd.cmdarg = start;
|
||||||
else
|
else
|
||||||
cmd.cmdarg = blocknum * mmc->read_bl_len;
|
cmd.cmdarg = start * mmc->read_bl_len;
|
||||||
|
|
||||||
cmd.resp_type = MMC_RSP_R1;
|
cmd.resp_type = MMC_RSP_R1;
|
||||||
cmd.flags = 0;
|
cmd.flags = 0;
|
||||||
|
|
||||||
data.dest = dst;
|
data.dest = dst;
|
||||||
data.blocks = 1;
|
data.blocks = blkcnt;
|
||||||
data.blocksize = mmc->read_bl_len;
|
data.blocksize = mmc->read_bl_len;
|
||||||
data.flags = MMC_DATA_READ;
|
data.flags = MMC_DATA_READ;
|
||||||
|
|
||||||
return mmc_send_cmd(mmc, &cmd, &data);
|
if (mmc_send_cmd(mmc, &cmd, &data))
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size)
|
if (blkcnt > 1) {
|
||||||
{
|
cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
|
||||||
char *buffer;
|
cmd.cmdarg = 0;
|
||||||
int i;
|
cmd.resp_type = MMC_RSP_R1b;
|
||||||
int blklen = mmc->read_bl_len;
|
cmd.flags = 0;
|
||||||
int startblock = lldiv(src, mmc->read_bl_len);
|
if (mmc_send_cmd(mmc, &cmd, NULL)) {
|
||||||
int endblock = lldiv(src + size - 1, mmc->read_bl_len);
|
printf("mmc fail to send stop cmd\n");
|
||||||
int err = 0;
|
return 0;
|
||||||
|
}
|
||||||
/* Make a buffer big enough to hold all the blocks we might read */
|
|
||||||
buffer = malloc(blklen);
|
|
||||||
|
|
||||||
if (!buffer) {
|
|
||||||
printf("Could not allocate buffer for MMC read!\n");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We always do full block reads from the card */
|
return blkcnt;
|
||||||
err = mmc_set_blocklen(mmc, mmc->read_bl_len);
|
|
||||||
|
|
||||||
if (err)
|
|
||||||
goto free_buffer;
|
|
||||||
|
|
||||||
for (i = startblock; i <= endblock; i++) {
|
|
||||||
int segment_size;
|
|
||||||
int offset;
|
|
||||||
|
|
||||||
err = mmc_read_block(mmc, buffer, i);
|
|
||||||
|
|
||||||
if (err)
|
|
||||||
goto free_buffer;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The first block may not be aligned, so we
|
|
||||||
* copy from the desired point in the block
|
|
||||||
*/
|
|
||||||
offset = (src & (blklen - 1));
|
|
||||||
segment_size = MIN(blklen - offset, size);
|
|
||||||
|
|
||||||
memcpy(dst, buffer + offset, segment_size);
|
|
||||||
|
|
||||||
dst += segment_size;
|
|
||||||
src += segment_size;
|
|
||||||
size -= segment_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
free_buffer:
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
|
static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
|
||||||
{
|
{
|
||||||
int err;
|
lbaint_t cur, blocks_todo = blkcnt;
|
||||||
int i;
|
|
||||||
struct mmc *mmc = find_mmc_device(dev_num);
|
|
||||||
|
|
||||||
|
if (blkcnt == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
struct mmc *mmc = find_mmc_device(dev_num);
|
||||||
if (!mmc)
|
if (!mmc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((start + blkcnt) > mmc->block_dev.lba) {
|
if ((start + blkcnt) > mmc->block_dev.lba) {
|
||||||
printf("MMC: block number 0x%lx exceeds max(0x%lx)",
|
printf("MMC: block number 0x%lx exceeds max(0x%lx)\n",
|
||||||
start + blkcnt, mmc->block_dev.lba);
|
start + blkcnt, mmc->block_dev.lba);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* We always do full block reads from the card */
|
|
||||||
err = mmc_set_blocklen(mmc, mmc->read_bl_len);
|
|
||||||
|
|
||||||
if (err) {
|
if (mmc_set_blocklen(mmc, mmc->read_bl_len))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = start; i < start + blkcnt; i++, dst += mmc->read_bl_len) {
|
do {
|
||||||
err = mmc_read_block(mmc, dst, i);
|
/*
|
||||||
|
* The 65535 constraint comes from some hardware has
|
||||||
if (err) {
|
* only 16 bit width block number counter
|
||||||
printf("block read failed: %d\n", err);
|
*/
|
||||||
return i - start;
|
cur = (blocks_todo > 65535) ? 65535 : blocks_todo;
|
||||||
}
|
if(mmc_read_blocks(mmc, dst, start, cur) != cur)
|
||||||
}
|
return 0;
|
||||||
|
blocks_todo -= cur;
|
||||||
|
start += cur;
|
||||||
|
dst += cur * mmc->read_bl_len;
|
||||||
|
} while (blocks_todo > 0);
|
||||||
|
|
||||||
return blkcnt;
|
return blkcnt;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue