pci.c 1.4 KB

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