[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 24/30] spapr: make IOMMU translation go through IOMM
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 24/30] spapr: make IOMMU translation go through IOMMUTLBEntry |
Date: |
Tue, 21 May 2013 12:57:25 +0200 |
The next step is to introduce the translation code that will be used for
IOMMU MemoryRegions, but still do the actual translation in a DMAContext.
Acked-by: David Gibson <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/ppc/spapr_iommu.c | 59 ++++++++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 25 deletions(-)
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 7a507e0..f6d74fe 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -68,15 +68,8 @@ static sPAPRTCETable *spapr_tce_find_by_liobn(uint32_t liobn)
return NULL;
}
-static int spapr_tce_translate(DMAContext *dma,
- dma_addr_t addr,
- hwaddr *paddr,
- hwaddr *len,
- DMADirection dir)
+static IOMMUTLBEntry spapr_tce_translate_iommu(sPAPRTCETable *tcet, hwaddr
addr)
{
- sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma);
- enum sPAPRTCEAccess access = (dir == DMA_DIRECTION_FROM_DEVICE)
- ? SPAPR_TCE_WO : SPAPR_TCE_RO;
uint64_t tce;
#ifdef DEBUG_TCE
@@ -85,9 +78,12 @@ static int spapr_tce_translate(DMAContext *dma,
#endif
if (tcet->bypass) {
- *paddr = addr;
- *len = (hwaddr)-1;
- return 0;
+ return (IOMMUTLBEntry) {
+ .iova = 0,
+ .translated_addr = 0,
+ .addr_mask = ~(hwaddr)0,
+ .perm = IOMMU_RW,
+ };
}
/* Check if we are in bound */
@@ -95,28 +91,41 @@ static int spapr_tce_translate(DMAContext *dma,
#ifdef DEBUG_TCE
fprintf(stderr, "spapr_tce_translate out of bounds\n");
#endif
- return -EFAULT;
+ return (IOMMUTLBEntry) { .perm = IOMMU_NONE };
}
tce = tcet->table[addr >> SPAPR_TCE_PAGE_SHIFT].tce;
- /* Check TCE */
- if (!(tce & access)) {
- return -EPERM;
- }
+#ifdef DEBUG_TCE
+ fprintf(stderr, " -> *paddr=0x%llx, *len=0x%llx\n",
+ (tce & ~SPAPR_TCE_PAGE_MASK), SPAPR_TCE_PAGE_MASK + 1);
+#endif
- /* How much til end of page ? */
- *len = ((~addr) & SPAPR_TCE_PAGE_MASK) + 1;
+ return (IOMMUTLBEntry) {
+ .iova = addr & ~SPAPR_TCE_PAGE_MASK,
+ .translated_addr = tce & ~SPAPR_TCE_PAGE_MASK,
+ .addr_mask = SPAPR_TCE_PAGE_MASK,
+ .perm = tce,
+ };
+}
- /* Translate */
- *paddr = (tce & ~SPAPR_TCE_PAGE_MASK) |
- (addr & SPAPR_TCE_PAGE_MASK);
+static int spapr_tce_translate(DMAContext *dma,
+ dma_addr_t addr,
+ hwaddr *paddr,
+ hwaddr *len,
+ DMADirection dir)
+ {
+ sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma);
+ bool is_write = (dir == DMA_DIRECTION_FROM_DEVICE);
+ IOMMUTLBEntry entry = spapr_tce_translate_iommu(tcet, addr);
-#ifdef DEBUG_TCE
- fprintf(stderr, " -> *paddr=0x" TARGET_FMT_plx ", *len=0x"
- TARGET_FMT_plx "\n", *paddr, *len);
-#endif
+ if (!(entry.perm & (1 << is_write))) {
+ return -EPERM;
+ }
+ /* Translate */
+ *paddr = entry.translated_addr | (addr & entry.addr_mask);
+ *len = (addr | entry.addr_mask) - addr + 1;
return 0;
}
--
1.8.1.4
- Re: [Qemu-devel] [PATCH 17/30] memory: add address_space_translate, (continued)
- [Qemu-devel] [PATCH 19/30] memory: Introduce address_space_lookup_region, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 20/30] memory: iommu support, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 21/30] memory: Add iommu map/unmap notifiers, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 22/30] vfio: abort if an emulated iommu is used, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 23/30] spapr: convert TCE API to use an opaque type, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 24/30] spapr: make IOMMU translation go through IOMMUTLBEntry,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 25/30] spapr: use memory core for iommu support, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 26/30] dma: eliminate old-style IOMMU support, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 27/30] pci: use memory core for iommu support, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 28/30] spapr_vio: take care of creating our own AddressSpace/DMAContext, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 30/30] memory: give name to every AddressSpace, Paolo Bonzini, 2013/05/21
- [Qemu-devel] [PATCH 29/30] dma: eliminate DMAContext, Paolo Bonzini, 2013/05/21