2 * Copyright 2016 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.
25 #include <linux/delay.h>
27 #include "dm_services.h"
28 #include "basics/dc_common.h"
29 #include "dm_helpers.h"
30 #include "core_types.h"
32 #include "dcn20/dcn20_resource.h"
33 #include "dcn20_hwseq.h"
34 #include "dce/dce_hwseq.h"
35 #include "dcn20/dcn20_dsc.h"
36 #include "dcn20/dcn20_optc.h"
41 #include "timing_generator.h"
47 #include "reg_helper.h"
48 #include "dcn10/dcn10_cm_common.h"
49 #include "vm_helper.h"
51 #include "dc_dmub_srv.h"
52 #include "dce/dmub_hw_lock_mgr.h"
53 #include "hw_sequencer.h"
54 #include "dpcd_defs.h"
55 #include "inc/link_enc_cfg.h"
56 #include "link_hwss.h"
58 #include "dc_state_priv.h"
62 #define DC_LOGGER_INIT(logger) \
63 struct dal_logger *dc_logger = logger
71 #define FN(reg_name, field_name) \
72 hws->shifts->field_name, hws->masks->field_name
74 void dcn20_log_color_state(struct dc *dc,
75 struct dc_log_buffer_ctx *log_ctx)
77 struct dc_context *dc_ctx = dc->ctx;
78 struct resource_pool *pool = dc->res_pool;
81 DTN_INFO("DPP: DGAM mode SHAPER mode 3DLUT mode 3DLUT bit depth"
82 " 3DLUT size RGAM mode GAMUT adjust "
85 "C31 C32 C33 C34 \n");
87 for (i = 0; i < pool->pipe_count; i++) {
88 struct dpp *dpp = pool->dpps[i];
89 struct dcn_dpp_state s = {0};
91 dpp->funcs->dpp_read_state(dpp, &s);
92 dpp->funcs->dpp_get_gamut_remap(dpp, &s.gamut_remap);
97 DTN_INFO("[%2d]: %8s %11s %10s %15s %10s %9s %12s "
98 "%010lld %010lld %010lld %010lld "
99 "%010lld %010lld %010lld %010lld "
100 "%010lld %010lld %010lld %010lld",
102 (s.dgam_lut_mode == 0) ? "Bypass" :
103 ((s.dgam_lut_mode == 1) ? "sRGB" :
104 ((s.dgam_lut_mode == 2) ? "Ycc" :
105 ((s.dgam_lut_mode == 3) ? "RAM" :
106 ((s.dgam_lut_mode == 4) ? "RAM" :
108 (s.shaper_lut_mode == 1) ? "RAM A" :
109 ((s.shaper_lut_mode == 2) ? "RAM B" :
111 (s.lut3d_mode == 1) ? "RAM A" :
112 ((s.lut3d_mode == 2) ? "RAM B" :
114 (s.lut3d_bit_depth <= 0) ? "12-bit" : "10-bit",
115 (s.lut3d_size == 0) ? "17x17x17" : "9x9x9",
116 (s.rgam_lut_mode == 1) ? "RAM A" :
117 ((s.rgam_lut_mode == 1) ? "RAM B" : "Bypass"),
118 (s.gamut_remap.gamut_adjust_type == 0) ? "Bypass" :
119 ((s.gamut_remap.gamut_adjust_type == 1) ? "HW" :
121 s.gamut_remap.temperature_matrix[0].value,
122 s.gamut_remap.temperature_matrix[1].value,
123 s.gamut_remap.temperature_matrix[2].value,
124 s.gamut_remap.temperature_matrix[3].value,
125 s.gamut_remap.temperature_matrix[4].value,
126 s.gamut_remap.temperature_matrix[5].value,
127 s.gamut_remap.temperature_matrix[6].value,
128 s.gamut_remap.temperature_matrix[7].value,
129 s.gamut_remap.temperature_matrix[8].value,
130 s.gamut_remap.temperature_matrix[9].value,
131 s.gamut_remap.temperature_matrix[10].value,
132 s.gamut_remap.temperature_matrix[11].value);
136 DTN_INFO("DPP Color Caps: input_lut_shared:%d icsc:%d"
137 " dgam_ram:%d dgam_rom: srgb:%d,bt2020:%d,gamma2_2:%d,pq:%d,hlg:%d"
138 " post_csc:%d gamcor:%d dgam_rom_for_yuv:%d 3d_lut:%d"
139 " blnd_lut:%d oscs:%d\n\n",
140 dc->caps.color.dpp.input_lut_shared,
141 dc->caps.color.dpp.icsc,
142 dc->caps.color.dpp.dgam_ram,
143 dc->caps.color.dpp.dgam_rom_caps.srgb,
144 dc->caps.color.dpp.dgam_rom_caps.bt2020,
145 dc->caps.color.dpp.dgam_rom_caps.gamma2_2,
146 dc->caps.color.dpp.dgam_rom_caps.pq,
147 dc->caps.color.dpp.dgam_rom_caps.hlg,
148 dc->caps.color.dpp.post_csc,
149 dc->caps.color.dpp.gamma_corr,
150 dc->caps.color.dpp.dgam_rom_for_yuv,
151 dc->caps.color.dpp.hw_3d_lut,
152 dc->caps.color.dpp.ogam_ram,
153 dc->caps.color.dpp.ocsc);
155 DTN_INFO("MPCC: OPP DPP MPCCBOT MODE ALPHA_MODE PREMULT OVERLAP_ONLY IDLE"
158 for (i = 0; i < pool->mpcc_count; i++) {
159 struct mpcc_state s = {0};
161 pool->mpc->funcs->read_mpcc_state(pool->mpc, i, &s);
163 DTN_INFO("[%2d]: %2xh %2xh %6xh %4d %10d %7d %12d %4d %9s\n",
164 i, s.opp_id, s.dpp_id, s.bot_mpcc_id,
165 s.mode, s.alpha_mode, s.pre_multiplied_alpha, s.overlap_only,
167 (s.rgam_mode == 1) ? "RAM A" :
168 ((s.rgam_mode == 2) ? "RAM B" :
172 DTN_INFO("MPC Color Caps: gamut_remap:%d, 3dlut:%d, ogam_ram:%d, ocsc:%d\n\n",
173 dc->caps.color.mpc.gamut_remap,
174 dc->caps.color.mpc.num_3dluts,
175 dc->caps.color.mpc.ogam_ram,
176 dc->caps.color.mpc.ocsc);
180 static int find_free_gsl_group(const struct dc *dc)
182 if (dc->res_pool->gsl_groups.gsl_0 == 0)
184 if (dc->res_pool->gsl_groups.gsl_1 == 0)
186 if (dc->res_pool->gsl_groups.gsl_2 == 0)
192 /* NOTE: This is not a generic setup_gsl function (hence the suffix as_lock)
193 * This is only used to lock pipes in pipe splitting case with immediate flip
194 * Ordinary MPC/OTG locks suppress VUPDATE which doesn't help with immediate,
195 * so we get tearing with freesync since we cannot flip multiple pipes
197 * We use GSL for this:
198 * - immediate flip: find first available GSL group if not already assigned
199 * program gsl with that group, set current OTG as master
200 * and always us 0x4 = AND of flip_ready from all pipes
201 * - vsync flip: disable GSL if used
203 * Groups in stream_res are stored as +1 from HW registers, i.e.
204 * gsl_0 <=> pipe_ctx->stream_res.gsl_group == 1
205 * Using a magic value like -1 would require tracking all inits/resets
207 void dcn20_setup_gsl_group_as_lock(
209 struct pipe_ctx *pipe_ctx,
212 struct gsl_params gsl;
215 memset(&gsl, 0, sizeof(struct gsl_params));
218 /* return if group already assigned since GSL was set up
219 * for vsync flip, we would unassign so it can't be "left over"
221 if (pipe_ctx->stream_res.gsl_group > 0)
224 group_idx = find_free_gsl_group(dc);
225 ASSERT(group_idx != 0);
226 pipe_ctx->stream_res.gsl_group = group_idx;
228 /* set gsl group reg field and mark resource used */
232 dc->res_pool->gsl_groups.gsl_0 = 1;
236 dc->res_pool->gsl_groups.gsl_1 = 1;
240 dc->res_pool->gsl_groups.gsl_2 = 1;
244 return; // invalid case
246 gsl.gsl_master_en = 1;
248 group_idx = pipe_ctx->stream_res.gsl_group;
250 return; // if not in use, just return
252 pipe_ctx->stream_res.gsl_group = 0;
254 /* unset gsl group reg field and mark resource free */
258 dc->res_pool->gsl_groups.gsl_0 = 0;
262 dc->res_pool->gsl_groups.gsl_1 = 0;
266 dc->res_pool->gsl_groups.gsl_2 = 0;
272 gsl.gsl_master_en = 0;
275 /* at this point we want to program whether it's to enable or disable */
276 if (pipe_ctx->stream_res.tg->funcs->set_gsl != NULL &&
277 pipe_ctx->stream_res.tg->funcs->set_gsl_source_select != NULL) {
278 pipe_ctx->stream_res.tg->funcs->set_gsl(
279 pipe_ctx->stream_res.tg,
282 pipe_ctx->stream_res.tg->funcs->set_gsl_source_select(
283 pipe_ctx->stream_res.tg, group_idx, enable ? 4 : 0);
288 void dcn20_set_flip_control_gsl(
289 struct pipe_ctx *pipe_ctx,
292 if (pipe_ctx && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl)
293 pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl(
294 pipe_ctx->plane_res.hubp, flip_immediate);
298 void dcn20_enable_power_gating_plane(
299 struct dce_hwseq *hws,
302 bool force_on = true; /* disable power gating */
303 uint32_t org_ip_request_cntl = 0;
308 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
309 if (org_ip_request_cntl == 0)
310 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
312 /* DCHUBP0/1/2/3/4/5 */
313 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on);
314 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN2_POWER_FORCEON, force_on);
315 REG_UPDATE(DOMAIN4_PG_CONFIG, DOMAIN4_POWER_FORCEON, force_on);
316 REG_UPDATE(DOMAIN6_PG_CONFIG, DOMAIN6_POWER_FORCEON, force_on);
317 if (REG(DOMAIN8_PG_CONFIG))
318 REG_UPDATE(DOMAIN8_PG_CONFIG, DOMAIN8_POWER_FORCEON, force_on);
319 if (REG(DOMAIN10_PG_CONFIG))
320 REG_UPDATE(DOMAIN10_PG_CONFIG, DOMAIN8_POWER_FORCEON, force_on);
323 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN1_POWER_FORCEON, force_on);
324 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN3_POWER_FORCEON, force_on);
325 REG_UPDATE(DOMAIN5_PG_CONFIG, DOMAIN5_POWER_FORCEON, force_on);
326 REG_UPDATE(DOMAIN7_PG_CONFIG, DOMAIN7_POWER_FORCEON, force_on);
327 if (REG(DOMAIN9_PG_CONFIG))
328 REG_UPDATE(DOMAIN9_PG_CONFIG, DOMAIN9_POWER_FORCEON, force_on);
329 if (REG(DOMAIN11_PG_CONFIG))
330 REG_UPDATE(DOMAIN11_PG_CONFIG, DOMAIN9_POWER_FORCEON, force_on);
333 REG_UPDATE(DOMAIN16_PG_CONFIG, DOMAIN16_POWER_FORCEON, force_on);
334 REG_UPDATE(DOMAIN17_PG_CONFIG, DOMAIN17_POWER_FORCEON, force_on);
335 REG_UPDATE(DOMAIN18_PG_CONFIG, DOMAIN18_POWER_FORCEON, force_on);
336 if (REG(DOMAIN19_PG_CONFIG))
337 REG_UPDATE(DOMAIN19_PG_CONFIG, DOMAIN19_POWER_FORCEON, force_on);
338 if (REG(DOMAIN20_PG_CONFIG))
339 REG_UPDATE(DOMAIN20_PG_CONFIG, DOMAIN20_POWER_FORCEON, force_on);
340 if (REG(DOMAIN21_PG_CONFIG))
341 REG_UPDATE(DOMAIN21_PG_CONFIG, DOMAIN21_POWER_FORCEON, force_on);
343 if (org_ip_request_cntl == 0)
344 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
348 void dcn20_dccg_init(struct dce_hwseq *hws)
351 * set MICROSECOND_TIME_BASE_DIV
352 * 100Mhz refclk -> 0x120264
353 * 27Mhz refclk -> 0x12021b
354 * 48Mhz refclk -> 0x120230
357 REG_WRITE(MICROSECOND_TIME_BASE_DIV, 0x120264);
360 * set MILLISECOND_TIME_BASE_DIV
361 * 100Mhz refclk -> 0x1186a0
362 * 27Mhz refclk -> 0x106978
363 * 48Mhz refclk -> 0x10bb80
366 REG_WRITE(MILLISECOND_TIME_BASE_DIV, 0x1186a0);
368 /* This value is dependent on the hardware pipeline delay so set once per SOC */
369 REG_WRITE(DISPCLK_FREQ_CHANGE_CNTL, 0xe01003c);
372 void dcn20_disable_vga(
373 struct dce_hwseq *hws)
375 REG_WRITE(D1VGA_CONTROL, 0);
376 REG_WRITE(D2VGA_CONTROL, 0);
377 REG_WRITE(D3VGA_CONTROL, 0);
378 REG_WRITE(D4VGA_CONTROL, 0);
379 REG_WRITE(D5VGA_CONTROL, 0);
380 REG_WRITE(D6VGA_CONTROL, 0);
383 void dcn20_program_triple_buffer(
385 struct pipe_ctx *pipe_ctx,
386 bool enable_triple_buffer)
388 if (pipe_ctx->plane_res.hubp && pipe_ctx->plane_res.hubp->funcs) {
389 pipe_ctx->plane_res.hubp->funcs->hubp_enable_tripleBuffer(
390 pipe_ctx->plane_res.hubp,
391 enable_triple_buffer);
395 /* Blank pixel data during initialization */
396 void dcn20_init_blank(
398 struct timing_generator *tg)
400 struct dce_hwseq *hws = dc->hwseq;
401 enum dc_color_space color_space;
402 struct tg_color black_color = {0};
403 struct output_pixel_processor *opp = NULL;
404 struct output_pixel_processor *bottom_opp = NULL;
405 uint32_t num_opps, opp_id_src0, opp_id_src1;
406 uint32_t otg_active_width = 0, otg_active_height = 0;
408 /* program opp dpg blank color */
409 color_space = COLOR_SPACE_SRGB;
410 color_space_to_black_color(dc, color_space, &black_color);
412 /* get the OTG active size */
413 tg->funcs->get_otg_active_size(tg,
417 /* get the OPTC source */
418 tg->funcs->get_optc_source(tg, &num_opps, &opp_id_src0, &opp_id_src1);
420 if (opp_id_src0 >= dc->res_pool->res_cap->num_opp) {
424 opp = dc->res_pool->opps[opp_id_src0];
426 /* don't override the blank pattern if already enabled with the correct one. */
427 if (opp->funcs->dpg_is_blanked && opp->funcs->dpg_is_blanked(opp))
431 otg_active_width = otg_active_width / 2;
433 if (opp_id_src1 >= dc->res_pool->res_cap->num_opp) {
437 bottom_opp = dc->res_pool->opps[opp_id_src1];
440 opp->funcs->opp_set_disp_pattern_generator(
442 CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
443 CONTROLLER_DP_COLOR_SPACE_UDEFINED,
444 COLOR_DEPTH_UNDEFINED,
451 bottom_opp->funcs->opp_set_disp_pattern_generator(
453 CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
454 CONTROLLER_DP_COLOR_SPACE_UDEFINED,
455 COLOR_DEPTH_UNDEFINED,
462 hws->funcs.wait_for_blank_complete(opp);
465 void dcn20_dsc_pg_control(
466 struct dce_hwseq *hws,
467 unsigned int dsc_inst,
470 uint32_t power_gate = power_on ? 0 : 1;
471 uint32_t pwr_status = power_on ? 0 : 2;
472 uint32_t org_ip_request_cntl = 0;
474 if (hws->ctx->dc->debug.disable_dsc_power_gate)
477 if (REG(DOMAIN16_PG_CONFIG) == 0)
480 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
481 if (org_ip_request_cntl == 0)
482 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
486 REG_UPDATE(DOMAIN16_PG_CONFIG,
487 DOMAIN16_POWER_GATE, power_gate);
489 REG_WAIT(DOMAIN16_PG_STATUS,
490 DOMAIN16_PGFSM_PWR_STATUS, pwr_status,
494 REG_UPDATE(DOMAIN17_PG_CONFIG,
495 DOMAIN17_POWER_GATE, power_gate);
497 REG_WAIT(DOMAIN17_PG_STATUS,
498 DOMAIN17_PGFSM_PWR_STATUS, pwr_status,
502 REG_UPDATE(DOMAIN18_PG_CONFIG,
503 DOMAIN18_POWER_GATE, power_gate);
505 REG_WAIT(DOMAIN18_PG_STATUS,
506 DOMAIN18_PGFSM_PWR_STATUS, pwr_status,
510 REG_UPDATE(DOMAIN19_PG_CONFIG,
511 DOMAIN19_POWER_GATE, power_gate);
513 REG_WAIT(DOMAIN19_PG_STATUS,
514 DOMAIN19_PGFSM_PWR_STATUS, pwr_status,
518 REG_UPDATE(DOMAIN20_PG_CONFIG,
519 DOMAIN20_POWER_GATE, power_gate);
521 REG_WAIT(DOMAIN20_PG_STATUS,
522 DOMAIN20_PGFSM_PWR_STATUS, pwr_status,
526 REG_UPDATE(DOMAIN21_PG_CONFIG,
527 DOMAIN21_POWER_GATE, power_gate);
529 REG_WAIT(DOMAIN21_PG_STATUS,
530 DOMAIN21_PGFSM_PWR_STATUS, pwr_status,
538 if (org_ip_request_cntl == 0)
539 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
542 void dcn20_dpp_pg_control(
543 struct dce_hwseq *hws,
544 unsigned int dpp_inst,
547 uint32_t power_gate = power_on ? 0 : 1;
548 uint32_t pwr_status = power_on ? 0 : 2;
550 if (hws->ctx->dc->debug.disable_dpp_power_gate)
552 if (REG(DOMAIN1_PG_CONFIG) == 0)
557 REG_UPDATE(DOMAIN1_PG_CONFIG,
558 DOMAIN1_POWER_GATE, power_gate);
560 REG_WAIT(DOMAIN1_PG_STATUS,
561 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
565 REG_UPDATE(DOMAIN3_PG_CONFIG,
566 DOMAIN3_POWER_GATE, power_gate);
568 REG_WAIT(DOMAIN3_PG_STATUS,
569 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
573 REG_UPDATE(DOMAIN5_PG_CONFIG,
574 DOMAIN5_POWER_GATE, power_gate);
576 REG_WAIT(DOMAIN5_PG_STATUS,
577 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
581 REG_UPDATE(DOMAIN7_PG_CONFIG,
582 DOMAIN7_POWER_GATE, power_gate);
584 REG_WAIT(DOMAIN7_PG_STATUS,
585 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
589 REG_UPDATE(DOMAIN9_PG_CONFIG,
590 DOMAIN9_POWER_GATE, power_gate);
592 REG_WAIT(DOMAIN9_PG_STATUS,
593 DOMAIN9_PGFSM_PWR_STATUS, pwr_status,
598 * Do not power gate DPP5, should be left at HW default, power on permanently.
599 * PG on Pipe5 is De-featured, attempting to put it to PG state may result in hard
601 * REG_UPDATE(DOMAIN11_PG_CONFIG,
602 * DOMAIN11_POWER_GATE, power_gate);
604 * REG_WAIT(DOMAIN11_PG_STATUS,
605 * DOMAIN11_PGFSM_PWR_STATUS, pwr_status,
616 void dcn20_hubp_pg_control(
617 struct dce_hwseq *hws,
618 unsigned int hubp_inst,
621 uint32_t power_gate = power_on ? 0 : 1;
622 uint32_t pwr_status = power_on ? 0 : 2;
624 if (hws->ctx->dc->debug.disable_hubp_power_gate)
626 if (REG(DOMAIN0_PG_CONFIG) == 0)
630 case 0: /* DCHUBP0 */
631 REG_UPDATE(DOMAIN0_PG_CONFIG,
632 DOMAIN0_POWER_GATE, power_gate);
634 REG_WAIT(DOMAIN0_PG_STATUS,
635 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
638 case 1: /* DCHUBP1 */
639 REG_UPDATE(DOMAIN2_PG_CONFIG,
640 DOMAIN2_POWER_GATE, power_gate);
642 REG_WAIT(DOMAIN2_PG_STATUS,
643 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
646 case 2: /* DCHUBP2 */
647 REG_UPDATE(DOMAIN4_PG_CONFIG,
648 DOMAIN4_POWER_GATE, power_gate);
650 REG_WAIT(DOMAIN4_PG_STATUS,
651 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
654 case 3: /* DCHUBP3 */
655 REG_UPDATE(DOMAIN6_PG_CONFIG,
656 DOMAIN6_POWER_GATE, power_gate);
658 REG_WAIT(DOMAIN6_PG_STATUS,
659 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
662 case 4: /* DCHUBP4 */
663 REG_UPDATE(DOMAIN8_PG_CONFIG,
664 DOMAIN8_POWER_GATE, power_gate);
666 REG_WAIT(DOMAIN8_PG_STATUS,
667 DOMAIN8_PGFSM_PWR_STATUS, pwr_status,
670 case 5: /* DCHUBP5 */
672 * Do not power gate DCHUB5, should be left at HW default, power on permanently.
673 * PG on Pipe5 is De-featured, attempting to put it to PG state may result in hard
675 * REG_UPDATE(DOMAIN10_PG_CONFIG,
676 * DOMAIN10_POWER_GATE, power_gate);
678 * REG_WAIT(DOMAIN10_PG_STATUS,
679 * DOMAIN10_PGFSM_PWR_STATUS, pwr_status,
690 /* disable HW used by plane.
691 * note: cannot disable until disconnect is complete
693 void dcn20_plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
695 struct dce_hwseq *hws = dc->hwseq;
696 struct hubp *hubp = pipe_ctx->plane_res.hubp;
697 struct dpp *dpp = pipe_ctx->plane_res.dpp;
699 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
701 /* In flip immediate with pipe splitting case GSL is used for
702 * synchronization so we must disable it when the plane is disabled.
704 if (pipe_ctx->stream_res.gsl_group != 0)
705 dcn20_setup_gsl_group_as_lock(dc, pipe_ctx, false);
707 if (hubp->funcs->hubp_update_mall_sel)
708 hubp->funcs->hubp_update_mall_sel(hubp, 0, false);
710 dc->hwss.set_flip_control_gsl(pipe_ctx, false);
712 hubp->funcs->hubp_clk_cntl(hubp, false);
714 dpp->funcs->dpp_dppclk_control(dpp, false, false);
716 hubp->power_gated = true;
718 hws->funcs.plane_atomic_power_down(dc,
719 pipe_ctx->plane_res.dpp,
720 pipe_ctx->plane_res.hubp);
722 pipe_ctx->stream = NULL;
723 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
724 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
725 pipe_ctx->top_pipe = NULL;
726 pipe_ctx->bottom_pipe = NULL;
727 pipe_ctx->prev_odm_pipe = NULL;
728 pipe_ctx->next_odm_pipe = NULL;
729 pipe_ctx->plane_state = NULL;
733 void dcn20_disable_plane(struct dc *dc, struct dc_state *state, struct pipe_ctx *pipe_ctx)
735 bool is_phantom = dc_state_get_pipe_subvp_type(state, pipe_ctx) == SUBVP_PHANTOM;
736 struct timing_generator *tg = is_phantom ? pipe_ctx->stream_res.tg : NULL;
738 DC_LOGGER_INIT(dc->ctx->logger);
740 if (!pipe_ctx->plane_res.hubp || pipe_ctx->plane_res.hubp->power_gated)
743 dcn20_plane_atomic_disable(dc, pipe_ctx);
745 /* Turn back off the phantom OTG after the phantom plane is fully disabled
748 if (tg && tg->funcs->disable_phantom_crtc)
749 tg->funcs->disable_phantom_crtc(tg);
751 DC_LOG_DC("Power down front end %d\n",
755 void dcn20_disable_pixel_data(struct dc *dc, struct pipe_ctx *pipe_ctx, bool blank)
757 dcn20_blank_pixel_data(dc, pipe_ctx, blank);
760 static int calc_mpc_flow_ctrl_cnt(const struct dc_stream_state *stream,
761 int opp_cnt, bool is_two_pixels_per_container)
763 bool hblank_halved = is_two_pixels_per_container;
767 hblank_halved = true;
769 flow_ctrl_cnt = stream->timing.h_total - stream->timing.h_addressable -
770 stream->timing.h_border_left -
771 stream->timing.h_border_right;
776 /* ODM combine 4:1 case */
780 return flow_ctrl_cnt;
783 static enum phyd32clk_clock_source get_phyd32clk_src(struct dc_link *link)
785 switch (link->link_enc->transmitter) {
786 case TRANSMITTER_UNIPHY_A:
788 case TRANSMITTER_UNIPHY_B:
790 case TRANSMITTER_UNIPHY_C:
792 case TRANSMITTER_UNIPHY_D:
794 case TRANSMITTER_UNIPHY_E:
801 static int get_odm_segment_count(struct pipe_ctx *pipe_ctx)
803 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
806 while (odm_pipe != NULL) {
808 odm_pipe = odm_pipe->next_odm_pipe;
814 enum dc_status dcn20_enable_stream_timing(
815 struct pipe_ctx *pipe_ctx,
816 struct dc_state *context,
819 struct dce_hwseq *hws = dc->hwseq;
820 struct dc_stream_state *stream = pipe_ctx->stream;
821 struct drr_params params = {0};
822 unsigned int event_triggers = 0;
824 int opp_inst[MAX_PIPES] = {0};
825 bool interlace = stream->timing.flags.INTERLACE;
827 struct mpc_dwb_flow_control flow_control;
828 struct mpc *mpc = dc->res_pool->mpc;
829 bool is_two_pixels_per_container =
830 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing);
831 bool rate_control_2x_pclk = (interlace || is_two_pixels_per_container);
833 int last_odm_slice_width;
834 struct pipe_ctx *opp_heads[MAX_PIPES];
836 if (dc->res_pool->dccg->funcs->set_pixel_rate_div)
837 dc->res_pool->dccg->funcs->set_pixel_rate_div(
839 pipe_ctx->stream_res.tg->inst,
840 pipe_ctx->pixel_rate_divider.div_factor1,
841 pipe_ctx->pixel_rate_divider.div_factor2);
843 /* by upper caller loop, pipe0 is parent pipe and be called first.
844 * back end is set up by for pipe0. Other children pipe share back end
845 * with pipe 0. No program is needed.
847 if (pipe_ctx->top_pipe != NULL)
850 /* TODO check if timing_changed, disable stream if timing changed */
852 opp_cnt = resource_get_opp_heads_for_otg_master(pipe_ctx, &context->res_ctx, opp_heads);
853 for (i = 0; i < opp_cnt; i++)
854 opp_inst[i] = opp_heads[i]->stream_res.opp->inst;
856 odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, false);
857 last_odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, true);
859 pipe_ctx->stream_res.tg->funcs->set_odm_combine(
860 pipe_ctx->stream_res.tg,
861 opp_inst, opp_cnt, odm_slice_width,
862 last_odm_slice_width);
864 /* HW program guide assume display already disable
865 * by unplug sequence. OTG assume stop.
867 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
869 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
870 pipe_ctx->clock_source,
871 &pipe_ctx->stream_res.pix_clk_params,
872 dc->link_srv->dp_get_encoding_format(&pipe_ctx->link_config.dp_link_settings),
873 &pipe_ctx->pll_settings)) {
875 return DC_ERROR_UNEXPECTED;
878 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
879 struct dccg *dccg = dc->res_pool->dccg;
880 struct timing_generator *tg = pipe_ctx->stream_res.tg;
881 struct dtbclk_dto_params dto_params = {0};
883 if (dccg->funcs->set_dtbclk_p_src)
884 dccg->funcs->set_dtbclk_p_src(dccg, DTBCLK0, tg->inst);
886 dto_params.otg_inst = tg->inst;
887 dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10;
888 dto_params.num_odm_segments = get_odm_segment_count(pipe_ctx);
889 dto_params.timing = &pipe_ctx->stream->timing;
890 dto_params.ref_dtbclk_khz = dc->clk_mgr->funcs->get_dtb_ref_clk_frequency(dc->clk_mgr);
891 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
894 if (dc_is_hdmi_tmds_signal(stream->signal)) {
895 stream->link->phy_state.symclk_ref_cnts.otg = 1;
896 if (stream->link->phy_state.symclk_state == SYMCLK_OFF_TX_OFF)
897 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
899 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
902 if (dc->hwseq->funcs.PLAT_58856_wa && (!dc_is_dp_signal(stream->signal)))
903 dc->hwseq->funcs.PLAT_58856_wa(context, pipe_ctx);
905 pipe_ctx->stream_res.tg->funcs->program_timing(
906 pipe_ctx->stream_res.tg,
908 pipe_ctx->pipe_dlg_param.vready_offset,
909 pipe_ctx->pipe_dlg_param.vstartup_start,
910 pipe_ctx->pipe_dlg_param.vupdate_offset,
911 pipe_ctx->pipe_dlg_param.vupdate_width,
912 pipe_ctx->pipe_dlg_param.pstate_keepout,
913 pipe_ctx->stream->signal,
916 rate_control_2x_pclk = rate_control_2x_pclk || opp_cnt > 1;
917 flow_control.flow_ctrl_mode = 0;
918 flow_control.flow_ctrl_cnt0 = 0x80;
919 flow_control.flow_ctrl_cnt1 = calc_mpc_flow_ctrl_cnt(stream, opp_cnt,
920 is_two_pixels_per_container);
921 if (mpc->funcs->set_out_rate_control) {
922 for (i = 0; i < opp_cnt; ++i) {
923 mpc->funcs->set_out_rate_control(
926 rate_control_2x_pclk,
931 for (i = 0; i < opp_cnt; i++) {
932 opp_heads[i]->stream_res.opp->funcs->opp_pipe_clock_control(
933 opp_heads[i]->stream_res.opp,
935 opp_heads[i]->stream_res.opp->funcs->opp_program_left_edge_extra_pixel(
936 opp_heads[i]->stream_res.opp,
937 stream->timing.pixel_encoding,
938 resource_is_pipe_type(opp_heads[i], OTG_MASTER));
941 hws->funcs.blank_pixel_data(dc, pipe_ctx, true);
943 /* VTG is within DCHUB command block. DCFCLK is always on */
944 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
946 return DC_ERROR_UNEXPECTED;
949 hws->funcs.wait_for_blank_complete(pipe_ctx->stream_res.opp);
951 params.vertical_total_min = stream->adjust.v_total_min;
952 params.vertical_total_max = stream->adjust.v_total_max;
953 params.vertical_total_mid = stream->adjust.v_total_mid;
954 params.vertical_total_mid_frame_num = stream->adjust.v_total_mid_frame_num;
955 if (pipe_ctx->stream_res.tg->funcs->set_drr)
956 pipe_ctx->stream_res.tg->funcs->set_drr(
957 pipe_ctx->stream_res.tg, ¶ms);
959 // DRR should set trigger event to monitor surface update event
960 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
961 event_triggers = 0x80;
962 /* Event triggers and num frames initialized for DRR, but can be
963 * later updated for PSR use. Note DRR trigger events are generated
964 * regardless of whether num frames met.
966 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
967 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
968 pipe_ctx->stream_res.tg, event_triggers, 2);
970 /* TODO program crtc source select for non-virtual signal*/
971 /* TODO program FMT */
972 /* TODO setup link_enc */
973 /* TODO set stream attributes */
974 /* TODO program audio */
975 /* TODO enable stream if timing changed */
976 /* TODO unblank stream if DP */
978 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) == SUBVP_PHANTOM) {
979 if (pipe_ctx->stream_res.tg->funcs->phantom_crtc_post_enable)
980 pipe_ctx->stream_res.tg->funcs->phantom_crtc_post_enable(pipe_ctx->stream_res.tg);
986 void dcn20_program_output_csc(struct dc *dc,
987 struct pipe_ctx *pipe_ctx,
988 enum dc_color_space colorspace,
992 struct mpc *mpc = dc->res_pool->mpc;
993 enum mpc_output_csc_mode ocsc_mode = MPC_OUTPUT_CSC_COEF_A;
994 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
996 if (mpc->funcs->power_on_mpc_mem_pwr)
997 mpc->funcs->power_on_mpc_mem_pwr(mpc, mpcc_id, true);
999 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1000 if (mpc->funcs->set_output_csc != NULL)
1001 mpc->funcs->set_output_csc(mpc,
1006 if (mpc->funcs->set_ocsc_default != NULL)
1007 mpc->funcs->set_ocsc_default(mpc,
1014 bool dcn20_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
1015 const struct dc_stream_state *stream)
1017 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
1018 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
1019 const struct pwl_params *params = NULL;
1021 * program OGAM only for the top pipe
1022 * if there is a pipe split then fix diagnostic is required:
1023 * how to pass OGAM parameter for stream.
1024 * if programming for all pipes is required then remove condition
1025 * pipe_ctx->top_pipe == NULL ,but then fix the diagnostic.
1027 if (mpc->funcs->power_on_mpc_mem_pwr)
1028 mpc->funcs->power_on_mpc_mem_pwr(mpc, mpcc_id, true);
1029 if (pipe_ctx->top_pipe == NULL
1030 && mpc->funcs->set_output_gamma) {
1031 if (stream->out_transfer_func.type == TF_TYPE_HWPWL)
1032 params = &stream->out_transfer_func.pwl;
1033 else if (pipe_ctx->stream->out_transfer_func.type ==
1034 TF_TYPE_DISTRIBUTED_POINTS &&
1035 cm_helper_translate_curve_to_hw_format(dc->ctx,
1036 &stream->out_transfer_func,
1037 &mpc->blender_params, false))
1038 params = &mpc->blender_params;
1042 if (stream->out_transfer_func.type == TF_TYPE_PREDEFINED)
1043 BREAK_TO_DEBUGGER();
1046 * if above if is not executed then 'params' equal to 0 and set in bypass
1048 if (mpc->funcs->set_output_gamma)
1049 mpc->funcs->set_output_gamma(mpc, mpcc_id, params);
1054 bool dcn20_set_blend_lut(
1055 struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state)
1057 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1059 const struct pwl_params *blend_lut = NULL;
1061 if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
1062 blend_lut = &plane_state->blend_tf.pwl;
1063 else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
1064 cm_helper_translate_curve_to_hw_format(plane_state->ctx,
1065 &plane_state->blend_tf,
1066 &dpp_base->regamma_params, false);
1067 blend_lut = &dpp_base->regamma_params;
1069 result = dpp_base->funcs->dpp_program_blnd_lut(dpp_base, blend_lut);
1074 bool dcn20_set_shaper_3dlut(
1075 struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state)
1077 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1079 const struct pwl_params *shaper_lut = NULL;
1081 if (plane_state->in_shaper_func.type == TF_TYPE_HWPWL)
1082 shaper_lut = &plane_state->in_shaper_func.pwl;
1083 else if (plane_state->in_shaper_func.type == TF_TYPE_DISTRIBUTED_POINTS) {
1084 cm_helper_translate_curve_to_hw_format(plane_state->ctx,
1085 &plane_state->in_shaper_func,
1086 &dpp_base->shaper_params, true);
1087 shaper_lut = &dpp_base->shaper_params;
1090 result = dpp_base->funcs->dpp_program_shaper_lut(dpp_base, shaper_lut);
1091 if (plane_state->lut3d_func.state.bits.initialized == 1)
1092 result = dpp_base->funcs->dpp_program_3dlut(dpp_base,
1093 &plane_state->lut3d_func.lut_3d);
1095 result = dpp_base->funcs->dpp_program_3dlut(dpp_base, NULL);
1100 bool dcn20_set_input_transfer_func(struct dc *dc,
1101 struct pipe_ctx *pipe_ctx,
1102 const struct dc_plane_state *plane_state)
1104 struct dce_hwseq *hws = dc->hwseq;
1105 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1106 const struct dc_transfer_func *tf = NULL;
1108 bool use_degamma_ram = false;
1110 if (dpp_base == NULL || plane_state == NULL)
1113 hws->funcs.set_shaper_3dlut(pipe_ctx, plane_state);
1114 hws->funcs.set_blend_lut(pipe_ctx, plane_state);
1116 tf = &plane_state->in_transfer_func;
1118 if (tf->type == TF_TYPE_HWPWL || tf->type == TF_TYPE_DISTRIBUTED_POINTS)
1119 use_degamma_ram = true;
1121 if (use_degamma_ram == true) {
1122 if (tf->type == TF_TYPE_HWPWL)
1123 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base,
1125 else if (tf->type == TF_TYPE_DISTRIBUTED_POINTS) {
1126 cm_helper_translate_curve_to_degamma_hw_format(tf,
1127 &dpp_base->degamma_params);
1128 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base,
1129 &dpp_base->degamma_params);
1133 /* handle here the optimized cases when de-gamma ROM could be used.
1136 if (tf->type == TF_TYPE_PREDEFINED) {
1138 case TRANSFER_FUNCTION_SRGB:
1139 dpp_base->funcs->dpp_set_degamma(dpp_base,
1140 IPP_DEGAMMA_MODE_HW_sRGB);
1142 case TRANSFER_FUNCTION_BT709:
1143 dpp_base->funcs->dpp_set_degamma(dpp_base,
1144 IPP_DEGAMMA_MODE_HW_xvYCC);
1146 case TRANSFER_FUNCTION_LINEAR:
1147 dpp_base->funcs->dpp_set_degamma(dpp_base,
1148 IPP_DEGAMMA_MODE_BYPASS);
1150 case TRANSFER_FUNCTION_PQ:
1151 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_USER_PWL);
1152 cm_helper_translate_curve_to_degamma_hw_format(tf, &dpp_base->degamma_params);
1153 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base, &dpp_base->degamma_params);
1160 } else if (tf->type == TF_TYPE_BYPASS)
1161 dpp_base->funcs->dpp_set_degamma(dpp_base,
1162 IPP_DEGAMMA_MODE_BYPASS);
1165 * if we are here, we did not handle correctly.
1166 * fix is required for this use case
1168 BREAK_TO_DEBUGGER();
1169 dpp_base->funcs->dpp_set_degamma(dpp_base,
1170 IPP_DEGAMMA_MODE_BYPASS);
1176 void dcn20_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
1178 struct pipe_ctx *odm_pipe;
1180 int opp_inst[MAX_PIPES] = { pipe_ctx->stream_res.opp->inst };
1181 int odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, false);
1182 int last_odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, true);
1184 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
1185 opp_inst[opp_cnt] = odm_pipe->stream_res.opp->inst;
1190 pipe_ctx->stream_res.tg->funcs->set_odm_combine(
1191 pipe_ctx->stream_res.tg,
1193 odm_slice_width, last_odm_slice_width);
1195 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
1196 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
1199 void dcn20_blank_pixel_data(
1201 struct pipe_ctx *pipe_ctx,
1204 struct tg_color black_color = {0};
1205 struct stream_resource *stream_res = &pipe_ctx->stream_res;
1206 struct dc_stream_state *stream = pipe_ctx->stream;
1207 enum dc_color_space color_space = stream->output_color_space;
1208 enum controller_dp_test_pattern test_pattern = CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR;
1209 enum controller_dp_color_space test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED;
1210 struct pipe_ctx *odm_pipe;
1211 struct rect odm_slice_src;
1213 if (stream->link->test_pattern_enabled)
1216 /* get opp dpg blank color */
1217 color_space_to_black_color(dc, color_space, &black_color);
1220 dc->hwss.set_abm_immediate_disable(pipe_ctx);
1222 if (dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE) {
1223 test_pattern = CONTROLLER_DP_TEST_PATTERN_COLORSQUARES;
1224 test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_RGB;
1227 test_pattern = CONTROLLER_DP_TEST_PATTERN_VIDEOMODE;
1230 odm_pipe = pipe_ctx;
1232 while (odm_pipe->next_odm_pipe) {
1233 odm_slice_src = resource_get_odm_slice_src_rect(odm_pipe);
1234 dc->hwss.set_disp_pattern_generator(dc,
1237 test_pattern_color_space,
1238 stream->timing.display_color_depth,
1240 odm_slice_src.width,
1241 odm_slice_src.height,
1243 odm_pipe = odm_pipe->next_odm_pipe;
1246 odm_slice_src = resource_get_odm_slice_src_rect(odm_pipe);
1247 dc->hwss.set_disp_pattern_generator(dc,
1250 test_pattern_color_space,
1251 stream->timing.display_color_depth,
1253 odm_slice_src.width,
1254 odm_slice_src.height,
1258 if (stream_res->abm) {
1259 dc->hwss.set_pipe(pipe_ctx);
1260 stream_res->abm->funcs->set_abm_level(stream_res->abm, stream->abm_level);
1265 static void dcn20_power_on_plane_resources(
1266 struct dce_hwseq *hws,
1267 struct pipe_ctx *pipe_ctx)
1269 DC_LOGGER_INIT(hws->ctx->logger);
1271 if (hws->funcs.dpp_root_clock_control)
1272 hws->funcs.dpp_root_clock_control(hws, pipe_ctx->plane_res.dpp->inst, true);
1274 if (REG(DC_IP_REQUEST_CNTL)) {
1275 REG_SET(DC_IP_REQUEST_CNTL, 0,
1278 if (hws->funcs.dpp_pg_control)
1279 hws->funcs.dpp_pg_control(hws, pipe_ctx->plane_res.dpp->inst, true);
1281 if (hws->funcs.hubp_pg_control)
1282 hws->funcs.hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, true);
1284 REG_SET(DC_IP_REQUEST_CNTL, 0,
1287 "Un-gated front end for pipe %d\n", pipe_ctx->plane_res.hubp->inst);
1291 void dcn20_enable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx,
1292 struct dc_state *context)
1294 //if (dc->debug.sanity_checks) {
1295 // dcn10_verify_allow_pstate_change_high(dc);
1297 dcn20_power_on_plane_resources(dc->hwseq, pipe_ctx);
1299 /* enable DCFCLK current DCHUB */
1300 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true);
1302 /* initialize HUBP on power up */
1303 pipe_ctx->plane_res.hubp->funcs->hubp_init(pipe_ctx->plane_res.hubp);
1305 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1306 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
1307 pipe_ctx->stream_res.opp,
1310 /* TODO: enable/disable in dm as per update type.
1312 DC_LOG_DC(dc->ctx->logger,
1313 "Pipe:%d 0x%x: addr hi:0x%x, "
1316 " %d; dst: %d, %d, %d, %d;\n",
1319 plane_state->address.grph.addr.high_part,
1320 plane_state->address.grph.addr.low_part,
1321 plane_state->src_rect.x,
1322 plane_state->src_rect.y,
1323 plane_state->src_rect.width,
1324 plane_state->src_rect.height,
1325 plane_state->dst_rect.x,
1326 plane_state->dst_rect.y,
1327 plane_state->dst_rect.width,
1328 plane_state->dst_rect.height);
1330 DC_LOG_DC(dc->ctx->logger,
1331 "Pipe %d: width, height, x, y format:%d\n"
1332 "viewport:%d, %d, %d, %d\n"
1333 "recout: %d, %d, %d, %d\n",
1335 plane_state->format,
1336 pipe_ctx->plane_res.scl_data.viewport.width,
1337 pipe_ctx->plane_res.scl_data.viewport.height,
1338 pipe_ctx->plane_res.scl_data.viewport.x,
1339 pipe_ctx->plane_res.scl_data.viewport.y,
1340 pipe_ctx->plane_res.scl_data.recout.width,
1341 pipe_ctx->plane_res.scl_data.recout.height,
1342 pipe_ctx->plane_res.scl_data.recout.x,
1343 pipe_ctx->plane_res.scl_data.recout.y);
1344 print_rq_dlg_ttu(dc, pipe_ctx);
1347 if (dc->vm_pa_config.valid) {
1348 struct vm_system_aperture_param apt;
1350 apt.sys_default.quad_part = 0;
1352 apt.sys_low.quad_part = dc->vm_pa_config.system_aperture.start_addr;
1353 apt.sys_high.quad_part = dc->vm_pa_config.system_aperture.end_addr;
1355 // Program system aperture settings
1356 pipe_ctx->plane_res.hubp->funcs->hubp_set_vm_system_aperture_settings(pipe_ctx->plane_res.hubp, &apt);
1359 if (!pipe_ctx->top_pipe
1360 && pipe_ctx->plane_state
1361 && pipe_ctx->plane_state->flip_int_enabled
1362 && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_int)
1363 pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_int(pipe_ctx->plane_res.hubp);
1365 // if (dc->debug.sanity_checks) {
1366 // dcn10_verify_allow_pstate_change_high(dc);
1370 void dcn20_pipe_control_lock(
1372 struct pipe_ctx *pipe,
1375 struct pipe_ctx *temp_pipe;
1376 bool flip_immediate = false;
1378 /* use TG master update lock to lock everything on the TG
1379 * therefore only top pipe need to lock
1381 if (!pipe || pipe->top_pipe)
1384 if (pipe->plane_state != NULL)
1385 flip_immediate = pipe->plane_state->flip_immediate;
1387 if (pipe->stream_res.gsl_group > 0) {
1388 temp_pipe = pipe->bottom_pipe;
1389 while (!flip_immediate && temp_pipe) {
1390 if (temp_pipe->plane_state != NULL)
1391 flip_immediate = temp_pipe->plane_state->flip_immediate;
1392 temp_pipe = temp_pipe->bottom_pipe;
1396 if (flip_immediate && lock) {
1397 const int TIMEOUT_FOR_FLIP_PENDING_US = 100000;
1398 unsigned int polling_interval_us = 1;
1403 if (temp_pipe->plane_state && temp_pipe->plane_state->flip_immediate) {
1404 for (i = 0; i < TIMEOUT_FOR_FLIP_PENDING_US / polling_interval_us; ++i) {
1405 if (!temp_pipe->plane_res.hubp->funcs->hubp_is_flip_pending(temp_pipe->plane_res.hubp))
1407 udelay(polling_interval_us);
1410 /* no reason it should take this long for immediate flips */
1411 ASSERT(i != TIMEOUT_FOR_FLIP_PENDING_US);
1413 temp_pipe = temp_pipe->bottom_pipe;
1417 /* In flip immediate and pipe splitting case, we need to use GSL
1418 * for synchronization. Only do setup on locking and on flip type change.
1420 if (lock && (pipe->bottom_pipe != NULL || !flip_immediate))
1421 if ((flip_immediate && pipe->stream_res.gsl_group == 0) ||
1422 (!flip_immediate && pipe->stream_res.gsl_group > 0))
1423 dcn20_setup_gsl_group_as_lock(dc, pipe, flip_immediate);
1425 if (pipe->plane_state != NULL)
1426 flip_immediate = pipe->plane_state->flip_immediate;
1428 temp_pipe = pipe->bottom_pipe;
1429 while (flip_immediate && temp_pipe) {
1430 if (temp_pipe->plane_state != NULL)
1431 flip_immediate = temp_pipe->plane_state->flip_immediate;
1432 temp_pipe = temp_pipe->bottom_pipe;
1435 if (!lock && pipe->stream_res.gsl_group > 0 && pipe->plane_state &&
1437 dcn20_setup_gsl_group_as_lock(dc, pipe, false);
1439 if (pipe->stream && should_use_dmub_lock(pipe->stream->link)) {
1440 union dmub_hw_lock_flags hw_locks = { 0 };
1441 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
1443 hw_locks.bits.lock_pipe = 1;
1444 inst_flags.otg_inst = pipe->stream_res.tg->inst;
1446 if (pipe->plane_state != NULL)
1447 hw_locks.bits.triple_buffer_lock = pipe->plane_state->triplebuffer_flips;
1449 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
1453 } else if (pipe->plane_state != NULL && pipe->plane_state->triplebuffer_flips) {
1455 pipe->stream_res.tg->funcs->triplebuffer_lock(pipe->stream_res.tg);
1457 pipe->stream_res.tg->funcs->triplebuffer_unlock(pipe->stream_res.tg);
1460 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1462 if (dc->hwseq->funcs.perform_3dlut_wa_unlock)
1463 dc->hwseq->funcs.perform_3dlut_wa_unlock(pipe);
1465 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1470 void dcn20_detect_pipe_changes(struct dc_state *old_state,
1471 struct dc_state *new_state,
1472 struct pipe_ctx *old_pipe,
1473 struct pipe_ctx *new_pipe)
1475 bool old_is_phantom = dc_state_get_pipe_subvp_type(old_state, old_pipe) == SUBVP_PHANTOM;
1476 bool new_is_phantom = dc_state_get_pipe_subvp_type(new_state, new_pipe) == SUBVP_PHANTOM;
1478 new_pipe->update_flags.raw = 0;
1480 /* If non-phantom pipe is being transitioned to a phantom pipe,
1481 * set disable and return immediately. This is because the pipe
1482 * that was previously in use must be fully disabled before we
1483 * can "enable" it as a phantom pipe (since the OTG will certainly
1484 * be different). The post_unlock sequence will set the correct
1485 * update flags to enable the phantom pipe.
1487 if (old_pipe->plane_state && !old_is_phantom &&
1488 new_pipe->plane_state && new_is_phantom) {
1489 new_pipe->update_flags.bits.disable = 1;
1493 if (resource_is_pipe_type(new_pipe, OTG_MASTER) &&
1494 resource_is_odm_topology_changed(new_pipe, old_pipe))
1495 /* Detect odm changes */
1496 new_pipe->update_flags.bits.odm = 1;
1498 /* Exit on unchanged, unused pipe */
1499 if (!old_pipe->plane_state && !new_pipe->plane_state)
1501 /* Detect pipe enable/disable */
1502 if (!old_pipe->plane_state && new_pipe->plane_state) {
1503 new_pipe->update_flags.bits.enable = 1;
1504 new_pipe->update_flags.bits.mpcc = 1;
1505 new_pipe->update_flags.bits.dppclk = 1;
1506 new_pipe->update_flags.bits.hubp_interdependent = 1;
1507 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
1508 new_pipe->update_flags.bits.unbounded_req = 1;
1509 new_pipe->update_flags.bits.gamut_remap = 1;
1510 new_pipe->update_flags.bits.scaler = 1;
1511 new_pipe->update_flags.bits.viewport = 1;
1512 new_pipe->update_flags.bits.det_size = 1;
1513 if (new_pipe->stream->test_pattern.type != DP_TEST_PATTERN_VIDEO_MODE &&
1514 new_pipe->stream_res.test_pattern_params.width != 0 &&
1515 new_pipe->stream_res.test_pattern_params.height != 0)
1516 new_pipe->update_flags.bits.test_pattern_changed = 1;
1517 if (!new_pipe->top_pipe && !new_pipe->prev_odm_pipe) {
1518 new_pipe->update_flags.bits.odm = 1;
1519 new_pipe->update_flags.bits.global_sync = 1;
1524 /* For SubVP we need to unconditionally enable because any phantom pipes are
1525 * always removed then newly added for every full updates whenever SubVP is in use.
1526 * The remove-add sequence of the phantom pipe always results in the pipe
1527 * being blanked in enable_stream_timing (DPG).
1529 if (new_pipe->stream && dc_state_get_pipe_subvp_type(new_state, new_pipe) == SUBVP_PHANTOM)
1530 new_pipe->update_flags.bits.enable = 1;
1532 /* Phantom pipes are effectively disabled, if the pipe was previously phantom
1535 if (old_pipe->plane_state && old_is_phantom &&
1536 new_pipe->plane_state && !new_is_phantom)
1537 new_pipe->update_flags.bits.enable = 1;
1539 if (old_pipe->plane_state && !new_pipe->plane_state) {
1540 new_pipe->update_flags.bits.disable = 1;
1544 /* Detect plane change */
1545 if (old_pipe->plane_state != new_pipe->plane_state) {
1546 new_pipe->update_flags.bits.plane_changed = true;
1549 /* Detect top pipe only changes */
1550 if (resource_is_pipe_type(new_pipe, OTG_MASTER)) {
1551 /* Detect global sync changes */
1552 if (old_pipe->pipe_dlg_param.vready_offset != new_pipe->pipe_dlg_param.vready_offset
1553 || old_pipe->pipe_dlg_param.vstartup_start != new_pipe->pipe_dlg_param.vstartup_start
1554 || old_pipe->pipe_dlg_param.vupdate_offset != new_pipe->pipe_dlg_param.vupdate_offset
1555 || old_pipe->pipe_dlg_param.vupdate_width != new_pipe->pipe_dlg_param.vupdate_width)
1556 new_pipe->update_flags.bits.global_sync = 1;
1559 if (old_pipe->det_buffer_size_kb != new_pipe->det_buffer_size_kb)
1560 new_pipe->update_flags.bits.det_size = 1;
1563 * Detect opp / tg change, only set on change, not on enable
1564 * Assume mpcc inst = pipe index, if not this code needs to be updated
1565 * since mpcc is what is affected by these. In fact all of our sequence
1566 * makes this assumption at the moment with how hubp reset is matched to
1567 * same index mpcc reset.
1569 if (old_pipe->stream_res.opp != new_pipe->stream_res.opp)
1570 new_pipe->update_flags.bits.opp_changed = 1;
1571 if (old_pipe->stream_res.tg != new_pipe->stream_res.tg)
1572 new_pipe->update_flags.bits.tg_changed = 1;
1575 * Detect mpcc blending changes, only dpp inst and opp matter here,
1576 * mpccs getting removed/inserted update connected ones during their own
1579 if (old_pipe->plane_res.dpp != new_pipe->plane_res.dpp
1580 || old_pipe->stream_res.opp != new_pipe->stream_res.opp)
1581 new_pipe->update_flags.bits.mpcc = 1;
1583 /* Detect dppclk change */
1584 if (old_pipe->plane_res.bw.dppclk_khz != new_pipe->plane_res.bw.dppclk_khz)
1585 new_pipe->update_flags.bits.dppclk = 1;
1587 /* Check for scl update */
1588 if (memcmp(&old_pipe->plane_res.scl_data, &new_pipe->plane_res.scl_data, sizeof(struct scaler_data)))
1589 new_pipe->update_flags.bits.scaler = 1;
1590 /* Check for vp update */
1591 if (memcmp(&old_pipe->plane_res.scl_data.viewport, &new_pipe->plane_res.scl_data.viewport, sizeof(struct rect))
1592 || memcmp(&old_pipe->plane_res.scl_data.viewport_c,
1593 &new_pipe->plane_res.scl_data.viewport_c, sizeof(struct rect)))
1594 new_pipe->update_flags.bits.viewport = 1;
1596 /* Detect dlg/ttu/rq updates */
1598 struct _vcs_dpi_display_dlg_regs_st old_dlg_attr = old_pipe->dlg_regs;
1599 struct _vcs_dpi_display_ttu_regs_st old_ttu_attr = old_pipe->ttu_regs;
1600 struct _vcs_dpi_display_dlg_regs_st *new_dlg_attr = &new_pipe->dlg_regs;
1601 struct _vcs_dpi_display_ttu_regs_st *new_ttu_attr = &new_pipe->ttu_regs;
1603 /* Detect pipe interdependent updates */
1604 if (old_dlg_attr.dst_y_prefetch != new_dlg_attr->dst_y_prefetch ||
1605 old_dlg_attr.vratio_prefetch != new_dlg_attr->vratio_prefetch ||
1606 old_dlg_attr.vratio_prefetch_c != new_dlg_attr->vratio_prefetch_c ||
1607 old_dlg_attr.dst_y_per_vm_vblank != new_dlg_attr->dst_y_per_vm_vblank ||
1608 old_dlg_attr.dst_y_per_row_vblank != new_dlg_attr->dst_y_per_row_vblank ||
1609 old_dlg_attr.dst_y_per_vm_flip != new_dlg_attr->dst_y_per_vm_flip ||
1610 old_dlg_attr.dst_y_per_row_flip != new_dlg_attr->dst_y_per_row_flip ||
1611 old_dlg_attr.refcyc_per_meta_chunk_vblank_l != new_dlg_attr->refcyc_per_meta_chunk_vblank_l ||
1612 old_dlg_attr.refcyc_per_meta_chunk_vblank_c != new_dlg_attr->refcyc_per_meta_chunk_vblank_c ||
1613 old_dlg_attr.refcyc_per_meta_chunk_flip_l != new_dlg_attr->refcyc_per_meta_chunk_flip_l ||
1614 old_dlg_attr.refcyc_per_line_delivery_pre_l != new_dlg_attr->refcyc_per_line_delivery_pre_l ||
1615 old_dlg_attr.refcyc_per_line_delivery_pre_c != new_dlg_attr->refcyc_per_line_delivery_pre_c ||
1616 old_ttu_attr.refcyc_per_req_delivery_pre_l != new_ttu_attr->refcyc_per_req_delivery_pre_l ||
1617 old_ttu_attr.refcyc_per_req_delivery_pre_c != new_ttu_attr->refcyc_per_req_delivery_pre_c ||
1618 old_ttu_attr.refcyc_per_req_delivery_pre_cur0 != new_ttu_attr->refcyc_per_req_delivery_pre_cur0 ||
1619 old_ttu_attr.refcyc_per_req_delivery_pre_cur1 != new_ttu_attr->refcyc_per_req_delivery_pre_cur1 ||
1620 old_ttu_attr.min_ttu_vblank != new_ttu_attr->min_ttu_vblank ||
1621 old_ttu_attr.qos_level_flip != new_ttu_attr->qos_level_flip) {
1622 old_dlg_attr.dst_y_prefetch = new_dlg_attr->dst_y_prefetch;
1623 old_dlg_attr.vratio_prefetch = new_dlg_attr->vratio_prefetch;
1624 old_dlg_attr.vratio_prefetch_c = new_dlg_attr->vratio_prefetch_c;
1625 old_dlg_attr.dst_y_per_vm_vblank = new_dlg_attr->dst_y_per_vm_vblank;
1626 old_dlg_attr.dst_y_per_row_vblank = new_dlg_attr->dst_y_per_row_vblank;
1627 old_dlg_attr.dst_y_per_vm_flip = new_dlg_attr->dst_y_per_vm_flip;
1628 old_dlg_attr.dst_y_per_row_flip = new_dlg_attr->dst_y_per_row_flip;
1629 old_dlg_attr.refcyc_per_meta_chunk_vblank_l = new_dlg_attr->refcyc_per_meta_chunk_vblank_l;
1630 old_dlg_attr.refcyc_per_meta_chunk_vblank_c = new_dlg_attr->refcyc_per_meta_chunk_vblank_c;
1631 old_dlg_attr.refcyc_per_meta_chunk_flip_l = new_dlg_attr->refcyc_per_meta_chunk_flip_l;
1632 old_dlg_attr.refcyc_per_line_delivery_pre_l = new_dlg_attr->refcyc_per_line_delivery_pre_l;
1633 old_dlg_attr.refcyc_per_line_delivery_pre_c = new_dlg_attr->refcyc_per_line_delivery_pre_c;
1634 old_ttu_attr.refcyc_per_req_delivery_pre_l = new_ttu_attr->refcyc_per_req_delivery_pre_l;
1635 old_ttu_attr.refcyc_per_req_delivery_pre_c = new_ttu_attr->refcyc_per_req_delivery_pre_c;
1636 old_ttu_attr.refcyc_per_req_delivery_pre_cur0 = new_ttu_attr->refcyc_per_req_delivery_pre_cur0;
1637 old_ttu_attr.refcyc_per_req_delivery_pre_cur1 = new_ttu_attr->refcyc_per_req_delivery_pre_cur1;
1638 old_ttu_attr.min_ttu_vblank = new_ttu_attr->min_ttu_vblank;
1639 old_ttu_attr.qos_level_flip = new_ttu_attr->qos_level_flip;
1640 new_pipe->update_flags.bits.hubp_interdependent = 1;
1642 /* Detect any other updates to ttu/rq/dlg */
1643 if (memcmp(&old_dlg_attr, &new_pipe->dlg_regs, sizeof(old_dlg_attr)) ||
1644 memcmp(&old_ttu_attr, &new_pipe->ttu_regs, sizeof(old_ttu_attr)) ||
1645 memcmp(&old_pipe->rq_regs, &new_pipe->rq_regs, sizeof(old_pipe->rq_regs)))
1646 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
1649 if (old_pipe->unbounded_req != new_pipe->unbounded_req)
1650 new_pipe->update_flags.bits.unbounded_req = 1;
1652 if (memcmp(&old_pipe->stream_res.test_pattern_params,
1653 &new_pipe->stream_res.test_pattern_params, sizeof(struct test_pattern_params))) {
1654 new_pipe->update_flags.bits.test_pattern_changed = 1;
1658 void dcn20_update_dchubp_dpp(
1660 struct pipe_ctx *pipe_ctx,
1661 struct dc_state *context)
1663 struct dce_hwseq *hws = dc->hwseq;
1664 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1665 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1666 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1667 struct dccg *dccg = dc->res_pool->dccg;
1668 bool viewport_changed = false;
1669 enum mall_stream_type pipe_mall_type = dc_state_get_pipe_subvp_type(context, pipe_ctx);
1671 if (pipe_ctx->update_flags.bits.dppclk)
1672 dpp->funcs->dpp_dppclk_control(dpp, false, true);
1674 if (pipe_ctx->update_flags.bits.enable)
1675 dccg->funcs->update_dpp_dto(dccg, dpp->inst, pipe_ctx->plane_res.bw.dppclk_khz);
1677 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
1678 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
1679 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
1682 if (pipe_ctx->update_flags.bits.hubp_rq_dlg_ttu) {
1683 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst);
1685 if (hubp->funcs->hubp_setup2) {
1686 hubp->funcs->hubp_setup2(
1688 &pipe_ctx->hubp_regs,
1689 &pipe_ctx->global_sync,
1690 &pipe_ctx->stream->timing);
1692 hubp->funcs->hubp_setup(
1694 &pipe_ctx->dlg_regs,
1695 &pipe_ctx->ttu_regs,
1697 &pipe_ctx->pipe_dlg_param);
1701 if (pipe_ctx->update_flags.bits.unbounded_req && hubp->funcs->set_unbounded_requesting)
1702 hubp->funcs->set_unbounded_requesting(hubp, pipe_ctx->unbounded_req);
1704 if (pipe_ctx->update_flags.bits.hubp_interdependent) {
1705 if (hubp->funcs->hubp_setup_interdependent2) {
1706 hubp->funcs->hubp_setup_interdependent2(
1708 &pipe_ctx->hubp_regs);
1710 hubp->funcs->hubp_setup_interdependent(
1712 &pipe_ctx->dlg_regs,
1713 &pipe_ctx->ttu_regs);
1717 if (pipe_ctx->update_flags.bits.enable ||
1718 pipe_ctx->update_flags.bits.plane_changed ||
1719 plane_state->update_flags.bits.bpp_change ||
1720 plane_state->update_flags.bits.input_csc_change ||
1721 plane_state->update_flags.bits.color_space_change ||
1722 plane_state->update_flags.bits.coeff_reduction_change) {
1723 struct dc_bias_and_scale bns_params = plane_state->bias_and_scale;
1725 // program the input csc
1726 dpp->funcs->dpp_setup(dpp,
1727 plane_state->format,
1728 EXPANSION_MODE_ZERO,
1729 plane_state->input_csc_color_matrix,
1730 plane_state->color_space,
1733 if (dpp->funcs->set_cursor_matrix) {
1734 dpp->funcs->set_cursor_matrix(dpp,
1735 plane_state->color_space,
1736 plane_state->cursor_csc_color_matrix);
1738 if (dpp->funcs->dpp_program_bias_and_scale) {
1739 //TODO :for CNVC set scale and bias registers if necessary
1740 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1744 if (pipe_ctx->update_flags.bits.mpcc
1745 || pipe_ctx->update_flags.bits.plane_changed
1746 || plane_state->update_flags.bits.global_alpha_change
1747 || plane_state->update_flags.bits.per_pixel_alpha_change) {
1748 // MPCC inst is equal to pipe index in practice
1749 hws->funcs.update_mpcc(dc, pipe_ctx);
1752 if (pipe_ctx->update_flags.bits.scaler ||
1753 plane_state->update_flags.bits.scaling_change ||
1754 plane_state->update_flags.bits.position_change ||
1755 plane_state->update_flags.bits.per_pixel_alpha_change ||
1756 pipe_ctx->stream->update_flags.bits.scaling) {
1757 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->plane_state->per_pixel_alpha;
1758 ASSERT(pipe_ctx->plane_res.scl_data.lb_params.depth == LB_PIXEL_DEPTH_36BPP);
1759 /* scaler configuration */
1760 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1761 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
1764 if (pipe_ctx->update_flags.bits.viewport ||
1765 (context == dc->current_state && plane_state->update_flags.bits.position_change) ||
1766 (context == dc->current_state && plane_state->update_flags.bits.scaling_change) ||
1767 (context == dc->current_state && pipe_ctx->stream->update_flags.bits.scaling)) {
1769 hubp->funcs->mem_program_viewport(
1771 &pipe_ctx->plane_res.scl_data.viewport,
1772 &pipe_ctx->plane_res.scl_data.viewport_c);
1773 viewport_changed = true;
1776 if (hubp->funcs->hubp_program_mcache_id_and_split_coordinate)
1777 hubp->funcs->hubp_program_mcache_id_and_split_coordinate(hubp, &pipe_ctx->mcache_regs);
1779 /* Any updates are handled in dc interface, just need to apply existing for plane enable */
1780 if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed ||
1781 pipe_ctx->update_flags.bits.scaler || viewport_changed == true) &&
1782 pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
1783 dc->hwss.set_cursor_attribute(pipe_ctx);
1784 dc->hwss.set_cursor_position(pipe_ctx);
1786 if (dc->hwss.set_cursor_sdr_white_level)
1787 dc->hwss.set_cursor_sdr_white_level(pipe_ctx);
1790 /* Any updates are handled in dc interface, just need
1791 * to apply existing for plane enable / opp change */
1792 if (pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed
1793 || pipe_ctx->update_flags.bits.plane_changed
1794 || pipe_ctx->stream->update_flags.bits.gamut_remap
1795 || plane_state->update_flags.bits.gamut_remap_change
1796 || pipe_ctx->stream->update_flags.bits.out_csc) {
1797 /* dpp/cm gamut remap*/
1798 dc->hwss.program_gamut_remap(pipe_ctx);
1800 /*call the dcn2 method which uses mpc csc*/
1801 dc->hwss.program_output_csc(dc,
1803 pipe_ctx->stream->output_color_space,
1804 pipe_ctx->stream->csc_color_matrix.matrix,
1808 if (pipe_ctx->update_flags.bits.enable ||
1809 pipe_ctx->update_flags.bits.plane_changed ||
1810 pipe_ctx->update_flags.bits.opp_changed ||
1811 plane_state->update_flags.bits.pixel_format_change ||
1812 plane_state->update_flags.bits.horizontal_mirror_change ||
1813 plane_state->update_flags.bits.rotation_change ||
1814 plane_state->update_flags.bits.swizzle_change ||
1815 plane_state->update_flags.bits.dcc_change ||
1816 plane_state->update_flags.bits.bpp_change ||
1817 plane_state->update_flags.bits.scaling_change ||
1818 plane_state->update_flags.bits.plane_size_change) {
1819 struct plane_size size = plane_state->plane_size;
1821 size.surface_size = pipe_ctx->plane_res.scl_data.viewport;
1822 hubp->funcs->hubp_program_surface_config(
1824 plane_state->format,
1825 &plane_state->tiling_info,
1827 plane_state->rotation,
1829 plane_state->horizontal_mirror,
1831 hubp->power_gated = false;
1834 if (pipe_ctx->update_flags.bits.enable ||
1835 pipe_ctx->update_flags.bits.plane_changed ||
1836 plane_state->update_flags.bits.addr_update) {
1837 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER) &&
1838 pipe_mall_type == SUBVP_MAIN) {
1839 union block_sequence_params params;
1841 params.subvp_save_surf_addr.dc_dmub_srv = dc->ctx->dmub_srv;
1842 params.subvp_save_surf_addr.addr = &pipe_ctx->plane_state->address;
1843 params.subvp_save_surf_addr.subvp_index = pipe_ctx->subvp_index;
1844 hwss_subvp_save_surf_addr(¶ms);
1846 dc->hwss.update_plane_addr(dc, pipe_ctx);
1849 if (pipe_ctx->update_flags.bits.enable)
1850 hubp->funcs->set_blank(hubp, false);
1851 /* If the stream paired with this plane is phantom, the plane is also phantom */
1852 if (pipe_mall_type == SUBVP_PHANTOM && hubp->funcs->phantom_hubp_post_enable)
1853 hubp->funcs->phantom_hubp_post_enable(hubp);
1856 static int dcn20_calculate_vready_offset_for_group(struct pipe_ctx *pipe)
1858 struct pipe_ctx *other_pipe;
1859 int vready_offset = pipe->pipe_dlg_param.vready_offset;
1861 /* Always use the largest vready_offset of all connected pipes */
1862 for (other_pipe = pipe->bottom_pipe; other_pipe != NULL; other_pipe = other_pipe->bottom_pipe) {
1863 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1864 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1866 for (other_pipe = pipe->top_pipe; other_pipe != NULL; other_pipe = other_pipe->top_pipe) {
1867 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1868 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1870 for (other_pipe = pipe->next_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->next_odm_pipe) {
1871 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1872 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1874 for (other_pipe = pipe->prev_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->prev_odm_pipe) {
1875 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1876 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1879 return vready_offset;
1882 static void dcn20_program_tg(
1884 struct pipe_ctx *pipe_ctx,
1885 struct dc_state *context,
1886 struct dce_hwseq *hws)
1888 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1889 pipe_ctx->stream_res.tg,
1890 dcn20_calculate_vready_offset_for_group(pipe_ctx),
1891 pipe_ctx->pipe_dlg_param.vstartup_start,
1892 pipe_ctx->pipe_dlg_param.vupdate_offset,
1893 pipe_ctx->pipe_dlg_param.vupdate_width,
1894 pipe_ctx->pipe_dlg_param.pstate_keepout);
1896 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM)
1897 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
1899 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
1900 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, true);
1902 if (hws->funcs.setup_vupdate_interrupt)
1903 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1906 static void dcn20_program_pipe(
1908 struct pipe_ctx *pipe_ctx,
1909 struct dc_state *context)
1911 struct dce_hwseq *hws = dc->hwseq;
1913 /* Only need to unblank on top pipe */
1914 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER)) {
1915 if (pipe_ctx->update_flags.bits.enable ||
1916 pipe_ctx->update_flags.bits.odm ||
1917 pipe_ctx->stream->update_flags.bits.abm_level)
1918 hws->funcs.blank_pixel_data(dc, pipe_ctx,
1919 !pipe_ctx->plane_state ||
1920 !pipe_ctx->plane_state->visible);
1923 /* Only update TG on top pipe */
1924 if (pipe_ctx->update_flags.bits.global_sync && !pipe_ctx->top_pipe
1925 && !pipe_ctx->prev_odm_pipe)
1926 dcn20_program_tg(dc, pipe_ctx, context, hws);
1928 if (pipe_ctx->update_flags.bits.odm)
1929 hws->funcs.update_odm(dc, context, pipe_ctx);
1931 if (pipe_ctx->update_flags.bits.enable) {
1932 if (hws->funcs.enable_plane)
1933 hws->funcs.enable_plane(dc, pipe_ctx, context);
1935 dcn20_enable_plane(dc, pipe_ctx, context);
1937 if (dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes)
1938 dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes(dc->res_pool->hubbub);
1941 if (pipe_ctx->update_flags.bits.det_size) {
1942 if (dc->res_pool->hubbub->funcs->program_det_size)
1943 dc->res_pool->hubbub->funcs->program_det_size(
1944 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->det_buffer_size_kb);
1946 if (dc->res_pool->hubbub->funcs->program_det_segments)
1947 dc->res_pool->hubbub->funcs->program_det_segments(
1948 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->hubp_regs.det_size);
1951 if (pipe_ctx->plane_state && (pipe_ctx->update_flags.raw ||
1952 pipe_ctx->plane_state->update_flags.raw ||
1953 pipe_ctx->stream->update_flags.raw))
1954 dcn20_update_dchubp_dpp(dc, pipe_ctx, context);
1956 if (pipe_ctx->plane_state && (pipe_ctx->update_flags.bits.enable ||
1957 pipe_ctx->plane_state->update_flags.bits.hdr_mult))
1958 hws->funcs.set_hdr_multiplier(pipe_ctx);
1960 if (hws->funcs.populate_mcm_luts) {
1961 if (pipe_ctx->plane_state) {
1962 hws->funcs.populate_mcm_luts(dc, pipe_ctx, pipe_ctx->plane_state->mcm_luts,
1963 pipe_ctx->plane_state->lut_bank_a);
1964 pipe_ctx->plane_state->lut_bank_a = !pipe_ctx->plane_state->lut_bank_a;
1968 if (pipe_ctx->plane_state &&
1969 (pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
1970 pipe_ctx->plane_state->update_flags.bits.gamma_change ||
1971 pipe_ctx->plane_state->update_flags.bits.lut_3d ||
1972 pipe_ctx->update_flags.bits.enable))
1973 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
1975 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
1976 * only do gamma programming for powering on, internal memcmp to avoid
1977 * updating on slave planes
1979 if (pipe_ctx->update_flags.bits.enable ||
1980 pipe_ctx->update_flags.bits.plane_changed ||
1981 pipe_ctx->stream->update_flags.bits.out_tf ||
1982 (pipe_ctx->plane_state &&
1983 pipe_ctx->plane_state->update_flags.bits.output_tf_change))
1984 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
1986 /* If the pipe has been enabled or has a different opp, we
1987 * should reprogram the fmt. This deals with cases where
1988 * interation between mpc and odm combine on different streams
1989 * causes a different pipe to be chosen to odm combine with.
1991 if (pipe_ctx->update_flags.bits.enable
1992 || pipe_ctx->update_flags.bits.opp_changed) {
1994 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1995 pipe_ctx->stream_res.opp,
1996 COLOR_SPACE_YCBCR601,
1997 pipe_ctx->stream->timing.display_color_depth,
1998 pipe_ctx->stream->signal);
2000 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
2001 pipe_ctx->stream_res.opp,
2002 &pipe_ctx->stream->bit_depth_params,
2003 &pipe_ctx->stream->clamping);
2006 /* Set ABM pipe after other pipe configurations done */
2007 if ((pipe_ctx->plane_state && pipe_ctx->plane_state->visible)) {
2008 if (pipe_ctx->stream_res.abm) {
2009 dc->hwss.set_pipe(pipe_ctx);
2010 pipe_ctx->stream_res.abm->funcs->set_abm_level(pipe_ctx->stream_res.abm,
2011 pipe_ctx->stream->abm_level);
2015 if (pipe_ctx->update_flags.bits.test_pattern_changed) {
2016 struct output_pixel_processor *odm_opp = pipe_ctx->stream_res.opp;
2017 struct bit_depth_reduction_params params;
2019 memset(¶ms, 0, sizeof(params));
2020 odm_opp->funcs->opp_program_bit_depth_reduction(odm_opp, ¶ms);
2021 dc->hwss.set_disp_pattern_generator(dc,
2023 pipe_ctx->stream_res.test_pattern_params.test_pattern,
2024 pipe_ctx->stream_res.test_pattern_params.color_space,
2025 pipe_ctx->stream_res.test_pattern_params.color_depth,
2027 pipe_ctx->stream_res.test_pattern_params.width,
2028 pipe_ctx->stream_res.test_pattern_params.height,
2029 pipe_ctx->stream_res.test_pattern_params.offset);
2033 void dcn20_program_front_end_for_ctx(
2035 struct dc_state *context)
2038 unsigned int prev_hubp_count = 0;
2039 unsigned int hubp_count = 0;
2040 struct dce_hwseq *hws = dc->hwseq;
2041 struct pipe_ctx *pipe = NULL;
2043 DC_LOGGER_INIT(dc->ctx->logger);
2045 if (resource_is_pipe_topology_changed(dc->current_state, context))
2046 resource_log_pipe_topology_update(dc, context);
2048 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2049 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2050 pipe = &context->res_ctx.pipe_ctx[i];
2052 if (!pipe->top_pipe && !pipe->prev_odm_pipe && pipe->plane_state) {
2053 ASSERT(!pipe->plane_state->triplebuffer_flips);
2054 /*turn off triple buffer for full update*/
2055 dc->hwss.program_triplebuffer(
2056 dc, pipe, pipe->plane_state->triplebuffer_flips);
2061 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2062 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
2064 if (context->res_ctx.pipe_ctx[i].plane_state)
2068 if (prev_hubp_count == 0 && hubp_count > 0) {
2069 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2070 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2071 dc->res_pool->hubbub, true, false);
2075 /* Set pipe update flags and lock pipes */
2076 for (i = 0; i < dc->res_pool->pipe_count; i++)
2077 dcn20_detect_pipe_changes(dc->current_state, context, &dc->current_state->res_ctx.pipe_ctx[i],
2078 &context->res_ctx.pipe_ctx[i]);
2080 /* When disabling phantom pipes, turn on phantom OTG first (so we can get double
2081 * buffer updates properly)
2083 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2084 struct dc_stream_state *stream = dc->current_state->res_ctx.pipe_ctx[i].stream;
2086 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2088 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable && stream &&
2089 dc_state_get_pipe_subvp_type(dc->current_state, pipe) == SUBVP_PHANTOM) {
2090 struct timing_generator *tg = dc->current_state->res_ctx.pipe_ctx[i].stream_res.tg;
2092 if (tg->funcs->enable_crtc) {
2093 if (dc->hwseq->funcs.blank_pixel_data)
2094 dc->hwseq->funcs.blank_pixel_data(dc, pipe, true);
2096 tg->funcs->enable_crtc(tg);
2100 /* OTG blank before disabling all front ends */
2101 for (i = 0; i < dc->res_pool->pipe_count; i++)
2102 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2103 && !context->res_ctx.pipe_ctx[i].top_pipe
2104 && !context->res_ctx.pipe_ctx[i].prev_odm_pipe
2105 && context->res_ctx.pipe_ctx[i].stream)
2106 hws->funcs.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true);
2108 /* Disconnect mpcc */
2109 for (i = 0; i < dc->res_pool->pipe_count; i++)
2110 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2111 || context->res_ctx.pipe_ctx[i].update_flags.bits.opp_changed) {
2112 struct hubbub *hubbub = dc->res_pool->hubbub;
2114 /* Phantom pipe DET should be 0, but if a pipe in use is being transitioned to phantom
2115 * then we want to do the programming here (effectively it's being disabled). If we do
2116 * the programming later the DET won't be updated until the OTG for the phantom pipe is
2117 * turned on (i.e. in an MCLK switch) which can come in too late and cause issues with
2120 if ((context->res_ctx.pipe_ctx[i].update_flags.bits.disable ||
2121 (context->res_ctx.pipe_ctx[i].plane_state &&
2122 dc_state_get_pipe_subvp_type(context, &context->res_ctx.pipe_ctx[i])
2123 == SUBVP_PHANTOM))) {
2124 if (hubbub->funcs->program_det_size)
2125 hubbub->funcs->program_det_size(hubbub,
2126 dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2127 if (dc->res_pool->hubbub->funcs->program_det_segments)
2128 dc->res_pool->hubbub->funcs->program_det_segments(
2129 hubbub, dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2131 hws->funcs.plane_atomic_disconnect(dc, dc->current_state,
2132 &dc->current_state->res_ctx.pipe_ctx[i]);
2133 DC_LOG_DC("Reset mpcc for pipe %d\n", dc->current_state->res_ctx.pipe_ctx[i].pipe_idx);
2136 /* update ODM for blanked OTG master pipes */
2137 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2138 pipe = &context->res_ctx.pipe_ctx[i];
2139 if (resource_is_pipe_type(pipe, OTG_MASTER) &&
2140 !resource_is_pipe_type(pipe, DPP_PIPE) &&
2141 pipe->update_flags.bits.odm &&
2142 hws->funcs.update_odm)
2143 hws->funcs.update_odm(dc, context, pipe);
2147 * Program all updated pipes, order matters for mpcc setup. Start with
2148 * top pipe and program all pipes that follow in order
2150 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2151 pipe = &context->res_ctx.pipe_ctx[i];
2153 if (pipe->plane_state && !pipe->top_pipe) {
2155 if (hws->funcs.program_pipe)
2156 hws->funcs.program_pipe(dc, pipe, context);
2158 /* Don't program phantom pipes in the regular front end programming sequence.
2159 * There is an MPO transition case where a pipe being used by a video plane is
2160 * transitioned directly to be a phantom pipe when closing the MPO video.
2161 * However the phantom pipe will program a new HUBP_VTG_SEL (update takes place
2162 * right away) but the MPO still exists until the double buffered update of the
2163 * main pipe so we will get a frame of underflow if the phantom pipe is
2167 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM)
2168 dcn20_program_pipe(dc, pipe, context);
2171 pipe = pipe->bottom_pipe;
2175 /* Program secondary blending tree and writeback pipes */
2176 pipe = &context->res_ctx.pipe_ctx[i];
2177 if (!pipe->top_pipe && !pipe->prev_odm_pipe
2178 && pipe->stream && pipe->stream->num_wb_info > 0
2179 && (pipe->update_flags.raw || (pipe->plane_state && pipe->plane_state->update_flags.raw)
2180 || pipe->stream->update_flags.raw)
2181 && hws->funcs.program_all_writeback_pipes_in_tree)
2182 hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context);
2184 /* Avoid underflow by check of pipe line read when adding 2nd plane. */
2185 if (hws->wa.wait_hubpret_read_start_during_mpo_transition &&
2188 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start &&
2189 dc->current_state->stream_status[0].plane_count == 1 &&
2190 context->stream_status[0].plane_count > 1) {
2191 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start(pipe->plane_res.hubp);
2196 /* post_unlock_reset_opp - the function wait for corresponding double
2197 * buffered pending status clear and reset opp head pipe's none double buffered
2198 * registers to their initial state.
2200 void dcn20_post_unlock_reset_opp(struct dc *dc,
2201 struct pipe_ctx *opp_head)
2203 struct display_stream_compressor *dsc = opp_head->stream_res.dsc;
2204 struct dccg *dccg = dc->res_pool->dccg;
2207 * wait for all DPP pipes in current mpc blending tree completes double
2208 * buffered disconnection before resetting OPP
2210 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, opp_head);
2213 bool is_dsc_ungated = false;
2215 if (dc->hwseq->funcs.dsc_pg_status)
2216 is_dsc_ungated = dc->hwseq->funcs.dsc_pg_status(dc->hwseq, dsc->inst);
2218 if (is_dsc_ungated) {
2220 * seamless update specific where we will postpone non
2221 * double buffered DSCCLK disable logic in post unlock
2222 * sequence after DSC is disconnected from OPP but not
2225 dsc->funcs->dsc_wait_disconnect_pending_clear(dsc);
2226 dsc->funcs->dsc_disable(dsc);
2227 if (dccg->funcs->set_ref_dscclk)
2228 dccg->funcs->set_ref_dscclk(dccg, dsc->inst);
2233 void dcn20_post_unlock_program_front_end(
2235 struct dc_state *context)
2237 // Timeout for pipe enable
2238 unsigned int timeout_us = 100000;
2239 unsigned int polling_interval_us = 1;
2240 struct dce_hwseq *hwseq = dc->hwseq;
2243 for (i = 0; i < dc->res_pool->pipe_count; i++)
2244 if (resource_is_pipe_type(&dc->current_state->res_ctx.pipe_ctx[i], OPP_HEAD) &&
2245 !resource_is_pipe_type(&context->res_ctx.pipe_ctx[i], OPP_HEAD))
2246 dcn20_post_unlock_reset_opp(dc,
2247 &dc->current_state->res_ctx.pipe_ctx[i]);
2249 for (i = 0; i < dc->res_pool->pipe_count; i++)
2250 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable)
2251 dc->hwss.disable_plane(dc, dc->current_state, &dc->current_state->res_ctx.pipe_ctx[i]);
2254 * If we are enabling a pipe, we need to wait for pending clear as this is a critical
2255 * part of the enable operation otherwise, DM may request an immediate flip which
2256 * will cause HW to perform an "immediate enable" (as opposed to "vsync enable") which
2257 * is unsupported on DCN.
2259 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2260 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2261 // Don't check flip pending on phantom pipes
2262 if (pipe->plane_state && !pipe->top_pipe && pipe->update_flags.bits.enable &&
2263 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2264 struct hubp *hubp = pipe->plane_res.hubp;
2267 for (j = 0; j < timeout_us / polling_interval_us
2268 && hubp->funcs->hubp_is_flip_pending(hubp); j++)
2269 udelay(polling_interval_us);
2273 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2274 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2275 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2277 /* When going from a smaller ODM slice count to larger, we must ensure double
2278 * buffer update completes before we return to ensure we don't reduce DISPCLK
2279 * before we've transitioned to 2:1 or 4:1
2281 if (resource_is_pipe_type(old_pipe, OTG_MASTER) && resource_is_pipe_type(pipe, OTG_MASTER) &&
2282 resource_get_odm_slice_count(old_pipe) < resource_get_odm_slice_count(pipe) &&
2283 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2285 struct timing_generator *tg = pipe->stream_res.tg;
2287 if (tg->funcs->get_optc_double_buffer_pending) {
2288 for (j = 0; j < timeout_us / polling_interval_us
2289 && tg->funcs->get_optc_double_buffer_pending(tg); j++)
2290 udelay(polling_interval_us);
2295 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2296 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2297 dc->res_pool->hubbub, false, false);
2299 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2300 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2302 if (pipe->plane_state && !pipe->top_pipe) {
2303 /* Program phantom pipe here to prevent a frame of underflow in the MPO transition
2304 * case (if a pipe being used for a video plane transitions to a phantom pipe, it
2305 * can underflow due to HUBP_VTG_SEL programming if done in the regular front end
2306 * programming sequence).
2309 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
2310 /* When turning on the phantom pipe we want to run through the
2311 * entire enable sequence, so apply all the "enable" flags.
2313 if (dc->hwss.apply_update_flags_for_phantom)
2314 dc->hwss.apply_update_flags_for_phantom(pipe);
2315 if (dc->hwss.update_phantom_vp_position)
2316 dc->hwss.update_phantom_vp_position(dc, context, pipe);
2317 dcn20_program_pipe(dc, pipe, context);
2319 pipe = pipe->bottom_pipe;
2327 /* P-State support transitions:
2328 * Natural -> FPO: P-State disabled in prepare, force disallow anytime is safe
2329 * FPO -> Natural: Unforce anytime after FW disable is safe (P-State will assert naturally)
2330 * Unsupported -> FPO: P-State enabled in optimize, force disallow anytime is safe
2331 * FPO -> Unsupported: P-State disabled in prepare, unforce disallow anytime is safe
2332 * FPO <-> SubVP: Force disallow is maintained on the FPO / SubVP pipes
2334 if (hwseq->funcs.update_force_pstate)
2335 dc->hwseq->funcs.update_force_pstate(dc, context);
2337 /* Only program the MALL registers after all the main and phantom pipes
2338 * are done programming.
2340 if (hwseq->funcs.program_mall_pipe_config)
2341 hwseq->funcs.program_mall_pipe_config(dc, context);
2343 /* WA to apply WM setting*/
2344 if (hwseq->wa.DEGVIDCN21)
2345 dc->res_pool->hubbub->funcs->apply_DEDCN21_147_wa(dc->res_pool->hubbub);
2347 /* WA for stutter underflow during MPO transitions when adding 2nd plane */
2348 if (hwseq->wa.disallow_self_refresh_during_multi_plane_transition) {
2350 if (dc->current_state->stream_status[0].plane_count == 1 &&
2351 context->stream_status[0].plane_count > 1) {
2353 struct timing_generator *tg = dc->res_pool->timing_generators[0];
2355 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub, false);
2357 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied = true;
2358 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied_on_frame = tg->funcs->get_frame_count(tg);
2363 void dcn20_prepare_bandwidth(
2365 struct dc_state *context)
2367 struct hubbub *hubbub = dc->res_pool->hubbub;
2368 unsigned int compbuf_size_kb = 0;
2369 unsigned int cache_wm_a = context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns;
2372 dc->clk_mgr->funcs->update_clocks(
2377 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2378 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2380 // At optimize don't restore the original watermark value
2381 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_NONE) {
2382 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2387 /* program dchubbub watermarks:
2388 * For assigning wm_optimized_required, use |= operator since we don't want
2389 * to clear the value if the optimize has not happened yet
2391 dc->wm_optimized_required |= hubbub->funcs->program_watermarks(hubbub,
2392 &context->bw_ctx.bw.dcn.watermarks,
2393 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
2396 // Restore the real watermark so we can commit the value to DMCUB
2397 // DMCUB uses the "original" watermark value in SubVP MCLK switch
2398 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = cache_wm_a;
2400 /* decrease compbuf size */
2401 if (hubbub->funcs->program_compbuf_size) {
2402 if (context->bw_ctx.dml.ip.min_comp_buffer_size_kbytes) {
2403 compbuf_size_kb = context->bw_ctx.dml.ip.min_comp_buffer_size_kbytes;
2404 dc->wm_optimized_required |= (compbuf_size_kb != dc->current_state->bw_ctx.dml.ip.min_comp_buffer_size_kbytes);
2406 compbuf_size_kb = context->bw_ctx.bw.dcn.compbuf_size_kb;
2407 dc->wm_optimized_required |= (compbuf_size_kb != dc->current_state->bw_ctx.bw.dcn.compbuf_size_kb);
2410 hubbub->funcs->program_compbuf_size(hubbub, compbuf_size_kb, false);
2414 void dcn20_optimize_bandwidth(
2416 struct dc_state *context)
2418 struct hubbub *hubbub = dc->res_pool->hubbub;
2421 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2422 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2424 // At optimize don't need to restore the original watermark value
2425 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_NONE) {
2426 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2431 /* program dchubbub watermarks */
2432 hubbub->funcs->program_watermarks(hubbub,
2433 &context->bw_ctx.bw.dcn.watermarks,
2434 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
2437 if (dc->clk_mgr->dc_mode_softmax_enabled)
2438 if (dc->clk_mgr->clks.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 &&
2439 context->bw_ctx.bw.dcn.clk.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000)
2440 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->dc_mode_softmax_memclk);
2442 /* increase compbuf size */
2443 if (hubbub->funcs->program_compbuf_size)
2444 hubbub->funcs->program_compbuf_size(hubbub, context->bw_ctx.bw.dcn.compbuf_size_kb, true);
2446 if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching) {
2447 dc_dmub_srv_p_state_delegate(dc,
2449 context->bw_ctx.bw.dcn.clk.p_state_change_support = true;
2450 dc->clk_mgr->clks.fw_based_mclk_switching = true;
2452 dc->clk_mgr->clks.fw_based_mclk_switching = false;
2455 dc->clk_mgr->funcs->update_clocks(
2459 if (context->bw_ctx.bw.dcn.clk.zstate_support == DCN_ZSTATE_SUPPORT_ALLOW &&
2460 !dc->debug.disable_extblankadj) {
2461 for (i = 0; i < dc->res_pool->pipe_count; ++i) {
2462 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2464 if (pipe_ctx->stream && pipe_ctx->plane_res.hubp->funcs->program_extended_blank
2465 && pipe_ctx->stream->adjust.v_total_min == pipe_ctx->stream->adjust.v_total_max
2466 && pipe_ctx->stream->adjust.v_total_max > pipe_ctx->stream->timing.v_total)
2467 pipe_ctx->plane_res.hubp->funcs->program_extended_blank(pipe_ctx->plane_res.hubp,
2468 pipe_ctx->dlg_regs.min_dst_y_next_start);
2473 bool dcn20_update_bandwidth(
2475 struct dc_state *context)
2478 struct dce_hwseq *hws = dc->hwseq;
2480 /* recalculate DML parameters */
2481 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false))
2484 /* apply updated bandwidth parameters */
2485 dc->hwss.prepare_bandwidth(dc, context);
2487 /* update hubp configs for all pipes */
2488 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2489 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2491 if (pipe_ctx->plane_state == NULL)
2494 if (pipe_ctx->top_pipe == NULL) {
2495 bool blank = !is_pipe_tree_visible(pipe_ctx);
2497 pipe_ctx->stream_res.tg->funcs->program_global_sync(
2498 pipe_ctx->stream_res.tg,
2499 dcn20_calculate_vready_offset_for_group(pipe_ctx),
2500 pipe_ctx->pipe_dlg_param.vstartup_start,
2501 pipe_ctx->pipe_dlg_param.vupdate_offset,
2502 pipe_ctx->pipe_dlg_param.vupdate_width,
2503 pipe_ctx->pipe_dlg_param.pstate_keepout);
2505 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
2506 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, false);
2508 if (pipe_ctx->prev_odm_pipe == NULL)
2509 hws->funcs.blank_pixel_data(dc, pipe_ctx, blank);
2511 if (hws->funcs.setup_vupdate_interrupt)
2512 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
2515 pipe_ctx->plane_res.hubp->funcs->hubp_setup(
2516 pipe_ctx->plane_res.hubp,
2517 &pipe_ctx->dlg_regs,
2518 &pipe_ctx->ttu_regs,
2520 &pipe_ctx->pipe_dlg_param);
2526 void dcn20_enable_writeback(
2528 struct dc_writeback_info *wb_info,
2529 struct dc_state *context)
2532 struct mcif_wb *mcif_wb;
2533 struct timing_generator *optc;
2535 ASSERT(wb_info->dwb_pipe_inst < MAX_DWB_PIPES);
2536 ASSERT(wb_info->wb_enabled);
2537 dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst];
2538 mcif_wb = dc->res_pool->mcif_wb[wb_info->dwb_pipe_inst];
2540 /* set the OPTC source mux */
2541 optc = dc->res_pool->timing_generators[dwb->otg_inst];
2542 optc->funcs->set_dwb_source(optc, wb_info->dwb_pipe_inst);
2543 /* set MCIF_WB buffer and arbitration configuration */
2544 mcif_wb->funcs->config_mcif_buf(mcif_wb, &wb_info->mcif_buf_params, wb_info->dwb_params.dest_height);
2545 mcif_wb->funcs->config_mcif_arb(mcif_wb, &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[wb_info->dwb_pipe_inst]);
2546 /* Enable MCIF_WB */
2547 mcif_wb->funcs->enable_mcif(mcif_wb);
2549 dwb->funcs->enable(dwb, &wb_info->dwb_params);
2550 /* TODO: add sequence to enable/disable warmup */
2553 void dcn20_disable_writeback(
2555 unsigned int dwb_pipe_inst)
2558 struct mcif_wb *mcif_wb;
2560 ASSERT(dwb_pipe_inst < MAX_DWB_PIPES);
2561 dwb = dc->res_pool->dwbc[dwb_pipe_inst];
2562 mcif_wb = dc->res_pool->mcif_wb[dwb_pipe_inst];
2564 dwb->funcs->disable(dwb);
2565 mcif_wb->funcs->disable_mcif(mcif_wb);
2568 bool dcn20_wait_for_blank_complete(
2569 struct output_pixel_processor *opp)
2576 for (counter = 0; counter < 1000; counter++) {
2577 if (!opp->funcs->dpg_is_pending(opp))
2583 if (counter == 1000) {
2584 dm_error("DC: failed to blank crtc!\n");
2588 return opp->funcs->dpg_is_blanked(opp);
2591 bool dcn20_dmdata_status_done(struct pipe_ctx *pipe_ctx)
2593 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2597 return hubp->funcs->dmdata_status_done(hubp);
2600 void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
2602 struct dce_hwseq *hws = dc->hwseq;
2604 if (pipe_ctx->stream_res.dsc) {
2605 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2607 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, true);
2609 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, true);
2610 odm_pipe = odm_pipe->next_odm_pipe;
2615 void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
2617 struct dce_hwseq *hws = dc->hwseq;
2619 if (pipe_ctx->stream_res.dsc) {
2620 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2622 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, false);
2624 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, false);
2625 odm_pipe = odm_pipe->next_odm_pipe;
2630 void dcn20_set_dmdata_attributes(struct pipe_ctx *pipe_ctx)
2632 struct dc_dmdata_attributes attr = { 0 };
2633 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2635 attr.dmdata_mode = DMDATA_HW_MODE;
2637 dc_is_hdmi_signal(pipe_ctx->stream->signal) ? 32 : 36;
2638 attr.address.quad_part =
2639 pipe_ctx->stream->dmdata_address.quad_part;
2640 attr.dmdata_dl_delta = 0;
2641 attr.dmdata_qos_mode = 0;
2642 attr.dmdata_qos_level = 0;
2643 attr.dmdata_repeat = 1; /* always repeat */
2644 attr.dmdata_updated = 1;
2645 attr.dmdata_sw_data = NULL;
2647 hubp->funcs->dmdata_set_attributes(hubp, &attr);
2650 void dcn20_init_vm_ctx(
2651 struct dce_hwseq *hws,
2653 struct dc_virtual_addr_space_config *va_config,
2656 struct dcn_hubbub_virt_addr_config config;
2659 ASSERT(0); /* VMID cannot be 0 for vm context */
2663 config.page_table_start_addr = va_config->page_table_start_addr;
2664 config.page_table_end_addr = va_config->page_table_end_addr;
2665 config.page_table_block_size = va_config->page_table_block_size_in_bytes;
2666 config.page_table_depth = va_config->page_table_depth;
2667 config.page_table_base_addr = va_config->page_table_base_addr;
2669 dc->res_pool->hubbub->funcs->init_vm_ctx(dc->res_pool->hubbub, &config, vmid);
2672 int dcn20_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config)
2674 struct dcn_hubbub_phys_addr_config config;
2676 config.system_aperture.fb_top = pa_config->system_aperture.fb_top;
2677 config.system_aperture.fb_offset = pa_config->system_aperture.fb_offset;
2678 config.system_aperture.fb_base = pa_config->system_aperture.fb_base;
2679 config.system_aperture.agp_top = pa_config->system_aperture.agp_top;
2680 config.system_aperture.agp_bot = pa_config->system_aperture.agp_bot;
2681 config.system_aperture.agp_base = pa_config->system_aperture.agp_base;
2682 config.gart_config.page_table_start_addr = pa_config->gart_config.page_table_start_addr;
2683 config.gart_config.page_table_end_addr = pa_config->gart_config.page_table_end_addr;
2684 config.gart_config.page_table_base_addr = pa_config->gart_config.page_table_base_addr;
2685 config.page_table_default_page_addr = pa_config->page_table_default_page_addr;
2687 return dc->res_pool->hubbub->funcs->init_dchub_sys_ctx(dc->res_pool->hubbub, &config);
2690 static bool patch_address_for_sbs_tb_stereo(
2691 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
2693 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2694 bool sec_split = pipe_ctx->top_pipe &&
2695 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
2696 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2697 (pipe_ctx->stream->timing.timing_3d_format ==
2698 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2699 pipe_ctx->stream->timing.timing_3d_format ==
2700 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
2701 *addr = plane_state->address.grph_stereo.left_addr;
2702 plane_state->address.grph_stereo.left_addr =
2703 plane_state->address.grph_stereo.right_addr;
2707 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
2708 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
2709 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
2710 plane_state->address.grph_stereo.right_addr =
2711 plane_state->address.grph_stereo.left_addr;
2712 plane_state->address.grph_stereo.right_meta_addr =
2713 plane_state->address.grph_stereo.left_meta_addr;
2718 void dcn20_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
2720 bool addr_patched = false;
2721 PHYSICAL_ADDRESS_LOC addr;
2722 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2724 if (plane_state == NULL)
2727 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
2729 // Call Helper to track VMID use
2730 vm_helper_mark_vmid_used(dc->vm_helper, plane_state->address.vmid, pipe_ctx->plane_res.hubp->inst);
2732 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
2733 pipe_ctx->plane_res.hubp,
2734 &plane_state->address,
2735 plane_state->flip_immediate);
2737 plane_state->status.requested_address = plane_state->address;
2739 if (plane_state->flip_immediate)
2740 plane_state->status.current_address = plane_state->address;
2743 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
2746 void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx,
2747 struct dc_link_settings *link_settings)
2749 struct encoder_unblank_param params = {0};
2750 struct dc_stream_state *stream = pipe_ctx->stream;
2751 struct dc_link *link = stream->link;
2752 struct dce_hwseq *hws = link->dc->hwseq;
2753 struct pipe_ctx *odm_pipe;
2754 bool is_two_pixels_per_container =
2755 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing);
2759 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
2762 /* only 3 items below are used by unblank */
2763 params.timing = pipe_ctx->stream->timing;
2765 params.link_settings.link_rate = link_settings->link_rate;
2767 if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
2768 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
2769 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_unblank(
2770 pipe_ctx->stream_res.hpo_dp_stream_enc,
2771 pipe_ctx->stream_res.tg->inst);
2772 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
2773 if (is_two_pixels_per_container || params.opp_cnt > 1)
2774 params.timing.pix_clk_100hz /= 2;
2775 pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine(
2776 pipe_ctx->stream_res.stream_enc, params.opp_cnt > 1);
2777 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
2780 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
2781 hws->funcs.edp_backlight_control(link, true);
2785 void dcn20_setup_vupdate_interrupt(struct dc *dc, struct pipe_ctx *pipe_ctx)
2787 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2788 int start_line = dc->hwss.get_vupdate_offset_from_vsync(pipe_ctx);
2793 if (tg->funcs->setup_vertical_interrupt2)
2794 tg->funcs->setup_vertical_interrupt2(tg, start_line);
2797 void dcn20_reset_back_end_for_pipe(
2799 struct pipe_ctx *pipe_ctx,
2800 struct dc_state *context)
2802 struct dc_link *link = pipe_ctx->stream->link;
2803 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
2805 DC_LOGGER_INIT(dc->ctx->logger);
2806 if (pipe_ctx->stream_res.stream_enc == NULL) {
2807 pipe_ctx->stream = NULL;
2811 /* DPMS may already disable or */
2812 /* dpms_off status is incorrect due to fastboot
2813 * feature. When system resume from S4 with second
2814 * screen only, the dpms_off would be true but
2815 * VBIOS lit up eDP, so check link status too.
2817 if (!pipe_ctx->stream->dpms_off || link->link_status.link_active)
2818 dc->link_srv->set_dpms_off(pipe_ctx);
2819 else if (pipe_ctx->stream_res.audio)
2820 dc->hwss.disable_audio_stream(pipe_ctx);
2822 /* free acquired resources */
2823 if (pipe_ctx->stream_res.audio) {
2824 /*disable az_endpoint*/
2825 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2828 if (dc->caps.dynamic_audio == true) {
2829 /*we have to dynamic arbitrate the audio endpoints*/
2830 /*we free the resource, need reset is_audio_acquired*/
2831 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2832 pipe_ctx->stream_res.audio, false);
2833 pipe_ctx->stream_res.audio = NULL;
2837 /* by upper caller loop, parent pipe: pipe0, will be reset last.
2838 * back end share by all pipes and will be disable only when disable
2841 if (pipe_ctx->top_pipe == NULL) {
2843 dc->hwss.set_abm_immediate_disable(pipe_ctx);
2845 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
2847 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
2848 if (pipe_ctx->stream_res.tg->funcs->set_odm_bypass)
2849 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
2850 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
2852 if (pipe_ctx->stream_res.tg->funcs->set_drr)
2853 pipe_ctx->stream_res.tg->funcs->set_drr(
2854 pipe_ctx->stream_res.tg, NULL);
2855 /* TODO - convert symclk_ref_cnts for otg to a bit map to solve
2856 * the case where the same symclk is shared across multiple otg
2859 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
2860 link->phy_state.symclk_ref_cnts.otg = 0;
2861 if (link->phy_state.symclk_state == SYMCLK_ON_TX_OFF) {
2862 link_hwss->disable_link_output(link,
2863 &pipe_ctx->link_res, pipe_ctx->stream->signal);
2864 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
2869 * In case of a dangling plane, setting this to NULL unconditionally
2870 * causes failures during reset hw ctx where, if stream is NULL,
2871 * it is expected that the pipe_ctx pointers to pipes and plane are NULL.
2873 pipe_ctx->stream = NULL;
2874 pipe_ctx->top_pipe = NULL;
2875 pipe_ctx->bottom_pipe = NULL;
2876 pipe_ctx->next_odm_pipe = NULL;
2877 pipe_ctx->prev_odm_pipe = NULL;
2878 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
2879 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
2882 void dcn20_reset_hw_ctx_wrap(
2884 struct dc_state *context)
2887 struct dce_hwseq *hws = dc->hwseq;
2890 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
2891 struct pipe_ctx *pipe_ctx_old =
2892 &dc->current_state->res_ctx.pipe_ctx[i];
2893 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2895 if (!pipe_ctx_old->stream)
2898 if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe)
2901 if (!pipe_ctx->stream ||
2902 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2903 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2905 dcn20_reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
2906 if (hws->funcs.enable_stream_gating)
2907 hws->funcs.enable_stream_gating(dc, pipe_ctx_old);
2909 old_clk->funcs->cs_power_down(old_clk);
2914 void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
2916 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2917 struct mpcc_blnd_cfg blnd_cfg = {0};
2918 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha;
2920 struct mpcc *new_mpcc;
2921 struct mpc *mpc = dc->res_pool->mpc;
2922 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
2924 blnd_cfg.overlap_only = false;
2925 blnd_cfg.global_gain = 0xff;
2927 if (per_pixel_alpha) {
2928 blnd_cfg.pre_multiplied_alpha = pipe_ctx->plane_state->pre_multiplied_alpha;
2929 if (pipe_ctx->plane_state->global_alpha) {
2930 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN;
2931 blnd_cfg.global_gain = pipe_ctx->plane_state->global_alpha_value;
2933 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
2936 blnd_cfg.pre_multiplied_alpha = false;
2937 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
2940 if (pipe_ctx->plane_state->global_alpha)
2941 blnd_cfg.global_alpha = pipe_ctx->plane_state->global_alpha_value;
2943 blnd_cfg.global_alpha = 0xff;
2945 blnd_cfg.background_color_bpc = 4;
2946 blnd_cfg.bottom_gain_mode = 0;
2947 blnd_cfg.top_gain = 0x1f000;
2948 blnd_cfg.bottom_inside_gain = 0x1f000;
2949 blnd_cfg.bottom_outside_gain = 0x1f000;
2951 if (pipe_ctx->plane_state->format
2952 == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA)
2953 blnd_cfg.pre_multiplied_alpha = false;
2957 * Note: currently there is a bug in init_hw such that
2958 * on resume from hibernate, BIOS sets up MPCC0, and
2959 * we do mpcc_remove but the mpcc cannot go to idle
2960 * after remove. This cause us to pick mpcc1 here,
2961 * which causes a pstate hang for yet unknown reason.
2963 mpcc_id = hubp->inst;
2965 /* If there is no full update, don't need to touch MPC tree*/
2966 if (!pipe_ctx->plane_state->update_flags.bits.full_update &&
2967 !pipe_ctx->update_flags.bits.mpcc) {
2968 mpc->funcs->update_blending(mpc, &blnd_cfg, mpcc_id);
2969 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, mpcc_id);
2973 /* check if this MPCC is already being used */
2974 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
2975 /* remove MPCC if being used */
2976 if (new_mpcc != NULL)
2977 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
2979 if (dc->debug.sanity_checks)
2980 mpc->funcs->assert_mpcc_idle_before_connect(
2981 dc->res_pool->mpc, mpcc_id);
2983 /* Call MPC to insert new plane */
2984 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
2991 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, mpcc_id);
2993 ASSERT(new_mpcc != NULL);
2994 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
2995 hubp->mpcc_id = mpcc_id;
2998 void dcn20_enable_stream(struct pipe_ctx *pipe_ctx)
3000 enum dc_lane_count lane_count =
3001 pipe_ctx->stream->link->cur_link_settings.lane_count;
3003 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
3004 struct dc_link *link = pipe_ctx->stream->link;
3006 uint32_t active_total_with_borders;
3007 uint32_t early_control = 0;
3008 struct timing_generator *tg = pipe_ctx->stream_res.tg;
3009 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
3010 struct dc *dc = pipe_ctx->stream->ctx->dc;
3011 struct dtbclk_dto_params dto_params = {0};
3012 struct dccg *dccg = dc->res_pool->dccg;
3013 enum phyd32clk_clock_source phyd32clk;
3016 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
3017 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
3019 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
3020 dto_params.otg_inst = tg->inst;
3021 dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10;
3022 dto_params.num_odm_segments = get_odm_segment_count(pipe_ctx);
3023 dto_params.timing = &pipe_ctx->stream->timing;
3024 dto_params.ref_dtbclk_khz = dc->clk_mgr->funcs->get_dtb_ref_clk_frequency(dc->clk_mgr);
3025 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
3026 dp_hpo_inst = pipe_ctx->stream_res.hpo_dp_stream_enc->inst;
3027 dccg->funcs->set_dpstreamclk(dccg, DTBCLK0, tg->inst, dp_hpo_inst);
3029 phyd32clk = get_phyd32clk_src(link);
3030 dccg->funcs->enable_symclk32_se(dccg, dp_hpo_inst, phyd32clk);
3032 if (dccg->funcs->enable_symclk_se)
3033 dccg->funcs->enable_symclk_se(dccg, stream_enc->stream_enc_inst,
3034 link_enc->transmitter - TRANSMITTER_UNIPHY_A);
3037 if (dc->res_pool->dccg->funcs->set_pixel_rate_div)
3038 dc->res_pool->dccg->funcs->set_pixel_rate_div(
3040 pipe_ctx->stream_res.tg->inst,
3041 pipe_ctx->pixel_rate_divider.div_factor1,
3042 pipe_ctx->pixel_rate_divider.div_factor2);
3044 link_hwss->setup_stream_encoder(pipe_ctx);
3046 if (pipe_ctx->plane_state && pipe_ctx->plane_state->flip_immediate != 1) {
3047 if (dc->hwss.program_dmdata_engine)
3048 dc->hwss.program_dmdata_engine(pipe_ctx);
3051 dc->hwss.update_info_frame(pipe_ctx);
3053 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3054 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
3056 /* enable early control to avoid corruption on DP monitor*/
3057 active_total_with_borders =
3058 timing->h_addressable
3059 + timing->h_border_left
3060 + timing->h_border_right;
3062 if (lane_count != 0)
3063 early_control = active_total_with_borders % lane_count;
3065 if (early_control == 0)
3066 early_control = lane_count;
3068 tg->funcs->set_early_control(tg, early_control);
3071 void dcn20_program_dmdata_engine(struct pipe_ctx *pipe_ctx)
3073 struct dc_stream_state *stream = pipe_ctx->stream;
3074 struct hubp *hubp = pipe_ctx->plane_res.hubp;
3075 bool enable = false;
3076 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
3077 enum dynamic_metadata_mode mode = dc_is_dp_signal(stream->signal)
3081 /* if using dynamic meta, don't set up generic infopackets */
3082 if (pipe_ctx->stream->dmdata_address.quad_part != 0) {
3083 pipe_ctx->stream_res.encoder_info_frame.hdrsmd.valid = false;
3090 if (!stream_enc || !stream_enc->funcs->set_dynamic_metadata)
3093 stream_enc->funcs->set_dynamic_metadata(stream_enc, enable,
3097 void dcn20_fpga_init_hw(struct dc *dc)
3100 struct dce_hwseq *hws = dc->hwseq;
3101 struct resource_pool *res_pool = dc->res_pool;
3102 struct dc_state *context = dc->current_state;
3104 if (dc->clk_mgr && dc->clk_mgr->funcs->init_clocks)
3105 dc->clk_mgr->funcs->init_clocks(dc->clk_mgr);
3107 // Initialize the dccg
3108 if (res_pool->dccg->funcs->dccg_init)
3109 res_pool->dccg->funcs->dccg_init(res_pool->dccg);
3111 //Enable ability to power gate / don't force power on permanently
3112 hws->funcs.enable_power_gating_plane(hws, true);
3114 // Specific to FPGA dccg and registers
3115 REG_WRITE(RBBMIF_TIMEOUT_DIS, 0xFFFFFFFF);
3116 REG_WRITE(RBBMIF_TIMEOUT_DIS_2, 0xFFFFFFFF);
3118 hws->funcs.dccg_init(hws);
3120 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, 2);
3121 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
3122 if (REG(REFCLK_CNTL))
3123 REG_WRITE(REFCLK_CNTL, 0);
3127 /* Blank pixel data with OPP DPG */
3128 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3129 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3131 if (tg->funcs->is_tg_enabled(tg))
3132 dcn20_init_blank(dc, tg);
3135 for (i = 0; i < res_pool->timing_generator_count; i++) {
3136 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3138 if (tg->funcs->is_tg_enabled(tg))
3139 tg->funcs->lock(tg);
3142 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3143 struct dpp *dpp = res_pool->dpps[i];
3145 dpp->funcs->dpp_reset(dpp);
3148 /* Reset all MPCC muxes */
3149 res_pool->mpc->funcs->mpc_init(res_pool->mpc);
3151 /* initialize OPP mpc_tree parameter */
3152 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3153 res_pool->opps[i]->mpc_tree_params.opp_id = res_pool->opps[i]->inst;
3154 res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
3155 for (j = 0; j < MAX_PIPES; j++)
3156 res_pool->opps[i]->mpcc_disconnect_pending[j] = false;
3159 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3160 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3161 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3162 struct hubp *hubp = dc->res_pool->hubps[i];
3163 struct dpp *dpp = dc->res_pool->dpps[i];
3165 pipe_ctx->stream_res.tg = tg;
3166 pipe_ctx->pipe_idx = i;
3168 pipe_ctx->plane_res.hubp = hubp;
3169 pipe_ctx->plane_res.dpp = dpp;
3170 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
3171 hubp->mpcc_id = dpp->inst;
3172 hubp->opp_id = OPP_ID_INVALID;
3173 hubp->power_gated = false;
3174 pipe_ctx->stream_res.opp = NULL;
3176 hubp->funcs->hubp_init(hubp);
3178 //dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
3179 //dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
3180 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
3181 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
3183 hws->funcs.plane_atomic_disconnect(dc, context, pipe_ctx);
3186 /* initialize DWB pointer to MCIF_WB */
3187 for (i = 0; i < res_pool->res_cap->num_dwb; i++)
3188 res_pool->dwbc[i]->mcif = res_pool->mcif_wb[i];
3190 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3191 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3193 if (tg->funcs->is_tg_enabled(tg))
3194 tg->funcs->unlock(tg);
3197 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3198 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3200 dc->hwss.disable_plane(dc, context, pipe_ctx);
3202 pipe_ctx->stream_res.tg = NULL;
3203 pipe_ctx->plane_res.hubp = NULL;
3206 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3207 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3209 tg->funcs->tg_init(tg);
3212 if (dc->res_pool->hubbub->funcs->init_crb)
3213 dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub);
3216 void dcn20_set_disp_pattern_generator(const struct dc *dc,
3217 struct pipe_ctx *pipe_ctx,
3218 enum controller_dp_test_pattern test_pattern,
3219 enum controller_dp_color_space color_space,
3220 enum dc_color_depth color_depth,
3221 const struct tg_color *solid_color,
3222 int width, int height, int offset)
3224 pipe_ctx->stream_res.opp->funcs->opp_set_disp_pattern_generator(pipe_ctx->stream_res.opp, test_pattern,
3225 color_space, color_depth, solid_color, width, height, offset);