]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Introduce virtio.c and virtio.h
authorAsias He <asias.hejun@gmail.com>
Fri, 8 Apr 2011 16:10:04 +0000 (00:10 +0800)
committerPekka Enberg <penberg@kernel.org>
Fri, 8 Apr 2011 16:22:00 +0000 (19:22 +0300)
This patch moves common virtio code to virtio.c and virtio.h.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/Makefile
tools/kvm/blk-virtio.c
tools/kvm/console-virtio.c
tools/kvm/include/kvm/virtio.h [new file with mode: 0644]
tools/kvm/include/kvm/virtqueue.h [deleted file]
tools/kvm/virtio.c [new file with mode: 0644]

index 55f342d9d2601b3cd546ceca59210d5bdaac27f3..82d41b6b06c5647a5d86b01859d0d883a5011331 100644 (file)
@@ -26,6 +26,7 @@ OBJS  += mmio.o
 OBJS   += pci.o
 OBJS   += util.o
 OBJS   += term.o
+OBJS   += virtio.o
 
 DEPS   := $(patsubst %.o,%.d,$(OBJS))
 
index e94d7b3a771fc1b0b8ace7ed06360a28ae6a8629..2eb9734547d5125a25a70fc1d3e33fc799c01c42 100644 (file)
@@ -3,7 +3,7 @@
 #include "kvm/virtio_pci.h"
 
 #include "kvm/disk-image.h"
-#include "kvm/virtqueue.h"
+#include "kvm/virtio.h"
 #include "kvm/ioport.h"
 #include "kvm/util.h"
 #include "kvm/kvm.h"
index f094610d3d03ae22219305a1a464c02e05ce1c42..3926536d734bddcf726f7b839561d9d995c2f435 100644 (file)
@@ -1,7 +1,7 @@
 #include "kvm/console-virtio.h"
 #include "kvm/virtio_pci.h"
 #include "kvm/disk-image.h"
-#include "kvm/virtqueue.h"
+#include "kvm/virtio.h"
 #include "kvm/ioport.h"
 #include "kvm/util.h"
 #include "kvm/term.h"
diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
new file mode 100644 (file)
index 0000000..075387d
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef KVM__VIRTIO_H
+#define KVM__VIRTIO_H
+
+#include <linux/virtio_ring.h>
+
+#include <stdint.h>
+#include <sys/uio.h>
+
+#include "kvm/kvm.h"
+
+struct virt_queue {
+       struct vring                    vring;
+       uint32_t                        pfn;
+       /* The last_avail_idx field is an index to ->ring of struct vring_avail.
+          It's where we assume the next request index is at.  */
+       uint16_t                        last_avail_idx;
+};
+
+static inline uint16_t virt_queue__pop(struct virt_queue *queue)
+{
+       return queue->vring.avail->ring[queue->last_avail_idx++ % queue->vring.num];
+}
+
+static inline struct vring_desc *virt_queue__get_desc(struct virt_queue *queue, uint16_t desc_ndx)
+{
+       return &queue->vring.desc[desc_ndx];
+}
+
+static inline struct vring_used_elem *virt_queue__get_used_elem(struct virt_queue *queue)
+{
+       return &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
+}
+
+
+static inline bool virt_queue__available(struct virt_queue *vq)
+{
+       return vq->vring.avail->idx !=  vq->last_avail_idx;
+}
+
+struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len);
+
+uint16_t virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], uint16_t *out, uint16_t *in, struct kvm *kvm);
+
+#endif /* KVM__VIRTIO_H */
diff --git a/tools/kvm/include/kvm/virtqueue.h b/tools/kvm/include/kvm/virtqueue.h
deleted file mode 100644 (file)
index de360ae..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-#ifndef KVM__VIRTQUEUE_H
-#define KVM__VIRTQUEUE_H
-
-#include <linux/virtio_ring.h>
-
-#include <stdint.h>
-#include <sys/uio.h>
-
-#include "kvm/kvm.h"
-
-struct virt_queue {
-       struct vring                    vring;
-       uint32_t                        pfn;
-       /* The last_avail_idx field is an index to ->ring of struct vring_avail.
-          It's where we assume the next request index is at.  */
-       uint16_t                        last_avail_idx;
-};
-
-static inline uint16_t virt_queue__pop(struct virt_queue *queue)
-{
-       return queue->vring.avail->ring[queue->last_avail_idx++ % queue->vring.num];
-}
-
-static inline struct vring_desc *virt_queue__get_desc(struct virt_queue *queue, uint16_t desc_ndx)
-{
-       return &queue->vring.desc[desc_ndx];
-}
-
-static inline struct vring_used_elem *virt_queue__get_used_elem(struct virt_queue *queue)
-{
-       return &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
-}
-
-static inline struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len)
-{
-       struct vring_used_elem *used_elem;
-       used_elem       = &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
-       used_elem->id   = head;
-       used_elem->len  = len;
-       return used_elem;
-}
-
-static inline bool virt_queue__available(struct virt_queue *vq)
-{
-       return vq->vring.avail->idx !=  vq->last_avail_idx;
-}
-
-static inline uint16_t virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], uint16_t *out, uint16_t *in, struct kvm *kvm)
-{
-       struct vring_desc *desc;
-       uint16_t head, idx;
-
-       idx = head = virt_queue__pop(queue);
-       *out = *in = 0;
-
-       do {
-               desc                            = virt_queue__get_desc(queue, idx);
-               iov[*out + *in].iov_base        = guest_flat_to_host(kvm, desc->addr);
-               iov[*out + *in].iov_len         = desc->len;
-               if (desc->flags & VRING_DESC_F_WRITE)
-                       (*in)++;
-               else
-                       (*out)++;
-               if (desc->flags & VRING_DESC_F_NEXT)
-                       idx = desc->next;
-               else
-                       break;
-       } while (1);
-
-       return head;
-}
-
-#endif /* KVM__VIRTQUEUE_H */
diff --git a/tools/kvm/virtio.c b/tools/kvm/virtio.c
new file mode 100644 (file)
index 0000000..6249521
--- /dev/null
@@ -0,0 +1,39 @@
+#include <linux/virtio_ring.h>
+#include <stdint.h>
+#include <sys/uio.h>
+#include "kvm/kvm.h"
+#include "kvm/virtio.h"
+
+struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len)
+{
+       struct vring_used_elem *used_elem;
+       used_elem       = &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
+       used_elem->id   = head;
+       used_elem->len  = len;
+       return used_elem;
+}
+
+uint16_t virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], uint16_t *out, uint16_t *in, struct kvm *kvm)
+{
+       struct vring_desc *desc;
+       uint16_t head, idx;
+
+       idx = head = virt_queue__pop(queue);
+       *out = *in = 0;
+
+       do {
+               desc                            = virt_queue__get_desc(queue, idx);
+               iov[*out + *in].iov_base        = guest_flat_to_host(kvm, desc->addr);
+               iov[*out + *in].iov_len         = desc->len;
+               if (desc->flags & VRING_DESC_F_WRITE)
+                       (*in)++;
+               else
+                       (*out)++;
+               if (desc->flags & VRING_DESC_F_NEXT)
+                       idx = desc->next;
+               else
+                       break;
+       } while (1);
+
+       return head;
+}