From: Gabe Teeger <[email protected]> [Why] Some ASICs have more pipes than OTGs and OPPs. A stream could be given a pipe without its own OTG and was then aliased to the last OTG and OPP, which another stream already used. Both streams then shared one OTG, so one of them stopped getting vblank interrupts.
[How] Only pick a pipe as OTG master if it has its own OTG. If none is free, drop another stream's ODM slices and let DML validation add them back if needed. Remove the aliasing fallback. Skip pipes without an OPP when acquiring an ODM slice. Cc: Charlene Liu <[email protected]> Signed-off-by: Gabe Teeger <[email protected]> Signed-off-by: Chenyu Chen <[email protected]> --- .../gpu/drm/amd/display/dc/core/dc_resource.c | 64 ++++++++++++--- .../dc/resource/dcn42b/dcn42b_resource.c | 82 ++++++++++++++++++- .../dc/resource/dcn42b/dcn42b_resource.h | 6 ++ 3 files changed, 140 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_resource.c b/drivers/gpu/drm/amd/display/dc/core/dc_resource.c index ec11a79811e7..cb537aa90ad5 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_resource.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_resource.c @@ -4295,6 +4295,48 @@ static void mark_seamless_boot_stream(const struct dc *dc, } } +/* + * Some ASICs (e.g. DCN 2.0.1 and DCN 4.2B) have more pipes than OTGs. A pipe + * without its own OTG can only be a secondary DPP pipe. As an OTG master it + * would share the OTG and OPP of another stream. + */ +static bool can_pipe_be_otg_master(const struct resource_pool *pool, + int pipe_idx) +{ + return pipe_idx >= 0 && + (unsigned int)pipe_idx < pool->timing_generator_count; +} + +/* + * Remove the ODM slices of the first stream that has more than one and return + * the first free pipe. DML re-evaluates the ODM slice count of that stream + * during validation. It adds the slices back if the timing needs them and + * enough OPPs are left, and fails validation otherwise. + */ +static int release_odm_slices_of_a_stream( + const struct dc_state *cur_ctx, + struct dc_state *new_ctx, + const struct resource_pool *pool) +{ + unsigned int i; + + for (i = 0; i < pool->pipe_count; i++) { + struct pipe_ctx *otg_master = &new_ctx->res_ctx.pipe_ctx[i]; + + if (!resource_is_pipe_type(otg_master, OTG_MASTER) || + resource_get_odm_slice_count(otg_master) == 1) + continue; + + if (!resource_update_pipes_for_stream_with_slice_count(new_ctx, + cur_ctx, pool, otg_master->stream, 1)) + return FREE_PIPE_INDEX_NOT_FOUND; + + return resource_find_any_free_pipe(&new_ctx->res_ctx, pool); + } + + return FREE_PIPE_INDEX_NOT_FOUND; +} + /* * Acquire a pipe as OTG master and assign to the stream in new dc context. * return - true if OTG master pipe is acquired and new dc context is updated. @@ -4349,7 +4391,7 @@ static bool acquire_otg_master_pipe_for_stream( * Try to acquire a pipe not used in current resource context to avoid * pipe swapping. */ - if (pipe_idx == FREE_PIPE_INDEX_NOT_FOUND) + if (!can_pipe_be_otg_master(pool, pipe_idx)) pipe_idx = recource_find_free_pipe_not_used_in_cur_res_ctx( &cur_ctx->res_ctx, &new_ctx->res_ctx, pool); /* @@ -4357,12 +4399,19 @@ static bool acquire_otg_master_pipe_for_stream( * secondary DPP pipe in current state as we prioritize to support more * streams over supporting MPO planes. */ - if (pipe_idx == FREE_PIPE_INDEX_NOT_FOUND) + if (!can_pipe_be_otg_master(pool, pipe_idx)) pipe_idx = resource_find_free_pipe_used_as_cur_sec_dpp( &cur_ctx->res_ctx, &new_ctx->res_ctx, pool); - if (pipe_idx == FREE_PIPE_INDEX_NOT_FOUND) + if (!can_pipe_be_otg_master(pool, pipe_idx)) pipe_idx = resource_find_any_free_pipe(&new_ctx->res_ctx, pool); - if (pipe_idx != FREE_PIPE_INDEX_NOT_FOUND) { + /* + * If the only free pipes have no OTG (e.g. pipe 3 on DCN 4.2B), free a + * pipe that has one by removing the ODM slices of another stream. + */ + if (pipe_idx != FREE_PIPE_INDEX_NOT_FOUND && + !can_pipe_be_otg_master(pool, pipe_idx)) + pipe_idx = release_odm_slices_of_a_stream(cur_ctx, new_ctx, pool); + if (can_pipe_be_otg_master(pool, pipe_idx)) { pipe_ctx = &new_ctx->res_ctx.pipe_ctx[pipe_idx]; memset(pipe_ctx, 0, sizeof(*pipe_ctx)); pipe_ctx->pipe_idx = (uint8_t)pipe_idx; @@ -4376,13 +4425,6 @@ static bool acquire_otg_master_pipe_for_stream( if (pool->dpps[pipe_idx]) pipe_ctx->plane_res.mpcc_inst = (uint8_t)pool->dpps[pipe_idx]->inst; - if ((unsigned int)pipe_idx >= pool->timing_generator_count && pool->timing_generator_count != 0) { - int tg_inst = pool->timing_generator_count - 1; - - pipe_ctx->stream_res.tg = pool->timing_generators[tg_inst]; - pipe_ctx->stream_res.opp = pool->opps[tg_inst]; - } - pipe_ctx->stream = stream; } else { pipe_idx = acquire_first_split_pipe(&new_ctx->res_ctx, pool, stream); diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c index 338c506588d9..aeecdd2daae2 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c @@ -1950,6 +1950,86 @@ static unsigned int dcn42b_get_max_hw_cursor_size(const struct dc *dc, return dc->caps.max_cursor_size; } +/* + * DCN 4.2B has 4 pipes but only 3 OPPs. An OPP head needs its own OPP, so the + * pipe without one can only be a secondary DPP pipe. + */ +static bool dcn42b_can_pipe_be_opp_head(const struct resource_pool *pool, + int pipe_idx) +{ + return pipe_idx >= 0 && pool->opps[pipe_idx]; +} + +static int dcn42b_find_optimal_free_pipe_as_secondary_opp_head( + const struct resource_context *cur_res_ctx, + struct resource_context *new_res_ctx, + const struct resource_pool *pool, + const struct pipe_ctx *new_otg_master) +{ + const struct pipe_ctx *cur_otg_master; + int free_pipe_idx; + + cur_otg_master = &cur_res_ctx->pipe_ctx[new_otg_master->pipe_idx]; + free_pipe_idx = resource_find_free_pipe_used_as_sec_opp_head_by_cur_otg_master( + cur_res_ctx, new_res_ctx, cur_otg_master); + + if (!dcn42b_can_pipe_be_opp_head(pool, free_pipe_idx)) + free_pipe_idx = recource_find_free_pipe_not_used_in_cur_res_ctx( + cur_res_ctx, new_res_ctx, pool); + + if (!dcn42b_can_pipe_be_opp_head(pool, free_pipe_idx)) + free_pipe_idx = resource_find_any_free_pipe(new_res_ctx, pool); + + if (!dcn42b_can_pipe_be_opp_head(pool, free_pipe_idx)) + return FREE_PIPE_INDEX_NOT_FOUND; + + return free_pipe_idx; +} + +struct pipe_ctx *dcn42b_acquire_free_pipe_as_secondary_opp_head( + const struct dc_state *cur_ctx, + struct dc_state *new_ctx, + const struct resource_pool *pool, + const struct pipe_ctx *otg_master) +{ + int free_pipe_idx = dcn42b_find_optimal_free_pipe_as_secondary_opp_head( + &cur_ctx->res_ctx, &new_ctx->res_ctx, + pool, otg_master); + struct pipe_ctx *free_pipe; + + if (free_pipe_idx >= 0) { + free_pipe = &new_ctx->res_ctx.pipe_ctx[free_pipe_idx]; + free_pipe->pipe_idx = (uint8_t)free_pipe_idx; + free_pipe->stream = otg_master->stream; + free_pipe->stream_res.tg = otg_master->stream_res.tg; + free_pipe->stream_res.dsc = NULL; + free_pipe->stream_res.opp = pool->opps[free_pipe_idx]; + free_pipe->plane_res.mi = pool->mis[free_pipe_idx]; + free_pipe->plane_res.hubp = pool->hubps[free_pipe_idx]; + free_pipe->plane_res.ipp = pool->ipps[free_pipe_idx]; + free_pipe->plane_res.xfm = pool->transforms[free_pipe_idx]; + free_pipe->plane_res.dpp = pool->dpps[free_pipe_idx]; + free_pipe->plane_res.mpcc_inst = (uint8_t)pool->dpps[free_pipe_idx]->inst; + free_pipe->dsc_padding_params = otg_master->dsc_padding_params; + if (free_pipe->stream->timing.flags.DSC == 1) { + dcn20_acquire_dsc(free_pipe->stream->ctx->dc, + &new_ctx->res_ctx, + &free_pipe->stream_res.dsc, + free_pipe_idx); + ASSERT(free_pipe->stream_res.dsc); + if (free_pipe->stream_res.dsc == NULL) { + memset(free_pipe, 0, sizeof(*free_pipe)); + free_pipe = NULL; + } + } + } else { + ASSERT(otg_master); + free_pipe = NULL; + } + + return free_pipe; +} + static struct resource_funcs dcn42b_res_pool_funcs = { .destroy = dcn42b_destroy_resource_pool, .link_enc_create = dcn42b_link_encoder_create, @@ -1961,7 +2041,7 @@ static struct resource_funcs dcn42b_res_pool_funcs = { .calculate_wm_and_dlg = NULL, .populate_dml_pipes = NULL, .acquire_free_pipe_as_secondary_dpp_pipe = dcn32_acquire_free_pipe_as_secondary_dpp_pipe, - .acquire_free_pipe_as_secondary_opp_head = dcn32_acquire_free_pipe_as_secondary_opp_head, + .acquire_free_pipe_as_secondary_opp_head = dcn42b_acquire_free_pipe_as_secondary_opp_head, .release_pipe = dcn20_release_pipe, .add_stream_to_ctx = dcn30_add_stream_to_ctx, .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource, diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.h b/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.h index 484ba1455468..8b9e3e9723ed 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.h +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.h @@ -516,4 +516,10 @@ enum dc_status dcn42b_validate_bandwidth(struct dc *dc, void dcn42b_prepare_mcache_programming(struct dc *dc, struct dc_state *context); +struct pipe_ctx *dcn42b_acquire_free_pipe_as_secondary_opp_head( + const struct dc_state *cur_ctx, + struct dc_state *new_ctx, + const struct resource_pool *pool, + const struct pipe_ctx *otg_master); + #endif /* _DCN42B_RESOURCE_H_ */ -- 2.43.0
