mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-08 10:04:42 +00:00
dm: virtio: remove hv_caps from virtio_ops
currently, each virtio device has their own virtio_ops implementation.
Take virtio-blk for example:
static struct virtio_ops virtio_blk_ops = {
"virtio_blk",
1,
sizeof(struct virtio_blk_config),
virtio_blk_reset,
virtio_blk_notify,
virtio_blk_cfgread,
virtio_blk_cfgwrite,
NULL,
NULL,
VIRTIO_BLK_S_HOSTCAPS,
};
If start DM with two virtio-blk, this global variable will be
assigined to two virtio-blk instances. Changing hv_caps for one
instance will affect others. But different instances may need
different capabilities.
To support this requirement, we suggest to move hv_caps to
virtio_base structure, and each instance can return their own
capabilities.
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
@@ -381,7 +381,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx,
|
||||
if ((vdir->flags & VRING_DESC_F_INDIRECT) == 0) {
|
||||
_vq_record(i, vdir, ctx, iov, n_iov, flags);
|
||||
i++;
|
||||
} else if ((base->vops->hv_caps &
|
||||
} else if ((base->device_caps &
|
||||
VIRTIO_RING_F_INDIRECT_DESC) == 0) {
|
||||
fprintf(stderr,
|
||||
"%s: descriptor has forbidden INDIRECT flag, "
|
||||
@@ -696,7 +696,7 @@ bad:
|
||||
|
||||
switch (offset) {
|
||||
case VIRTIO_CR_HOSTCAP:
|
||||
value = vops->hv_caps;
|
||||
value = base->device_caps;
|
||||
break;
|
||||
case VIRTIO_CR_GUESTCAP:
|
||||
value = base->negotiated_caps;
|
||||
@@ -813,7 +813,7 @@ bad:
|
||||
|
||||
switch (offset) {
|
||||
case VIRTIO_CR_GUESTCAP:
|
||||
base->negotiated_caps = value & vops->hv_caps;
|
||||
base->negotiated_caps = value & base->device_caps;
|
||||
if (vops->apply_features)
|
||||
(*vops->apply_features)(DEV_STRUCT(base),
|
||||
base->negotiated_caps);
|
||||
@@ -1020,7 +1020,7 @@ virtio_set_modern_bar(struct virtio_base *base, bool use_notify_pio)
|
||||
|
||||
vops = base->vops;
|
||||
|
||||
if (!vops || (vops->hv_caps & VIRTIO_F_VERSION_1) == 0)
|
||||
if (!vops || (base->device_caps & VIRTIO_F_VERSION_1) == 0)
|
||||
return -1;
|
||||
|
||||
if (use_notify_pio)
|
||||
@@ -1111,9 +1111,9 @@ virtio_common_cfg_read(struct pci_vdev *dev, uint64_t offset, int size)
|
||||
break;
|
||||
case VIRTIO_COMMON_DF:
|
||||
if (base->device_feature_select == 0)
|
||||
value = vops->hv_caps & 0xffffffff;
|
||||
value = base->device_caps & 0xffffffff;
|
||||
else if (base->device_feature_select == 1)
|
||||
value = (vops->hv_caps >> 32) & 0xffffffff;
|
||||
value = (base->device_caps >> 32) & 0xffffffff;
|
||||
else /* present 0, see 4.1.4.3.1 */
|
||||
value = 0;
|
||||
break;
|
||||
@@ -1240,7 +1240,7 @@ virtio_common_cfg_write(struct pci_vdev *dev, uint64_t offset, int size,
|
||||
value &= 0xffffffff;
|
||||
base->negotiated_caps =
|
||||
(value << (base->driver_feature_select * 32))
|
||||
& vops->hv_caps;
|
||||
& base->device_caps;
|
||||
if (vops->apply_features)
|
||||
(*vops->apply_features)(DEV_STRUCT(base),
|
||||
base->negotiated_caps);
|
||||
|
||||
@@ -88,7 +88,6 @@ static struct virtio_ops virtio_audio_ops_k = {
|
||||
NULL, /* write virtio config */
|
||||
NULL, /* apply negotiated features */
|
||||
virtio_audio_k_set_status,/* called on guest set status */
|
||||
0, /* our capabilities */
|
||||
};
|
||||
|
||||
static int
|
||||
|
||||
@@ -143,7 +143,6 @@ static struct virtio_ops virtio_blk_ops = {
|
||||
virtio_blk_cfgwrite, /* write PCI config */
|
||||
NULL, /* apply negotiated features */
|
||||
NULL, /* called on guest set status */
|
||||
VIRTIO_BLK_S_HOSTCAPS, /* our capabilities */
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -339,6 +338,7 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
/* init virtio struct and virtqueues */
|
||||
virtio_linkup(&blk->base, &virtio_blk_ops, blk, dev, &blk->vq);
|
||||
blk->base.mtx = &blk->mtx;
|
||||
blk->base.device_caps = VIRTIO_BLK_S_HOSTCAPS;
|
||||
|
||||
blk->vq.qsize = VIRTIO_BLK_RINGSZ;
|
||||
/* blk->vq.vq_notify = we have no per-queue notify */
|
||||
|
||||
@@ -164,7 +164,6 @@ static struct virtio_ops virtio_console_ops = {
|
||||
virtio_console_cfgwrite, /* write virtio config */
|
||||
virtio_console_neg_features, /* apply negotiated features */
|
||||
NULL, /* called on guest set status */
|
||||
VIRTIO_CONSOLE_S_HOSTCAPS, /* our capabilities */
|
||||
};
|
||||
|
||||
static const char *virtio_console_be_table[VIRTIO_CONSOLE_BE_MAX] = {
|
||||
@@ -837,6 +836,7 @@ virtio_console_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
virtio_linkup(&console->base, &virtio_console_ops, console, dev,
|
||||
console->queues);
|
||||
console->base.mtx = &console->mtx;
|
||||
console->base.device_caps = VIRTIO_CONSOLE_S_HOSTCAPS;
|
||||
|
||||
for (i = 0; i < VIRTIO_CONSOLE_MAXQ; i++) {
|
||||
console->queues[i].qsize = VIRTIO_CONSOLE_RINGSZ;
|
||||
|
||||
@@ -151,7 +151,6 @@ static struct virtio_ops virtio_heci_ops = {
|
||||
virtio_heci_cfgwrite, /* write virtio config */
|
||||
NULL, /* apply negotiated features */
|
||||
NULL, /* called on guest set status */
|
||||
0, /* our capabilities */
|
||||
};
|
||||
|
||||
static void
|
||||
|
||||
@@ -84,7 +84,6 @@ static struct virtio_ops virtio_hyper_dmabuf_ops_k = {
|
||||
NULL, /* write virtio config */
|
||||
NULL, /* apply negotiated features */
|
||||
virtio_hyper_dmabuf_set_status, /* called on guest set status */
|
||||
0, /* our capabilities */
|
||||
};
|
||||
|
||||
static int
|
||||
|
||||
@@ -143,7 +143,6 @@ static struct virtio_ops virtio_input_ops = {
|
||||
virtio_input_cfgwrite, /* write virtio config */
|
||||
virtio_input_neg_features, /* apply negotiated features */
|
||||
virtio_input_set_status, /* called on guest set status */
|
||||
VIRTIO_INPUT_S_HOSTCAPS, /* our capabilities */
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -606,6 +605,7 @@ virtio_input_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
|
||||
virtio_linkup(&vi->base, &virtio_input_ops, vi, dev, vi->queues);
|
||||
vi->base.mtx = &vi->mtx;
|
||||
vi->base.device_caps = VIRTIO_INPUT_S_HOSTCAPS;
|
||||
|
||||
vi->queues[VIRTIO_INPUT_EVENT_QUEUE].qsize = VIRTIO_INPUT_RINGSZ;
|
||||
vi->queues[VIRTIO_INPUT_EVENT_QUEUE].notify =
|
||||
|
||||
@@ -168,7 +168,6 @@ static struct virtio_ops virtio_net_ops = {
|
||||
virtio_net_cfgwrite, /* write PCI config */
|
||||
virtio_net_neg_features, /* apply negotiated features */
|
||||
NULL, /* called on guest set status */
|
||||
VIRTIO_NET_S_HOSTCAPS, /* our capabilities */
|
||||
};
|
||||
|
||||
static struct ether_addr *
|
||||
@@ -914,6 +913,7 @@ virtio_net_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
|
||||
virtio_linkup(&net->base, &virtio_net_ops, net, dev, net->queues);
|
||||
net->base.mtx = &net->mtx;
|
||||
net->base.device_caps = VIRTIO_NET_S_HOSTCAPS;
|
||||
|
||||
net->queues[VIRTIO_NET_RXQ].qsize = VIRTIO_NET_RINGSZ;
|
||||
net->queues[VIRTIO_NET_RXQ].notify = virtio_net_ping_rxq;
|
||||
|
||||
@@ -97,7 +97,6 @@ static struct virtio_ops virtio_rnd_ops = {
|
||||
NULL, /* write virtio config */
|
||||
NULL, /* apply negotiated features */
|
||||
NULL, /* called on guest set status */
|
||||
0, /* our capabilities */
|
||||
};
|
||||
|
||||
/* VBS-K virtio_ops */
|
||||
@@ -113,7 +112,6 @@ static struct virtio_ops virtio_rnd_ops_k = {
|
||||
NULL, /* write virtio config */
|
||||
NULL, /* apply negotiated features */
|
||||
virtio_rnd_k_set_status,/* called on guest set status */
|
||||
0, /* our capabilities */
|
||||
};
|
||||
|
||||
/* VBS-K interface function implementations */
|
||||
|
||||
@@ -600,7 +600,6 @@ static struct virtio_ops virtio_rpmb_ops = {
|
||||
NULL, /* write virtio config */
|
||||
NULL, /* apply negotiated features */
|
||||
NULL, /* called on guest set status */
|
||||
0, /* our capabilities */
|
||||
};
|
||||
|
||||
static int
|
||||
|
||||
Reference in New Issue
Block a user