aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBin Meng <bmeng.cn@gmail.com>2018-08-03 01:14:39 -0700
committerSimon Glass <sjg@chromium.org>2018-08-08 12:49:31 +0100
commit2db7f2b722c6314b731d961d5796f97028601250 (patch)
treefee92b3ee1006bc667f2120abee7bfcd69188b27 /test
parentdd4808f9fab54b94df76447b7a7f383cd1b2f5d0 (diff)
downloadu-boot-2db7f2b722c6314b731d961d5796f97028601250.zip
u-boot-2db7f2b722c6314b731d961d5796f97028601250.tar.gz
u-boot-2db7f2b722c6314b731d961d5796f97028601250.tar.bz2
test: dm: pci: Test more than one device on the same bus
It's quite common to have more than one device on the same PCI bus. This updates the test case to test such scenario. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/dm/pci.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/test/dm/pci.c b/test/dm/pci.c
index be1208c..f2bd52a 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -20,16 +20,24 @@ static int dm_test_pci_base(struct unit_test_state *uts)
}
DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-/* Test that sandbox PCI bus numbering works correctly */
-static int dm_test_pci_busnum(struct unit_test_state *uts)
+/* Test that sandbox PCI bus numbering and device works correctly */
+static int dm_test_pci_busdev(struct unit_test_state *uts)
{
struct udevice *bus;
+ struct udevice *emul, *swap;
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
+ ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
+ ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
+ ut_assert(device_active(swap));
+ ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 1, &emul));
+ ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
+ ut_assert(device_active(swap));
+
return 0;
}
-DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_busdev, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
/* Test that we can use the swapcase device correctly */
static int dm_test_pci_swapcase(struct unit_test_state *uts)
@@ -38,7 +46,28 @@ static int dm_test_pci_swapcase(struct unit_test_state *uts)
ulong io_addr, mem_addr;
char *ptr;
- /* Check that asking for the device automatically fires up PCI */
+ /* Check that asking for the device 0 automatically fires up PCI */
+ ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
+
+ /* First test I/O */
+ io_addr = dm_pci_read_bar32(swap, 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 = dm_pci_read_bar32(swap, 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);
+
+ /* Check that asking for the device 1 automatically fires up PCI */
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
/* First test I/O */