blob: 949710fdb4e3cdc399366b16961fdd4d6acb6716 [file] [log] [blame]
Grygorii Strashkob3309912018-11-28 19:17:51 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Direct Memory Access U-Class tests
4 *
5 * Copyright (C) 2018 Texas Instruments Incorporated <www.ti.com>
6 * Grygorii Strashko <grygorii.strashko@ti.com>
7 */
8
Grygorii Strashkob3309912018-11-28 19:17:51 +01009#include <dm.h>
Simon Glass336d4612020-02-03 07:36:16 -070010#include <malloc.h>
Grygorii Strashkob3309912018-11-28 19:17:51 +010011#include <dm/test.h>
12#include <dma.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060013#include <test/test.h>
Grygorii Strashkob3309912018-11-28 19:17:51 +010014#include <test/ut.h>
15
16static int dm_test_dma_m2m(struct unit_test_state *uts)
17{
18 struct udevice *dev;
19 struct dma dma_m2m;
20 u8 src_buf[512];
21 u8 dst_buf[512];
22 size_t len = 512;
23 int i;
24
25 ut_assertok(uclass_get_device_by_name(UCLASS_DMA, "dma", &dev));
26 ut_assertok(dma_get_by_name(dev, "m2m", &dma_m2m));
27
28 memset(dst_buf, 0, len);
29 for (i = 0; i < len; i++)
30 src_buf[i] = i;
31
32 ut_assertok(dma_memcpy(dst_buf, src_buf, len));
Simon Glassf91f3662020-05-10 12:52:45 -060033 ut_asserteq_mem(src_buf, dst_buf, len);
Grygorii Strashkob3309912018-11-28 19:17:51 +010034
Grygorii Strashkob3309912018-11-28 19:17:51 +010035 return 0;
36}
Simon Glasse180c2b2020-07-28 19:41:12 -060037DM_TEST(dm_test_dma_m2m, UT_TESTF_SCAN_FDT);
Grygorii Strashkob3309912018-11-28 19:17:51 +010038
39static int dm_test_dma(struct unit_test_state *uts)
40{
41 struct udevice *dev;
42 struct dma dma_tx, dma_rx;
43 u8 src_buf[512];
44 u8 dst_buf[512];
45 void *dst_ptr;
46 size_t len = 512;
47 u32 meta1, meta2;
48 int i;
49
50 ut_assertok(uclass_get_device_by_name(UCLASS_DMA, "dma", &dev));
51
52 ut_assertok(dma_get_by_name(dev, "tx0", &dma_tx));
53 ut_assertok(dma_get_by_name(dev, "rx0", &dma_rx));
54
55 ut_assertok(dma_enable(&dma_tx));
56 ut_assertok(dma_enable(&dma_rx));
57
58 memset(dst_buf, 0, len);
59 for (i = 0; i < len; i++)
60 src_buf[i] = i;
61 meta1 = 0xADADDEAD;
62 meta2 = 0;
63 dst_ptr = &dst_buf;
64
65 ut_assertok(dma_send(&dma_tx, src_buf, len, &meta1));
66
67 ut_asserteq(len, dma_receive(&dma_rx, &dst_ptr, &meta2));
68 ut_asserteq(0xADADDEAD, meta2);
69
70 ut_assertok(dma_disable(&dma_tx));
71 ut_assertok(dma_disable(&dma_rx));
72
73 ut_assertok(dma_free(&dma_tx));
74 ut_assertok(dma_free(&dma_rx));
Simon Glassf91f3662020-05-10 12:52:45 -060075 ut_asserteq_mem(src_buf, dst_buf, len);
Grygorii Strashkob3309912018-11-28 19:17:51 +010076
77 return 0;
78}
Simon Glasse180c2b2020-07-28 19:41:12 -060079DM_TEST(dm_test_dma, UT_TESTF_SCAN_FDT);
Grygorii Strashkob3309912018-11-28 19:17:51 +010080
81static int dm_test_dma_rx(struct unit_test_state *uts)
82{
83 struct udevice *dev;
84 struct dma dma_tx, dma_rx;
85 u8 src_buf[512];
86 u8 dst_buf[512];
87 void *dst_ptr;
88 size_t len = 512;
89 u32 meta1, meta2;
90 int i;
91
92 ut_assertok(uclass_get_device_by_name(UCLASS_DMA, "dma", &dev));
93
94 ut_assertok(dma_get_by_name(dev, "tx0", &dma_tx));
95 ut_assertok(dma_get_by_name(dev, "rx0", &dma_rx));
96
97 ut_assertok(dma_enable(&dma_tx));
98 ut_assertok(dma_enable(&dma_rx));
99
100 memset(dst_buf, 0, len);
101 for (i = 0; i < len; i++)
102 src_buf[i] = i;
103 meta1 = 0xADADDEAD;
104 meta2 = 0;
105 dst_ptr = NULL;
106
107 ut_assertok(dma_prepare_rcv_buf(&dma_tx, dst_buf, len));
108
109 ut_assertok(dma_send(&dma_tx, src_buf, len, &meta1));
110
111 ut_asserteq(len, dma_receive(&dma_rx, &dst_ptr, &meta2));
112 ut_asserteq(0xADADDEAD, meta2);
113 ut_asserteq_ptr(dst_buf, dst_ptr);
114
115 ut_assertok(dma_disable(&dma_tx));
116 ut_assertok(dma_disable(&dma_rx));
117
118 ut_assertok(dma_free(&dma_tx));
119 ut_assertok(dma_free(&dma_rx));
Simon Glassf91f3662020-05-10 12:52:45 -0600120 ut_asserteq_mem(src_buf, dst_buf, len);
Grygorii Strashkob3309912018-11-28 19:17:51 +0100121
122 return 0;
123}
Simon Glasse180c2b2020-07-28 19:41:12 -0600124DM_TEST(dm_test_dma_rx, UT_TESTF_SCAN_FDT);