diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2021-03-03 17:12:47 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-03-04 12:11:22 +0100 |
commit | 3f975f810bd34c56cfafd88d1d4e6eb669e74561 (patch) | |
tree | 4ee73d2980ee39d9c6bed962f04ddd4f7eb63430 /drivers/dma | |
parent | 598217bad38f62aa1691742839cfe856ba2a99e2 (diff) | |
download | barebox-3f975f810bd34c56cfafd88d1d4e6eb669e74561.tar.gz barebox-3f975f810bd34c56cfafd88d1d4e6eb669e74561.tar.xz |
dma: move dma_map/unmap_single from ARM to common code
There's nothing ARM specific about these functions. Move them to a
common location, so other arches can use them as well.
This also fixes a bug on ARM MMU=n configurations:
Previously these two functions these functions only respected
dma-ranges translation when compiled with MMU support. DMA address
translation is applicable regardless of CPU use of MMU though.
Now, dma-ranges should be respected unconditionally.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/dma')
-rw-r--r-- | drivers/dma/Makefile | 1 | ||||
-rw-r--r-- | drivers/dma/map.c | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile index 7a3a3b2bd8..49d6d6573f 100644 --- a/drivers/dma/Makefile +++ b/drivers/dma/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_MXS_APBH_DMA) += apbh_dma.o +obj-$(CONFIG_HAS_DMA) += map.o diff --git a/drivers/dma/map.c b/drivers/dma/map.c new file mode 100644 index 0000000000..a3e1b3b5b5 --- /dev/null +++ b/drivers/dma/map.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* SPDX-FileCopyrightText: 2012 Marc Kleine-Budde <mkl@pengutronix.de> */ + +#include <dma.h> + +static inline dma_addr_t cpu_to_dma(struct device_d *dev, unsigned long cpu_addr) +{ + dma_addr_t dma_addr = cpu_addr; + + if (dev) + dma_addr -= dev->dma_offset; + + return dma_addr; +} + +static inline unsigned long dma_to_cpu(struct device_d *dev, dma_addr_t addr) +{ + unsigned long cpu_addr = addr; + + if (dev) + cpu_addr += dev->dma_offset; + + return cpu_addr; +} + +dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size, + enum dma_data_direction dir) +{ + unsigned long addr = (unsigned long)ptr; + + dma_sync_single_for_device(addr, size, dir); + + return cpu_to_dma(dev, addr); +} + +void dma_unmap_single(struct device_d *dev, dma_addr_t dma_addr, size_t size, + enum dma_data_direction dir) +{ + unsigned long addr = dma_to_cpu(dev, dma_addr); + + dma_sync_single_for_cpu(addr, size, dir); +} |