aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/ata/ahci-platform.txt1
-rw-r--r--Documentation/devicetree/bindings/dma/arm-pl330.txt3
-rw-r--r--Documentation/devicetree/bindings/net/calxeda-xgmac.txt3
-rw-r--r--arch/arm/boot/dts/highbank.dts1
-rw-r--r--arch/arm/include/asm/barrier.h7
-rw-r--r--arch/arm/include/asm/dma-mapping.h1
-rw-r--r--arch/arm/include/asm/memory.h8
-rw-r--r--arch/arm/mach-highbank/highbank.c52
-rw-r--r--arch/arm/mm/dma-mapping.c264
-rw-r--r--arch/arm/mm/mmu.c11
-rw-r--r--drivers/base/dma-contiguous.c18
11 files changed, 278 insertions, 91 deletions
diff --git a/Documentation/devicetree/bindings/ata/ahci-platform.txt b/Documentation/devicetree/bindings/ata/ahci-platform.txt
index 147c1f6653fe..b519f9b699c3 100644
--- a/Documentation/devicetree/bindings/ata/ahci-platform.txt
+++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt
@@ -12,6 +12,7 @@ Optional properties:
12- calxeda,port-phys: phandle-combophy and lane assignment, which maps each 12- calxeda,port-phys: phandle-combophy and lane assignment, which maps each
13 SATA port to a combophy and a lane within that 13 SATA port to a combophy and a lane within that
14 combophy 14 combophy
15- dma-coherent : Present if dma operations are coherent
15 16
16Example: 17Example:
17 sata@ffe08000 { 18 sata@ffe08000 {
diff --git a/Documentation/devicetree/bindings/dma/arm-pl330.txt b/Documentation/devicetree/bindings/dma/arm-pl330.txt
index a4cd273b2a67..36e27d54260b 100644
--- a/Documentation/devicetree/bindings/dma/arm-pl330.txt
+++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt
@@ -9,6 +9,9 @@ Required properties:
9 region. 9 region.
10 - interrupts: interrupt number to the cpu. 10 - interrupts: interrupt number to the cpu.
11 11
12Optional properties:
13- dma-coherent : Present if dma operations are coherent
14
12Example: 15Example:
13 16
14 pdma0: pdma@12680000 { 17 pdma0: pdma@12680000 {
diff --git a/Documentation/devicetree/bindings/net/calxeda-xgmac.txt b/Documentation/devicetree/bindings/net/calxeda-xgmac.txt
index 411727a3f82d..c8ae996bd8f2 100644
--- a/Documentation/devicetree/bindings/net/calxeda-xgmac.txt
+++ b/Documentation/devicetree/bindings/net/calxeda-xgmac.txt
@@ -6,6 +6,9 @@ Required properties:
6- interrupts : Should contain 3 xgmac interrupts. The 1st is main interrupt. 6- interrupts : Should contain 3 xgmac interrupts. The 1st is main interrupt.
7 The 2nd is pwr mgt interrupt. The 3rd is low power state interrupt. 7 The 2nd is pwr mgt interrupt. The 3rd is low power state interrupt.
8 8
9Optional properties:
10- dma-coherent : Present if dma operations are coherent
11
9Example: 12Example:
10 13
11ethernet@fff50000 { 14ethernet@fff50000 {
diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
index 5204cf73c2d8..0c6fc34821f9 100644
--- a/arch/arm/boot/dts/highbank.dts
+++ b/arch/arm/boot/dts/highbank.dts
@@ -124,6 +124,7 @@
124 calxeda,port-phys = <&combophy5 0 &combophy0 0 124 calxeda,port-phys = <&combophy5 0 &combophy0 0
125 &combophy0 1 &combophy0 2 125 &combophy0 1 &combophy0 2
126 &combophy0 3>; 126 &combophy0 3>;
127 dma-coherent;
127 }; 128 };
128 129
129 sdhci@ffe0e000 { 130 sdhci@ffe0e000 {
diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
index 05112380dc53..8dcd9c702d90 100644
--- a/arch/arm/include/asm/barrier.h
+++ b/arch/arm/include/asm/barrier.h
@@ -44,10 +44,9 @@
44#define rmb() dsb() 44#define rmb() dsb()
45#define wmb() mb() 45#define wmb() mb()
46#else 46#else
47#include <asm/memory.h> 47#define mb() barrier()
48#define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0) 48#define rmb() barrier()
49#define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0) 49#define wmb() barrier()
50#define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
51#endif 50#endif
52 51
53#ifndef CONFIG_SMP 52#ifndef CONFIG_SMP
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 5c44dcb0987b..23004847bb05 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -13,6 +13,7 @@
13 13
14#define DMA_ERROR_CODE (~0) 14#define DMA_ERROR_CODE (~0)
15extern struct dma_map_ops arm_dma_ops; 15extern struct dma_map_ops arm_dma_ops;
16extern struct dma_map_ops arm_coherent_dma_ops;
16 17
17static inline struct dma_map_ops *get_dma_ops(struct device *dev) 18static inline struct dma_map_ops *get_dma_ops(struct device *dev)
18{ 19{
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 5f6ddcc56452..73cf03aa981e 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -275,14 +275,6 @@ static inline __deprecated void *bus_to_virt(unsigned long x)
275#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 275#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
276#define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory) 276#define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
277 277
278/*
279 * Optional coherency support. Currently used only by selected
280 * Intel XSC3-based systems.
281 */
282#ifndef arch_is_coherent
283#define arch_is_coherent() 0
284#endif
285
286#endif 278#endif
287 279
288#include <asm-generic/memory_model.h> 280#include <asm-generic/memory_model.h>
diff --git a/arch/arm/mach-highbank/highbank.c b/arch/arm/mach-highbank/highbank.c
index af1da34ccf9d..40e36a50304c 100644
--- a/arch/arm/mach-highbank/highbank.c
+++ b/arch/arm/mach-highbank/highbank.c
@@ -15,6 +15,7 @@
15 */ 15 */
16#include <linux/clk.h> 16#include <linux/clk.h>
17#include <linux/clkdev.h> 17#include <linux/clkdev.h>
18#include <linux/dma-mapping.h>
18#include <linux/io.h> 19#include <linux/io.h>
19#include <linux/irq.h> 20#include <linux/irq.h>
20#include <linux/irqdomain.h> 21#include <linux/irqdomain.h>
@@ -23,6 +24,7 @@
23#include <linux/of_platform.h> 24#include <linux/of_platform.h>
24#include <linux/of_address.h> 25#include <linux/of_address.h>
25#include <linux/smp.h> 26#include <linux/smp.h>
27#include <linux/amba/bus.h>
26 28
27#include <asm/cacheflush.h> 29#include <asm/cacheflush.h>
28#include <asm/smp_plat.h> 30#include <asm/smp_plat.h>
@@ -149,11 +151,61 @@ static void highbank_power_off(void)
149 cpu_do_idle(); 151 cpu_do_idle();
150} 152}
151 153
154static int highbank_platform_notifier(struct notifier_block *nb,
155 unsigned long event, void *__dev)
156{
157 struct resource *res;
158 int reg = -1;
159 struct device *dev = __dev;
160
161 if (event != BUS_NOTIFY_ADD_DEVICE)
162 return NOTIFY_DONE;
163
164 if (of_device_is_compatible(dev->of_node, "calxeda,hb-ahci"))
165 reg = 0xc;
166 else if (of_device_is_compatible(dev->of_node, "calxeda,hb-sdhci"))
167 reg = 0x18;
168 else if (of_device_is_compatible(dev->of_node, "arm,pl330"))
169 reg = 0x20;
170 else if (of_device_is_compatible(dev->of_node, "calxeda,hb-xgmac")) {
171 res = platform_get_resource(to_platform_device(dev),
172 IORESOURCE_MEM, 0);
173 if (res) {
174 if (res->start == 0xfff50000)
175 reg = 0;
176 else if (res->start == 0xfff51000)
177 reg = 4;
178 }
179 }
180
181 if (reg < 0)
182 return NOTIFY_DONE;
183
184 if (of_property_read_bool(dev->of_node, "dma-coherent")) {
185 writel(0xff31, sregs_base + reg);
186 set_dma_ops(dev, &arm_coherent_dma_ops);
187 } else
188 writel(0, sregs_base + reg);
189
190 return NOTIFY_OK;
191}
192
193static struct notifier_block highbank_amba_nb = {
194 .notifier_call = highbank_platform_notifier,
195};
196
197static struct notifier_block highbank_platform_nb = {
198 .notifier_call = highbank_platform_notifier,
199};
200
152static void __init highbank_init(void) 201static void __init highbank_init(void)
153{ 202{
154 pm_power_off = highbank_power_off; 203 pm_power_off = highbank_power_off;
155 highbank_pm_init(); 204 highbank_pm_init();
156 205
206 bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
207 bus_register_notifier(&amba_bustype, &highbank_amba_nb);
208
157 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 209 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
158} 210}
159 211
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 13f555d62491..477a2d23ddf1 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -73,11 +73,18 @@ static dma_addr_t arm_dma_map_page(struct device *dev, struct page *page,
73 unsigned long offset, size_t size, enum dma_data_direction dir, 73 unsigned long offset, size_t size, enum dma_data_direction dir,
74 struct dma_attrs *attrs) 74 struct dma_attrs *attrs)
75{ 75{
76 if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) 76 if (!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
77 __dma_page_cpu_to_dev(page, offset, size, dir); 77 __dma_page_cpu_to_dev(page, offset, size, dir);
78 return pfn_to_dma(dev, page_to_pfn(page)) + offset; 78 return pfn_to_dma(dev, page_to_pfn(page)) + offset;
79} 79}
80 80
81static dma_addr_t arm_coherent_dma_map_page(struct device *dev, struct page *page,
82 unsigned long offset, size_t size, enum dma_data_direction dir,
83 struct dma_attrs *attrs)
84{
85 return pfn_to_dma(dev, page_to_pfn(page)) + offset;
86}
87
81/** 88/**
82 * arm_dma_unmap_page - unmap a buffer previously mapped through dma_map_page() 89 * arm_dma_unmap_page - unmap a buffer previously mapped through dma_map_page()
83 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices 90 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
@@ -96,7 +103,7 @@ static void arm_dma_unmap_page(struct device *dev, dma_addr_t handle,
96 size_t size, enum dma_data_direction dir, 103 size_t size, enum dma_data_direction dir,
97 struct dma_attrs *attrs) 104 struct dma_attrs *attrs)
98{ 105{
99 if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) 106 if (!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
100 __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)), 107 __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)),
101 handle & ~PAGE_MASK, size, dir); 108 handle & ~PAGE_MASK, size, dir);
102} 109}
@@ -106,8 +113,7 @@ static void arm_dma_sync_single_for_cpu(struct device *dev,
106{ 113{
107 unsigned int offset = handle & (PAGE_SIZE - 1); 114 unsigned int offset = handle & (PAGE_SIZE - 1);
108 struct page *page = pfn_to_page(dma_to_pfn(dev, handle-offset)); 115 struct page *page = pfn_to_page(dma_to_pfn(dev, handle-offset));
109 if (!arch_is_coherent()) 116 __dma_page_dev_to_cpu(page, offset, size, dir);
110 __dma_page_dev_to_cpu(page, offset, size, dir);
111} 117}
112 118
113static void arm_dma_sync_single_for_device(struct device *dev, 119static void arm_dma_sync_single_for_device(struct device *dev,
@@ -115,8 +121,7 @@ static void arm_dma_sync_single_for_device(struct device *dev,
115{ 121{
116 unsigned int offset = handle & (PAGE_SIZE - 1); 122 unsigned int offset = handle & (PAGE_SIZE - 1);
117 struct page *page = pfn_to_page(dma_to_pfn(dev, handle-offset)); 123 struct page *page = pfn_to_page(dma_to_pfn(dev, handle-offset));
118 if (!arch_is_coherent()) 124 __dma_page_cpu_to_dev(page, offset, size, dir);
119 __dma_page_cpu_to_dev(page, offset, size, dir);
120} 125}
121 126
122static int arm_dma_set_mask(struct device *dev, u64 dma_mask); 127static int arm_dma_set_mask(struct device *dev, u64 dma_mask);
@@ -138,6 +143,22 @@ struct dma_map_ops arm_dma_ops = {
138}; 143};
139EXPORT_SYMBOL(arm_dma_ops); 144EXPORT_SYMBOL(arm_dma_ops);
140 145
146static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
147 dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs);
148static void arm_coherent_dma_free(struct device *dev, size_t size, void *cpu_addr,
149 dma_addr_t handle, struct dma_attrs *attrs);
150
151struct dma_map_ops arm_coherent_dma_ops = {
152 .alloc = arm_coherent_dma_alloc,
153 .free = arm_coherent_dma_free,
154 .mmap = arm_dma_mmap,
155 .get_sgtable = arm_dma_get_sgtable,
156 .map_page = arm_coherent_dma_map_page,
157 .map_sg = arm_dma_map_sg,
158 .set_dma_mask = arm_dma_set_mask,
159};
160EXPORT_SYMBOL(arm_coherent_dma_ops);
161
141static u64 get_coherent_dma_mask(struct device *dev) 162static u64 get_coherent_dma_mask(struct device *dev)
142{ 163{
143 u64 mask = (u64)arm_dma_limit; 164 u64 mask = (u64)arm_dma_limit;
@@ -586,7 +607,7 @@ static void *__alloc_simple_buffer(struct device *dev, size_t size, gfp_t gfp,
586 607
587 608
588static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, 609static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
589 gfp_t gfp, pgprot_t prot, const void *caller) 610 gfp_t gfp, pgprot_t prot, bool is_coherent, const void *caller)
590{ 611{
591 u64 mask = get_coherent_dma_mask(dev); 612 u64 mask = get_coherent_dma_mask(dev);
592 struct page *page; 613 struct page *page;
@@ -619,7 +640,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
619 *handle = DMA_ERROR_CODE; 640 *handle = DMA_ERROR_CODE;
620 size = PAGE_ALIGN(size); 641 size = PAGE_ALIGN(size);
621 642
622 if (arch_is_coherent() || nommu()) 643 if (is_coherent || nommu())
623 addr = __alloc_simple_buffer(dev, size, gfp, &page); 644 addr = __alloc_simple_buffer(dev, size, gfp, &page);
624 else if (gfp & GFP_ATOMIC) 645 else if (gfp & GFP_ATOMIC)
625 addr = __alloc_from_pool(size, &page); 646 addr = __alloc_from_pool(size, &page);
@@ -647,7 +668,20 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
647 if (dma_alloc_from_coherent(dev, size, handle, &memory)) 668 if (dma_alloc_from_coherent(dev, size, handle, &memory))
648 return memory; 669 return memory;
649 670
650 return __dma_alloc(dev, size, handle, gfp, prot, 671 return __dma_alloc(dev, size, handle, gfp, prot, false,
672 __builtin_return_address(0));
673}
674
675static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
676 dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs)
677{
678 pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
679 void *memory;
680
681 if (dma_alloc_from_coherent(dev, size, handle, &memory))
682 return memory;
683
684 return __dma_alloc(dev, size, handle, gfp, prot, true,
651 __builtin_return_address(0)); 685 __builtin_return_address(0));
652} 686}
653 687
@@ -684,8 +718,9 @@ int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,
684/* 718/*
685 * Free a buffer as defined by the above mapping. 719 * Free a buffer as defined by the above mapping.
686 */ 720 */
687void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, 721static void __arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
688 dma_addr_t handle, struct dma_attrs *attrs) 722 dma_addr_t handle, struct dma_attrs *attrs,
723 bool is_coherent)
689{ 724{
690 struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); 725 struct page *page = pfn_to_page(dma_to_pfn(dev, handle));
691 726
@@ -694,7 +729,7 @@ void arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
694 729
695 size = PAGE_ALIGN(size); 730 size = PAGE_ALIGN(size);
696 731
697 if (arch_is_coherent() || nommu()) { 732 if (is_coherent || nommu()) {
698 __dma_free_buffer(page, size); 733 __dma_free_buffer(page, size);
699 } else if (__free_from_pool(cpu_addr, size)) { 734 } else if (__free_from_pool(cpu_addr, size)) {
700 return; 735 return;
@@ -710,6 +745,18 @@ void arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
710 } 745 }
711} 746}
712 747
748void arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
749 dma_addr_t handle, struct dma_attrs *attrs)
750{
751 __arm_dma_free(dev, size, cpu_addr, handle, attrs, false);
752}
753
754static void arm_coherent_dma_free(struct device *dev, size_t size, void *cpu_addr,
755 dma_addr_t handle, struct dma_attrs *attrs)
756{
757 __arm_dma_free(dev, size, cpu_addr, handle, attrs, true);
758}
759
713int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt, 760int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
714 void *cpu_addr, dma_addr_t handle, size_t size, 761 void *cpu_addr, dma_addr_t handle, size_t size,
715 struct dma_attrs *attrs) 762 struct dma_attrs *attrs)
@@ -1012,11 +1059,12 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, gfp_t
1012 if (!pages[i]) 1059 if (!pages[i])
1013 goto error; 1060 goto error;
1014 1061
1015 if (order) 1062 if (order) {
1016 split_page(pages[i], order); 1063 split_page(pages[i], order);
1017 j = 1 << order; 1064 j = 1 << order;
1018 while (--j) 1065 while (--j)
1019 pages[i + j] = pages[i] + j; 1066 pages[i + j] = pages[i] + j;
1067 }
1020 1068
1021 __dma_clear_buffer(pages[i], PAGE_SIZE << order); 1069 __dma_clear_buffer(pages[i], PAGE_SIZE << order);
1022 i += 1 << order; 1070 i += 1 << order;
@@ -1303,7 +1351,8 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,
1303 */ 1351 */
1304static int __map_sg_chunk(struct device *dev, struct scatterlist *sg, 1352static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
1305 size_t size, dma_addr_t *handle, 1353 size_t size, dma_addr_t *handle,
1306 enum dma_data_direction dir, struct dma_attrs *attrs) 1354 enum dma_data_direction dir, struct dma_attrs *attrs,
1355 bool is_coherent)
1307{ 1356{
1308 struct dma_iommu_mapping *mapping = dev->archdata.mapping; 1357 struct dma_iommu_mapping *mapping = dev->archdata.mapping;
1309 dma_addr_t iova, iova_base; 1358 dma_addr_t iova, iova_base;
@@ -1322,8 +1371,8 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
1322 phys_addr_t phys = page_to_phys(sg_page(s)); 1371 phys_addr_t phys = page_to_phys(sg_page(s));
1323 unsigned int len = PAGE_ALIGN(s->offset + s->length); 1372 unsigned int len = PAGE_ALIGN(s->offset + s->length);
1324 1373
1325 if (!arch_is_coherent() && 1374 if (!is_coherent &&
1326 !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) 1375 !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
1327 __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir); 1376 __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
1328 1377
1329 ret = iommu_map(mapping->domain, iova, phys, len, 0); 1378 ret = iommu_map(mapping->domain, iova, phys, len, 0);
@@ -1341,20 +1390,9 @@ fail:
1341 return ret; 1390 return ret;
1342} 1391}
1343 1392
1344/** 1393static int __iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
1345 * arm_iommu_map_sg - map a set of SG buffers for streaming mode DMA 1394 enum dma_data_direction dir, struct dma_attrs *attrs,
1346 * @dev: valid struct device pointer 1395 bool is_coherent)
1347 * @sg: list of buffers
1348 * @nents: number of buffers to map
1349 * @dir: DMA transfer direction
1350 *
1351 * Map a set of buffers described by scatterlist in streaming mode for DMA.
1352 * The scatter gather list elements are merged together (if possible) and
1353 * tagged with the appropriate dma address and length. They are obtained via
1354 * sg_dma_{address,length}.
1355 */
1356int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
1357 enum dma_data_direction dir, struct dma_attrs *attrs)
1358{ 1396{
1359 struct scatterlist *s = sg, *dma = sg, *start = sg; 1397 struct scatterlist *s = sg, *dma = sg, *start = sg;
1360 int i, count = 0; 1398 int i, count = 0;
@@ -1370,7 +1408,7 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
1370 1408
1371 if (s->offset || (size & ~PAGE_MASK) || size + s->length > max) { 1409 if (s->offset || (size & ~PAGE_MASK) || size + s->length > max) {
1372 if (__map_sg_chunk(dev, start, size, &dma->dma_address, 1410 if (__map_sg_chunk(dev, start, size, &dma->dma_address,
1373 dir, attrs) < 0) 1411 dir, attrs, is_coherent) < 0)
1374 goto bad_mapping; 1412 goto bad_mapping;
1375 1413
1376 dma->dma_address += offset; 1414 dma->dma_address += offset;
@@ -1383,7 +1421,8 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
1383 } 1421 }
1384 size += s->length; 1422 size += s->length;
1385 } 1423 }
1386 if (__map_sg_chunk(dev, start, size, &dma->dma_address, dir, attrs) < 0) 1424 if (__map_sg_chunk(dev, start, size, &dma->dma_address, dir, attrs,
1425 is_coherent) < 0)
1387 goto bad_mapping; 1426 goto bad_mapping;
1388 1427
1389 dma->dma_address += offset; 1428 dma->dma_address += offset;
@@ -1398,17 +1437,44 @@ bad_mapping:
1398} 1437}
1399 1438
1400/** 1439/**
1401 * arm_iommu_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg 1440 * arm_coherent_iommu_map_sg - map a set of SG buffers for streaming mode DMA
1402 * @dev: valid struct device pointer 1441 * @dev: valid struct device pointer
1403 * @sg: list of buffers 1442 * @sg: list of buffers
1404 * @nents: number of buffers to unmap (same as was passed to dma_map_sg) 1443 * @nents: number of buffers to map
1405 * @dir: DMA transfer direction (same as was passed to dma_map_sg) 1444 * @dir: DMA transfer direction
1406 * 1445 *
1407 * Unmap a set of streaming mode DMA translations. Again, CPU access 1446 * Map a set of i/o coherent buffers described by scatterlist in streaming
1408 * rules concerning calls here are the same as for dma_unmap_single(). 1447 * mode for DMA. The scatter gather list elements are merged together (if
1448 * possible) and tagged with the appropriate dma address and length. They are
1449 * obtained via sg_dma_{address,length}.
1409 */ 1450 */
1410void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, 1451int arm_coherent_iommu_map_sg(struct device *dev, struct scatterlist *sg,
1411 enum dma_data_direction dir, struct dma_attrs *attrs) 1452 int nents, enum dma_data_direction dir, struct dma_attrs *attrs)
1453{
1454 return __iommu_map_sg(dev, sg, nents, dir, attrs, true);
1455}
1456
1457/**
1458 * arm_iommu_map_sg - map a set of SG buffers for streaming mode DMA
1459 * @dev: valid struct device pointer
1460 * @sg: list of buffers
1461 * @nents: number of buffers to map
1462 * @dir: DMA transfer direction
1463 *
1464 * Map a set of buffers described by scatterlist in streaming mode for DMA.
1465 * The scatter gather list elements are merged together (if possible) and
1466 * tagged with the appropriate dma address and length. They are obtained via
1467 * sg_dma_{address,length}.
1468 */
1469int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg,
1470 int nents, enum dma_data_direction dir, struct dma_attrs *attrs)
1471{
1472 return __iommu_map_sg(dev, sg, nents, dir, attrs, false);
1473}
1474
1475static void __iommu_unmap_sg(struct device *dev, struct scatterlist *sg,
1476 int nents, enum dma_data_direction dir, struct dma_attrs *attrs,
1477 bool is_coherent)
1412{ 1478{
1413 struct scatterlist *s; 1479 struct scatterlist *s;
1414 int i; 1480 int i;
@@ -1417,7 +1483,7 @@ void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
1417 if (sg_dma_len(s)) 1483 if (sg_dma_len(s))
1418 __iommu_remove_mapping(dev, sg_dma_address(s), 1484 __iommu_remove_mapping(dev, sg_dma_address(s),
1419 sg_dma_len(s)); 1485 sg_dma_len(s));
1420 if (!arch_is_coherent() && 1486 if (!is_coherent &&
1421 !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) 1487 !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
1422 __dma_page_dev_to_cpu(sg_page(s), s->offset, 1488 __dma_page_dev_to_cpu(sg_page(s), s->offset,
1423 s->length, dir); 1489 s->length, dir);
@@ -1425,6 +1491,38 @@ void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
1425} 1491}
1426 1492
1427/** 1493/**
1494 * arm_coherent_iommu_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg
1495 * @dev: valid struct device pointer
1496 * @sg: list of buffers
1497 * @nents: number of buffers to unmap (same as was passed to dma_map_sg)
1498 * @dir: DMA transfer direction (same as was passed to dma_map_sg)
1499 *
1500 * Unmap a set of streaming mode DMA translations. Again, CPU access
1501 * rules concerning calls here are the same as for dma_unmap_single().
1502 */
1503void arm_coherent_iommu_unmap_sg(struct device *dev, struct scatterlist *sg,
1504 int nents, enum dma_data_direction dir, struct dma_attrs *attrs)
1505{
1506 __iommu_unmap_sg(dev, sg, nents, dir, attrs, true);
1507}
1508
1509/**
1510 * arm_iommu_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg
1511 * @dev: valid struct device pointer
1512 * @sg: list of buffers
1513 * @nents: number of buffers to unmap (same as was passed to dma_map_sg)
1514 * @dir: DMA transfer direction (same as was passed to dma_map_sg)
1515 *
1516 * Unmap a set of streaming mode DMA translations. Again, CPU access
1517 * rules concerning calls here are the same as for dma_unmap_single().
1518 */
1519void arm_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
1520 enum dma_data_direction dir, struct dma_attrs *attrs)
1521{
1522 __iommu_unmap_sg(dev, sg, nents, dir, attrs, false);
1523}
1524
1525/**
1428 * arm_iommu_sync_sg_for_cpu 1526 * arm_iommu_sync_sg_for_cpu
1429 * @dev: valid struct device pointer 1527 * @dev: valid struct device pointer
1430 * @sg: list of buffers 1528 * @sg: list of buffers
@@ -1438,8 +1536,7 @@ void arm_iommu_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
1438 int i; 1536 int i;
1439 1537
1440 for_each_sg(sg, s, nents, i) 1538 for_each_sg(sg, s, nents, i)
1441 if (!arch_is_coherent()) 1539 __dma_page_dev_to_cpu(sg_page(s), s->offset, s->length, dir);
1442 __dma_page_dev_to_cpu(sg_page(s), s->offset, s->length, dir);
1443 1540
1444} 1541}
1445 1542
@@ -1457,22 +1554,21 @@ void arm_iommu_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
1457 int i; 1554 int i;
1458 1555
1459 for_each_sg(sg, s, nents, i) 1556 for_each_sg(sg, s, nents, i)
1460 if (!arch_is_coherent()) 1557 __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
1461 __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
1462} 1558}
1463 1559
1464 1560
1465/** 1561/**
1466 * arm_iommu_map_page 1562 * arm_coherent_iommu_map_page
1467 * @dev: valid struct device pointer 1563 * @dev: valid struct device pointer
1468 * @page: page that buffer resides in 1564 * @page: page that buffer resides in
1469 * @offset: offset into page for start of buffer 1565 * @offset: offset into page for start of buffer
1470 * @size: size of buffer to map 1566 * @size: size of buffer to map
1471 * @dir: DMA transfer direction 1567 * @dir: DMA transfer direction
1472 * 1568 *
1473 * IOMMU aware version of arm_dma_map_page() 1569 * Coherent IOMMU aware version of arm_dma_map_page()
1474 */ 1570 */
1475static dma_addr_t arm_iommu_map_page(struct device *dev, struct page *page, 1571static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *page,
1476 unsigned long offset, size_t size, enum dma_data_direction dir, 1572 unsigned long offset, size_t size, enum dma_data_direction dir,
1477 struct dma_attrs *attrs) 1573 struct dma_attrs *attrs)
1478{ 1574{
@@ -1480,9 +1576,6 @@ static dma_addr_t arm_iommu_map_page(struct device *dev, struct page *page,
1480 dma_addr_t dma_addr; 1576 dma_addr_t dma_addr;
1481 int ret, len = PAGE_ALIGN(size + offset); 1577 int ret, len = PAGE_ALIGN(size + offset);
1482 1578
1483 if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
1484 __dma_page_cpu_to_dev(page, offset, size, dir);
1485
1486 dma_addr = __alloc_iova(mapping, len); 1579 dma_addr = __alloc_iova(mapping, len);
1487 if (dma_addr == DMA_ERROR_CODE) 1580 if (dma_addr == DMA_ERROR_CODE)
1488 return dma_addr; 1581 return dma_addr;
@@ -1498,6 +1591,51 @@ fail:
1498} 1591}
1499 1592
1500/** 1593/**
1594 * arm_iommu_map_page
1595 * @dev: valid struct device pointer
1596 * @page: page that buffer resides in
1597 * @offset: offset into page for start of buffer
1598 * @size: size of buffer to map
1599 * @dir: DMA transfer direction
1600 *
1601 * IOMMU aware version of arm_dma_map_page()
1602 */
1603static dma_addr_t arm_iommu_map_page(struct device *dev, struct page *page,
1604 unsigned long offset, size_t size, enum dma_data_direction dir,
1605 struct dma_attrs *attrs)
1606{
1607 if (!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
1608 __dma_page_cpu_to_dev(page, offset, size, dir);
1609
1610 return arm_coherent_iommu_map_page(dev, page, offset, size, dir, attrs);
1611}
1612
1613/**
1614 * arm_coherent_iommu_unmap_page
1615 * @dev: valid struct device pointer
1616 * @handle: DMA address of buffer
1617 * @size: size of buffer (same as passed to dma_map_page)
1618 * @dir: DMA transfer direction (same as passed to dma_map_page)
1619 *
1620 * Coherent IOMMU aware version of arm_dma_unmap_page()
1621 */
1622static void arm_coherent_iommu_unmap_page(struct device *dev, dma_addr_t handle,
1623 size_t size, enum dma_data_direction dir,
1624 struct dma_attrs *attrs)
1625{
1626 struct dma_iommu_mapping *mapping = dev->archdata.mapping;
1627 dma_addr_t iova = handle & PAGE_MASK;
1628 int offset = handle & ~PAGE_MASK;
1629 int len = PAGE_ALIGN(size + offset);
1630
1631 if (!iova)
1632 return;
1633
1634 iommu_unmap(mapping->domain, iova, len);
1635 __free_iova(mapping, iova, len);
1636}
1637
1638/**
1501 * arm_iommu_unmap_page 1639 * arm_iommu_unmap_page
1502 * @dev: valid struct device pointer 1640 * @dev: valid struct device pointer
1503 * @handle: DMA address of buffer 1641 * @handle: DMA address of buffer
@@ -1519,7 +1657,7 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle,
1519 if (!iova) 1657 if (!iova)
1520 return; 1658 return;
1521 1659
1522 if (!arch_is_coherent() && !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) 1660 if (!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
1523 __dma_page_dev_to_cpu(page, offset, size, dir); 1661 __dma_page_dev_to_cpu(page, offset, size, dir);
1524 1662
1525 iommu_unmap(mapping->domain, iova, len); 1663 iommu_unmap(mapping->domain, iova, len);
@@ -1537,8 +1675,7 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev,
1537 if (!iova) 1675 if (!iova)
1538 return; 1676 return;
1539 1677
1540 if (!arch_is_coherent()) 1678 __dma_page_dev_to_cpu(page, offset, size, dir);
1541 __dma_page_dev_to_cpu(page, offset, size, dir);
1542} 1679}
1543 1680
1544static void arm_iommu_sync_single_for_device(struct device *dev, 1681static void arm_iommu_sync_single_for_device(struct device *dev,
@@ -1572,6 +1709,19 @@ struct dma_map_ops iommu_ops = {
1572 .sync_sg_for_device = arm_iommu_sync_sg_for_device, 1709 .sync_sg_for_device = arm_iommu_sync_sg_for_device,
1573}; 1710};
1574 1711
1712struct dma_map_ops iommu_coherent_ops = {
1713 .alloc = arm_iommu_alloc_attrs,
1714 .free = arm_iommu_free_attrs,
1715 .mmap = arm_iommu_mmap_attrs,
1716 .get_sgtable = arm_iommu_get_sgtable,
1717
1718 .map_page = arm_coherent_iommu_map_page,
1719 .unmap_page = arm_coherent_iommu_unmap_page,
1720
1721 .map_sg = arm_coherent_iommu_map_sg,
1722 .unmap_sg = arm_coherent_iommu_unmap_sg,
1723};
1724
1575/** 1725/**
1576 * arm_iommu_create_mapping 1726 * arm_iommu_create_mapping
1577 * @bus: pointer to the bus holding the client device (for IOMMU calls) 1727 * @bus: pointer to the bus holding the client device (for IOMMU calls)
@@ -1665,7 +1815,7 @@ int arm_iommu_attach_device(struct device *dev,
1665 dev->archdata.mapping = mapping; 1815 dev->archdata.mapping = mapping;
1666 set_dma_ops(dev, &iommu_ops); 1816 set_dma_ops(dev, &iommu_ops);
1667 1817
1668 pr_info("Attached IOMMU controller to %s device.\n", dev_name(dev)); 1818 pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev));
1669 return 0; 1819 return 0;
1670} 1820}
1671 1821
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 18144e6a3115..941dfb9e9a78 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -423,17 +423,6 @@ static void __init build_mem_type_table(void)
423 vecs_pgprot = kern_pgprot = user_pgprot = cp->pte; 423 vecs_pgprot = kern_pgprot = user_pgprot = cp->pte;
424 424
425 /* 425 /*
426 * Enable CPU-specific coherency if supported.
427 * (Only available on XSC3 at the moment.)
428 */
429 if (arch_is_coherent() && cpu_is_xsc3()) {
430 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
431 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
432 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
433 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
434 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
435 }
436 /*
437 * ARMv6 and above have extended page tables. 426 * ARMv6 and above have extended page tables.
438 */ 427 */
439 if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) { 428 if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 34d94c762a1e..9a1469474f55 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -315,6 +315,7 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
315{ 315{
316 unsigned long mask, pfn, pageno, start = 0; 316 unsigned long mask, pfn, pageno, start = 0;
317 struct cma *cma = dev_get_cma_area(dev); 317 struct cma *cma = dev_get_cma_area(dev);
318 struct page *page = NULL;
318 int ret; 319 int ret;
319 320
320 if (!cma || !cma->count) 321 if (!cma || !cma->count)
@@ -336,18 +337,17 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
336 for (;;) { 337 for (;;) {
337 pageno = bitmap_find_next_zero_area(cma->bitmap, cma->count, 338 pageno = bitmap_find_next_zero_area(cma->bitmap, cma->count,
338 start, count, mask); 339 start, count, mask);
339 if (pageno >= cma->count) { 340 if (pageno >= cma->count)
340 ret = -ENOMEM; 341 break;
341 goto error;
342 }
343 342
344 pfn = cma->base_pfn + pageno; 343 pfn = cma->base_pfn + pageno;
345 ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA); 344 ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
346 if (ret == 0) { 345 if (ret == 0) {
347 bitmap_set(cma->bitmap, pageno, count); 346 bitmap_set(cma->bitmap, pageno, count);
347 page = pfn_to_page(pfn);
348 break; 348 break;
349 } else if (ret != -EBUSY) { 349 } else if (ret != -EBUSY) {
350 goto error; 350 break;
351 } 351 }
352 pr_debug("%s(): memory range at %p is busy, retrying\n", 352 pr_debug("%s(): memory range at %p is busy, retrying\n",
353 __func__, pfn_to_page(pfn)); 353 __func__, pfn_to_page(pfn));
@@ -356,12 +356,8 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
356 } 356 }
357 357
358 mutex_unlock(&cma_mutex); 358 mutex_unlock(&cma_mutex);
359 359 pr_debug("%s(): returned %p\n", __func__, page);
360 pr_debug("%s(): returned %p\n", __func__, pfn_to_page(pfn)); 360 return page;
361 return pfn_to_page(pfn);
362error:
363 mutex_unlock(&cma_mutex);
364 return NULL;
365} 361}
366 362
367/** 363/**