Blame view
test/dm/pci.c
1.66 KB
d3b7ff14f
|
1 2 3 4 5 6 7 8 9 10 |
/* * 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> |
e721b882e
|
11 |
#include <test/ut.h> |
d3b7ff14f
|
12 13 |
/* Test that sandbox PCI works correctly */ |
e721b882e
|
14 |
static int dm_test_pci_base(struct unit_test_state *uts) |
d3b7ff14f
|
15 16 17 18 19 20 21 22 |
{ 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); |
2bb02e4fe
|
23 24 25 26 27 28 29 30 31 32 |
/* 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); |
d3b7ff14f
|
33 |
/* Test that we can use the swapcase device correctly */ |
e721b882e
|
34 |
static int dm_test_pci_swapcase(struct unit_test_state *uts) |
d3b7ff14f
|
35 |
{ |
c03224123
|
36 |
struct udevice *emul, *swap; |
d3b7ff14f
|
37 38 39 40 |
ulong io_addr, mem_addr; char *ptr; /* Check that asking for the device automatically fires up PCI */ |
c03224123
|
41 42 43 |
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)); |
d3b7ff14f
|
44 45 |
/* First test I/O */ |
c03224123
|
46 |
io_addr = dm_pci_read_bar32(swap, 0); |
d3b7ff14f
|
47 48 49 50 51 52 53 |
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. */ |
c03224123
|
54 |
mem_addr = dm_pci_read_bar32(swap, 1); |
d3b7ff14f
|
55 56 57 58 59 60 61 62 63 64 65 |
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); |