1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2018
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
7 #include <axi.h>
8 #include <dm.h>
9 #include <log.h>
10 #include <asm/axi.h>
11 #include <dm/test.h>
12 #include <test/test.h>
13 #include <test/ut.h>
14
15 /* Test that sandbox AXI works correctly */
dm_test_axi_base(struct unit_test_state * uts)16 static int dm_test_axi_base(struct unit_test_state *uts)
17 {
18 struct udevice *bus;
19
20 ut_assertok(uclass_get_device(UCLASS_AXI, 0, &bus));
21
22 return 0;
23 }
24 DM_TEST(dm_test_axi_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
25
26 /* Test that sandbox PCI bus numbering works correctly */
dm_test_axi_busnum(struct unit_test_state * uts)27 static int dm_test_axi_busnum(struct unit_test_state *uts)
28 {
29 struct udevice *bus;
30
31 ut_assertok(uclass_get_device_by_seq(UCLASS_AXI, 0, &bus));
32
33 return 0;
34 }
35 DM_TEST(dm_test_axi_busnum, UTF_SCAN_PDATA | UTF_SCAN_FDT);
36
37 /* Test that we can use the store device correctly */
dm_test_axi_store(struct unit_test_state * uts)38 static int dm_test_axi_store(struct unit_test_state *uts)
39 {
40 struct udevice *store;
41 u8 tdata1[] = {0x55, 0x66, 0x77, 0x88};
42 u8 tdata2[] = {0xaa, 0xbb, 0xcc, 0xdd};
43 u32 val;
44 u8 *data;
45
46 /* Check that asking for the device automatically fires up AXI */
47 ut_assertok(uclass_get_device(UCLASS_AXI_EMUL, 0, &store));
48 ut_assert(device_active(store));
49
50 axi_get_store(store, &data);
51
52 /* Test reading */
53 memcpy(data, tdata1, ARRAY_SIZE(tdata1));
54 axi_read(store, 0, &val, AXI_SIZE_32);
55 ut_asserteq(0x55667788, val);
56
57 memcpy(data + 3, tdata2, ARRAY_SIZE(tdata2));
58 axi_read(store, 3, &val, AXI_SIZE_32);
59 ut_asserteq(0xaabbccdd, val);
60
61 /* Reset data store */
62 memset(data, 0, 16);
63
64 /* Test writing */
65 val = 0x55667788;
66 axi_write(store, 0, &val, AXI_SIZE_32);
67 ut_asserteq_mem(data, tdata1, ARRAY_SIZE(tdata1));
68
69 val = 0xaabbccdd;
70 axi_write(store, 3, &val, AXI_SIZE_32);
71 ut_asserteq_mem(data + 3, tdata2, ARRAY_SIZE(tdata1));
72
73 return 0;
74 }
75 DM_TEST(dm_test_axi_store, UTF_SCAN_PDATA | UTF_SCAN_FDT);
76