* [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend
@ 2022-11-16 16:40 Alex Deucher
2022-11-16 23:32 ` Guilherme G. Piccoli
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alex Deucher @ 2022-11-16 16:40 UTC (permalink / raw)
To: amd-gfx; +Cc: Alex Deucher
We can reuse the same buffers on resume.
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 56 +++++++++++++------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 0a8c30475dda..d9cb4c4b8289 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -172,6 +172,7 @@ void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
{
amdgpu_bo_free_kernel(&mem_ctx->shared_bo, &mem_ctx->shared_mc_addr,
&mem_ctx->shared_buf);
+ mem_ctx->shared_bo = NULL;
}
static void psp_free_shared_bufs(struct psp_context *psp)
@@ -182,6 +183,7 @@ static void psp_free_shared_bufs(struct psp_context *psp)
/* free TMR memory buffer */
pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
+ psp->tmr_bo = NULL;
/* free xgmi shared memory */
psp_ta_free_shared_buf(&psp->xgmi_context.context.mem_context);
@@ -743,37 +745,39 @@ static int psp_load_toc(struct psp_context *psp,
/* Set up Trusted Memory Region */
static int psp_tmr_init(struct psp_context *psp)
{
- int ret;
+ int ret = 0;
int tmr_size;
void *tmr_buf;
void **pptr;
- /*
- * According to HW engineer, they prefer the TMR address be "naturally
- * aligned" , e.g. the start address be an integer divide of TMR size.
- *
- * Note: this memory need be reserved till the driver
- * uninitializes.
- */
- tmr_size = PSP_TMR_SIZE(psp->adev);
-
- /* For ASICs support RLC autoload, psp will parse the toc
- * and calculate the total size of TMR needed */
- if (!amdgpu_sriov_vf(psp->adev) &&
- psp->toc.start_addr &&
- psp->toc.size_bytes &&
- psp->fw_pri_buf) {
- ret = psp_load_toc(psp, &tmr_size);
- if (ret) {
- DRM_ERROR("Failed to load toc\n");
- return ret;
+ if (!psp->tmr_bo) {
+ /*
+ * According to HW engineer, they prefer the TMR address be "naturally
+ * aligned" , e.g. the start address be an integer divide of TMR size.
+ *
+ * Note: this memory need be reserved till the driver
+ * uninitializes.
+ */
+ tmr_size = PSP_TMR_SIZE(psp->adev);
+
+ /* For ASICs support RLC autoload, psp will parse the toc
+ * and calculate the total size of TMR needed */
+ if (!amdgpu_sriov_vf(psp->adev) &&
+ psp->toc.start_addr &&
+ psp->toc.size_bytes &&
+ psp->fw_pri_buf) {
+ ret = psp_load_toc(psp, &tmr_size);
+ if (ret) {
+ DRM_ERROR("Failed to load toc\n");
+ return ret;
+ }
}
- }
- pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
- ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_ALIGNMENT,
- AMDGPU_GEM_DOMAIN_VRAM,
- &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
+ pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
+ ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_ALIGNMENT,
+ AMDGPU_GEM_DOMAIN_VRAM,
+ &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
+ }
return ret;
}
@@ -2701,8 +2705,6 @@ static int psp_suspend(void *handle)
}
out:
- psp_free_shared_bufs(psp);
-
return ret;
}
--
2.38.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend
2022-11-16 16:40 [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend Alex Deucher
@ 2022-11-16 23:32 ` Guilherme G. Piccoli
2022-11-18 16:01 ` Alex Deucher
2022-11-18 16:50 ` Christian König
2 siblings, 0 replies; 4+ messages in thread
From: Guilherme G. Piccoli @ 2022-11-16 23:32 UTC (permalink / raw)
To: amd-gfx; +Cc: alexander.deucher
Thanks for the fix, feel free to add my:
Tested-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend
2022-11-16 16:40 [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend Alex Deucher
2022-11-16 23:32 ` Guilherme G. Piccoli
@ 2022-11-18 16:01 ` Alex Deucher
2022-11-18 16:50 ` Christian König
2 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2022-11-18 16:01 UTC (permalink / raw)
To: Alex Deucher, Arunpravin, Christian Koenig; +Cc: amd-gfx
On Wed, Nov 16, 2022 at 11:40 AM Alex Deucher <alexander.deucher@amd.com> wrote:
>
> We can reuse the same buffers on resume.
>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Anyone want to give me an RB or AB?
Thanks,
Alex
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 56 +++++++++++++------------
> 1 file changed, 29 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> index 0a8c30475dda..d9cb4c4b8289 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> @@ -172,6 +172,7 @@ void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
> {
> amdgpu_bo_free_kernel(&mem_ctx->shared_bo, &mem_ctx->shared_mc_addr,
> &mem_ctx->shared_buf);
> + mem_ctx->shared_bo = NULL;
> }
>
> static void psp_free_shared_bufs(struct psp_context *psp)
> @@ -182,6 +183,7 @@ static void psp_free_shared_bufs(struct psp_context *psp)
> /* free TMR memory buffer */
> pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
> amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
> + psp->tmr_bo = NULL;
>
> /* free xgmi shared memory */
> psp_ta_free_shared_buf(&psp->xgmi_context.context.mem_context);
> @@ -743,37 +745,39 @@ static int psp_load_toc(struct psp_context *psp,
> /* Set up Trusted Memory Region */
> static int psp_tmr_init(struct psp_context *psp)
> {
> - int ret;
> + int ret = 0;
> int tmr_size;
> void *tmr_buf;
> void **pptr;
>
> - /*
> - * According to HW engineer, they prefer the TMR address be "naturally
> - * aligned" , e.g. the start address be an integer divide of TMR size.
> - *
> - * Note: this memory need be reserved till the driver
> - * uninitializes.
> - */
> - tmr_size = PSP_TMR_SIZE(psp->adev);
> -
> - /* For ASICs support RLC autoload, psp will parse the toc
> - * and calculate the total size of TMR needed */
> - if (!amdgpu_sriov_vf(psp->adev) &&
> - psp->toc.start_addr &&
> - psp->toc.size_bytes &&
> - psp->fw_pri_buf) {
> - ret = psp_load_toc(psp, &tmr_size);
> - if (ret) {
> - DRM_ERROR("Failed to load toc\n");
> - return ret;
> + if (!psp->tmr_bo) {
> + /*
> + * According to HW engineer, they prefer the TMR address be "naturally
> + * aligned" , e.g. the start address be an integer divide of TMR size.
> + *
> + * Note: this memory need be reserved till the driver
> + * uninitializes.
> + */
> + tmr_size = PSP_TMR_SIZE(psp->adev);
> +
> + /* For ASICs support RLC autoload, psp will parse the toc
> + * and calculate the total size of TMR needed */
> + if (!amdgpu_sriov_vf(psp->adev) &&
> + psp->toc.start_addr &&
> + psp->toc.size_bytes &&
> + psp->fw_pri_buf) {
> + ret = psp_load_toc(psp, &tmr_size);
> + if (ret) {
> + DRM_ERROR("Failed to load toc\n");
> + return ret;
> + }
> }
> - }
>
> - pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
> - ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_ALIGNMENT,
> - AMDGPU_GEM_DOMAIN_VRAM,
> - &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
> + pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
> + ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_ALIGNMENT,
> + AMDGPU_GEM_DOMAIN_VRAM,
> + &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
> + }
>
> return ret;
> }
> @@ -2701,8 +2705,6 @@ static int psp_suspend(void *handle)
> }
>
> out:
> - psp_free_shared_bufs(psp);
> -
> return ret;
> }
>
> --
> 2.38.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend
2022-11-16 16:40 [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend Alex Deucher
2022-11-16 23:32 ` Guilherme G. Piccoli
2022-11-18 16:01 ` Alex Deucher
@ 2022-11-18 16:50 ` Christian König
2 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2022-11-18 16:50 UTC (permalink / raw)
To: Alex Deucher, amd-gfx
Am 16.11.22 um 17:40 schrieb Alex Deucher:
> We can reuse the same buffers on resume.
>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
But I would like to ad the WARN_ON() to not free anything during suspend
on newer kernels as well.
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 56 +++++++++++++------------
> 1 file changed, 29 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> index 0a8c30475dda..d9cb4c4b8289 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> @@ -172,6 +172,7 @@ void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
> {
> amdgpu_bo_free_kernel(&mem_ctx->shared_bo, &mem_ctx->shared_mc_addr,
> &mem_ctx->shared_buf);
> + mem_ctx->shared_bo = NULL;
> }
>
> static void psp_free_shared_bufs(struct psp_context *psp)
> @@ -182,6 +183,7 @@ static void psp_free_shared_bufs(struct psp_context *psp)
> /* free TMR memory buffer */
> pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
> amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
> + psp->tmr_bo = NULL;
>
> /* free xgmi shared memory */
> psp_ta_free_shared_buf(&psp->xgmi_context.context.mem_context);
> @@ -743,37 +745,39 @@ static int psp_load_toc(struct psp_context *psp,
> /* Set up Trusted Memory Region */
> static int psp_tmr_init(struct psp_context *psp)
> {
> - int ret;
> + int ret = 0;
> int tmr_size;
> void *tmr_buf;
> void **pptr;
>
> - /*
> - * According to HW engineer, they prefer the TMR address be "naturally
> - * aligned" , e.g. the start address be an integer divide of TMR size.
> - *
> - * Note: this memory need be reserved till the driver
> - * uninitializes.
> - */
> - tmr_size = PSP_TMR_SIZE(psp->adev);
> -
> - /* For ASICs support RLC autoload, psp will parse the toc
> - * and calculate the total size of TMR needed */
> - if (!amdgpu_sriov_vf(psp->adev) &&
> - psp->toc.start_addr &&
> - psp->toc.size_bytes &&
> - psp->fw_pri_buf) {
> - ret = psp_load_toc(psp, &tmr_size);
> - if (ret) {
> - DRM_ERROR("Failed to load toc\n");
> - return ret;
> + if (!psp->tmr_bo) {
> + /*
> + * According to HW engineer, they prefer the TMR address be "naturally
> + * aligned" , e.g. the start address be an integer divide of TMR size.
> + *
> + * Note: this memory need be reserved till the driver
> + * uninitializes.
> + */
> + tmr_size = PSP_TMR_SIZE(psp->adev);
> +
> + /* For ASICs support RLC autoload, psp will parse the toc
> + * and calculate the total size of TMR needed */
> + if (!amdgpu_sriov_vf(psp->adev) &&
> + psp->toc.start_addr &&
> + psp->toc.size_bytes &&
> + psp->fw_pri_buf) {
> + ret = psp_load_toc(psp, &tmr_size);
> + if (ret) {
> + DRM_ERROR("Failed to load toc\n");
> + return ret;
> + }
> }
> - }
>
> - pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
> - ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_ALIGNMENT,
> - AMDGPU_GEM_DOMAIN_VRAM,
> - &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
> + pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
> + ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_ALIGNMENT,
> + AMDGPU_GEM_DOMAIN_VRAM,
> + &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
> + }
>
> return ret;
> }
> @@ -2701,8 +2705,6 @@ static int psp_suspend(void *handle)
> }
>
> out:
> - psp_free_shared_bufs(psp);
> -
> return ret;
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-18 16:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 16:40 [PATCH] drm/amdgpu/psp: don't free PSP buffers on suspend Alex Deucher
2022-11-16 23:32 ` Guilherme G. Piccoli
2022-11-18 16:01 ` Alex Deucher
2022-11-18 16:50 ` Christian König
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.