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.
26 #include <linux/delay.h>
27 #include "dm_services.h"
28 #include "core_types.h"
30 #include "custom_float.h"
31 #include "dcn10_hw_sequencer.h"
32 #include "dce110/dce110_hw_sequencer.h"
33 #include "dce/dce_hwseq.h"
36 #include "dcn10_optc.h"
37 #include "dcn10/dcn10_dpp.h"
38 #include "dcn10/dcn10_mpc.h"
39 #include "timing_generator.h"
43 #include "reg_helper.h"
44 #include "custom_float.h"
45 #include "dcn10_hubp.h"
46 #include "dcn10_hubbub.h"
47 #include "dcn10_cm_common.h"
49 #define DC_LOGGER_INIT(logger)
57 #define FN(reg_name, field_name) \
58 hws->shifts->field_name, hws->masks->field_name
60 /*print is 17 wide, first two characters are spaces*/
61 #define DTN_INFO_MICRO_SEC(ref_cycle) \
62 print_microsec(dc_ctx, ref_cycle)
64 void print_microsec(struct dc_context *dc_ctx, uint32_t ref_cycle)
66 const uint32_t ref_clk_mhz = dc_ctx->dc->res_pool->ref_clock_inKhz / 1000;
67 static const unsigned int frac = 1000;
68 uint32_t us_x10 = (ref_cycle * frac) / ref_clk_mhz;
70 DTN_INFO(" %11d.%03d",
76 static void log_mpc_crc(struct dc *dc)
78 struct dc_context *dc_ctx = dc->ctx;
79 struct dce_hwseq *hws = dc->hwseq;
81 if (REG(MPC_CRC_RESULT_GB))
82 DTN_INFO("MPC_CRC_RESULT_GB:%d MPC_CRC_RESULT_C:%d MPC_CRC_RESULT_AR:%d\n",
83 REG_READ(MPC_CRC_RESULT_GB), REG_READ(MPC_CRC_RESULT_C), REG_READ(MPC_CRC_RESULT_AR));
84 if (REG(DPP_TOP0_DPP_CRC_VAL_B_A))
85 DTN_INFO("DPP_TOP0_DPP_CRC_VAL_B_A:%d DPP_TOP0_DPP_CRC_VAL_R_G:%d\n",
86 REG_READ(DPP_TOP0_DPP_CRC_VAL_B_A), REG_READ(DPP_TOP0_DPP_CRC_VAL_R_G));
89 void dcn10_log_hubbub_state(struct dc *dc)
91 struct dc_context *dc_ctx = dc->ctx;
92 struct dcn_hubbub_wm wm;
95 hubbub1_wm_read_state(dc->res_pool->hubbub, &wm);
97 DTN_INFO("HUBBUB WM: data_urgent pte_meta_urgent"
98 " sr_enter sr_exit dram_clk_change\n");
100 for (i = 0; i < 4; i++) {
101 struct dcn_hubbub_wm_set *s;
104 DTN_INFO("WM_Set[%d]:", s->wm_set);
105 DTN_INFO_MICRO_SEC(s->data_urgent);
106 DTN_INFO_MICRO_SEC(s->pte_meta_urgent);
107 DTN_INFO_MICRO_SEC(s->sr_enter);
108 DTN_INFO_MICRO_SEC(s->sr_exit);
109 DTN_INFO_MICRO_SEC(s->dram_clk_chanage);
116 static void dcn10_log_hubp_states(struct dc *dc)
118 struct dc_context *dc_ctx = dc->ctx;
119 struct resource_pool *pool = dc->res_pool;
122 DTN_INFO("HUBP: format addr_hi width height"
123 " rot mir sw_mode dcc_en blank_en ttu_dis underflow"
124 " min_ttu_vblank qos_low_wm qos_high_wm\n");
125 for (i = 0; i < pool->pipe_count; i++) {
126 struct hubp *hubp = pool->hubps[i];
127 struct dcn_hubp_state *s = &(TO_DCN10_HUBP(hubp)->state);
129 hubp->funcs->hubp_read_state(hubp);
132 DTN_INFO("[%2d]: %5xh %6xh %5d %6d %2xh %2xh %6xh"
145 s->underflow_status);
146 DTN_INFO_MICRO_SEC(s->min_ttu_vblank);
147 DTN_INFO_MICRO_SEC(s->qos_level_low_wm);
148 DTN_INFO_MICRO_SEC(s->qos_level_high_wm);
153 DTN_INFO("\n=========RQ========\n");
154 DTN_INFO("HUBP: drq_exp_m prq_exp_m mrq_exp_m crq_exp_m plane1_ba L:chunk_s min_chu_s meta_ch_s"
155 " min_m_c_s dpte_gr_s mpte_gr_s swath_hei pte_row_h C:chunk_s min_chu_s meta_ch_s"
156 " min_m_c_s dpte_gr_s mpte_gr_s swath_hei pte_row_h\n");
157 for (i = 0; i < pool->pipe_count; i++) {
158 struct dcn_hubp_state *s = &(TO_DCN10_HUBP(pool->hubps[i])->state);
159 struct _vcs_dpi_display_rq_regs_st *rq_regs = &s->rq_regs;
162 DTN_INFO("[%2d]: %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh\n",
163 pool->hubps[i]->inst, rq_regs->drq_expansion_mode, rq_regs->prq_expansion_mode, rq_regs->mrq_expansion_mode,
164 rq_regs->crq_expansion_mode, rq_regs->plane1_base_address, rq_regs->rq_regs_l.chunk_size,
165 rq_regs->rq_regs_l.min_chunk_size, rq_regs->rq_regs_l.meta_chunk_size,
166 rq_regs->rq_regs_l.min_meta_chunk_size, rq_regs->rq_regs_l.dpte_group_size,
167 rq_regs->rq_regs_l.mpte_group_size, rq_regs->rq_regs_l.swath_height,
168 rq_regs->rq_regs_l.pte_row_height_linear, rq_regs->rq_regs_c.chunk_size, rq_regs->rq_regs_c.min_chunk_size,
169 rq_regs->rq_regs_c.meta_chunk_size, rq_regs->rq_regs_c.min_meta_chunk_size,
170 rq_regs->rq_regs_c.dpte_group_size, rq_regs->rq_regs_c.mpte_group_size,
171 rq_regs->rq_regs_c.swath_height, rq_regs->rq_regs_c.pte_row_height_linear);
174 DTN_INFO("========DLG========\n");
175 DTN_INFO("HUBP: rc_hbe dlg_vbe min_d_y_n rc_per_ht rc_x_a_s "
176 " dst_y_a_s dst_y_pf dst_y_vvb dst_y_rvb dst_y_vfl dst_y_rfl rf_pix_fq"
177 " vratio_pf vrat_pf_c rc_pg_vbl rc_pg_vbc rc_mc_vbl rc_mc_vbc rc_pg_fll"
178 " rc_pg_flc rc_mc_fll rc_mc_flc pr_nom_l pr_nom_c rc_pg_nl rc_pg_nc "
179 " mr_nom_l mr_nom_c rc_mc_nl rc_mc_nc rc_ld_pl rc_ld_pc rc_ld_l "
180 " rc_ld_c cha_cur0 ofst_cur1 cha_cur1 vr_af_vc0 ddrq_limt x_rt_dlay"
181 " x_rp_dlay x_rr_sfl\n");
182 for (i = 0; i < pool->pipe_count; i++) {
183 struct dcn_hubp_state *s = &(TO_DCN10_HUBP(pool->hubps[i])->state);
184 struct _vcs_dpi_display_dlg_regs_st *dlg_regs = &s->dlg_attr;
187 DTN_INFO("[%2d]: %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh"
188 "% 8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh"
189 " %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh\n",
190 pool->hubps[i]->inst, dlg_regs->refcyc_h_blank_end, dlg_regs->dlg_vblank_end, dlg_regs->min_dst_y_next_start,
191 dlg_regs->refcyc_per_htotal, dlg_regs->refcyc_x_after_scaler, dlg_regs->dst_y_after_scaler,
192 dlg_regs->dst_y_prefetch, dlg_regs->dst_y_per_vm_vblank, dlg_regs->dst_y_per_row_vblank,
193 dlg_regs->dst_y_per_vm_flip, dlg_regs->dst_y_per_row_flip, dlg_regs->ref_freq_to_pix_freq,
194 dlg_regs->vratio_prefetch, dlg_regs->vratio_prefetch_c, dlg_regs->refcyc_per_pte_group_vblank_l,
195 dlg_regs->refcyc_per_pte_group_vblank_c, dlg_regs->refcyc_per_meta_chunk_vblank_l,
196 dlg_regs->refcyc_per_meta_chunk_vblank_c, dlg_regs->refcyc_per_pte_group_flip_l,
197 dlg_regs->refcyc_per_pte_group_flip_c, dlg_regs->refcyc_per_meta_chunk_flip_l,
198 dlg_regs->refcyc_per_meta_chunk_flip_c, dlg_regs->dst_y_per_pte_row_nom_l,
199 dlg_regs->dst_y_per_pte_row_nom_c, dlg_regs->refcyc_per_pte_group_nom_l,
200 dlg_regs->refcyc_per_pte_group_nom_c, dlg_regs->dst_y_per_meta_row_nom_l,
201 dlg_regs->dst_y_per_meta_row_nom_c, dlg_regs->refcyc_per_meta_chunk_nom_l,
202 dlg_regs->refcyc_per_meta_chunk_nom_c, dlg_regs->refcyc_per_line_delivery_pre_l,
203 dlg_regs->refcyc_per_line_delivery_pre_c, dlg_regs->refcyc_per_line_delivery_l,
204 dlg_regs->refcyc_per_line_delivery_c, dlg_regs->chunk_hdl_adjust_cur0, dlg_regs->dst_y_offset_cur1,
205 dlg_regs->chunk_hdl_adjust_cur1, dlg_regs->vready_after_vcount0, dlg_regs->dst_y_delta_drq_limit,
206 dlg_regs->xfc_reg_transfer_delay, dlg_regs->xfc_reg_precharge_delay,
207 dlg_regs->xfc_reg_remote_surface_flip_latency);
210 DTN_INFO("========TTU========\n");
211 DTN_INFO("HUBP: qos_ll_wm qos_lh_wm mn_ttu_vb qos_l_flp rc_rd_p_l rc_rd_l rc_rd_p_c"
212 " rc_rd_c rc_rd_c0 rc_rd_pc0 rc_rd_c1 rc_rd_pc1 qos_lf_l qos_rds_l"
213 " qos_lf_c qos_rds_c qos_lf_c0 qos_rds_c0 qos_lf_c1 qos_rds_c1\n");
214 for (i = 0; i < pool->pipe_count; i++) {
215 struct dcn_hubp_state *s = &(TO_DCN10_HUBP(pool->hubps[i])->state);
216 struct _vcs_dpi_display_ttu_regs_st *ttu_regs = &s->ttu_attr;
219 DTN_INFO("[%2d]: %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh %8xh\n",
220 pool->hubps[i]->inst, ttu_regs->qos_level_low_wm, ttu_regs->qos_level_high_wm, ttu_regs->min_ttu_vblank,
221 ttu_regs->qos_level_flip, ttu_regs->refcyc_per_req_delivery_pre_l, ttu_regs->refcyc_per_req_delivery_l,
222 ttu_regs->refcyc_per_req_delivery_pre_c, ttu_regs->refcyc_per_req_delivery_c, ttu_regs->refcyc_per_req_delivery_cur0,
223 ttu_regs->refcyc_per_req_delivery_pre_cur0, ttu_regs->refcyc_per_req_delivery_cur1,
224 ttu_regs->refcyc_per_req_delivery_pre_cur1, ttu_regs->qos_level_fixed_l, ttu_regs->qos_ramp_disable_l,
225 ttu_regs->qos_level_fixed_c, ttu_regs->qos_ramp_disable_c, ttu_regs->qos_level_fixed_cur0,
226 ttu_regs->qos_ramp_disable_cur0, ttu_regs->qos_level_fixed_cur1, ttu_regs->qos_ramp_disable_cur1);
231 void dcn10_log_hw_state(struct dc *dc)
233 struct dc_context *dc_ctx = dc->ctx;
234 struct resource_pool *pool = dc->res_pool;
239 dcn10_log_hubbub_state(dc);
241 dcn10_log_hubp_states(dc);
243 DTN_INFO("DPP: IGAM format IGAM mode DGAM mode RGAM mode"
244 " GAMUT mode C11 C12 C13 C14 C21 C22 C23 C24 "
245 "C31 C32 C33 C34\n");
246 for (i = 0; i < pool->pipe_count; i++) {
247 struct dpp *dpp = pool->dpps[i];
248 struct dcn_dpp_state s;
250 dpp->funcs->dpp_read_state(dpp, &s);
252 DTN_INFO("[%2d]: %11xh %-11s %-11s %-11s"
253 "%8x %08xh %08xh %08xh %08xh %08xh %08xh",
256 (s.igam_lut_mode == 0) ? "BypassFixed" :
257 ((s.igam_lut_mode == 1) ? "BypassFloat" :
258 ((s.igam_lut_mode == 2) ? "RAM" :
259 ((s.igam_lut_mode == 3) ? "RAM" :
261 (s.dgam_lut_mode == 0) ? "Bypass" :
262 ((s.dgam_lut_mode == 1) ? "sRGB" :
263 ((s.dgam_lut_mode == 2) ? "Ycc" :
264 ((s.dgam_lut_mode == 3) ? "RAM" :
265 ((s.dgam_lut_mode == 4) ? "RAM" :
267 (s.rgam_lut_mode == 0) ? "Bypass" :
268 ((s.rgam_lut_mode == 1) ? "sRGB" :
269 ((s.rgam_lut_mode == 2) ? "Ycc" :
270 ((s.rgam_lut_mode == 3) ? "RAM" :
271 ((s.rgam_lut_mode == 4) ? "RAM" :
274 s.gamut_remap_c11_c12,
275 s.gamut_remap_c13_c14,
276 s.gamut_remap_c21_c22,
277 s.gamut_remap_c23_c24,
278 s.gamut_remap_c31_c32,
279 s.gamut_remap_c33_c34);
284 DTN_INFO("MPCC: OPP DPP MPCCBOT MODE ALPHA_MODE PREMULT OVERLAP_ONLY IDLE\n");
285 for (i = 0; i < pool->pipe_count; i++) {
286 struct mpcc_state s = {0};
288 pool->mpc->funcs->read_mpcc_state(pool->mpc, i, &s);
290 DTN_INFO("[%2d]: %2xh %2xh %6xh %4d %10d %7d %12d %4d\n",
291 i, s.opp_id, s.dpp_id, s.bot_mpcc_id,
292 s.mode, s.alpha_mode, s.pre_multiplied_alpha, s.overlap_only,
297 DTN_INFO("OTG: v_bs v_be v_ss v_se vpol vmax vmin vmax_sel vmin_sel"
298 " h_bs h_be h_ss h_se hpol htot vtot underflow\n");
300 for (i = 0; i < pool->timing_generator_count; i++) {
301 struct timing_generator *tg = pool->timing_generators[i];
302 struct dcn_otg_state s = {0};
304 optc1_read_otg_state(DCN10TG_FROM_TG(tg), &s);
306 //only print if OTG master is enabled
307 if ((s.otg_enabled & 1) == 0)
310 DTN_INFO("[%d]: %5d %5d %5d %5d %5d %5d %5d %9d %9d %5d %5d %5d"
311 " %5d %5d %5d %5d %9d\n",
329 s.underflow_occurred_status);
331 // Clear underflow for debug purposes
332 // We want to keep underflow sticky bit on for the longevity tests outside of test environment.
333 // This function is called only from Windows or Diags test environment, hence it's safe to clear
334 // it from here without affecting the original intent.
335 tg->funcs->clear_optc_underflow(tg);
339 DTN_INFO("\nCALCULATED Clocks: dcfclk_khz:%d dcfclk_deep_sleep_khz:%d dispclk_khz:%d\n"
340 "dppclk_khz:%d max_supported_dppclk_khz:%d fclk_khz:%d socclk_khz:%d\n\n",
341 dc->current_state->bw.dcn.clk.dcfclk_khz,
342 dc->current_state->bw.dcn.clk.dcfclk_deep_sleep_khz,
343 dc->current_state->bw.dcn.clk.dispclk_khz,
344 dc->current_state->bw.dcn.clk.dppclk_khz,
345 dc->current_state->bw.dcn.clk.max_supported_dppclk_khz,
346 dc->current_state->bw.dcn.clk.fclk_khz,
347 dc->current_state->bw.dcn.clk.socclk_khz);
354 static void enable_power_gating_plane(
355 struct dce_hwseq *hws,
358 bool force_on = 1; /* disable power gating */
364 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on);
365 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN2_POWER_FORCEON, force_on);
366 REG_UPDATE(DOMAIN4_PG_CONFIG, DOMAIN4_POWER_FORCEON, force_on);
367 REG_UPDATE(DOMAIN6_PG_CONFIG, DOMAIN6_POWER_FORCEON, force_on);
370 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN1_POWER_FORCEON, force_on);
371 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN3_POWER_FORCEON, force_on);
372 REG_UPDATE(DOMAIN5_PG_CONFIG, DOMAIN5_POWER_FORCEON, force_on);
373 REG_UPDATE(DOMAIN7_PG_CONFIG, DOMAIN7_POWER_FORCEON, force_on);
376 static void disable_vga(
377 struct dce_hwseq *hws)
379 unsigned int in_vga1_mode = 0;
380 unsigned int in_vga2_mode = 0;
381 unsigned int in_vga3_mode = 0;
382 unsigned int in_vga4_mode = 0;
384 REG_GET(D1VGA_CONTROL, D1VGA_MODE_ENABLE, &in_vga1_mode);
385 REG_GET(D2VGA_CONTROL, D2VGA_MODE_ENABLE, &in_vga2_mode);
386 REG_GET(D3VGA_CONTROL, D3VGA_MODE_ENABLE, &in_vga3_mode);
387 REG_GET(D4VGA_CONTROL, D4VGA_MODE_ENABLE, &in_vga4_mode);
389 if (in_vga1_mode == 0 && in_vga2_mode == 0 &&
390 in_vga3_mode == 0 && in_vga4_mode == 0)
393 REG_WRITE(D1VGA_CONTROL, 0);
394 REG_WRITE(D2VGA_CONTROL, 0);
395 REG_WRITE(D3VGA_CONTROL, 0);
396 REG_WRITE(D4VGA_CONTROL, 0);
398 /* HW Engineer's Notes:
399 * During switch from vga->extended, if we set the VGA_TEST_ENABLE and
400 * then hit the VGA_TEST_RENDER_START, then the DCHUBP timing gets updated correctly.
402 * Then vBIOS will have it poll for the VGA_TEST_RENDER_DONE and unset
403 * VGA_TEST_ENABLE, to leave it in the same state as before.
405 REG_UPDATE(VGA_TEST_CONTROL, VGA_TEST_ENABLE, 1);
406 REG_UPDATE(VGA_TEST_CONTROL, VGA_TEST_RENDER_START, 1);
409 static void dpp_pg_control(
410 struct dce_hwseq *hws,
411 unsigned int dpp_inst,
414 uint32_t power_gate = power_on ? 0 : 1;
415 uint32_t pwr_status = power_on ? 0 : 2;
417 if (hws->ctx->dc->debug.disable_dpp_power_gate)
419 if (REG(DOMAIN1_PG_CONFIG) == 0)
424 REG_UPDATE(DOMAIN1_PG_CONFIG,
425 DOMAIN1_POWER_GATE, power_gate);
427 REG_WAIT(DOMAIN1_PG_STATUS,
428 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
432 REG_UPDATE(DOMAIN3_PG_CONFIG,
433 DOMAIN3_POWER_GATE, power_gate);
435 REG_WAIT(DOMAIN3_PG_STATUS,
436 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
440 REG_UPDATE(DOMAIN5_PG_CONFIG,
441 DOMAIN5_POWER_GATE, power_gate);
443 REG_WAIT(DOMAIN5_PG_STATUS,
444 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
448 REG_UPDATE(DOMAIN7_PG_CONFIG,
449 DOMAIN7_POWER_GATE, power_gate);
451 REG_WAIT(DOMAIN7_PG_STATUS,
452 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
461 static void hubp_pg_control(
462 struct dce_hwseq *hws,
463 unsigned int hubp_inst,
466 uint32_t power_gate = power_on ? 0 : 1;
467 uint32_t pwr_status = power_on ? 0 : 2;
469 if (hws->ctx->dc->debug.disable_hubp_power_gate)
471 if (REG(DOMAIN0_PG_CONFIG) == 0)
475 case 0: /* DCHUBP0 */
476 REG_UPDATE(DOMAIN0_PG_CONFIG,
477 DOMAIN0_POWER_GATE, power_gate);
479 REG_WAIT(DOMAIN0_PG_STATUS,
480 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
483 case 1: /* DCHUBP1 */
484 REG_UPDATE(DOMAIN2_PG_CONFIG,
485 DOMAIN2_POWER_GATE, power_gate);
487 REG_WAIT(DOMAIN2_PG_STATUS,
488 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
491 case 2: /* DCHUBP2 */
492 REG_UPDATE(DOMAIN4_PG_CONFIG,
493 DOMAIN4_POWER_GATE, power_gate);
495 REG_WAIT(DOMAIN4_PG_STATUS,
496 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
499 case 3: /* DCHUBP3 */
500 REG_UPDATE(DOMAIN6_PG_CONFIG,
501 DOMAIN6_POWER_GATE, power_gate);
503 REG_WAIT(DOMAIN6_PG_STATUS,
504 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
513 static void power_on_plane(
514 struct dce_hwseq *hws,
517 DC_LOGGER_INIT(hws->ctx->logger);
518 if (REG(DC_IP_REQUEST_CNTL)) {
519 REG_SET(DC_IP_REQUEST_CNTL, 0,
521 dpp_pg_control(hws, plane_id, true);
522 hubp_pg_control(hws, plane_id, true);
523 REG_SET(DC_IP_REQUEST_CNTL, 0,
526 "Un-gated front end for pipe %d\n", plane_id);
530 static void undo_DEGVIDCN10_253_wa(struct dc *dc)
532 struct dce_hwseq *hws = dc->hwseq;
533 struct hubp *hubp = dc->res_pool->hubps[0];
535 if (!hws->wa_state.DEGVIDCN10_253_applied)
538 hubp->funcs->set_blank(hubp, true);
540 REG_SET(DC_IP_REQUEST_CNTL, 0,
543 hubp_pg_control(hws, 0, false);
544 REG_SET(DC_IP_REQUEST_CNTL, 0,
547 hws->wa_state.DEGVIDCN10_253_applied = false;
550 static void apply_DEGVIDCN10_253_wa(struct dc *dc)
552 struct dce_hwseq *hws = dc->hwseq;
553 struct hubp *hubp = dc->res_pool->hubps[0];
556 if (dc->debug.disable_stutter)
559 if (!hws->wa.DEGVIDCN10_253)
562 for (i = 0; i < dc->res_pool->pipe_count; i++) {
563 if (!dc->res_pool->hubps[i]->power_gated)
567 /* all pipe power gated, apply work around to enable stutter. */
569 REG_SET(DC_IP_REQUEST_CNTL, 0,
572 hubp_pg_control(hws, 0, true);
573 REG_SET(DC_IP_REQUEST_CNTL, 0,
576 hubp->funcs->set_hubp_blank_en(hubp, false);
577 hws->wa_state.DEGVIDCN10_253_applied = true;
580 static void bios_golden_init(struct dc *dc)
582 struct dc_bios *bp = dc->ctx->dc_bios;
585 /* initialize dcn global */
586 bp->funcs->enable_disp_power_gating(bp,
587 CONTROLLER_ID_D0, ASIC_PIPE_INIT);
589 for (i = 0; i < dc->res_pool->pipe_count; i++) {
590 /* initialize dcn per pipe */
591 bp->funcs->enable_disp_power_gating(bp,
592 CONTROLLER_ID_D0 + i, ASIC_PIPE_DISABLE);
596 static void false_optc_underflow_wa(
598 const struct dc_stream_state *stream,
599 struct timing_generator *tg)
604 if (!dc->hwseq->wa.false_optc_underflow)
607 underflow = tg->funcs->is_optc_underflow_occurred(tg);
609 for (i = 0; i < dc->res_pool->pipe_count; i++) {
610 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
612 if (old_pipe_ctx->stream != stream)
615 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, old_pipe_ctx);
618 tg->funcs->set_blank_data_double_buffer(tg, true);
620 if (tg->funcs->is_optc_underflow_occurred(tg) && !underflow)
621 tg->funcs->clear_optc_underflow(tg);
624 static enum dc_status dcn10_enable_stream_timing(
625 struct pipe_ctx *pipe_ctx,
626 struct dc_state *context,
629 struct dc_stream_state *stream = pipe_ctx->stream;
630 enum dc_color_space color_space;
631 struct tg_color black_color = {0};
633 /* by upper caller loop, pipe0 is parent pipe and be called first.
634 * back end is set up by for pipe0. Other children pipe share back end
635 * with pipe 0. No program is needed.
637 if (pipe_ctx->top_pipe != NULL)
640 /* TODO check if timing_changed, disable stream if timing changed */
642 /* HW program guide assume display already disable
643 * by unplug sequence. OTG assume stop.
645 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
647 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
648 pipe_ctx->clock_source,
649 &pipe_ctx->stream_res.pix_clk_params,
650 &pipe_ctx->pll_settings)) {
652 return DC_ERROR_UNEXPECTED;
654 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
655 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
656 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
657 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
659 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
661 pipe_ctx->stream_res.tg->funcs->program_timing(
662 pipe_ctx->stream_res.tg,
666 #if 0 /* move to after enable_crtc */
667 /* TODO: OPP FMT, ABM. etc. should be done here. */
668 /* or FPGA now. instance 0 only. TODO: move to opp.c */
670 inst_offset = reg_offsets[pipe_ctx->stream_res.tg->inst].fmt;
672 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
673 pipe_ctx->stream_res.opp,
674 &stream->bit_depth_params,
677 /* program otg blank color */
678 color_space = stream->output_color_space;
679 color_space_to_black_color(dc, color_space, &black_color);
681 if (pipe_ctx->stream_res.tg->funcs->set_blank_color)
682 pipe_ctx->stream_res.tg->funcs->set_blank_color(
683 pipe_ctx->stream_res.tg,
686 if (pipe_ctx->stream_res.tg->funcs->is_blanked &&
687 !pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg)) {
688 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
689 hwss_wait_for_blank_complete(pipe_ctx->stream_res.tg);
690 false_optc_underflow_wa(dc, pipe_ctx->stream, pipe_ctx->stream_res.tg);
693 /* VTG is within DCHUB command block. DCFCLK is always on */
694 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
696 return DC_ERROR_UNEXPECTED;
699 /* TODO program crtc source select for non-virtual signal*/
700 /* TODO program FMT */
701 /* TODO setup link_enc */
702 /* TODO set stream attributes */
703 /* TODO program audio */
704 /* TODO enable stream if timing changed */
705 /* TODO unblank stream if DP */
710 static void reset_back_end_for_pipe(
712 struct pipe_ctx *pipe_ctx,
713 struct dc_state *context)
716 DC_LOGGER_INIT(dc->ctx->logger);
717 if (pipe_ctx->stream_res.stream_enc == NULL) {
718 pipe_ctx->stream = NULL;
722 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
723 /* DPMS may already disable */
724 if (!pipe_ctx->stream->dpms_off)
725 core_link_disable_stream(pipe_ctx, FREE_ACQUIRED_RESOURCE);
726 else if (pipe_ctx->stream_res.audio) {
727 dc->hwss.disable_audio_stream(pipe_ctx, FREE_ACQUIRED_RESOURCE);
732 /* by upper caller loop, parent pipe: pipe0, will be reset last.
733 * back end share by all pipes and will be disable only when disable
736 if (pipe_ctx->top_pipe == NULL) {
737 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
739 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
742 for (i = 0; i < dc->res_pool->pipe_count; i++)
743 if (&dc->current_state->res_ctx.pipe_ctx[i] == pipe_ctx)
746 if (i == dc->res_pool->pipe_count)
749 pipe_ctx->stream = NULL;
750 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
751 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
754 static bool dcn10_hw_wa_force_recovery(struct dc *dc)
758 bool need_recover = true;
760 if (!dc->debug.recovery_enabled)
763 for (i = 0; i < dc->res_pool->pipe_count; i++) {
764 struct pipe_ctx *pipe_ctx =
765 &dc->current_state->res_ctx.pipe_ctx[i];
766 if (pipe_ctx != NULL) {
767 hubp = pipe_ctx->plane_res.hubp;
769 if (hubp->funcs->hubp_get_underflow_status(hubp) != 0) {
770 /* one pipe underflow, we will reset all the pipes*/
779 DCHUBP_CNTL:HUBP_BLANK_EN=1
780 DCHUBBUB_SOFT_RESET:DCHUBBUB_GLOBAL_SOFT_RESET=1
781 DCHUBP_CNTL:HUBP_DISABLE=1
782 DCHUBP_CNTL:HUBP_DISABLE=0
783 DCHUBBUB_SOFT_RESET:DCHUBBUB_GLOBAL_SOFT_RESET=0
784 DCSURF_PRIMARY_SURFACE_ADDRESS
785 DCHUBP_CNTL:HUBP_BLANK_EN=0
788 for (i = 0; i < dc->res_pool->pipe_count; i++) {
789 struct pipe_ctx *pipe_ctx =
790 &dc->current_state->res_ctx.pipe_ctx[i];
791 if (pipe_ctx != NULL) {
792 hubp = pipe_ctx->plane_res.hubp;
793 /*DCHUBP_CNTL:HUBP_BLANK_EN=1*/
795 hubp->funcs->set_hubp_blank_en(hubp, true);
798 /*DCHUBBUB_SOFT_RESET:DCHUBBUB_GLOBAL_SOFT_RESET=1*/
799 hubbub1_soft_reset(dc->res_pool->hubbub, true);
801 for (i = 0; i < dc->res_pool->pipe_count; i++) {
802 struct pipe_ctx *pipe_ctx =
803 &dc->current_state->res_ctx.pipe_ctx[i];
804 if (pipe_ctx != NULL) {
805 hubp = pipe_ctx->plane_res.hubp;
806 /*DCHUBP_CNTL:HUBP_DISABLE=1*/
808 hubp->funcs->hubp_disable_control(hubp, true);
811 for (i = 0; i < dc->res_pool->pipe_count; i++) {
812 struct pipe_ctx *pipe_ctx =
813 &dc->current_state->res_ctx.pipe_ctx[i];
814 if (pipe_ctx != NULL) {
815 hubp = pipe_ctx->plane_res.hubp;
816 /*DCHUBP_CNTL:HUBP_DISABLE=0*/
818 hubp->funcs->hubp_disable_control(hubp, true);
821 /*DCHUBBUB_SOFT_RESET:DCHUBBUB_GLOBAL_SOFT_RESET=0*/
822 hubbub1_soft_reset(dc->res_pool->hubbub, false);
823 for (i = 0; i < dc->res_pool->pipe_count; i++) {
824 struct pipe_ctx *pipe_ctx =
825 &dc->current_state->res_ctx.pipe_ctx[i];
826 if (pipe_ctx != NULL) {
827 hubp = pipe_ctx->plane_res.hubp;
828 /*DCHUBP_CNTL:HUBP_BLANK_EN=0*/
830 hubp->funcs->set_hubp_blank_en(hubp, true);
838 void dcn10_verify_allow_pstate_change_high(struct dc *dc)
840 static bool should_log_hw_state; /* prevent hw state log by default */
842 if (!hubbub1_verify_allow_pstate_change_high(dc->res_pool->hubbub)) {
843 if (should_log_hw_state) {
844 dcn10_log_hw_state(dc);
847 if (dcn10_hw_wa_force_recovery(dc)) {
849 if (!hubbub1_verify_allow_pstate_change_high(dc->res_pool->hubbub))
855 /* trigger HW to start disconnect plane from stream on the next vsync */
856 void hwss1_plane_atomic_disconnect(struct dc *dc, struct pipe_ctx *pipe_ctx)
858 struct hubp *hubp = pipe_ctx->plane_res.hubp;
859 int dpp_id = pipe_ctx->plane_res.dpp->inst;
860 struct mpc *mpc = dc->res_pool->mpc;
861 struct mpc_tree *mpc_tree_params;
862 struct mpcc *mpcc_to_remove = NULL;
863 struct output_pixel_processor *opp = pipe_ctx->stream_res.opp;
865 mpc_tree_params = &(opp->mpc_tree_params);
866 mpcc_to_remove = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, dpp_id);
869 if (mpcc_to_remove == NULL)
872 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, mpcc_to_remove);
874 opp->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
876 dc->optimized_required = true;
878 if (hubp->funcs->hubp_disconnect)
879 hubp->funcs->hubp_disconnect(hubp);
881 if (dc->debug.sanity_checks)
882 dcn10_verify_allow_pstate_change_high(dc);
885 static void plane_atomic_power_down(struct dc *dc, struct pipe_ctx *pipe_ctx)
887 struct dce_hwseq *hws = dc->hwseq;
888 struct dpp *dpp = pipe_ctx->plane_res.dpp;
889 DC_LOGGER_INIT(dc->ctx->logger);
891 if (REG(DC_IP_REQUEST_CNTL)) {
892 REG_SET(DC_IP_REQUEST_CNTL, 0,
894 dpp_pg_control(hws, dpp->inst, false);
895 hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, false);
896 dpp->funcs->dpp_reset(dpp);
897 REG_SET(DC_IP_REQUEST_CNTL, 0,
900 "Power gated front end %d\n", pipe_ctx->pipe_idx);
904 /* disable HW used by plane.
905 * note: cannot disable until disconnect is complete
907 static void plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
909 struct hubp *hubp = pipe_ctx->plane_res.hubp;
910 struct dpp *dpp = pipe_ctx->plane_res.dpp;
911 int opp_id = hubp->opp_id;
913 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
915 hubp->funcs->hubp_clk_cntl(hubp, false);
917 dpp->funcs->dpp_dppclk_control(dpp, false, false);
919 if (opp_id != 0xf && pipe_ctx->stream_res.opp->mpc_tree_params.opp_list == NULL)
920 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
921 pipe_ctx->stream_res.opp,
924 hubp->power_gated = true;
925 dc->optimized_required = false; /* We're powering off, no need to optimize */
927 plane_atomic_power_down(dc, pipe_ctx);
929 pipe_ctx->stream = NULL;
930 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
931 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
932 pipe_ctx->top_pipe = NULL;
933 pipe_ctx->bottom_pipe = NULL;
934 pipe_ctx->plane_state = NULL;
937 static void dcn10_disable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx)
939 DC_LOGGER_INIT(dc->ctx->logger);
941 if (!pipe_ctx->plane_res.hubp || pipe_ctx->plane_res.hubp->power_gated)
944 plane_atomic_disable(dc, pipe_ctx);
946 apply_DEGVIDCN10_253_wa(dc);
948 DC_LOG_DC("Power down front end %d\n",
952 static void dcn10_init_hw(struct dc *dc)
955 struct abm *abm = dc->res_pool->abm;
956 struct dmcu *dmcu = dc->res_pool->dmcu;
957 struct dce_hwseq *hws = dc->hwseq;
958 struct dc_bios *dcb = dc->ctx->dc_bios;
959 struct dc_state *context = dc->current_state;
961 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
962 REG_WRITE(REFCLK_CNTL, 0);
963 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
964 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
966 if (!dc->debug.disable_clock_gate) {
967 /* enable all DCN clock gating */
968 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
970 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
972 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
975 enable_power_gating_plane(dc->hwseq, true);
978 if (!dcb->funcs->is_accelerated_mode(dcb)) {
979 bios_golden_init(dc);
980 disable_vga(dc->hwseq);
983 for (i = 0; i < dc->link_count; i++) {
984 /* Power up AND update implementation according to the
985 * required signal (which may be different from the
986 * default signal on connector).
988 struct dc_link *link = dc->links[i];
990 if (link->link_enc->connector.id == CONNECTOR_ID_EDP)
991 dc->hwss.edp_power_control(link, true);
993 link->link_enc->funcs->hw_init(link->link_enc);
997 for (i = 0; i < dc->res_pool->pipe_count; i++) {
998 struct timing_generator *tg = dc->res_pool->timing_generators[i];
1000 if (tg->funcs->is_tg_enabled(tg))
1001 tg->funcs->lock(tg);
1004 /* Blank controller using driver code instead of
1007 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1008 struct timing_generator *tg = dc->res_pool->timing_generators[i];
1010 if (tg->funcs->is_tg_enabled(tg)) {
1011 tg->funcs->set_blank(tg, true);
1012 hwss_wait_for_blank_complete(tg);
1016 /* Reset all MPCC muxes */
1017 dc->res_pool->mpc->funcs->mpc_init(dc->res_pool->mpc);
1019 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1020 struct timing_generator *tg = dc->res_pool->timing_generators[i];
1021 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1022 struct hubp *hubp = dc->res_pool->hubps[i];
1023 struct dpp *dpp = dc->res_pool->dpps[i];
1025 pipe_ctx->stream_res.tg = tg;
1026 pipe_ctx->pipe_idx = i;
1028 pipe_ctx->plane_res.hubp = hubp;
1029 pipe_ctx->plane_res.dpp = dpp;
1030 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
1031 hubp->mpcc_id = dpp->inst;
1033 hubp->power_gated = false;
1035 dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
1036 dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
1037 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
1038 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
1040 hwss1_plane_atomic_disconnect(dc, pipe_ctx);
1043 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1044 struct timing_generator *tg = dc->res_pool->timing_generators[i];
1046 if (tg->funcs->is_tg_enabled(tg))
1047 tg->funcs->unlock(tg);
1050 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1051 struct timing_generator *tg = dc->res_pool->timing_generators[i];
1052 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1054 dcn10_disable_plane(dc, pipe_ctx);
1056 pipe_ctx->stream_res.tg = NULL;
1057 pipe_ctx->plane_res.hubp = NULL;
1059 tg->funcs->tg_init(tg);
1062 /* end of FPGA. Below if real ASIC */
1063 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
1066 for (i = 0; i < dc->res_pool->audio_count; i++) {
1067 struct audio *audio = dc->res_pool->audios[i];
1069 audio->funcs->hw_init(audio);
1073 abm->funcs->init_backlight(abm);
1074 abm->funcs->abm_init(abm);
1078 dmcu->funcs->dmcu_init(dmcu);
1080 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
1081 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
1083 if (!dc->debug.disable_clock_gate) {
1084 /* enable all DCN clock gating */
1085 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
1087 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
1089 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
1092 enable_power_gating_plane(dc->hwseq, true);
1094 memset(&dc->res_pool->dccg->clks, 0, sizeof(dc->res_pool->dccg->clks));
1097 static void reset_hw_ctx_wrap(
1099 struct dc_state *context)
1104 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
1105 struct pipe_ctx *pipe_ctx_old =
1106 &dc->current_state->res_ctx.pipe_ctx[i];
1107 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1109 if (!pipe_ctx_old->stream)
1112 if (pipe_ctx_old->top_pipe)
1115 if (!pipe_ctx->stream ||
1116 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
1117 struct clock_source *old_clk = pipe_ctx_old->clock_source;
1119 reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
1121 old_clk->funcs->cs_power_down(old_clk);
1127 static bool patch_address_for_sbs_tb_stereo(
1128 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
1130 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1131 bool sec_split = pipe_ctx->top_pipe &&
1132 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
1133 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
1134 (pipe_ctx->stream->timing.timing_3d_format ==
1135 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
1136 pipe_ctx->stream->timing.timing_3d_format ==
1137 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
1138 *addr = plane_state->address.grph_stereo.left_addr;
1139 plane_state->address.grph_stereo.left_addr =
1140 plane_state->address.grph_stereo.right_addr;
1143 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
1144 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
1145 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
1146 plane_state->address.grph_stereo.right_addr =
1147 plane_state->address.grph_stereo.left_addr;
1155 static void dcn10_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
1157 bool addr_patched = false;
1158 PHYSICAL_ADDRESS_LOC addr;
1159 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1161 if (plane_state == NULL)
1164 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
1166 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
1167 pipe_ctx->plane_res.hubp,
1168 &plane_state->address,
1169 plane_state->flip_immediate);
1171 plane_state->status.requested_address = plane_state->address;
1173 if (plane_state->flip_immediate)
1174 plane_state->status.current_address = plane_state->address;
1177 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
1180 static bool dcn10_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
1181 const struct dc_plane_state *plane_state)
1183 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1184 const struct dc_transfer_func *tf = NULL;
1187 if (dpp_base == NULL)
1190 if (plane_state->in_transfer_func)
1191 tf = plane_state->in_transfer_func;
1193 if (plane_state->gamma_correction &&
1194 !dpp_base->ctx->dc->debug.always_use_regamma
1195 && !plane_state->gamma_correction->is_identity
1196 && dce_use_lut(plane_state->format))
1197 dpp_base->funcs->dpp_program_input_lut(dpp_base, plane_state->gamma_correction);
1200 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
1201 else if (tf->type == TF_TYPE_PREDEFINED) {
1203 case TRANSFER_FUNCTION_SRGB:
1204 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_sRGB);
1206 case TRANSFER_FUNCTION_BT709:
1207 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_xvYCC);
1209 case TRANSFER_FUNCTION_LINEAR:
1210 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
1212 case TRANSFER_FUNCTION_PQ:
1217 } else if (tf->type == TF_TYPE_BYPASS) {
1218 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
1220 cm_helper_translate_curve_to_degamma_hw_format(tf,
1221 &dpp_base->degamma_params);
1222 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base,
1223 &dpp_base->degamma_params);
1235 dcn10_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
1236 const struct dc_stream_state *stream)
1238 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1243 dpp->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
1245 if (stream->out_transfer_func &&
1246 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
1247 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB)
1248 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_SRGB);
1250 /* dcn10_translate_regamma_to_hw_format takes 750us, only do it when full
1253 else if (cm_helper_translate_curve_to_hw_format(
1254 stream->out_transfer_func,
1255 &dpp->regamma_params, false)) {
1256 dpp->funcs->dpp_program_regamma_pwl(
1258 &dpp->regamma_params, OPP_REGAMMA_USER);
1260 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_BYPASS);
1265 static void dcn10_pipe_control_lock(
1267 struct pipe_ctx *pipe,
1270 /* use TG master update lock to lock everything on the TG
1271 * therefore only top pipe need to lock
1276 if (dc->debug.sanity_checks)
1277 dcn10_verify_allow_pstate_change_high(dc);
1280 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1282 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1284 if (dc->debug.sanity_checks)
1285 dcn10_verify_allow_pstate_change_high(dc);
1288 static bool wait_for_reset_trigger_to_occur(
1289 struct dc_context *dc_ctx,
1290 struct timing_generator *tg)
1294 /* To avoid endless loop we wait at most
1295 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
1296 const uint32_t frames_to_wait_on_triggered_reset = 10;
1299 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
1301 if (!tg->funcs->is_counter_moving(tg)) {
1302 DC_ERROR("TG counter is not moving!\n");
1306 if (tg->funcs->did_triggered_reset_occur(tg)) {
1308 /* usually occurs at i=1 */
1309 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
1314 /* Wait for one frame. */
1315 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
1316 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
1320 DC_ERROR("GSL: Timeout on reset trigger!\n");
1325 static void dcn10_enable_timing_synchronization(
1329 struct pipe_ctx *grouped_pipes[])
1331 struct dc_context *dc_ctx = dc->ctx;
1334 DC_SYNC_INFO("Setting up OTG reset trigger\n");
1336 for (i = 1; i < group_size; i++)
1337 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
1338 grouped_pipes[i]->stream_res.tg,
1339 grouped_pipes[0]->stream_res.tg->inst);
1341 DC_SYNC_INFO("Waiting for trigger\n");
1343 /* Need to get only check 1 pipe for having reset as all the others are
1344 * synchronized. Look at last pipe programmed to reset.
1347 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[1]->stream_res.tg);
1348 for (i = 1; i < group_size; i++)
1349 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
1350 grouped_pipes[i]->stream_res.tg);
1352 DC_SYNC_INFO("Sync complete\n");
1355 static void dcn10_enable_per_frame_crtc_position_reset(
1358 struct pipe_ctx *grouped_pipes[])
1360 struct dc_context *dc_ctx = dc->ctx;
1363 DC_SYNC_INFO("Setting up\n");
1364 for (i = 0; i < group_size; i++)
1365 if (grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset)
1366 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
1367 grouped_pipes[i]->stream_res.tg,
1368 grouped_pipes[i]->stream->triggered_crtc_reset.event_source->status.primary_otg_inst,
1369 &grouped_pipes[i]->stream->triggered_crtc_reset);
1371 DC_SYNC_INFO("Waiting for trigger\n");
1373 for (i = 0; i < group_size; i++)
1374 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
1376 DC_SYNC_INFO("Multi-display sync is complete\n");
1379 /*static void print_rq_dlg_ttu(
1381 struct pipe_ctx *pipe_ctx)
1383 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1384 "\n============== DML TTU Output parameters [%d] ==============\n"
1385 "qos_level_low_wm: %d, \n"
1386 "qos_level_high_wm: %d, \n"
1387 "min_ttu_vblank: %d, \n"
1388 "qos_level_flip: %d, \n"
1389 "refcyc_per_req_delivery_l: %d, \n"
1390 "qos_level_fixed_l: %d, \n"
1391 "qos_ramp_disable_l: %d, \n"
1392 "refcyc_per_req_delivery_pre_l: %d, \n"
1393 "refcyc_per_req_delivery_c: %d, \n"
1394 "qos_level_fixed_c: %d, \n"
1395 "qos_ramp_disable_c: %d, \n"
1396 "refcyc_per_req_delivery_pre_c: %d\n"
1397 "=============================================================\n",
1399 pipe_ctx->ttu_regs.qos_level_low_wm,
1400 pipe_ctx->ttu_regs.qos_level_high_wm,
1401 pipe_ctx->ttu_regs.min_ttu_vblank,
1402 pipe_ctx->ttu_regs.qos_level_flip,
1403 pipe_ctx->ttu_regs.refcyc_per_req_delivery_l,
1404 pipe_ctx->ttu_regs.qos_level_fixed_l,
1405 pipe_ctx->ttu_regs.qos_ramp_disable_l,
1406 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_l,
1407 pipe_ctx->ttu_regs.refcyc_per_req_delivery_c,
1408 pipe_ctx->ttu_regs.qos_level_fixed_c,
1409 pipe_ctx->ttu_regs.qos_ramp_disable_c,
1410 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_c
1413 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1414 "\n============== DML DLG Output parameters [%d] ==============\n"
1415 "refcyc_h_blank_end: %d, \n"
1416 "dlg_vblank_end: %d, \n"
1417 "min_dst_y_next_start: %d, \n"
1418 "refcyc_per_htotal: %d, \n"
1419 "refcyc_x_after_scaler: %d, \n"
1420 "dst_y_after_scaler: %d, \n"
1421 "dst_y_prefetch: %d, \n"
1422 "dst_y_per_vm_vblank: %d, \n"
1423 "dst_y_per_row_vblank: %d, \n"
1424 "ref_freq_to_pix_freq: %d, \n"
1425 "vratio_prefetch: %d, \n"
1426 "refcyc_per_pte_group_vblank_l: %d, \n"
1427 "refcyc_per_meta_chunk_vblank_l: %d, \n"
1428 "dst_y_per_pte_row_nom_l: %d, \n"
1429 "refcyc_per_pte_group_nom_l: %d, \n",
1431 pipe_ctx->dlg_regs.refcyc_h_blank_end,
1432 pipe_ctx->dlg_regs.dlg_vblank_end,
1433 pipe_ctx->dlg_regs.min_dst_y_next_start,
1434 pipe_ctx->dlg_regs.refcyc_per_htotal,
1435 pipe_ctx->dlg_regs.refcyc_x_after_scaler,
1436 pipe_ctx->dlg_regs.dst_y_after_scaler,
1437 pipe_ctx->dlg_regs.dst_y_prefetch,
1438 pipe_ctx->dlg_regs.dst_y_per_vm_vblank,
1439 pipe_ctx->dlg_regs.dst_y_per_row_vblank,
1440 pipe_ctx->dlg_regs.ref_freq_to_pix_freq,
1441 pipe_ctx->dlg_regs.vratio_prefetch,
1442 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_l,
1443 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_l,
1444 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_l,
1445 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_l
1448 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1449 "\ndst_y_per_meta_row_nom_l: %d, \n"
1450 "refcyc_per_meta_chunk_nom_l: %d, \n"
1451 "refcyc_per_line_delivery_pre_l: %d, \n"
1452 "refcyc_per_line_delivery_l: %d, \n"
1453 "vratio_prefetch_c: %d, \n"
1454 "refcyc_per_pte_group_vblank_c: %d, \n"
1455 "refcyc_per_meta_chunk_vblank_c: %d, \n"
1456 "dst_y_per_pte_row_nom_c: %d, \n"
1457 "refcyc_per_pte_group_nom_c: %d, \n"
1458 "dst_y_per_meta_row_nom_c: %d, \n"
1459 "refcyc_per_meta_chunk_nom_c: %d, \n"
1460 "refcyc_per_line_delivery_pre_c: %d, \n"
1461 "refcyc_per_line_delivery_c: %d \n"
1462 "========================================================\n",
1463 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_l,
1464 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_l,
1465 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_l,
1466 pipe_ctx->dlg_regs.refcyc_per_line_delivery_l,
1467 pipe_ctx->dlg_regs.vratio_prefetch_c,
1468 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_c,
1469 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_c,
1470 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_c,
1471 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_c,
1472 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_c,
1473 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_c,
1474 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_c,
1475 pipe_ctx->dlg_regs.refcyc_per_line_delivery_c
1478 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1479 "\n============== DML RQ Output parameters [%d] ==============\n"
1481 "min_chunk_size: %d \n"
1482 "meta_chunk_size: %d \n"
1483 "min_meta_chunk_size: %d \n"
1484 "dpte_group_size: %d \n"
1485 "mpte_group_size: %d \n"
1486 "swath_height: %d \n"
1487 "pte_row_height_linear: %d \n"
1488 "========================================================\n",
1490 pipe_ctx->rq_regs.rq_regs_l.chunk_size,
1491 pipe_ctx->rq_regs.rq_regs_l.min_chunk_size,
1492 pipe_ctx->rq_regs.rq_regs_l.meta_chunk_size,
1493 pipe_ctx->rq_regs.rq_regs_l.min_meta_chunk_size,
1494 pipe_ctx->rq_regs.rq_regs_l.dpte_group_size,
1495 pipe_ctx->rq_regs.rq_regs_l.mpte_group_size,
1496 pipe_ctx->rq_regs.rq_regs_l.swath_height,
1497 pipe_ctx->rq_regs.rq_regs_l.pte_row_height_linear
1502 static void mmhub_read_vm_system_aperture_settings(struct dcn10_hubp *hubp1,
1503 struct vm_system_aperture_param *apt,
1504 struct dce_hwseq *hws)
1506 PHYSICAL_ADDRESS_LOC physical_page_number;
1507 uint32_t logical_addr_low;
1508 uint32_t logical_addr_high;
1510 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
1511 PHYSICAL_PAGE_NUMBER_MSB, &physical_page_number.high_part);
1512 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
1513 PHYSICAL_PAGE_NUMBER_LSB, &physical_page_number.low_part);
1515 REG_GET(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1516 LOGICAL_ADDR, &logical_addr_low);
1518 REG_GET(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1519 LOGICAL_ADDR, &logical_addr_high);
1521 apt->sys_default.quad_part = physical_page_number.quad_part << 12;
1522 apt->sys_low.quad_part = (int64_t)logical_addr_low << 18;
1523 apt->sys_high.quad_part = (int64_t)logical_addr_high << 18;
1526 /* Temporary read settings, future will get values from kmd directly */
1527 static void mmhub_read_vm_context0_settings(struct dcn10_hubp *hubp1,
1528 struct vm_context0_param *vm0,
1529 struct dce_hwseq *hws)
1531 PHYSICAL_ADDRESS_LOC fb_base;
1532 PHYSICAL_ADDRESS_LOC fb_offset;
1533 uint32_t fb_base_value;
1534 uint32_t fb_offset_value;
1536 REG_GET(DCHUBBUB_SDPIF_FB_BASE, SDPIF_FB_BASE, &fb_base_value);
1537 REG_GET(DCHUBBUB_SDPIF_FB_OFFSET, SDPIF_FB_OFFSET, &fb_offset_value);
1539 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
1540 PAGE_DIRECTORY_ENTRY_HI32, &vm0->pte_base.high_part);
1541 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
1542 PAGE_DIRECTORY_ENTRY_LO32, &vm0->pte_base.low_part);
1544 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
1545 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_start.high_part);
1546 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
1547 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_start.low_part);
1549 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
1550 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_end.high_part);
1551 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
1552 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_end.low_part);
1554 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
1555 PHYSICAL_PAGE_ADDR_HI4, &vm0->fault_default.high_part);
1556 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
1557 PHYSICAL_PAGE_ADDR_LO32, &vm0->fault_default.low_part);
1560 * The values in VM_CONTEXT0_PAGE_TABLE_BASE_ADDR is in UMA space.
1561 * Therefore we need to do
1562 * DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
1563 * - DCHUBBUB_SDPIF_FB_OFFSET + DCHUBBUB_SDPIF_FB_BASE
1565 fb_base.quad_part = (uint64_t)fb_base_value << 24;
1566 fb_offset.quad_part = (uint64_t)fb_offset_value << 24;
1567 vm0->pte_base.quad_part += fb_base.quad_part;
1568 vm0->pte_base.quad_part -= fb_offset.quad_part;
1572 static void dcn10_program_pte_vm(struct dce_hwseq *hws, struct hubp *hubp)
1574 struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
1575 struct vm_system_aperture_param apt = { {{ 0 } } };
1576 struct vm_context0_param vm0 = { { { 0 } } };
1578 mmhub_read_vm_system_aperture_settings(hubp1, &apt, hws);
1579 mmhub_read_vm_context0_settings(hubp1, &vm0, hws);
1581 hubp->funcs->hubp_set_vm_system_aperture_settings(hubp, &apt);
1582 hubp->funcs->hubp_set_vm_context0_settings(hubp, &vm0);
1585 static void dcn10_enable_plane(
1587 struct pipe_ctx *pipe_ctx,
1588 struct dc_state *context)
1590 struct dce_hwseq *hws = dc->hwseq;
1592 if (dc->debug.sanity_checks) {
1593 dcn10_verify_allow_pstate_change_high(dc);
1596 undo_DEGVIDCN10_253_wa(dc);
1598 power_on_plane(dc->hwseq,
1599 pipe_ctx->plane_res.hubp->inst);
1601 /* enable DCFCLK current DCHUB */
1602 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true);
1604 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1605 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
1606 pipe_ctx->stream_res.opp,
1609 /* TODO: enable/disable in dm as per update type.
1611 DC_LOG_DC(dc->ctx->logger,
1612 "Pipe:%d 0x%x: addr hi:0x%x, "
1615 " %d; dst: %d, %d, %d, %d;\n",
1618 plane_state->address.grph.addr.high_part,
1619 plane_state->address.grph.addr.low_part,
1620 plane_state->src_rect.x,
1621 plane_state->src_rect.y,
1622 plane_state->src_rect.width,
1623 plane_state->src_rect.height,
1624 plane_state->dst_rect.x,
1625 plane_state->dst_rect.y,
1626 plane_state->dst_rect.width,
1627 plane_state->dst_rect.height);
1629 DC_LOG_DC(dc->ctx->logger,
1630 "Pipe %d: width, height, x, y format:%d\n"
1631 "viewport:%d, %d, %d, %d\n"
1632 "recout: %d, %d, %d, %d\n",
1634 plane_state->format,
1635 pipe_ctx->plane_res.scl_data.viewport.width,
1636 pipe_ctx->plane_res.scl_data.viewport.height,
1637 pipe_ctx->plane_res.scl_data.viewport.x,
1638 pipe_ctx->plane_res.scl_data.viewport.y,
1639 pipe_ctx->plane_res.scl_data.recout.width,
1640 pipe_ctx->plane_res.scl_data.recout.height,
1641 pipe_ctx->plane_res.scl_data.recout.x,
1642 pipe_ctx->plane_res.scl_data.recout.y);
1643 print_rq_dlg_ttu(dc, pipe_ctx);
1646 if (dc->config.gpu_vm_support)
1647 dcn10_program_pte_vm(hws, pipe_ctx->plane_res.hubp);
1649 if (dc->debug.sanity_checks) {
1650 dcn10_verify_allow_pstate_change_high(dc);
1654 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
1657 struct dpp_grph_csc_adjustment adjust;
1658 memset(&adjust, 0, sizeof(adjust));
1659 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
1662 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
1663 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
1664 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
1665 adjust.temperature_matrix[i] =
1666 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
1669 pipe_ctx->plane_res.dpp->funcs->dpp_set_gamut_remap(pipe_ctx->plane_res.dpp, &adjust);
1673 static void program_csc_matrix(struct pipe_ctx *pipe_ctx,
1674 enum dc_color_space colorspace,
1677 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1678 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1679 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment(pipe_ctx->plane_res.dpp, matrix);
1681 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default != NULL)
1682 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default(pipe_ctx->plane_res.dpp, colorspace);
1686 static void dcn10_program_output_csc(struct dc *dc,
1687 struct pipe_ctx *pipe_ctx,
1688 enum dc_color_space colorspace,
1692 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1693 program_csc_matrix(pipe_ctx,
1698 static bool is_lower_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1700 if (pipe_ctx->plane_state->visible)
1702 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1707 static bool is_upper_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1709 if (pipe_ctx->plane_state->visible)
1711 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1716 static bool is_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1718 if (pipe_ctx->plane_state->visible)
1720 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1722 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1727 bool is_rgb_cspace(enum dc_color_space output_color_space)
1729 switch (output_color_space) {
1730 case COLOR_SPACE_SRGB:
1731 case COLOR_SPACE_SRGB_LIMITED:
1732 case COLOR_SPACE_2020_RGB_FULLRANGE:
1733 case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
1734 case COLOR_SPACE_ADOBERGB:
1736 case COLOR_SPACE_YCBCR601:
1737 case COLOR_SPACE_YCBCR709:
1738 case COLOR_SPACE_YCBCR601_LIMITED:
1739 case COLOR_SPACE_YCBCR709_LIMITED:
1740 case COLOR_SPACE_2020_YCBCR:
1743 /* Add a case to switch */
1744 BREAK_TO_DEBUGGER();
1749 static void dcn10_get_surface_visual_confirm_color(
1750 const struct pipe_ctx *pipe_ctx,
1751 struct tg_color *color)
1753 uint32_t color_value = MAX_TG_COLOR_VALUE;
1755 switch (pipe_ctx->plane_res.scl_data.format) {
1756 case PIXEL_FORMAT_ARGB8888:
1757 /* set boarder color to red */
1758 color->color_r_cr = color_value;
1761 case PIXEL_FORMAT_ARGB2101010:
1762 /* set boarder color to blue */
1763 color->color_b_cb = color_value;
1765 case PIXEL_FORMAT_420BPP8:
1766 /* set boarder color to green */
1767 color->color_g_y = color_value;
1769 case PIXEL_FORMAT_420BPP10:
1770 /* set boarder color to yellow */
1771 color->color_g_y = color_value;
1772 color->color_r_cr = color_value;
1774 case PIXEL_FORMAT_FP16:
1775 /* set boarder color to white */
1776 color->color_r_cr = color_value;
1777 color->color_b_cb = color_value;
1778 color->color_g_y = color_value;
1785 static void dcn10_get_hdr_visual_confirm_color(
1786 struct pipe_ctx *pipe_ctx,
1787 struct tg_color *color)
1789 uint32_t color_value = MAX_TG_COLOR_VALUE;
1791 // Determine the overscan color based on the top-most (desktop) plane's context
1792 struct pipe_ctx *top_pipe_ctx = pipe_ctx;
1794 while (top_pipe_ctx->top_pipe != NULL)
1795 top_pipe_ctx = top_pipe_ctx->top_pipe;
1797 switch (top_pipe_ctx->plane_res.scl_data.format) {
1798 case PIXEL_FORMAT_ARGB2101010:
1799 if (top_pipe_ctx->stream->out_transfer_func->tf == TRANSFER_FUNCTION_UNITY) {
1800 /* HDR10, ARGB2101010 - set boarder color to red */
1801 color->color_r_cr = color_value;
1804 case PIXEL_FORMAT_FP16:
1805 if (top_pipe_ctx->stream->out_transfer_func->tf == TRANSFER_FUNCTION_PQ) {
1806 /* HDR10, FP16 - set boarder color to blue */
1807 color->color_b_cb = color_value;
1808 } else if (top_pipe_ctx->stream->out_transfer_func->tf == TRANSFER_FUNCTION_GAMMA22) {
1809 /* FreeSync 2 HDR - set boarder color to green */
1810 color->color_g_y = color_value;
1814 /* SDR - set boarder color to Gray */
1815 color->color_r_cr = color_value/2;
1816 color->color_b_cb = color_value/2;
1817 color->color_g_y = color_value/2;
1822 static uint16_t fixed_point_to_int_frac(
1823 struct fixed31_32 arg,
1824 uint8_t integer_bits,
1825 uint8_t fractional_bits)
1828 int32_t divisor = 1 << fractional_bits;
1832 uint16_t d = (uint16_t)dc_fixpt_floor(
1836 if (d <= (uint16_t)(1 << integer_bits) - (1 / (uint16_t)divisor))
1837 numerator = (uint16_t)dc_fixpt_floor(
1842 numerator = dc_fixpt_floor(
1845 1LL << integer_bits),
1852 result = (uint16_t)numerator;
1854 result = (uint16_t)(
1855 (1 << (integer_bits + fractional_bits + 1)) + numerator);
1857 if ((result != 0) && dc_fixpt_lt(
1858 arg, dc_fixpt_zero))
1859 result |= 1 << (integer_bits + fractional_bits);
1864 void build_prescale_params(struct dc_bias_and_scale *bias_and_scale,
1865 const struct dc_plane_state *plane_state)
1867 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1868 && plane_state->format != SURFACE_PIXEL_FORMAT_INVALID
1869 && plane_state->input_csc_color_matrix.enable_adjustment
1870 && plane_state->coeff_reduction_factor.value != 0) {
1871 bias_and_scale->scale_blue = fixed_point_to_int_frac(
1872 dc_fixpt_mul(plane_state->coeff_reduction_factor,
1873 dc_fixpt_from_fraction(256, 255)),
1876 bias_and_scale->scale_red = bias_and_scale->scale_blue;
1877 bias_and_scale->scale_green = bias_and_scale->scale_blue;
1879 bias_and_scale->scale_blue = 0x2000;
1880 bias_and_scale->scale_red = 0x2000;
1881 bias_and_scale->scale_green = 0x2000;
1885 static void update_dpp(struct dpp *dpp, struct dc_plane_state *plane_state)
1887 struct dc_bias_and_scale bns_params = {0};
1889 // program the input csc
1890 dpp->funcs->dpp_setup(dpp,
1891 plane_state->format,
1892 EXPANSION_MODE_ZERO,
1893 plane_state->input_csc_color_matrix,
1894 plane_state->color_space);
1896 //set scale and bias registers
1897 build_prescale_params(&bns_params, plane_state);
1898 if (dpp->funcs->dpp_program_bias_and_scale)
1899 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1902 static void dcn10_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
1904 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1905 struct mpcc_blnd_cfg blnd_cfg = {0};
1906 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1908 struct mpcc *new_mpcc;
1909 struct mpc *mpc = dc->res_pool->mpc;
1910 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
1914 /* TODO: proper fix once fpga works */
1916 if (dc->debug.visual_confirm == VISUAL_CONFIRM_HDR) {
1917 dcn10_get_hdr_visual_confirm_color(
1918 pipe_ctx, &blnd_cfg.black_color);
1919 } else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE) {
1920 dcn10_get_surface_visual_confirm_color(
1921 pipe_ctx, &blnd_cfg.black_color);
1923 color_space_to_black_color(
1924 dc, pipe_ctx->stream->output_color_space,
1925 &blnd_cfg.black_color);
1928 if (per_pixel_alpha)
1929 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
1931 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
1933 blnd_cfg.overlap_only = false;
1934 blnd_cfg.global_alpha = 0xff;
1935 blnd_cfg.global_gain = 0xff;
1937 /* DCN1.0 has output CM before MPC which seems to screw with
1938 * pre-multiplied alpha.
1940 blnd_cfg.pre_multiplied_alpha = is_rgb_cspace(
1941 pipe_ctx->stream->output_color_space)
1947 * Note: currently there is a bug in init_hw such that
1948 * on resume from hibernate, BIOS sets up MPCC0, and
1949 * we do mpcc_remove but the mpcc cannot go to idle
1950 * after remove. This cause us to pick mpcc1 here,
1951 * which causes a pstate hang for yet unknown reason.
1953 mpcc_id = hubp->inst;
1955 /* If there is no full update, don't need to touch MPC tree*/
1956 if (!pipe_ctx->plane_state->update_flags.bits.full_update) {
1957 mpc->funcs->update_blending(mpc, &blnd_cfg, mpcc_id);
1961 /* check if this MPCC is already being used */
1962 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
1963 /* remove MPCC if being used */
1964 if (new_mpcc != NULL)
1965 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
1967 if (dc->debug.sanity_checks)
1968 mpc->funcs->assert_mpcc_idle_before_connect(
1969 dc->res_pool->mpc, mpcc_id);
1971 /* Call MPC to insert new plane */
1972 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
1980 ASSERT(new_mpcc != NULL);
1982 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
1983 hubp->mpcc_id = mpcc_id;
1986 static void update_scaler(struct pipe_ctx *pipe_ctx)
1988 bool per_pixel_alpha =
1989 pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1991 /* TODO: proper fix once fpga works */
1993 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = per_pixel_alpha;
1994 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1995 /* scaler configuration */
1996 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1997 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
2000 static void update_dchubp_dpp(
2002 struct pipe_ctx *pipe_ctx,
2003 struct dc_state *context)
2005 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2006 struct dpp *dpp = pipe_ctx->plane_res.dpp;
2007 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2008 union plane_size size = plane_state->plane_size;
2010 /* depends on DML calculation, DPP clock value may change dynamically */
2011 /* If request max dpp clk is lower than current dispclk, no need to
2014 if (plane_state->update_flags.bits.full_update) {
2015 bool should_divided_by_2 = context->bw.dcn.clk.dppclk_khz <=
2016 dc->res_pool->dccg->clks.dispclk_khz / 2;
2018 dpp->funcs->dpp_dppclk_control(
2020 should_divided_by_2,
2023 dc->res_pool->dccg->clks.dppclk_khz = should_divided_by_2 ?
2024 dc->res_pool->dccg->clks.dispclk_khz / 2 :
2025 dc->res_pool->dccg->clks.dispclk_khz;
2028 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
2029 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
2030 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
2032 if (plane_state->update_flags.bits.full_update) {
2033 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst);
2035 hubp->funcs->hubp_setup(
2037 &pipe_ctx->dlg_regs,
2038 &pipe_ctx->ttu_regs,
2040 &pipe_ctx->pipe_dlg_param);
2043 size.grph.surface_size = pipe_ctx->plane_res.scl_data.viewport;
2045 if (plane_state->update_flags.bits.full_update ||
2046 plane_state->update_flags.bits.bpp_change)
2047 update_dpp(dpp, plane_state);
2049 if (plane_state->update_flags.bits.full_update ||
2050 plane_state->update_flags.bits.per_pixel_alpha_change)
2051 dc->hwss.update_mpcc(dc, pipe_ctx);
2053 if (plane_state->update_flags.bits.full_update ||
2054 plane_state->update_flags.bits.per_pixel_alpha_change ||
2055 plane_state->update_flags.bits.scaling_change ||
2056 plane_state->update_flags.bits.position_change) {
2057 update_scaler(pipe_ctx);
2060 if (plane_state->update_flags.bits.full_update ||
2061 plane_state->update_flags.bits.scaling_change ||
2062 plane_state->update_flags.bits.position_change) {
2063 hubp->funcs->mem_program_viewport(
2065 &pipe_ctx->plane_res.scl_data.viewport,
2066 &pipe_ctx->plane_res.scl_data.viewport_c);
2069 if (pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
2070 dc->hwss.set_cursor_position(pipe_ctx);
2071 dc->hwss.set_cursor_attribute(pipe_ctx);
2074 if (plane_state->update_flags.bits.full_update) {
2076 program_gamut_remap(pipe_ctx);
2078 dc->hwss.program_output_csc(dc,
2080 pipe_ctx->stream->output_color_space,
2081 pipe_ctx->stream->csc_color_matrix.matrix,
2085 if (plane_state->update_flags.bits.full_update ||
2086 plane_state->update_flags.bits.pixel_format_change ||
2087 plane_state->update_flags.bits.horizontal_mirror_change ||
2088 plane_state->update_flags.bits.rotation_change ||
2089 plane_state->update_flags.bits.swizzle_change ||
2090 plane_state->update_flags.bits.dcc_change ||
2091 plane_state->update_flags.bits.bpp_change ||
2092 plane_state->update_flags.bits.scaling_change) {
2093 hubp->funcs->hubp_program_surface_config(
2095 plane_state->format,
2096 &plane_state->tiling_info,
2098 plane_state->rotation,
2100 plane_state->horizontal_mirror);
2103 hubp->power_gated = false;
2105 dc->hwss.update_plane_addr(dc, pipe_ctx);
2107 if (is_pipe_tree_visible(pipe_ctx))
2108 hubp->funcs->set_blank(hubp, false);
2111 static void dcn10_blank_pixel_data(
2113 struct pipe_ctx *pipe_ctx,
2116 enum dc_color_space color_space;
2117 struct tg_color black_color = {0};
2118 struct stream_resource *stream_res = &pipe_ctx->stream_res;
2119 struct dc_stream_state *stream = pipe_ctx->stream;
2121 /* program otg blank color */
2122 color_space = stream->output_color_space;
2123 color_space_to_black_color(dc, color_space, &black_color);
2126 * The way 420 is packed, 2 channels carry Y component, 1 channel
2127 * alternate between Cb and Cr, so both channels need the pixel
2130 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
2131 black_color.color_r_cr = black_color.color_g_y;
2134 if (stream_res->tg->funcs->set_blank_color)
2135 stream_res->tg->funcs->set_blank_color(
2140 if (stream_res->tg->funcs->set_blank)
2141 stream_res->tg->funcs->set_blank(stream_res->tg, blank);
2142 if (stream_res->abm)
2143 stream_res->abm->funcs->set_abm_level(stream_res->abm, stream->abm_level);
2145 if (stream_res->abm)
2146 stream_res->abm->funcs->set_abm_immediate_disable(stream_res->abm);
2147 if (stream_res->tg->funcs->set_blank)
2148 stream_res->tg->funcs->set_blank(stream_res->tg, blank);
2152 static void set_hdr_multiplier(struct pipe_ctx *pipe_ctx)
2154 struct fixed31_32 multiplier = dc_fixpt_from_fraction(
2155 pipe_ctx->plane_state->sdr_white_level, 80);
2156 uint32_t hw_mult = 0x1f000; // 1.0 default multiplier
2157 struct custom_float_format fmt;
2159 fmt.exponenta_bits = 6;
2160 fmt.mantissa_bits = 12;
2163 if (pipe_ctx->plane_state->sdr_white_level > 80)
2164 convert_to_custom_float_format(multiplier, &fmt, &hw_mult);
2166 pipe_ctx->plane_res.dpp->funcs->dpp_set_hdr_multiplier(
2167 pipe_ctx->plane_res.dpp, hw_mult);
2170 void dcn10_program_pipe(
2172 struct pipe_ctx *pipe_ctx,
2173 struct dc_state *context)
2175 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2176 dcn10_enable_plane(dc, pipe_ctx, context);
2178 update_dchubp_dpp(dc, pipe_ctx, context);
2180 set_hdr_multiplier(pipe_ctx);
2182 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2183 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2184 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2185 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
2187 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
2188 * only do gamma programming for full update.
2189 * TODO: This can be further optimized/cleaned up
2190 * Always call this for now since it does memcmp inside before
2191 * doing heavy calculation and programming
2193 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2194 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
2197 static void program_all_pipe_in_tree(
2199 struct pipe_ctx *pipe_ctx,
2200 struct dc_state *context)
2202 if (pipe_ctx->top_pipe == NULL) {
2203 bool blank = !is_pipe_tree_visible(pipe_ctx);
2205 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
2206 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
2207 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
2208 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
2209 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
2211 pipe_ctx->stream_res.tg->funcs->program_global_sync(
2212 pipe_ctx->stream_res.tg);
2214 dc->hwss.blank_pixel_data(dc, pipe_ctx, blank);
2218 if (pipe_ctx->plane_state != NULL) {
2219 dcn10_program_pipe(dc, pipe_ctx, context);
2222 if (pipe_ctx->bottom_pipe != NULL && pipe_ctx->bottom_pipe != pipe_ctx) {
2223 program_all_pipe_in_tree(dc, pipe_ctx->bottom_pipe, context);
2227 static void dcn10_pplib_apply_display_requirements(
2229 struct dc_state *context)
2231 struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
2233 pp_display_cfg->min_engine_clock_khz = dc->res_pool->dccg->clks.dcfclk_khz;
2234 pp_display_cfg->min_memory_clock_khz = dc->res_pool->dccg->clks.fclk_khz;
2235 pp_display_cfg->min_engine_clock_deep_sleep_khz = dc->res_pool->dccg->clks.dcfclk_deep_sleep_khz;
2236 pp_display_cfg->min_dcfc_deep_sleep_clock_khz = dc->res_pool->dccg->clks.dcfclk_deep_sleep_khz;
2237 pp_display_cfg->min_dcfclock_khz = dc->res_pool->dccg->clks.dcfclk_khz;
2238 pp_display_cfg->disp_clk_khz = dc->res_pool->dccg->clks.dispclk_khz;
2239 dce110_fill_display_configs(context, pp_display_cfg);
2241 if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof(
2242 struct dm_pp_display_configuration)) != 0)
2243 dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
2245 dc->prev_display_config = *pp_display_cfg;
2248 static void optimize_shared_resources(struct dc *dc)
2250 if (dc->current_state->stream_count == 0) {
2252 dcn10_pplib_apply_display_requirements(dc, dc->current_state);
2255 if (dc->debug.pplib_wm_report_mode == WM_REPORT_OVERRIDE)
2256 dcn_bw_notify_pplib_of_wm_ranges(dc);
2259 static void ready_shared_resources(struct dc *dc, struct dc_state *context)
2262 if (dc->current_state->stream_count == 0 &&
2263 context->stream_count != 0)
2264 dcn10_pplib_apply_display_requirements(dc, context);
2267 static struct pipe_ctx *find_top_pipe_for_stream(
2269 struct dc_state *context,
2270 const struct dc_stream_state *stream)
2274 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2275 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2276 struct pipe_ctx *old_pipe_ctx =
2277 &dc->current_state->res_ctx.pipe_ctx[i];
2279 if (!pipe_ctx->plane_state && !old_pipe_ctx->plane_state)
2282 if (pipe_ctx->stream != stream)
2285 if (!pipe_ctx->top_pipe)
2291 static void dcn10_apply_ctx_for_surface(
2293 const struct dc_stream_state *stream,
2295 struct dc_state *context)
2298 struct timing_generator *tg;
2299 bool removed_pipe[4] = { false };
2300 struct pipe_ctx *top_pipe_to_program =
2301 find_top_pipe_for_stream(dc, context, stream);
2302 DC_LOGGER_INIT(dc->ctx->logger);
2304 if (!top_pipe_to_program)
2307 tg = top_pipe_to_program->stream_res.tg;
2309 dcn10_pipe_control_lock(dc, top_pipe_to_program, true);
2311 if (num_planes == 0) {
2312 /* OTG blank before remove all front end */
2313 dc->hwss.blank_pixel_data(dc, top_pipe_to_program, true);
2316 /* Disconnect unused mpcc */
2317 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2318 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2319 struct pipe_ctx *old_pipe_ctx =
2320 &dc->current_state->res_ctx.pipe_ctx[i];
2322 * Powergate reused pipes that are not powergated
2323 * fairly hacky right now, using opp_id as indicator
2324 * TODO: After move dc_post to dc_update, this will
2327 if (pipe_ctx->plane_state && !old_pipe_ctx->plane_state) {
2328 if (old_pipe_ctx->stream_res.tg == tg &&
2329 old_pipe_ctx->plane_res.hubp &&
2330 old_pipe_ctx->plane_res.hubp->opp_id != 0xf) {
2331 dcn10_disable_plane(dc, old_pipe_ctx);
2333 * power down fe will unlock when calling reset, need
2334 * to lock it back here. Messy, need rework.
2336 pipe_ctx->stream_res.tg->funcs->lock(pipe_ctx->stream_res.tg);
2340 if ((!pipe_ctx->plane_state ||
2341 pipe_ctx->stream_res.tg != old_pipe_ctx->stream_res.tg) &&
2342 old_pipe_ctx->plane_state &&
2343 old_pipe_ctx->stream_res.tg == tg) {
2345 dc->hwss.plane_atomic_disconnect(dc, old_pipe_ctx);
2346 removed_pipe[i] = true;
2348 DC_LOG_DC("Reset mpcc for pipe %d\n",
2349 old_pipe_ctx->pipe_idx);
2354 program_all_pipe_in_tree(dc, top_pipe_to_program, context);
2356 dcn10_pipe_control_lock(dc, top_pipe_to_program, false);
2358 if (num_planes == 0)
2359 false_optc_underflow_wa(dc, stream, tg);
2361 for (i = 0; i < dc->res_pool->pipe_count; i++)
2362 if (removed_pipe[i])
2363 dcn10_disable_plane(dc, &dc->current_state->res_ctx.pipe_ctx[i]);
2365 if (dc->hwseq->wa.DEGVIDCN10_254)
2366 hubbub1_wm_change_req_wa(dc->res_pool->hubbub);
2369 static void dcn10_set_bandwidth(
2371 struct dc_state *context,
2374 if (dc->debug.sanity_checks)
2375 dcn10_verify_allow_pstate_change_high(dc);
2377 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
2378 if (context->stream_count == 0)
2379 context->bw.dcn.clk.phyclk_khz = 0;
2381 dc->res_pool->dccg->funcs->update_clocks(
2383 &context->bw.dcn.clk,
2386 dcn10_pplib_apply_display_requirements(dc, context);
2389 hubbub1_program_watermarks(dc->res_pool->hubbub,
2390 &context->bw.dcn.watermarks,
2391 dc->res_pool->ref_clock_inKhz / 1000,
2394 if (dc->debug.sanity_checks)
2395 dcn10_verify_allow_pstate_change_high(dc);
2398 static void set_drr(struct pipe_ctx **pipe_ctx,
2399 int num_pipes, int vmin, int vmax)
2402 struct drr_params params = {0};
2404 params.vertical_total_max = vmax;
2405 params.vertical_total_min = vmin;
2407 /* TODO: If multiple pipes are to be supported, you need
2410 for (i = 0; i < num_pipes; i++) {
2411 pipe_ctx[i]->stream_res.tg->funcs->set_drr(pipe_ctx[i]->stream_res.tg, ¶ms);
2415 static void get_position(struct pipe_ctx **pipe_ctx,
2417 struct crtc_position *position)
2421 /* TODO: handle pipes > 1
2423 for (i = 0; i < num_pipes; i++)
2424 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2427 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2428 int num_pipes, const struct dc_static_screen_events *events)
2431 unsigned int value = 0;
2433 if (events->surface_update)
2435 if (events->cursor_update)
2437 if (events->force_trigger)
2440 for (i = 0; i < num_pipes; i++)
2441 pipe_ctx[i]->stream_res.tg->funcs->
2442 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
2445 static void dcn10_config_stereo_parameters(
2446 struct dc_stream_state *stream, struct crtc_stereo_flags *flags)
2448 enum view_3d_format view_format = stream->view_format;
2449 enum dc_timing_3d_format timing_3d_format =\
2450 stream->timing.timing_3d_format;
2451 bool non_stereo_timing = false;
2453 if (timing_3d_format == TIMING_3D_FORMAT_NONE ||
2454 timing_3d_format == TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2455 timing_3d_format == TIMING_3D_FORMAT_TOP_AND_BOTTOM)
2456 non_stereo_timing = true;
2458 if (non_stereo_timing == false &&
2459 view_format == VIEW_3D_FORMAT_FRAME_SEQUENTIAL) {
2461 flags->PROGRAM_STEREO = 1;
2462 flags->PROGRAM_POLARITY = 1;
2463 if (timing_3d_format == TIMING_3D_FORMAT_INBAND_FA ||
2464 timing_3d_format == TIMING_3D_FORMAT_DP_HDMI_INBAND_FA ||
2465 timing_3d_format == TIMING_3D_FORMAT_SIDEBAND_FA) {
2466 enum display_dongle_type dongle = \
2467 stream->sink->link->ddc->dongle_type;
2468 if (dongle == DISPLAY_DONGLE_DP_VGA_CONVERTER ||
2469 dongle == DISPLAY_DONGLE_DP_DVI_CONVERTER ||
2470 dongle == DISPLAY_DONGLE_DP_HDMI_CONVERTER)
2471 flags->DISABLE_STEREO_DP_SYNC = 1;
2473 flags->RIGHT_EYE_POLARITY =\
2474 stream->timing.flags.RIGHT_EYE_3D_POLARITY;
2475 if (timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2476 flags->FRAME_PACKED = 1;
2482 static void dcn10_setup_stereo(struct pipe_ctx *pipe_ctx, struct dc *dc)
2484 struct crtc_stereo_flags flags = { 0 };
2485 struct dc_stream_state *stream = pipe_ctx->stream;
2487 dcn10_config_stereo_parameters(stream, &flags);
2489 pipe_ctx->stream_res.opp->funcs->opp_program_stereo(
2490 pipe_ctx->stream_res.opp,
2491 flags.PROGRAM_STEREO == 1 ? true:false,
2494 pipe_ctx->stream_res.tg->funcs->program_stereo(
2495 pipe_ctx->stream_res.tg,
2502 static struct hubp *get_hubp_by_inst(struct resource_pool *res_pool, int mpcc_inst)
2506 for (i = 0; i < res_pool->pipe_count; i++) {
2507 if (res_pool->hubps[i]->inst == mpcc_inst)
2508 return res_pool->hubps[i];
2514 static void dcn10_wait_for_mpcc_disconnect(
2516 struct resource_pool *res_pool,
2517 struct pipe_ctx *pipe_ctx)
2521 if (dc->debug.sanity_checks) {
2522 dcn10_verify_allow_pstate_change_high(dc);
2525 if (!pipe_ctx->stream_res.opp)
2528 for (mpcc_inst = 0; mpcc_inst < MAX_PIPES; mpcc_inst++) {
2529 if (pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst]) {
2530 struct hubp *hubp = get_hubp_by_inst(res_pool, mpcc_inst);
2532 res_pool->mpc->funcs->wait_for_idle(res_pool->mpc, mpcc_inst);
2533 pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst] = false;
2534 hubp->funcs->set_blank(hubp, true);
2535 /*DC_LOG_ERROR(dc->ctx->logger,
2536 "[debug_mpo: wait_for_mpcc finished waiting on mpcc %d]\n",
2541 if (dc->debug.sanity_checks) {
2542 dcn10_verify_allow_pstate_change_high(dc);
2547 static bool dcn10_dummy_display_power_gating(
2549 uint8_t controller_id,
2550 struct dc_bios *dcb,
2551 enum pipe_gating_control power_gating)
2556 static void dcn10_update_pending_status(struct pipe_ctx *pipe_ctx)
2558 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2559 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2562 if (plane_state == NULL)
2565 flip_pending = pipe_ctx->plane_res.hubp->funcs->hubp_is_flip_pending(
2566 pipe_ctx->plane_res.hubp);
2568 plane_state->status.is_flip_pending = flip_pending;
2571 plane_state->status.current_address = plane_state->status.requested_address;
2573 if (plane_state->status.current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2574 tg->funcs->is_stereo_left_eye) {
2575 plane_state->status.is_right_eye =
2576 !tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2580 static void dcn10_update_dchub(struct dce_hwseq *hws, struct dchub_init_data *dh_data)
2582 if (hws->ctx->dc->res_pool->hubbub != NULL) {
2583 struct hubp *hubp = hws->ctx->dc->res_pool->hubps[0];
2585 if (hubp->funcs->hubp_update_dchub)
2586 hubp->funcs->hubp_update_dchub(hubp, dh_data);
2588 hubbub1_update_dchub(hws->ctx->dc->res_pool->hubbub, dh_data);
2592 static void dcn10_set_cursor_position(struct pipe_ctx *pipe_ctx)
2594 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2595 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2596 struct dpp *dpp = pipe_ctx->plane_res.dpp;
2597 struct dc_cursor_mi_param param = {
2598 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_khz,
2599 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clock_inKhz,
2600 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2601 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2602 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2603 .rotation = pipe_ctx->plane_state->rotation,
2604 .mirror = pipe_ctx->plane_state->horizontal_mirror
2607 if (pipe_ctx->plane_state->address.type
2608 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2609 pos_cpy.enable = false;
2611 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2612 pos_cpy.enable = false;
2614 hubp->funcs->set_cursor_position(hubp, &pos_cpy, ¶m);
2615 dpp->funcs->set_cursor_position(dpp, &pos_cpy, ¶m, hubp->curs_attr.width);
2618 static void dcn10_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2620 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2622 pipe_ctx->plane_res.hubp->funcs->set_cursor_attributes(
2623 pipe_ctx->plane_res.hubp, attributes);
2624 pipe_ctx->plane_res.dpp->funcs->set_cursor_attributes(
2625 pipe_ctx->plane_res.dpp, attributes->color_format);
2628 static void dcn10_set_cursor_sdr_white_level(struct pipe_ctx *pipe_ctx)
2630 uint32_t sdr_white_level = pipe_ctx->stream->cursor_attributes.sdr_white_level;
2631 struct fixed31_32 multiplier;
2632 struct dpp_cursor_attributes opt_attr = { 0 };
2633 uint32_t hw_scale = 0x3c00; // 1.0 default multiplier
2634 struct custom_float_format fmt;
2636 if (!pipe_ctx->plane_res.dpp->funcs->set_optional_cursor_attributes)
2639 fmt.exponenta_bits = 5;
2640 fmt.mantissa_bits = 10;
2643 if (sdr_white_level > 80) {
2644 multiplier = dc_fixpt_from_fraction(sdr_white_level, 80);
2645 convert_to_custom_float_format(multiplier, &fmt, &hw_scale);
2648 opt_attr.scale = hw_scale;
2651 pipe_ctx->plane_res.dpp->funcs->set_optional_cursor_attributes(
2652 pipe_ctx->plane_res.dpp, &opt_attr);
2655 static const struct hw_sequencer_funcs dcn10_funcs = {
2656 .program_gamut_remap = program_gamut_remap,
2657 .program_csc_matrix = program_csc_matrix,
2658 .init_hw = dcn10_init_hw,
2659 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2660 .apply_ctx_for_surface = dcn10_apply_ctx_for_surface,
2661 .update_plane_addr = dcn10_update_plane_addr,
2662 .plane_atomic_disconnect = hwss1_plane_atomic_disconnect,
2663 .update_dchub = dcn10_update_dchub,
2664 .update_mpcc = dcn10_update_mpcc,
2665 .update_pending_status = dcn10_update_pending_status,
2666 .set_input_transfer_func = dcn10_set_input_transfer_func,
2667 .set_output_transfer_func = dcn10_set_output_transfer_func,
2668 .program_output_csc = dcn10_program_output_csc,
2669 .power_down = dce110_power_down,
2670 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2671 .enable_timing_synchronization = dcn10_enable_timing_synchronization,
2672 .enable_per_frame_crtc_position_reset = dcn10_enable_per_frame_crtc_position_reset,
2673 .update_info_frame = dce110_update_info_frame,
2674 .enable_stream = dce110_enable_stream,
2675 .disable_stream = dce110_disable_stream,
2676 .unblank_stream = dce110_unblank_stream,
2677 .blank_stream = dce110_blank_stream,
2678 .enable_audio_stream = dce110_enable_audio_stream,
2679 .disable_audio_stream = dce110_disable_audio_stream,
2680 .enable_display_power_gating = dcn10_dummy_display_power_gating,
2681 .disable_plane = dcn10_disable_plane,
2682 .blank_pixel_data = dcn10_blank_pixel_data,
2683 .pipe_control_lock = dcn10_pipe_control_lock,
2684 .set_bandwidth = dcn10_set_bandwidth,
2685 .reset_hw_ctx_wrap = reset_hw_ctx_wrap,
2686 .enable_stream_timing = dcn10_enable_stream_timing,
2688 .get_position = get_position,
2689 .set_static_screen_control = set_static_screen_control,
2690 .setup_stereo = dcn10_setup_stereo,
2691 .set_avmute = dce110_set_avmute,
2692 .log_hw_state = dcn10_log_hw_state,
2693 .wait_for_mpcc_disconnect = dcn10_wait_for_mpcc_disconnect,
2694 .ready_shared_resources = ready_shared_resources,
2695 .optimize_shared_resources = optimize_shared_resources,
2696 .pplib_apply_display_requirements =
2697 dcn10_pplib_apply_display_requirements,
2698 .edp_backlight_control = hwss_edp_backlight_control,
2699 .edp_power_control = hwss_edp_power_control,
2700 .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready,
2701 .set_cursor_position = dcn10_set_cursor_position,
2702 .set_cursor_attribute = dcn10_set_cursor_attribute,
2703 .set_cursor_sdr_white_level = dcn10_set_cursor_sdr_white_level
2707 void dcn10_hw_sequencer_construct(struct dc *dc)
2709 dc->hwss = dcn10_funcs;