|
|
|
|
|
|
|
|
|
|
xen-devel
[Xen-devel] [PATCH RFC 1/3] virtio infrastructure
To: |
kvm-devel <kvm-devel@xxxxxxxxxxxxxxxxxxxxx>, Xen Mailing List <xen-devel@xxxxxxxxxxxxxxxxxxx>, virtualization <virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx> |
Subject: |
[Xen-devel] [PATCH RFC 1/3] virtio infrastructure |
From: |
Rusty Russell <rusty@xxxxxxxxxxxxxxx> |
Date: |
Thu, 31 May 2007 22:19:07 +1000 |
Cc: |
Jimi Xenidis <jimix@xxxxxxxxxxxxxx>, Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>, "jmk@xxxxxxxxxxxxxxxxxxx" <jmk@xxxxxxxxxxxxxxxxxxx>, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>, Christian Borntraeger <cborntra@xxxxxxxxxx>, Suzanne McIntosh <skranjac@xxxxxxxxxx>, Anthony Liguori <anthony@xxxxxxxxxxxxx>, Martin Schwidefsky <schwidefsky@xxxxxxxxxx> |
Delivery-date: |
Thu, 31 May 2007 05:17:55 -0700 |
Envelope-to: |
www-data@xxxxxxxxxxxxxxxxxx |
List-help: |
<mailto:xen-devel-request@lists.xensource.com?subject=help> |
List-id: |
Xen developer discussion <xen-devel.lists.xensource.com> |
List-post: |
<mailto:xen-devel@lists.xensource.com> |
List-subscribe: |
<http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe> |
List-unsubscribe: |
<http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe> |
Sender: |
xen-devel-bounces@xxxxxxxxxxxxxxxxxxx |
This attempts to implement a "virtual I/O" layer which should allow
common drivers to be efficiently used across most virtual I/O
mechanisms. It will no-doubt need further enhancement.
The details of probing the device are left to hypervisor-specific
code: it simple constructs the "struct virtio_device" and hands it to
the probe function (eg. virtnet_probe() or virtblk_probe()).
The virtio drivers add and detach input and output buffers; as the
buffers are used up their associated "used" pointers are filled in.
I have written two virtio device drivers (net and block) and two
virtio implementations (for lguest): a read-write socket-style
implementation, and a more efficient descriptor-based implementation).
Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
---
include/linux/virtio.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff -r 2db2135723b0 include/linux/virtio.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/linux/virtio.h Thu May 31 17:52:19 2007 +1000
@@ -0,0 +1,66 @@
+#ifndef _LINUX_VIRTIO_H
+#define _LINUX_VIRTIO_H
+#include <linux/types.h>
+#include <linux/scatterlist.h>
+
+/**
+ * virtio_device - description and routines to drive a virtual device.
+ * @dev: the underlying struct device.
+ * @ops: the operations for this virtual device.
+ */
+struct virtio_device {
+ struct device *dev;
+ struct virtio_ops *ops;
+};
+
+/**
+ * virtio_ops - virtio abstraction layer
+ * @add_outbuf: prepare to send data to the other end:
+ * vdev: the virtio_device
+ * sg: the description of the buffer(s).
+ * num: the size of the sg array.
+ * used: the length sent (set once sending is done).
+ * Returns an identifier or an error.
+ * @add_inbuf: prepare to receive data from the other end:
+ * vdev: the virtio_device
+ * sg: the description of the buffer(s).
+ * num: the size of the sg array.
+ * used: the length sent (set once data received).
+ * Returns an identifier or an error (eg. -ENOSPC).
+ * @sync: update after add_inbuf/add_outbuf
+ * vdev: the virtio_device we're talking about.
+ * Use the virtio_sync wrapper, to avoid unnecessary calls.
+ * @detach_outbuf: make sure sent sg can no longer be read.
+ * vdev: the virtio_device we're talking about.
+ * id: the identifier returned from add_outbuf.
+ * @detach_inbuf: make sure sent sg can no longer be written to.
+ * vdev: the virtio_device we're talking about.
+ * id: the identifier returned from add_inbuf.
+ */
+struct virtio_ops {
+ unsigned long (*add_outbuf)(struct virtio_device *vdev,
+ const struct scatterlist sg[],
+ unsigned int num,
+ unsigned long *used);
+
+ unsigned long (*add_inbuf)(struct virtio_device *vdev,
+ struct scatterlist sg[],
+ unsigned int num,
+ unsigned long *used);
+
+ void (*sync)(struct virtio_device *vdev);
+
+ void (*detach_outbuf)(struct virtio_device *vdev, unsigned long id);
+ void (*detach_inbuf)(struct virtio_device *vdev, unsigned long id);
+};
+
+/**
+ * virtio_sync - start sending/receiving data from the other end.
+ * @vdev: the virtio_device we're talking about.
+ */
+static inline void virtio_sync(struct virtio_device *vdev)
+{
+ if (vdev->ops->sync)
+ vdev->ops->sync(vdev);
+}
+#endif /* _LINUX_VIRTIO_H */
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
|
|
|
|