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> |
| 11 | #include <dm/ut.h> |
| 12 | |
| 13 | /* Test that sandbox PCI works correctly */ |
| 14 | static int dm_test_pci_base(struct dm_test_state *dms) |
| 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 | |
| 24 | /* Test that we can use the swapcase device correctly */ |
| 25 | static int dm_test_pci_swapcase(struct dm_test_state *dms) |
| 26 | { |
| 27 | pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0); |
| 28 | struct pci_controller *hose; |
| 29 | struct udevice *bus, *swap; |
| 30 | ulong io_addr, mem_addr; |
| 31 | char *ptr; |
| 32 | |
| 33 | /* Check that asking for the device automatically fires up PCI */ |
| 34 | ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &swap)); |
| 35 | |
| 36 | ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus)); |
| 37 | hose = dev_get_uclass_priv(bus); |
| 38 | |
| 39 | /* First test I/O */ |
| 40 | io_addr = pci_read_bar32(hose, pci_dev, 0); |
| 41 | outb(2, io_addr); |
| 42 | ut_asserteq(2, inb(io_addr)); |
| 43 | |
| 44 | /* |
| 45 | * Now test memory mapping - note we must unmap and remap to cause |
| 46 | * the swapcase emulation to see our data and response. |
| 47 | */ |
| 48 | mem_addr = pci_read_bar32(hose, pci_dev, 1); |
| 49 | ptr = map_sysmem(mem_addr, 20); |
| 50 | strcpy(ptr, "This is a TesT"); |
| 51 | unmap_sysmem(ptr); |
| 52 | |
| 53 | ptr = map_sysmem(mem_addr, 20); |
| 54 | ut_asserteq_str("tHIS IS A tESt", ptr); |
| 55 | unmap_sysmem(ptr); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |