pci.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <test/ut.h>
  11. /* Test that sandbox PCI works correctly */
  12. static int dm_test_pci_base(struct unit_test_state *uts)
  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 sandbox PCI bus numbering works correctly */
  20. static int dm_test_pci_busnum(struct unit_test_state *uts)
  21. {
  22. struct udevice *bus;
  23. ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
  24. return 0;
  25. }
  26. DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  27. /* Test that we can use the swapcase device correctly */
  28. static int dm_test_pci_swapcase(struct unit_test_state *uts)
  29. {
  30. pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0);
  31. struct pci_controller *hose;
  32. struct udevice *bus, *swap;
  33. ulong io_addr, mem_addr;
  34. char *ptr;
  35. /* Check that asking for the device automatically fires up PCI */
  36. ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &swap));
  37. ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
  38. hose = dev_get_uclass_priv(bus);
  39. /* First test I/O */
  40. io_addr = pci_read_bar32(hose, pci_dev, 0);
  41. outb(2, io_addr);
  42. ut_asserteq(2, inb(io_addr));
  43. /*
  44. * Now test memory mapping - note we must unmap and remap to cause
  45. * the swapcase emulation to see our data and response.
  46. */
  47. mem_addr = pci_read_bar32(hose, pci_dev, 1);
  48. ptr = map_sysmem(mem_addr, 20);
  49. strcpy(ptr, "This is a TesT");
  50. unmap_sysmem(ptr);
  51. ptr = map_sysmem(mem_addr, 20);
  52. ut_asserteq_str("tHIS IS A tESt", ptr);
  53. unmap_sysmem(ptr);
  54. return 0;
  55. }
  56. DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);