diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2013-04-10 17:30:48 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2013-06-20 16:32:47 +0200 |
commit | 2b7dc949e241ac2b069d2d6183c1346cad792662 (patch) | |
tree | 036435406f192d463a234f7df11678dc61bec7c4 /hw/ppc/spapr_iommu.c | |
parent | 06d985f5d844d07d31b4dada20f4ff6cf0d6ff4a (diff) | |
download | qemu-2b7dc949e241ac2b069d2d6183c1346cad792662.zip qemu-2b7dc949e241ac2b069d2d6183c1346cad792662.tar.gz qemu-2b7dc949e241ac2b069d2d6183c1346cad792662.tar.bz2 |
spapr: convert TCE API to use an opaque type
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>
Diffstat (limited to 'hw/ppc/spapr_iommu.c')
-rw-r--r-- | hw/ppc/spapr_iommu.c | 54 |
1 files changed, 22 insertions, 32 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); } |