Ramon Fried | afdb342 | 2019-04-27 11:15:24 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 Ramon Fried |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 8 | #include <hexdump.h> |
| 9 | #include <pci_ep.h> |
Ramon Fried | afdb342 | 2019-04-27 11:15:24 +0300 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/test.h> |
| 12 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 13 | #include <test/test.h> |
Ramon Fried | afdb342 | 2019-04-27 11:15:24 +0300 | [diff] [blame] | 14 | #include <test/ut.h> |
Ramon Fried | afdb342 | 2019-04-27 11:15:24 +0300 | [diff] [blame] | 15 | |
| 16 | /* Test that sandbox PCI EP works correctly */ |
| 17 | static int dm_test_pci_ep_base(struct unit_test_state *uts) |
| 18 | { |
| 19 | struct udevice *bus; |
| 20 | struct pci_bar tmp_bar; |
| 21 | struct pci_ep_header tmp_header; |
| 22 | int i; |
| 23 | |
| 24 | struct pci_ep_header ep_header = { |
| 25 | .vendorid = 0x1234, |
| 26 | .deviceid = 0x2020, |
| 27 | .revid = 1, |
| 28 | .interrupt_pin = PCI_INTERRUPT_INTA, |
| 29 | }; |
| 30 | |
| 31 | struct pci_bar bar = { |
| 32 | .phys_addr = 0x80000000, |
| 33 | .size = 0x100000, |
| 34 | .barno = BAR_0, |
| 35 | .flags = PCI_BASE_ADDRESS_MEM_TYPE_64 | |
| 36 | PCI_BASE_ADDRESS_MEM_PREFETCH, |
| 37 | }; |
| 38 | |
| 39 | ut_assertok(uclass_get_device(UCLASS_PCI_EP, 0, &bus)); |
| 40 | ut_assertnonnull(bus); |
| 41 | |
| 42 | ut_assertok(pci_ep_write_header(bus, 0, &ep_header)); |
| 43 | ut_assertok(pci_ep_read_header(bus, 0, &tmp_header)); |
| 44 | ut_asserteq_mem(&tmp_header, &ep_header, sizeof(ep_header)); |
| 45 | |
| 46 | ut_assertok(pci_ep_set_msi(bus, 0, 4)); |
| 47 | ut_asserteq(pci_ep_get_msi(bus, 0), 4); |
| 48 | |
| 49 | ut_assertok(pci_ep_set_msix(bus, 0, 360)); |
| 50 | ut_asserteq(pci_ep_get_msix(bus, 0), 360); |
| 51 | |
| 52 | ut_assertok(pci_ep_set_bar(bus, 0, &bar)); |
| 53 | |
| 54 | ut_assertok(pci_ep_read_bar(bus, 0, &tmp_bar, BAR_0)); |
| 55 | ut_asserteq_mem(&tmp_bar, &bar, sizeof(bar)); |
| 56 | |
| 57 | for (i = 0; i < 10; i++) |
| 58 | ut_assertok(pci_ep_raise_irq(bus, 0, 1, PCI_EP_IRQ_LEGACY)); |
| 59 | |
| 60 | ut_asserteq(sandbox_get_pci_ep_irq_count(bus), 10); |
| 61 | return 0; |
| 62 | } |
| 63 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 64 | DM_TEST(dm_test_pci_ep_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |