Virtio devices are initialized prior to plugging them into a bus. However, other initializations (such as host_features) don't occur until after the device is plugged into the bus. If a device needs to modify it's configuration based on host_features, then it needs to be notified when the bus is attached and host_features is available for use.
This patch extends struct VirtioDeviceClass to add a bus_plugged() method. If implemented by a device, it will be called after the device is attached to a bus. Signed-off-by: Jesse Larrew <jlar...@linux.vnet.ibm.com> --- hw/virtio/virtio.c | 3 +++ include/hw/virtio/virtio.h | 1 + 2 files changed, 4 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 8176c14..96735fa 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1114,6 +1114,9 @@ static int virtio_device_init(DeviceState *qdev) return -1; } virtio_bus_plug_device(vdev); + if (k->bus_plugged) { + k->bus_plugged(vdev); + } return 0; } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 6afdfd8..31fad30 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -156,6 +156,7 @@ typedef struct VirtioDeviceClass { * must mask in frontend instead. */ void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask); + void (*bus_plugged)(VirtIODevice *vdev); } VirtioDeviceClass; void virtio_init(VirtIODevice *vdev, const char *name, -- 1.7.11.7