1 From 3acd6b15ab8ca78e01c5ab003e5c3a136722ea0d Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 6 Oct 2023 13:50:21 -0500
4 Subject: drm/amd: Add concept of running prepare_suspend() sequence for IP
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 From: Mario Limonciello <mario.limonciello@amd.com>
12 [ Upstream commit cb11ca3233aa3303dc11dca25977d2e7f24be00f ]
14 If any IP blocks allocate memory during their hw_fini() sequence
15 this can cause the suspend to fail under memory pressure. Introduce
16 a new phase that IP blocks can use to allocate memory before suspend
17 starts so that it can potentially be evicted into swap instead.
19 Reviewed-by: Christian König <christian.koenig@amd.com>
20 Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
21 Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
22 Stable-dep-of: ca299b4512d4 ("drm/amd: Flush GFXOFF requests in prepare stage")
23 Signed-off-by: Sasha Levin <sashal@kernel.org>
25 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
26 drivers/gpu/drm/amd/include/amd_shared.h | 1 +
27 2 files changed, 12 insertions(+), 1 deletion(-)
29 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
30 index 707c17641c757..4ebe42395708f 100644
31 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
32 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
33 @@ -4107,7 +4107,7 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
34 int amdgpu_device_prepare(struct drm_device *dev)
36 struct amdgpu_device *adev = drm_to_adev(dev);
40 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
42 @@ -4117,6 +4117,16 @@ int amdgpu_device_prepare(struct drm_device *dev)
46 + for (i = 0; i < adev->num_ip_blocks; i++) {
47 + if (!adev->ip_blocks[i].status.valid)
49 + if (!adev->ip_blocks[i].version->funcs->prepare_suspend)
51 + r = adev->ip_blocks[i].version->funcs->prepare_suspend((void *)adev);
59 diff --git a/drivers/gpu/drm/amd/include/amd_shared.h b/drivers/gpu/drm/amd/include/amd_shared.h
60 index abe829bbd54af..a9880fc531955 100644
61 --- a/drivers/gpu/drm/amd/include/amd_shared.h
62 +++ b/drivers/gpu/drm/amd/include/amd_shared.h
63 @@ -295,6 +295,7 @@ struct amd_ip_funcs {
64 int (*hw_init)(void *handle);
65 int (*hw_fini)(void *handle);
66 void (*late_fini)(void *handle);
67 + int (*prepare_suspend)(void *handle);
68 int (*suspend)(void *handle);
69 int (*resume)(void *handle);
70 bool (*is_idle)(void *handle);