hw/sd: Use sdbus_read_data() instead of sdbus_read_byte() when possible
Use the recently added sdbus_read_data() to read multiple bytes at once, instead of looping calling sdbus_read_byte(). Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20200814092346.21825-8-f4bug@amsat.org>
This commit is contained in:
parent
6505a91a77
commit
618e0be1ba
@ -337,9 +337,7 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s,
|
|||||||
|
|
||||||
/* Read from SD bus */
|
/* Read from SD bus */
|
||||||
} else {
|
} else {
|
||||||
for (uint32_t i = 0; i < buf_bytes; i++) {
|
sdbus_read_data(&s->sdbus, buf, buf_bytes);
|
||||||
buf[i] = sdbus_read_byte(&s->sdbus);
|
|
||||||
}
|
|
||||||
cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
|
cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
|
||||||
buf, buf_bytes);
|
buf, buf_bytes);
|
||||||
}
|
}
|
||||||
@ -518,10 +516,8 @@ static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset,
|
|||||||
break;
|
break;
|
||||||
case REG_SD_FIFO: /* Read/Write FIFO */
|
case REG_SD_FIFO: /* Read/Write FIFO */
|
||||||
if (sdbus_data_ready(&s->sdbus)) {
|
if (sdbus_data_ready(&s->sdbus)) {
|
||||||
res = sdbus_read_byte(&s->sdbus);
|
sdbus_read_data(&s->sdbus, &res, sizeof(uint32_t));
|
||||||
res |= sdbus_read_byte(&s->sdbus) << 8;
|
le32_to_cpus(&res);
|
||||||
res |= sdbus_read_byte(&s->sdbus) << 16;
|
|
||||||
res |= sdbus_read_byte(&s->sdbus) << 24;
|
|
||||||
allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
|
allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
|
||||||
allwinner_sdhost_auto_stop(s);
|
allwinner_sdhost_auto_stop(s);
|
||||||
allwinner_sdhost_update_irq(s);
|
allwinner_sdhost_update_irq(s);
|
||||||
|
@ -151,11 +151,8 @@ static uint64_t memcard_read(void *opaque, hwaddr addr,
|
|||||||
if (!s->enabled) {
|
if (!s->enabled) {
|
||||||
r = 0xffffffff;
|
r = 0xffffffff;
|
||||||
} else {
|
} else {
|
||||||
r = 0;
|
sdbus_read_data(&s->sdbus, &r, sizeof(r));
|
||||||
r |= sdbus_read_byte(&s->sdbus) << 24;
|
be32_to_cpus(&r);
|
||||||
r |= sdbus_read_byte(&s->sdbus) << 16;
|
|
||||||
r |= sdbus_read_byte(&s->sdbus) << 8;
|
|
||||||
r |= sdbus_read_byte(&s->sdbus);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R_CLK2XDIV:
|
case R_CLK2XDIV:
|
||||||
|
@ -399,8 +399,6 @@ static void sdhci_end_transfer(SDHCIState *s)
|
|||||||
/* Fill host controller's read buffer with BLKSIZE bytes of data from card */
|
/* Fill host controller's read buffer with BLKSIZE bytes of data from card */
|
||||||
static void sdhci_read_block_from_card(SDHCIState *s)
|
static void sdhci_read_block_from_card(SDHCIState *s)
|
||||||
{
|
{
|
||||||
int index = 0;
|
|
||||||
uint8_t data;
|
|
||||||
const uint16_t blk_size = s->blksize & BLOCK_SIZE_MASK;
|
const uint16_t blk_size = s->blksize & BLOCK_SIZE_MASK;
|
||||||
|
|
||||||
if ((s->trnmod & SDHC_TRNS_MULTI) &&
|
if ((s->trnmod & SDHC_TRNS_MULTI) &&
|
||||||
@ -408,12 +406,9 @@ static void sdhci_read_block_from_card(SDHCIState *s)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index = 0; index < blk_size; index++) {
|
if (!FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
|
||||||
data = sdbus_read_byte(&s->sdbus);
|
/* Device is not in tuning */
|
||||||
if (!FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
|
sdbus_read_data(&s->sdbus, s->fifo_buffer, blk_size);
|
||||||
/* Device is not in tuning */
|
|
||||||
s->fifo_buffer[index] = data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
|
if (FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
|
||||||
@ -574,7 +569,7 @@ static void sdhci_write_dataport(SDHCIState *s, uint32_t value, unsigned size)
|
|||||||
static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
|
static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
|
||||||
{
|
{
|
||||||
bool page_aligned = false;
|
bool page_aligned = false;
|
||||||
unsigned int n, begin;
|
unsigned int begin;
|
||||||
const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
|
const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
|
||||||
uint32_t boundary_chk = 1 << (((s->blksize & ~BLOCK_SIZE_MASK) >> 12) + 12);
|
uint32_t boundary_chk = 1 << (((s->blksize & ~BLOCK_SIZE_MASK) >> 12) + 12);
|
||||||
uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);
|
uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);
|
||||||
@ -596,9 +591,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
|
|||||||
SDHC_DAT_LINE_ACTIVE;
|
SDHC_DAT_LINE_ACTIVE;
|
||||||
while (s->blkcnt) {
|
while (s->blkcnt) {
|
||||||
if (s->data_count == 0) {
|
if (s->data_count == 0) {
|
||||||
for (n = 0; n < block_size; n++) {
|
sdbus_read_data(&s->sdbus, s->fifo_buffer, block_size);
|
||||||
s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
begin = s->data_count;
|
begin = s->data_count;
|
||||||
if (((boundary_count + begin) < block_size) && page_aligned) {
|
if (((boundary_count + begin) < block_size) && page_aligned) {
|
||||||
@ -662,13 +655,10 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
|
|||||||
/* single block SDMA transfer */
|
/* single block SDMA transfer */
|
||||||
static void sdhci_sdma_transfer_single_block(SDHCIState *s)
|
static void sdhci_sdma_transfer_single_block(SDHCIState *s)
|
||||||
{
|
{
|
||||||
int n;
|
|
||||||
uint32_t datacnt = s->blksize & BLOCK_SIZE_MASK;
|
uint32_t datacnt = s->blksize & BLOCK_SIZE_MASK;
|
||||||
|
|
||||||
if (s->trnmod & SDHC_TRNS_READ) {
|
if (s->trnmod & SDHC_TRNS_READ) {
|
||||||
for (n = 0; n < datacnt; n++) {
|
sdbus_read_data(&s->sdbus, s->fifo_buffer, datacnt);
|
||||||
s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus);
|
|
||||||
}
|
|
||||||
dma_memory_write(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt);
|
dma_memory_write(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt);
|
||||||
} else {
|
} else {
|
||||||
dma_memory_read(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt);
|
dma_memory_read(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt);
|
||||||
@ -731,7 +721,7 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
|
|||||||
|
|
||||||
static void sdhci_do_adma(SDHCIState *s)
|
static void sdhci_do_adma(SDHCIState *s)
|
||||||
{
|
{
|
||||||
unsigned int n, begin, length;
|
unsigned int begin, length;
|
||||||
const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
|
const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
|
||||||
ADMADescr dscr = {};
|
ADMADescr dscr = {};
|
||||||
int i;
|
int i;
|
||||||
@ -765,9 +755,7 @@ static void sdhci_do_adma(SDHCIState *s)
|
|||||||
if (s->trnmod & SDHC_TRNS_READ) {
|
if (s->trnmod & SDHC_TRNS_READ) {
|
||||||
while (length) {
|
while (length) {
|
||||||
if (s->data_count == 0) {
|
if (s->data_count == 0) {
|
||||||
for (n = 0; n < block_size; n++) {
|
sdbus_read_data(&s->sdbus, s->fifo_buffer, block_size);
|
||||||
s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
begin = s->data_count;
|
begin = s->data_count;
|
||||||
if ((length + begin) < block_size) {
|
if ((length + begin) < block_size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user