Skip to content

Commit 4c612ad

Browse files
Eugeniy Paltsevvineetgarc
authored andcommitted
ARC: dma [non IOC]: fix arc_dma_sync_single_for_(device|cpu)
ARC backend for dma_sync_single_for_(device|cpu) was broken as it was not honoring the @dir argument and simply forcing it based on the call: - arc_dma_sync_single_for_device(dir) assumed DMA_TO_DEVICE (cache wback) - arc_dma_sync_single_for_cpu(dir) assumed DMA_FROM_DEVICE (cache inv) This is not true given the DMA API programming model and has been discussed here [1] in some detail. Interestingly while the deficiency has been there forever, it only started showing up after 4.17 dma common ops rework, commit a8eb92d ("arc: fix arc_dma_{map,unmap}_page") which wired up these calls under the more commonly used dma_map_page API triggering the issue. [1]: https://lkml.org/lkml/2018/5/18/979 Fixes: commit a8eb92d ("arc: fix arc_dma_{map,unmap}_page") Cc: stable@kernel.org # v4.17+ Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com> Signed-off-by: Vineet Gupta <vgupta@synopsys.com> [vgupta: reworked changelog]
1 parent 6d20cae commit 4c612ad

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

‎arch/arc/mm/dma.c‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,59 @@ int arch_dma_mmap(struct device *dev, struct vm_area_struct *vma,
129129
return ret;
130130
}
131131

132+
/*
133+
* Cache operations depending on function and direction argument, inspired by
134+
* https://lkml.org/lkml/2018/5/18/979
135+
* "dma_sync_*_for_cpu and direction=TO_DEVICE (was Re: [PATCH 02/20]
136+
* dma-mapping: provide a generic dma-noncoherent implementation)"
137+
*
138+
* | map == for_device | unmap == for_cpu
139+
* |----------------------------------------------------------------
140+
* TO_DEV | writeback writeback | none none
141+
* FROM_DEV | invalidate invalidate | invalidate* invalidate*
142+
* BIDIR | writeback+inv writeback+inv | invalidate invalidate
143+
*
144+
* [*] needed for CPU speculative prefetches
145+
*
146+
* NOTE: we don't check the validity of direction argument as it is done in
147+
* upper layer functions (in include/linux/dma-mapping.h)
148+
*/
149+
132150
void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
133151
size_t size, enum dma_data_direction dir)
134152
{
135-
dma_cache_wback(paddr, size);
153+
switch (dir) {
154+
case DMA_TO_DEVICE:
155+
dma_cache_wback(paddr, size);
156+
break;
157+
158+
case DMA_FROM_DEVICE:
159+
dma_cache_inv(paddr, size);
160+
break;
161+
162+
case DMA_BIDIRECTIONAL:
163+
dma_cache_wback_inv(paddr, size);
164+
break;
165+
166+
default:
167+
break;
168+
}
136169
}
137170

138171
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
139172
size_t size, enum dma_data_direction dir)
140173
{
141-
dma_cache_inv(paddr, size);
174+
switch (dir) {
175+
case DMA_TO_DEVICE:
176+
break;
177+
178+
/* FROM_DEVICE invalidate needed if speculative CPU prefetch only */
179+
case DMA_FROM_DEVICE:
180+
case DMA_BIDIRECTIONAL:
181+
dma_cache_inv(paddr, size);
182+
break;
183+
184+
default:
185+
break;
186+
}
142187
}

0 commit comments

Comments
 (0)