diff --git a/devicemodel/hw/pci/virtio/virtio.c b/devicemodel/hw/pci/virtio/virtio.c index ec86fc4f7..19458fe68 100644 --- a/devicemodel/hw/pci/virtio/virtio.c +++ b/devicemodel/hw/pci/virtio/virtio.c @@ -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); diff --git a/devicemodel/hw/pci/virtio/virtio_audio.c b/devicemodel/hw/pci/virtio/virtio_audio.c index 455b26077..0dbfdfc0a 100644 --- a/devicemodel/hw/pci/virtio/virtio_audio.c +++ b/devicemodel/hw/pci/virtio/virtio_audio.c @@ -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 diff --git a/devicemodel/hw/pci/virtio/virtio_block.c b/devicemodel/hw/pci/virtio/virtio_block.c index c047ba655..07245b1a9 100644 --- a/devicemodel/hw/pci/virtio/virtio_block.c +++ b/devicemodel/hw/pci/virtio/virtio_block.c @@ -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 */ diff --git a/devicemodel/hw/pci/virtio/virtio_console.c b/devicemodel/hw/pci/virtio/virtio_console.c index a512359ca..52f77de32 100644 --- a/devicemodel/hw/pci/virtio/virtio_console.c +++ b/devicemodel/hw/pci/virtio/virtio_console.c @@ -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; diff --git a/devicemodel/hw/pci/virtio/virtio_heci.c b/devicemodel/hw/pci/virtio/virtio_heci.c index c15a7ad38..e5af6fd5d 100644 --- a/devicemodel/hw/pci/virtio/virtio_heci.c +++ b/devicemodel/hw/pci/virtio/virtio_heci.c @@ -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 diff --git a/devicemodel/hw/pci/virtio/virtio_hyper_dmabuf.c b/devicemodel/hw/pci/virtio/virtio_hyper_dmabuf.c index 21d445623..1c854a114 100644 --- a/devicemodel/hw/pci/virtio/virtio_hyper_dmabuf.c +++ b/devicemodel/hw/pci/virtio/virtio_hyper_dmabuf.c @@ -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 diff --git a/devicemodel/hw/pci/virtio/virtio_input.c b/devicemodel/hw/pci/virtio/virtio_input.c index aa13c7264..fa8476da7 100644 --- a/devicemodel/hw/pci/virtio/virtio_input.c +++ b/devicemodel/hw/pci/virtio/virtio_input.c @@ -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 = diff --git a/devicemodel/hw/pci/virtio/virtio_net.c b/devicemodel/hw/pci/virtio/virtio_net.c index f254355ee..2b5f94d3b 100644 --- a/devicemodel/hw/pci/virtio/virtio_net.c +++ b/devicemodel/hw/pci/virtio/virtio_net.c @@ -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; diff --git a/devicemodel/hw/pci/virtio/virtio_rnd.c b/devicemodel/hw/pci/virtio/virtio_rnd.c index 618aa66a8..033552b87 100644 --- a/devicemodel/hw/pci/virtio/virtio_rnd.c +++ b/devicemodel/hw/pci/virtio/virtio_rnd.c @@ -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 */ diff --git a/devicemodel/hw/pci/virtio/virtio_rpmb.c b/devicemodel/hw/pci/virtio/virtio_rpmb.c index ec365240a..b0c0cda53 100644 --- a/devicemodel/hw/pci/virtio/virtio_rpmb.c +++ b/devicemodel/hw/pci/virtio/virtio_rpmb.c @@ -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 diff --git a/devicemodel/include/virtio.h b/devicemodel/include/virtio.h index ff71b491b..ad0266663 100644 --- a/devicemodel/include/virtio.h +++ b/devicemodel/include/virtio.h @@ -507,6 +507,7 @@ struct virtio_base { pthread_mutex_t *mtx; /**< POSIX mutex, if any */ struct pci_vdev *dev; /**< PCI device instance */ uint64_t negotiated_caps; /**< negotiated capabilities */ + uint64_t device_caps; /**< device capabilities */ struct virtio_vq_info *queues; /**< one per nvq */ int curq; /**< current queue */ uint8_t status; /**< value from last status write */ @@ -552,7 +553,6 @@ struct virtio_ops { /**< to apply negotiated features */ void (*set_status)(void *, uint64_t); /**< called to set device status */ - uint64_t hv_caps; /**< hypervisor-provided capabilities */ }; #define VQ_ALLOC 0x01 /* set once we have a pfn */