Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] drm/virtgpu: Add PM support for suspend/resume
@ 2026-04-01  6:10 Morris Pan
  2026-04-01  6:24 ` Thomas Zimmermann
  2026-04-08 12:59 ` Dmitry Osipenko
  0 siblings, 2 replies; 6+ messages in thread
From: Morris Pan @ 2026-04-01  6:10 UTC (permalink / raw)
  To: airlied, kraxel, dmitry.osipenko
  Cc: srv_heupstream, gurchetansingh, olvaffe, maarten.lankhorst,
	mripard, tzimmermann, simona, dri-devel, virtualization,
	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 <morris.pan@mediatek.com>
---
 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)
+{
+	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);
+
+	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)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-30 22:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01  6:10 [PATCH] drm/virtgpu: Add PM support for suspend/resume Morris Pan
2026-04-01  6:24 ` Thomas Zimmermann
2026-04-08  7:04   ` Morris Pan (潘泰為)
2026-04-08 12:59 ` Dmitry Osipenko
2026-04-17  9:40   ` Morris Pan (潘泰為)
2026-04-30 22:49     ` Dmitry Osipenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox