clear-pkgs-linux-iot-lts2018/0781-VBS-K-use-kernel-virti...

197 lines
6.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jian Jun Chen <jian.jun.chen@intel.com>
Date: Thu, 6 Dec 2018 12:07:14 +0800
Subject: [PATCH] VBS-K: use kernel virtio header files
Current VBS-K implementation defines its own set of vring structures
and virtio feature flags. Some of them have the same names as those
in kernel virtio header files. Redefinition errors happen when some
modules try to include both the vbs-k header files and linux virtio
header files. This patch remove those definitions in vbs-k header
files and use linux virtio header files directly.
Tracked-On: projectacrn/acrn-hypervisor#1993
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Tracked-On: PKT-1617
---
drivers/vbs/vq.c | 18 +++++++++---------
include/linux/vbs/vbs.h | 28 +++-------------------------
include/linux/vbs/vq.h | 23 ++---------------------
3 files changed, 14 insertions(+), 55 deletions(-)
diff --git a/drivers/vbs/vq.c b/drivers/vbs/vq.c
index 4ea44c47b871..3a714441f11a 100644
--- a/drivers/vbs/vq.c
+++ b/drivers/vbs/vq.c
@@ -75,7 +75,7 @@ void * paddr_guest2host(struct ctx *ctx, uintptr_t gaddr, size_t len)
* helper function for vq_getchain():
* record the i'th "real" descriptor.
*/
-static inline void _vq_record(int i, volatile struct virtio_desc *vd,
+static inline void _vq_record(int i, volatile struct vring_desc *vd,
struct ctx *ctx, struct iovec *iov,
int n_iov, uint16_t *flags)
{
@@ -140,7 +140,7 @@ int virtio_vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx,
struct virtio_dev_info *dev;
const char *name;
- volatile struct virtio_desc *vdir, *vindir, *vp;
+ volatile struct vring_desc *vdir, *vindir, *vp;
dev = vq->dev;
name = dev->name;
@@ -193,7 +193,7 @@ int virtio_vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx,
_vq_record(i, vdir, ctx, iov, n_iov, flags);
i++;
} else if ((dev->negotiated_features &
- VIRTIO_RING_F_INDIRECT_DESC) == 0) {
+ (1U << VIRTIO_RING_F_INDIRECT_DESC)) == 0) {
pr_err("%s: descriptor has forbidden INDIRECT flag, "
"driver confused?\r\n", name);
return -1;
@@ -269,7 +269,7 @@ void virtio_vq_relchain(struct virtio_vq_info *vq, uint16_t idx,
{
uint16_t uidx, mask;
volatile struct vring_used *vuh;
- volatile struct virtio_used *vue;
+ volatile struct vring_used_elem *vue;
/*
* Notes:
@@ -286,7 +286,7 @@ void virtio_vq_relchain(struct virtio_vq_info *vq, uint16_t idx,
uidx = vuh->idx;
vue = &vuh->ring[uidx++ & mask];
- vue->idx = idx;
+ vue->id = idx;
vue->len = iolen;
vuh->idx = uidx;
}
@@ -326,9 +326,9 @@ void virtio_vq_endchains(struct virtio_vq_info *vq, int used_all_avail)
old_idx = vq->save_used;
vq->save_used = new_idx = vq->used->idx;
if (used_all_avail &&
- (dev->negotiated_features & VIRTIO_F_NOTIFY_ON_EMPTY))
+ (dev->negotiated_features & (1U << VIRTIO_F_NOTIFY_ON_EMPTY)))
intr = 1;
- else if (dev->negotiated_features & VIRTIO_RING_F_EVENT_IDX) {
+ else if (dev->negotiated_features & (1U << VIRTIO_RING_F_EVENT_IDX)) {
event_idx = VQ_USED_EVENT_IDX(vq);
/*
* This calculation is per docs and the kernel
@@ -364,8 +364,8 @@ void virtio_vq_init(struct virtio_vq_info *vq, uint32_t pfn)
base = paddr_guest2host(ctx, phys, size);
/* First page(s) are descriptors... */
- vq->desc = (struct virtio_desc *)base;
- base += vq->qsize * sizeof(struct virtio_desc);
+ vq->desc = (struct vring_desc *)base;
+ base += vq->qsize * sizeof(struct vring_desc);
/* ... immediately followed by "avail" ring (entirely uint16_t's) */
vq->avail = (struct vring_avail *)base;
diff --git a/include/linux/vbs/vbs.h b/include/linux/vbs/vbs.h
index a72bb9612d1e..765dc9c33a07 100644
--- a/include/linux/vbs/vbs.h
+++ b/include/linux/vbs/vbs.h
@@ -62,6 +62,8 @@
#ifndef _VBS_H_
#define _VBS_H_
+#include <linux/virtio_ring.h>
+#include <linux/virtio_config.h>
#include <linux/vbs/vbs_common_if.h>
#include <linux/vhm/acrn_common.h>
#include <linux/vhm/acrn_vhm_ioreq.h>
@@ -92,30 +94,6 @@ struct ctx {
struct vhm_request *req_buf;
};
-struct virtio_desc { /* AKA vring_desc */
- uint64_t addr; /* guest physical address */
- uint32_t len; /* length of scatter/gather seg */
- uint16_t flags; /* desc flags */
- uint16_t next; /* next desc if F_NEXT */
-} __attribute__((packed));
-
-struct virtio_used { /* AKA vring_used_elem */
- uint32_t idx; /* head of used descriptor chain */
- uint32_t len; /* length written-to */
-} __attribute__((packed));
-
-struct vring_avail {
- uint16_t flags; /* vring_avail flags */
- uint16_t idx; /* counts to 65535, then cycles */
- uint16_t ring[]; /* size N, reported in QNUM value */
-} __attribute__((packed));
-
-struct vring_used {
- uint16_t flags; /* vring_used flags */
- uint16_t idx; /* counts to 65535, then cycles */
- struct virtio_used ring[]; /* size N */
-} __attribute__((packed));
-
/**
* struct virtio_vq_info - virtqueue data structure
*/
@@ -147,7 +125,7 @@ struct virtio_vq_info {
uint16_t save_used;
/* private: descriptor array */
- volatile struct virtio_desc *desc;
+ volatile struct vring_desc *desc;
/* private: the "avail" ring */
volatile struct vring_avail *avail;
/* private: the "used" ring */
diff --git a/include/linux/vbs/vq.h b/include/linux/vbs/vq.h
index ca14f8f34888..45e462920506 100644
--- a/include/linux/vbs/vq.h
+++ b/include/linux/vbs/vq.h
@@ -77,27 +77,8 @@
#define VQ_ALLOC 0x01
#define VQ_BROKED 0x02
-/*
- * Feature flags.
- * Note: bits 0 through 23 are reserved to each device type.
- */
-#define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24)
-#define VIRTIO_RING_F_INDIRECT_DESC (1 << 28)
-#define VIRTIO_RING_F_EVENT_IDX (1 << 29)
-
#define VQ_MAX_DESCRIPTORS 512
-/* virtio_desc flags */
-#define VRING_DESC_F_NEXT (1 << 0)
-#define VRING_DESC_F_WRITE (1 << 1)
-#define VRING_DESC_F_INDIRECT (1 << 2)
-
-/* vring_avail flags */
-#define VRING_AVAIL_F_NO_INTERRUPT 1
-
-/* vring_used flags */
-#define VRING_USED_F_NO_NOTIFY 1
-
/* Functions for dealing with generalized "virtual devices" */
#define VQ_USED_EVENT_IDX(vq) ((vq)->avail->ring[(vq)->qsize])
@@ -113,11 +94,11 @@ static inline size_t virtio_vq_ring_size(unsigned int qsz)
size_t size;
/* constant 3 below = va_flags, va_idx, va_used_event */
- size = sizeof(struct virtio_desc) * qsz + sizeof(uint16_t) * (3 + qsz);
+ size = sizeof(struct vring_desc) * qsz + sizeof(uint16_t) * (3 + qsz);
size = roundup2(size, VRING_ALIGN);
/* constant 3 below = vu_flags, vu_idx, vu_avail_event */
- size += sizeof(uint16_t) * 3 + sizeof(struct virtio_used) * qsz;
+ size += sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * qsz;
size = roundup2(size, VRING_ALIGN);
return size;
--
https://clearlinux.org