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 <common.h>
8 #include <axi.h>
9 #include <dm.h>
10 #include <dm/test.h>
11 #include <test/ut.h>
12 #include <asm/axi.h>
13
14 /* Test that sandbox AXI works correctly */
dm_test_axi_base(struct unit_test_state * uts)15 static int dm_test_axi_base(struct unit_test_state *uts)
16 {
17 struct udevice *bus;
18
19 ut_assertok(uclass_get_device(UCLASS_AXI, 0, &bus));
20
21 return 0;
22 }
23
24 DM_TEST(dm_test_axi_base, DM_TESTF_SCAN_PDATA | DM_TESTF_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
36 DM_TEST(dm_test_axi_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
37
38 /* Test that we can use the store device correctly */
dm_test_axi_store(struct unit_test_state * uts)39 static int dm_test_axi_store(struct unit_test_state *uts)
40 {
41 struct udevice *store;
42 u8 tdata1[] = {0x55, 0x66, 0x77, 0x88};
43 u8 tdata2[] = {0xaa, 0xbb, 0xcc, 0xdd};
44 u32 val;
45 u8 *data;
46
47 /* Check that asking for the device automatically fires up AXI */
48 ut_assertok(uclass_get_device(UCLASS_AXI_EMUL, 0, &store));
49 ut_assert(device_active(store));
50
51 axi_get_store(store, &data);
52
53 /* Test reading */
54 memcpy(data, tdata1, ARRAY_SIZE(tdata1));
55 axi_read(store, 0, &val, AXI_SIZE_32);
56 ut_asserteq(0x55667788, val);
57
58 memcpy(data + 3, tdata2, ARRAY_SIZE(tdata2));
59 axi_read(store, 3, &val, AXI_SIZE_32);
60 ut_asserteq(0xaabbccdd, val);
61
62 /* Reset data store */
63 memset(data, 0, 16);
64
65 /* Test writing */
66 val = 0x55667788;
67 axi_write(store, 0, &val, AXI_SIZE_32);
68 ut_asserteq(0, memcmp(data, tdata1, ARRAY_SIZE(tdata1)));
69
70 val = 0xaabbccdd;
71 axi_write(store, 3, &val, AXI_SIZE_32);
72 ut_asserteq(0, memcmp(data + 3, tdata2, ARRAY_SIZE(tdata1)));
73
74 return 0;
75 }
76
77 DM_TEST(dm_test_axi_store, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
78