1 // SPDX-License-Identifier: GPL-2.0+
3 * Direct Memory Access U-Class tests
5 * Copyright (C) 2018 Texas Instruments Incorporated <www.ti.com>
14 #include <test/test.h>
17 static int dm_test_dma_m2m(struct unit_test_state *uts)
26 ut_assertok(uclass_get_device_by_name(UCLASS_DMA, "dma", &dev));
27 ut_assertok(dma_get_by_name(dev, "m2m", &dma_m2m));
29 memset(dst_buf, 0, len);
30 for (i = 0; i < len; i++)
33 ut_assertok(dma_memcpy(dst_buf, src_buf, len));
34 ut_asserteq_mem(src_buf, dst_buf, len);
38 DM_TEST(dm_test_dma_m2m, UT_TESTF_SCAN_FDT);
40 static int dm_test_dma(struct unit_test_state *uts)
43 struct dma dma_tx, dma_rx;
51 ut_assertok(uclass_get_device_by_name(UCLASS_DMA, "dma", &dev));
53 ut_assertok(dma_get_by_name(dev, "tx0", &dma_tx));
54 ut_assertok(dma_get_by_name(dev, "rx0", &dma_rx));
56 ut_assertok(dma_enable(&dma_tx));
57 ut_assertok(dma_enable(&dma_rx));
59 memset(dst_buf, 0, len);
60 for (i = 0; i < len; i++)
66 ut_assertok(dma_send(&dma_tx, src_buf, len, &meta1));
68 ut_asserteq(len, dma_receive(&dma_rx, &dst_ptr, &meta2));
69 ut_asserteq(0xADADDEAD, meta2);
71 ut_assertok(dma_disable(&dma_tx));
72 ut_assertok(dma_disable(&dma_rx));
74 ut_assertok(dma_free(&dma_tx));
75 ut_assertok(dma_free(&dma_rx));
76 ut_asserteq_mem(src_buf, dst_buf, len);
80 DM_TEST(dm_test_dma, UT_TESTF_SCAN_FDT);
82 static int dm_test_dma_rx(struct unit_test_state *uts)
85 struct dma dma_tx, dma_rx;
93 ut_assertok(uclass_get_device_by_name(UCLASS_DMA, "dma", &dev));
95 ut_assertok(dma_get_by_name(dev, "tx0", &dma_tx));
96 ut_assertok(dma_get_by_name(dev, "rx0", &dma_rx));
98 ut_assertok(dma_enable(&dma_tx));
99 ut_assertok(dma_enable(&dma_rx));
101 memset(dst_buf, 0, len);
102 for (i = 0; i < len; i++)
108 ut_assertok(dma_prepare_rcv_buf(&dma_tx, dst_buf, len));
110 ut_assertok(dma_send(&dma_tx, src_buf, len, &meta1));
112 ut_asserteq(len, dma_receive(&dma_rx, &dst_ptr, &meta2));
113 ut_asserteq(0xADADDEAD, meta2);
114 ut_asserteq_ptr(dst_buf, dst_ptr);
116 ut_assertok(dma_disable(&dma_tx));
117 ut_assertok(dma_disable(&dma_rx));
119 ut_assertok(dma_free(&dma_tx));
120 ut_assertok(dma_free(&dma_rx));
121 ut_asserteq_mem(src_buf, dst_buf, len);
125 DM_TEST(dm_test_dma_rx, UT_TESTF_SCAN_FDT);