axi.c 1.8 KB

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