drm/amd/display: remove code duplication on dcn401
Subsystems (3)
cover drm/amd/display: remove code duplication on dcn401
Hi,
I've been examining dcn401 code to figure out what is causing a wrong cursor gamma on HDR issue reported in [1], and I found unnecessary code duplications during this inspection. I don't have the HW, so I'd appreciate if someone can validate this series (if it makes sense to you ofc).
This series basically adds some hooks to dcn20 base functions that are usually used in other hw versions and reuses those functions on dcn401 so that we can reduce many lines of code and also increase the coverage of bug fixes by avoiding the kind of issue of [2]. Better for debugging and maintainability too.
[1] https://gitlab.freedesktop.org/drm/amd/-/issues/4176
[2] https://lore.kernel.org/amd-gfx/[email protected]/
Melissa Wen (5):
drm/amd/display: add hook for program_tg
drm/amd/display: hook up program_tg for dcn401 drm/amd/display: remove duplicated program_front_end_for_ctx code drm/amd/display: remove duplicated post_unlock_program_front_end code
on dcn401
drm/amd/display: remove duplicated program_pipe code on dcn401
.../amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 40 +- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.c | 436 +----------------- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.h | 10 +- .../amd/display/dc/hwss/dcn401/dcn401_init.c | 5 +- .../drm/amd/display/dc/hwss/hw_sequencer.h | 4 + 5 files changed, 45 insertions(+), 450 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/5 drm/amd/display: add hook for program_tg
The only actual difference between dcn20_program_pipe and dcn401_program_pipe is the way they program global sync. Create a hook to enable hw-family function calls, so that we can reuse dcn20_program_pipe, avoid code duplication and prevent future partial fixes for the same portion of code.
--- .../gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 11 ++++++++--- drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c +8 -3
@@ -1925,9 +1925,14 @@ static void dcn20_program_pipe( }/* Only update TG on top pipe */ -if (pipe_ctx->update_flags.bits.global_sync && !pipe_ctx->top_pipe - && !pipe_ctx->prev_odm_pipe) -dcn20_program_tg (dc, pipe_ctx, context, hws); +if (pipe_ctx->update_flags.bits.global_sync && + !pipe_ctx->top_pipe && + !pipe_ctx->prev_odm_pipe) { +if (dc->hwss.program_tg) + dc->hwss.program_tg (dc, pipe_ctx, context, hws); +else +dcn20_program_tg (dc, pipe_ctx, context, hws); + }if (pipe_ctx->update_flags.bits.odm) hws->funcs.update_odm (dc, context, pipe_ctx);
drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h +4 -0
@@ -467,6 +467,10 @@ struct hw_sequencer_funcs {struct dc_state *new_state, struct pipe_ctx *old_pipe, struct pipe_ctx *new_pipe); +void (*program_tg)(struct dc *dc, +struct pipe_ctx *pipe_ctx, +struct dc_state *context, +struct dce_hwseq *hws);void (*enable_plane)(struct dc *dc,struct pipe_ctx *pipe_ctx,struct dc_state *context);
Signature · 1 line
2.47.2
PATCH 2/5 drm/amd/display: hook up program_tg for dcn401
In reply to Melissa WenIn this version, the global sync programming differs and needs an specific function call slightly different from the commonly used dcn20_program_tg. Hook up dcn401_program_tg only for dcn401.
--- .../gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c | 9 ++++----- .../gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.h | 4 ++++ drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_init.c | 1 + 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c +4 -5
@@ -2191,11 +2191,10 @@ static unsigned int dcn401_calculate_vready_offset_for_group(struct pipe_ctx *pireturn vready_offset; } -static void dcn401_program_tg ( -struct dc *dc, -struct pipe_ctx *pipe_ctx, -struct dc_state *context, -struct dce_hwseq *hws) +void dcn401_program_tg (struct dc *dc, +struct pipe_ctx *pipe_ctx, +struct dc_state *context, +struct dce_hwseq *hws) { pipe_ctx->stream_res.tg->funcs->program_global_sync( pipe_ctx->stream_res.tg,
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.h +4 -0
@@ -93,6 +93,10 @@ void dcn401_reset_back_end_for_pipe(void dcn401_reset_hw_ctx_wrap (struct dc *dc,struct dc_state *context); +void dcn401_program_tg (struct dc *dc, +struct pipe_ctx *pipe_ctx, +struct dc_state *context, +struct dce_hwseq *hws); void dcn401_program_pipe( struct dc *dc, struct pipe_ctx *pipe_ctx,
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_init.c +1 -0
@@ -101,6 +101,7 @@ static const struct hw_sequencer_funcs dcn401_funcs = { .program_outstanding_updates = dcn401_program_outstanding_updates, .wait_for_all_pending_updates = dcn30_wait_for_all_pending_updates, .detect_pipe_changes = dcn401_detect_pipe_changes, + .program_tg = dcn401_program_tg, .enable_plane = dcn20_enable_plane, .update_dchubp_dpp = dcn20_update_dchubp_dpp, .post_unlock_reset_opp = dcn20_post_unlock_reset_opp,
Signature · 1 line
2.47.2
PATCH 3/5 drm/amd/display: remove duplicated program_front_end_for_ctx code
In reply to Melissa WenAdd detect_pipe_changes hook to dcn20_program_front_end_for_ctx and hook the later to program_front_end_for_ctx in dcn401, then remove dcn401_program_front_end_for_ctx duplicated code.
--- .../amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 13 +- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.c | 166 ------------------ .../amd/display/dc/hwss/dcn401/dcn401_hwseq.h | 1 - .../amd/display/dc/hwss/dcn401/dcn401_init.c | 2 +- 4 files changed, 11 insertions(+), 171 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c +10 -3
@@ -2082,9 +2082,16 @@ void dcn20_program_front_end_for_ctx( }/* Set pipe update flags and lock pipes */ -for (i =0 ; i < dc->res_pool->pipe_count; i++) -dcn20_detect_pipe_changes (dc->current_state, context, &dc->current_state->res_ctx.pipe_ctx[i], - &context->res_ctx.pipe_ctx[i]); +for (i =0 ; i < dc->res_pool->pipe_count; i++) { +if (dc->hwss.detect_pipe_changes) + dc->hwss.detect_pipe_changes (dc->current_state, context, + &dc->current_state->res_ctx.pipe_ctx[i], + &context->res_ctx.pipe_ctx[i]); +else +dcn20_detect_pipe_changes (dc->current_state, context, + &dc->current_state->res_ctx.pipe_ctx[i], + &context->res_ctx.pipe_ctx[i]); + }/* When disabling phantom pipes, turn on phantom OTG first (so we can get double * buffer updates properly)
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c +0 -166
172 lines not on this page · raw message
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.h +0 -1
@@ -102,7 +102,6 @@ void dcn401_program_pipe(struct pipe_ctx *pipe_ctx, struct dc_state *context);void dcn401_perform_3dlut_wa_unlock (struct pipe_ctx *pipe_ctx); -void dcn401_program_front_end_for_ctx (struct dc *dc,struct dc_state *context);void dcn401_post_unlock_program_front_end (struct dc *dc,struct dc_state *context);bool dcn401_update_bandwidth (struct dc *dc,struct dc_state *context); void dcn401_detect_pipe_changes(
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_init.c +1 -1
@@ -17,7 +17,7 @@ static const struct hw_sequencer_funcs dcn401_funcs = { .init_hw = dcn401_init_hw, .apply_ctx_to_hw = dce110_apply_ctx_to_hw, .apply_ctx_for_surface = NULL, - .program_front_end_for_ctx = dcn401_program_front_end_for_ctx, + .program_front_end_for_ctx = dcn20_program_front_end_for_ctx, .clear_surface_dcc_and_tiling = dcn10_reset_surface_dcc_and_tiling, .wait_for_pending_cleared = dcn10_wait_for_pending_cleared, .post_unlock_program_front_end = dcn401_post_unlock_program_front_end,
Signature · 1 line
2.47.2
PATCH 4/5 drm/amd/display: remove duplicated post_unlock_program_front_end code on dcn401
In reply to Melissa WenEnable hw_sequence_private funcs: enable plane for program_pipe and post_unlock_reset_opp for post_unlock_program_front_end (even if this is actually dcn20_post_unlock_reset_opp) to remove duplicated post_unlock_program_front_end code on dcn401.
--- .../amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 16 ++- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.c | 135 ------------------ .../amd/display/dc/hwss/dcn401/dcn401_hwseq.h | 1 - .../amd/display/dc/hwss/dcn401/dcn401_init.c | 2 +- 4 files changed, 13 insertions(+), 141 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c +12 -4
@@ -1940,6 +1940,8 @@ static void dcn20_program_pipe(if (pipe_ctx->update_flags.bits.enable) {if (hws->funcs.enable_plane) hws->funcs.enable_plane (dc, pipe_ctx, context); +else if (dc->hwss.enable_plane) + dc->hwss.enable_plane (dc, pipe_ctx, context);else dcn20_enable_plane (dc, pipe_ctx, context);
@@ -2256,11 +2258,17 @@ void dcn20_post_unlock_program_front_end(struct dce_hwseq *hwseq = dc->hwseq;int i; -for (i =0 ; i < dc->res_pool->pipe_count; i++) +for (i =0 ; i < dc->res_pool->pipe_count; i++) {if (resource_is_pipe_type (&dc->current_state->res_ctx.pipe_ctx[i],OPP_HEAD ) && - !resource_is_pipe_type (&context->res_ctx.pipe_ctx[i],OPP_HEAD )) -dcn20_post_unlock_reset_opp (dc, - &dc->current_state->res_ctx.pipe_ctx[i]); + !resource_is_pipe_type (&context->res_ctx.pipe_ctx[i],OPP_HEAD )) { +if (dc->hwss.post_unlock_reset_opp) + dc->hwss.post_unlock_reset_opp (dc, + &dc->current_state->res_ctx.pipe_ctx[i]); +else +dcn20_post_unlock_reset_opp (dc, + &dc->current_state->res_ctx.pipe_ctx[i]); + } + }for (i =0 ; i < dc->res_pool->pipe_count; i++)if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable)
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c +0 -135
141 lines not on this page · raw message
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.h +0 -1
@@ -102,7 +102,6 @@ void dcn401_program_pipe(struct pipe_ctx *pipe_ctx, struct dc_state *context);void dcn401_perform_3dlut_wa_unlock (struct pipe_ctx *pipe_ctx); -void dcn401_post_unlock_program_front_end (struct dc *dc,struct dc_state *context);bool dcn401_update_bandwidth (struct dc *dc,struct dc_state *context); void dcn401_detect_pipe_changes( struct dc_state *old_state,
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_init.c +1 -1
@@ -20,7 +20,7 @@ static const struct hw_sequencer_funcs dcn401_funcs = { .program_front_end_for_ctx = dcn20_program_front_end_for_ctx, .clear_surface_dcc_and_tiling = dcn10_reset_surface_dcc_and_tiling, .wait_for_pending_cleared = dcn10_wait_for_pending_cleared, - .post_unlock_program_front_end = dcn401_post_unlock_program_front_end, + .post_unlock_program_front_end = dcn20_post_unlock_program_front_end, .update_plane_addr = dcn20_update_plane_addr, .update_dchub = dcn10_update_dchub, .update_pending_status = dcn10_update_pending_status,
Signature · 1 line
2.47.2
PATCH 5/5 drm/amd/display: remove duplicated program_pipe code on dcn401
In reply to Melissa WenReduce code duplication by reusing dcn20_program_pipe since both dcn401/dcn20_program_pipe now does the same thing and so its caller on dcn401.
--- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.c | 126 ------------------ .../amd/display/dc/hwss/dcn401/dcn401_hwseq.h | 4 - 2 files changed, 130 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c +0 -126
@@ -2214,132 +2214,6 @@ void dcn401_program_tg(struct dc *dc, hws->funcs.setup_vupdate_interrupt (dc, pipe_ctx); } -void dcn401_program_pipe ( -struct dc *dc, -struct pipe_ctx *pipe_ctx, -struct dc_state *context) -{ -struct dce_hwseq *hws = dc->hwseq; - -/* Only need to unblank on top pipe */ -if (resource_is_pipe_type (pipe_ctx,OTG_MASTER )) { -if (pipe_ctx->update_flags.bits.enable || - pipe_ctx->update_flags.bits.odm || - pipe_ctx->stream->update_flags.bits.abm_level) - hws->funcs.blank_pixel_data (dc, pipe_ctx, - !pipe_ctx->plane_state || - !pipe_ctx->plane_state->visible); - } - -/* Only update TG on top pipe */ -if (pipe_ctx->update_flags.bits.global_sync && !pipe_ctx->top_pipe - && !pipe_ctx->prev_odm_pipe) -dcn401_program_tg (dc, pipe_ctx, context, hws); - -if (pipe_ctx->update_flags.bits.odm) - hws->funcs.update_odm (dc, context, pipe_ctx); - -if (pipe_ctx->update_flags.bits.enable) { -if (hws->funcs.enable_plane) - hws->funcs.enable_plane (dc, pipe_ctx, context); -else - dc->hwss.enable_plane (dc, pipe_ctx, context); - -if (dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes) - dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes (dc->res_pool->hubbub); - } - -if (pipe_ctx->update_flags.bits.det_size) { -if (dc->res_pool->hubbub->funcs->program_det_size) - dc->res_pool->hubbub->funcs->program_det_size ( - dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->det_buffer_size_kb); -if (dc->res_pool->hubbub->funcs->program_det_segments) - dc->res_pool->hubbub->funcs->program_det_segments ( - dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->hubp_regs.det_size); - } - -if (pipe_ctx->plane_state && (pipe_ctx->update_flags.raw || - pipe_ctx->plane_state->update_flags.raw || - pipe_ctx->stream->update_flags.raw)) - dc->hwss.update_dchubp_dpp (dc, pipe_ctx, context); - -if (pipe_ctx->plane_state && (pipe_ctx->update_flags.bits.enable || - pipe_ctx->plane_state->update_flags.bits.hdr_mult)) - hws->funcs.set_hdr_multiplier (pipe_ctx); - -if (hws->funcs.populate_mcm_luts) { -if (pipe_ctx->plane_state) { - hws->funcs.populate_mcm_luts (dc, pipe_ctx, pipe_ctx->plane_state->mcm_luts, - pipe_ctx->plane_state->lut_bank_a); - pipe_ctx->plane_state->lut_bank_a = !pipe_ctx->plane_state->lut_bank_a; - } - } - -if (pipe_ctx->plane_state && - (pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change || - pipe_ctx->plane_state->update_flags.bits.gamma_change || - pipe_ctx->plane_state->update_flags.bits.lut_3d || - pipe_ctx->update_flags.bits.enable)) - hws->funcs.set_input_transfer_func (dc, pipe_ctx, pipe_ctx->plane_state); - -/* dcn10_translate_regamma_to_hw_format takes 750us to finish -* only do gamma programming for powering on, internal memcmp to avoid -* updating on slave planes -*/ -if (pipe_ctx->update_flags.bits.enable || - pipe_ctx->update_flags.bits.plane_changed || - pipe_ctx->stream->update_flags.bits.out_tf || - (pipe_ctx->plane_state && - pipe_ctx->plane_state->update_flags.bits.output_tf_change)) - hws->funcs.set_output_transfer_func (dc, pipe_ctx, pipe_ctx->stream); - -/* If the pipe has been enabled or has a different opp, we -* should reprogram the fmt. This deals with cases where -* interation between mpc and odm combine on different streams -* causes a different pipe to be chosen to odm combine with. -*/ -if (pipe_ctx->update_flags.bits.enable - || pipe_ctx->update_flags.bits.opp_changed) { - - pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion ( - pipe_ctx->stream_res.opp, -COLOR_SPACE_YCBCR601 , - pipe_ctx->stream->timing.display_color_depth, - pipe_ctx->stream->signal); - - pipe_ctx->stream_res.opp->funcs->opp_program_fmt ( - pipe_ctx->stream_res.opp, - &pipe_ctx->stream->bit_depth_params, - &pipe_ctx->stream->clamping); - } - -/* Set ABM pipe after other pipe configurations done */ -if ((pipe_ctx->plane_state && pipe_ctx->plane_state->visible)) { -if (pipe_ctx->stream_res.abm) { - dc->hwss.set_pipe (pipe_ctx); - pipe_ctx->stream_res.abm->funcs->set_abm_level (pipe_ctx->stream_res.abm, - pipe_ctx->stream->abm_level); - } - } - -if (pipe_ctx->update_flags.bits.test_pattern_changed) { -struct output_pixel_processor *odm_opp = pipe_ctx->stream_res.opp; -struct bit_depth_reduction_params params; - -memset (¶ms,0 ,sizeof (params)); - odm_opp->funcs->opp_program_bit_depth_reduction (odm_opp, ¶ms); - dc->hwss.set_disp_pattern_generator (dc, - pipe_ctx, - pipe_ctx->stream_res.test_pattern_params.test_pattern, - pipe_ctx->stream_res.test_pattern_params.color_space, - pipe_ctx->stream_res.test_pattern_params.color_depth, -NULL , - pipe_ctx->stream_res.test_pattern_params.width, - pipe_ctx->stream_res.test_pattern_params.height, - pipe_ctx->stream_res.test_pattern_params.offset); - } -} -bool dcn401_update_bandwidth (struct dc *dc,struct dc_state *context)
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.h +0 -4
@@ -97,10 +97,6 @@ void dcn401_program_tg(struct dc *dc,struct pipe_ctx *pipe_ctx, struct dc_state *context, struct dce_hwseq *hws); -void dcn401_program_pipe ( -struct dc *dc, -struct pipe_ctx *pipe_ctx, -struct dc_state *context);void dcn401_perform_3dlut_wa_unlock (struct pipe_ctx *pipe_ctx);bool dcn401_update_bandwidth (struct dc *dc,struct dc_state *context); void dcn401_detect_pipe_changes(
Signature · 1 line
2.47.2
Hi Melissa,
The patchset looks good to me but there is WIP dcn401 code, meaning dcn20 and dcn401 are different.
I will check how to refactor code so this patchset can fit better.
Thanks
Quoted 32 lines · Melissa Wen
Hi,
I've been examining dcn401 code to figure out what is causing a wrong cursor gamma on HDR issue reported in [1], and I found unnecessary code duplications during this inspection. I don't have the HW, so I'd appreciate if someone can validate this series (if it makes sense to you ofc).
This series basically adds some hooks to dcn20 base functions that are usually used in other hw versions and reuses those functions on dcn401 so that we can reduce many lines of code and also increase the coverage of bug fixes by avoiding the kind of issue of [2]. Better for debugging and maintainability too.
[1] https://gitlab.freedesktop.org/drm/amd/-/issues/4176
[2] https://lore.kernel.org/amd-gfx/[email protected]/Melissa Wen (5):
drm/amd/display: add hook forprogram_tg
drm/amd/display: hook upprogram_tgfor dcn401 drm/amd/display: remove duplicatedprogram_front_end_for_ctxcode drm/amd/display: remove duplicatedpost_unlock_program_front_endcodeon dcn401drm/amd/display: remove duplicated
program_pipecode on dcn401.../amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 40 +- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.c | 436 +----------------- .../amd/display/dc/hwss/dcn401/dcn401_hwseq.h | 10 +- .../amd/display/dc/hwss/dcn401/dcn401_init.c | 5 +- .../drm/amd/display/dc/hwss/hw_sequencer.h | 4 + 5 files changed, 45 insertions(+), 450 deletions(-)
Quoted 5 lines · Alex Hung
Hi Melissa,
The patchset looks good to me but there is WIP dcn401 code, meaning dcn20 and dcn401 are different.
I will check how to refactor code so this patchset can fit better.
I see. Let's wait a bit so.
Anyway, thanks for taking a look.
Melissa
Quoted 37 lines
Thanks
Quoted 32 lines · Melissa Wen
Hi,
I've been examining dcn401 code to figure out what is causing a wrong cursor gamma on HDR issue reported in [1], and I found unnecessary code duplications during this inspection. I don't have the HW, so I'd appreciate if someone can validate this series (if it makes sense to you ofc).
This series basically adds some hooks to dcn20 base functions that are usually used in other hw versions and reuses those functions on dcn401 so that we can reduce many lines of code and also increase the coverage of bug fixes by avoiding the kind of issue of [2]. Better for debugging and maintainability too.
[1] https://gitlab.freedesktop.org/drm/amd/-/issues/4176
[2] https://lore.kernel.org/amd-gfx/[email protected]/Melissa Wen (5):
drm/amd/display: add hook forprogram_tg
drm/amd/display: hook upprogram_tgfor dcn401 drm/amd/display: remove duplicatedprogram_front_end_for_ctxcode drm/amd/display: remove duplicatedpost_unlock_program_front_endcode on dcn401
drm/amd/display: remove duplicatedprogram_pipecode on dcn401.../amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 40 +-
.../amd/display/dc/hwss/dcn401/dcn401_hwseq.c| 436 +-----------------.../amd/display/dc/hwss/dcn401/dcn401_hwseq.h| 10 +- .../amd/display/dc/hwss/dcn401/dcn401_init.c | 5 +- .../drm/amd/display/dc/hwss/hw_sequencer.h | 4 +5 files changed, 45 insertions(+), 450 deletions(-)