[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/6] hw/sd/allwinner-sdhost: Do DMA accesses via DMA address spac
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 3/6] hw/sd/allwinner-sdhost: Do DMA accesses via DMA address space |
Date: |
Sun, 31 May 2020 19:54:22 +0200 |
The DMA operations should not use the CPU address space, but
the DMA address space. Add support for a DMA address space,
and replace the cpu_physical_memory API calls by equivalent
dma_memory_read/write calls.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/sd/allwinner-sdhost.h | 4 ++++
hw/sd/allwinner-sdhost.c | 36 ++++++++++++++++++++++++++------
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/include/hw/sd/allwinner-sdhost.h b/include/hw/sd/allwinner-sdhost.h
index d94606a853..ae1125c026 100644
--- a/include/hw/sd/allwinner-sdhost.h
+++ b/include/hw/sd/allwinner-sdhost.h
@@ -68,6 +68,10 @@ typedef struct AwSdHostState {
/** Maps I/O registers in physical memory */
MemoryRegion iomem;
+ /** DMA physical memory */
+ MemoryRegion *dma_mr;
+ AddressSpace dma_as;
+
/** Interrupt output signal to notify CPU */
qemu_irq irq;
diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
index f404e1fdb4..9a2b5fcaeb 100644
--- a/hw/sd/allwinner-sdhost.c
+++ b/hw/sd/allwinner-sdhost.c
@@ -21,7 +21,10 @@
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu/units.h"
+#include "qapi/error.h"
#include "sysemu/blockdev.h"
+#include "sysemu/dma.h"
+#include "hw/qdev-properties.h"
#include "hw/irq.h"
#include "hw/sd/allwinner-sdhost.h"
#include "migration/vmstate.h"
@@ -306,7 +309,7 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState
*s,
uint8_t buf[1024];
/* Read descriptor */
- cpu_physical_memory_read(desc_addr, desc, sizeof(*desc));
+ dma_memory_read(&s->dma_as, desc_addr, desc, sizeof(*desc));
if (desc->size == 0) {
desc->size = klass->max_desc_size;
} else if (desc->size > klass->max_desc_size) {
@@ -331,8 +334,9 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState
*s,
/* Write to SD bus */
if (is_write) {
- cpu_physical_memory_read((desc->addr & DESC_SIZE_MASK) + num_done,
- buf, buf_bytes);
+ dma_memory_read(&s->dma_as,
+ (desc->addr & DESC_SIZE_MASK) + num_done,
+ buf, buf_bytes);
for (uint32_t i = 0; i < buf_bytes; i++) {
sdbus_write_data(&s->sdbus, buf[i]);
@@ -343,15 +347,16 @@ static uint32_t
allwinner_sdhost_process_desc(AwSdHostState *s,
for (uint32_t i = 0; i < buf_bytes; i++) {
buf[i] = sdbus_read_data(&s->sdbus);
}
- cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
- buf, buf_bytes);
+ dma_memory_write(&s->dma_as,
+ (desc->addr & DESC_SIZE_MASK) + num_done,
+ buf, buf_bytes);
}
num_done += buf_bytes;
}
/* Clear hold flag and flush descriptor */
desc->status &= ~DESC_STATUS_HOLD;
- cpu_physical_memory_write(desc_addr, desc, sizeof(*desc));
+ dma_memory_write(&s->dma_as, desc_addr, desc, sizeof(*desc));
return num_done;
}
@@ -742,6 +747,17 @@ static void allwinner_sdhost_init(Object *obj)
sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
}
+static void allwinner_sdhost_realize(DeviceState *dev, Error **errp)
+{
+ AwSdHostState *s = AW_SDHOST(dev);
+
+ if (!s->dma_mr) {
+ error_setg(errp, "\"dma\" property must be provided.");
+ return;
+ }
+ address_space_init(&s->dma_as, s->dma_mr, "sdhost-dma");
+}
+
static void allwinner_sdhost_reset(DeviceState *dev)
{
AwSdHostState *s = AW_SDHOST(dev);
@@ -787,6 +803,12 @@ static void allwinner_sdhost_reset(DeviceState *dev)
s->status_crc = REG_SD_CRC_STA_RST;
}
+static Property allwinner_sdhost_properties[] = {
+ DEFINE_PROP_LINK("dma", AwSdHostState,
+ dma_mr, TYPE_MEMORY_REGION, MemoryRegion *),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void allwinner_sdhost_bus_class_init(ObjectClass *klass, void *data)
{
SDBusClass *sbc = SD_BUS_CLASS(klass);
@@ -798,7 +820,9 @@ static void allwinner_sdhost_class_init(ObjectClass *klass,
void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ device_class_set_props(dc, allwinner_sdhost_properties);
dc->reset = allwinner_sdhost_reset;
+ dc->realize = allwinner_sdhost_realize;
dc->vmsd = &vmstate_allwinner_sdhost;
}
--
2.21.3
- [PATCH 0/6] exec/memory: Rework some address and access size limits, Philippe Mathieu-Daudé, 2020/05/31
- [PATCH 1/6] target/s390x/mmu_helper: Use address_space_rw() in place, Philippe Mathieu-Daudé, 2020/05/31
- [PATCH 3/6] hw/sd/allwinner-sdhost: Do DMA accesses via DMA address space,
Philippe Mathieu-Daudé <=
- [PATCH 2/6] hw/dma/rc4030: Use DMA address space to do DMA accesses, Philippe Mathieu-Daudé, 2020/05/31
- [PATCH 4/6] exec/cpu-common: Do not restrict CPU to 32-bit memory access maximum, Philippe Mathieu-Daudé, 2020/05/31
- [PATCH 5/6] exec: Restrict 32-bit CPUs to 32-bit address space, Philippe Mathieu-Daudé, 2020/05/31
- [RFC PATCH 6/6] memory: Use CPU register size as default access_size_max, Philippe Mathieu-Daudé, 2020/05/31
- Re: [PATCH 0/6] exec/memory: Rework some address and access size limits, no-reply, 2020/05/31