1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Ramon Fried
12 #include <test/test.h>
15 /* Test that sandbox PCI EP works correctly */
16 static int dm_test_pci_ep_base(struct unit_test_state *uts)
19 struct pci_bar tmp_bar;
20 struct pci_ep_header tmp_header;
23 struct pci_ep_header ep_header = {
27 .interrupt_pin = PCI_INTERRUPT_INTA,
30 struct pci_bar bar = {
31 .phys_addr = 0x80000000,
34 .flags = PCI_BASE_ADDRESS_MEM_TYPE_64 |
35 PCI_BASE_ADDRESS_MEM_PREFETCH,
38 ut_assertok(uclass_get_device(UCLASS_PCI_EP, 0, &bus));
39 ut_assertnonnull(bus);
41 ut_assertok(pci_ep_write_header(bus, 0, &ep_header));
42 ut_assertok(pci_ep_read_header(bus, 0, &tmp_header));
43 ut_asserteq_mem(&tmp_header, &ep_header, sizeof(ep_header));
45 ut_assertok(pci_ep_set_msi(bus, 0, 4));
46 ut_asserteq(pci_ep_get_msi(bus, 0), 4);
48 ut_assertok(pci_ep_set_msix(bus, 0, 360));
49 ut_asserteq(pci_ep_get_msix(bus, 0), 360);
51 ut_assertok(pci_ep_set_bar(bus, 0, &bar));
53 ut_assertok(pci_ep_read_bar(bus, 0, &tmp_bar, BAR_0));
54 ut_asserteq_mem(&tmp_bar, &bar, sizeof(bar));
56 for (i = 0; i < 10; i++)
57 ut_assertok(pci_ep_raise_irq(bus, 0, 1, PCI_EP_IRQ_LEGACY));
59 ut_asserteq(sandbox_get_pci_ep_irq_count(bus), 10);
63 DM_TEST(dm_test_pci_ep_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);