2 * Copyright (C) 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
13 /* Test that sandbox PCI works correctly */
14 static int dm_test_pci_base(struct unit_test_state *uts)
18 ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
22 DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
24 /* Test that sandbox PCI bus numbering works correctly */
25 static int dm_test_pci_busnum(struct unit_test_state *uts)
29 ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
33 DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
35 /* Test that we can use the swapcase device correctly */
36 static int dm_test_pci_swapcase(struct unit_test_state *uts)
38 pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0);
39 struct pci_controller *hose;
40 struct udevice *bus, *swap;
41 ulong io_addr, mem_addr;
44 /* Check that asking for the device automatically fires up PCI */
45 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &swap));
47 ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
48 hose = dev_get_uclass_priv(bus);
51 io_addr = pci_read_bar32(hose, pci_dev, 0);
53 ut_asserteq(2, inb(io_addr));
56 * Now test memory mapping - note we must unmap and remap to cause
57 * the swapcase emulation to see our data and response.
59 mem_addr = pci_read_bar32(hose, pci_dev, 1);
60 ptr = map_sysmem(mem_addr, 20);
61 strcpy(ptr, "This is a TesT");
64 ptr = map_sysmem(mem_addr, 20);
65 ut_asserteq_str("tHIS IS A tESt", ptr);
70 DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);