From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>,
liu ping fan <qemulist@gmail.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Blue Swirl <blauwirbel@gmail.com>
Subject: [Qemu-devel] [PATCH v1 20/23] dma: make dma access its own address space
Date: Sun, 7 Oct 2012 14:38:25 +0200 [thread overview]
Message-ID: <1349613508-22980-21-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1349613508-22980-1-git-send-email-avi@redhat.com>
Instead of accessing the cpu address space, use an address space
configured by the caller.
Eventually all dma functionality will be folded into AddressSpace,
but we have to start from something.
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
dma-helpers.c | 25 ++++++++++++-------------
dma.h | 17 ++++++++---------
hw/Makefile.objs | 5 +++--
hw/spapr_iommu.c | 3 ++-
4 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/dma-helpers.c b/dma-helpers.c
index 433d8b2..3f09dcb 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -14,7 +14,8 @@
/* #define DEBUG_IOMMU */
-static void do_dma_memory_set(dma_addr_t addr, uint8_t c, dma_addr_t len)
+static void do_dma_memory_set(AddressSpace *as,
+ dma_addr_t addr, uint8_t c, dma_addr_t len)
{
#define FILLBUF_SIZE 512
uint8_t fillbuf[FILLBUF_SIZE];
@@ -23,7 +24,7 @@ static void do_dma_memory_set(dma_addr_t addr, uint8_t c, dma_addr_t len)
memset(fillbuf, c, FILLBUF_SIZE);
while (len > 0) {
l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
- cpu_physical_memory_rw(addr, fillbuf, l, true);
+ address_space_rw(as, addr, fillbuf, l, true);
len -= l;
addr += l;
}
@@ -36,7 +37,7 @@ int dma_memory_set(DMAContext *dma, dma_addr_t addr, uint8_t c, dma_addr_t len)
if (dma_has_iommu(dma)) {
return iommu_dma_memory_set(dma, addr, c, len);
}
- do_dma_memory_set(addr, c, len);
+ do_dma_memory_set(dma->as, addr, c, len);
return 0;
}
@@ -332,8 +333,7 @@ int iommu_dma_memory_rw(DMAContext *dma, dma_addr_t addr,
plen = len;
}
- cpu_physical_memory_rw(paddr, buf, plen,
- dir == DMA_DIRECTION_FROM_DEVICE);
+ address_space_rw(dma->as, paddr, buf, plen, dir == DMA_DIRECTION_FROM_DEVICE);
len -= plen;
addr += plen;
@@ -366,7 +366,7 @@ int iommu_dma_memory_set(DMAContext *dma, dma_addr_t addr, uint8_t c,
plen = len;
}
- do_dma_memory_set(paddr, c, plen);
+ do_dma_memory_set(dma->as, paddr, c, plen);
len -= plen;
addr += plen;
@@ -375,13 +375,14 @@ int iommu_dma_memory_set(DMAContext *dma, dma_addr_t addr, uint8_t c,
return 0;
}
-void dma_context_init(DMAContext *dma, DMATranslateFunc translate,
+void dma_context_init(DMAContext *dma, AddressSpace *as, DMATranslateFunc translate,
DMAMapFunc map, DMAUnmapFunc unmap)
{
#ifdef DEBUG_IOMMU
fprintf(stderr, "dma_context_init(%p, %p, %p, %p)\n",
dma, translate, map, unmap);
#endif
+ dma->as = as;
dma->translate = translate;
dma->map = map;
dma->unmap = unmap;
@@ -407,14 +408,13 @@ void *iommu_dma_memory_map(DMAContext *dma, dma_addr_t addr, dma_addr_t *len,
/*
* If this is true, the virtual region is contiguous,
* but the translated physical region isn't. We just
- * clamp *len, much like cpu_physical_memory_map() does.
+ * clamp *len, much like address_space_map() does.
*/
if (plen < *len) {
*len = plen;
}
- buf = cpu_physical_memory_map(paddr, &plen,
- dir == DMA_DIRECTION_FROM_DEVICE);
+ buf = address_space_map(dma->as, paddr, &plen, dir == DMA_DIRECTION_FROM_DEVICE);
*len = plen;
return buf;
@@ -428,8 +428,7 @@ void iommu_dma_memory_unmap(DMAContext *dma, void *buffer, dma_addr_t len,
return;
}
- cpu_physical_memory_unmap(buffer, len,
- dir == DMA_DIRECTION_FROM_DEVICE,
- access_len);
+ address_space_unmap(dma->as, buffer, len, dir == DMA_DIRECTION_FROM_DEVICE,
+ access_len);
}
diff --git a/dma.h b/dma.h
index f35c4b6..94cf806 100644
--- a/dma.h
+++ b/dma.h
@@ -11,6 +11,7 @@
#define DMA_H
#include <stdio.h>
+#include "memory.h"
#include "hw/hw.h"
#include "block.h"
#include "kvm.h"
@@ -61,6 +62,7 @@ typedef void DMAUnmapFunc(DMAContext *dma,
dma_addr_t access_len);
struct DMAContext {
+ AddressSpace *as;
DMATranslateFunc *translate;
DMAMapFunc *map;
DMAUnmapFunc *unmap;
@@ -93,7 +95,7 @@ static inline void dma_barrier(DMAContext *dma, DMADirection dir)
static inline bool dma_has_iommu(DMAContext *dma)
{
- return !!dma;
+ return dma && dma->translate;
}
/* Checks that the given range of addresses is valid for DMA. This is
@@ -120,8 +122,7 @@ static inline int dma_memory_rw_relaxed(DMAContext *dma, dma_addr_t addr,
{
if (!dma_has_iommu(dma)) {
/* Fast-path for no IOMMU */
- cpu_physical_memory_rw(addr, buf, len,
- dir == DMA_DIRECTION_FROM_DEVICE);
+ address_space_rw(dma->as, addr, buf, len, dir == DMA_DIRECTION_FROM_DEVICE);
return 0;
} else {
return iommu_dma_memory_rw(dma, addr, buf, len, dir);
@@ -179,8 +180,7 @@ static inline void *dma_memory_map(DMAContext *dma,
target_phys_addr_t xlen = *len;
void *p;
- p = cpu_physical_memory_map(addr, &xlen,
- dir == DMA_DIRECTION_FROM_DEVICE);
+ p = address_space_map(dma->as, addr, &xlen, dir == DMA_DIRECTION_FROM_DEVICE);
*len = xlen;
return p;
} else {
@@ -196,9 +196,8 @@ static inline void dma_memory_unmap(DMAContext *dma,
DMADirection dir, dma_addr_t access_len)
{
if (!dma_has_iommu(dma)) {
- cpu_physical_memory_unmap(buffer, (target_phys_addr_t)len,
- dir == DMA_DIRECTION_FROM_DEVICE,
- access_len);
+ address_space_unmap(dma->as, buffer, (target_phys_addr_t)len,
+ dir == DMA_DIRECTION_FROM_DEVICE, access_len);
} else {
iommu_dma_memory_unmap(dma, buffer, len, dir, access_len);
}
@@ -242,7 +241,7 @@ DEFINE_LDST_DMA(q, q, 64, be);
#undef DEFINE_LDST_DMA
-void dma_context_init(DMAContext *dma, DMATranslateFunc translate,
+void dma_context_init(DMAContext *dma, AddressSpace *as, DMATranslateFunc translate,
DMAMapFunc map, DMAUnmapFunc unmap);
struct ScatterGatherEntry {
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index ecdbe44..9e4ec6e 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -169,8 +169,9 @@ common-obj-$(CONFIG_MAX111X) += max111x.o
common-obj-$(CONFIG_DS1338) += ds1338.o
common-obj-y += i2c.o smbus.o smbus_eeprom.o
common-obj-y += eeprom93xx.o
-common-obj-y += scsi-disk.o cdrom.o hd-geometry.o block-common.o
-common-obj-y += scsi-generic.o scsi-bus.o
+common-obj-y += cdrom.o hd-geometry.o block-common.o
+common-obj-y += scsi-generic.o
+hw-obj-y += scsi-disk.o scsi-bus.o
common-obj-y += hid.o
common-obj-$(CONFIG_SSI) += ssi.o
common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
diff --git a/hw/spapr_iommu.c b/hw/spapr_iommu.c
index 53b7317..54798a3 100644
--- a/hw/spapr_iommu.c
+++ b/hw/spapr_iommu.c
@@ -21,6 +21,7 @@
#include "qdev.h"
#include "kvm_ppc.h"
#include "dma.h"
+#include "exec-memory.h"
#include "hw/spapr.h"
@@ -117,7 +118,7 @@ DMAContext *spapr_tce_new_dma_context(uint32_t liobn, size_t window_size)
}
tcet = g_malloc0(sizeof(*tcet));
- dma_context_init(&tcet->dma, spapr_tce_translate, NULL, NULL);
+ dma_context_init(&tcet->dma, &address_space_memory, spapr_tce_translate, NULL, NULL);
tcet->liobn = liobn;
tcet->window_size = window_size;
--
1.7.12
next prev parent reply other threads:[~2012-10-07 12:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-07 12:38 [Qemu-devel] [PATCH v1 00/23] Integrate DMA into the memory API Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 01/23] memory: rename 'exec-obsolete.h' Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 02/23] vhost: use MemoryListener filtering to only monitor RAM address space Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 03/23] kvm: use separate MemoryListeners for memory and I/O Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 04/23] xen_pt: " Avi Kivity
2012-10-08 12:18 ` Stefano Stabellini
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 05/23] memory: prepare AddressSpace for exporting Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 06/23] memory: export AddressSpace Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 07/23] memory: maintain a list of address spaces Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 08/23] memory: provide defaults for MemoryListener operations Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 09/23] memory: use new MEMORY_LISTENER_DEFAULT_OPS Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 10/23] vfio: " Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 11/23] xen_pt: " Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 12/23] kvm: " Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 13/23] xen: " Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 14/23] memory: manage coalesced mmio via a MemoryListener Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 15/23] memory: move address_space_memory and address_space_io out of memory core Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 16/23] memory: move tcg flush into a tcg memory listener Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 17/23] memory: use AddressSpace for MemoryListener filtering Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 18/23] s390: avoid reaching into memory core internals Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 19/23] memory: per-AddressSpace dispatch Avi Kivity
2012-10-07 12:38 ` Avi Kivity [this message]
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 21/23] memory: add address_space_destroy() Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 22/23] pci: give each device its own address space Avi Kivity
2012-10-07 12:38 ` [Qemu-devel] [PATCH v1 23/23] pci: honor PCI_COMMAND_MASTER Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349613508-22980-21-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=blauwirbel@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).