Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding virtio over MMIO for CHERI-malta #13

Merged
merged 2 commits into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions hw/mips/mips_malta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
49 changes: 49 additions & 0 deletions hw/virtio/virtio-mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand Down