From 0398498846ec7f90f105ede4850536d4351cd8dc Mon Sep 17 00:00:00 2001 From: Jian Jun Chen Date: Thu, 29 Mar 2018 12:29:00 +0800 Subject: [PATCH] dm/VBS-U: implement virtio_dev_error When the device has experienced an error from which it cannot re-cover, DEVICE_NEEDS_RESET is set to the device status register and a config change intr is sent to the guest driver. Signed-off-by: Jian Jun Chen Reviewed-by: Hao Li Reviewed-by: Zhao Yakui Acked-by: Eddie Dong --- devicemodel/hw/pci/virtio/virtio.c | 13 +++++++++++++ devicemodel/include/virtio.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/devicemodel/hw/pci/virtio/virtio.c b/devicemodel/hw/pci/virtio/virtio.c index 21506f595..b02f4851b 100644 --- a/devicemodel/hw/pci/virtio/virtio.c +++ b/devicemodel/hw/pci/virtio/virtio.c @@ -1008,6 +1008,19 @@ virtio_set_modern_bar(struct virtio_base *base, bool use_notify_pio) return rc; } +void +virtio_dev_error(struct virtio_base *base) +{ + if (base->negotiated_caps & VIRTIO_F_VERSION_1) { + /* see 2.1.2. if DRIVER_OK is set, need to send + * a device configuration change notification to the driver + */ + base->status |= VIRTIO_CR_STATUS_NEEDS_RESET; + if (base->status & VIRTIO_CR_STATUS_DRIVER_OK) + virtio_config_changed(base); + } +} + static struct cap_region { uint64_t cap_offset; /* offset of capability region */ int cap_size; /* size of capability region */ diff --git a/devicemodel/include/virtio.h b/devicemodel/include/virtio.h index c1574ec88..d35fc69d5 100644 --- a/devicemodel/include/virtio.h +++ b/devicemodel/include/virtio.h @@ -841,6 +841,19 @@ uint64_t virtio_pci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, void virtio_pci_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx, uint64_t offset, int size, uint64_t value); +/** + * @brief Indicate the device has experienced an error. + * + * This is called when the device has experienced an error from which it + * cannot re-cover. DEVICE_NEEDS_RESET is set to the device status register + * and a config change intr is sent to the guest driver. + * + * @param base Pointer to struct virtio_base. + * + * @return N/A + */ +void virtio_dev_error(struct virtio_base *base); + /** * @brief Set modern BAR (usually 4) to map PCI config registers. *