axi.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <log.h>
  10. #include <asm/axi.h>
  11. #include <dm/test.h>
  12. #include <test/test.h>
  13. #include <test/ut.h>
  14. /* Test that sandbox AXI works correctly */
  15. static int dm_test_axi_base(struct unit_test_state *uts)
  16. {
  17. struct udevice *bus;
  18. ut_assertok(uclass_get_device(UCLASS_AXI, 0, &bus));
  19. return 0;
  20. }
  21. DM_TEST(dm_test_axi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  22. /* Test that sandbox PCI bus numbering works correctly */
  23. static int dm_test_axi_busnum(struct unit_test_state *uts)
  24. {
  25. struct udevice *bus;
  26. ut_assertok(uclass_get_device_by_seq(UCLASS_AXI, 0, &bus));
  27. return 0;
  28. }
  29. DM_TEST(dm_test_axi_busnum, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  30. /* Test that we can use the store device correctly */
  31. static int dm_test_axi_store(struct unit_test_state *uts)
  32. {
  33. struct udevice *store;
  34. u8 tdata1[] = {0x55, 0x66, 0x77, 0x88};
  35. u8 tdata2[] = {0xaa, 0xbb, 0xcc, 0xdd};
  36. u32 val;
  37. u8 *data;
  38. /* Check that asking for the device automatically fires up AXI */
  39. ut_assertok(uclass_get_device(UCLASS_AXI_EMUL, 0, &store));
  40. ut_assert(device_active(store));
  41. axi_get_store(store, &data);
  42. /* Test reading */
  43. memcpy(data, tdata1, ARRAY_SIZE(tdata1));
  44. axi_read(store, 0, &val, AXI_SIZE_32);
  45. ut_asserteq(0x55667788, val);
  46. memcpy(data + 3, tdata2, ARRAY_SIZE(tdata2));
  47. axi_read(store, 3, &val, AXI_SIZE_32);
  48. ut_asserteq(0xaabbccdd, val);
  49. /* Reset data store */
  50. memset(data, 0, 16);
  51. /* Test writing */
  52. val = 0x55667788;
  53. axi_write(store, 0, &val, AXI_SIZE_32);
  54. ut_asserteq_mem(data, tdata1, ARRAY_SIZE(tdata1));
  55. val = 0xaabbccdd;
  56. axi_write(store, 3, &val, AXI_SIZE_32);
  57. ut_asserteq_mem(data + 3, tdata2, ARRAY_SIZE(tdata1));
  58. return 0;
  59. }
  60. DM_TEST(dm_test_axi_store, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);