Skip to content

Commit 68f5d3f

Browse files
jmberg-intelrichardweinberger
authored andcommitted
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus support driver. This driver uses virtio, which in UML is really just vhost-user, to talk to devices, and adds the devices to the virtual PCI bus in the system. Since virtio already allows DMA/bus mastering this really isn't all that hard, of course we need the logic_iomem infrastructure that was added by a previous patch. The protocol to talk to the device is has a few fairly simple messages for reading to/writing from config and IO spaces, and messages for the device to send the various interrupts (INT#, MSI/MSI-X and while suspended PME#). Note that currently no offical virtio device ID is assigned for this protocol, as a consequence this patch requires defining it in the Kconfig, with a default that makes the driver refuse to work at all. Finally, in order to add support for MSI/MSI-X interrupts, some small changes are needed in the UML IRQ code, it needs to have more interrupts, changing NR_IRQS from 64 to 128 if this driver is enabled, but not actually use them for anything so that the generic IRQ domain/MSI infrastructure can allocate IRQ numbers. Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent a5ab7c8 commit 68f5d3f

File tree

13 files changed

+1054
-6
lines changed

13 files changed

+1054
-6
lines changed

arch/um/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ config UML
1515
select HAVE_FUTEX_CMPXCHG if FUTEX
1616
select HAVE_DEBUG_KMEMLEAK
1717
select HAVE_DEBUG_BUGVERBOSE
18-
select NO_DMA
18+
select NO_DMA if !UML_DMA_EMULATION
1919
select GENERIC_IRQ_SHOW
2020
select GENERIC_CPU_DEVICES
2121
select HAVE_GCC_PLUGINS
@@ -26,10 +26,21 @@ config MMU
2626
bool
2727
default y
2828

29+
config UML_DMA_EMULATION
30+
bool
31+
2932
config NO_IOMEM
3033
bool "disable IOMEM" if EXPERT
34+
depends on !INDIRECT_IOMEM
3135
default y
3236

37+
config UML_IOMEM_EMULATION
38+
bool
39+
select INDIRECT_IOMEM
40+
select GENERIC_PCI_IOMAP
41+
select GENERIC_IOMAP
42+
select NO_GENERIC_PCI_IOPORT_MAP
43+
3344
config NO_IOPORT_MAP
3445
def_bool y
3546

arch/um/drivers/Kconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,23 @@ config UML_RTC
357357
rtcwake, especially in time-travel mode. This driver enables that
358358
by providing a fake RTC clock that causes a wakeup at the right
359359
time.
360+
361+
config UML_PCI_OVER_VIRTIO
362+
bool "Enable PCI over VIRTIO device simulation"
363+
# in theory, just VIRTIO is enough, but that causes recursion
364+
depends on VIRTIO_UML
365+
select FORCE_PCI
366+
select UML_IOMEM_EMULATION
367+
select UML_DMA_EMULATION
368+
select PCI_MSI
369+
select PCI_MSI_IRQ_DOMAIN
370+
select PCI_LOCKLESS_CONFIG
371+
372+
config UML_PCI_OVER_VIRTIO_DEVICE_ID
373+
int "set the virtio device ID for PCI emulation"
374+
default -1
375+
depends on UML_PCI_OVER_VIRTIO
376+
help
377+
There's no official device ID assigned (yet), set the one you
378+
wish to use for experimentation here. The default of -1 is
379+
not valid and will cause the driver to fail at probe.

arch/um/drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
6464
obj-$(CONFIG_UML_RANDOM) += random.o
6565
obj-$(CONFIG_VIRTIO_UML) += virtio_uml.o
6666
obj-$(CONFIG_UML_RTC) += rtc.o
67+
obj-$(CONFIG_UML_PCI_OVER_VIRTIO) += virt-pci.o
6768

6869
# pcap_user.o must be added explicitly.
6970
USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o pcap_user.o vde_user.o vector_user.o

0 commit comments

Comments
 (0)