diff options
author | Alexey Kardashevskiy <aik@ozlabs.ru> | 2017-03-22 00:21:48 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2017-03-30 06:42:01 -0400 |
commit | a540aa56ba3d29084f28710c8b93cc9c3c422943 (patch) | |
tree | 265e8987fb9f37ede5fb9175dac3e26b62745ed8 | |
parent | 6b5c19c55266f6efd10ffac0e9f9f2b7aa420a58 (diff) |
powerpc/powernv/iommu: Add real mode version of iommu_table_ops::exchange()
In real mode, TCE tables are invalidated using special
cache-inhibited store instructions which are not available in
virtual mode
This defines and implements exchange_rm() callback. This does not
define set_rm/clear_rm/flush_rm callbacks as there is no user for those -
exchange/exchange_rm are only to be used by KVM for VFIO.
The exchange_rm callback is defined for IODA1/IODA2 powernv platforms.
This replaces list_for_each_entry_rcu with its lockless version as
from now on pnv_pci_ioda2_tce_invalidate() can be called in
the real mode too.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | arch/powerpc/include/asm/iommu.h | 7 | ||||
-rw-r--r-- | arch/powerpc/kernel/iommu.c | 25 | ||||
-rw-r--r-- | arch/powerpc/platforms/powernv/pci-ioda.c | 26 |
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); | |||
208 | extern int __init tce_iommu_bus_notifier_init(void); | 213 | extern int __init tce_iommu_bus_notifier_init(void); |
209 | extern long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry, | 214 | extern 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); |
216 | extern 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 |
212 | static inline void iommu_register_group(struct iommu_table_group *table_group, | 219 | static 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 | } |
1005 | EXPORT_SYMBOL_GPL(iommu_tce_xchg); | 1005 | EXPORT_SYMBOL_GPL(iommu_tce_xchg); |
1006 | 1006 | ||
1007 | #ifdef CONFIG_PPC_BOOK3S_64 | ||
1008 | long 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 | } | ||
1029 | EXPORT_SYMBOL_GPL(iommu_tce_xchg_rm); | ||
1030 | #endif | ||
1031 | |||
1007 | int iommu_take_ownership(struct iommu_table *tbl) | 1032 | int 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 | |||
1864 | static 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 | ||
1865 | static void pnv_ioda1_tce_free(struct iommu_table *tbl, long index, | 1876 | static 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 | |||
2020 | static 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 | ||
2009 | static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index, | 2032 | static 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, |