diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index 00205cb..1c9b346 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -194,11 +194,12 @@ extern int iommu_tce_clear_param_check(struct iommu_table *tbl,
 extern int iommu_tce_put_param_check(struct iommu_table *tbl,
 		unsigned long ioba, unsigned long tce);
 extern int iommu_tce_build(struct iommu_table *tbl, unsigned long entry,
-		unsigned long hwaddr, enum dma_data_direction direction);
+		unsigned long *hpas, unsigned long npages, bool realmode);
 extern unsigned long iommu_clear_tce(struct iommu_table *tbl,
 		unsigned long entry);
 extern int iommu_clear_tces_and_put_pages(struct iommu_table *tbl,
-		unsigned long entry, unsigned long pages);
+		unsigned long entry, unsigned long pages,
+		bool realmode);
 extern int iommu_put_tce_user_mode(struct iommu_table *tbl,
 		unsigned long entry, unsigned long tce);
 
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 25fda58..8771b73 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1018,7 +1018,8 @@ unsigned long iommu_clear_tce(struct iommu_table *tbl, unsigned long entry)
 EXPORT_SYMBOL_GPL(iommu_clear_tce);
 
 int iommu_clear_tces_and_put_pages(struct iommu_table *tbl,
-		unsigned long entry, unsigned long pages)
+		unsigned long entry, unsigned long pages,
+		bool realmode)
 {
 	unsigned long oldtce;
 	struct page *page;
@@ -1046,15 +1047,16 @@ EXPORT_SYMBOL_GPL(iommu_clear_tces_and_put_pages);
  * tce_build converts it to a physical address.
  */
 int iommu_tce_build(struct iommu_table *tbl, unsigned long entry,
-		unsigned long hwaddr, enum dma_data_direction direction)
+		unsigned long *hpas, unsigned long npages, bool realmode)
 {
 	int ret = -EBUSY;
 	unsigned long oldtce;
 	struct iommu_pool *pool = get_pool(tbl, entry);
+	enum dma_data_direction direction = iommu_tce_direction(*hpas);
 
 	spin_lock(&(pool->lock));
 
-	ret = ppc_md.tce_build(tbl, entry, 1, hwaddr, &oldtce,
+	ret = ppc_md.tce_build(tbl, entry, 1, *hpas, &oldtce,
 			direction, NULL);
 
 	if (oldtce & (TCE_PCI_WRITE | TCE_PCI_READ))
@@ -1089,7 +1091,7 @@ int iommu_put_tce_user_mode(struct iommu_table *tbl, unsigned long entry,
 	hwaddr = (unsigned long) page_address(page) + offset;
 	hwaddr |= tce & (TCE_PCI_READ | TCE_PCI_WRITE);
 
-	ret = iommu_tce_build(tbl, entry, hwaddr, direction);
+	ret = iommu_tce_build(tbl, entry, &hwaddr, 1, direction);
 	if (ret)
 		put_page(page);
 
@@ -1124,7 +1126,7 @@ int iommu_take_ownership(struct iommu_table *tbl)
 
 	if (!ret)
 		iommu_clear_tces_and_put_pages(tbl, tbl->it_offset,
-				tbl->it_size);
+				tbl->it_size, false);
 
 	for (i = 0; i < tbl->nr_pools; i++)
 		spin_unlock(&tbl->pools[i].lock);
@@ -1138,7 +1140,8 @@ void iommu_release_ownership(struct iommu_table *tbl)
 {
 	unsigned long flags, i, sz = (tbl->it_size + 7) >> 3;
 
-	iommu_clear_tces_and_put_pages(tbl, tbl->it_offset, tbl->it_size);
+	iommu_clear_tces_and_put_pages(tbl, tbl->it_offset, tbl->it_size,
+			false);
 
 	spin_lock_irqsave(&tbl->large_pool.lock, flags);
 	for (i = 0; i < tbl->nr_pools; i++)
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 63aa697..2d65a7d 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -895,7 +895,8 @@ static long pnv_pci_ioda2_ddw_remove(struct spapr_tce_iommu_group *data,
 
 	pr_info("Removing huge 64bit DMA window\n");
 
-	iommu_clear_tces_and_put_pages(tbl, tbl->it_offset, tbl->it_size);
+	iommu_clear_tces_and_put_pages(tbl, tbl->it_offset, tbl->it_size,
+			false);
 
 	pe->tce64_active = false;
 
diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 8f992de..ff1b29e 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -283,7 +283,8 @@ static long tce_iommu_ioctl(void *iommu_data,
 		}
 		if (ret)
 			iommu_clear_tces_and_put_pages(tbl,
-					param.iova >> tbl->it_page_shift, i);
+					param.iova >> tbl->it_page_shift, i,
+					false);
 
 		iommu_flush_tce(tbl);
 
@@ -330,7 +331,8 @@ static long tce_iommu_ioctl(void *iommu_data,
 
 		ret = iommu_clear_tces_and_put_pages(tbl,
 				param.iova >> tbl->it_page_shift,
-				param.size >> tbl->it_page_shift);
+				param.size >> tbl->it_page_shift,
+				false);
 		iommu_flush_tce(tbl);
 
 		return ret;
