aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/powerpc/include/asm/iommu.h7
-rw-r--r--arch/powerpc/kernel/iommu.c25
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c26
3 files changed, 57 insertions, 1 deletions
diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index 2c1d50792944..4554699aec02 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -64,6 +64,11 @@ struct iommu_table_ops {
64 long index, 64 long index,
65 unsigned long *hpa, 65 unsigned long *hpa,
66 enum dma_data_direction *direction); 66 enum dma_data_direction *direction);
67 /* Real mode */
68 int (*exchange_rm)(struct iommu_table *tbl,
69 long index,
70 unsigned long *hpa,
71 enum dma_data_direction *direction);
67#endif 72#endif
68 void (*clear)(struct iommu_table *tbl, 73 void (*clear)(struct iommu_table *tbl,
69 long index, long npages); 74 long index, long npages);
@@ -208,6 +213,8 @@ extern void iommu_del_device(struct device *dev);
208extern int __init tce_iommu_bus_notifier_init(void); 213extern int __init tce_iommu_bus_notifier_init(void);
209extern long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry, 214extern long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry,
210 unsigned long *hpa, enum dma_data_direction *direction); 215 unsigned long *hpa, enum dma_data_direction *direction);
216extern long iommu_tce_xchg_rm(struct iommu_table *tbl, unsigned long entry,
217 unsigned long *hpa, enum dma_data_direction *direction);
211#else 218#else
212static inline void iommu_register_group(struct iommu_table_group *table_group, 219static inline void iommu_register_group(struct iommu_table_group *table_group,
213 int pci_domain_number, 220 int pci_domain_number,
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 5f202a566ec5..685a4767b722 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1004,6 +1004,31 @@ long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry,
1004} 1004}
1005EXPORT_SYMBOL_GPL(iommu_tce_xchg); 1005EXPORT_SYMBOL_GPL(iommu_tce_xchg);
1006 1006
1007#ifdef CONFIG_PPC_BOOK3S_64
1008long iommu_tce_xchg_rm(struct iommu_table *tbl, unsigned long entry,
1009 unsigned long *hpa, enum dma_data_direction *direction)
1010{
1011 long ret;
1012
1013 ret = tbl->it_ops->exchange_rm(tbl, entry, hpa, direction);
1014
1015 if (!ret && ((*direction == DMA_FROM_DEVICE) ||
1016 (*direction == DMA_BIDIRECTIONAL))) {
1017 struct page *pg = realmode_pfn_to_page(*hpa >> PAGE_SHIFT);
1018
1019 if (likely(pg)) {
1020 SetPageDirty(pg);
1021 } else {
1022 tbl->it_ops->exchange_rm(tbl, entry, hpa, direction);
1023 ret = -EFAULT;
1024 }
1025 }
1026
1027 return ret;
1028}
1029EXPORT_SYMBOL_GPL(iommu_tce_xchg_rm);
1030#endif
1031
1007int iommu_take_ownership(struct iommu_table *tbl) 1032int iommu_take_ownership(struct iommu_table *tbl)
1008{ 1033{
1009 unsigned long flags, i, sz = (tbl->it_size + 7) >> 3; 1034 unsigned long flags, i, sz = (tbl->it_size + 7) >> 3;
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index e36738291c32..572e9c9f1ea0 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1860,6 +1860,17 @@ static int pnv_ioda1_tce_xchg(struct iommu_table *tbl, long index,
1860 1860
1861 return ret; 1861 return ret;
1862} 1862}
1863
1864static int pnv_ioda1_tce_xchg_rm(struct iommu_table *tbl, long index,
1865 unsigned long *hpa, enum dma_data_direction *direction)
1866{
1867 long ret = pnv_tce_xchg(tbl, index, hpa, direction);
1868
1869 if (!ret)
1870 pnv_pci_p7ioc_tce_invalidate(tbl, index, 1, true);
1871
1872 return ret;
1873}
1863#endif 1874#endif
1864 1875
1865static void pnv_ioda1_tce_free(struct iommu_table *tbl, long index, 1876static void pnv_ioda1_tce_free(struct iommu_table *tbl, long index,
@@ -1874,6 +1885,7 @@ static struct iommu_table_ops pnv_ioda1_iommu_ops = {
1874 .set = pnv_ioda1_tce_build, 1885 .set = pnv_ioda1_tce_build,
1875#ifdef CONFIG_IOMMU_API 1886#ifdef CONFIG_IOMMU_API
1876 .exchange = pnv_ioda1_tce_xchg, 1887 .exchange = pnv_ioda1_tce_xchg,
1888 .exchange_rm = pnv_ioda1_tce_xchg_rm,
1877#endif 1889#endif
1878 .clear = pnv_ioda1_tce_free, 1890 .clear = pnv_ioda1_tce_free,
1879 .get = pnv_tce_get, 1891 .get = pnv_tce_get,
@@ -1948,7 +1960,7 @@ static void pnv_pci_ioda2_tce_invalidate(struct iommu_table *tbl,
1948{ 1960{
1949 struct iommu_table_group_link *tgl; 1961 struct iommu_table_group_link *tgl;
1950 1962
1951 list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) { 1963 list_for_each_entry_lockless(tgl, &tbl->it_group_list, next) {
1952 struct pnv_ioda_pe *pe = container_of(tgl->table_group, 1964 struct pnv_ioda_pe *pe = container_of(tgl->table_group,
1953 struct pnv_ioda_pe, table_group); 1965 struct pnv_ioda_pe, table_group);
1954 struct pnv_phb *phb = pe->phb; 1966 struct pnv_phb *phb = pe->phb;
@@ -2004,6 +2016,17 @@ static int pnv_ioda2_tce_xchg(struct iommu_table *tbl, long index,
2004 2016
2005 return ret; 2017 return ret;
2006} 2018}
2019
2020static int pnv_ioda2_tce_xchg_rm(struct iommu_table *tbl, long index,
2021 unsigned long *hpa, enum dma_data_direction *direction)
2022{
2023 long ret = pnv_tce_xchg(tbl, index, hpa, direction);
2024
2025 if (!ret)
2026 pnv_pci_ioda2_tce_invalidate(tbl, index, 1, true);
2027
2028 return ret;
2029}
2007#endif 2030#endif
2008 2031
2009static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index, 2032static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index,
@@ -2024,6 +2047,7 @@ static struct iommu_table_ops pnv_ioda2_iommu_ops = {
2024 .set = pnv_ioda2_tce_build, 2047 .set = pnv_ioda2_tce_build,
2025#ifdef CONFIG_IOMMU_API 2048#ifdef CONFIG_IOMMU_API
2026 .exchange = pnv_ioda2_tce_xchg, 2049 .exchange = pnv_ioda2_tce_xchg,
2050 .exchange_rm = pnv_ioda2_tce_xchg_rm,
2027#endif 2051#endif
2028 .clear = pnv_ioda2_tce_free, 2052 .clear = pnv_ioda2_tce_free,
2029 .get = pnv_tce_get, 2053 .get = pnv_tce_get,