Use bootorder fw_cfg file to find bootable virtio-mmio devices. Also add a new virtio-mmio.c source file, providing a function to register virtio-mmio devices.
Signed-off-by: Gerd Hoffmann kraxel@redhat.com --- Makefile | 2 +- src/hw/virtio-mmio.h | 6 ++++++ src/fw/paravirt.c | 24 ++++++++++++++++++++++++ src/hw/virtio-mmio.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/hw/virtio-mmio.h create mode 100644 src/hw/virtio-mmio.c
diff --git a/Makefile b/Makefile index 5f7d5370198a..985ef591a13b 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ SRC32FLAT=$(SRCBOTH) post.c e820map.c malloc.c romfile.c x86.c optionroms.c \ fw/coreboot.c fw/lzmadecode.c fw/multiboot.c fw/csm.c fw/biostables.c \ fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/smp.c fw/mtrr.c fw/xen.c \ fw/acpi.c fw/mptable.c fw/pirtable.c fw/smbios.c fw/romfile_loader.c \ - hw/virtio-ring.c hw/virtio-pci.c hw/virtio-blk.c hw/virtio-scsi.c \ + hw/virtio-ring.c hw/virtio-pci.c hw/virtio-mmio.c hw/virtio-blk.c hw/virtio-scsi.c \ hw/tpm_drivers.c hw/nvme.c SRC32SEG=string.c output.c pcibios.c apm.c stacks.c hw/pci.c hw/serialio.c DIRS=src src/hw src/fw vgasrc diff --git a/src/hw/virtio-mmio.h b/src/hw/virtio-mmio.h new file mode 100644 index 000000000000..751984241f49 --- /dev/null +++ b/src/hw/virtio-mmio.h @@ -0,0 +1,6 @@ +#ifndef _VIRTIO_MMIO_H +#define _VIRTIO_MMIO_H + +void virtio_mmio_register(u64 mmio); + +#endif /* _VIRTIO_MMIO_H */ diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 119280c574fd..aaaf8b8dad31 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -15,6 +15,7 @@ #include "hw/pcidevice.h" // pci_probe_devices #include "hw/pci_regs.h" // PCI_DEVICE_ID #include "hw/serialio.h" // PORT_SERIAL1 +#include "hw/virtio-mmio.h" // virtio_mmio_register #include "hw/rtc.h" // CMOS_* #include "malloc.h" // malloc_tmp #include "output.h" // dprintf @@ -192,6 +193,27 @@ static void msr_feature_control_setup(void) wrmsr_smp(MSR_IA32_FEATURE_CONTROL, feature_control_bits); }
+static void qemu_probe_virtio_mmio(void) +{ + char *data, *next; + int size; + u64 mmio; + + data = romfile_loadfile("bootorder", &size); + while (data) { + next = strchr(data, '\n'); + if (next) { + *next = '\0'; + next++; + } + if (memcmp("/virtio-mmio@", data, 13) == 0) { + mmio = strtol(data+13, 16); + virtio_mmio_register(mmio); + } + data = next; + } +} + void qemu_platform_setup(void) { @@ -217,6 +239,8 @@ qemu_platform_setup(void) msr_feature_control_setup(); smp_setup();
+ qemu_probe_virtio_mmio(); + // Create bios tables if (MaxCountCPUs <= 255) { pirtable_setup(); diff --git a/src/hw/virtio-mmio.c b/src/hw/virtio-mmio.c new file mode 100644 index 000000000000..0f320921df30 --- /dev/null +++ b/src/hw/virtio-mmio.c @@ -0,0 +1,30 @@ +#include "config.h" // CONFIG_DEBUG_LEVEL +#include "malloc.h" // free +#include "output.h" // dprintf +#include "virtio-pci.h" +#include "virtio-ring.h" + +/* qemu microvm supports 8 virtio-mmio devices */ +static u64 devs[8]; + +void virtio_mmio_register(u64 mmio) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devs); i++) { + if (devs[i] == mmio) { + /* + * This can happen in case we have multiple scsi devices + * attached to a single virtio-scsi controller + */ + dprintf(3, "virtio-mmio: duplicate device at 0x%llx, ignoring\n", mmio); + return; + } + if (devs[i] == 0) { + dprintf(1, "virtio-mmio: device at 0x%llx\n", mmio); + devs[i] = mmio; + return; + } + } + dprintf(1, "virtio-mmio: device list full\n"); +}