Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 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> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 11 | #include <asm/axi.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <dm/test.h> |
| 13 | #include <test/test.h> |
| 14 | #include <test/ut.h> |
Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 15 | |
| 16 | /* Test that sandbox AXI works correctly */ |
| 17 | static 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 | |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame^] | 26 | DM_TEST(dm_test_axi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 27 | |
| 28 | /* Test that sandbox PCI bus numbering works correctly */ |
| 29 | static 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 | |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame^] | 38 | DM_TEST(dm_test_axi_busnum, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 39 | |
| 40 | /* Test that we can use the store device correctly */ |
| 41 | static 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 Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 70 | ut_asserteq_mem(data, tdata1, ARRAY_SIZE(tdata1)); |
Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 71 | |
| 72 | val = 0xaabbccdd; |
| 73 | axi_write(store, 3, &val, AXI_SIZE_32); |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 74 | ut_asserteq_mem(data + 3, tdata2, ARRAY_SIZE(tdata1)); |
Mario Six | 87940ec | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame^] | 79 | DM_TEST(dm_test_axi_store, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |