diff options
| author | GuEe-GUI <[email protected]> | 2024-09-10 13:38:24 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2024-09-13 17:33:29 -0400 |
| commit | 2d026a316aa39b13897959d3fc851e39aaa0d054 (patch) | |
| tree | 4982127c0ae1159fccee1cf12b661bbdab68c010 /components/drivers/include | |
| parent | 117e6ed347ee67699238170e76633d70703c2b55 (diff) | |
[FEATURE/OFW] add address reverse/translate for DMA/CPU's address
DMA and CPU address view is different, we need to convert them:
+--------+ +--------+ +---------+ +--------+
| | | | | | | |
| CPUs | | DEV0 | | IOMMU <----+ | DEV1 |
| | | | | | | | |
+----+---+ +----+---+ +----+----+ | +----+---+
| | | | |
0x200000 | 0x1000 | 0x1000 | | 0x8000 |
| | | | |
+-------------+-----------+ +----------+
|
|
+--------v----------------------------------------------------+
| |
| Address BUS |
| |
+-------------------------------------------------------------+
Signed-off-by: GuEe-GUI <[email protected]>
Diffstat (limited to 'components/drivers/include')
| -rwxr-xr-x | components/drivers/include/drivers/ofw_io.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/components/drivers/include/drivers/ofw_io.h b/components/drivers/include/drivers/ofw_io.h index 4ebfbe2c82..f458435d09 100755 --- a/components/drivers/include/drivers/ofw_io.h +++ b/components/drivers/include/drivers/ofw_io.h @@ -26,6 +26,27 @@ rt_err_t rt_ofw_get_address_by_name(struct rt_ofw_node *np, const char *name, int rt_ofw_get_address_array(struct rt_ofw_node *np, int nr, rt_uint64_t *out_regs); rt_uint64_t rt_ofw_translate_address(struct rt_ofw_node *np, const char *range_type, rt_uint64_t address); +rt_uint64_t rt_ofw_reverse_address(struct rt_ofw_node *np, const char *range_type, rt_uint64_t address); + +rt_inline rt_uint64_t rt_ofw_translate_dma2cpu(struct rt_ofw_node *np, rt_uint64_t address) +{ + rt_uint64_t bus_addr, cpu_addr; + + bus_addr = rt_ofw_reverse_address(np, "dma-ranges", address); + cpu_addr = rt_ofw_translate_address(np, "ranges", bus_addr); + + return cpu_addr != ~0ULL ? cpu_addr : address; +} + +rt_inline rt_uint64_t rt_ofw_translate_cpu2dma(struct rt_ofw_node *np, rt_uint64_t address) +{ + rt_uint64_t bus_addr, dma_addr; + + bus_addr = rt_ofw_reverse_address(np, "ranges", address); + dma_addr = rt_ofw_translate_address(np, "dma-ranges", bus_addr); + + return dma_addr != ~0ULL ? dma_addr : address; +} void *rt_ofw_iomap(struct rt_ofw_node *np, int index); void *rt_ofw_iomap_by_name(struct rt_ofw_node *np, const char *name); |
