2015-03-05 19:25:34 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2015-05-20 19:27:27 +00:00
|
|
|
#include <test/ut.h>
|
2015-03-05 19:25:34 +00:00
|
|
|
|
|
|
|
/* Test that sandbox PCI works correctly */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_pci_base(struct unit_test_state *uts)
|
2015-03-05 19:25:34 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2015-05-11 03:08:06 +00:00
|
|
|
/* Test that sandbox PCI bus numbering works correctly */
|
|
|
|
static int dm_test_pci_busnum(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *bus;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
|
|
|
|
2015-03-05 19:25:34 +00:00
|
|
|
/* Test that we can use the swapcase device correctly */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_pci_swapcase(struct unit_test_state *uts)
|
2015-03-05 19:25:34 +00:00
|
|
|
{
|
2015-11-29 20:18:02 +00:00
|
|
|
struct udevice *emul, *swap;
|
2015-03-05 19:25:34 +00:00
|
|
|
ulong io_addr, mem_addr;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
/* Check that asking for the device automatically fires up PCI */
|
2015-11-29 20:18:02 +00:00
|
|
|
ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
|
|
|
|
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
|
|
|
|
ut_assert(device_active(swap));
|
2015-03-05 19:25:34 +00:00
|
|
|
|
|
|
|
/* First test I/O */
|
2015-11-29 20:18:02 +00:00
|
|
|
io_addr = dm_pci_read_bar32(swap, 0);
|
2015-03-05 19:25:34 +00:00
|
|
|
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.
|
|
|
|
*/
|
2015-11-29 20:18:02 +00:00
|
|
|
mem_addr = dm_pci_read_bar32(swap, 1);
|
2015-03-05 19:25:34 +00:00
|
|
|
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);
|