aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/Kconfig76
-rw-r--r--drivers/iommu/Makefile2
-rw-r--r--drivers/iommu/amd_iommu.c3
-rw-r--r--drivers/iommu/amd_iommu_init.c44
-rw-r--r--drivers/iommu/dmar.c2
-rw-r--r--drivers/iommu/exynos-iommu.c2
-rw-r--r--drivers/iommu/intel-iommu.c21
-rw-r--r--drivers/iommu/iommu.c66
-rw-r--r--drivers/iommu/shmobile-iommu.c395
-rw-r--r--drivers/iommu/shmobile-ipmmu.c136
-rw-r--r--drivers/iommu/shmobile-ipmmu.h34
-rw-r--r--drivers/iommu/tegra-gart.c4
-rw-r--r--drivers/iommu/tegra-smmu.c75
13 files changed, 803 insertions, 57 deletions
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index e39f9dbf297b..8fc1c7fa20b5 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -158,7 +158,7 @@ config TEGRA_IOMMU_GART
158 158
159config TEGRA_IOMMU_SMMU 159config TEGRA_IOMMU_SMMU
160 bool "Tegra SMMU IOMMU Support" 160 bool "Tegra SMMU IOMMU Support"
161 depends on ARCH_TEGRA_3x_SOC && TEGRA_AHB 161 depends on ARCH_TEGRA && TEGRA_AHB
162 select IOMMU_API 162 select IOMMU_API
163 help 163 help
164 Enables support for remapping discontiguous physical memory 164 Enables support for remapping discontiguous physical memory
@@ -187,4 +187,78 @@ config EXYNOS_IOMMU_DEBUG
187 187
188 Say N unless you need kernel log message for IOMMU debugging 188 Say N unless you need kernel log message for IOMMU debugging
189 189
190config SHMOBILE_IPMMU
191 bool
192
193config SHMOBILE_IPMMU_TLB
194 bool
195
196config SHMOBILE_IOMMU
197 bool "IOMMU for Renesas IPMMU/IPMMUI"
198 default n
199 depends on (ARM && ARCH_SHMOBILE)
200 select IOMMU_API
201 select ARM_DMA_USE_IOMMU
202 select SHMOBILE_IPMMU
203 select SHMOBILE_IPMMU_TLB
204 help
205 Support for Renesas IPMMU/IPMMUI. This option enables
206 remapping of DMA memory accesses from all of the IP blocks
207 on the ICB.
208
209 Warning: Drivers (including userspace drivers of UIO
210 devices) of the IP blocks on the ICB *must* use addresses
211 allocated from the IPMMU (iova) for DMA with this option
212 enabled.
213
214 If unsure, say N.
215
216choice
217 prompt "IPMMU/IPMMUI address space size"
218 default SHMOBILE_IOMMU_ADDRSIZE_2048MB
219 depends on SHMOBILE_IOMMU
220 help
221 This option sets IPMMU/IPMMUI address space size by
222 adjusting the 1st level page table size. The page table size
223 is calculated as follows:
224
225 page table size = number of page table entries * 4 bytes
226 number of page table entries = address space size / 1 MiB
227
228 For example, when the address space size is 2048 MiB, the
229 1st level page table size is 8192 bytes.
230
231 config SHMOBILE_IOMMU_ADDRSIZE_2048MB
232 bool "2 GiB"
233
234 config SHMOBILE_IOMMU_ADDRSIZE_1024MB
235 bool "1 GiB"
236
237 config SHMOBILE_IOMMU_ADDRSIZE_512MB
238 bool "512 MiB"
239
240 config SHMOBILE_IOMMU_ADDRSIZE_256MB
241 bool "256 MiB"
242
243 config SHMOBILE_IOMMU_ADDRSIZE_128MB
244 bool "128 MiB"
245
246 config SHMOBILE_IOMMU_ADDRSIZE_64MB
247 bool "64 MiB"
248
249 config SHMOBILE_IOMMU_ADDRSIZE_32MB
250 bool "32 MiB"
251
252endchoice
253
254config SHMOBILE_IOMMU_L1SIZE
255 int
256 default 8192 if SHMOBILE_IOMMU_ADDRSIZE_2048MB
257 default 4096 if SHMOBILE_IOMMU_ADDRSIZE_1024MB
258 default 2048 if SHMOBILE_IOMMU_ADDRSIZE_512MB
259 default 1024 if SHMOBILE_IOMMU_ADDRSIZE_256MB
260 default 512 if SHMOBILE_IOMMU_ADDRSIZE_128MB
261 default 256 if SHMOBILE_IOMMU_ADDRSIZE_64MB
262 default 128 if SHMOBILE_IOMMU_ADDRSIZE_32MB
263
190endif # IOMMU_SUPPORT 264endif # IOMMU_SUPPORT
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index f66b816d455c..ef0e5207ad69 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -13,3 +13,5 @@ obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
13obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o 13obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o
14obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o 14obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
15obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o 15obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
16obj-$(CONFIG_SHMOBILE_IOMMU) += shmobile-iommu.o
17obj-$(CONFIG_SHMOBILE_IPMMU) += shmobile-ipmmu.o
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index c1c74e030a58..f6f4a62ddf09 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3187,8 +3187,7 @@ int __init amd_iommu_init_dma_ops(void)
3187free_domains: 3187free_domains:
3188 3188
3189 for_each_iommu(iommu) { 3189 for_each_iommu(iommu) {
3190 if (iommu->default_dom) 3190 dma_ops_domain_free(iommu->default_dom);
3191 dma_ops_domain_free(iommu->default_dom);
3192 } 3191 }
3193 3192
3194 return ret; 3193 return ret;
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 81837b0710a9..b6ecddb63cd0 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -975,6 +975,38 @@ static void __init free_iommu_all(void)
975} 975}
976 976
977/* 977/*
978 * Family15h Model 10h-1fh erratum 746 (IOMMU Logging May Stall Translations)
979 * Workaround:
980 * BIOS should disable L2B micellaneous clock gating by setting
981 * L2_L2B_CK_GATE_CONTROL[CKGateL2BMiscDisable](D0F2xF4_x90[2]) = 1b
982 */
983static void __init amd_iommu_erratum_746_workaround(struct amd_iommu *iommu)
984{
985 u32 value;
986
987 if ((boot_cpu_data.x86 != 0x15) ||
988 (boot_cpu_data.x86_model < 0x10) ||
989 (boot_cpu_data.x86_model > 0x1f))
990 return;
991
992 pci_write_config_dword(iommu->dev, 0xf0, 0x90);
993 pci_read_config_dword(iommu->dev, 0xf4, &value);
994
995 if (value & BIT(2))
996 return;
997
998 /* Select NB indirect register 0x90 and enable writing */
999 pci_write_config_dword(iommu->dev, 0xf0, 0x90 | (1 << 8));
1000
1001 pci_write_config_dword(iommu->dev, 0xf4, value | 0x4);
1002 pr_info("AMD-Vi: Applying erratum 746 workaround for IOMMU at %s\n",
1003 dev_name(&iommu->dev->dev));
1004
1005 /* Clear the enable writing bit */
1006 pci_write_config_dword(iommu->dev, 0xf0, 0x90);
1007}
1008
1009/*
978 * This function clues the initialization function for one IOMMU 1010 * This function clues the initialization function for one IOMMU
979 * together and also allocates the command buffer and programs the 1011 * together and also allocates the command buffer and programs the
980 * hardware. It does NOT enable the IOMMU. This is done afterwards. 1012 * hardware. It does NOT enable the IOMMU. This is done afterwards.
@@ -1172,6 +1204,8 @@ static int iommu_init_pci(struct amd_iommu *iommu)
1172 iommu->stored_l2[i] = iommu_read_l2(iommu, i); 1204 iommu->stored_l2[i] = iommu_read_l2(iommu, i);
1173 } 1205 }
1174 1206
1207 amd_iommu_erratum_746_workaround(iommu);
1208
1175 return pci_enable_device(iommu->dev); 1209 return pci_enable_device(iommu->dev);
1176} 1210}
1177 1211
@@ -1842,11 +1876,6 @@ static int amd_iommu_init_dma(void)
1842 struct amd_iommu *iommu; 1876 struct amd_iommu *iommu;
1843 int ret; 1877 int ret;
1844 1878
1845 init_device_table_dma();
1846
1847 for_each_iommu(iommu)
1848 iommu_flush_all_caches(iommu);
1849
1850 if (iommu_pass_through) 1879 if (iommu_pass_through)
1851 ret = amd_iommu_init_passthrough(); 1880 ret = amd_iommu_init_passthrough();
1852 else 1881 else
@@ -1855,6 +1884,11 @@ static int amd_iommu_init_dma(void)
1855 if (ret) 1884 if (ret)
1856 return ret; 1885 return ret;
1857 1886
1887 init_device_table_dma();
1888
1889 for_each_iommu(iommu)
1890 iommu_flush_all_caches(iommu);
1891
1858 amd_iommu_init_api(); 1892 amd_iommu_init_api();
1859 1893
1860 amd_iommu_init_notifier(); 1894 amd_iommu_init_notifier();
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 86e2f4a62b9a..2623a570ad2f 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -1040,7 +1040,7 @@ int dmar_enable_qi(struct intel_iommu *iommu)
1040 1040
1041 qi->desc = page_address(desc_page); 1041 qi->desc = page_address(desc_page);
1042 1042
1043 qi->desc_status = kmalloc(QI_LENGTH * sizeof(int), GFP_ATOMIC); 1043 qi->desc_status = kzalloc(QI_LENGTH * sizeof(int), GFP_ATOMIC);
1044 if (!qi->desc_status) { 1044 if (!qi->desc_status) {
1045 free_page((unsigned long) qi->desc); 1045 free_page((unsigned long) qi->desc);
1046 kfree(qi); 1046 kfree(qi);
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 7fe44f83cc37..238a3caa949a 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -511,7 +511,7 @@ int exynos_sysmmu_enable(struct device *dev, unsigned long pgtable)
511 return ret; 511 return ret;
512} 512}
513 513
514bool exynos_sysmmu_disable(struct device *dev) 514static bool exynos_sysmmu_disable(struct device *dev)
515{ 515{
516 struct sysmmu_drvdata *data = dev_get_drvdata(dev->archdata.iommu); 516 struct sysmmu_drvdata *data = dev_get_drvdata(dev->archdata.iommu);
517 bool disabled; 517 bool disabled;
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index b9d091157884..eca28014ef3e 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4234,6 +4234,21 @@ static struct iommu_ops intel_iommu_ops = {
4234 .pgsize_bitmap = INTEL_IOMMU_PGSIZES, 4234 .pgsize_bitmap = INTEL_IOMMU_PGSIZES,
4235}; 4235};
4236 4236
4237static void quirk_iommu_g4x_gfx(struct pci_dev *dev)
4238{
4239 /* G4x/GM45 integrated gfx dmar support is totally busted. */
4240 printk(KERN_INFO "DMAR: Disabling IOMMU for graphics on this chipset\n");
4241 dmar_map_gfx = 0;
4242}
4243
4244DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_g4x_gfx);
4245DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e00, quirk_iommu_g4x_gfx);
4246DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e10, quirk_iommu_g4x_gfx);
4247DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e20, quirk_iommu_g4x_gfx);
4248DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e30, quirk_iommu_g4x_gfx);
4249DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e40, quirk_iommu_g4x_gfx);
4250DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e90, quirk_iommu_g4x_gfx);
4251
4237static void quirk_iommu_rwbf(struct pci_dev *dev) 4252static void quirk_iommu_rwbf(struct pci_dev *dev)
4238{ 4253{
4239 /* 4254 /*
@@ -4242,12 +4257,6 @@ static void quirk_iommu_rwbf(struct pci_dev *dev)
4242 */ 4257 */
4243 printk(KERN_INFO "DMAR: Forcing write-buffer flush capability\n"); 4258 printk(KERN_INFO "DMAR: Forcing write-buffer flush capability\n");
4244 rwbf_quirk = 1; 4259 rwbf_quirk = 1;
4245
4246 /* https://bugzilla.redhat.com/show_bug.cgi?id=538163 */
4247 if (dev->revision == 0x07) {
4248 printk(KERN_INFO "DMAR: Disabling IOMMU for graphics on this chipset\n");
4249 dmar_map_gfx = 0;
4250 }
4251} 4260}
4252 4261
4253DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_rwbf); 4262DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_rwbf);
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index ddbdacad7768..b972d430d92b 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -734,7 +734,8 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
734 size_t orig_size = size; 734 size_t orig_size = size;
735 int ret = 0; 735 int ret = 0;
736 736
737 if (unlikely(domain->ops->map == NULL)) 737 if (unlikely(domain->ops->unmap == NULL ||
738 domain->ops->pgsize_bitmap == 0UL))
738 return -ENODEV; 739 return -ENODEV;
739 740
740 /* find out the minimum page size supported */ 741 /* find out the minimum page size supported */
@@ -808,7 +809,8 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
808 size_t unmapped_page, unmapped = 0; 809 size_t unmapped_page, unmapped = 0;
809 unsigned int min_pagesz; 810 unsigned int min_pagesz;
810 811
811 if (unlikely(domain->ops->unmap == NULL)) 812 if (unlikely(domain->ops->unmap == NULL ||
813 domain->ops->pgsize_bitmap == 0UL))
812 return -ENODEV; 814 return -ENODEV;
813 815
814 /* find out the minimum page size supported */ 816 /* find out the minimum page size supported */
@@ -850,6 +852,26 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
850} 852}
851EXPORT_SYMBOL_GPL(iommu_unmap); 853EXPORT_SYMBOL_GPL(iommu_unmap);
852 854
855
856int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
857 phys_addr_t paddr, u64 size)
858{
859 if (unlikely(domain->ops->domain_window_enable == NULL))
860 return -ENODEV;
861
862 return domain->ops->domain_window_enable(domain, wnd_nr, paddr, size);
863}
864EXPORT_SYMBOL_GPL(iommu_domain_window_enable);
865
866void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr)
867{
868 if (unlikely(domain->ops->domain_window_disable == NULL))
869 return;
870
871 return domain->ops->domain_window_disable(domain, wnd_nr);
872}
873EXPORT_SYMBOL_GPL(iommu_domain_window_disable);
874
853static int __init iommu_init(void) 875static int __init iommu_init(void)
854{ 876{
855 iommu_group_kset = kset_create_and_add("iommu_groups", 877 iommu_group_kset = kset_create_and_add("iommu_groups",
@@ -861,13 +883,15 @@ static int __init iommu_init(void)
861 883
862 return 0; 884 return 0;
863} 885}
864subsys_initcall(iommu_init); 886arch_initcall(iommu_init);
865 887
866int iommu_domain_get_attr(struct iommu_domain *domain, 888int iommu_domain_get_attr(struct iommu_domain *domain,
867 enum iommu_attr attr, void *data) 889 enum iommu_attr attr, void *data)
868{ 890{
869 struct iommu_domain_geometry *geometry; 891 struct iommu_domain_geometry *geometry;
892 bool *paging;
870 int ret = 0; 893 int ret = 0;
894 u32 *count;
871 895
872 switch (attr) { 896 switch (attr) {
873 case DOMAIN_ATTR_GEOMETRY: 897 case DOMAIN_ATTR_GEOMETRY:
@@ -875,6 +899,19 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
875 *geometry = domain->geometry; 899 *geometry = domain->geometry;
876 900
877 break; 901 break;
902 case DOMAIN_ATTR_PAGING:
903 paging = data;
904 *paging = (domain->ops->pgsize_bitmap != 0UL);
905 break;
906 case DOMAIN_ATTR_WINDOWS:
907 count = data;
908
909 if (domain->ops->domain_get_windows != NULL)
910 *count = domain->ops->domain_get_windows(domain);
911 else
912 ret = -ENODEV;
913
914 break;
878 default: 915 default:
879 if (!domain->ops->domain_get_attr) 916 if (!domain->ops->domain_get_attr)
880 return -EINVAL; 917 return -EINVAL;
@@ -889,9 +926,26 @@ EXPORT_SYMBOL_GPL(iommu_domain_get_attr);
889int iommu_domain_set_attr(struct iommu_domain *domain, 926int iommu_domain_set_attr(struct iommu_domain *domain,
890 enum iommu_attr attr, void *data) 927 enum iommu_attr attr, void *data)
891{ 928{
892 if (!domain->ops->domain_set_attr) 929 int ret = 0;
893 return -EINVAL; 930 u32 *count;
894 931
895 return domain->ops->domain_set_attr(domain, attr, data); 932 switch (attr) {
933 case DOMAIN_ATTR_WINDOWS:
934 count = data;
935
936 if (domain->ops->domain_set_windows != NULL)
937 ret = domain->ops->domain_set_windows(domain, *count);
938 else
939 ret = -ENODEV;
940
941 break;
942 default:
943 if (domain->ops->domain_set_attr == NULL)
944 return -EINVAL;
945
946 ret = domain->ops->domain_set_attr(domain, attr, data);
947 }
948
949 return ret;
896} 950}
897EXPORT_SYMBOL_GPL(iommu_domain_set_attr); 951EXPORT_SYMBOL_GPL(iommu_domain_set_attr);
diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c
new file mode 100644
index 000000000000..b6e8b57cf0a8
--- /dev/null
+++ b/drivers/iommu/shmobile-iommu.c
@@ -0,0 +1,395 @@
1/*
2 * IOMMU for IPMMU/IPMMUI
3 * Copyright (C) 2012 Hideki EIRAKU
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 */
9
10#include <linux/dma-mapping.h>
11#include <linux/io.h>
12#include <linux/iommu.h>
13#include <linux/platform_device.h>
14#include <linux/sizes.h>
15#include <linux/slab.h>
16#include <asm/dma-iommu.h>
17#include "shmobile-ipmmu.h"
18
19#define L1_SIZE CONFIG_SHMOBILE_IOMMU_L1SIZE
20#define L1_LEN (L1_SIZE / 4)
21#define L1_ALIGN L1_SIZE
22#define L2_SIZE SZ_1K
23#define L2_LEN (L2_SIZE / 4)
24#define L2_ALIGN L2_SIZE
25
26struct shmobile_iommu_domain_pgtable {
27 uint32_t *pgtable;
28 dma_addr_t handle;
29};
30
31struct shmobile_iommu_archdata {
32 struct list_head attached_list;
33 struct dma_iommu_mapping *iommu_mapping;
34 spinlock_t attach_lock;
35 struct shmobile_iommu_domain *attached;
36 int num_attached_devices;
37 struct shmobile_ipmmu *ipmmu;
38};
39
40struct shmobile_iommu_domain {
41 struct shmobile_iommu_domain_pgtable l1, l2[L1_LEN];
42 spinlock_t map_lock;
43 spinlock_t attached_list_lock;
44 struct list_head attached_list;
45};
46
47static struct shmobile_iommu_archdata *ipmmu_archdata;
48static struct kmem_cache *l1cache, *l2cache;
49
50static int pgtable_alloc(struct shmobile_iommu_domain_pgtable *pgtable,
51 struct kmem_cache *cache, size_t size)
52{
53 pgtable->pgtable = kmem_cache_zalloc(cache, GFP_ATOMIC);
54 if (!pgtable->pgtable)
55 return -ENOMEM;
56 pgtable->handle = dma_map_single(NULL, pgtable->pgtable, size,
57 DMA_TO_DEVICE);
58 return 0;
59}
60
61static void pgtable_free(struct shmobile_iommu_domain_pgtable *pgtable,
62 struct kmem_cache *cache, size_t size)
63{
64 dma_unmap_single(NULL, pgtable->handle, size, DMA_TO_DEVICE);
65 kmem_cache_free(cache, pgtable->pgtable);
66}
67
68static uint32_t pgtable_read(struct shmobile_iommu_domain_pgtable *pgtable,
69 unsigned int index)
70{
71 return pgtable->pgtable[index];
72}
73
74static void pgtable_write(struct shmobile_iommu_domain_pgtable *pgtable,
75 unsigned int index, unsigned int count, uint32_t val)
76{
77 unsigned int i;
78
79 for (i = 0; i < count; i++)
80 pgtable->pgtable[index + i] = val;
81 dma_sync_single_for_device(NULL, pgtable->handle + index * sizeof(val),
82 sizeof(val) * count, DMA_TO_DEVICE);
83}
84
85static int shmobile_iommu_domain_init(struct iommu_domain *domain)
86{
87 struct shmobile_iommu_domain *sh_domain;
88 int i, ret;
89
90 sh_domain = kmalloc(sizeof(*sh_domain), GFP_KERNEL);
91 if (!sh_domain)
92 return -ENOMEM;
93 ret = pgtable_alloc(&sh_domain->l1, l1cache, L1_SIZE);
94 if (ret < 0) {
95 kfree(sh_domain);
96 return ret;
97 }
98 for (i = 0; i < L1_LEN; i++)
99 sh_domain->l2[i].pgtable = NULL;
100 spin_lock_init(&sh_domain->map_lock);
101 spin_lock_init(&sh_domain->attached_list_lock);
102 INIT_LIST_HEAD(&sh_domain->attached_list);
103 domain->priv = sh_domain;
104 return 0;
105}
106
107static void shmobile_iommu_domain_destroy(struct iommu_domain *domain)
108{
109 struct shmobile_iommu_domain *sh_domain = domain->priv;
110 int i;
111
112 for (i = 0; i < L1_LEN; i++) {
113 if (sh_domain->l2[i].pgtable)
114 pgtable_free(&sh_domain->l2[i], l2cache, L2_SIZE);
115 }
116 pgtable_free(&sh_domain->l1, l1cache, L1_SIZE);
117 kfree(sh_domain);
118 domain->priv = NULL;
119}
120
121static int shmobile_iommu_attach_device(struct iommu_domain *domain,
122 struct device *dev)
123{
124 struct shmobile_iommu_archdata *archdata = dev->archdata.iommu;
125 struct shmobile_iommu_domain *sh_domain = domain->priv;
126 int ret = -EBUSY;
127
128 if (!archdata)
129 return -ENODEV;
130 spin_lock(&sh_domain->attached_list_lock);
131 spin_lock(&archdata->attach_lock);
132 if (archdata->attached != sh_domain) {
133 if (archdata->attached)
134 goto err;
135 ipmmu_tlb_set(archdata->ipmmu, sh_domain->l1.handle, L1_SIZE,
136 0);
137 ipmmu_tlb_flush(archdata->ipmmu);
138 archdata->attached = sh_domain;
139 archdata->num_attached_devices = 0;
140 list_add(&archdata->attached_list, &sh_domain->attached_list);
141 }
142 archdata->num_attached_devices++;
143 ret = 0;
144err:
145 spin_unlock(&archdata->attach_lock);
146 spin_unlock(&sh_domain->attached_list_lock);
147 return ret;
148}
149
150static void shmobile_iommu_detach_device(struct iommu_domain *domain,
151 struct device *dev)
152{
153 struct shmobile_iommu_archdata *archdata = dev->archdata.iommu;
154 struct shmobile_iommu_domain *sh_domain = domain->priv;
155
156 if (!archdata)
157 return;
158 spin_lock(&sh_domain->attached_list_lock);
159 spin_lock(&archdata->attach_lock);
160 archdata->num_attached_devices--;
161 if (!archdata->num_attached_devices) {
162 ipmmu_tlb_set(archdata->ipmmu, 0, 0, 0);
163 ipmmu_tlb_flush(archdata->ipmmu);
164 archdata->attached = NULL;
165 list_del(&archdata->attached_list);
166 }
167 spin_unlock(&archdata->attach_lock);
168 spin_unlock(&sh_domain->attached_list_lock);
169}
170
171static void domain_tlb_flush(struct shmobile_iommu_domain *sh_domain)
172{
173 struct shmobile_iommu_archdata *archdata;
174
175 spin_lock(&sh_domain->attached_list_lock);
176 list_for_each_entry(archdata, &sh_domain->attached_list, attached_list)
177 ipmmu_tlb_flush(archdata->ipmmu);
178 spin_unlock(&sh_domain->attached_list_lock);
179}
180
181static int l2alloc(struct shmobile_iommu_domain *sh_domain,
182 unsigned int l1index)
183{
184 int ret;
185
186 if (!sh_domain->l2[l1index].pgtable) {
187 ret = pgtable_alloc(&sh_domain->l2[l1index], l2cache, L2_SIZE);
188 if (ret < 0)
189 return ret;
190 }
191 pgtable_write(&sh_domain->l1, l1index, 1,
192 sh_domain->l2[l1index].handle | 0x1);
193 return 0;
194}
195
196static void l2realfree(struct shmobile_iommu_domain_pgtable *l2)
197{
198 if (l2->pgtable)
199 pgtable_free(l2, l2cache, L2_SIZE);
200}
201
202static void l2free(struct shmobile_iommu_domain *sh_domain,
203 unsigned int l1index,
204 struct shmobile_iommu_domain_pgtable *l2)
205{
206 pgtable_write(&sh_domain->l1, l1index, 1, 0);
207 if (sh_domain->l2[l1index].pgtable) {
208 *l2 = sh_domain->l2[l1index];
209 sh_domain->l2[l1index].pgtable = NULL;
210 }
211}
212
213static int shmobile_iommu_map(struct iommu_domain *domain, unsigned long iova,
214 phys_addr_t paddr, size_t size, int prot)
215{
216 struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
217 struct shmobile_iommu_domain *sh_domain = domain->priv;
218 unsigned int l1index, l2index;
219 int ret;
220
221 l1index = iova >> 20;
222 switch (size) {
223 case SZ_4K:
224 l2index = (iova >> 12) & 0xff;
225 spin_lock(&sh_domain->map_lock);
226 ret = l2alloc(sh_domain, l1index);
227 if (!ret)
228 pgtable_write(&sh_domain->l2[l1index], l2index, 1,
229 paddr | 0xff2);
230 spin_unlock(&sh_domain->map_lock);
231 break;
232 case SZ_64K:
233 l2index = (iova >> 12) & 0xf0;
234 spin_lock(&sh_domain->map_lock);
235 ret = l2alloc(sh_domain, l1index);
236 if (!ret)
237 pgtable_write(&sh_domain->l2[l1index], l2index, 0x10,
238 paddr | 0xff1);
239 spin_unlock(&sh_domain->map_lock);
240 break;
241 case SZ_1M:
242 spin_lock(&sh_domain->map_lock);
243 l2free(sh_domain, l1index, &l2);
244 pgtable_write(&sh_domain->l1, l1index, 1, paddr | 0xc02);
245 spin_unlock(&sh_domain->map_lock);
246 ret = 0;
247 break;
248 default:
249 ret = -EINVAL;
250 }
251 if (!ret)
252 domain_tlb_flush(sh_domain);
253 l2realfree(&l2);
254 return ret;
255}
256
257static size_t shmobile_iommu_unmap(struct iommu_domain *domain,
258 unsigned long iova, size_t size)
259{
260 struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
261 struct shmobile_iommu_domain *sh_domain = domain->priv;
262 unsigned int l1index, l2index;
263 uint32_t l2entry = 0;
264 size_t ret = 0;
265
266 l1index = iova >> 20;
267 if (!(iova & 0xfffff) && size >= SZ_1M) {
268 spin_lock(&sh_domain->map_lock);
269 l2free(sh_domain, l1index, &l2);
270 spin_unlock(&sh_domain->map_lock);
271 ret = SZ_1M;
272 goto done;
273 }
274 l2index = (iova >> 12) & 0xff;
275 spin_lock(&sh_domain->map_lock);
276 if (sh_domain->l2[l1index].pgtable)
277 l2entry = pgtable_read(&sh_domain->l2[l1index], l2index);
278 switch (l2entry & 3) {
279 case 1:
280 if (l2index & 0xf)
281 break;
282 pgtable_write(&sh_domain->l2[l1index], l2index, 0x10, 0);
283 ret = SZ_64K;
284 break;
285 case 2:
286 pgtable_write(&sh_domain->l2[l1index], l2index, 1, 0);
287 ret = SZ_4K;
288 break;
289 }
290 spin_unlock(&sh_domain->map_lock);
291done:
292 if (ret)
293 domain_tlb_flush(sh_domain);
294 l2realfree(&l2);
295 return ret;
296}
297
298static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain,
299 unsigned long iova)
300{
301 struct shmobile_iommu_domain *sh_domain = domain->priv;
302 uint32_t l1entry = 0, l2entry = 0;
303 unsigned int l1index, l2index;
304
305 l1index = iova >> 20;
306 l2index = (iova >> 12) & 0xff;
307 spin_lock(&sh_domain->map_lock);
308 if (sh_domain->l2[l1index].pgtable)
309 l2entry = pgtable_read(&sh_domain->l2[l1index], l2index);
310 else
311 l1entry = pgtable_read(&sh_domain->l1, l1index);
312 spin_unlock(&sh_domain->map_lock);
313 switch (l2entry & 3) {
314 case 1:
315 return (l2entry & ~0xffff) | (iova & 0xffff);
316 case 2:
317 return (l2entry & ~0xfff) | (iova & 0xfff);
318 default:
319 if ((l1entry & 3) == 2)
320 return (l1entry & ~0xfffff) | (iova & 0xfffff);
321 return 0;
322 }
323}
324
325static int find_dev_name(struct shmobile_ipmmu *ipmmu, const char *dev_name)
326{
327 unsigned int i, n = ipmmu->num_dev_names;
328
329 for (i = 0; i < n; i++) {
330 if (strcmp(ipmmu->dev_names[i], dev_name) == 0)
331 return 1;
332 }
333 return 0;
334}
335
336static int shmobile_iommu_add_device(struct device *dev)
337{
338 struct shmobile_iommu_archdata *archdata = ipmmu_archdata;
339 struct dma_iommu_mapping *mapping;
340
341 if (!find_dev_name(archdata->ipmmu, dev_name(dev)))
342 return 0;
343 mapping = archdata->iommu_mapping;
344 if (!mapping) {
345 mapping = arm_iommu_create_mapping(&platform_bus_type, 0,
346 L1_LEN << 20, 0);
347 if (IS_ERR(mapping))
348 return PTR_ERR(mapping);
349 archdata->iommu_mapping = mapping;
350 }
351 dev->archdata.iommu = archdata;
352 if (arm_iommu_attach_device(dev, mapping))
353 pr_err("arm_iommu_attach_device failed\n");
354 return 0;
355}
356
357static struct iommu_ops shmobile_iommu_ops = {
358 .domain_init = shmobile_iommu_domain_init,
359 .domain_destroy = shmobile_iommu_domain_destroy,
360 .attach_dev = shmobile_iommu_attach_device,
361 .detach_dev = shmobile_iommu_detach_device,
362 .map = shmobile_iommu_map,
363 .unmap = shmobile_iommu_unmap,
364 .iova_to_phys = shmobile_iommu_iova_to_phys,
365 .add_device = shmobile_iommu_add_device,
366 .pgsize_bitmap = SZ_1M | SZ_64K | SZ_4K,
367};
368
369int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
370{
371 static struct shmobile_iommu_archdata *archdata;
372
373 l1cache = kmem_cache_create("shmobile-iommu-pgtable1", L1_SIZE,
374 L1_ALIGN, SLAB_HWCACHE_ALIGN, NULL);
375 if (!l1cache)
376 return -ENOMEM;
377 l2cache = kmem_cache_create("shmobile-iommu-pgtable2", L2_SIZE,
378 L2_ALIGN, SLAB_HWCACHE_ALIGN, NULL);
379 if (!l2cache) {
380 kmem_cache_destroy(l1cache);
381 return -ENOMEM;
382 }
383 archdata = kmalloc(sizeof(*archdata), GFP_KERNEL);
384 if (!archdata) {
385 kmem_cache_destroy(l1cache);
386 kmem_cache_destroy(l2cache);
387 return -ENOMEM;
388 }
389 spin_lock_init(&archdata->attach_lock);
390 archdata->attached = NULL;
391 archdata->ipmmu = ipmmu;
392 ipmmu_archdata = archdata;
393 bus_set_iommu(&platform_bus_type, &shmobile_iommu_ops);
394 return 0;
395}
diff --git a/drivers/iommu/shmobile-ipmmu.c b/drivers/iommu/shmobile-ipmmu.c
new file mode 100644
index 000000000000..8321f89596c4
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.c
@@ -0,0 +1,136 @@
1/*
2 * IPMMU/IPMMUI
3 * Copyright (C) 2012 Hideki EIRAKU
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 */
9
10#include <linux/err.h>
11#include <linux/export.h>
12#include <linux/io.h>
13#include <linux/platform_device.h>
14#include <linux/slab.h>
15#include <linux/platform_data/sh_ipmmu.h>
16#include "shmobile-ipmmu.h"
17
18#define IMCTR1 0x000
19#define IMCTR2 0x004
20#define IMASID 0x010
21#define IMTTBR 0x014
22#define IMTTBCR 0x018
23
24#define IMCTR1_TLBEN (1 << 0)
25#define IMCTR1_FLUSH (1 << 1)
26
27static void ipmmu_reg_write(struct shmobile_ipmmu *ipmmu, unsigned long reg_off,
28 unsigned long data)
29{
30 iowrite32(data, ipmmu->ipmmu_base + reg_off);
31}
32
33void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu)
34{
35 if (!ipmmu)
36 return;
37
38 mutex_lock(&ipmmu->flush_lock);
39 if (ipmmu->tlb_enabled)
40 ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH | IMCTR1_TLBEN);
41 else
42 ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH);
43 mutex_unlock(&ipmmu->flush_lock);
44}
45
46void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
47 int asid)
48{
49 if (!ipmmu)
50 return;
51
52 mutex_lock(&ipmmu->flush_lock);
53 switch (size) {
54 default:
55 ipmmu->tlb_enabled = 0;
56 break;
57 case 0x2000:
58 ipmmu_reg_write(ipmmu, IMTTBCR, 1);
59 ipmmu->tlb_enabled = 1;
60 break;
61 case 0x1000:
62 ipmmu_reg_write(ipmmu, IMTTBCR, 2);
63 ipmmu->tlb_enabled = 1;
64 break;
65 case 0x800:
66 ipmmu_reg_write(ipmmu, IMTTBCR, 3);
67 ipmmu->tlb_enabled = 1;
68 break;
69 case 0x400:
70 ipmmu_reg_write(ipmmu, IMTTBCR, 4);
71 ipmmu->tlb_enabled = 1;
72 break;
73 case 0x200:
74 ipmmu_reg_write(ipmmu, IMTTBCR, 5);
75 ipmmu->tlb_enabled = 1;
76 break;
77 case 0x100:
78 ipmmu_reg_write(ipmmu, IMTTBCR, 6);
79 ipmmu->tlb_enabled = 1;
80 break;
81 case 0x80:
82 ipmmu_reg_write(ipmmu, IMTTBCR, 7);
83 ipmmu->tlb_enabled = 1;
84 break;
85 }
86 ipmmu_reg_write(ipmmu, IMTTBR, phys);
87 ipmmu_reg_write(ipmmu, IMASID, asid);
88 mutex_unlock(&ipmmu->flush_lock);
89}
90
91static int ipmmu_probe(struct platform_device *pdev)
92{
93 struct shmobile_ipmmu *ipmmu;
94 struct resource *res;
95 struct shmobile_ipmmu_platform_data *pdata = pdev->dev.platform_data;
96
97 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98 if (!res) {
99 dev_err(&pdev->dev, "cannot get platform resources\n");
100 return -ENOENT;
101 }
102 ipmmu = devm_kzalloc(&pdev->dev, sizeof(*ipmmu), GFP_KERNEL);
103 if (!ipmmu) {
104 dev_err(&pdev->dev, "cannot allocate device data\n");
105 return -ENOMEM;
106 }
107 mutex_init(&ipmmu->flush_lock);
108 ipmmu->dev = &pdev->dev;
109 ipmmu->ipmmu_base = devm_ioremap_nocache(&pdev->dev, res->start,
110 resource_size(res));
111 if (!ipmmu->ipmmu_base) {
112 dev_err(&pdev->dev, "ioremap_nocache failed\n");
113 return -ENOMEM;
114 }
115 ipmmu->dev_names = pdata->dev_names;
116 ipmmu->num_dev_names = pdata->num_dev_names;
117 platform_set_drvdata(pdev, ipmmu);
118 ipmmu_reg_write(ipmmu, IMCTR1, 0x0); /* disable TLB */
119 ipmmu_reg_write(ipmmu, IMCTR2, 0x0); /* disable PMB */
120 ipmmu_iommu_init(ipmmu);
121 return 0;
122}
123
124static struct platform_driver ipmmu_driver = {
125 .probe = ipmmu_probe,
126 .driver = {
127 .owner = THIS_MODULE,
128 .name = "ipmmu",
129 },
130};
131
132static int __init ipmmu_init(void)
133{
134 return platform_driver_register(&ipmmu_driver);
135}
136subsys_initcall(ipmmu_init);
diff --git a/drivers/iommu/shmobile-ipmmu.h b/drivers/iommu/shmobile-ipmmu.h
new file mode 100644
index 000000000000..4d53684673e1
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.h
@@ -0,0 +1,34 @@
1/* shmobile-ipmmu.h
2 *
3 * Copyright (C) 2012 Hideki EIRAKU
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 */
9
10#ifndef __SHMOBILE_IPMMU_H__
11#define __SHMOBILE_IPMMU_H__
12
13struct shmobile_ipmmu {
14 struct device *dev;
15 void __iomem *ipmmu_base;
16 int tlb_enabled;
17 struct mutex flush_lock;
18 const char * const *dev_names;
19 unsigned int num_dev_names;
20};
21
22#ifdef CONFIG_SHMOBILE_IPMMU_TLB
23void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu);
24void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
25 int asid);
26int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu);
27#else
28static inline int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
29{
30 return -EINVAL;
31}
32#endif
33
34#endif /* __SHMOBILE_IPMMU_H__ */
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index 8219f1d596ee..86437575f94d 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -430,13 +430,11 @@ const struct dev_pm_ops tegra_gart_pm_ops = {
430 .resume = tegra_gart_resume, 430 .resume = tegra_gart_resume,
431}; 431};
432 432
433#ifdef CONFIG_OF
434static struct of_device_id tegra_gart_of_match[] = { 433static struct of_device_id tegra_gart_of_match[] = {
435 { .compatible = "nvidia,tegra20-gart", }, 434 { .compatible = "nvidia,tegra20-gart", },
436 { }, 435 { },
437}; 436};
438MODULE_DEVICE_TABLE(of, tegra_gart_of_match); 437MODULE_DEVICE_TABLE(of, tegra_gart_of_match);
439#endif
440 438
441static struct platform_driver tegra_gart_driver = { 439static struct platform_driver tegra_gart_driver = {
442 .probe = tegra_gart_probe, 440 .probe = tegra_gart_probe,
@@ -445,7 +443,7 @@ static struct platform_driver tegra_gart_driver = {
445 .owner = THIS_MODULE, 443 .owner = THIS_MODULE,
446 .name = "tegra-gart", 444 .name = "tegra-gart",
447 .pm = &tegra_gart_pm_ops, 445 .pm = &tegra_gart_pm_ops,
448 .of_match_table = of_match_ptr(tegra_gart_of_match), 446 .of_match_table = tegra_gart_of_match,
449 }, 447 },
450}; 448};
451 449
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index fc178893789a..8b1d9f758076 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * IOMMU API for SMMU in Tegra30 2 * IOMMU API for SMMU in Tegra30
3 * 3 *
4 * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved. 4 * Copyright (c) 2011-2013, NVIDIA CORPORATION. All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License, 7 * under the terms and conditions of the GNU General Public License,
@@ -293,7 +293,11 @@ struct smmu_debugfs_info {
293 * Per SMMU device - IOMMU device 293 * Per SMMU device - IOMMU device
294 */ 294 */
295struct smmu_device { 295struct smmu_device {
296 void __iomem *regs[NUM_SMMU_REG_BANKS]; 296 void __iomem *regbase; /* register offset base */
297 void __iomem **regs; /* register block start address array */
298 void __iomem **rege; /* register block end address array */
299 int nregs; /* number of register blocks */
300
297 unsigned long iovmm_base; /* remappable base address */ 301 unsigned long iovmm_base; /* remappable base address */
298 unsigned long page_count; /* total remappable size */ 302 unsigned long page_count; /* total remappable size */
299 spinlock_t lock; 303 spinlock_t lock;
@@ -323,38 +327,37 @@ static struct smmu_device *smmu_handle; /* unique for a system */
323/* 327/*
324 * SMMU register accessors 328 * SMMU register accessors
325 */ 329 */
330static bool inline smmu_valid_reg(struct smmu_device *smmu,
331 void __iomem *addr)
332{
333 int i;
334
335 for (i = 0; i < smmu->nregs; i++) {
336 if (addr < smmu->regs[i])
337 break;
338 if (addr <= smmu->rege[i])
339 return true;
340 }
341
342 return false;
343}
344
326static inline u32 smmu_read(struct smmu_device *smmu, size_t offs) 345static inline u32 smmu_read(struct smmu_device *smmu, size_t offs)
327{ 346{
328 BUG_ON(offs < 0x10); 347 void __iomem *addr = smmu->regbase + offs;
329 if (offs < 0x3c) 348
330 return readl(smmu->regs[0] + offs - 0x10); 349 BUG_ON(!smmu_valid_reg(smmu, addr));
331 BUG_ON(offs < 0x1f0); 350
332 if (offs < 0x200) 351 return readl(addr);
333 return readl(smmu->regs[1] + offs - 0x1f0);
334 BUG_ON(offs < 0x228);
335 if (offs < 0x284)
336 return readl(smmu->regs[2] + offs - 0x228);
337 BUG();
338} 352}
339 353
340static inline void smmu_write(struct smmu_device *smmu, u32 val, size_t offs) 354static inline void smmu_write(struct smmu_device *smmu, u32 val, size_t offs)
341{ 355{
342 BUG_ON(offs < 0x10); 356 void __iomem *addr = smmu->regbase + offs;
343 if (offs < 0x3c) { 357
344 writel(val, smmu->regs[0] + offs - 0x10); 358 BUG_ON(!smmu_valid_reg(smmu, addr));
345 return; 359
346 } 360 writel(val, addr);
347 BUG_ON(offs < 0x1f0);
348 if (offs < 0x200) {
349 writel(val, smmu->regs[1] + offs - 0x1f0);
350 return;
351 }
352 BUG_ON(offs < 0x228);
353 if (offs < 0x284) {
354 writel(val, smmu->regs[2] + offs - 0x228);
355 return;
356 }
357 BUG();
358} 361}
359 362
360#define VA_PAGE_TO_PA(va, page) \ 363#define VA_PAGE_TO_PA(va, page) \
@@ -1170,7 +1173,13 @@ static int tegra_smmu_probe(struct platform_device *pdev)
1170 return -ENOMEM; 1173 return -ENOMEM;
1171 } 1174 }
1172 1175
1173 for (i = 0; i < ARRAY_SIZE(smmu->regs); i++) { 1176 smmu->nregs = pdev->num_resources;
1177 smmu->regs = devm_kzalloc(dev, 2 * smmu->nregs * sizeof(*smmu->regs),
1178 GFP_KERNEL);
1179 smmu->rege = smmu->regs + smmu->nregs;
1180 if (!smmu->regs)
1181 return -ENOMEM;
1182 for (i = 0; i < smmu->nregs; i++) {
1174 struct resource *res; 1183 struct resource *res;
1175 1184
1176 res = platform_get_resource(pdev, IORESOURCE_MEM, i); 1185 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
@@ -1179,7 +1188,10 @@ static int tegra_smmu_probe(struct platform_device *pdev)
1179 smmu->regs[i] = devm_request_and_ioremap(&pdev->dev, res); 1188 smmu->regs[i] = devm_request_and_ioremap(&pdev->dev, res);
1180 if (!smmu->regs[i]) 1189 if (!smmu->regs[i])
1181 return -EBUSY; 1190 return -EBUSY;
1191 smmu->rege[i] = smmu->regs[i] + resource_size(res) - 1;
1182 } 1192 }
1193 /* Same as "mc" 1st regiter block start address */
1194 smmu->regbase = (void __iomem *)((u32)smmu->regs[0] & PAGE_MASK);
1183 1195
1184 err = of_get_dma_window(dev->of_node, NULL, 0, NULL, &base, &size); 1196 err = of_get_dma_window(dev->of_node, NULL, 0, NULL, &base, &size);
1185 if (err) 1197 if (err)
@@ -1216,6 +1228,7 @@ static int tegra_smmu_probe(struct platform_device *pdev)
1216 as->pte_attr = _PTE_ATTR; 1228 as->pte_attr = _PTE_ATTR;
1217 1229
1218 spin_lock_init(&as->lock); 1230 spin_lock_init(&as->lock);
1231 spin_lock_init(&as->client_lock);
1219 INIT_LIST_HEAD(&as->client); 1232 INIT_LIST_HEAD(&as->client);
1220 } 1233 }
1221 spin_lock_init(&smmu->lock); 1234 spin_lock_init(&smmu->lock);
@@ -1254,13 +1267,11 @@ const struct dev_pm_ops tegra_smmu_pm_ops = {
1254 .resume = tegra_smmu_resume, 1267 .resume = tegra_smmu_resume,
1255}; 1268};
1256 1269
1257#ifdef CONFIG_OF
1258static struct of_device_id tegra_smmu_of_match[] = { 1270static struct of_device_id tegra_smmu_of_match[] = {
1259 { .compatible = "nvidia,tegra30-smmu", }, 1271 { .compatible = "nvidia,tegra30-smmu", },
1260 { }, 1272 { },
1261}; 1273};
1262MODULE_DEVICE_TABLE(of, tegra_smmu_of_match); 1274MODULE_DEVICE_TABLE(of, tegra_smmu_of_match);
1263#endif
1264 1275
1265static struct platform_driver tegra_smmu_driver = { 1276static struct platform_driver tegra_smmu_driver = {
1266 .probe = tegra_smmu_probe, 1277 .probe = tegra_smmu_probe,
@@ -1269,7 +1280,7 @@ static struct platform_driver tegra_smmu_driver = {
1269 .owner = THIS_MODULE, 1280 .owner = THIS_MODULE,
1270 .name = "tegra-smmu", 1281 .name = "tegra-smmu",
1271 .pm = &tegra_smmu_pm_ops, 1282 .pm = &tegra_smmu_pm_ops,
1272 .of_match_table = of_match_ptr(tegra_smmu_of_match), 1283 .of_match_table = tegra_smmu_of_match,
1273 }, 1284 },
1274}; 1285};
1275 1286