blob: 5b1bbab0b811df3a7edd5cd5b80e9667e193c0a4 [file] [log] [blame]
Mario Six16f57da2018-08-09 14:51:20 +02001// 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>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass75c4d412020-07-19 10:15:37 -060011#include <asm/axi.h>
Mario Six16f57da2018-08-09 14:51:20 +020012#include <dm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060013#include <test/test.h>
Mario Six16f57da2018-08-09 14:51:20 +020014#include <test/ut.h>
Mario Six16f57da2018-08-09 14:51:20 +020015
16/* Test that sandbox AXI works correctly */
17static int dm_test_axi_base(struct unit_test_state *uts)
18{
19 struct udevice *bus;
20
21 ut_assertok(uclass_get_device(UCLASS_AXI, 0, &bus));
22
23 return 0;
24}
25
26DM_TEST(dm_test_axi_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
27
28/* Test that sandbox PCI bus numbering works correctly */
29static int dm_test_axi_busnum(struct unit_test_state *uts)
30{
31 struct udevice *bus;
32
33 ut_assertok(uclass_get_device_by_seq(UCLASS_AXI, 0, &bus));
34
35 return 0;
36}
37
38DM_TEST(dm_test_axi_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
39
40/* Test that we can use the store device correctly */
41static int dm_test_axi_store(struct unit_test_state *uts)
42{
43 struct udevice *store;
44 u8 tdata1[] = {0x55, 0x66, 0x77, 0x88};
45 u8 tdata2[] = {0xaa, 0xbb, 0xcc, 0xdd};
46 u32 val;
47 u8 *data;
48
49 /* Check that asking for the device automatically fires up AXI */
50 ut_assertok(uclass_get_device(UCLASS_AXI_EMUL, 0, &store));
51 ut_assert(device_active(store));
52
53 axi_get_store(store, &data);
54
55 /* Test reading */
56 memcpy(data, tdata1, ARRAY_SIZE(tdata1));
57 axi_read(store, 0, &val, AXI_SIZE_32);
58 ut_asserteq(0x55667788, val);
59
60 memcpy(data + 3, tdata2, ARRAY_SIZE(tdata2));
61 axi_read(store, 3, &val, AXI_SIZE_32);
62 ut_asserteq(0xaabbccdd, val);
63
64 /* Reset data store */
65 memset(data, 0, 16);
66
67 /* Test writing */
68 val = 0x55667788;
69 axi_write(store, 0, &val, AXI_SIZE_32);
Simon Glassa3186e62020-05-10 12:52:45 -060070 ut_asserteq_mem(data, tdata1, ARRAY_SIZE(tdata1));
Mario Six16f57da2018-08-09 14:51:20 +020071
72 val = 0xaabbccdd;
73 axi_write(store, 3, &val, AXI_SIZE_32);
Simon Glassa3186e62020-05-10 12:52:45 -060074 ut_asserteq_mem(data + 3, tdata2, ARRAY_SIZE(tdata1));
Mario Six16f57da2018-08-09 14:51:20 +020075
76 return 0;
77}
78
79DM_TEST(dm_test_axi_store, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);