blob: 47b5d22af8fe05571371ead69a636b4f8f583f36 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassd3b7ff12015-03-05 12:25:34 -07002/*
3 * Copyright (C) 2015 Google, Inc
Simon Glassd3b7ff12015-03-05 12:25:34 -07004 */
5
6#include <common.h>
7#include <dm.h>
8#include <asm/io.h>
9#include <dm/test.h>
Joe Hershbergere721b882015-05-20 14:27:27 -050010#include <test/ut.h>
Simon Glassd3b7ff12015-03-05 12:25:34 -070011
12/* Test that sandbox PCI works correctly */
Joe Hershbergere721b882015-05-20 14:27:27 -050013static int dm_test_pci_base(struct unit_test_state *uts)
Simon Glassd3b7ff12015-03-05 12:25:34 -070014{
15 struct udevice *bus;
16
17 ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
18
19 return 0;
20}
21DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
22
Simon Glass2bb02e42015-05-10 21:08:06 -060023/* Test that sandbox PCI bus numbering works correctly */
24static 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}
32DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
33
Simon Glassd3b7ff12015-03-05 12:25:34 -070034/* Test that we can use the swapcase device correctly */
Joe Hershbergere721b882015-05-20 14:27:27 -050035static int dm_test_pci_swapcase(struct unit_test_state *uts)
Simon Glassd3b7ff12015-03-05 12:25:34 -070036{
Simon Glassc0322412015-11-29 13:18:02 -070037 struct udevice *emul, *swap;
Simon Glassd3b7ff12015-03-05 12:25:34 -070038 ulong io_addr, mem_addr;
39 char *ptr;
40
41 /* Check that asking for the device automatically fires up PCI */
Simon Glassc0322412015-11-29 13:18:02 -070042 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
43 ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
44 ut_assert(device_active(swap));
Simon Glassd3b7ff12015-03-05 12:25:34 -070045
46 /* First test I/O */
Simon Glassc0322412015-11-29 13:18:02 -070047 io_addr = dm_pci_read_bar32(swap, 0);
Simon Glassd3b7ff12015-03-05 12:25:34 -070048 outb(2, io_addr);
49 ut_asserteq(2, inb(io_addr));
50
51 /*
52 * Now test memory mapping - note we must unmap and remap to cause
53 * the swapcase emulation to see our data and response.
54 */
Simon Glassc0322412015-11-29 13:18:02 -070055 mem_addr = dm_pci_read_bar32(swap, 1);
Simon Glassd3b7ff12015-03-05 12:25:34 -070056 ptr = map_sysmem(mem_addr, 20);
57 strcpy(ptr, "This is a TesT");
58 unmap_sysmem(ptr);
59
60 ptr = map_sysmem(mem_addr, 20);
61 ut_asserteq_str("tHIS IS A tESt", ptr);
62 unmap_sysmem(ptr);
63
64 return 0;
65}
66DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);