Anthony Liguori wrote:

------------------------------------------------------------------------

Subject: [PATCH 1/3] virtio infrastructure
Cc: Rusty Russell <[EMAIL PROTECTED]>
Cc: Avi Kivity <[EMAIL PROTECTED]>
Cc: Dor Laor <[EMAIL PROTECTED]>

This patch implements the basic infrastructure for virtio devices.  These
devices are exposed to the guest as real PCI devices.  The PCI vendor/device
IDs have been donated by Qumranet and the subsystem IDs are used to distinguish
the virtio device itself.

Virtio provides an abstraction for performing guest=>host and host=>guest
communications.  It also provides a standard ring queue interface and discovery
mechanism.  Finally, virtio provides a simple mechanism for passing
configuration between host and guest.

In this virtio implementation, we provide these things via normal PCI
operations.  The Linux kernel support for this virtio device is pending in
Rusty's virtio patch queue[1].  They should be submitted once the merge window
opens again.

Some future TODOs are to use endian/alignment safe routines when accessing the
virtqueue so that mixed mode host/guests are supported.

[1] http://ozlabs.org/~rusty/kernel/hg

Index: qemu/Makefile.target
===================================================================
--- qemu.orig/Makefile.target   2007-12-04 10:00:43.000000000 -0600
+++ qemu/Makefile.target        2007-12-04 14:15:20.000000000 -0600
@@ -435,6 +435,9 @@
VL_OBJS += pcnet.o
VL_OBJS += rtl8139.o

+# virtio devices
+VL_OBJS += virtio.o
+
ifeq ($(TARGET_BASE_ARCH), i386)
# Hardware support
VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
Index: qemu/hw/virtio.c
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ qemu/hw/virtio.c    2007-12-04 14:17:15.000000000 -0600
@@ -0,0 +1,422 @@

[snip]

+#define VIRTIO_PCI_CONFIG              20
+

[snip]

+static void virtio_map(PCIDevice *pci_dev, int region_num,
+                      uint32_t addr, uint32_t size, int type)
+{
+    VirtIODevice *vdev = to_virtio_device(pci_dev);
+    int i;
+
+    vdev->addr = addr;
+    for (i = 0; i < 3; i++) {
+       register_ioport_write(addr, 20, 1 << i, virtio_ioport_write, vdev);
+       register_ioport_read(addr, 20, 1 << i, virtio_ioport_read, vdev);

Can you use VIRTIO_PCI_CONFIG instead of 20?

+    }
+
+    if (vdev->config_len) {
+       register_ioport_write(addr + 20, vdev->config_len, 1,
+                             virtio_config_writeb, vdev);
+       register_ioport_write(addr + 20, vdev->config_len, 2,
+                             virtio_config_writew, vdev);
+       register_ioport_write(addr + 20, vdev->config_len, 4,
+                             virtio_config_writel, vdev);
+       register_ioport_read(addr + 20, vdev->config_len, 1,
+                            virtio_config_readb, vdev);
+       register_ioport_read(addr + 20, vdev->config_len, 2,
+                            virtio_config_readw, vdev);
+       register_ioport_read(addr + 20, vdev->config_len, 4,
+                            virtio_config_readl, vdev);
+
+       vdev->update_config(vdev, vdev->config);
+    }
+}
+
+

I liked the push/pop functions, this encapsulation improves code
readability, cheers.
Dor.

+void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
+                   unsigned int len);
+
+int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
+
+void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
+
+#endif

Reply via email to