From 383bc5100af30bf35580f5c7ef7f9d700593a9ca Mon Sep 17 00:00:00 2001 From: Shuo Liu Date: Sun, 11 Feb 2018 17:01:05 +0800 Subject: [PATCH] virtio: config changed notify interface Some virtio PCI devices can change the device configuration state, as reflected in the device-specific configuration region of the device. In this case: * If MSI-X capability is disabled: 1. Set the second lower bit of the ISR Status field for the device 2. Send the appropriate PCI interrupt for the device. * If MSI-X capability is enabled: 1. If config_msix_vector is not NO_VECTOR, request the appropriate MSI-X interrupt message for the device, config_msix_vector sets the MSI-X Table entry number. A single interrupt MAY indicate both that one or more virtqueue has been used and that the configuration space has changed. Signed-off-by: Shuo Liu Reviewed-by: Hao Li --- include/virtio.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/include/virtio.h b/include/virtio.h index 5ed442a2d..676a831c9 100644 --- a/include/virtio.h +++ b/include/virtio.h @@ -294,7 +294,7 @@ struct vring_used { */ #define VIRTIO_CR_ISR_QUEUES 0x01 /* re-scan queues */ -#define VIRTIO_CR_ISR_CONF_CHANGED 0x80 +#define VIRTIO_CR_ISR_CONF_CHANGED 0x02 /* configuration changed */ #define VIRTIO_MSI_NO_VECTOR 0xFFFF @@ -524,6 +524,30 @@ vq_interrupt(struct virtio_base *vb, struct virtio_vq_info *vq) } } +/** + * @brief Deliver an config changed interrupt to guest. + * + * MSI-X or a generic MSI interrupt with config changed event. + * + * @param vb Pointer to struct virtio_base. + * + * @return NULL. + */ +static inline void +virtio_config_changed(struct virtio_base *vb) +{ + + if (pci_msix_enabled(vb->dev)) + pci_generate_msix(vb->dev, vb->msix_cfg_idx); + else { + VIRTIO_BASE_LOCK(vb); + vb->isr |= VIRTIO_CR_ISR_CONF_CHANGED; + pci_generate_msi(vb->dev, 0); + pci_lintr_assert(vb->dev); + VIRTIO_BASE_UNLOCK(vb); + } +} + struct iovec; /**