blob: 3ab4ba811cf4280462cd3bacd2897fe08bc3a094 [file] [log] [blame]
Simon Glassd3b7ff12015-03-05 12:25:34 -07001/*
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>
Joe Hershbergere721b882015-05-20 14:27:27 -050011#include <test/ut.h>
Simon Glassd3b7ff12015-03-05 12:25:34 -070012
13/* Test that sandbox PCI works correctly */
Joe Hershbergere721b882015-05-20 14:27:27 -050014static int dm_test_pci_base(struct unit_test_state *uts)
Simon Glassd3b7ff12015-03-05 12:25:34 -070015{
16 struct udevice *bus;
17
18 ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
19
20 return 0;
21}
22DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
23
Simon Glass2bb02e42015-05-10 21:08:06 -060024/* Test that sandbox PCI bus numbering works correctly */
25static int dm_test_pci_busnum(struct unit_test_state *uts)
26{
27 struct udevice *bus;
28
29 ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
30
31 return 0;
32}
33DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
34
Simon Glassd3b7ff12015-03-05 12:25:34 -070035/* Test that we can use the swapcase device correctly */
Joe Hershbergere721b882015-05-20 14:27:27 -050036static int dm_test_pci_swapcase(struct unit_test_state *uts)
Simon Glassd3b7ff12015-03-05 12:25:34 -070037{
38 pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0);
39 struct pci_controller *hose;
40 struct udevice *bus, *swap;
41 ulong io_addr, mem_addr;
42 char *ptr;
43
44 /* Check that asking for the device automatically fires up PCI */
45 ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &swap));
46
47 ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
48 hose = dev_get_uclass_priv(bus);
49
50 /* First test I/O */
51 io_addr = pci_read_bar32(hose, pci_dev, 0);
52 outb(2, io_addr);
53 ut_asserteq(2, inb(io_addr));
54
55 /*
56 * Now test memory mapping - note we must unmap and remap to cause
57 * the swapcase emulation to see our data and response.
58 */
59 mem_addr = pci_read_bar32(hose, pci_dev, 1);
60 ptr = map_sysmem(mem_addr, 20);
61 strcpy(ptr, "This is a TesT");
62 unmap_sysmem(ptr);
63
64 ptr = map_sysmem(mem_addr, 20);
65 ut_asserteq_str("tHIS IS A tESt", ptr);
66 unmap_sysmem(ptr);
67
68 return 0;
69}
70DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);