From: Bin Meng <[email protected]>
Signed-off-by: Bin Meng <[email protected]>
Message-ID: <[email protected]>
[PMD: Split of bigger patch]
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
hw/sd/sdhci.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index ad370407c6e..93e1687dbe5 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -598,6 +598,11 @@ static void sdhci_write_dataport(SDHCIState *s, uint32_t
value, unsigned size)
* Single DMA data transfer
*/
+static uint64_t sdhci_sdma_address(SDHCIState *s)
+{
+ return s->sdmasysad;
+}
+
static void sdhci_advance_sdma_address(SDHCIState *s, uint32_t bytes)
{
s->sdmasysad += bytes;
@@ -610,7 +615,8 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
unsigned int begin;
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_count = boundary_chk - (s->sdmasysad % boundary_chk);
+ uint64_t sdma_address = sdhci_sdma_address(s);
+ uint32_t boundary_count = boundary_chk - (sdma_address % boundary_chk);
if (!(s->trnmod & SDHC_TRNS_BLK_CNT_EN) || !s->blkcnt) {
qemu_log_mask(LOG_UNIMP, "infinite transfer is not supported\n");
@@ -622,7 +628,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
* possible stop at page boundary if initial address is not page aligned,
* allow them to work properly
*/
- if ((s->sdmasysad % boundary_chk) == 0) {
+ if ((sdma_address % boundary_chk) == 0) {
page_aligned = true;
}
@@ -644,7 +650,8 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
s->blkcnt--;
}
}
- dma_memory_write(s->dma_as, s->sdmasysad, &s->fifo_buffer[begin],
+ dma_memory_write(s->dma_as, sdhci_sdma_address(s),
+ &s->fifo_buffer[begin],
s->data_count - begin, MEMTXATTRS_UNSPECIFIED);
sdhci_advance_sdma_address(s, s->data_count - begin);
if (s->data_count == block_size) {
@@ -665,7 +672,8 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
s->data_count = block_size;
boundary_count -= block_size - begin;
}
- dma_memory_read(s->dma_as, s->sdmasysad, &s->fifo_buffer[begin],
+ dma_memory_read(s->dma_as, sdhci_sdma_address(s),
+ &s->fifo_buffer[begin],
s->data_count - begin, MEMTXATTRS_UNSPECIFIED);
sdhci_advance_sdma_address(s, s->data_count - begin);
if (s->data_count == block_size) {
@@ -700,10 +708,12 @@ static void sdhci_sdma_transfer_single_block(SDHCIState
*s)
if (s->trnmod & SDHC_TRNS_READ) {
sdbus_read_data(&s->sdbus, s->fifo_buffer, datacnt);
- dma_memory_write(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt,
+ dma_memory_write(s->dma_as, sdhci_sdma_address(s),
+ s->fifo_buffer, datacnt,
MEMTXATTRS_UNSPECIFIED);
} else {
- dma_memory_read(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt,
+ dma_memory_read(s->dma_as, sdhci_sdma_address(s),
+ s->fifo_buffer, datacnt,
MEMTXATTRS_UNSPECIFIED);
sdbus_write_data(&s->sdbus, s->fifo_buffer, datacnt);
}
--
2.53.0