2 * Copyright 2022 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 // header file of functions being implemented
27 #include "dcn32_resource.h"
28 #include "dcn20/dcn20_resource.h"
29 #include "dml/dcn32/display_mode_vba_util_32.h"
32 * ********************************************************************************************
33 * dcn32_helper_calculate_num_ways_for_subvp: Calculate number of ways needed for SubVP
35 * This function first checks the bytes required per pixel on the SubVP pipe, then calculates
36 * the total number of pixels required in the SubVP MALL region. These are used to calculate
37 * the number of cache lines used (then number of ways required) for SubVP MCLK switching.
39 * @param [in] dc: current dc state
40 * @param [in] context: new dc state
42 * @return: number of ways required for SubVP
44 * ********************************************************************************************
46 uint32_t dcn32_helper_calculate_num_ways_for_subvp(struct dc *dc, struct dc_state *context)
48 uint32_t num_ways = 0;
49 uint32_t mall_region_pixels = 0;
50 uint32_t bytes_per_pixel = 0;
51 uint32_t cache_lines_used = 0;
52 uint32_t lines_per_way = 0;
53 uint32_t total_cache_lines = 0;
54 uint32_t bytes_in_mall = 0;
55 uint32_t num_mblks = 0;
56 uint32_t cache_lines_per_plane = 0;
59 for (i = 0; i < dc->res_pool->pipe_count; i++) {
60 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
62 // Find the phantom pipes
63 if (pipe->stream && pipe->plane_state && !pipe->top_pipe &&
64 pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
65 bytes_per_pixel = pipe->plane_state->format >= SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616 ? 8 : 4;
66 mall_region_pixels = pipe->plane_state->plane_size.surface_pitch * pipe->stream->timing.v_addressable;
68 // For bytes required in MALL, calculate based on number of MBlks required
69 num_mblks = (mall_region_pixels * bytes_per_pixel +
70 DCN3_2_MALL_MBLK_SIZE_BYTES - 1) / DCN3_2_MALL_MBLK_SIZE_BYTES;
71 bytes_in_mall = num_mblks * DCN3_2_MALL_MBLK_SIZE_BYTES;
72 // cache lines used is total bytes / cache_line size. Add +2 for worst case alignment
73 // (MALL is 64-byte aligned)
74 cache_lines_per_plane = bytes_in_mall / dc->caps.cache_line_size + 2;
76 // For DCC we must cache the meat surface, so double cache lines required
77 if (pipe->plane_state->dcc.enable)
78 cache_lines_per_plane *= 2;
79 cache_lines_used += cache_lines_per_plane;
83 total_cache_lines = dc->caps.max_cab_allocation_bytes / dc->caps.cache_line_size;
84 lines_per_way = total_cache_lines / dc->caps.cache_num_ways;
85 num_ways = cache_lines_used / lines_per_way;
86 if (cache_lines_used % lines_per_way > 0)
92 void dcn32_merge_pipes_for_subvp(struct dc *dc,
93 struct dc_state *context)
97 /* merge pipes if necessary */
98 for (i = 0; i < dc->res_pool->pipe_count; i++) {
99 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
101 // For now merge all pipes for SubVP since pipe split case isn't supported yet
103 /* if ODM merge we ignore mpc tree, mpo pipes will have their own flags */
104 if (pipe->prev_odm_pipe) {
105 /*split off odm pipe*/
106 pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe;
107 if (pipe->next_odm_pipe)
108 pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe;
110 pipe->bottom_pipe = NULL;
111 pipe->next_odm_pipe = NULL;
112 pipe->plane_state = NULL;
114 pipe->top_pipe = NULL;
115 pipe->prev_odm_pipe = NULL;
116 if (pipe->stream_res.dsc)
117 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc);
118 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
119 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
120 } else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
121 struct pipe_ctx *top_pipe = pipe->top_pipe;
122 struct pipe_ctx *bottom_pipe = pipe->bottom_pipe;
124 top_pipe->bottom_pipe = bottom_pipe;
126 bottom_pipe->top_pipe = top_pipe;
128 pipe->top_pipe = NULL;
129 pipe->bottom_pipe = NULL;
130 pipe->plane_state = NULL;
132 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
133 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
138 bool dcn32_all_pipes_have_stream_and_plane(struct dc *dc,
139 struct dc_state *context)
143 for (i = 0; i < dc->res_pool->pipe_count; i++) {
144 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
149 if (!pipe->plane_state)
155 bool dcn32_subvp_in_use(struct dc *dc,
156 struct dc_state *context)
160 for (i = 0; i < dc->res_pool->pipe_count; i++) {
161 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
163 if (pipe->stream && pipe->stream->mall_stream_config.type != SUBVP_NONE)
169 bool dcn32_mpo_in_use(struct dc_state *context)
173 for (i = 0; i < context->stream_count; i++) {
174 if (context->stream_status[i].plane_count > 1)
180 void dcn32_determine_det_override(struct dc_state *context, display_e2e_pipe_params_st *pipes,
181 bool *is_pipe_split_expected, int pipe_cnt)
183 int i, j, count, stream_segments, pipe_segments[MAX_PIPES];
185 if (context->stream_count > 0) {
186 stream_segments = 18 / context->stream_count;
187 for (i = 0; i < context->stream_count; i++) {
189 for (j = 0; j < pipe_cnt; j++) {
190 if (context->res_ctx.pipe_ctx[j].stream == context->streams[i]) {
192 if (is_pipe_split_expected[j])
196 pipe_segments[i] = stream_segments / count;
199 for (i = 0; i < pipe_cnt; i++) {
200 pipes[i].pipe.src.det_size_override = 0;
201 for (j = 0; j < context->stream_count; j++) {
202 if (context->res_ctx.pipe_ctx[i].stream == context->streams[j]) {
203 pipes[i].pipe.src.det_size_override = pipe_segments[j] * DCN3_2_DET_SEG_SIZE;
209 for (i = 0; i < pipe_cnt; i++)
210 pipes[i].pipe.src.det_size_override = 4 * DCN3_2_DET_SEG_SIZE; //DCN3_2_DEFAULT_DET_SIZE