pci.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <asm/io.h>
  8. #include <dm/test.h>
  9. #include <test/ut.h>
  10. /* Test that sandbox PCI works correctly */
  11. static int dm_test_pci_base(struct unit_test_state *uts)
  12. {
  13. struct udevice *bus;
  14. ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
  15. return 0;
  16. }
  17. DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  18. /* Test that sandbox PCI bus numbering works correctly */
  19. static int dm_test_pci_busnum(struct unit_test_state *uts)
  20. {
  21. struct udevice *bus;
  22. ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
  23. return 0;
  24. }
  25. DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  26. /* Test that we can use the swapcase device correctly */
  27. static int dm_test_pci_swapcase(struct unit_test_state *uts)
  28. {
  29. struct udevice *emul, *swap;
  30. ulong io_addr, mem_addr;
  31. char *ptr;
  32. /* Check that asking for the device automatically fires up PCI */
  33. ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
  34. ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
  35. ut_assert(device_active(swap));
  36. /* First test I/O */
  37. io_addr = dm_pci_read_bar32(swap, 0);
  38. outb(2, io_addr);
  39. ut_asserteq(2, inb(io_addr));
  40. /*
  41. * Now test memory mapping - note we must unmap and remap to cause
  42. * the swapcase emulation to see our data and response.
  43. */
  44. mem_addr = dm_pci_read_bar32(swap, 1);
  45. ptr = map_sysmem(mem_addr, 20);
  46. strcpy(ptr, "This is a TesT");
  47. unmap_sysmem(ptr);
  48. ptr = map_sysmem(mem_addr, 20);
  49. ut_asserteq_str("tHIS IS A tESt", ptr);
  50. unmap_sysmem(ptr);
  51. return 0;
  52. }
  53. DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);