<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Calibri;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - AMD Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
Reviewed-by: Wenjing Liu <wenjing.liu@amd.com></div>
<div id="appendonsend"></div>
<hr style="display: inline-block; width: 98%;">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b>From:</b> SHANMUGAM, SRINIVASAN <SRINIVASAN.SHANMUGAM@amd.com><br>
<b>Sent:</b> Thursday, July 24, 2025 11:45 PM<br>
<b>To:</b> Pillai, Aurabindo <Aurabindo.Pillai@amd.com>; Liu, Wenjing <Wenjing.Liu@amd.com>; Strauss, Michael <Michael.Strauss@amd.com>; Hung, Alex <Alex.Hung@amd.com>; Shen, George <George.Shen@amd.com><br>
<b>Cc:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; SHANMUGAM, SRINIVASAN <SRINIVASAN.SHANMUGAM@amd.com>; Lin, Wayne <Wayne.Lin@amd.com>; Lee, Alvin <Alvin.Lee2@amd.com>; Wu, Ray <Ray.Wu@amd.com>; Wentland, Harry <Harry.Wentland@amd.com>;
 Chung, ChiaHsuan (Tom) <ChiaHsuan.Chung@amd.com>; Li, Roman <Roman.Li@amd.com><br>
<b>Subject:</b> [PATCH v4] drm/amd/display: Reduce Stack Usage by moving 'audio_output' into 'stream_res' v4
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-size: 11pt;">The function `dp_retrain_link_dp_test` currently allocates a large<br>
audio_output array on the stack, causing the stack frame size to exceed<br>
the compiler limit (1080 bytes > 1024 bytes).<br>
<br>
This change prevents stack overflow issues:<br>
amdgpu/../display/dc/link/accessories/link_dp_cts.c:65:13: warning: stack frame size (1080) exceeds limit (1024) in 'dp_retrain_link_dp_test' [-Wframe-larger-than]<br>
static void dp_retrain_link_dp_test(struct dc_link *link,<br>
<br>
v2: Move audio-related data like `audio_output` is kept "per pipe" to<br>
    manage the audio for that specific display pipeline/display output path<br>
    (stream). (Wenjing)<br>
<br>
v3: Update in all the places where `build_audio_output` is currently<br>
    called with a separate audio_output variable on the stack & wherever<br>
    `audio_output` is passed to other functions<br>
    `dce110_apply_single_controller_ctx_to_hw()` &<br>
    `dce110_setup_audio_dto()` (like `az_configure`, `wall_dto_setup`)<br>
    replace with usage of `pipe_ctx->stream_res.audio_output`<br>
    to centralize audio data per pipe.<br>
<br>
v4: Remove empty lines before `build_audio_output`. (Alex)<br>
<br>
'Fixes: 9437059b4bfb ("drm/amd/display: Fix Link Override Sequencing When<br>
Switching Between DIO/HPO")'<br>
Cc: Wayne Lin <wayne.lin@amd.com><br>
Cc: George Shen <george.shen@amd.com><br>
Cc: Michael Strauss <michael.strauss@amd.com><br>
Cc: Alvin Lee <Alvin.Lee2@amd.com><br>
Cc: Ray Wu <ray.wu@amd.com><br>
Cc: Wenjing Liu <wenjing.liu@amd.com><br>
Cc: Harry Wentland <harry.wentland@amd.com><br>
Cc: Tom Chung <chiahsuan.chung@amd.com><br>
Cc: Roman Li <roman.li@amd.com><br>
Cc: Alex Hung <alex.hung@amd.com><br>
Cc: Aurabindo Pillai <aurabindo.pillai@amd.com><br>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com><br>
---<br>
 .../amd/display/dc/hwss/dce110/dce110_hwseq.c | 32 ++++++++-----------<br>
 .../gpu/drm/amd/display/dc/inc/core_types.h   |  5 +--<br>
 .../display/dc/link/accessories/link_dp_cts.c | 12 +++----<br>
 .../dc/resource/dcn31/dcn31_resource.c        |  5 ++-<br>
 .../dc/resource/dcn31/dcn31_resource.h        |  3 +-<br>
 5 files changed, 26 insertions(+), 31 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c b/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c<br>
index 4ea13d0bf815..c69194e04ff9 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c<br>
@@ -1600,19 +1600,17 @@ enum dc_status dce110_apply_single_controller_ctx_to_hw(<br>
         }<br>
 <br>
         if (pipe_ctx->stream_res.audio != NULL) {<br>
-               struct audio_output audio_output = {0};<br>
+               build_audio_output(context, pipe_ctx, &pipe_ctx->stream_res.audio_output);<br>
 <br>
-               build_audio_output(context, pipe_ctx, &audio_output);<br>
-<br>
-               link_hwss->setup_audio_output(pipe_ctx, &audio_output,<br>
+               link_hwss->setup_audio_output(pipe_ctx, &pipe_ctx->stream_res.audio_output,<br>
                                 pipe_ctx->stream_res.audio->inst);<br>
 <br>
                 pipe_ctx->stream_res.audio->funcs->az_configure(<br>
                                 pipe_ctx->stream_res.audio,<br>
                                 pipe_ctx->stream->signal,<br>
-                               &audio_output.crtc_info,<br>
+                               &pipe_ctx->stream_res.audio_output.crtc_info,<br>
                                 &pipe_ctx->stream->audio_info,<br>
-                               &audio_output.dp_link_info);<br>
+                               &pipe_ctx->stream_res.audio_output.dp_link_info);<br>
 <br>
                 if (dc->config.disable_hbr_audio_dp2)<br>
                         if (pipe_ctx->stream_res.audio->funcs->az_disable_hbr_audio &&<br>
@@ -2386,9 +2384,7 @@ static void dce110_setup_audio_dto(<br>
                 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)<br>
                         continue;<br>
                 if (pipe_ctx->stream_res.audio != NULL) {<br>
-                       struct audio_output audio_output;<br>
-<br>
-                       build_audio_output(context, pipe_ctx, &audio_output);<br>
+                       build_audio_output(context, pipe_ctx, &pipe_ctx->stream_res.audio_output);<br>
 <br>
                         if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {<br>
                                 struct dtbclk_dto_params dto_params = {0};<br>
@@ -2399,14 +2395,14 @@ static void dce110_setup_audio_dto(<br>
                                 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(<br>
                                                 pipe_ctx->stream_res.audio,<br>
                                                 pipe_ctx->stream->signal,<br>
-                                               &audio_output.crtc_info,<br>
-                                               &audio_output.pll_info);<br>
+                                               &pipe_ctx->stream_res.audio_output.crtc_info,<br>
+                                               &pipe_ctx->stream_res.audio_output.pll_info);<br>
                         } else<br>
                                 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(<br>
                                         pipe_ctx->stream_res.audio,<br>
                                         pipe_ctx->stream->signal,<br>
-                                       &audio_output.crtc_info,<br>
-                                       &audio_output.pll_info);<br>
+                                       &pipe_ctx->stream_res.audio_output.crtc_info,<br>
+                                       &pipe_ctx->stream_res.audio_output.pll_info);<br>
                         break;<br>
                 }<br>
         }<br>
@@ -2426,15 +2422,15 @@ static void dce110_setup_audio_dto(<br>
                                 continue;<br>
 <br>
                         if (pipe_ctx->stream_res.audio != NULL) {<br>
-                               struct audio_output audio_output = {0};<br>
-<br>
-                               build_audio_output(context, pipe_ctx, &audio_output);<br>
+                               build_audio_output(context,<br>
+                                                  pipe_ctx,<br>
+                                                  &pipe_ctx->stream_res.audio_output);<br>
 <br>
                                 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(<br>
                                         pipe_ctx->stream_res.audio,<br>
                                         pipe_ctx->stream->signal,<br>
-                                       &audio_output.crtc_info,<br>
-                                       &audio_output.pll_info);<br>
+                                       &pipe_ctx->stream_res.audio_output.crtc_info,<br>
+                                       &pipe_ctx->stream_res.audio_output.pll_info);<br>
                                 break;<br>
                         }<br>
                 }<br>
diff --git a/drivers/gpu/drm/amd/display/dc/inc/core_types.h b/drivers/gpu/drm/amd/display/dc/inc/core_types.h<br>
index f0d7185153b2..f896cce87b8d 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/inc/core_types.h<br>
+++ b/drivers/gpu/drm/amd/display/dc/inc/core_types.h<br>
@@ -228,8 +228,7 @@ struct resource_funcs {<br>
         enum dc_status (*update_dc_state_for_encoder_switch)(struct dc_link *link,<br>
                 struct dc_link_settings *link_setting,<br>
                 uint8_t pipe_count,<br>
-               struct pipe_ctx *pipes,<br>
-               struct audio_output *audio_output);<br>
+               struct pipe_ctx *pipes);<br>
 };<br>
 <br>
 struct audio_support{<br>
@@ -361,6 +360,8 @@ struct stream_resource {<br>
         uint8_t gsl_group;<br>
 <br>
         struct test_pattern_params test_pattern_params;<br>
+<br>
+       struct audio_output audio_output;<br>
 };<br>
 <br>
 struct plane_resource {<br>
diff --git a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c<br>
index 2956c2b3ad1a..b12d61701d4d 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c<br>
@@ -75,7 +75,6 @@ static void dp_retrain_link_dp_test(struct dc_link *link,<br>
         bool is_hpo_acquired;<br>
         uint8_t count;<br>
         int i;<br>
-       struct audio_output audio_output[MAX_PIPES];<br>
 <br>
         needs_divider_update = (link->dc->link_srv->dp_get_encoding_format(link_setting) !=<br>
         link->dc->link_srv->dp_get_encoding_format((const struct dc_link_settings *) &link->cur_link_settings));<br>
@@ -99,7 +98,7 @@ static void dp_retrain_link_dp_test(struct dc_link *link,<br>
         if (needs_divider_update && link->dc->res_pool->funcs->update_dc_state_for_encoder_switch) {<br>
                 link->dc->res_pool->funcs->update_dc_state_for_encoder_switch(link,<br>
                                 link_setting, count,<br>
-                               *pipes, &audio_output[0]);<br>
+                               *pipes);<br>
                 for (i = 0; i < count; i++) {<br>
                         pipes[i]->clock_source->funcs->program_pix_clk(<br>
                                         pipes[i]->clock_source,<br>
@@ -111,15 +110,16 @@ static void dp_retrain_link_dp_test(struct dc_link *link,<br>
                                 const struct link_hwss *link_hwss = get_link_hwss(<br>
                                         link, &pipes[i]->link_res);<br>
 <br>
-                               link_hwss->setup_audio_output(pipes[i], &audio_output[i],<br>
-                                               pipes[i]->stream_res.audio->inst);<br>
+                               link_hwss->setup_audio_output(pipes[i],<br>
+                                                             &pipes[i]->stream_res.audio_output,<br>
+                                                             pipes[i]->stream_res.audio->inst);<br>
 <br>
                                 pipes[i]->stream_res.audio->funcs->az_configure(<br>
                                                 pipes[i]->stream_res.audio,<br>
                                                 pipes[i]->stream->signal,<br>
-                                               &audio_output[i].crtc_info,<br>
+                                               &pipes[i]->stream_res.audio_output.crtc_info,<br>
                                                 &pipes[i]->stream->audio_info,<br>
-                                               &audio_output[i].dp_link_info);<br>
+                                               &pipes[i]->stream_res.audio_output.dp_link_info);<br>
 <br>
                                 if (link->dc->config.disable_hbr_audio_dp2 &&<br>
                                                 pipes[i]->stream_res.audio->funcs->az_disable_hbr_audio &&<br>
diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c<br>
index 3ed7f50554e2..ca17e5d8fdc2 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c<br>
@@ -2239,8 +2239,7 @@ struct resource_pool *dcn31_create_resource_pool(<br>
 enum dc_status dcn31_update_dc_state_for_encoder_switch(struct dc_link *link,<br>
         struct dc_link_settings *link_setting,<br>
         uint8_t pipe_count,<br>
-       struct pipe_ctx *pipes,<br>
-       struct audio_output *audio_output)<br>
+       struct pipe_ctx *pipes)<br>
 {<br>
         struct dc_state *state = link->dc->current_state;<br>
         int i;<br>
@@ -2255,7 +2254,7 @@ enum dc_status dcn31_update_dc_state_for_encoder_switch(struct dc_link *link,<br>
 <br>
                 // Setup audio<br>
                 if (pipes[i].stream_res.audio != NULL)<br>
-                       build_audio_output(state, &pipes[i], &audio_output[i]);<br>
+                       build_audio_output(state, &pipes[i], &pipes[i].stream_res.audio_output);<br>
         }<br>
 #else<br>
         /* This DCN requires rate divider updates and audio reprogramming to allow DP1<-->DP2 link rate switching,<br>
diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.h b/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.h<br>
index c32c85ef0ba4..7e8fde65528f 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.h<br>
+++ b/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.h<br>
@@ -69,8 +69,7 @@ unsigned int dcn31_get_det_buffer_size(<br>
 enum dc_status dcn31_update_dc_state_for_encoder_switch(struct dc_link *link,<br>
         struct dc_link_settings *link_setting,<br>
         uint8_t pipe_count,<br>
-       struct pipe_ctx *pipes,<br>
-       struct audio_output *audio_output);<br>
+       struct pipe_ctx *pipes);<br>
 <br>
 /*temp: B0 specific before switch to dcn313 headers*/<br>
 #ifndef regPHYPLLF_PIXCLK_RESYNC_CNTL<br>
--<br>
2.34.1<br>
<br>
</div>
</div>
</body>
</html>