From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IzhRl-0007T3-A5 for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:45:01 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IzhRk-0007Qa-J8 for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:45:00 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IzhRk-0007OF-1v for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:45:00 -0500 Received: from ug-out-1314.google.com ([66.249.92.173]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IzhRg-0007Ts-O0 for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:44:57 -0500 Received: by ug-out-1314.google.com with SMTP id m2so226304uge for ; Tue, 04 Dec 2007 15:44:51 -0800 (PST) Message-ID: <4755E66F.3080300@qumranet.com> Date: Wed, 05 Dec 2007 01:44:47 +0200 MIME-Version: 1.0 References: <4755CC65.7040908@us.ibm.com> In-Reply-To: <4755CC65.7040908@us.ibm.com> Content-Type: multipart/alternative; boundary="------------050500070303070303070406" From: Dor Laor Subject: [Qemu-devel] Re: [PATCH 1/3] virtio infrastructure Reply-To: dor.laor@qumranet.com, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Rusty Russell , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------050500070303070303070406 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Anthony Liguori wrote: ------------------------------------------------------------------------ Subject: [PATCH 1/3] virtio infrastructure Cc: Rusty Russell Cc: Avi Kivity Cc: Dor Laor 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 --------------050500070303070303070406 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Anthony Liguori wrote:

Subject: [PATCH 1/3] virtio infrastructure Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Avi Kivity <avi@qumranet.com> Cc: Dor Laor <dor.laor@qumranet.com> 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
--------------050500070303070303070406--