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