Commit 39d6af07 authored by Asias He's avatar Asias He Committed by Will Deacon
Browse files

kvm tools: Introduce virtio.c and virtio.h



This patch moves common virtio code to virtio.c and virtio.h.

Signed-off-by: default avatarAsias He <asias.hejun@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent 802e07a0
......@@ -26,6 +26,7 @@ OBJS += mmio.o
OBJS += pci.o
OBJS += util.o
OBJS += term.o
OBJS += virtio.o
DEPS := $(patsubst %.o,%.d,$(OBJS))
......
......@@ -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"
......
#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"
......
#ifndef KVM__VIRTQUEUE_H
#define KVM__VIRTQUEUE_H
#ifndef KVM__VIRTIO_H
#define KVM__VIRTIO_H
#include <linux/virtio_ring.h>
......@@ -31,43 +31,14 @@ static inline struct vring_used_elem *virt_queue__get_used_elem(struct virt_queu
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);
struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len);
return head;
}
uint16_t virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], uint16_t *out, uint16_t *in, struct kvm *kvm);
#endif /* KVM__VIRTQUEUE_H */
#endif /* KVM__VIRTIO_H */
#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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment