Commit 3ed214ac9bbd1df6cb5e043a39d9de41e481c3e9
Committed by
Simon Glass
1 parent
841f3216c2
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
test: dm: pci: Add tests for mixed static and dynamic devices on the same bus
In the Sandbox test configuration, PCI bus#0 only has static devices while bus#1 only has dynamic devices. Create a bus#2 that has both types of devices and test such. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 81 additions and 0 deletions Side-by-side Diff
arch/sandbox/dts/test.dts
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | mmc1 = "/mmc1"; |
17 | 17 | pci0 = &pci0; |
18 | 18 | pci1 = &pci1; |
19 | + pci2 = &pci2; | |
19 | 20 | remoteproc1 = &rproc_1; |
20 | 21 | remoteproc2 = &rproc_2; |
21 | 22 | rtc0 = &rtc_0; |
... | ... | @@ -328,6 +329,23 @@ |
328 | 329 | 0x01000000 0 0x40000000 0x40000000 0 0x2000>; |
329 | 330 | sandbox,dev-info = <0x08 0x00 0x1234 0x5678 |
330 | 331 | 0x0c 0x00 0x1234 0x5678>; |
332 | + }; | |
333 | + | |
334 | + pci2: pci-controller2 { | |
335 | + compatible = "sandbox,pci"; | |
336 | + device_type = "pci"; | |
337 | + #address-cells = <3>; | |
338 | + #size-cells = <2>; | |
339 | + ranges = <0x02000000 0 0x50000000 0x50000000 0 0x2000 | |
340 | + 0x01000000 0 0x60000000 0x60000000 0 0x2000>; | |
341 | + sandbox,dev-info = <0x08 0x00 0x1234 0x5678>; | |
342 | + pci@1f,0 { | |
343 | + compatible = "pci-generic"; | |
344 | + reg = <0xf800 0 0 0 0>; | |
345 | + emul@1f,0 { | |
346 | + compatible = "sandbox,swap-case"; | |
347 | + }; | |
348 | + }; | |
331 | 349 | }; |
332 | 350 | |
333 | 351 | probing { |
test/dm/pci.c
... | ... | @@ -125,4 +125,67 @@ |
125 | 125 | return 0; |
126 | 126 | } |
127 | 127 | DM_TEST(dm_test_pci_drvdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
128 | + | |
129 | +/* Test that devices on PCI bus#2 can be accessed correctly */ | |
130 | +static int dm_test_pci_mixed(struct unit_test_state *uts) | |
131 | +{ | |
132 | + /* PCI bus#2 has both statically and dynamic declared devices */ | |
133 | + struct udevice *bus, *swap; | |
134 | + u16 vendor, device; | |
135 | + ulong io_addr, mem_addr; | |
136 | + char *ptr; | |
137 | + | |
138 | + ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 2, &bus)); | |
139 | + | |
140 | + /* Test the dynamic device */ | |
141 | + ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(2, 0x08, 0), &swap)); | |
142 | + vendor = 0; | |
143 | + ut_assertok(dm_pci_read_config16(swap, PCI_VENDOR_ID, &vendor)); | |
144 | + ut_asserteq(SANDBOX_PCI_VENDOR_ID, vendor); | |
145 | + | |
146 | + /* First test I/O */ | |
147 | + io_addr = dm_pci_read_bar32(swap, 0); | |
148 | + outb(2, io_addr); | |
149 | + ut_asserteq(2, inb(io_addr)); | |
150 | + | |
151 | + /* | |
152 | + * Now test memory mapping - note we must unmap and remap to cause | |
153 | + * the swapcase emulation to see our data and response. | |
154 | + */ | |
155 | + mem_addr = dm_pci_read_bar32(swap, 1); | |
156 | + ptr = map_sysmem(mem_addr, 30); | |
157 | + strcpy(ptr, "This is a TesT oN dYNAMIc"); | |
158 | + unmap_sysmem(ptr); | |
159 | + | |
160 | + ptr = map_sysmem(mem_addr, 30); | |
161 | + ut_asserteq_str("tHIS IS A tESt On DynamiC", ptr); | |
162 | + unmap_sysmem(ptr); | |
163 | + | |
164 | + /* Test the static device */ | |
165 | + ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(2, 0x1f, 0), &swap)); | |
166 | + device = 0; | |
167 | + ut_assertok(dm_pci_read_config16(swap, PCI_DEVICE_ID, &device)); | |
168 | + ut_asserteq(SANDBOX_PCI_DEVICE_ID, device); | |
169 | + | |
170 | + /* First test I/O */ | |
171 | + io_addr = dm_pci_read_bar32(swap, 0); | |
172 | + outb(2, io_addr); | |
173 | + ut_asserteq(2, inb(io_addr)); | |
174 | + | |
175 | + /* | |
176 | + * Now test memory mapping - note we must unmap and remap to cause | |
177 | + * the swapcase emulation to see our data and response. | |
178 | + */ | |
179 | + mem_addr = dm_pci_read_bar32(swap, 1); | |
180 | + ptr = map_sysmem(mem_addr, 30); | |
181 | + strcpy(ptr, "This is a TesT oN sTATIc"); | |
182 | + unmap_sysmem(ptr); | |
183 | + | |
184 | + ptr = map_sysmem(mem_addr, 30); | |
185 | + ut_asserteq_str("tHIS IS A tESt On StatiC", ptr); | |
186 | + unmap_sysmem(ptr); | |
187 | + | |
188 | + return 0; | |
189 | +} | |
190 | +DM_TEST(dm_test_pci_mixed, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |