Mario Six | 16f57da | 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 | |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 7 | #include <axi.h> |
| 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 10 | #include <asm/axi.h> |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 11 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <test/test.h> |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 13 | #include <test/ut.h> |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 14 | |
| 15 | /* Test that sandbox AXI works correctly */ |
| 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 | |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 25 | DM_TEST(dm_test_axi_base, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 26 | |
| 27 | /* Test that sandbox PCI bus numbering works correctly */ |
| 28 | static int dm_test_axi_busnum(struct unit_test_state *uts) |
| 29 | { |
| 30 | struct udevice *bus; |
| 31 | |
| 32 | ut_assertok(uclass_get_device_by_seq(UCLASS_AXI, 0, &bus)); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 37 | DM_TEST(dm_test_axi_busnum, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 38 | |
| 39 | /* Test that we can use the store device correctly */ |
| 40 | static int dm_test_axi_store(struct unit_test_state *uts) |
| 41 | { |
| 42 | struct udevice *store; |
| 43 | u8 tdata1[] = {0x55, 0x66, 0x77, 0x88}; |
| 44 | u8 tdata2[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 45 | u32 val; |
| 46 | u8 *data; |
| 47 | |
| 48 | /* Check that asking for the device automatically fires up AXI */ |
| 49 | ut_assertok(uclass_get_device(UCLASS_AXI_EMUL, 0, &store)); |
| 50 | ut_assert(device_active(store)); |
| 51 | |
| 52 | axi_get_store(store, &data); |
| 53 | |
| 54 | /* Test reading */ |
| 55 | memcpy(data, tdata1, ARRAY_SIZE(tdata1)); |
| 56 | axi_read(store, 0, &val, AXI_SIZE_32); |
| 57 | ut_asserteq(0x55667788, val); |
| 58 | |
| 59 | memcpy(data + 3, tdata2, ARRAY_SIZE(tdata2)); |
| 60 | axi_read(store, 3, &val, AXI_SIZE_32); |
| 61 | ut_asserteq(0xaabbccdd, val); |
| 62 | |
| 63 | /* Reset data store */ |
| 64 | memset(data, 0, 16); |
| 65 | |
| 66 | /* Test writing */ |
| 67 | val = 0x55667788; |
| 68 | axi_write(store, 0, &val, AXI_SIZE_32); |
Simon Glass | a3186e6 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 69 | ut_asserteq_mem(data, tdata1, ARRAY_SIZE(tdata1)); |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 70 | |
| 71 | val = 0xaabbccdd; |
| 72 | axi_write(store, 3, &val, AXI_SIZE_32); |
Simon Glass | a3186e6 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 73 | ut_asserteq_mem(data + 3, tdata2, ARRAY_SIZE(tdata1)); |
Mario Six | 16f57da | 2018-08-09 14:51:20 +0200 | [diff] [blame] | 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 78 | DM_TEST(dm_test_axi_store, UTF_SCAN_PDATA | UTF_SCAN_FDT); |