]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/ttm: add new api ttm_device_prepare_hibernation()
authorSamuel Zhang <guoqing.zhang@amd.com>
Thu, 10 Jul 2025 06:23:09 +0000 (14:23 +0800)
committerMario Limonciello <mario.limonciello@amd.com>
Thu, 10 Jul 2025 15:49:44 +0000 (10:49 -0500)
This new api is used for hibernation to move GTT BOs to shmem after
VRAM eviction. shmem will be flushed to swap disk later to reduce
the system memory usage for hibernation.

Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20250710062313.3226149-2-guoqing.zhang@amd.com
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
drivers/gpu/drm/ttm/ttm_device.c
include/drm/ttm/ttm_device.h

index 816e2cba6016e82479d82a68932fdc3fc5e7fc13..c3e2fcbdd2cc6fa2935178e15186f41118b50f9d 100644 (file)
@@ -125,6 +125,28 @@ out:
        return ret;
 }
 
+/**
+ * ttm_device_prepare_hibernation - move GTT BOs to shmem for hibernation.
+ *
+ * @bdev: A pointer to a struct ttm_device to prepare hibernation for.
+ *
+ * Return: 0 on success, negative number on failure.
+ */
+int ttm_device_prepare_hibernation(struct ttm_device *bdev)
+{
+       struct ttm_operation_ctx ctx = {
+               .interruptible = false,
+               .no_wait_gpu = false,
+       };
+       int ret;
+
+       do {
+               ret = ttm_device_swapout(bdev, &ctx, GFP_KERNEL);
+       } while (ret > 0);
+       return ret;
+}
+EXPORT_SYMBOL(ttm_device_prepare_hibernation);
+
 /*
  * A buffer object shrink method that tries to swap out the first
  * buffer object on the global::swap_lru list.
index 39b8636b18451283912528447ee177a9949e2044..592b5f80285993412f68d3accbd61f3415b71cc6 100644 (file)
@@ -272,6 +272,7 @@ struct ttm_device {
 int ttm_global_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags);
 int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
                       gfp_t gfp_flags);
+int ttm_device_prepare_hibernation(struct ttm_device *bdev);
 
 static inline struct ttm_resource_manager *
 ttm_manager_type(struct ttm_device *bdev, int mem_type)