dm: core: Introduce xxx_translate_dma_address()
Add the following functions to translate DMA address to CPU address:
- dev_translate_dma_address()
- ofnode_translate_dma_address()
- of_translate_dma_address()
- fdt_translate_dma_address()
These functions work the same way as xxx_translate_address(), with the
difference that the translation relies on the "dma-ranges" property
instead of the "ranges" property.
Add related test. Test report:
=> ut dm fdt_translation
Test: dm_test_fdt_translation: test-fdt.c
Test: dm_test_fdt_translation: test-fdt.c (flat tree)
Failures: 0
Signed-off-by: Fabien Dessenne <fabien.dessenne@st.com>
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index be16c99..ad85916 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -490,6 +490,7 @@
static int dm_test_fdt_translation(struct unit_test_state *uts)
{
struct udevice *dev;
+ fdt32_t dma_addr[2];
/* Some simple translations */
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
@@ -509,6 +510,17 @@
ut_asserteq_str("dev@42", dev->name);
ut_asserteq(0x42, dev_read_addr(dev));
+ /* dma address translation */
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+ dma_addr[0] = cpu_to_be32(0);
+ dma_addr[1] = cpu_to_be32(0);
+ ut_asserteq(0x10000000, dev_translate_dma_address(dev, dma_addr));
+
+ ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
+ dma_addr[0] = cpu_to_be32(1);
+ dma_addr[1] = cpu_to_be32(0x100);
+ ut_asserteq(0x20000000, dev_translate_dma_address(dev, dma_addr));
+
return 0;
}
DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);