1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
12 /* Test that sandbox PCI works correctly */
13 static int dm_test_pci_base(struct unit_test_state *uts)
17 ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
21 DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
23 /* Test that sandbox PCI bus numbering and device works correctly */
24 static int dm_test_pci_busdev(struct unit_test_state *uts)
27 struct udevice *emul, *swap;
29 /* Test bus#0 and its devices */
30 ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
32 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
33 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
34 ut_assert(device_active(swap));
35 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 1, &emul));
36 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
37 ut_assert(device_active(swap));
39 /* Test bus#1 and its devices */
40 ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
42 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 2, &emul));
43 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
44 ut_assert(device_active(swap));
45 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 3, &emul));
46 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
47 ut_assert(device_active(swap));
51 DM_TEST(dm_test_pci_busdev, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
53 /* Test that we can use the swapcase device correctly */
54 static int dm_test_pci_swapcase(struct unit_test_state *uts)
57 ulong io_addr, mem_addr;
60 /* Check that asking for the device 0 automatically fires up PCI */
61 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
64 io_addr = dm_pci_read_bar32(swap, 0);
66 ut_asserteq(2, inb(io_addr));
69 * Now test memory mapping - note we must unmap and remap to cause
70 * the swapcase emulation to see our data and response.
72 mem_addr = dm_pci_read_bar32(swap, 1);
73 ptr = map_sysmem(mem_addr, 20);
74 strcpy(ptr, "This is a TesT");
77 ptr = map_sysmem(mem_addr, 20);
78 ut_asserteq_str("tHIS IS A tESt", ptr);
81 /* Check that asking for the device 1 automatically fires up PCI */
82 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
85 io_addr = dm_pci_read_bar32(swap, 0);
87 ut_asserteq(2, inb(io_addr));
90 * Now test memory mapping - note we must unmap and remap to cause
91 * the swapcase emulation to see our data and response.
93 mem_addr = dm_pci_read_bar32(swap, 1);
94 ptr = map_sysmem(mem_addr, 20);
95 strcpy(ptr, "This is a TesT");
98 ptr = map_sysmem(mem_addr, 20);
99 ut_asserteq_str("tHIS IS A tESt", ptr);
104 DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);