diff options
author | Simon Glass <sjg@chromium.org> | 2015-03-05 22:25:34 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-04-18 20:11:09 +0300 |
commit | d3b7ff14f4944a391da3d1146e36dba42e811766 (patch) | |
tree | 0f4a1703764552b12b8863be2b881f700a63c082 /test/dm/pci.c | |
parent | aad78d2732ee04326fb3523815795f76012aab99 (diff) | |
download | u-boot-d3b7ff14f4944a391da3d1146e36dba42e811766.tar.xz |
dm: pci: Add driver model tests for PCI
Add some basic tests to check that things work as expected with sandbox.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm/pci.c')
-rw-r--r-- | test/dm/pci.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/dm/pci.c b/test/dm/pci.c new file mode 100644 index 0000000000..6c63fa4c1f --- /dev/null +++ b/test/dm/pci.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/test.h> +#include <dm/ut.h> + +/* Test that sandbox PCI works correctly */ +static int dm_test_pci_base(struct dm_test_state *dms) +{ + struct udevice *bus; + + ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus)); + + return 0; +} +DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that we can use the swapcase device correctly */ +static int dm_test_pci_swapcase(struct dm_test_state *dms) +{ + pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0); + struct pci_controller *hose; + struct udevice *bus, *swap; + ulong io_addr, mem_addr; + char *ptr; + + /* Check that asking for the device automatically fires up PCI */ + ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &swap)); + + ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus)); + hose = dev_get_uclass_priv(bus); + + /* First test I/O */ + io_addr = pci_read_bar32(hose, pci_dev, 0); + outb(2, io_addr); + ut_asserteq(2, inb(io_addr)); + + /* + * Now test memory mapping - note we must unmap and remap to cause + * the swapcase emulation to see our data and response. + */ + mem_addr = pci_read_bar32(hose, pci_dev, 1); + ptr = map_sysmem(mem_addr, 20); + strcpy(ptr, "This is a TesT"); + unmap_sysmem(ptr); + + ptr = map_sysmem(mem_addr, 20); + ut_asserteq_str("tHIS IS A tESt", ptr); + unmap_sysmem(ptr); + + return 0; +} +DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |