};
struct sPAPRTCETable {
+ /* temporary until everyone has its own AddressSpace */
DMAContext dma;
+ AddressSpace as;
+
uint32_t liobn;
uint32_t window_size;
sPAPRTCE *table;
bool bypass;
int fd;
+ MemoryRegion iommu;
QLIST_ENTRY(sPAPRTCETable) list;
};
return NULL;
}
-static IOMMUTLBEntry spapr_tce_translate_iommu(sPAPRTCETable *tcet, hwaddr addr)
+static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr)
{
+ sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu);
uint64_t tce;
#ifdef DEBUG_TCE
};
}
-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);
- 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;
-}
+static MemoryRegionIOMMUOps spapr_iommu_ops = {
+ .translate = spapr_tce_translate_iommu,
+};
sPAPRTCETable *spapr_tce_new_table(uint32_t liobn, size_t window_size)
{
}
tcet = g_malloc0(sizeof(*tcet));
- dma_context_init(&tcet->dma, &address_space_memory, spapr_tce_translate, NULL, NULL);
-
tcet->liobn = liobn;
tcet->window_size = window_size;
"table @ %p, fd=%d\n", tcet, liobn, tcet->table, tcet->fd);
#endif
+ memory_region_init_iommu(&tcet->iommu, &spapr_iommu_ops,
+ "iommu-spapr", UINT64_MAX);
+ address_space_init(&tcet->as, &tcet->iommu);
+ dma_context_init(&tcet->dma, &tcet->as, NULL, NULL, NULL);
+
QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list);
return tcet;
return &tcet->dma;
}
+MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet)
+{
+ return &tcet->iommu;
+}
+
void spapr_tce_set_bypass(sPAPRTCETable *tcet, bool bypass)
{
tcet->bypass = bypass;
target_ulong tce)
{
sPAPRTCE *tcep;
+ IOMMUTLBEntry entry;
if (ioba >= tcet->window_size) {
hcall_dprintf("spapr_vio_put_tce on out-of-bounds IOBA 0x"
tcep = tcet->table + (ioba >> SPAPR_TCE_PAGE_SHIFT);
tcep->tce = tce;
+ entry.target_as = &address_space_memory,
+ entry.iova = ioba & ~SPAPR_TCE_PAGE_MASK;
+ entry.translated_addr = tce & ~SPAPR_TCE_PAGE_MASK;
+ entry.addr_mask = SPAPR_TCE_PAGE_MASK;
+ entry.perm = tce;
+ memory_region_notify_iommu(&tcet->iommu, entry);
+
return H_SUCCESS;
}