@@ -1651,6 +1651,11 @@ static void virtio_pci_common_write(void *opaque, hwaddr addr,
proxy->vqs[vdev->queue_sel].enabled = 0;
}
break;
+ case VIRTIO_PCI_COMMON_F_MODE:
+ virtio_pci_freeze_mode_t freeze_mode = (virtio_pci_freeze_mode_t)val;
+ if ((1 << freeze_mode) & VIRTIO_PCI_FREEZE_MODE_MASK)
+ vdev->freeze_mode = freeze_mode;
+ break;
default:
break;
}
@@ -3201,6 +3201,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size)
vdev->vhost_started = false;
vdev->device_id = device_id;
vdev->status = 0;
+ vdev->freeze_mode = VIRTIO_PCI_FREEZE_MODE_UNFREEZE;
qatomic_set(&vdev->isr, 0);
vdev->queue_sel = 0;
vdev->config_vector = VIRTIO_NO_VECTOR;
@@ -21,6 +21,7 @@
#include "qemu/event_notifier.h"
#include "standard-headers/linux/virtio_config.h"
#include "standard-headers/linux/virtio_ring.h"
+#include "standard-headers/linux/virtio_pci.h"
#include "qom/object.h"
/*
@@ -106,6 +107,7 @@ struct VirtIODevice
DeviceState parent_obj;
const char *name;
uint8_t status;
+ virtio_pci_freeze_mode_t freeze_mode;
uint8_t isr;
uint16_t queue_sel;
/**
When guest vm do S3, Qemu will reset and clear some things of virtio devices, but guest can't aware that, so that may cause some problems. For excample, Qemu calls virtio_reset->virtio_gpu_gl_reset, that will destroy render resources of virtio-gpu. As a result, after guest resume, the display can't come back and we only saw a black screen. Due to guest can't re-create all the resources, so we need to let Qemu not to destroy them when S3. For above purpose, this patch add a new parameter named freeze_mode to struct VirtIODevice, and when guest suspends, guest can write freeze_mode to be FREEZE_S3, so that virtio devices can change their reset behavior on Qemu side according to that mode. Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com> --- hw/virtio/virtio-pci.c | 5 +++++ hw/virtio/virtio.c | 1 + include/hw/virtio/virtio.h | 2 ++ 3 files changed, 8 insertions(+)