[PATCH v5 2/7] drm/amd: Add concept of running prepare() sequence for IP blocks

Christian König ckoenig.leichtzumerken at gmail.com
Mon Oct 9 08:46:50 UTC 2023


Am 06.10.23 um 20:50 schrieb Mario Limonciello:
> If any IP blocks allocate memory during their sw_fini() sequence

hw_fini instead of sw_fini? sw_fini should only be called on driver unload.

> this can cause the suspend to fail under memory pressure.  Introduce
> a new phase that IP blocks can use to allocate memory before suspend
> starts so that it can potentially be evicted into swap instead.
>
> Signed-off-by: Mario Limonciello <mario.limonciello at amd.com>

Apart from the commit message Reviewed-by: Christian König 
<christian.koenig at amd.com>.

Regards,
Christian.

> ---
> v4->v5:
>   * New patch
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
>   drivers/gpu/drm/amd/include/amd_shared.h   |  1 +
>   2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index cb334dc57c59..a362152cd0da 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -4348,7 +4348,7 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
>   int amdgpu_device_prepare(struct drm_device *dev)
>   {
>   	struct amdgpu_device *adev = drm_to_adev(dev);
> -	int r;
> +	int i, r;
>   
>   	if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
>   		return 0;
> @@ -4358,6 +4358,16 @@ int amdgpu_device_prepare(struct drm_device *dev)
>   	if (r)
>   		return r;
>   
> +	for (i = 0; i < adev->num_ip_blocks; i++) {
> +		if (!adev->ip_blocks[i].status.valid)
> +			continue;
> +		if (!adev->ip_blocks[i].version->funcs->prepare)
> +			continue;
> +		r = adev->ip_blocks[i].version->funcs->prepare((void *)adev);
> +		if (r)
> +			return r;
> +	}
> +
>   	return 0;
>   }
>   
> diff --git a/drivers/gpu/drm/amd/include/amd_shared.h b/drivers/gpu/drm/amd/include/amd_shared.h
> index ce75351204bb..1f831cb747e0 100644
> --- a/drivers/gpu/drm/amd/include/amd_shared.h
> +++ b/drivers/gpu/drm/amd/include/amd_shared.h
> @@ -299,6 +299,7 @@ struct amd_ip_funcs {
>   	int (*hw_init)(void *handle);
>   	int (*hw_fini)(void *handle);
>   	void (*late_fini)(void *handle);
> +	int (*prepare)(void *prepare);
>   	int (*suspend)(void *handle);
>   	int (*resume)(void *handle);
>   	bool (*is_idle)(void *handle);



More information about the amd-gfx mailing list