From f657dbe2cf075c1568ec15a87fbd722112e7eb53 Mon Sep 17 00:00:00 2001 From: hbcam <> Date: Fri, 15 Jul 2016 13:58:57 +0100 Subject: [PATCH 1/2] Add virtio 1.0 way of handling virtqueues for virtio over MMIO. --- hw/virtio/virtio-mmio.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 18660b07b1c..a64525e62ea 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -66,10 +66,17 @@ do { printf("virtio_mmio: " fmt , ## __VA_ARGS__); } while (0) #define VIRTIO_MMIO_QUEUENUM 0x38 #define VIRTIO_MMIO_QUEUEALIGN 0x3c #define VIRTIO_MMIO_QUEUEPFN 0x40 +#define VIRTIO_MMIO_QUEUE_READY 0x44 #define VIRTIO_MMIO_QUEUENOTIFY 0x50 #define VIRTIO_MMIO_INTERRUPTSTATUS 0x60 #define VIRTIO_MMIO_INTERRUPTACK 0x64 #define VIRTIO_MMIO_STATUS 0x70 +#define VIRTIO_MMIO_QUEUE_DESC_LOW 0x80 +#define VIRTIO_MMIO_QUEUE_DESC_HIGH 0x84 +#define VIRTIO_MMIO_QUEUE_AVAIL_LOW 0x90 +#define VIRTIO_MMIO_QUEUE_AVAIL_HIGH 0x94 +#define VIRTIO_MMIO_QUEUE_USED_LOW 0xA0 +#define VIRTIO_MMIO_QUEUE_USED_HIGH 0xA4 /* Device specific config space starts here */ #define VIRTIO_MMIO_CONFIG 0x100 @@ -90,6 +97,13 @@ typedef struct { VirtioBusState bus; bool ioeventfd_disabled; bool ioeventfd_started; + /* Virtio transitional stub. Supports one virtqueue only */ + uint32_t queue_desc_low; + uint32_t queue_desc_high; + uint32_t queue_avail_low; + uint32_t queue_avail_high; + uint32_t queue_used_low; + uint32_t queue_used_high; } VirtIOMMIOProxy; static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy, @@ -348,6 +362,16 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, value << proxy->guest_page_shift); } break; + case VIRTIO_MMIO_QUEUE_READY: + assert(vdev->queue_sel == 0); + virtio_queue_set_rings(vdev, vdev->queue_sel, + ((uint64_t)proxy->queue_desc_high) << 32 | + proxy->queue_desc_low, + ((uint64_t)proxy->queue_avail_high) << 32 | + proxy->queue_avail_low, + ((uint64_t)proxy->queue_used_high) << 32 | + proxy->queue_used_low); + break; case VIRTIO_MMIO_QUEUENOTIFY: if (value < VIRTIO_QUEUE_MAX) { virtio_queue_notify(vdev, value); @@ -372,6 +396,31 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, virtio_reset(vdev); } break; + case VIRTIO_MMIO_QUEUE_DESC_LOW: + assert(vdev->queue_sel == 0); + proxy->queue_desc_low = value; + break; + case VIRTIO_MMIO_QUEUE_DESC_HIGH: + assert(vdev->queue_sel == 0); + proxy->queue_desc_high = value; + break; + case VIRTIO_MMIO_QUEUE_AVAIL_LOW: + assert(vdev->queue_sel == 0); + proxy->queue_avail_low = value; + break; + case VIRTIO_MMIO_QUEUE_AVAIL_HIGH: + assert(vdev->queue_sel == 0); + proxy->queue_avail_high = value; + break; + case VIRTIO_MMIO_QUEUE_USED_LOW: + assert(vdev->queue_sel == 0); + proxy->queue_used_low = value; + break; + case VIRTIO_MMIO_QUEUE_USED_HIGH: + assert(vdev->queue_sel == 0); + proxy->queue_used_high = value; + break; + case VIRTIO_MMIO_MAGIC: case VIRTIO_MMIO_VERSION: case VIRTIO_MMIO_DEVICEID: From 2942122a0ec2de2da29b5234f792cfb50baf0922 Mon Sep 17 00:00:00 2001 From: hbcam <> Date: Fri, 15 Jul 2016 14:00:42 +0100 Subject: [PATCH 2/2] Add a virtio over MMIO device for CHERI-malta. --- hw/mips/mips_malta.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 241d1635866..0b829f7554d 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -914,6 +914,14 @@ static void cpu_request_exit(void *opaque, int irq, int level) } } +static void create_virtio_devices(qemu_irq *pic) +{ + hwaddr base = 0x1e400000; + int irq = 4; + + sysbus_create_simple("virtio-mmio", base, pic[irq]); +} + static void mips_malta_init(MachineState *machine) { @@ -1206,6 +1214,9 @@ void mips_malta_init(MachineState *machine) /* Optional PCI video card */ pci_vga_init(pci_bus); + + /* Virtio over MMIO */ + create_virtio_devices(env->irq); } static int mips_malta_sysbus_device_init(SysBusDevice *sysbusdev)