Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <dm/test.h> |
Joe Hershberger | e721b88 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 11 | #include <test/ut.h> |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 12 | |
| 13 | /* Test that sandbox PCI works correctly */ |
Joe Hershberger | e721b88 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 14 | static int dm_test_pci_base(struct unit_test_state *uts) |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 15 | { |
| 16 | struct udevice *bus; |
| 17 | |
| 18 | ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus)); |
| 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 23 | |
Simon Glass | 2bb02e4 | 2015-05-10 21:08:06 -0600 | [diff] [blame] | 24 | /* Test that sandbox PCI bus numbering works correctly */ |
| 25 | static int dm_test_pci_busnum(struct unit_test_state *uts) |
| 26 | { |
| 27 | struct udevice *bus; |
| 28 | |
| 29 | ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus)); |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 34 | |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 35 | /* Test that we can use the swapcase device correctly */ |
Joe Hershberger | e721b88 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 36 | static int dm_test_pci_swapcase(struct unit_test_state *uts) |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 37 | { |
Simon Glass | c032241 | 2015-11-29 13:18:02 -0700 | [diff] [blame] | 38 | struct udevice *emul, *swap; |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 39 | ulong io_addr, mem_addr; |
| 40 | char *ptr; |
| 41 | |
| 42 | /* Check that asking for the device automatically fires up PCI */ |
Simon Glass | c032241 | 2015-11-29 13:18:02 -0700 | [diff] [blame] | 43 | ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul)); |
| 44 | ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap)); |
| 45 | ut_assert(device_active(swap)); |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 46 | |
| 47 | /* First test I/O */ |
Simon Glass | c032241 | 2015-11-29 13:18:02 -0700 | [diff] [blame] | 48 | io_addr = dm_pci_read_bar32(swap, 0); |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 49 | outb(2, io_addr); |
| 50 | ut_asserteq(2, inb(io_addr)); |
| 51 | |
| 52 | /* |
| 53 | * Now test memory mapping - note we must unmap and remap to cause |
| 54 | * the swapcase emulation to see our data and response. |
| 55 | */ |
Simon Glass | c032241 | 2015-11-29 13:18:02 -0700 | [diff] [blame] | 56 | mem_addr = dm_pci_read_bar32(swap, 1); |
Simon Glass | d3b7ff1 | 2015-03-05 12:25:34 -0700 | [diff] [blame] | 57 | ptr = map_sysmem(mem_addr, 20); |
| 58 | strcpy(ptr, "This is a TesT"); |
| 59 | unmap_sysmem(ptr); |
| 60 | |
| 61 | ptr = map_sysmem(mem_addr, 20); |
| 62 | ut_asserteq_str("tHIS IS A tESt", ptr); |
| 63 | unmap_sysmem(ptr); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |