From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, jan.kiszka@gmail.com,
David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCH 23/30] spapr: convert TCE API to use an opaque type
Date: Tue, 21 May 2013 12:57:24 +0200 [thread overview]
Message-ID: <1369133851-1894-24-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1369133851-1894-1-git-send-email-pbonzini@redhat.com>
The TCE table is currently returned as a DMAContext, and non-type-safe
APIs are called later passing back the DMAContext. Since we want to move
away from DMAContext, use an opaque type instead, and add an accessor
to retrieve the DMAContext from it.
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/ppc/spapr_iommu.c | 54 ++++++++++++++++++---------------------------
hw/ppc/spapr_pci.c | 8 +++----
hw/ppc/spapr_vio.c | 13 ++++++-----
include/hw/pci-host/spapr.h | 2 +-
include/hw/ppc/spapr.h | 12 +++++-----
include/hw/ppc/spapr_vio.h | 1 +
6 files changed, 42 insertions(+), 48 deletions(-)
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index e1fe941..7a507e0 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -36,8 +36,6 @@ enum sPAPRTCEAccess {
SPAPR_TCE_RW = 3,
};
-typedef struct sPAPRTCETable sPAPRTCETable;
-
struct sPAPRTCETable {
DMAContext dma;
uint32_t liobn;
@@ -122,7 +120,7 @@ static int spapr_tce_translate(DMAContext *dma,
return 0;
}
-DMAContext *spapr_tce_new_dma_context(uint32_t liobn, size_t window_size)
+sPAPRTCETable *spapr_tce_new_table(uint32_t liobn, size_t window_size)
{
sPAPRTCETable *tcet;
@@ -155,43 +153,40 @@ DMAContext *spapr_tce_new_dma_context(uint32_t liobn, size_t window_size)
}
#ifdef DEBUG_TCE
- fprintf(stderr, "spapr_iommu: New TCE table, liobn=0x%x, context @ %p, "
- "table @ %p, fd=%d\n", liobn, &tcet->dma, tcet->table, tcet->fd);
+ fprintf(stderr, "spapr_iommu: New TCE table @ %p, liobn=0x%x, "
+ "table @ %p, fd=%d\n", tcet, liobn, tcet->table, tcet->fd);
#endif
QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list);
- return &tcet->dma;
+ return tcet;
}
-void spapr_tce_free(DMAContext *dma)
+void spapr_tce_free(sPAPRTCETable *tcet)
{
+ QLIST_REMOVE(tcet, list);
- if (dma) {
- sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma);
-
- QLIST_REMOVE(tcet, list);
-
- if (!kvm_enabled() ||
- (kvmppc_remove_spapr_tce(tcet->table, tcet->fd,
- tcet->window_size) != 0)) {
- g_free(tcet->table);
- }
-
- g_free(tcet);
+ if (!kvm_enabled() ||
+ (kvmppc_remove_spapr_tce(tcet->table, tcet->fd,
+ tcet->window_size) != 0)) {
+ g_free(tcet->table);
}
+
+ g_free(tcet);
}
-void spapr_tce_set_bypass(DMAContext *dma, bool bypass)
+DMAContext *spapr_tce_get_dma(sPAPRTCETable *tcet)
{
- sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma);
+ return &tcet->dma;
+}
+void spapr_tce_set_bypass(sPAPRTCETable *tcet, bool bypass)
+{
tcet->bypass = bypass;
}
-void spapr_tce_reset(DMAContext *dma)
+void spapr_tce_reset(sPAPRTCETable *tcet)
{
- sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma);
size_t table_size = (tcet->window_size >> SPAPR_TCE_PAGE_SHIFT)
* sizeof(sPAPRTCE);
@@ -277,17 +272,12 @@ int spapr_dma_dt(void *fdt, int node_off, const char *propname,
}
int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
- DMAContext *iommu)
+ sPAPRTCETable *tcet)
{
- if (!iommu) {
+ if (!tcet) {
return 0;
}
- if (iommu->translate == spapr_tce_translate) {
- sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, iommu);
- return spapr_dma_dt(fdt, node_off, propname,
- tcet->liobn, 0, tcet->window_size);
- }
-
- return -1;
+ return spapr_dma_dt(fdt, node_off, propname,
+ tcet->liobn, 0, tcet->window_size);
}
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 62ff323..eb64a8f 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -511,7 +511,7 @@ static DMAContext *spapr_pci_dma_context_fn(PCIBus *bus, void *opaque,
{
sPAPRPHBState *phb = opaque;
- return phb->dma;
+ return spapr_tce_get_dma(phb->tcet);
}
static int spapr_phb_init(SysBusDevice *s)
@@ -646,8 +646,8 @@ static int spapr_phb_init(SysBusDevice *s)
sphb->dma_window_start = 0;
sphb->dma_window_size = 0x40000000;
- sphb->dma = spapr_tce_new_dma_context(sphb->dma_liobn, sphb->dma_window_size);
- if (!sphb->dma) {
+ sphb->tcet = spapr_tce_new_table(sphb->dma_liobn, sphb->dma_window_size);
+ if (!sphb->tcet) {
fprintf(stderr, "Unable to create TCE table for %s\n", sphb->dtbusname);
return -1;
}
@@ -676,7 +676,7 @@ static void spapr_phb_reset(DeviceState *qdev)
sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
/* Reset the IOMMU state */
- spapr_tce_reset(sphb->dma);
+ spapr_tce_reset(sphb->tcet);
}
static Property spapr_phb_properties[] = {
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index 1405c32..a06ac94 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -145,7 +145,7 @@ static int vio_make_devnode(VIOsPAPRDevice *dev,
}
}
- ret = spapr_tcet_dma_dt(fdt, node_off, "ibm,my-dma-window", dev->dma);
+ ret = spapr_tcet_dma_dt(fdt, node_off, "ibm,my-dma-window", dev->tcet);
if (ret < 0) {
return ret;
}
@@ -319,8 +319,8 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)
static void spapr_vio_quiesce_one(VIOsPAPRDevice *dev)
{
- if (dev->dma) {
- spapr_tce_reset(dev->dma);
+ if (dev->tcet) {
+ spapr_tce_reset(dev->tcet);
}
free_crq(dev);
}
@@ -345,12 +345,12 @@ static void rtas_set_tce_bypass(sPAPREnvironment *spapr, uint32_t token,
return;
}
- if (!dev->dma) {
+ if (!dev->tcet) {
rtas_st(rets, 0, -3);
return;
}
- spapr_tce_set_bypass(dev->dma, !!enable);
+ spapr_tce_set_bypass(dev->tcet, !!enable);
rtas_st(rets, 0, 0);
}
@@ -457,7 +457,8 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
if (pc->rtce_window_size) {
uint32_t liobn = SPAPR_VIO_BASE_LIOBN | dev->reg;
- dev->dma = spapr_tce_new_dma_context(liobn, pc->rtce_window_size);
+ dev->tcet = spapr_tce_new_table(liobn, pc->rtce_window_size);
+ dev->dma = spapr_tce_get_dma(dev->tcet);
}
return pc->init(dev);
diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h
index b21080c..653dd40 100644
--- a/include/hw/pci-host/spapr.h
+++ b/include/hw/pci-host/spapr.h
@@ -49,7 +49,7 @@ typedef struct sPAPRPHBState {
uint32_t dma_liobn;
uint64_t dma_window_start;
uint64_t dma_window_size;
- DMAContext *dma;
+ sPAPRTCETable *tcet;
struct {
uint32_t irq;
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 864bee9..e8d617b 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -342,17 +342,19 @@ typedef struct sPAPRTCE {
#define RTAS_ERROR_LOG_MAX 2048
+typedef struct sPAPRTCETable sPAPRTCETable;
void spapr_iommu_init(void);
void spapr_events_init(sPAPREnvironment *spapr);
void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
-DMAContext *spapr_tce_new_dma_context(uint32_t liobn, size_t window_size);
-void spapr_tce_free(DMAContext *dma);
-void spapr_tce_reset(DMAContext *dma);
-void spapr_tce_set_bypass(DMAContext *dma, bool bypass);
+sPAPRTCETable *spapr_tce_new_table(uint32_t liobn, size_t window_size);
+DMAContext *spapr_tce_get_dma(sPAPRTCETable *tcet);
+void spapr_tce_free(sPAPRTCETable *tcet);
+void spapr_tce_reset(sPAPRTCETable *tcet);
+void spapr_tce_set_bypass(sPAPRTCETable *tcet, bool bypass);
int spapr_dma_dt(void *fdt, int node_off, const char *propname,
uint32_t liobn, uint64_t window, uint32_t size);
int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
- DMAContext *dma);
+ sPAPRTCETable *tcet);
#endif /* !defined (__HW_SPAPR_H__) */
diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
index f98ec0a..56f2821 100644
--- a/include/hw/ppc/spapr_vio.h
+++ b/include/hw/ppc/spapr_vio.h
@@ -63,6 +63,7 @@ struct VIOsPAPRDevice {
uint32_t irq;
target_ulong signal_state;
VIOsPAPR_CRQ crq;
+ sPAPRTCETable *tcet;
DMAContext *dma;
};
--
1.8.1.4
next prev parent reply other threads:[~2013-05-21 10:58 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-21 10:57 [Qemu-devel] [PATCH 00/30] Introduction of IOMMUs into the memory API Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 01/30] exec: remove obsolete comment Paolo Bonzini
2013-05-21 11:36 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 02/30] exec: eliminate qemu_put_ram_ptr Paolo Bonzini
2013-05-21 11:38 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 03/30] exec: make qemu_get_ram_ptr private Paolo Bonzini
2013-05-21 11:38 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 04/30] exec: eliminate stq_phys_notdirty Paolo Bonzini
2013-05-23 17:32 ` Peter Maydell
2013-05-23 19:18 ` Anthony Liguori
2013-05-23 19:22 ` Paolo Bonzini
2013-05-23 23:14 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 05/30] memory: assert that PhysPageEntry's ptr does not overflow Paolo Bonzini
2013-05-23 17:36 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 06/30] memory: allow memory_region_find() to run on non-root memory regions Paolo Bonzini
2013-05-23 17:52 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 07/30] memory: Replace open-coded memory_region_is_romd Paolo Bonzini
2013-05-21 11:54 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 08/30] memory: Rename readable flag to romd_mode Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 09/30] memory: do not duplicate memory_region_destructor_none Paolo Bonzini
2013-05-21 11:55 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 10/30] memory: make memory_global_sync_dirty_bitmap take an AddressSpace Paolo Bonzini
2013-05-21 11:56 ` Peter Maydell
2013-05-23 1:05 ` David Gibson
2013-05-21 10:57 ` [Qemu-devel] [PATCH 11/30] memory: fix address space initialization/destruction Paolo Bonzini
2013-05-21 11:58 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 12/30] s390x: reduce TARGET_PHYS_ADDR_SPACE_BITS to 62 Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 13/30] memory: limit sections in the radix tree to the actual address space size Paolo Bonzini
2013-05-21 12:02 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 14/30] memory: create FlatView for new address spaces Paolo Bonzini
2013-05-21 12:03 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 15/30] memory: add address_space_valid Paolo Bonzini
2013-05-23 12:05 ` David Gibson
2013-05-23 14:22 ` Jan Kiszka
2013-05-23 14:43 ` Paolo Bonzini
2013-05-23 18:04 ` Peter Maydell
2013-05-24 6:13 ` Jan Kiszka
2013-05-24 10:28 ` Jan Kiszka
2013-05-24 10:50 ` Peter Maydell
2013-05-24 11:02 ` Jan Kiszka
2013-05-24 8:02 ` Paolo Bonzini
2013-05-24 10:52 ` Peter Maydell
2013-05-24 12:58 ` Paolo Bonzini
2013-05-24 13:27 ` Peter Maydell
2013-05-24 13:33 ` Paolo Bonzini
2013-05-24 13:38 ` Peter Maydell
2013-05-25 3:44 ` David Gibson
2013-05-25 9:23 ` Peter Maydell
2013-05-26 13:02 ` David Gibson
2013-05-21 10:57 ` [Qemu-devel] [PATCH 16/30] memory: clean up phys_page_find Paolo Bonzini
2013-05-23 18:06 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 17/30] memory: add address_space_translate Paolo Bonzini
2013-05-23 7:09 ` liu ping fan
2013-05-23 9:59 ` Paolo Bonzini
2013-05-23 13:06 ` liu ping fan
2013-05-23 13:17 ` Paolo Bonzini
2013-05-23 18:15 ` Peter Maydell
2013-05-25 6:40 ` Jan Kiszka
2013-05-25 7:47 ` Paolo Bonzini
2013-05-25 10:19 ` Jan Kiszka
2013-05-25 11:20 ` Paolo Bonzini
2013-05-25 11:30 ` Jan Kiszka
2013-05-26 8:56 ` Paolo Bonzini
2013-05-26 9:02 ` Jan Kiszka
2013-05-27 7:20 ` Paolo Bonzini
2013-05-27 7:23 ` Jan Kiszka
2013-05-27 8:19 ` Paolo Bonzini
2013-05-27 8:37 ` Jan Kiszka
2013-05-27 10:33 ` Peter Maydell
2013-05-27 10:45 ` Paolo Bonzini
2013-05-27 11:33 ` Peter Maydell
2013-05-26 9:01 ` Paolo Bonzini
2013-05-26 9:12 ` Jan Kiszka
2013-05-26 18:23 ` Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 18/30] memory: add return value to address_space_rw/read/write Paolo Bonzini
2013-05-23 18:18 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 19/30] memory: Introduce address_space_lookup_region Paolo Bonzini
2013-05-23 18:19 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 20/30] memory: iommu support Paolo Bonzini
2013-05-23 18:24 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 21/30] memory: Add iommu map/unmap notifiers Paolo Bonzini
2013-05-23 18:27 ` Peter Maydell
2013-05-23 19:24 ` Paolo Bonzini
2013-05-29 4:08 ` David Gibson
2013-05-21 10:57 ` [Qemu-devel] [PATCH 22/30] vfio: abort if an emulated iommu is used Paolo Bonzini
2013-05-21 10:57 ` Paolo Bonzini [this message]
2013-05-21 10:57 ` [Qemu-devel] [PATCH 24/30] spapr: make IOMMU translation go through IOMMUTLBEntry Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 25/30] spapr: use memory core for iommu support Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 26/30] dma: eliminate old-style IOMMU support Paolo Bonzini
2013-05-23 18:31 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 27/30] pci: use memory core for iommu support Paolo Bonzini
2013-05-23 18:36 ` Peter Maydell
2013-05-23 21:22 ` Michael S. Tsirkin
2013-05-21 10:57 ` [Qemu-devel] [PATCH 28/30] spapr_vio: take care of creating our own AddressSpace/DMAContext Paolo Bonzini
2013-05-21 10:57 ` [Qemu-devel] [PATCH 29/30] dma: eliminate DMAContext Paolo Bonzini
2013-05-23 18:40 ` Peter Maydell
2013-05-21 10:57 ` [Qemu-devel] [PATCH 30/30] memory: give name to every AddressSpace Paolo Bonzini
2013-05-23 18:46 ` Peter Maydell
2013-05-22 2:30 ` [Qemu-devel] [PATCH 00/30] Introduction of IOMMUs into the memory API Alexey Kardashevskiy
2013-05-22 9:24 ` Paolo Bonzini
2013-05-23 17:08 ` Paolo Bonzini
2013-05-23 17:25 ` Peter Maydell
2013-05-23 17:30 ` Paolo Bonzini
2013-05-23 18:47 ` Peter Maydell
2013-05-24 14:12 ` Alexey Kardashevskiy
2013-05-24 14:20 ` Paolo Bonzini
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=1369133851-1894-24-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=jan.kiszka@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).