0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "resource.h"
0027 #include "core_types.h"
0028 #include "dsc.h"
0029 #include "clk_mgr.h"
0030
0031 #ifndef DC_LOGGER_INIT
0032 #define DC_LOGGER_INIT
0033 #undef DC_LOG_WARNING
0034 #define DC_LOG_WARNING
0035 #endif
0036
0037 #define DML_WRAPPER_TRANSLATION_
0038 #include "dml_wrapper_translation.c"
0039 #undef DML_WRAPPER_TRANSLATION_
0040
0041 static bool is_dual_plane(enum surface_pixel_format format)
0042 {
0043 return format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN || format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA;
0044 }
0045
0046 static void build_clamping_params(struct dc_stream_state *stream)
0047 {
0048 stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
0049 stream->clamping.c_depth = stream->timing.display_color_depth;
0050 stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
0051 }
0052
0053 static void get_pixel_clock_parameters(
0054 const struct pipe_ctx *pipe_ctx,
0055 struct pixel_clk_params *pixel_clk_params)
0056 {
0057 const struct dc_stream_state *stream = pipe_ctx->stream;
0058
0059
0060
0061
0062
0063 pixel_clk_params->requested_pix_clk_100hz = stream->timing.pix_clk_100hz;
0064 pixel_clk_params->encoder_object_id = stream->link->link_enc->id;
0065 pixel_clk_params->signal_type = pipe_ctx->stream->signal;
0066 pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
0067
0068 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
0069 LINK_RATE_REF_FREQ_IN_KHZ;
0070 pixel_clk_params->flags.ENABLE_SS = 0;
0071 pixel_clk_params->color_depth =
0072 stream->timing.display_color_depth;
0073 pixel_clk_params->flags.DISPLAY_BLANKED = 1;
0074 pixel_clk_params->flags.SUPPORT_YCBCR420 = (stream->timing.pixel_encoding ==
0075 PIXEL_ENCODING_YCBCR420);
0076 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
0077 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) {
0078 pixel_clk_params->color_depth = COLOR_DEPTH_888;
0079 }
0080 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
0081 pixel_clk_params->requested_pix_clk_100hz = pixel_clk_params->requested_pix_clk_100hz / 2;
0082 }
0083 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
0084 pixel_clk_params->requested_pix_clk_100hz *= 2;
0085
0086 }
0087
0088 static void resource_build_bit_depth_reduction_params(struct dc_stream_state *stream,
0089 struct bit_depth_reduction_params *fmt_bit_depth)
0090 {
0091 enum dc_dither_option option = stream->dither_option;
0092 enum dc_pixel_encoding pixel_encoding =
0093 stream->timing.pixel_encoding;
0094
0095 memset(fmt_bit_depth, 0, sizeof(*fmt_bit_depth));
0096
0097 if (option == DITHER_OPTION_DEFAULT) {
0098 switch (stream->timing.display_color_depth) {
0099 case COLOR_DEPTH_666:
0100 option = DITHER_OPTION_SPATIAL6;
0101 break;
0102 case COLOR_DEPTH_888:
0103 option = DITHER_OPTION_SPATIAL8;
0104 break;
0105 case COLOR_DEPTH_101010:
0106 option = DITHER_OPTION_SPATIAL10;
0107 break;
0108 default:
0109 option = DITHER_OPTION_DISABLE;
0110 }
0111 }
0112
0113 if (option == DITHER_OPTION_DISABLE)
0114 return;
0115
0116 if (option == DITHER_OPTION_TRUN6) {
0117 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
0118 fmt_bit_depth->flags.TRUNCATE_DEPTH = 0;
0119 } else if (option == DITHER_OPTION_TRUN8 ||
0120 option == DITHER_OPTION_TRUN8_SPATIAL6 ||
0121 option == DITHER_OPTION_TRUN8_FM6) {
0122 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
0123 fmt_bit_depth->flags.TRUNCATE_DEPTH = 1;
0124 } else if (option == DITHER_OPTION_TRUN10 ||
0125 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
0126 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
0127 option == DITHER_OPTION_TRUN10_FM8 ||
0128 option == DITHER_OPTION_TRUN10_FM6 ||
0129 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
0130 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
0131 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
0132 }
0133
0134
0135
0136
0137
0138
0139
0140
0141 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
0142 option == DITHER_OPTION_SPATIAL6 ||
0143 option == DITHER_OPTION_FM6) {
0144 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
0145 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
0146 fmt_bit_depth->flags.TRUNCATE_MODE = 1;
0147 }
0148
0149
0150
0151
0152 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
0153 option == DITHER_OPTION_SPATIAL6 ||
0154 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
0155 option == DITHER_OPTION_TRUN8_SPATIAL6) {
0156 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
0157 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 0;
0158 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
0159 fmt_bit_depth->flags.RGB_RANDOM =
0160 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
0161 } else if (option == DITHER_OPTION_SPATIAL8_FRAME_RANDOM ||
0162 option == DITHER_OPTION_SPATIAL8 ||
0163 option == DITHER_OPTION_SPATIAL8_FM6 ||
0164 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
0165 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
0166 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
0167 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 1;
0168 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
0169 fmt_bit_depth->flags.RGB_RANDOM =
0170 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
0171 } else if (option == DITHER_OPTION_SPATIAL10_FRAME_RANDOM ||
0172 option == DITHER_OPTION_SPATIAL10 ||
0173 option == DITHER_OPTION_SPATIAL10_FM8 ||
0174 option == DITHER_OPTION_SPATIAL10_FM6) {
0175 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
0176 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 2;
0177 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
0178 fmt_bit_depth->flags.RGB_RANDOM =
0179 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
0180 }
0181
0182 if (option == DITHER_OPTION_SPATIAL6 ||
0183 option == DITHER_OPTION_SPATIAL8 ||
0184 option == DITHER_OPTION_SPATIAL10) {
0185 fmt_bit_depth->flags.FRAME_RANDOM = 0;
0186 } else {
0187 fmt_bit_depth->flags.FRAME_RANDOM = 1;
0188 }
0189
0190
0191
0192
0193 if (option == DITHER_OPTION_FM6 ||
0194 option == DITHER_OPTION_SPATIAL8_FM6 ||
0195 option == DITHER_OPTION_SPATIAL10_FM6 ||
0196 option == DITHER_OPTION_TRUN10_FM6 ||
0197 option == DITHER_OPTION_TRUN8_FM6 ||
0198 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
0199 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
0200 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 0;
0201 } else if (option == DITHER_OPTION_FM8 ||
0202 option == DITHER_OPTION_SPATIAL10_FM8 ||
0203 option == DITHER_OPTION_TRUN10_FM8) {
0204 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
0205 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 1;
0206 } else if (option == DITHER_OPTION_FM10) {
0207 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
0208 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 2;
0209 }
0210
0211 fmt_bit_depth->pixel_encoding = pixel_encoding;
0212 }
0213
0214
0215
0216
0217
0218 static enum dc_status build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
0219 {
0220
0221 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
0222
0223 if (pipe_ctx->clock_source)
0224 pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
0225 pipe_ctx->clock_source,
0226 &pipe_ctx->stream_res.pix_clk_params,
0227 &pipe_ctx->pll_settings);
0228
0229 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
0230
0231 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
0232 &pipe_ctx->stream->bit_depth_params);
0233 build_clamping_params(pipe_ctx->stream);
0234
0235 return DC_OK;
0236 }
0237
0238 bool dml_validate_dsc(struct dc *dc, struct dc_state *new_ctx)
0239 {
0240 int i;
0241
0242
0243 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0244 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i];
0245 struct dc_stream_state *stream = pipe_ctx->stream;
0246 struct dsc_config dsc_cfg;
0247 struct pipe_ctx *odm_pipe;
0248 int opp_cnt = 1;
0249
0250 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
0251 opp_cnt++;
0252
0253
0254 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe || !stream || !stream->timing.flags.DSC)
0255 continue;
0256
0257 dsc_cfg.pic_width = (stream->timing.h_addressable + stream->timing.h_border_left
0258 + stream->timing.h_border_right) / opp_cnt;
0259 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top
0260 + stream->timing.v_border_bottom;
0261 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
0262 dsc_cfg.color_depth = stream->timing.display_color_depth;
0263 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
0264 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
0265 dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt;
0266
0267 if (pipe_ctx->stream_res.dsc && !pipe_ctx->stream_res.dsc->funcs->dsc_validate_stream(pipe_ctx->stream_res.dsc, &dsc_cfg))
0268 return false;
0269 }
0270 return true;
0271 }
0272
0273 enum dc_status dml_build_mapped_resource(const struct dc *dc, struct dc_state *context, struct dc_stream_state *stream)
0274 {
0275 enum dc_status status = DC_OK;
0276 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
0277
0278 if (!pipe_ctx)
0279 return DC_ERROR_UNEXPECTED;
0280
0281
0282 status = build_pipe_hw_param(pipe_ctx);
0283
0284 return status;
0285 }
0286
0287 void dml_acquire_dsc(const struct dc *dc,
0288 struct resource_context *res_ctx,
0289 struct display_stream_compressor **dsc,
0290 int pipe_idx)
0291 {
0292 int i;
0293 const struct resource_pool *pool = dc->res_pool;
0294 struct display_stream_compressor *dsc_old = dc->current_state->res_ctx.pipe_ctx[pipe_idx].stream_res.dsc;
0295
0296 ASSERT(*dsc == NULL);
0297 *dsc = NULL;
0298
0299
0300 if (pool->res_cap->num_dsc == pool->res_cap->num_opp) {
0301 *dsc = pool->dscs[pipe_idx];
0302 res_ctx->is_dsc_acquired[pipe_idx] = true;
0303 return;
0304 }
0305
0306
0307 if (dsc_old && !res_ctx->is_dsc_acquired[dsc_old->inst]) {
0308 *dsc = dsc_old;
0309 res_ctx->is_dsc_acquired[dsc_old->inst] = true;
0310 return ;
0311 }
0312
0313
0314 for (i = 0; i < pool->res_cap->num_dsc; i++)
0315 if (!res_ctx->is_dsc_acquired[i]) {
0316 *dsc = pool->dscs[i];
0317 res_ctx->is_dsc_acquired[i] = true;
0318 break;
0319 }
0320 }
0321
0322 static bool dml_split_stream_for_mpc_or_odm(
0323 const struct dc *dc,
0324 struct resource_context *res_ctx,
0325 struct pipe_ctx *pri_pipe,
0326 struct pipe_ctx *sec_pipe,
0327 bool odm)
0328 {
0329 int pipe_idx = sec_pipe->pipe_idx;
0330 const struct resource_pool *pool = dc->res_pool;
0331
0332 *sec_pipe = *pri_pipe;
0333
0334 sec_pipe->pipe_idx = pipe_idx;
0335 sec_pipe->plane_res.mi = pool->mis[pipe_idx];
0336 sec_pipe->plane_res.hubp = pool->hubps[pipe_idx];
0337 sec_pipe->plane_res.ipp = pool->ipps[pipe_idx];
0338 sec_pipe->plane_res.xfm = pool->transforms[pipe_idx];
0339 sec_pipe->plane_res.dpp = pool->dpps[pipe_idx];
0340 sec_pipe->plane_res.mpcc_inst = pool->dpps[pipe_idx]->inst;
0341 sec_pipe->stream_res.dsc = NULL;
0342 if (odm) {
0343 if (pri_pipe->next_odm_pipe) {
0344 ASSERT(pri_pipe->next_odm_pipe != sec_pipe);
0345 sec_pipe->next_odm_pipe = pri_pipe->next_odm_pipe;
0346 sec_pipe->next_odm_pipe->prev_odm_pipe = sec_pipe;
0347 }
0348 if (pri_pipe->top_pipe && pri_pipe->top_pipe->next_odm_pipe) {
0349 pri_pipe->top_pipe->next_odm_pipe->bottom_pipe = sec_pipe;
0350 sec_pipe->top_pipe = pri_pipe->top_pipe->next_odm_pipe;
0351 }
0352 if (pri_pipe->bottom_pipe && pri_pipe->bottom_pipe->next_odm_pipe) {
0353 pri_pipe->bottom_pipe->next_odm_pipe->top_pipe = sec_pipe;
0354 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe->next_odm_pipe;
0355 }
0356 pri_pipe->next_odm_pipe = sec_pipe;
0357 sec_pipe->prev_odm_pipe = pri_pipe;
0358 ASSERT(sec_pipe->top_pipe == NULL);
0359
0360 if (!sec_pipe->top_pipe)
0361 sec_pipe->stream_res.opp = pool->opps[pipe_idx];
0362 else
0363 sec_pipe->stream_res.opp = sec_pipe->top_pipe->stream_res.opp;
0364 if (sec_pipe->stream->timing.flags.DSC == 1) {
0365 dml_acquire_dsc(dc, res_ctx, &sec_pipe->stream_res.dsc, pipe_idx);
0366 ASSERT(sec_pipe->stream_res.dsc);
0367 if (sec_pipe->stream_res.dsc == NULL)
0368 return false;
0369 }
0370 } else {
0371 if (pri_pipe->bottom_pipe) {
0372 ASSERT(pri_pipe->bottom_pipe != sec_pipe);
0373 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe;
0374 sec_pipe->bottom_pipe->top_pipe = sec_pipe;
0375 }
0376 pri_pipe->bottom_pipe = sec_pipe;
0377 sec_pipe->top_pipe = pri_pipe;
0378
0379 ASSERT(pri_pipe->plane_state);
0380 }
0381
0382 return true;
0383 }
0384
0385 static struct pipe_ctx *dml_find_split_pipe(
0386 struct dc *dc,
0387 struct dc_state *context,
0388 int old_index)
0389 {
0390 struct pipe_ctx *pipe = NULL;
0391 int i;
0392
0393 if (old_index >= 0 && context->res_ctx.pipe_ctx[old_index].stream == NULL) {
0394 pipe = &context->res_ctx.pipe_ctx[old_index];
0395 pipe->pipe_idx = old_index;
0396 }
0397
0398 if (!pipe)
0399 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
0400 if (dc->current_state->res_ctx.pipe_ctx[i].top_pipe == NULL
0401 && dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe == NULL) {
0402 if (context->res_ctx.pipe_ctx[i].stream == NULL) {
0403 pipe = &context->res_ctx.pipe_ctx[i];
0404 pipe->pipe_idx = i;
0405 break;
0406 }
0407 }
0408 }
0409
0410
0411
0412
0413
0414
0415 if (!pipe)
0416 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
0417 if (context->res_ctx.pipe_ctx[i].stream == NULL) {
0418 pipe = &context->res_ctx.pipe_ctx[i];
0419 pipe->pipe_idx = i;
0420 break;
0421 }
0422 }
0423
0424 return pipe;
0425 }
0426
0427 static void dml_release_dsc(struct resource_context *res_ctx,
0428 const struct resource_pool *pool,
0429 struct display_stream_compressor **dsc)
0430 {
0431 int i;
0432
0433 for (i = 0; i < pool->res_cap->num_dsc; i++)
0434 if (pool->dscs[i] == *dsc) {
0435 res_ctx->is_dsc_acquired[i] = false;
0436 *dsc = NULL;
0437 break;
0438 }
0439 }
0440
0441 static int dml_get_num_mpc_splits(struct pipe_ctx *pipe)
0442 {
0443 int mpc_split_count = 0;
0444 struct pipe_ctx *other_pipe = pipe->bottom_pipe;
0445
0446 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
0447 mpc_split_count++;
0448 other_pipe = other_pipe->bottom_pipe;
0449 }
0450 other_pipe = pipe->top_pipe;
0451 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
0452 mpc_split_count++;
0453 other_pipe = other_pipe->top_pipe;
0454 }
0455
0456 return mpc_split_count;
0457 }
0458
0459 static bool dml_enough_pipes_for_subvp(struct dc *dc,
0460 struct dc_state *context)
0461 {
0462 int i = 0;
0463 int num_pipes = 0;
0464
0465 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0466 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0467
0468 if (pipe->stream && pipe->plane_state)
0469 num_pipes++;
0470 }
0471
0472
0473
0474 if (num_pipes * 2 > dc->res_pool->pipe_count)
0475 return false;
0476
0477 return true;
0478 }
0479
0480 static int dml_validate_apply_pipe_split_flags(
0481 struct dc *dc,
0482 struct dc_state *context,
0483 int vlevel,
0484 int *split,
0485 bool *merge)
0486 {
0487 int i, pipe_idx, vlevel_split;
0488 int plane_count = 0;
0489 bool force_split = false;
0490 bool avoid_split = dc->debug.pipe_split_policy == MPC_SPLIT_AVOID;
0491 struct vba_vars_st *v = &context->bw_ctx.dml.vba;
0492 int max_mpc_comb = v->maxMpcComb;
0493
0494 if (context->stream_count > 1) {
0495 if (dc->debug.pipe_split_policy == MPC_SPLIT_AVOID_MULT_DISP)
0496 avoid_split = true;
0497 } else if (dc->debug.force_single_disp_pipe_split)
0498 force_split = true;
0499
0500 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0501 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0502
0503
0504
0505
0506
0507
0508 if (pipe->plane_state &&
0509 (pipe->plane_state->dst_rect.width <= 16 ||
0510 pipe->plane_state->dst_rect.height <= 16 ||
0511 pipe->plane_state->src_rect.width <= 16 ||
0512 pipe->plane_state->src_rect.height <= 16))
0513 avoid_split = true;
0514
0515
0516 if (pipe->stream && !pipe->prev_odm_pipe &&
0517 (!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state))
0518 ++plane_count;
0519 }
0520 if (plane_count > dc->res_pool->pipe_count / 2)
0521 avoid_split = true;
0522
0523
0524 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0525 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0526 struct dc_crtc_timing timing;
0527
0528 if (!pipe->stream)
0529 continue;
0530 else {
0531 timing = pipe->stream->timing;
0532 if (timing.h_border_left + timing.h_border_right
0533 + timing.v_border_top + timing.v_border_bottom > 0) {
0534 avoid_split = true;
0535 break;
0536 }
0537 }
0538 }
0539
0540
0541 if (avoid_split) {
0542 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
0543 if (!context->res_ctx.pipe_ctx[i].stream)
0544 continue;
0545
0546 for (vlevel_split = vlevel; vlevel <= context->bw_ctx.dml.soc.num_states; vlevel++)
0547 if (v->NoOfDPP[vlevel][0][pipe_idx] == 1 &&
0548 v->ModeSupport[vlevel][0])
0549 break;
0550
0551 if (vlevel > context->bw_ctx.dml.soc.num_states)
0552 vlevel = vlevel_split;
0553 else
0554 max_mpc_comb = 0;
0555 pipe_idx++;
0556 }
0557 v->maxMpcComb = max_mpc_comb;
0558 }
0559
0560
0561 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
0562 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0563 int pipe_plane = v->pipe_plane[pipe_idx];
0564 bool split4mpc = context->stream_count == 1 && plane_count == 1
0565 && dc->config.enable_4to1MPC && dc->res_pool->pipe_count >= 4;
0566
0567 if (!context->res_ctx.pipe_ctx[i].stream)
0568 continue;
0569
0570 if (split4mpc || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 4)
0571 split[i] = 4;
0572 else if (force_split || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 2)
0573 split[i] = 2;
0574
0575 if ((pipe->stream->view_format ==
0576 VIEW_3D_FORMAT_SIDE_BY_SIDE ||
0577 pipe->stream->view_format ==
0578 VIEW_3D_FORMAT_TOP_AND_BOTTOM) &&
0579 (pipe->stream->timing.timing_3d_format ==
0580 TIMING_3D_FORMAT_TOP_AND_BOTTOM ||
0581 pipe->stream->timing.timing_3d_format ==
0582 TIMING_3D_FORMAT_SIDE_BY_SIDE))
0583 split[i] = 2;
0584 if (dc->debug.force_odm_combine & (1 << pipe->stream_res.tg->inst)) {
0585 split[i] = 2;
0586 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_2to1;
0587 }
0588 if (dc->debug.force_odm_combine_4to1 & (1 << pipe->stream_res.tg->inst)) {
0589 split[i] = 4;
0590 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_4to1;
0591 }
0592
0593 if (pipe->stream->timing.h_addressable > 7680 &&
0594 pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
0595 split[i] = 4;
0596 }
0597
0598 v->ODMCombineEnabled[pipe_plane] =
0599 v->ODMCombineEnablePerState[vlevel][pipe_plane];
0600
0601 if (v->ODMCombineEnabled[pipe_plane] == dm_odm_combine_mode_disabled) {
0602 if (dml_get_num_mpc_splits(pipe) == 1) {
0603
0604 if (split[i] == 4)
0605 split[i] = 2;
0606 else if (split[i] == 2)
0607 split[i] = 0;
0608 else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state)
0609 merge[i] = true;
0610 } else if (dml_get_num_mpc_splits(pipe) == 3) {
0611
0612 if (split[i] == 2 && ((pipe->top_pipe && !pipe->top_pipe->top_pipe)
0613 || !pipe->bottom_pipe)) {
0614 merge[i] = true;
0615 } else if (split[i] == 0 && pipe->top_pipe &&
0616 pipe->top_pipe->plane_state == pipe->plane_state)
0617 merge[i] = true;
0618 split[i] = 0;
0619 } else if (dml_get_num_mpc_splits(pipe)) {
0620
0621 if (pipe->prev_odm_pipe) {
0622 split[i] = 0;
0623 merge[i] = true;
0624 }
0625 }
0626 } else {
0627 if (dml_get_num_mpc_splits(pipe) == 1) {
0628
0629 if (split[i] == 4)
0630 split[i] = 2;
0631 else if (split[i] == 2)
0632 split[i] = 0;
0633 else if (pipe->prev_odm_pipe) {
0634 ASSERT(0);
0635 merge[i] = true;
0636 }
0637 } else if (dml_get_num_mpc_splits(pipe) == 3) {
0638
0639 if (split[i] == 2 && ((pipe->prev_odm_pipe && !pipe->prev_odm_pipe->prev_odm_pipe)
0640 || !pipe->next_odm_pipe)) {
0641 ASSERT(0);
0642 merge[i] = true;
0643 } else if (split[i] == 0 && pipe->prev_odm_pipe) {
0644 ASSERT(0);
0645 merge[i] = true;
0646 }
0647 split[i] = 0;
0648 } else if (dml_get_num_mpc_splits(pipe)) {
0649
0650 ASSERT(0);
0651 if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
0652 split[i] = 0;
0653 merge[i] = true;
0654 }
0655 }
0656 }
0657
0658
0659 if (split[i] != 0 && v->NoOfDPP[vlevel][max_mpc_comb][pipe_idx] == 1)
0660 v->RequiredDPPCLK[vlevel][max_mpc_comb][pipe_idx] /= 2;
0661 pipe_idx++;
0662 }
0663
0664 return vlevel;
0665 }
0666
0667 static void dml_set_phantom_stream_timing(struct dc *dc,
0668 struct dc_state *context,
0669 struct pipe_ctx *ref_pipe,
0670 struct dc_stream_state *phantom_stream)
0671 {
0672
0673 uint32_t phantom_vactive_us = context->bw_ctx.dml.soc.dram_clock_change_latency_us + 60 +
0674 dc->caps.subvp_fw_processing_delay_us +
0675 dc->caps.subvp_pstate_allow_width_us;
0676 uint32_t phantom_vactive = ((double)phantom_vactive_us/1000000) *
0677 (ref_pipe->stream->timing.pix_clk_100hz * 100) /
0678 (double)ref_pipe->stream->timing.h_total;
0679 uint32_t phantom_bp = ref_pipe->pipe_dlg_param.vstartup_start;
0680
0681 phantom_stream->dst.y = 0;
0682 phantom_stream->dst.height = phantom_vactive;
0683 phantom_stream->src.y = 0;
0684 phantom_stream->src.height = phantom_vactive;
0685
0686 phantom_stream->timing.v_addressable = phantom_vactive;
0687 phantom_stream->timing.v_front_porch = 1;
0688 phantom_stream->timing.v_total = phantom_stream->timing.v_addressable +
0689 phantom_stream->timing.v_front_porch +
0690 phantom_stream->timing.v_sync_width +
0691 phantom_bp;
0692 }
0693
0694 static struct dc_stream_state *dml_enable_phantom_stream(struct dc *dc,
0695 struct dc_state *context,
0696 struct pipe_ctx *ref_pipe)
0697 {
0698 struct dc_stream_state *phantom_stream = NULL;
0699
0700 phantom_stream = dc_create_stream_for_sink(ref_pipe->stream->sink);
0701 phantom_stream->signal = SIGNAL_TYPE_VIRTUAL;
0702 phantom_stream->dpms_off = true;
0703 phantom_stream->mall_stream_config.type = SUBVP_PHANTOM;
0704 phantom_stream->mall_stream_config.paired_stream = ref_pipe->stream;
0705 ref_pipe->stream->mall_stream_config.type = SUBVP_MAIN;
0706 ref_pipe->stream->mall_stream_config.paired_stream = phantom_stream;
0707
0708
0709 memcpy(&phantom_stream->timing, &ref_pipe->stream->timing, sizeof(phantom_stream->timing));
0710 memcpy(&phantom_stream->src, &ref_pipe->stream->src, sizeof(phantom_stream->src));
0711 memcpy(&phantom_stream->dst, &ref_pipe->stream->dst, sizeof(phantom_stream->dst));
0712 dml_set_phantom_stream_timing(dc, context, ref_pipe, phantom_stream);
0713
0714 dc_add_stream_to_ctx(dc, context, phantom_stream);
0715 dc->hwss.apply_ctx_to_hw(dc, context);
0716 return phantom_stream;
0717 }
0718
0719 static void dml_enable_phantom_plane(struct dc *dc,
0720 struct dc_state *context,
0721 struct dc_stream_state *phantom_stream,
0722 struct pipe_ctx *main_pipe)
0723 {
0724 struct dc_plane_state *phantom_plane = NULL;
0725 struct dc_plane_state *prev_phantom_plane = NULL;
0726 struct pipe_ctx *curr_pipe = main_pipe;
0727
0728 while (curr_pipe) {
0729 if (curr_pipe->top_pipe && curr_pipe->top_pipe->plane_state == curr_pipe->plane_state)
0730 phantom_plane = prev_phantom_plane;
0731 else
0732 phantom_plane = dc_create_plane_state(dc);
0733
0734 memcpy(&phantom_plane->address, &curr_pipe->plane_state->address, sizeof(phantom_plane->address));
0735 memcpy(&phantom_plane->scaling_quality, &curr_pipe->plane_state->scaling_quality,
0736 sizeof(phantom_plane->scaling_quality));
0737 memcpy(&phantom_plane->src_rect, &curr_pipe->plane_state->src_rect, sizeof(phantom_plane->src_rect));
0738 memcpy(&phantom_plane->dst_rect, &curr_pipe->plane_state->dst_rect, sizeof(phantom_plane->dst_rect));
0739 memcpy(&phantom_plane->clip_rect, &curr_pipe->plane_state->clip_rect, sizeof(phantom_plane->clip_rect));
0740 memcpy(&phantom_plane->plane_size, &curr_pipe->plane_state->plane_size,
0741 sizeof(phantom_plane->plane_size));
0742 memcpy(&phantom_plane->tiling_info, &curr_pipe->plane_state->tiling_info,
0743 sizeof(phantom_plane->tiling_info));
0744 memcpy(&phantom_plane->dcc, &curr_pipe->plane_state->dcc, sizeof(phantom_plane->dcc));
0745
0746
0747
0748 phantom_plane->format = curr_pipe->plane_state->format;
0749 phantom_plane->rotation = curr_pipe->plane_state->rotation;
0750 phantom_plane->visible = curr_pipe->plane_state->visible;
0751
0752
0753 phantom_plane->clip_rect.y = 0;
0754 phantom_plane->clip_rect.height = phantom_stream->timing.v_addressable;
0755
0756 dc_add_plane_to_context(dc, phantom_stream, phantom_plane, context);
0757
0758 curr_pipe = curr_pipe->bottom_pipe;
0759 prev_phantom_plane = phantom_plane;
0760 }
0761 }
0762
0763 static void dml_add_phantom_pipes(struct dc *dc, struct dc_state *context)
0764 {
0765 int i = 0;
0766
0767 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0768 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0769 struct dc_stream_state *ref_stream = pipe->stream;
0770
0771 if (!pipe->top_pipe && pipe->plane_state && pipe->stream &&
0772 pipe->stream->mall_stream_config.type == SUBVP_NONE) {
0773 struct dc_stream_state *phantom_stream = NULL;
0774
0775 phantom_stream = dml_enable_phantom_stream(dc, context, pipe);
0776 dml_enable_phantom_plane(dc, context, phantom_stream, pipe);
0777 }
0778 }
0779
0780 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0781 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0782
0783 if (pipe->plane_state && pipe->stream &&
0784 pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
0785 pipe->stream->use_dynamic_meta = false;
0786 pipe->plane_state->flip_immediate = false;
0787 if (!resource_build_scaling_params(pipe)) {
0788
0789 }
0790 }
0791 }
0792 }
0793
0794 static void dml_remove_phantom_pipes(struct dc *dc, struct dc_state *context)
0795 {
0796 int i;
0797 bool removed_pipe = false;
0798
0799 for (i = 0; i < dc->res_pool->pipe_count; i++) {
0800 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0801
0802 if (pipe->plane_state && pipe->stream && pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
0803 dc_rem_all_planes_for_stream(dc, pipe->stream, context);
0804 dc_remove_stream_from_ctx(dc, context, pipe->stream);
0805 removed_pipe = true;
0806 }
0807
0808
0809 if (pipe->stream) {
0810 pipe->stream->mall_stream_config.type = SUBVP_NONE;
0811 pipe->stream->mall_stream_config.paired_stream = NULL;
0812 }
0813 }
0814 if (removed_pipe)
0815 dc->hwss.apply_ctx_to_hw(dc, context);
0816 }
0817
0818
0819
0820
0821
0822 static void populate_default_plane_from_timing(const struct dc_crtc_timing *timing, struct _vcs_dpi_display_pipe_params_st *pipe)
0823 {
0824 pipe->src.is_hsplit = pipe->dest.odm_combine != dm_odm_combine_mode_disabled;
0825 pipe->src.source_scan = dm_horz;
0826 pipe->src.sw_mode = dm_sw_4kb_s;
0827 pipe->src.macro_tile_size = dm_64k_tile;
0828 pipe->src.viewport_width = timing->h_addressable;
0829 if (pipe->src.viewport_width > 1920)
0830 pipe->src.viewport_width = 1920;
0831 pipe->src.viewport_height = timing->v_addressable;
0832 if (pipe->src.viewport_height > 1080)
0833 pipe->src.viewport_height = 1080;
0834 pipe->src.surface_height_y = pipe->src.viewport_height;
0835 pipe->src.surface_width_y = pipe->src.viewport_width;
0836 pipe->src.surface_height_c = pipe->src.viewport_height;
0837 pipe->src.surface_width_c = pipe->src.viewport_width;
0838 pipe->src.data_pitch = ((pipe->src.viewport_width + 255) / 256) * 256;
0839 pipe->src.source_format = dm_444_32;
0840 pipe->dest.recout_width = pipe->src.viewport_width;
0841 pipe->dest.recout_height = pipe->src.viewport_height;
0842 pipe->dest.full_recout_width = pipe->dest.recout_width;
0843 pipe->dest.full_recout_height = pipe->dest.recout_height;
0844 pipe->scale_ratio_depth.lb_depth = dm_lb_16;
0845 pipe->scale_ratio_depth.hscl_ratio = 1.0;
0846 pipe->scale_ratio_depth.vscl_ratio = 1.0;
0847 pipe->scale_ratio_depth.scl_enable = 0;
0848 pipe->scale_taps.htaps = 1;
0849 pipe->scale_taps.vtaps = 1;
0850 pipe->dest.vtotal_min = timing->v_total;
0851 pipe->dest.vtotal_max = timing->v_total;
0852
0853 if (pipe->dest.odm_combine == dm_odm_combine_mode_2to1) {
0854 pipe->src.viewport_width /= 2;
0855 pipe->dest.recout_width /= 2;
0856 } else if (pipe->dest.odm_combine == dm_odm_combine_mode_4to1) {
0857 pipe->src.viewport_width /= 4;
0858 pipe->dest.recout_width /= 4;
0859 }
0860
0861 pipe->src.dcc = false;
0862 pipe->src.dcc_rate = 1;
0863 }
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873 static void populate_hsplit_group_from_dc_pipe_ctx (const struct pipe_ctx *dc_pipe_ctx, struct _vcs_dpi_display_e2e_pipe_params_st *e2e_pipe)
0874 {
0875 e2e_pipe->pipe.src.hsplit_grp = dc_pipe_ctx->pipe_idx;
0876
0877 if (dc_pipe_ctx->top_pipe && dc_pipe_ctx->top_pipe->plane_state
0878 == dc_pipe_ctx->plane_state) {
0879 struct pipe_ctx *first_pipe = dc_pipe_ctx->top_pipe;
0880 int split_idx = 0;
0881
0882 while (first_pipe->top_pipe && first_pipe->top_pipe->plane_state
0883 == dc_pipe_ctx->plane_state) {
0884 first_pipe = first_pipe->top_pipe;
0885 split_idx++;
0886 }
0887
0888
0889 if (split_idx == 0)
0890 e2e_pipe->pipe.src.hsplit_grp = first_pipe->pipe_idx;
0891 else if (split_idx == 1)
0892 e2e_pipe->pipe.src.hsplit_grp = dc_pipe_ctx->pipe_idx;
0893 else if (split_idx == 2)
0894 e2e_pipe->pipe.src.hsplit_grp = dc_pipe_ctx->top_pipe->pipe_idx;
0895
0896 } else if (dc_pipe_ctx->prev_odm_pipe) {
0897 struct pipe_ctx *first_pipe = dc_pipe_ctx->prev_odm_pipe;
0898
0899 while (first_pipe->prev_odm_pipe)
0900 first_pipe = first_pipe->prev_odm_pipe;
0901 e2e_pipe->pipe.src.hsplit_grp = first_pipe->pipe_idx;
0902 }
0903 }
0904
0905 static void populate_dml_from_dc_pipe_ctx (const struct pipe_ctx *dc_pipe_ctx, struct _vcs_dpi_display_e2e_pipe_params_st *e2e_pipe, int always_scale)
0906 {
0907 const struct dc_plane_state *pln = dc_pipe_ctx->plane_state;
0908 const struct scaler_data *scl = &dc_pipe_ctx->plane_res.scl_data;
0909
0910 e2e_pipe->pipe.src.immediate_flip = pln->flip_immediate;
0911 e2e_pipe->pipe.src.is_hsplit = (dc_pipe_ctx->bottom_pipe && dc_pipe_ctx->bottom_pipe->plane_state == pln)
0912 || (dc_pipe_ctx->top_pipe && dc_pipe_ctx->top_pipe->plane_state == pln)
0913 || e2e_pipe->pipe.dest.odm_combine != dm_odm_combine_mode_disabled;
0914
0915
0916 if (pln->stereo_format == PLANE_STEREO_FORMAT_SIDE_BY_SIDE ||
0917 pln->stereo_format == PLANE_STEREO_FORMAT_TOP_AND_BOTTOM) {
0918 e2e_pipe->pipe.src.is_hsplit = false;
0919 e2e_pipe->pipe.src.hsplit_grp = dc_pipe_ctx->pipe_idx;
0920 }
0921
0922 e2e_pipe->pipe.src.source_scan = pln->rotation == ROTATION_ANGLE_90
0923 || pln->rotation == ROTATION_ANGLE_270 ? dm_vert : dm_horz;
0924 e2e_pipe->pipe.src.viewport_y_y = scl->viewport.y;
0925 e2e_pipe->pipe.src.viewport_y_c = scl->viewport_c.y;
0926 e2e_pipe->pipe.src.viewport_width = scl->viewport.width;
0927 e2e_pipe->pipe.src.viewport_width_c = scl->viewport_c.width;
0928 e2e_pipe->pipe.src.viewport_height = scl->viewport.height;
0929 e2e_pipe->pipe.src.viewport_height_c = scl->viewport_c.height;
0930 e2e_pipe->pipe.src.viewport_width_max = pln->src_rect.width;
0931 e2e_pipe->pipe.src.viewport_height_max = pln->src_rect.height;
0932 e2e_pipe->pipe.src.surface_width_y = pln->plane_size.surface_size.width;
0933 e2e_pipe->pipe.src.surface_height_y = pln->plane_size.surface_size.height;
0934 e2e_pipe->pipe.src.surface_width_c = pln->plane_size.chroma_size.width;
0935 e2e_pipe->pipe.src.surface_height_c = pln->plane_size.chroma_size.height;
0936
0937 if (pln->format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA
0938 || pln->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) {
0939 e2e_pipe->pipe.src.data_pitch = pln->plane_size.surface_pitch;
0940 e2e_pipe->pipe.src.data_pitch_c = pln->plane_size.chroma_pitch;
0941 e2e_pipe->pipe.src.meta_pitch = pln->dcc.meta_pitch;
0942 e2e_pipe->pipe.src.meta_pitch_c = pln->dcc.meta_pitch_c;
0943 } else {
0944 e2e_pipe->pipe.src.data_pitch = pln->plane_size.surface_pitch;
0945 e2e_pipe->pipe.src.meta_pitch = pln->dcc.meta_pitch;
0946 }
0947 e2e_pipe->pipe.src.dcc = pln->dcc.enable;
0948 e2e_pipe->pipe.src.dcc_rate = 1;
0949 e2e_pipe->pipe.dest.recout_width = scl->recout.width;
0950 e2e_pipe->pipe.dest.recout_height = scl->recout.height;
0951 e2e_pipe->pipe.dest.full_recout_height = scl->recout.height;
0952 e2e_pipe->pipe.dest.full_recout_width = scl->recout.width;
0953 if (e2e_pipe->pipe.dest.odm_combine == dm_odm_combine_mode_2to1)
0954 e2e_pipe->pipe.dest.full_recout_width *= 2;
0955 else if (e2e_pipe->pipe.dest.odm_combine == dm_odm_combine_mode_4to1)
0956 e2e_pipe->pipe.dest.full_recout_width *= 4;
0957 else {
0958 struct pipe_ctx *split_pipe = dc_pipe_ctx->bottom_pipe;
0959
0960 while (split_pipe && split_pipe->plane_state == pln) {
0961 e2e_pipe->pipe.dest.full_recout_width += split_pipe->plane_res.scl_data.recout.width;
0962 split_pipe = split_pipe->bottom_pipe;
0963 }
0964 split_pipe = dc_pipe_ctx->top_pipe;
0965 while (split_pipe && split_pipe->plane_state == pln) {
0966 e2e_pipe->pipe.dest.full_recout_width += split_pipe->plane_res.scl_data.recout.width;
0967 split_pipe = split_pipe->top_pipe;
0968 }
0969 }
0970
0971 e2e_pipe->pipe.scale_ratio_depth.lb_depth = dm_lb_16;
0972 e2e_pipe->pipe.scale_ratio_depth.hscl_ratio = (double) scl->ratios.horz.value / (1ULL<<32);
0973 e2e_pipe->pipe.scale_ratio_depth.hscl_ratio_c = (double) scl->ratios.horz_c.value / (1ULL<<32);
0974 e2e_pipe->pipe.scale_ratio_depth.vscl_ratio = (double) scl->ratios.vert.value / (1ULL<<32);
0975 e2e_pipe->pipe.scale_ratio_depth.vscl_ratio_c = (double) scl->ratios.vert_c.value / (1ULL<<32);
0976 e2e_pipe->pipe.scale_ratio_depth.scl_enable =
0977 scl->ratios.vert.value != dc_fixpt_one.value
0978 || scl->ratios.horz.value != dc_fixpt_one.value
0979 || scl->ratios.vert_c.value != dc_fixpt_one.value
0980 || scl->ratios.horz_c.value != dc_fixpt_one.value
0981 || always_scale;
0982 e2e_pipe->pipe.scale_taps.htaps = scl->taps.h_taps;
0983 e2e_pipe->pipe.scale_taps.htaps_c = scl->taps.h_taps_c;
0984 e2e_pipe->pipe.scale_taps.vtaps = scl->taps.v_taps;
0985 e2e_pipe->pipe.scale_taps.vtaps_c = scl->taps.v_taps_c;
0986
0987
0988
0989
0990
0991
0992
0993
0994
0995
0996
0997
0998
0999
1000 e2e_pipe->pipe.src.source_format = dc_source_format_to_dml_source_format(pln->format);
1001 }
1002
1003 static void populate_dml_cursor_parameters_from_dc_pipe_ctx (const struct pipe_ctx *dc_pipe_ctx, struct _vcs_dpi_display_e2e_pipe_params_st *e2e_pipe)
1004 {
1005
1006
1007
1008
1009 if (dc_pipe_ctx->plane_state &&
1010 (dc_pipe_ctx->plane_state->address.type == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE ||
1011 dc_pipe_ctx->stream->mall_stream_config.type == SUBVP_PHANTOM))
1012 e2e_pipe->pipe.src.num_cursors = 0;
1013 else
1014 e2e_pipe->pipe.src.num_cursors = 1;
1015
1016 e2e_pipe->pipe.src.cur0_src_width = 256;
1017 e2e_pipe->pipe.src.cur0_bpp = dm_cur_32bit;
1018 }
1019
1020 static int populate_dml_pipes_from_context_base(
1021 struct dc *dc,
1022 struct dc_state *context,
1023 display_e2e_pipe_params_st *pipes,
1024 bool fast_validate)
1025 {
1026 int pipe_cnt, i;
1027 bool synchronized_vblank = true;
1028 struct resource_context *res_ctx = &context->res_ctx;
1029
1030 for (i = 0, pipe_cnt = -1; i < dc->res_pool->pipe_count; i++) {
1031 if (!res_ctx->pipe_ctx[i].stream)
1032 continue;
1033
1034 if (pipe_cnt < 0) {
1035 pipe_cnt = i;
1036 continue;
1037 }
1038
1039 if (res_ctx->pipe_ctx[pipe_cnt].stream == res_ctx->pipe_ctx[i].stream)
1040 continue;
1041
1042 if (dc->debug.disable_timing_sync ||
1043 (!resource_are_streams_timing_synchronizable(
1044 res_ctx->pipe_ctx[pipe_cnt].stream,
1045 res_ctx->pipe_ctx[i].stream) &&
1046 !resource_are_vblanks_synchronizable(
1047 res_ctx->pipe_ctx[pipe_cnt].stream,
1048 res_ctx->pipe_ctx[i].stream))) {
1049 synchronized_vblank = false;
1050 break;
1051 }
1052 }
1053
1054 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1055 struct dc_crtc_timing *timing = &res_ctx->pipe_ctx[i].stream->timing;
1056
1057 struct audio_check aud_check = {0};
1058 if (!res_ctx->pipe_ctx[i].stream)
1059 continue;
1060
1061
1062
1063
1064
1065
1066 pipes[pipe_cnt].clks_cfg.refclk_mhz = dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000.0;
1067
1068 pipes[pipe_cnt].dout.dsc_enable = res_ctx->pipe_ctx[i].stream->timing.flags.DSC;
1069
1070 pipes[pipe_cnt].dout.dsc_slices = res_ctx->pipe_ctx[i].stream->timing.dsc_cfg.num_slices_h;
1071 if (res_ctx->pipe_ctx[i].stream->use_dynamic_meta) {
1072 pipes[pipe_cnt].pipe.src.dynamic_metadata_enable = true;
1073
1074 pipes[pipe_cnt].pipe.src.dynamic_metadata_lines_before_active =
1075 (timing->v_total - timing->v_addressable
1076 - timing->v_border_top - timing->v_border_bottom) / 2;
1077
1078 pipes[pipe_cnt].pipe.src.dynamic_metadata_xmit_bytes =
1079 dc_is_dp_signal(res_ctx->pipe_ctx[i].stream->signal) ? 36 : 32;
1080 }
1081 pipes[pipe_cnt].pipe.dest.synchronized_vblank_all_planes = synchronized_vblank;
1082
1083 dc_timing_to_dml_timing(timing, &pipes[pipe_cnt].pipe.dest);
1084 pipes[pipe_cnt].pipe.dest.vtotal_min = res_ctx->pipe_ctx[i].stream->adjust.v_total_min;
1085 pipes[pipe_cnt].pipe.dest.vtotal_max = res_ctx->pipe_ctx[i].stream->adjust.v_total_max;
1086
1087 pipes[pipe_cnt].pipe.dest.otg_inst = res_ctx->pipe_ctx[i].stream_res.tg->inst;
1088
1089 pipes[pipe_cnt].pipe.dest.odm_combine = get_dml_odm_combine(&res_ctx->pipe_ctx[i]);
1090
1091 populate_hsplit_group_from_dc_pipe_ctx(&res_ctx->pipe_ctx[i], &pipes[pipe_cnt]);
1092
1093 pipes[pipe_cnt].dout.dp_lanes = 4;
1094 pipes[pipe_cnt].dout.is_virtual = 0;
1095 pipes[pipe_cnt].dout.output_type = get_dml_output_type(res_ctx->pipe_ctx[i].stream->signal);
1096 if (pipes[pipe_cnt].dout.output_type < 0) {
1097 pipes[pipe_cnt].dout.output_type = dm_dp;
1098 pipes[pipe_cnt].dout.is_virtual = 1;
1099 }
1100
1101 populate_color_depth_and_encoding_from_timing(&res_ctx->pipe_ctx[i].stream->timing, &pipes[pipe_cnt].dout);
1102
1103 if (res_ctx->pipe_ctx[i].stream->timing.flags.DSC)
1104 pipes[pipe_cnt].dout.output_bpp = res_ctx->pipe_ctx[i].stream->timing.dsc_cfg.bits_per_pixel / 16.0;
1105
1106
1107 pipes[pipe_cnt].dout.dsc_input_bpc = 12;
1108
1109 get_audio_check(&res_ctx->pipe_ctx[i].stream->audio_info, &aud_check);
1110 pipes[pipe_cnt].dout.max_audio_sample_rate = aud_check.max_audiosample_rate / 1000;
1111
1112 populate_dml_cursor_parameters_from_dc_pipe_ctx(&res_ctx->pipe_ctx[i], &pipes[pipe_cnt]);
1113
1114 if (!res_ctx->pipe_ctx[i].plane_state) {
1115 populate_default_plane_from_timing(timing, &pipes[pipe_cnt].pipe);
1116 } else {
1117 populate_dml_from_dc_pipe_ctx(&res_ctx->pipe_ctx[i], &pipes[pipe_cnt], dc->debug.always_scale);
1118 }
1119
1120 pipe_cnt++;
1121 }
1122
1123
1124 if (dc->res_pool)
1125 dc->res_pool->funcs->populate_dml_writeback_from_context(dc, res_ctx, pipes);
1126
1127 return pipe_cnt;
1128 }
1129
1130 static int dml_populate_dml_pipes_from_context(
1131 struct dc *dc, struct dc_state *context,
1132 display_e2e_pipe_params_st *pipes,
1133 bool fast_validate)
1134 {
1135 int i, pipe_cnt;
1136 struct resource_context *res_ctx = &context->res_ctx;
1137 struct pipe_ctx *pipe = NULL;
1138
1139 populate_dml_pipes_from_context_base(dc, context, pipes, fast_validate);
1140
1141 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1142 struct dc_crtc_timing *timing;
1143
1144 if (!res_ctx->pipe_ctx[i].stream)
1145 continue;
1146 pipe = &res_ctx->pipe_ctx[i];
1147 timing = &pipe->stream->timing;
1148
1149 pipes[pipe_cnt].pipe.src.gpuvm = true;
1150 pipes[pipe_cnt].pipe.src.dcc_fraction_of_zs_req_luma = 0;
1151 pipes[pipe_cnt].pipe.src.dcc_fraction_of_zs_req_chroma = 0;
1152 pipes[pipe_cnt].pipe.dest.vfront_porch = timing->v_front_porch;
1153
1154 pipes[pipe_cnt].dout.dsc_input_bpc = 0;
1155 if (pipes[pipe_cnt].dout.dsc_enable) {
1156 switch (timing->display_color_depth) {
1157 case COLOR_DEPTH_888:
1158 pipes[pipe_cnt].dout.dsc_input_bpc = 8;
1159 break;
1160 case COLOR_DEPTH_101010:
1161 pipes[pipe_cnt].dout.dsc_input_bpc = 10;
1162 break;
1163 case COLOR_DEPTH_121212:
1164 pipes[pipe_cnt].dout.dsc_input_bpc = 12;
1165 break;
1166 default:
1167 ASSERT(0);
1168 break;
1169 }
1170 }
1171 pipe_cnt++;
1172 }
1173 dc->config.enable_4to1MPC = false;
1174 if (pipe_cnt == 1 && pipe->plane_state && !dc->debug.disable_z9_mpc) {
1175 if (is_dual_plane(pipe->plane_state->format)
1176 && pipe->plane_state->src_rect.width <= 1920 && pipe->plane_state->src_rect.height <= 1080) {
1177 dc->config.enable_4to1MPC = true;
1178 } else if (!is_dual_plane(pipe->plane_state->format)) {
1179 context->bw_ctx.dml.ip.det_buffer_size_kbytes = 192;
1180 pipes[0].pipe.src.unbounded_req_mode = true;
1181 }
1182 }
1183
1184 return pipe_cnt;
1185 }
1186
1187 static void dml_full_validate_bw_helper(struct dc *dc,
1188 struct dc_state *context,
1189 display_e2e_pipe_params_st *pipes,
1190 int *vlevel,
1191 int *split,
1192 bool *merge,
1193 int *pipe_cnt)
1194 {
1195 struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
1196
1197
1198
1199
1200
1201
1202 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1203 dm_allow_self_refresh_and_mclk_switch;
1204 *vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, *pipe_cnt);
1205
1206 if (*vlevel < context->bw_ctx.dml.soc.num_states)
1207 *vlevel = dml_validate_apply_pipe_split_flags(dc, context, *vlevel, split, merge);
1208
1209
1210
1211
1212
1213
1214
1215
1216 if (!dc->debug.force_disable_subvp &&
1217 dml_enough_pipes_for_subvp(dc, context) &&
1218 *vlevel < context->bw_ctx.dml.soc.num_states &&
1219 (vba->DRAMClockChangeSupport[*vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported ||
1220 dc->debug.force_subvp_mclk_switch)) {
1221
1222 dml_add_phantom_pipes(dc, context);
1223
1224
1225
1226
1227 *pipe_cnt = dml_populate_dml_pipes_from_context(dc, context, pipes, false);
1228 *vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, *pipe_cnt);
1229 if (*vlevel < context->bw_ctx.dml.soc.num_states) {
1230 memset(split, 0, MAX_PIPES * sizeof(*split));
1231 memset(merge, 0, MAX_PIPES * sizeof(*merge));
1232 *vlevel = dml_validate_apply_pipe_split_flags(dc, context, *vlevel, split, merge);
1233 }
1234
1235
1236
1237 if (*vlevel == context->bw_ctx.dml.soc.num_states ||
1238 vba->DRAMClockChangeSupport[*vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported) {
1239 dml_remove_phantom_pipes(dc, context);
1240 *pipe_cnt = dml_populate_dml_pipes_from_context(dc, context, pipes, false);
1241 }
1242 }
1243 }
1244
1245 static void dcn20_adjust_adaptive_sync_v_startup(
1246 const struct dc_crtc_timing *dc_crtc_timing, int *vstartup_start)
1247 {
1248 struct dc_crtc_timing patched_crtc_timing;
1249 uint32_t asic_blank_end = 0;
1250 uint32_t asic_blank_start = 0;
1251 uint32_t newVstartup = 0;
1252
1253 patched_crtc_timing = *dc_crtc_timing;
1254
1255 if (patched_crtc_timing.flags.INTERLACE == 1) {
1256 if (patched_crtc_timing.v_front_porch < 2)
1257 patched_crtc_timing.v_front_porch = 2;
1258 } else {
1259 if (patched_crtc_timing.v_front_porch < 1)
1260 patched_crtc_timing.v_front_porch = 1;
1261 }
1262
1263
1264 asic_blank_start = patched_crtc_timing.v_total -
1265 patched_crtc_timing.v_front_porch;
1266
1267
1268 asic_blank_end = asic_blank_start -
1269 patched_crtc_timing.v_border_bottom -
1270 patched_crtc_timing.v_addressable -
1271 patched_crtc_timing.v_border_top;
1272
1273 newVstartup = asic_blank_end + (patched_crtc_timing.v_total - asic_blank_start);
1274
1275 *vstartup_start = ((newVstartup > *vstartup_start) ? newVstartup : *vstartup_start);
1276 }
1277
1278 static bool is_dp_128b_132b_signal(struct pipe_ctx *pipe_ctx)
1279 {
1280 return (pipe_ctx->stream_res.hpo_dp_stream_enc &&
1281 pipe_ctx->link_res.hpo_dp_link_enc &&
1282 dc_is_dp_signal(pipe_ctx->stream->signal));
1283 }
1284
1285 static bool is_dtbclk_required(struct dc *dc, struct dc_state *context)
1286 {
1287 int i;
1288 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1289 if (!context->res_ctx.pipe_ctx[i].stream)
1290 continue;
1291 if (is_dp_128b_132b_signal(&context->res_ctx.pipe_ctx[i]))
1292 return true;
1293 }
1294 return false;
1295 }
1296
1297 static void dml_update_soc_for_wm_a(struct dc *dc, struct dc_state *context)
1298 {
1299 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].valid) {
1300 context->bw_ctx.dml.soc.dram_clock_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].dml_input.pstate_latency_us;
1301 context->bw_ctx.dml.soc.sr_enter_plus_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].dml_input.sr_enter_plus_exit_time_us;
1302 context->bw_ctx.dml.soc.sr_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].dml_input.sr_exit_time_us;
1303 context->bw_ctx.dml.soc.fclk_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].dml_input.fclk_change_latency_us;
1304 }
1305 }
1306
1307 static bool dml_internal_validate(
1308 struct dc *dc,
1309 struct dc_state *context,
1310 display_e2e_pipe_params_st *pipes,
1311 int *pipe_cnt_out,
1312 int *vlevel_out,
1313 bool fast_validate)
1314 {
1315 bool out = false;
1316 bool repopulate_pipes = false;
1317 int split[MAX_PIPES] = { 0 };
1318 bool merge[MAX_PIPES] = { false };
1319 bool newly_split[MAX_PIPES] = { false };
1320 int pipe_cnt, i, pipe_idx, vlevel;
1321 struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
1322
1323 ASSERT(pipes);
1324 if (!pipes)
1325 return false;
1326
1327
1328 dml_remove_phantom_pipes(dc, context);
1329
1330 dml_update_soc_for_wm_a(dc, context);
1331
1332 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1333 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1334
1335 if (pipe->plane_state) {
1336
1337
1338
1339
1340
1341 }
1342 }
1343 pipe_cnt = dml_populate_dml_pipes_from_context(dc, context, pipes, fast_validate);
1344
1345 if (!pipe_cnt) {
1346 out = true;
1347 goto validate_out;
1348 }
1349
1350 dml_log_pipe_params(&context->bw_ctx.dml, pipes, pipe_cnt);
1351
1352 if (!fast_validate) {
1353 dml_full_validate_bw_helper(dc, context, pipes, &vlevel, split, merge, &pipe_cnt);
1354 }
1355
1356 if (fast_validate || vlevel == context->bw_ctx.dml.soc.num_states ||
1357 vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported) {
1358
1359
1360
1361
1362
1363
1364
1365 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1366 dm_allow_self_refresh;
1367
1368 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1369 if (vlevel < context->bw_ctx.dml.soc.num_states) {
1370 memset(split, 0, sizeof(split));
1371 memset(merge, 0, sizeof(merge));
1372 vlevel = dml_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1373 }
1374 }
1375
1376 dml_log_mode_support_params(&context->bw_ctx.dml);
1377
1378 if (vlevel == context->bw_ctx.dml.soc.num_states)
1379 goto validate_fail;
1380
1381 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1382 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1383 struct pipe_ctx *mpo_pipe = pipe->bottom_pipe;
1384
1385 if (!pipe->stream)
1386 continue;
1387
1388
1389 if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled
1390 && pipe->plane_state && mpo_pipe
1391 && memcmp(&mpo_pipe->plane_res.scl_data.recout,
1392 &pipe->plane_res.scl_data.recout,
1393 sizeof(struct rect)) != 0) {
1394 ASSERT(mpo_pipe->plane_state != pipe->plane_state);
1395 goto validate_fail;
1396 }
1397 pipe_idx++;
1398 }
1399
1400
1401 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1402 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1403
1404
1405 if (!merge[i])
1406 continue;
1407
1408
1409 if (pipe->prev_odm_pipe) {
1410
1411 pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe;
1412 if (pipe->next_odm_pipe)
1413 pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe;
1414
1415 pipe->bottom_pipe = NULL;
1416 pipe->next_odm_pipe = NULL;
1417 pipe->plane_state = NULL;
1418 pipe->stream = NULL;
1419 pipe->top_pipe = NULL;
1420 pipe->prev_odm_pipe = NULL;
1421 if (pipe->stream_res.dsc)
1422 dml_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc);
1423 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1424 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1425 repopulate_pipes = true;
1426 } else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
1427 struct pipe_ctx *top_pipe = pipe->top_pipe;
1428 struct pipe_ctx *bottom_pipe = pipe->bottom_pipe;
1429
1430 top_pipe->bottom_pipe = bottom_pipe;
1431 if (bottom_pipe)
1432 bottom_pipe->top_pipe = top_pipe;
1433
1434 pipe->top_pipe = NULL;
1435 pipe->bottom_pipe = NULL;
1436 pipe->plane_state = NULL;
1437 pipe->stream = NULL;
1438 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1439 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1440 repopulate_pipes = true;
1441 } else
1442 ASSERT(0);
1443
1444 }
1445
1446 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
1447 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1448 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1449 struct pipe_ctx *hsplit_pipe = NULL;
1450 bool odm;
1451 int old_index = -1;
1452
1453 if (!pipe->stream || newly_split[i])
1454 continue;
1455
1456 pipe_idx++;
1457 odm = vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled;
1458
1459 if (!pipe->plane_state && !odm)
1460 continue;
1461
1462 if (split[i]) {
1463 if (odm) {
1464 if (split[i] == 4 && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe)
1465 old_index = old_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1466 else if (old_pipe->next_odm_pipe)
1467 old_index = old_pipe->next_odm_pipe->pipe_idx;
1468 } else {
1469 if (split[i] == 4 && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1470 old_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1471 old_index = old_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1472 else if (old_pipe->bottom_pipe &&
1473 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1474 old_index = old_pipe->bottom_pipe->pipe_idx;
1475 }
1476 hsplit_pipe = dml_find_split_pipe(dc, context, old_index);
1477 ASSERT(hsplit_pipe);
1478 if (!hsplit_pipe)
1479 goto validate_fail;
1480
1481 if (!dml_split_stream_for_mpc_or_odm(
1482 dc, &context->res_ctx,
1483 pipe, hsplit_pipe, odm))
1484 goto validate_fail;
1485
1486 newly_split[hsplit_pipe->pipe_idx] = true;
1487 repopulate_pipes = true;
1488 }
1489 if (split[i] == 4) {
1490 struct pipe_ctx *pipe_4to1;
1491
1492 if (odm && old_pipe->next_odm_pipe)
1493 old_index = old_pipe->next_odm_pipe->pipe_idx;
1494 else if (!odm && old_pipe->bottom_pipe &&
1495 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1496 old_index = old_pipe->bottom_pipe->pipe_idx;
1497 else
1498 old_index = -1;
1499 pipe_4to1 = dml_find_split_pipe(dc, context, old_index);
1500 ASSERT(pipe_4to1);
1501 if (!pipe_4to1)
1502 goto validate_fail;
1503 if (!dml_split_stream_for_mpc_or_odm(
1504 dc, &context->res_ctx,
1505 pipe, pipe_4to1, odm))
1506 goto validate_fail;
1507 newly_split[pipe_4to1->pipe_idx] = true;
1508
1509 if (odm && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe
1510 && old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe)
1511 old_index = old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1512 else if (!odm && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1513 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe &&
1514 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1515 old_index = old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1516 else
1517 old_index = -1;
1518 pipe_4to1 = dml_find_split_pipe(dc, context, old_index);
1519 ASSERT(pipe_4to1);
1520 if (!pipe_4to1)
1521 goto validate_fail;
1522 if (!dml_split_stream_for_mpc_or_odm(
1523 dc, &context->res_ctx,
1524 hsplit_pipe, pipe_4to1, odm))
1525 goto validate_fail;
1526 newly_split[pipe_4to1->pipe_idx] = true;
1527 }
1528 if (odm)
1529 dml_build_mapped_resource(dc, context, pipe->stream);
1530 }
1531
1532 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1533 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1534
1535 if (pipe->plane_state) {
1536 if (!resource_build_scaling_params(pipe))
1537 goto validate_fail;
1538 }
1539 }
1540
1541
1542 if (!dml_validate_dsc(dc, context)) {
1543 vba->ValidationStatus[vba->soc.num_states] = DML_FAIL_DSC_VALIDATION_FAILURE;
1544 goto validate_fail;
1545 }
1546
1547 if (repopulate_pipes)
1548 pipe_cnt = dml_populate_dml_pipes_from_context(dc, context, pipes, fast_validate);
1549 *vlevel_out = vlevel;
1550 *pipe_cnt_out = pipe_cnt;
1551
1552 out = true;
1553 goto validate_out;
1554
1555 validate_fail:
1556 out = false;
1557
1558 validate_out:
1559 return out;
1560 }
1561
1562 static void dml_calculate_dlg_params(
1563 struct dc *dc, struct dc_state *context,
1564 display_e2e_pipe_params_st *pipes,
1565 int pipe_cnt,
1566 int vlevel)
1567 {
1568 int i, pipe_idx;
1569 int plane_count;
1570
1571
1572 if (dc->res_pool)
1573 dc->res_pool->funcs->set_mcif_arb_params(dc, context, pipes, pipe_cnt);
1574
1575 context->bw_ctx.bw.dcn.clk.dispclk_khz = context->bw_ctx.dml.vba.DISPCLK * 1000;
1576 context->bw_ctx.bw.dcn.clk.dcfclk_khz = context->bw_ctx.dml.vba.DCFCLK * 1000;
1577 context->bw_ctx.bw.dcn.clk.socclk_khz = context->bw_ctx.dml.vba.SOCCLK * 1000;
1578 context->bw_ctx.bw.dcn.clk.dramclk_khz = context->bw_ctx.dml.vba.DRAMSpeed * 1000 / 16;
1579 context->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz = context->bw_ctx.dml.vba.DCFCLKDeepSleep * 1000;
1580 context->bw_ctx.bw.dcn.clk.fclk_khz = context->bw_ctx.dml.vba.FabricClock * 1000;
1581 context->bw_ctx.bw.dcn.clk.p_state_change_support =
1582 context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb]
1583 != dm_dram_clock_change_unsupported;
1584
1585 context->bw_ctx.bw.dcn.clk.dppclk_khz = 0;
1586
1587
1588
1589
1590 plane_count = 0;
1591 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1592 if (context->res_ctx.pipe_ctx[i].plane_state)
1593 plane_count++;
1594 }
1595
1596
1597
1598
1599
1600 context->bw_ctx.bw.dcn.clk.dtbclk_en = is_dtbclk_required(dc, context);
1601 context->bw_ctx.bw.dcn.clk.fclk_p_state_change_support =
1602 context->bw_ctx.dml.vba.FCLKChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb];
1603 if (context->bw_ctx.bw.dcn.clk.dispclk_khz < dc->debug.min_disp_clk_khz)
1604 context->bw_ctx.bw.dcn.clk.dispclk_khz = dc->debug.min_disp_clk_khz;
1605
1606 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1607 if (!context->res_ctx.pipe_ctx[i].stream)
1608 continue;
1609 pipes[pipe_idx].pipe.dest.vstartup_start = get_vstartup(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx);
1610 pipes[pipe_idx].pipe.dest.vupdate_offset = get_vupdate_offset(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx);
1611 pipes[pipe_idx].pipe.dest.vupdate_width = get_vupdate_width(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx);
1612 pipes[pipe_idx].pipe.dest.vready_offset = get_vready_offset(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx);
1613 if (context->res_ctx.pipe_ctx[i].stream->mall_stream_config.type == SUBVP_PHANTOM) {
1614
1615 context->res_ctx.pipe_ctx[i].det_buffer_size_kb = 0;
1616 context->res_ctx.pipe_ctx[i].unbounded_req = false;
1617 } else {
1618 context->res_ctx.pipe_ctx[i].det_buffer_size_kb = context->bw_ctx.dml.ip.det_buffer_size_kbytes;
1619 context->res_ctx.pipe_ctx[i].unbounded_req = pipes[pipe_idx].pipe.src.unbounded_req_mode;
1620 }
1621
1622 if (context->bw_ctx.bw.dcn.clk.dppclk_khz < pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000)
1623 context->bw_ctx.bw.dcn.clk.dppclk_khz = pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000;
1624 context->res_ctx.pipe_ctx[i].plane_res.bw.dppclk_khz =
1625 pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000;
1626 context->res_ctx.pipe_ctx[i].pipe_dlg_param = pipes[pipe_idx].pipe.dest;
1627 pipe_idx++;
1628 }
1629
1630 context->bw_ctx.bw.dcn.clk.bw_dppclk_khz = context->bw_ctx.bw.dcn.clk.dppclk_khz;
1631 context->bw_ctx.bw.dcn.clk.bw_dispclk_khz = context->bw_ctx.bw.dcn.clk.dispclk_khz;
1632 context->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz = context->bw_ctx.dml.soc.clock_limits[vlevel].dppclk_mhz * 1000;
1633 context->bw_ctx.bw.dcn.clk.max_supported_dispclk_khz = context->bw_ctx.dml.soc.clock_limits[vlevel].dispclk_mhz * 1000;
1634 context->bw_ctx.bw.dcn.compbuf_size_kb = context->bw_ctx.dml.ip.config_return_buffer_size_in_kbytes
1635 - context->bw_ctx.dml.ip.det_buffer_size_kbytes * pipe_idx;
1636
1637 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1638 bool cstate_en = context->bw_ctx.dml.vba.PrefetchMode[vlevel][context->bw_ctx.dml.vba.maxMpcComb] != 2;
1639
1640 if (!context->res_ctx.pipe_ctx[i].stream)
1641 continue;
1642
1643 context->bw_ctx.dml.funcs.rq_dlg_get_dlg_reg(&context->bw_ctx.dml,
1644 &context->res_ctx.pipe_ctx[i].dlg_regs,
1645 &context->res_ctx.pipe_ctx[i].ttu_regs,
1646 pipes,
1647 pipe_cnt,
1648 pipe_idx,
1649 cstate_en,
1650 context->bw_ctx.bw.dcn.clk.p_state_change_support,
1651 false, false, true);
1652
1653 context->bw_ctx.dml.funcs.rq_dlg_get_rq_reg(&context->bw_ctx.dml,
1654 &context->res_ctx.pipe_ctx[i].rq_regs,
1655 &pipes[pipe_idx].pipe);
1656 pipe_idx++;
1657 }
1658 }
1659
1660 static void dml_calculate_wm_and_dlg(
1661 struct dc *dc, struct dc_state *context,
1662 display_e2e_pipe_params_st *pipes,
1663 int pipe_cnt,
1664 int vlevel)
1665 {
1666 int i, pipe_idx, vlevel_temp = 0;
1667
1668 double dcfclk = context->bw_ctx.dml.soc.clock_limits[0].dcfclk_mhz;
1669 double dcfclk_from_validation = context->bw_ctx.dml.vba.DCFCLKState[vlevel][context->bw_ctx.dml.vba.maxMpcComb];
1670 unsigned int min_dram_speed_mts = context->bw_ctx.dml.vba.DRAMSpeed;
1671 bool pstate_en = context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] !=
1672 dm_dram_clock_change_unsupported;
1673
1674
1675
1676
1677
1678
1679
1680
1681 if (context->bw_ctx.dml.soc.num_states > 2) {
1682 vlevel_temp = 2;
1683 dcfclk = context->bw_ctx.dml.soc.clock_limits[2].dcfclk_mhz;
1684 } else
1685 dcfclk = 615;
1686
1687 pipes[0].clks_cfg.voltage = vlevel_temp;
1688 pipes[0].clks_cfg.dcfclk_mhz = dcfclk;
1689 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel_temp].socclk_mhz;
1690
1691 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_B].valid) {
1692 context->bw_ctx.dml.soc.dram_clock_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_B].dml_input.pstate_latency_us;
1693 context->bw_ctx.dml.soc.sr_enter_plus_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_B].dml_input.sr_enter_plus_exit_time_us;
1694 context->bw_ctx.dml.soc.sr_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_B].dml_input.sr_exit_time_us;
1695 }
1696 context->bw_ctx.bw.dcn.watermarks.b.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1697 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns = get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1698 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1699 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns = get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1700 context->bw_ctx.bw.dcn.watermarks.b.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1701 context->bw_ctx.bw.dcn.watermarks.b.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1702 context->bw_ctx.bw.dcn.watermarks.b.frac_urg_bw_flip = get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1703 context->bw_ctx.bw.dcn.watermarks.b.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1704 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717 if (context->bw_ctx.dml.soc.num_states > 2) {
1718 vlevel_temp = 0;
1719 dcfclk = dc->clk_mgr->bw_params->clk_table.entries[0].dcfclk_mhz;
1720 } else
1721 dcfclk = 615;
1722
1723 pipes[0].clks_cfg.voltage = vlevel_temp;
1724 pipes[0].clks_cfg.dcfclk_mhz = dcfclk;
1725 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel_temp].socclk_mhz;
1726
1727 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_D].valid) {
1728 context->bw_ctx.dml.soc.dram_clock_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_D].dml_input.pstate_latency_us;
1729 context->bw_ctx.dml.soc.sr_enter_plus_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_D].dml_input.sr_enter_plus_exit_time_us;
1730 context->bw_ctx.dml.soc.sr_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_D].dml_input.sr_exit_time_us;
1731 }
1732 context->bw_ctx.bw.dcn.watermarks.d.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1733 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns = get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1734 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1735 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns = get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1736 context->bw_ctx.bw.dcn.watermarks.d.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1737 context->bw_ctx.bw.dcn.watermarks.d.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1738 context->bw_ctx.bw.dcn.watermarks.d.frac_urg_bw_flip = get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1739 context->bw_ctx.bw.dcn.watermarks.d.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1740 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].valid) {
1752 unsigned int min_dram_speed_mts_margin = 160;
1753
1754 if ((!pstate_en))
1755 min_dram_speed_mts = dc->clk_mgr->bw_params->clk_table.entries[dc->clk_mgr->bw_params->clk_table.num_entries - 1].memclk_mhz * 16;
1756
1757
1758 for (i = 3; i > 0; i--)
1759 if (min_dram_speed_mts + min_dram_speed_mts_margin > dc->clk_mgr->bw_params->dummy_pstate_table[i].dram_speed_mts)
1760 break;
1761
1762 context->bw_ctx.dml.soc.dram_clock_change_latency_us = dc->clk_mgr->bw_params->dummy_pstate_table[i].dummy_pstate_latency_us;
1763 context->bw_ctx.dml.soc.dummy_pstate_latency_us = dc->clk_mgr->bw_params->dummy_pstate_table[i].dummy_pstate_latency_us;
1764 context->bw_ctx.dml.soc.sr_enter_plus_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].dml_input.sr_enter_plus_exit_time_us;
1765 context->bw_ctx.dml.soc.sr_exit_time_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].dml_input.sr_exit_time_us;
1766 }
1767 context->bw_ctx.bw.dcn.watermarks.c.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1768 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns = get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1769 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1770 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns = get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1771 context->bw_ctx.bw.dcn.watermarks.c.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1772 context->bw_ctx.bw.dcn.watermarks.c.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1773 context->bw_ctx.bw.dcn.watermarks.c.frac_urg_bw_flip = get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1774 context->bw_ctx.bw.dcn.watermarks.c.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1775 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1776
1777
1778
1779
1780 if ((!pstate_en) && (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].valid)) {
1781
1782
1783
1784
1785 context->bw_ctx.bw.dcn.watermarks.a = context->bw_ctx.bw.dcn.watermarks.c;
1786 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 0;
1787 } else {
1788
1789
1790
1791
1792
1793 dml_update_soc_for_wm_a(dc, context);
1794 context->bw_ctx.bw.dcn.watermarks.a.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1795 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns = get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1796 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1797 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1798 context->bw_ctx.bw.dcn.watermarks.a.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1799 context->bw_ctx.bw.dcn.watermarks.a.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1800 context->bw_ctx.bw.dcn.watermarks.a.frac_urg_bw_flip = get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1801 context->bw_ctx.bw.dcn.watermarks.a.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000;
1802 }
1803
1804 pipes[0].clks_cfg.voltage = vlevel;
1805 pipes[0].clks_cfg.dcfclk_mhz = dcfclk_from_validation;
1806 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel].socclk_mhz;
1807
1808 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1809 if (!context->res_ctx.pipe_ctx[i].stream)
1810 continue;
1811
1812 pipes[pipe_idx].clks_cfg.dispclk_mhz = get_dispclk_calculated(&context->bw_ctx.dml, pipes, pipe_cnt);
1813 pipes[pipe_idx].clks_cfg.dppclk_mhz = get_dppclk_calculated(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx);
1814
1815 if (dc->config.forced_clocks) {
1816 pipes[pipe_idx].clks_cfg.dispclk_mhz = context->bw_ctx.dml.soc.clock_limits[0].dispclk_mhz;
1817 pipes[pipe_idx].clks_cfg.dppclk_mhz = context->bw_ctx.dml.soc.clock_limits[0].dppclk_mhz;
1818 }
1819 if (dc->debug.min_disp_clk_khz > pipes[pipe_idx].clks_cfg.dispclk_mhz * 1000)
1820 pipes[pipe_idx].clks_cfg.dispclk_mhz = dc->debug.min_disp_clk_khz / 1000.0;
1821 if (dc->debug.min_dpp_clk_khz > pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000)
1822 pipes[pipe_idx].clks_cfg.dppclk_mhz = dc->debug.min_dpp_clk_khz / 1000.0;
1823
1824 pipe_idx++;
1825 }
1826
1827 context->perf_params.stutter_period_us = context->bw_ctx.dml.vba.StutterPeriod;
1828
1829 dml_calculate_dlg_params(dc, context, pipes, pipe_cnt, vlevel);
1830
1831 if (!pstate_en)
1832
1833 context->bw_ctx.dml.soc.dram_clock_change_latency_us =
1834 dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].dml_input.pstate_latency_us;
1835 }
1836
1837 bool dml_validate(struct dc *dc,
1838 struct dc_state *context,
1839 bool fast_validate)
1840 {
1841 bool out = false;
1842
1843 BW_VAL_TRACE_SETUP();
1844
1845 int vlevel = 0;
1846 int pipe_cnt = 0;
1847 display_e2e_pipe_params_st *pipes = context->bw_ctx.dml.dml_pipe_state;
1848 DC_LOGGER_INIT(dc->ctx->logger);
1849
1850 BW_VAL_TRACE_COUNT();
1851
1852 out = dml_internal_validate(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate);
1853
1854 if (pipe_cnt == 0)
1855 goto validate_out;
1856
1857 if (!out)
1858 goto validate_fail;
1859
1860 BW_VAL_TRACE_END_VOLTAGE_LEVEL();
1861
1862 if (fast_validate) {
1863 BW_VAL_TRACE_SKIP(fast);
1864 goto validate_out;
1865 }
1866
1867 dml_calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
1868
1869 BW_VAL_TRACE_END_WATERMARKS();
1870
1871 goto validate_out;
1872
1873 validate_fail:
1874 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n",
1875 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states]));
1876
1877 BW_VAL_TRACE_SKIP(fail);
1878 out = false;
1879
1880 validate_out:
1881 BW_VAL_TRACE_FINISH();
1882
1883 return out;
1884 }