Add features property to virtio. This makes it possible to e.g. define machine without indirect buffer support, which is required for 0.10 compatibility. or without hardware checksum support, which is required for 0.11 compatibility.
Signed-off-by: Michael S. Tsirkin <m...@redhat.com> --- Here's what I came up with for solving the problem of differences between features in virtio between 0.12 and 0.11 (applies on to of guest_features patch). Comments? Gerd, what do you think? hw/virtio-pci.c | 29 +++++++++++++++++++++++++++-- hw/virtio.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 80bc645..43b02b6 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -90,6 +90,7 @@ typedef struct { uint32_t addr; uint32_t class_code; uint32_t nvectors; + uint32_t host_features; DriveInfo *dinfo; NICConf nic; } VirtIOPCIProxy; @@ -235,8 +236,7 @@ static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr) switch (addr) { case VIRTIO_PCI_HOST_FEATURES: - ret = vdev->get_features(vdev); - ret |= vdev->binding->get_features(proxy); + ret = vdev->host_features; break; case VIRTIO_PCI_GUEST_FEATURES: ret = vdev->guest_features; @@ -398,6 +398,8 @@ static const VirtIOBindings virtio_pci_bindings = { .get_features = virtio_pci_get_features, }; +#define VIRTIO_PCI_NO_FEATURES 0xffffffff + static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, uint16_t vendor, uint16_t device, uint16_t class_code, uint8_t pif) @@ -442,6 +444,18 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, virtio_map); virtio_bind_device(vdev, &virtio_pci_bindings, proxy); + if (proxy->host_features == VIRTIO_PCI_NO_FEATURES) + proxy->host_features = vdev->get_features(vdev) | + vdev->binding->get_features(proxy); + else if (proxy->host_features & ~vdev->get_features(vdev) & + ~vdev->binding->get_features(proxy)) { + fprintf(stderr, "Requested host features 0x%x, " + "but supported features are transport:0x%x device:0x%x\n", + proxy->host_features, + vdev->binding->get_features(proxy), + vdev->get_features(vdev)); + exit(1); + } } static int virtio_blk_init_pci(PCIDevice *pci_dev) @@ -561,6 +575,8 @@ static PCIDeviceInfo virtio_info[] = { DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo), DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), + DEFINE_PROP_HEX32("features", VirtIOPCIProxy, host_features, + VIRTIO_PCI_NO_FEATURES), DEFINE_PROP_END_OF_LIST(), }, .qdev.reset = virtio_pci_reset, @@ -571,6 +587,8 @@ static PCIDeviceInfo virtio_info[] = { .exit = virtio_net_exit_pci, .qdev.props = (Property[]) { DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), + DEFINE_PROP_HEX32("features", VirtIOPCIProxy, host_features, + 0xffffffff), DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic), DEFINE_PROP_END_OF_LIST(), }, @@ -582,6 +600,8 @@ static PCIDeviceInfo virtio_info[] = { .exit = virtio_exit_pci, .qdev.props = (Property[]) { DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), + DEFINE_PROP_HEX32("features", VirtIOPCIProxy, host_features, + VIRTIO_PCI_NO_FEATURES), DEFINE_PROP_END_OF_LIST(), }, .qdev.reset = virtio_pci_reset, @@ -590,6 +610,11 @@ static PCIDeviceInfo virtio_info[] = { .qdev.size = sizeof(VirtIOPCIProxy), .init = virtio_balloon_init_pci, .exit = virtio_exit_pci, + .qdev.props = (Property[]) { + DEFINE_PROP_HEX32("features", VirtIOPCIProxy, host_features, + VIRTIO_PCI_NO_FEATURES), + DEFINE_PROP_END_OF_LIST(), + }, .qdev.reset = virtio_pci_reset, },{ /* end of list */ diff --git a/hw/virtio.h b/hw/virtio.h index 85ef171..73f784f 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -101,6 +101,7 @@ struct VirtIODevice uint8_t isr; uint16_t queue_sel; uint32_t guest_features; + uint32_t host_features; size_t config_len; void *config; uint16_t config_vector; -- 1.6.6.rc1.43.gf55cc