diff options
author | Christoph Hellwig <hch@lst.de> | 2018-07-19 08:54:39 -0400 |
---|---|---|
committer | Michal Simek <michal.simek@xilinx.com> | 2018-07-20 08:29:47 -0400 |
commit | 5411ad27dba1e59923f3865f90ab756fd6b9ab3c (patch) | |
tree | fba184190c76cefbaf233b08dbce9cb88adc8353 | |
parent | bd05a58ddfd719015d66e8670af48feb386a3ca6 (diff) |
microblaze: use generic dma_noncoherent_ops
Switch to the generic noncoherent direct mapping implementation.
This removes the direction-based optimizations in
sync_{single,sg}_for_{cpu,device} which were marked untestested and
do not match the usually very well tested {un,}map_{single,sg}
implementations.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
-rw-r--r-- | arch/microblaze/Kconfig | 4 | ||||
-rw-r--r-- | arch/microblaze/include/asm/Kbuild | 1 | ||||
-rw-r--r-- | arch/microblaze/include/asm/dma-mapping.h | 28 | ||||
-rw-r--r-- | arch/microblaze/include/asm/pgtable.h | 2 | ||||
-rw-r--r-- | arch/microblaze/kernel/dma.c | 144 | ||||
-rw-r--r-- | arch/microblaze/mm/consistent.c | 9 |
6 files changed, 22 insertions, 166 deletions
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig index d14782100088..848e31a86ba5 100644 --- a/arch/microblaze/Kconfig +++ b/arch/microblaze/Kconfig | |||
@@ -1,6 +1,8 @@ | |||
1 | config MICROBLAZE | 1 | config MICROBLAZE |
2 | def_bool y | 2 | def_bool y |
3 | select ARCH_HAS_GCOV_PROFILE_ALL | 3 | select ARCH_HAS_GCOV_PROFILE_ALL |
4 | select ARCH_HAS_SYNC_DMA_FOR_CPU | ||
5 | select ARCH_HAS_SYNC_DMA_FOR_DEVICE | ||
4 | select ARCH_MIGHT_HAVE_PC_PARPORT | 6 | select ARCH_MIGHT_HAVE_PC_PARPORT |
5 | select ARCH_NO_COHERENT_DMA_MMAP if !MMU | 7 | select ARCH_NO_COHERENT_DMA_MMAP if !MMU |
6 | select ARCH_WANT_IPC_PARSE_VERSION | 8 | select ARCH_WANT_IPC_PARSE_VERSION |
@@ -8,6 +10,8 @@ config MICROBLAZE | |||
8 | select TIMER_OF | 10 | select TIMER_OF |
9 | select CLONE_BACKWARDS3 | 11 | select CLONE_BACKWARDS3 |
10 | select COMMON_CLK | 12 | select COMMON_CLK |
13 | select DMA_NONCOHERENT_OPS | ||
14 | select DMA_NONCOHERENT_MMAP | ||
11 | select GENERIC_ATOMIC64 | 15 | select GENERIC_ATOMIC64 |
12 | select GENERIC_CLOCKEVENTS | 16 | select GENERIC_CLOCKEVENTS |
13 | select GENERIC_CPU_DEVICES | 17 | select GENERIC_CPU_DEVICES |
diff --git a/arch/microblaze/include/asm/Kbuild b/arch/microblaze/include/asm/Kbuild index fe6a6c6e5003..569ba9e670c1 100644 --- a/arch/microblaze/include/asm/Kbuild +++ b/arch/microblaze/include/asm/Kbuild | |||
@@ -5,6 +5,7 @@ generic-y += bugs.h | |||
5 | generic-y += compat.h | 5 | generic-y += compat.h |
6 | generic-y += device.h | 6 | generic-y += device.h |
7 | generic-y += div64.h | 7 | generic-y += div64.h |
8 | generic-y += dma-mapping.h | ||
8 | generic-y += emergency-restart.h | 9 | generic-y += emergency-restart.h |
9 | generic-y += exec.h | 10 | generic-y += exec.h |
10 | generic-y += extable.h | 11 | generic-y += extable.h |
diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h deleted file mode 100644 index add50c1373bf..000000000000 --- a/arch/microblaze/include/asm/dma-mapping.h +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* | ||
2 | * Implements the generic device dma API for microblaze and the pci | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 Michal Simek <monstr@monstr.eu> | ||
5 | * Copyright (C) 2009-2010 PetaLogix | ||
6 | * | ||
7 | * This file is subject to the terms and conditions of the GNU General | ||
8 | * Public License. See the file COPYING in the main directory of this | ||
9 | * archive for more details. | ||
10 | * | ||
11 | * This file is base on powerpc and x86 dma-mapping.h versions | ||
12 | * Copyright (C) 2004 IBM | ||
13 | */ | ||
14 | |||
15 | #ifndef _ASM_MICROBLAZE_DMA_MAPPING_H | ||
16 | #define _ASM_MICROBLAZE_DMA_MAPPING_H | ||
17 | |||
18 | /* | ||
19 | * Available generic sets of operations | ||
20 | */ | ||
21 | extern const struct dma_map_ops dma_nommu_ops; | ||
22 | |||
23 | static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) | ||
24 | { | ||
25 | return &dma_nommu_ops; | ||
26 | } | ||
27 | |||
28 | #endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */ | ||
diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h index db8b1fa83452..8a2e654b709f 100644 --- a/arch/microblaze/include/asm/pgtable.h +++ b/arch/microblaze/include/asm/pgtable.h | |||
@@ -553,8 +553,6 @@ void __init *early_get_page(void); | |||
553 | 553 | ||
554 | extern unsigned long ioremap_bot, ioremap_base; | 554 | extern unsigned long ioremap_bot, ioremap_base; |
555 | 555 | ||
556 | void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle); | ||
557 | void consistent_free(size_t size, void *vaddr); | ||
558 | void consistent_sync(void *vaddr, size_t size, int direction); | 556 | void consistent_sync(void *vaddr, size_t size, int direction); |
559 | void consistent_sync_page(struct page *page, unsigned long offset, | 557 | void consistent_sync_page(struct page *page, unsigned long offset, |
560 | size_t size, int direction); | 558 | size_t size, int direction); |
diff --git a/arch/microblaze/kernel/dma.c b/arch/microblaze/kernel/dma.c index 3145e7dc8ab1..71032cf64669 100644 --- a/arch/microblaze/kernel/dma.c +++ b/arch/microblaze/kernel/dma.c | |||
@@ -8,29 +8,15 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/device.h> | 10 | #include <linux/device.h> |
11 | #include <linux/dma-mapping.h> | 11 | #include <linux/dma-noncoherent.h> |
12 | #include <linux/gfp.h> | 12 | #include <linux/gfp.h> |
13 | #include <linux/dma-debug.h> | 13 | #include <linux/dma-debug.h> |
14 | #include <linux/export.h> | 14 | #include <linux/export.h> |
15 | #include <linux/bug.h> | 15 | #include <linux/bug.h> |
16 | #include <asm/cacheflush.h> | 16 | #include <asm/cacheflush.h> |
17 | 17 | ||
18 | static void *dma_nommu_alloc_coherent(struct device *dev, size_t size, | 18 | static void __dma_sync(struct device *dev, phys_addr_t paddr, size_t size, |
19 | dma_addr_t *dma_handle, gfp_t flag, | 19 | enum dma_data_direction direction) |
20 | unsigned long attrs) | ||
21 | { | ||
22 | return consistent_alloc(flag, size, dma_handle); | ||
23 | } | ||
24 | |||
25 | static void dma_nommu_free_coherent(struct device *dev, size_t size, | ||
26 | void *vaddr, dma_addr_t dma_handle, | ||
27 | unsigned long attrs) | ||
28 | { | ||
29 | consistent_free(size, vaddr); | ||
30 | } | ||
31 | |||
32 | static inline void __dma_sync(unsigned long paddr, | ||
33 | size_t size, enum dma_data_direction direction) | ||
34 | { | 20 | { |
35 | switch (direction) { | 21 | switch (direction) { |
36 | case DMA_TO_DEVICE: | 22 | case DMA_TO_DEVICE: |
@@ -45,113 +31,21 @@ static inline void __dma_sync(unsigned long paddr, | |||
45 | } | 31 | } |
46 | } | 32 | } |
47 | 33 | ||
48 | static int dma_nommu_map_sg(struct device *dev, struct scatterlist *sgl, | 34 | void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, |
49 | int nents, enum dma_data_direction direction, | 35 | size_t size, enum dma_data_direction dir) |
50 | unsigned long attrs) | ||
51 | { | 36 | { |
52 | struct scatterlist *sg; | 37 | __dma_sync(dev, paddr, size, dir); |
53 | int i; | ||
54 | |||
55 | /* FIXME this part of code is untested */ | ||
56 | for_each_sg(sgl, sg, nents, i) { | ||
57 | sg->dma_address = sg_phys(sg); | ||
58 | |||
59 | if (attrs & DMA_ATTR_SKIP_CPU_SYNC) | ||
60 | continue; | ||
61 | |||
62 | __dma_sync(sg_phys(sg), sg->length, direction); | ||
63 | } | ||
64 | |||
65 | return nents; | ||
66 | } | ||
67 | |||
68 | static inline dma_addr_t dma_nommu_map_page(struct device *dev, | ||
69 | struct page *page, | ||
70 | unsigned long offset, | ||
71 | size_t size, | ||
72 | enum dma_data_direction direction, | ||
73 | unsigned long attrs) | ||
74 | { | ||
75 | if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) | ||
76 | __dma_sync(page_to_phys(page) + offset, size, direction); | ||
77 | return page_to_phys(page) + offset; | ||
78 | } | 38 | } |
79 | 39 | ||
80 | static inline void dma_nommu_unmap_page(struct device *dev, | 40 | void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr, |
81 | dma_addr_t dma_address, | 41 | size_t size, enum dma_data_direction dir) |
82 | size_t size, | ||
83 | enum dma_data_direction direction, | ||
84 | unsigned long attrs) | ||
85 | { | 42 | { |
86 | /* There is not necessary to do cache cleanup | 43 | __dma_sync(dev, paddr, size, dir); |
87 | * | ||
88 | * phys_to_virt is here because in __dma_sync_page is __virt_to_phys and | ||
89 | * dma_address is physical address | ||
90 | */ | ||
91 | if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) | ||
92 | __dma_sync(dma_address, size, direction); | ||
93 | } | 44 | } |
94 | 45 | ||
95 | static inline void | 46 | int arch_dma_mmap(struct device *dev, struct vm_area_struct *vma, |
96 | dma_nommu_sync_single_for_cpu(struct device *dev, | 47 | void *cpu_addr, dma_addr_t handle, size_t size, |
97 | dma_addr_t dma_handle, size_t size, | 48 | unsigned long attrs) |
98 | enum dma_data_direction direction) | ||
99 | { | ||
100 | /* | ||
101 | * It's pointless to flush the cache as the memory segment | ||
102 | * is given to the CPU | ||
103 | */ | ||
104 | |||
105 | if (direction == DMA_FROM_DEVICE) | ||
106 | __dma_sync(dma_handle, size, direction); | ||
107 | } | ||
108 | |||
109 | static inline void | ||
110 | dma_nommu_sync_single_for_device(struct device *dev, | ||
111 | dma_addr_t dma_handle, size_t size, | ||
112 | enum dma_data_direction direction) | ||
113 | { | ||
114 | /* | ||
115 | * It's pointless to invalidate the cache if the device isn't | ||
116 | * supposed to write to the relevant region | ||
117 | */ | ||
118 | |||
119 | if (direction == DMA_TO_DEVICE) | ||
120 | __dma_sync(dma_handle, size, direction); | ||
121 | } | ||
122 | |||
123 | static inline void | ||
124 | dma_nommu_sync_sg_for_cpu(struct device *dev, | ||
125 | struct scatterlist *sgl, int nents, | ||
126 | enum dma_data_direction direction) | ||
127 | { | ||
128 | struct scatterlist *sg; | ||
129 | int i; | ||
130 | |||
131 | /* FIXME this part of code is untested */ | ||
132 | if (direction == DMA_FROM_DEVICE) | ||
133 | for_each_sg(sgl, sg, nents, i) | ||
134 | __dma_sync(sg->dma_address, sg->length, direction); | ||
135 | } | ||
136 | |||
137 | static inline void | ||
138 | dma_nommu_sync_sg_for_device(struct device *dev, | ||
139 | struct scatterlist *sgl, int nents, | ||
140 | enum dma_data_direction direction) | ||
141 | { | ||
142 | struct scatterlist *sg; | ||
143 | int i; | ||
144 | |||
145 | /* FIXME this part of code is untested */ | ||
146 | if (direction == DMA_TO_DEVICE) | ||
147 | for_each_sg(sgl, sg, nents, i) | ||
148 | __dma_sync(sg->dma_address, sg->length, direction); | ||
149 | } | ||
150 | |||
151 | static | ||
152 | int dma_nommu_mmap_coherent(struct device *dev, struct vm_area_struct *vma, | ||
153 | void *cpu_addr, dma_addr_t handle, size_t size, | ||
154 | unsigned long attrs) | ||
155 | { | 49 | { |
156 | #ifdef CONFIG_MMU | 50 | #ifdef CONFIG_MMU |
157 | unsigned long user_count = vma_pages(vma); | 51 | unsigned long user_count = vma_pages(vma); |
@@ -170,17 +64,3 @@ int dma_nommu_mmap_coherent(struct device *dev, struct vm_area_struct *vma, | |||
170 | return -ENXIO; | 64 | return -ENXIO; |
171 | #endif | 65 | #endif |
172 | } | 66 | } |
173 | |||
174 | const struct dma_map_ops dma_nommu_ops = { | ||
175 | .alloc = dma_nommu_alloc_coherent, | ||
176 | .free = dma_nommu_free_coherent, | ||
177 | .mmap = dma_nommu_mmap_coherent, | ||
178 | .map_sg = dma_nommu_map_sg, | ||
179 | .map_page = dma_nommu_map_page, | ||
180 | .unmap_page = dma_nommu_unmap_page, | ||
181 | .sync_single_for_cpu = dma_nommu_sync_single_for_cpu, | ||
182 | .sync_single_for_device = dma_nommu_sync_single_for_device, | ||
183 | .sync_sg_for_cpu = dma_nommu_sync_sg_for_cpu, | ||
184 | .sync_sg_for_device = dma_nommu_sync_sg_for_device, | ||
185 | }; | ||
186 | EXPORT_SYMBOL(dma_nommu_ops); | ||
diff --git a/arch/microblaze/mm/consistent.c b/arch/microblaze/mm/consistent.c index b06c3a7faf20..b9a9c8c3397b 100644 --- a/arch/microblaze/mm/consistent.c +++ b/arch/microblaze/mm/consistent.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/pci.h> | 33 | #include <linux/pci.h> |
34 | #include <linux/interrupt.h> | 34 | #include <linux/interrupt.h> |
35 | #include <linux/gfp.h> | 35 | #include <linux/gfp.h> |
36 | #include <linux/dma-noncoherent.h> | ||
36 | 37 | ||
37 | #include <asm/pgalloc.h> | 38 | #include <asm/pgalloc.h> |
38 | #include <linux/io.h> | 39 | #include <linux/io.h> |
@@ -59,7 +60,8 @@ | |||
59 | * uncached region. This will no doubt cause big problems if memory allocated | 60 | * uncached region. This will no doubt cause big problems if memory allocated |
60 | * here is not also freed properly. -- JW | 61 | * here is not also freed properly. -- JW |
61 | */ | 62 | */ |
62 | void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle) | 63 | void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, |
64 | gfp_t gfp, unsigned long attrs) | ||
63 | { | 65 | { |
64 | unsigned long order, vaddr; | 66 | unsigned long order, vaddr; |
65 | void *ret; | 67 | void *ret; |
@@ -154,7 +156,6 @@ void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle) | |||
154 | 156 | ||
155 | return ret; | 157 | return ret; |
156 | } | 158 | } |
157 | EXPORT_SYMBOL(consistent_alloc); | ||
158 | 159 | ||
159 | #ifdef CONFIG_MMU | 160 | #ifdef CONFIG_MMU |
160 | static pte_t *consistent_virt_to_pte(void *vaddr) | 161 | static pte_t *consistent_virt_to_pte(void *vaddr) |
@@ -178,7 +179,8 @@ unsigned long consistent_virt_to_pfn(void *vaddr) | |||
178 | /* | 179 | /* |
179 | * free page(s) as defined by the above mapping. | 180 | * free page(s) as defined by the above mapping. |
180 | */ | 181 | */ |
181 | void consistent_free(size_t size, void *vaddr) | 182 | void arch_dma_free(struct device *dev, size_t size, void *vaddr, |
183 | dma_addr_t dma_addr, unsigned long attrs) | ||
182 | { | 184 | { |
183 | struct page *page; | 185 | struct page *page; |
184 | 186 | ||
@@ -218,7 +220,6 @@ void consistent_free(size_t size, void *vaddr) | |||
218 | flush_tlb_all(); | 220 | flush_tlb_all(); |
219 | #endif | 221 | #endif |
220 | } | 222 | } |
221 | EXPORT_SYMBOL(consistent_free); | ||
222 | 223 | ||
223 | /* | 224 | /* |
224 | * make an area consistent. | 225 | * make an area consistent. |