Hi
Am 01.04.26 um 08:10 schrieb Morris Pan:
Add freeze/restore callbacks to handle system suspend/resume.
During freeze, delete virtqueues and reset device.
During restore, reinitialize virtqueues and mark device ready.
Signed-off-by: Morris Pan <[email protected]>
---
drivers/gpu/drm/virtio/virtgpu_drv.c | 40 +++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c
b/drivers/gpu/drm/virtio/virtgpu_drv.c
index a5ce96fb8a1d..fbca0a82958c 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -145,6 +145,40 @@ static void virtio_gpu_config_changed(struct virtio_device
*vdev)
schedule_work(&vgdev->config_changed_work);
}
+#ifdef CONFIG_PM_SLEEP
+static int virtgpu_freeze(struct virtio_device *vdev)
+{
I think you first need to call drm_mode_config_helper_suspend() [1] to
stop DRM and save the current state.
[1]
https://elixir.bootlin.com/linux/v6.19.10/source/drivers/gpu/drm/drm_modeset_helper.c#L179
+ vdev->config->del_vqs(vdev);
+ virtio_reset_device(vdev);
+
+ return 0;
+}
+
+static int virtgpu_restore(struct virtio_device *vdev)
+{
+ int ret;
+ struct virtqueue *vqs[2];
+ struct drm_device *dev = vdev->priv;
+ struct virtio_gpu_device *vgdev = dev->dev_private;
+ struct virtqueue_info vqs_info[] = {
+ { "control", virtio_gpu_ctrl_ack },
+ { "cursor", virtio_gpu_cursor_ack },
+ };
+
+ ret = virtio_find_vqs(vdev, 2, vqs, vqs_info, NULL);
+ if (ret) {
+ DRM_ERROR("failed to find virtio queues\n");
+ return ret;
+ }
+
+ vgdev->ctrlq.vq = vqs[0];
+ vgdev->cursorq.vq = vqs[1];
+ virtio_device_ready(vdev);
And here you have to call drm_mode_config_helper_resume() [2] to restore
the DRM state from before the freeze.
[2]
https://elixir.bootlin.com/linux/v6.19.10/source/drivers/gpu/drm/drm_modeset_helper.c#L227
Best regards
Thomas
+
+ return 0;
+}
+#endif
+
static struct virtio_device_id id_table[] = {
{ VIRTIO_ID_GPU, VIRTIO_DEV_ANY_ID },
{ 0 },
@@ -172,7 +206,11 @@ static struct virtio_driver virtio_gpu_driver = {
.probe = virtio_gpu_probe,
.remove = virtio_gpu_remove,
.shutdown = virtio_gpu_shutdown,
- .config_changed = virtio_gpu_config_changed
+ .config_changed = virtio_gpu_config_changed,
+#ifdef CONFIG_PM_SLEEP
+ .freeze = virtgpu_freeze,
+ .restore = virtgpu_restore
+#endif
};
static int __init virtio_gpu_driver_init(void)
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)