summaryrefslogtreecommitdiffstats
path: root/arch/riscv
diff options
context:
space:
mode:
authorDenis Orlov <denorl2009@gmail.com>2023-06-05 00:45:01 +0300
committerSascha Hauer <s.hauer@pengutronix.de>2023-06-06 09:12:28 +0200
commit00ac36614d66c25702ee712e91c793d2ac7dd9a2 (patch)
treebb8d5612534c523151c9067561c4a6fd2b2a8eba /arch/riscv
parent9d1bfb8417329b998407a7141d5a8558f735bf40 (diff)
downloadbarebox-00ac36614d66c25702ee712e91c793d2ac7dd9a2.tar.gz
barebox-00ac36614d66c25702ee712e91c793d2ac7dd9a2.tar.xz
dma: rework dma_sync_single_for_*() interface
Currently, a lot of code handles dma_addr_t values as if they actually hold CPU addresses. However, this is not always true. For example, MIPS architecture requires an explicit conversion from the physical address space to some virtual address space segment to get a valid CPU-side pointer. Another issue is that DMA ranges that may be specified in a device tree will not work this way. To get from a virtual address to a dma handle and vice versa we need to add/subtract some offset, which is calculated from "dma-ranges" property. Only dma_map_single() was doing this, but dma_sync_single_for_*() also should. Improve the interface by adding 'struct device' as the first argument to the dma_sync_single_for_*(). This allows to do cpu_to_dma/dma_to_cpu() conversions in common code and call into arch-specific code with proper cpu-side addresses. To make things more clear, make the virtual address argument of those arch-side functions be properly represented with a void* type. Apply the required changes in device drivers that use the affected functions, making them pass the appropriate device pointer. Signed-off-by: Denis Orlov <denorl2009@gmail.com> Link: https://lore.barebox.org/20230604215002.20240-2-denorl2009@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/riscv')
-rw-r--r--arch/riscv/cpu/dma.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/arch/riscv/cpu/dma.c b/arch/riscv/cpu/dma.c
index 5a4d714e5e..511170aaa4 100644
--- a/arch/riscv/cpu/dma.c
+++ b/arch/riscv/cpu/dma.c
@@ -52,23 +52,24 @@ void dma_set_ops(const struct dma_ops *ops)
dma_ops = ops;
}
-void dma_sync_single_for_cpu(dma_addr_t address, size_t size, enum dma_data_direction dir)
+void arch_sync_dma_for_cpu(void *vaddr, size_t size,
+ enum dma_data_direction dir)
{
- /*
- * FIXME: This function needs a device argument to support non 1:1 mappings
- */
+ unsigned long start = (unsigned long)vaddr;
+ unsigned long end = start + size;
+
if (dir != DMA_TO_DEVICE)
- dma_ops->inv_range(address, address + size);
+ dma_ops->inv_range(start, end);
}
-void dma_sync_single_for_device(dma_addr_t address, size_t size, enum dma_data_direction dir)
+void arch_sync_dma_for_device(void *vaddr, size_t size,
+ enum dma_data_direction dir)
{
- /*
- * FIXME: This function needs a device argument to support non 1:1 mappings
- */
+ unsigned long start = (unsigned long)vaddr;
+ unsigned long end = start + size;
if (dir == DMA_FROM_DEVICE)
- dma_ops->inv_range(address, address + size);
+ dma_ops->inv_range(start, end);
else
- dma_ops->flush_range(address, address + size);
+ dma_ops->flush_range(start, end);
}