pci_ep.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019 Ramon Fried
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <hexdump.h>
  8. #include <pci_ep.h>
  9. #include <asm/io.h>
  10. #include <asm/test.h>
  11. #include <dm/test.h>
  12. #include <test/test.h>
  13. #include <test/ut.h>
  14. /* Test that sandbox PCI EP works correctly */
  15. static int dm_test_pci_ep_base(struct unit_test_state *uts)
  16. {
  17. struct udevice *bus;
  18. struct pci_bar tmp_bar;
  19. struct pci_ep_header tmp_header;
  20. int i;
  21. struct pci_ep_header ep_header = {
  22. .vendorid = 0x1234,
  23. .deviceid = 0x2020,
  24. .revid = 1,
  25. .interrupt_pin = PCI_INTERRUPT_INTA,
  26. };
  27. struct pci_bar bar = {
  28. .phys_addr = 0x80000000,
  29. .size = 0x100000,
  30. .barno = BAR_0,
  31. .flags = PCI_BASE_ADDRESS_MEM_TYPE_64 |
  32. PCI_BASE_ADDRESS_MEM_PREFETCH,
  33. };
  34. ut_assertok(uclass_get_device(UCLASS_PCI_EP, 0, &bus));
  35. ut_assertnonnull(bus);
  36. ut_assertok(pci_ep_write_header(bus, 0, &ep_header));
  37. ut_assertok(pci_ep_read_header(bus, 0, &tmp_header));
  38. ut_asserteq_mem(&tmp_header, &ep_header, sizeof(ep_header));
  39. ut_assertok(pci_ep_set_msi(bus, 0, 4));
  40. ut_asserteq(pci_ep_get_msi(bus, 0), 4);
  41. ut_assertok(pci_ep_set_msix(bus, 0, 360));
  42. ut_asserteq(pci_ep_get_msix(bus, 0), 360);
  43. ut_assertok(pci_ep_set_bar(bus, 0, &bar));
  44. ut_assertok(pci_ep_read_bar(bus, 0, &tmp_bar, BAR_0));
  45. ut_asserteq_mem(&tmp_bar, &bar, sizeof(bar));
  46. for (i = 0; i < 10; i++)
  47. ut_assertok(pci_ep_raise_irq(bus, 0, 1, PCI_EP_IRQ_LEGACY));
  48. ut_asserteq(sandbox_get_pci_ep_irq_count(bus), 10);
  49. return 0;
  50. }
  51. DM_TEST(dm_test_pci_ep_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);