#include "kvm/blk-virtio.h"
+#include "kvm/virtio_pci.h"
#include "kvm/ioport.h"
#include "kvm/pci.h"
+#define VIRTIO_PCI_IOPORT_SIZE 24
+
#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001
#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
#define PCI_SUBSYSTEM_ID_VIRTIO_BLK 0x0002
-static struct pci_device_header virtio_device = {
+static struct pci_device_header blk_virtio_device = {
.vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
.device_id = PCI_DEVICE_ID_VIRTIO_BLK,
.header_type = PCI_HEADER_TYPE_NORMAL,
.bar[0] = IOPORT_VIRTIO | PCI_BASE_ADDRESS_SPACE_IO,
};
-static bool virtio_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
+static bool blk_virtio_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
{
- return true;
+ unsigned long offset;
+
+ offset = port - IOPORT_VIRTIO;
+
+ switch (offset) {
+ case VIRTIO_PCI_HOST_FEATURES:
+ case VIRTIO_PCI_GUEST_FEATURES:
+ case VIRTIO_PCI_QUEUE_PFN:
+ case VIRTIO_PCI_QUEUE_NUM:
+ case VIRTIO_PCI_QUEUE_SEL:
+ case VIRTIO_PCI_QUEUE_NOTIFY:
+ case VIRTIO_PCI_STATUS:
+ case VIRTIO_PCI_ISR:
+ case VIRTIO_MSI_CONFIG_VECTOR:
+ return true;
+ };
+
+ return false;
}
-static bool virtio_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
+static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
{
- return true;
+ unsigned long offset;
+
+ offset = port - IOPORT_VIRTIO;
+
+ switch (offset) {
+ case VIRTIO_PCI_GUEST_FEATURES:
+ case VIRTIO_PCI_QUEUE_PFN:
+ case VIRTIO_PCI_QUEUE_SEL:
+ case VIRTIO_PCI_QUEUE_NOTIFY:
+ case VIRTIO_PCI_STATUS:
+ case VIRTIO_MSI_CONFIG_VECTOR:
+ case VIRTIO_MSI_QUEUE_VECTOR:
+ return true;
+ };
+
+ return false;
}
-static struct ioport_operations virtio_io_ops = {
- .io_in = virtio_in,
- .io_out = virtio_out,
+static struct ioport_operations blk_virtio_io_ops = {
+ .io_in = blk_virtio_in,
+ .io_out = blk_virtio_out,
};
void blk_virtio__init(void)
{
- pci__register(&virtio_device, 1);
+ pci__register(&blk_virtio_device, 1);
- ioport__register(IOPORT_VIRTIO, &virtio_io_ops, 1);
+ ioport__register(IOPORT_VIRTIO, &blk_virtio_io_ops, VIRTIO_PCI_IOPORT_SIZE);
}
--- /dev/null
+/*
+ * Virtio PCI driver
+ *
+ * This module allows virtio devices to be used over a virtual PCI device.
+ * This can be used with QEMU based VMMs like KVM or Xen.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ */
+
+#ifndef _LINUX_VIRTIO_PCI_H
+#define _LINUX_VIRTIO_PCI_H
+
+/* A 32-bit r/o bitmask of the features supported by the host */
+#define VIRTIO_PCI_HOST_FEATURES 0
+
+/* A 32-bit r/w bitmask of features activated by the guest */
+#define VIRTIO_PCI_GUEST_FEATURES 4
+
+/* A 32-bit r/w PFN for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_PFN 8
+
+/* A 16-bit r/o queue size for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_NUM 12
+
+/* A 16-bit r/w queue selector */
+#define VIRTIO_PCI_QUEUE_SEL 14
+
+/* A 16-bit r/w queue notifier */
+#define VIRTIO_PCI_QUEUE_NOTIFY 16
+
+/* An 8-bit device status register. */
+#define VIRTIO_PCI_STATUS 18
+
+/* An 8-bit r/o interrupt status register. Reading the value will return the
+ * current contents of the ISR and will also clear it. This is effectively
+ * a read-and-acknowledge. */
+#define VIRTIO_PCI_ISR 19
+
+/* MSI-X registers: only enabled if MSI-X is enabled. */
+/* A 16-bit vector for configuration changes. */
+#define VIRTIO_MSI_CONFIG_VECTOR 20
+
+/* A 16-bit vector for selected queue notifications. */
+#define VIRTIO_MSI_QUEUE_VECTOR 22
+
+#endif /* _LINUX_VIRTIO_PCI_H */