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 "dm_services.h"
27 #include "core_types.h"
29 #include "custom_float.h"
30 #include "dcn10_hw_sequencer.h"
31 #include "dce110/dce110_hw_sequencer.h"
32 #include "dce/dce_hwseq.h"
35 #include "dcn10_optc.h"
36 #include "dcn10/dcn10_dpp.h"
37 #include "dcn10/dcn10_mpc.h"
38 #include "timing_generator.h"
42 #include "reg_helper.h"
43 #include "custom_float.h"
44 #include "dcn10_hubp.h"
45 #include "dcn10_hubbub.h"
46 #include "dcn10_cm_common.h"
56 #define FN(reg_name, field_name) \
57 hws->shifts->field_name, hws->masks->field_name
59 #define DTN_INFO_MICRO_SEC(ref_cycle) \
60 print_microsec(dc_ctx, ref_cycle)
62 void print_microsec(struct dc_context *dc_ctx, uint32_t ref_cycle)
64 static const uint32_t ref_clk_mhz = 48;
65 static const unsigned int frac = 10;
66 uint32_t us_x10 = (ref_cycle * frac) / ref_clk_mhz;
74 static void log_mpc_crc(struct dc *dc)
76 struct dc_context *dc_ctx = dc->ctx;
77 struct dce_hwseq *hws = dc->hwseq;
79 if (REG(MPC_CRC_RESULT_GB))
80 DTN_INFO("MPC_CRC_RESULT_GB:%d MPC_CRC_RESULT_C:%d MPC_CRC_RESULT_AR:%d\n",
81 REG_READ(MPC_CRC_RESULT_GB), REG_READ(MPC_CRC_RESULT_C), REG_READ(MPC_CRC_RESULT_AR));
82 if (REG(DPP_TOP0_DPP_CRC_VAL_B_A))
83 DTN_INFO("DPP_TOP0_DPP_CRC_VAL_B_A:%d DPP_TOP0_DPP_CRC_VAL_R_G:%d\n",
84 REG_READ(DPP_TOP0_DPP_CRC_VAL_B_A), REG_READ(DPP_TOP0_DPP_CRC_VAL_R_G));
87 void dcn10_log_hubbub_state(struct dc *dc)
89 struct dc_context *dc_ctx = dc->ctx;
90 struct dcn_hubbub_wm wm;
93 hubbub1_wm_read_state(dc->res_pool->hubbub, &wm);
95 DTN_INFO("HUBBUB WM: \t data_urgent \t pte_meta_urgent \t "
96 "sr_enter \t sr_exit \t dram_clk_change \n");
98 for (i = 0; i < 4; i++) {
99 struct dcn_hubbub_wm_set *s;
102 DTN_INFO("WM_Set[%d]:\t ", s->wm_set);
103 DTN_INFO_MICRO_SEC(s->data_urgent);
104 DTN_INFO_MICRO_SEC(s->pte_meta_urgent);
105 DTN_INFO_MICRO_SEC(s->sr_enter);
106 DTN_INFO_MICRO_SEC(s->sr_exit);
107 DTN_INFO_MICRO_SEC(s->dram_clk_chanage);
114 void dcn10_log_hw_state(struct dc *dc)
116 struct dc_context *dc_ctx = dc->ctx;
117 struct resource_pool *pool = dc->res_pool;
122 dcn10_log_hubbub_state(dc);
124 DTN_INFO("HUBP:\t format \t addr_hi \t width \t height \t "
125 "rotation \t mirror \t sw_mode \t "
126 "dcc_en \t blank_en \t ttu_dis \t underflow \t "
127 "min_ttu_vblank \t qos_low_wm \t qos_high_wm \n");
129 for (i = 0; i < pool->pipe_count; i++) {
130 struct hubp *hubp = pool->hubps[i];
131 struct dcn_hubp_state s;
133 hubp1_read_state(TO_DCN10_HUBP(hubp), &s);
135 DTN_INFO("[%d]:\t %xh \t %xh \t %d \t %d \t "
136 "%xh \t %xh \t %xh \t "
137 "%d \t %d \t %d \t %xh \t",
150 DTN_INFO_MICRO_SEC(s.min_ttu_vblank);
151 DTN_INFO_MICRO_SEC(s.qos_level_low_wm);
152 DTN_INFO_MICRO_SEC(s.qos_level_high_wm);
157 DTN_INFO("OTG:\t v_bs \t v_be \t v_ss \t v_se \t vpol \t vmax \t vmin \t "
158 "h_bs \t h_be \t h_ss \t h_se \t hpol \t htot \t vtot \t underflow\n");
160 for (i = 0; i < pool->timing_generator_count; i++) {
161 struct timing_generator *tg = pool->timing_generators[i];
162 struct dcn_otg_state s = {0};
164 optc1_read_otg_state(DCN10TG_FROM_TG(tg), &s);
166 //only print if OTG master is enabled
167 if ((s.otg_enabled & 1) == 0)
170 DTN_INFO("[%d]:\t %d \t %d \t %d \t %d \t "
171 "%d \t %d \t %d \t %d \t %d \t %d \t "
172 "%d \t %d \t %d \t %d \t %d \t ",
188 s.underflow_occurred_status);
198 static void enable_power_gating_plane(
199 struct dce_hwseq *hws,
202 bool force_on = 1; /* disable power gating */
208 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on);
209 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN2_POWER_FORCEON, force_on);
210 REG_UPDATE(DOMAIN4_PG_CONFIG, DOMAIN4_POWER_FORCEON, force_on);
211 REG_UPDATE(DOMAIN6_PG_CONFIG, DOMAIN6_POWER_FORCEON, force_on);
214 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN1_POWER_FORCEON, force_on);
215 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN3_POWER_FORCEON, force_on);
216 REG_UPDATE(DOMAIN5_PG_CONFIG, DOMAIN5_POWER_FORCEON, force_on);
217 REG_UPDATE(DOMAIN7_PG_CONFIG, DOMAIN7_POWER_FORCEON, force_on);
220 static void disable_vga(
221 struct dce_hwseq *hws)
223 REG_WRITE(D1VGA_CONTROL, 0);
224 REG_WRITE(D2VGA_CONTROL, 0);
225 REG_WRITE(D3VGA_CONTROL, 0);
226 REG_WRITE(D4VGA_CONTROL, 0);
229 static void dpp_pg_control(
230 struct dce_hwseq *hws,
231 unsigned int dpp_inst,
234 uint32_t power_gate = power_on ? 0 : 1;
235 uint32_t pwr_status = power_on ? 0 : 2;
237 if (hws->ctx->dc->debug.disable_dpp_power_gate)
242 REG_UPDATE(DOMAIN1_PG_CONFIG,
243 DOMAIN1_POWER_GATE, power_gate);
245 REG_WAIT(DOMAIN1_PG_STATUS,
246 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
250 REG_UPDATE(DOMAIN3_PG_CONFIG,
251 DOMAIN3_POWER_GATE, power_gate);
253 REG_WAIT(DOMAIN3_PG_STATUS,
254 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
258 REG_UPDATE(DOMAIN5_PG_CONFIG,
259 DOMAIN5_POWER_GATE, power_gate);
261 REG_WAIT(DOMAIN5_PG_STATUS,
262 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
266 REG_UPDATE(DOMAIN7_PG_CONFIG,
267 DOMAIN7_POWER_GATE, power_gate);
269 REG_WAIT(DOMAIN7_PG_STATUS,
270 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
279 static void hubp_pg_control(
280 struct dce_hwseq *hws,
281 unsigned int hubp_inst,
284 uint32_t power_gate = power_on ? 0 : 1;
285 uint32_t pwr_status = power_on ? 0 : 2;
287 if (hws->ctx->dc->debug.disable_hubp_power_gate)
291 case 0: /* DCHUBP0 */
292 REG_UPDATE(DOMAIN0_PG_CONFIG,
293 DOMAIN0_POWER_GATE, power_gate);
295 REG_WAIT(DOMAIN0_PG_STATUS,
296 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
299 case 1: /* DCHUBP1 */
300 REG_UPDATE(DOMAIN2_PG_CONFIG,
301 DOMAIN2_POWER_GATE, power_gate);
303 REG_WAIT(DOMAIN2_PG_STATUS,
304 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
307 case 2: /* DCHUBP2 */
308 REG_UPDATE(DOMAIN4_PG_CONFIG,
309 DOMAIN4_POWER_GATE, power_gate);
311 REG_WAIT(DOMAIN4_PG_STATUS,
312 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
315 case 3: /* DCHUBP3 */
316 REG_UPDATE(DOMAIN6_PG_CONFIG,
317 DOMAIN6_POWER_GATE, power_gate);
319 REG_WAIT(DOMAIN6_PG_STATUS,
320 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
329 static void power_on_plane(
330 struct dce_hwseq *hws,
333 struct dc_context *ctx = hws->ctx;
334 if (REG(DC_IP_REQUEST_CNTL)) {
335 REG_SET(DC_IP_REQUEST_CNTL, 0,
337 dpp_pg_control(hws, plane_id, true);
338 hubp_pg_control(hws, plane_id, true);
339 REG_SET(DC_IP_REQUEST_CNTL, 0,
342 "Un-gated front end for pipe %d\n", plane_id);
346 static void undo_DEGVIDCN10_253_wa(struct dc *dc)
348 struct dce_hwseq *hws = dc->hwseq;
349 struct hubp *hubp = dc->res_pool->hubps[0];
351 if (!hws->wa_state.DEGVIDCN10_253_applied)
354 hubp->funcs->set_blank(hubp, true);
356 REG_SET(DC_IP_REQUEST_CNTL, 0,
359 hubp_pg_control(hws, 0, false);
360 REG_SET(DC_IP_REQUEST_CNTL, 0,
363 hws->wa_state.DEGVIDCN10_253_applied = false;
366 static void apply_DEGVIDCN10_253_wa(struct dc *dc)
368 struct dce_hwseq *hws = dc->hwseq;
369 struct hubp *hubp = dc->res_pool->hubps[0];
372 if (dc->debug.disable_stutter)
375 if (!hws->wa.DEGVIDCN10_253)
378 for (i = 0; i < dc->res_pool->pipe_count; i++) {
379 if (!dc->res_pool->hubps[i]->power_gated)
383 /* all pipe power gated, apply work around to enable stutter. */
385 REG_SET(DC_IP_REQUEST_CNTL, 0,
388 hubp_pg_control(hws, 0, true);
389 REG_SET(DC_IP_REQUEST_CNTL, 0,
392 hubp->funcs->set_hubp_blank_en(hubp, false);
393 hws->wa_state.DEGVIDCN10_253_applied = true;
396 static void bios_golden_init(struct dc *dc)
398 struct dc_bios *bp = dc->ctx->dc_bios;
401 /* initialize dcn global */
402 bp->funcs->enable_disp_power_gating(bp,
403 CONTROLLER_ID_D0, ASIC_PIPE_INIT);
405 for (i = 0; i < dc->res_pool->pipe_count; i++) {
406 /* initialize dcn per pipe */
407 bp->funcs->enable_disp_power_gating(bp,
408 CONTROLLER_ID_D0 + i, ASIC_PIPE_DISABLE);
412 static void false_optc_underflow_wa(
414 const struct dc_stream_state *stream,
415 struct timing_generator *tg)
420 if (!dc->hwseq->wa.false_optc_underflow)
423 underflow = tg->funcs->is_optc_underflow_occurred(tg);
425 for (i = 0; i < dc->res_pool->pipe_count; i++) {
426 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
428 if (old_pipe_ctx->stream != stream)
431 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, old_pipe_ctx);
434 tg->funcs->set_blank_data_double_buffer(tg, true);
436 if (tg->funcs->is_optc_underflow_occurred(tg) && !underflow)
437 tg->funcs->clear_optc_underflow(tg);
440 static enum dc_status dcn10_prog_pixclk_crtc_otg(
441 struct pipe_ctx *pipe_ctx,
442 struct dc_state *context,
445 struct dc_stream_state *stream = pipe_ctx->stream;
446 enum dc_color_space color_space;
447 struct tg_color black_color = {0};
449 /* by upper caller loop, pipe0 is parent pipe and be called first.
450 * back end is set up by for pipe0. Other children pipe share back end
451 * with pipe 0. No program is needed.
453 if (pipe_ctx->top_pipe != NULL)
456 /* TODO check if timing_changed, disable stream if timing changed */
458 /* HW program guide assume display already disable
459 * by unplug sequence. OTG assume stop.
461 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
463 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
464 pipe_ctx->clock_source,
465 &pipe_ctx->stream_res.pix_clk_params,
466 &pipe_ctx->pll_settings)) {
468 return DC_ERROR_UNEXPECTED;
470 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
471 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
472 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
473 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
475 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
477 pipe_ctx->stream_res.tg->funcs->program_timing(
478 pipe_ctx->stream_res.tg,
482 #if 0 /* move to after enable_crtc */
483 /* TODO: OPP FMT, ABM. etc. should be done here. */
484 /* or FPGA now. instance 0 only. TODO: move to opp.c */
486 inst_offset = reg_offsets[pipe_ctx->stream_res.tg->inst].fmt;
488 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
489 pipe_ctx->stream_res.opp,
490 &stream->bit_depth_params,
493 /* program otg blank color */
494 color_space = stream->output_color_space;
495 color_space_to_black_color(dc, color_space, &black_color);
497 if (pipe_ctx->stream_res.tg->funcs->set_blank_color)
498 pipe_ctx->stream_res.tg->funcs->set_blank_color(
499 pipe_ctx->stream_res.tg,
502 if (pipe_ctx->stream_res.tg->funcs->is_blanked &&
503 !pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg)) {
504 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
505 hwss_wait_for_blank_complete(pipe_ctx->stream_res.tg);
506 false_optc_underflow_wa(dc, pipe_ctx->stream, pipe_ctx->stream_res.tg);
509 /* VTG is within DCHUB command block. DCFCLK is always on */
510 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
512 return DC_ERROR_UNEXPECTED;
515 /* TODO program crtc source select for non-virtual signal*/
516 /* TODO program FMT */
517 /* TODO setup link_enc */
518 /* TODO set stream attributes */
519 /* TODO program audio */
520 /* TODO enable stream if timing changed */
521 /* TODO unblank stream if DP */
526 static void reset_back_end_for_pipe(
528 struct pipe_ctx *pipe_ctx,
529 struct dc_state *context)
532 struct dc_context *ctx = dc->ctx;
533 if (pipe_ctx->stream_res.stream_enc == NULL) {
534 pipe_ctx->stream = NULL;
538 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
539 /* DPMS may already disable */
540 if (!pipe_ctx->stream->dpms_off)
541 core_link_disable_stream(pipe_ctx, FREE_ACQUIRED_RESOURCE);
542 else if (pipe_ctx->stream_res.audio) {
544 * if stream is already disabled outside of commit streams path,
545 * audio disable was skipped. Need to do it here
547 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
549 if (dc->caps.dynamic_audio == true) {
550 /*we have to dynamic arbitrate the audio endpoints*/
551 pipe_ctx->stream_res.audio = NULL;
552 /*we free the resource, need reset is_audio_acquired*/
553 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool, pipe_ctx->stream_res.audio, false);
560 /* by upper caller loop, parent pipe: pipe0, will be reset last.
561 * back end share by all pipes and will be disable only when disable
564 if (pipe_ctx->top_pipe == NULL) {
565 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
567 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
570 for (i = 0; i < dc->res_pool->pipe_count; i++)
571 if (&dc->current_state->res_ctx.pipe_ctx[i] == pipe_ctx)
574 if (i == dc->res_pool->pipe_count)
577 pipe_ctx->stream = NULL;
578 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
579 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
582 static void dcn10_verify_allow_pstate_change_high(struct dc *dc)
584 static bool should_log_hw_state; /* prevent hw state log by default */
586 if (!hubbub1_verify_allow_pstate_change_high(dc->res_pool->hubbub)) {
587 if (should_log_hw_state) {
588 dcn10_log_hw_state(dc);
595 /* trigger HW to start disconnect plane from stream on the next vsync */
596 static void plane_atomic_disconnect(struct dc *dc, struct pipe_ctx *pipe_ctx)
598 struct hubp *hubp = pipe_ctx->plane_res.hubp;
599 int dpp_id = pipe_ctx->plane_res.dpp->inst;
600 struct mpc *mpc = dc->res_pool->mpc;
601 struct mpc_tree *mpc_tree_params;
602 struct mpcc *mpcc_to_remove = NULL;
603 struct output_pixel_processor *opp = pipe_ctx->stream_res.opp;
605 mpc_tree_params = &(opp->mpc_tree_params);
606 mpcc_to_remove = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, dpp_id);
609 if (mpcc_to_remove == NULL)
612 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, mpcc_to_remove);
613 opp->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
615 dc->optimized_required = true;
617 if (hubp->funcs->hubp_disconnect)
618 hubp->funcs->hubp_disconnect(hubp);
620 if (dc->debug.sanity_checks)
621 dcn10_verify_allow_pstate_change_high(dc);
624 static void plane_atomic_power_down(struct dc *dc, struct pipe_ctx *pipe_ctx)
626 struct dce_hwseq *hws = dc->hwseq;
627 struct dpp *dpp = pipe_ctx->plane_res.dpp;
628 struct dc_context *ctx = dc->ctx;
630 if (REG(DC_IP_REQUEST_CNTL)) {
631 REG_SET(DC_IP_REQUEST_CNTL, 0,
633 dpp_pg_control(hws, dpp->inst, false);
634 hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, false);
635 dpp->funcs->dpp_reset(dpp);
636 REG_SET(DC_IP_REQUEST_CNTL, 0,
639 "Power gated front end %d\n", pipe_ctx->pipe_idx);
643 /* disable HW used by plane.
644 * note: cannot disable until disconnect is complete
646 static void plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
648 struct hubp *hubp = pipe_ctx->plane_res.hubp;
649 struct dpp *dpp = pipe_ctx->plane_res.dpp;
650 int opp_id = hubp->opp_id;
652 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
654 hubp->funcs->hubp_clk_cntl(hubp, false);
656 dpp->funcs->dpp_dppclk_control(dpp, false, false);
658 if (opp_id != 0xf && pipe_ctx->stream_res.opp->mpc_tree_params.opp_list == NULL)
659 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
660 pipe_ctx->stream_res.opp,
663 hubp->power_gated = true;
664 dc->optimized_required = false; /* We're powering off, no need to optimize */
666 plane_atomic_power_down(dc, pipe_ctx);
668 pipe_ctx->stream = NULL;
669 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
670 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
671 pipe_ctx->top_pipe = NULL;
672 pipe_ctx->bottom_pipe = NULL;
673 pipe_ctx->plane_state = NULL;
676 static void dcn10_disable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx)
678 struct dc_context *ctx = dc->ctx;
680 if (!pipe_ctx->plane_res.hubp || pipe_ctx->plane_res.hubp->power_gated)
683 plane_atomic_disable(dc, pipe_ctx);
685 apply_DEGVIDCN10_253_wa(dc);
687 DC_LOG_DC("Power down front end %d\n",
691 static void dcn10_init_hw(struct dc *dc)
694 struct abm *abm = dc->res_pool->abm;
695 struct dmcu *dmcu = dc->res_pool->dmcu;
696 struct dce_hwseq *hws = dc->hwseq;
697 struct dc_bios *dcb = dc->ctx->dc_bios;
698 struct dc_state *context = dc->current_state;
700 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
701 REG_WRITE(REFCLK_CNTL, 0);
702 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
703 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
705 if (!dc->debug.disable_clock_gate) {
706 /* enable all DCN clock gating */
707 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
709 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
711 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
714 enable_power_gating_plane(dc->hwseq, true);
717 if (!dcb->funcs->is_accelerated_mode(dcb)) {
718 bios_golden_init(dc);
719 disable_vga(dc->hwseq);
722 for (i = 0; i < dc->link_count; i++) {
723 /* Power up AND update implementation according to the
724 * required signal (which may be different from the
725 * default signal on connector).
727 struct dc_link *link = dc->links[i];
729 if (link->link_enc->connector.id == CONNECTOR_ID_EDP)
730 dc->hwss.edp_power_control(link, true);
732 link->link_enc->funcs->hw_init(link->link_enc);
736 for (i = 0; i < dc->res_pool->pipe_count; i++) {
737 struct timing_generator *tg = dc->res_pool->timing_generators[i];
739 if (tg->funcs->is_tg_enabled(tg))
743 /* Blank controller using driver code instead of
746 for (i = 0; i < dc->res_pool->pipe_count; i++) {
747 struct timing_generator *tg = dc->res_pool->timing_generators[i];
749 if (tg->funcs->is_tg_enabled(tg)) {
750 tg->funcs->set_blank(tg, true);
751 hwss_wait_for_blank_complete(tg);
755 /* Reset all MPCC muxes */
756 dc->res_pool->mpc->funcs->mpc_init(dc->res_pool->mpc);
758 for (i = 0; i < dc->res_pool->pipe_count; i++) {
759 struct timing_generator *tg = dc->res_pool->timing_generators[i];
760 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
761 struct hubp *hubp = dc->res_pool->hubps[i];
762 struct dpp *dpp = dc->res_pool->dpps[i];
764 pipe_ctx->stream_res.tg = tg;
765 pipe_ctx->pipe_idx = i;
767 pipe_ctx->plane_res.hubp = hubp;
768 pipe_ctx->plane_res.dpp = dpp;
769 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
770 hubp->mpcc_id = dpp->inst;
772 hubp->power_gated = false;
774 dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
775 dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
776 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
777 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
779 plane_atomic_disconnect(dc, pipe_ctx);
782 for (i = 0; i < dc->res_pool->pipe_count; i++) {
783 struct timing_generator *tg = dc->res_pool->timing_generators[i];
785 if (tg->funcs->is_tg_enabled(tg))
786 tg->funcs->unlock(tg);
789 for (i = 0; i < dc->res_pool->pipe_count; i++) {
790 struct timing_generator *tg = dc->res_pool->timing_generators[i];
791 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
793 dcn10_disable_plane(dc, pipe_ctx);
795 pipe_ctx->stream_res.tg = NULL;
796 pipe_ctx->plane_res.hubp = NULL;
798 tg->funcs->tg_init(tg);
801 /* end of FPGA. Below if real ASIC */
802 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
805 for (i = 0; i < dc->res_pool->audio_count; i++) {
806 struct audio *audio = dc->res_pool->audios[i];
808 audio->funcs->hw_init(audio);
812 abm->funcs->init_backlight(abm);
813 abm->funcs->abm_init(abm);
817 dmcu->funcs->dmcu_init(dmcu);
819 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
820 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
822 if (!dc->debug.disable_clock_gate) {
823 /* enable all DCN clock gating */
824 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
826 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
828 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
831 enable_power_gating_plane(dc->hwseq, true);
834 static void reset_hw_ctx_wrap(
836 struct dc_state *context)
841 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
842 struct pipe_ctx *pipe_ctx_old =
843 &dc->current_state->res_ctx.pipe_ctx[i];
844 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
846 if (!pipe_ctx_old->stream)
849 if (pipe_ctx_old->top_pipe)
852 if (!pipe_ctx->stream ||
853 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
854 struct clock_source *old_clk = pipe_ctx_old->clock_source;
856 reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
858 old_clk->funcs->cs_power_down(old_clk);
864 static bool patch_address_for_sbs_tb_stereo(
865 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
867 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
868 bool sec_split = pipe_ctx->top_pipe &&
869 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
870 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
871 (pipe_ctx->stream->timing.timing_3d_format ==
872 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
873 pipe_ctx->stream->timing.timing_3d_format ==
874 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
875 *addr = plane_state->address.grph_stereo.left_addr;
876 plane_state->address.grph_stereo.left_addr =
877 plane_state->address.grph_stereo.right_addr;
880 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
881 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
882 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
883 plane_state->address.grph_stereo.right_addr =
884 plane_state->address.grph_stereo.left_addr;
892 static void dcn10_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
894 bool addr_patched = false;
895 PHYSICAL_ADDRESS_LOC addr;
896 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
898 if (plane_state == NULL)
900 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
901 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
902 pipe_ctx->plane_res.hubp,
903 &plane_state->address,
904 plane_state->flip_immediate);
905 plane_state->status.requested_address = plane_state->address;
907 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
910 static bool dcn10_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
911 const struct dc_plane_state *plane_state)
913 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
914 const struct dc_transfer_func *tf = NULL;
917 if (dpp_base == NULL)
920 if (plane_state->in_transfer_func)
921 tf = plane_state->in_transfer_func;
923 if (plane_state->gamma_correction &&
924 plane_state->gamma_correction->is_identity)
925 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
926 else if (plane_state->gamma_correction && dce_use_lut(plane_state->format))
927 dpp_base->funcs->dpp_program_input_lut(dpp_base, plane_state->gamma_correction);
930 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
931 else if (tf->type == TF_TYPE_PREDEFINED) {
933 case TRANSFER_FUNCTION_SRGB:
934 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_sRGB);
936 case TRANSFER_FUNCTION_BT709:
937 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_xvYCC);
939 case TRANSFER_FUNCTION_LINEAR:
940 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
942 case TRANSFER_FUNCTION_PQ:
947 } else if (tf->type == TF_TYPE_BYPASS) {
948 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
950 /*TF_TYPE_DISTRIBUTED_POINTS*/
962 dcn10_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
963 const struct dc_stream_state *stream)
965 struct dpp *dpp = pipe_ctx->plane_res.dpp;
970 dpp->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
972 if (stream->out_transfer_func &&
973 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
974 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB)
975 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_SRGB);
977 /* dcn10_translate_regamma_to_hw_format takes 750us, only do it when full
980 else if (cm_helper_translate_curve_to_hw_format(
981 stream->out_transfer_func,
982 &dpp->regamma_params, false)) {
983 dpp->funcs->dpp_program_regamma_pwl(
985 &dpp->regamma_params, OPP_REGAMMA_USER);
987 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_BYPASS);
992 static void dcn10_pipe_control_lock(
994 struct pipe_ctx *pipe,
997 /* use TG master update lock to lock everything on the TG
998 * therefore only top pipe need to lock
1003 if (dc->debug.sanity_checks)
1004 dcn10_verify_allow_pstate_change_high(dc);
1007 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1009 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1011 if (dc->debug.sanity_checks)
1012 dcn10_verify_allow_pstate_change_high(dc);
1015 static bool wait_for_reset_trigger_to_occur(
1016 struct dc_context *dc_ctx,
1017 struct timing_generator *tg)
1021 /* To avoid endless loop we wait at most
1022 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
1023 const uint32_t frames_to_wait_on_triggered_reset = 10;
1026 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
1028 if (!tg->funcs->is_counter_moving(tg)) {
1029 DC_ERROR("TG counter is not moving!\n");
1033 if (tg->funcs->did_triggered_reset_occur(tg)) {
1035 /* usually occurs at i=1 */
1036 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
1041 /* Wait for one frame. */
1042 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
1043 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
1047 DC_ERROR("GSL: Timeout on reset trigger!\n");
1052 static void dcn10_enable_timing_synchronization(
1056 struct pipe_ctx *grouped_pipes[])
1058 struct dc_context *dc_ctx = dc->ctx;
1061 DC_SYNC_INFO("Setting up OTG reset trigger\n");
1063 for (i = 1; i < group_size; i++)
1064 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
1065 grouped_pipes[i]->stream_res.tg,
1066 grouped_pipes[0]->stream_res.tg->inst);
1068 DC_SYNC_INFO("Waiting for trigger\n");
1070 /* Need to get only check 1 pipe for having reset as all the others are
1071 * synchronized. Look at last pipe programmed to reset.
1074 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[1]->stream_res.tg);
1075 for (i = 1; i < group_size; i++)
1076 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
1077 grouped_pipes[i]->stream_res.tg);
1079 DC_SYNC_INFO("Sync complete\n");
1082 static void dcn10_enable_per_frame_crtc_position_reset(
1085 struct pipe_ctx *grouped_pipes[])
1087 struct dc_context *dc_ctx = dc->ctx;
1090 DC_SYNC_INFO("Setting up\n");
1091 for (i = 0; i < group_size; i++)
1092 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
1093 grouped_pipes[i]->stream_res.tg,
1094 grouped_pipes[i]->stream->triggered_crtc_reset.event_source->status.primary_otg_inst,
1095 &grouped_pipes[i]->stream->triggered_crtc_reset);
1097 DC_SYNC_INFO("Waiting for trigger\n");
1099 for (i = 0; i < group_size; i++)
1100 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
1102 DC_SYNC_INFO("Multi-display sync is complete\n");
1105 /*static void print_rq_dlg_ttu(
1107 struct pipe_ctx *pipe_ctx)
1109 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1110 "\n============== DML TTU Output parameters [%d] ==============\n"
1111 "qos_level_low_wm: %d, \n"
1112 "qos_level_high_wm: %d, \n"
1113 "min_ttu_vblank: %d, \n"
1114 "qos_level_flip: %d, \n"
1115 "refcyc_per_req_delivery_l: %d, \n"
1116 "qos_level_fixed_l: %d, \n"
1117 "qos_ramp_disable_l: %d, \n"
1118 "refcyc_per_req_delivery_pre_l: %d, \n"
1119 "refcyc_per_req_delivery_c: %d, \n"
1120 "qos_level_fixed_c: %d, \n"
1121 "qos_ramp_disable_c: %d, \n"
1122 "refcyc_per_req_delivery_pre_c: %d\n"
1123 "=============================================================\n",
1125 pipe_ctx->ttu_regs.qos_level_low_wm,
1126 pipe_ctx->ttu_regs.qos_level_high_wm,
1127 pipe_ctx->ttu_regs.min_ttu_vblank,
1128 pipe_ctx->ttu_regs.qos_level_flip,
1129 pipe_ctx->ttu_regs.refcyc_per_req_delivery_l,
1130 pipe_ctx->ttu_regs.qos_level_fixed_l,
1131 pipe_ctx->ttu_regs.qos_ramp_disable_l,
1132 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_l,
1133 pipe_ctx->ttu_regs.refcyc_per_req_delivery_c,
1134 pipe_ctx->ttu_regs.qos_level_fixed_c,
1135 pipe_ctx->ttu_regs.qos_ramp_disable_c,
1136 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_c
1139 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1140 "\n============== DML DLG Output parameters [%d] ==============\n"
1141 "refcyc_h_blank_end: %d, \n"
1142 "dlg_vblank_end: %d, \n"
1143 "min_dst_y_next_start: %d, \n"
1144 "refcyc_per_htotal: %d, \n"
1145 "refcyc_x_after_scaler: %d, \n"
1146 "dst_y_after_scaler: %d, \n"
1147 "dst_y_prefetch: %d, \n"
1148 "dst_y_per_vm_vblank: %d, \n"
1149 "dst_y_per_row_vblank: %d, \n"
1150 "ref_freq_to_pix_freq: %d, \n"
1151 "vratio_prefetch: %d, \n"
1152 "refcyc_per_pte_group_vblank_l: %d, \n"
1153 "refcyc_per_meta_chunk_vblank_l: %d, \n"
1154 "dst_y_per_pte_row_nom_l: %d, \n"
1155 "refcyc_per_pte_group_nom_l: %d, \n",
1157 pipe_ctx->dlg_regs.refcyc_h_blank_end,
1158 pipe_ctx->dlg_regs.dlg_vblank_end,
1159 pipe_ctx->dlg_regs.min_dst_y_next_start,
1160 pipe_ctx->dlg_regs.refcyc_per_htotal,
1161 pipe_ctx->dlg_regs.refcyc_x_after_scaler,
1162 pipe_ctx->dlg_regs.dst_y_after_scaler,
1163 pipe_ctx->dlg_regs.dst_y_prefetch,
1164 pipe_ctx->dlg_regs.dst_y_per_vm_vblank,
1165 pipe_ctx->dlg_regs.dst_y_per_row_vblank,
1166 pipe_ctx->dlg_regs.ref_freq_to_pix_freq,
1167 pipe_ctx->dlg_regs.vratio_prefetch,
1168 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_l,
1169 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_l,
1170 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_l,
1171 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_l
1174 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1175 "\ndst_y_per_meta_row_nom_l: %d, \n"
1176 "refcyc_per_meta_chunk_nom_l: %d, \n"
1177 "refcyc_per_line_delivery_pre_l: %d, \n"
1178 "refcyc_per_line_delivery_l: %d, \n"
1179 "vratio_prefetch_c: %d, \n"
1180 "refcyc_per_pte_group_vblank_c: %d, \n"
1181 "refcyc_per_meta_chunk_vblank_c: %d, \n"
1182 "dst_y_per_pte_row_nom_c: %d, \n"
1183 "refcyc_per_pte_group_nom_c: %d, \n"
1184 "dst_y_per_meta_row_nom_c: %d, \n"
1185 "refcyc_per_meta_chunk_nom_c: %d, \n"
1186 "refcyc_per_line_delivery_pre_c: %d, \n"
1187 "refcyc_per_line_delivery_c: %d \n"
1188 "========================================================\n",
1189 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_l,
1190 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_l,
1191 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_l,
1192 pipe_ctx->dlg_regs.refcyc_per_line_delivery_l,
1193 pipe_ctx->dlg_regs.vratio_prefetch_c,
1194 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_c,
1195 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_c,
1196 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_c,
1197 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_c,
1198 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_c,
1199 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_c,
1200 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_c,
1201 pipe_ctx->dlg_regs.refcyc_per_line_delivery_c
1204 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1205 "\n============== DML RQ Output parameters [%d] ==============\n"
1207 "min_chunk_size: %d \n"
1208 "meta_chunk_size: %d \n"
1209 "min_meta_chunk_size: %d \n"
1210 "dpte_group_size: %d \n"
1211 "mpte_group_size: %d \n"
1212 "swath_height: %d \n"
1213 "pte_row_height_linear: %d \n"
1214 "========================================================\n",
1216 pipe_ctx->rq_regs.rq_regs_l.chunk_size,
1217 pipe_ctx->rq_regs.rq_regs_l.min_chunk_size,
1218 pipe_ctx->rq_regs.rq_regs_l.meta_chunk_size,
1219 pipe_ctx->rq_regs.rq_regs_l.min_meta_chunk_size,
1220 pipe_ctx->rq_regs.rq_regs_l.dpte_group_size,
1221 pipe_ctx->rq_regs.rq_regs_l.mpte_group_size,
1222 pipe_ctx->rq_regs.rq_regs_l.swath_height,
1223 pipe_ctx->rq_regs.rq_regs_l.pte_row_height_linear
1228 static void mmhub_read_vm_system_aperture_settings(struct dcn10_hubp *hubp1,
1229 struct vm_system_aperture_param *apt,
1230 struct dce_hwseq *hws)
1232 PHYSICAL_ADDRESS_LOC physical_page_number;
1233 uint32_t logical_addr_low;
1234 uint32_t logical_addr_high;
1236 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
1237 PHYSICAL_PAGE_NUMBER_MSB, &physical_page_number.high_part);
1238 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
1239 PHYSICAL_PAGE_NUMBER_LSB, &physical_page_number.low_part);
1241 REG_GET(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1242 LOGICAL_ADDR, &logical_addr_low);
1244 REG_GET(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1245 LOGICAL_ADDR, &logical_addr_high);
1247 apt->sys_default.quad_part = physical_page_number.quad_part << 12;
1248 apt->sys_low.quad_part = (int64_t)logical_addr_low << 18;
1249 apt->sys_high.quad_part = (int64_t)logical_addr_high << 18;
1252 /* Temporary read settings, future will get values from kmd directly */
1253 static void mmhub_read_vm_context0_settings(struct dcn10_hubp *hubp1,
1254 struct vm_context0_param *vm0,
1255 struct dce_hwseq *hws)
1257 PHYSICAL_ADDRESS_LOC fb_base;
1258 PHYSICAL_ADDRESS_LOC fb_offset;
1259 uint32_t fb_base_value;
1260 uint32_t fb_offset_value;
1262 REG_GET(DCHUBBUB_SDPIF_FB_BASE, SDPIF_FB_BASE, &fb_base_value);
1263 REG_GET(DCHUBBUB_SDPIF_FB_OFFSET, SDPIF_FB_OFFSET, &fb_offset_value);
1265 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
1266 PAGE_DIRECTORY_ENTRY_HI32, &vm0->pte_base.high_part);
1267 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
1268 PAGE_DIRECTORY_ENTRY_LO32, &vm0->pte_base.low_part);
1270 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
1271 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_start.high_part);
1272 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
1273 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_start.low_part);
1275 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
1276 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_end.high_part);
1277 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
1278 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_end.low_part);
1280 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
1281 PHYSICAL_PAGE_ADDR_HI4, &vm0->fault_default.high_part);
1282 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
1283 PHYSICAL_PAGE_ADDR_LO32, &vm0->fault_default.low_part);
1286 * The values in VM_CONTEXT0_PAGE_TABLE_BASE_ADDR is in UMA space.
1287 * Therefore we need to do
1288 * DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
1289 * - DCHUBBUB_SDPIF_FB_OFFSET + DCHUBBUB_SDPIF_FB_BASE
1291 fb_base.quad_part = (uint64_t)fb_base_value << 24;
1292 fb_offset.quad_part = (uint64_t)fb_offset_value << 24;
1293 vm0->pte_base.quad_part += fb_base.quad_part;
1294 vm0->pte_base.quad_part -= fb_offset.quad_part;
1298 static void dcn10_program_pte_vm(struct dce_hwseq *hws, struct hubp *hubp)
1300 struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
1301 struct vm_system_aperture_param apt = { {{ 0 } } };
1302 struct vm_context0_param vm0 = { { { 0 } } };
1304 mmhub_read_vm_system_aperture_settings(hubp1, &apt, hws);
1305 mmhub_read_vm_context0_settings(hubp1, &vm0, hws);
1307 hubp->funcs->hubp_set_vm_system_aperture_settings(hubp, &apt);
1308 hubp->funcs->hubp_set_vm_context0_settings(hubp, &vm0);
1311 static void dcn10_enable_plane(
1313 struct pipe_ctx *pipe_ctx,
1314 struct dc_state *context)
1316 struct dce_hwseq *hws = dc->hwseq;
1318 if (dc->debug.sanity_checks) {
1319 dcn10_verify_allow_pstate_change_high(dc);
1322 undo_DEGVIDCN10_253_wa(dc);
1324 power_on_plane(dc->hwseq,
1325 pipe_ctx->plane_res.hubp->inst);
1327 /* enable DCFCLK current DCHUB */
1328 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true);
1330 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1331 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
1332 pipe_ctx->stream_res.opp,
1335 /* TODO: enable/disable in dm as per update type.
1337 DC_LOG_DC(dc->ctx->logger,
1338 "Pipe:%d 0x%x: addr hi:0x%x, "
1341 " %d; dst: %d, %d, %d, %d;\n",
1344 plane_state->address.grph.addr.high_part,
1345 plane_state->address.grph.addr.low_part,
1346 plane_state->src_rect.x,
1347 plane_state->src_rect.y,
1348 plane_state->src_rect.width,
1349 plane_state->src_rect.height,
1350 plane_state->dst_rect.x,
1351 plane_state->dst_rect.y,
1352 plane_state->dst_rect.width,
1353 plane_state->dst_rect.height);
1355 DC_LOG_DC(dc->ctx->logger,
1356 "Pipe %d: width, height, x, y format:%d\n"
1357 "viewport:%d, %d, %d, %d\n"
1358 "recout: %d, %d, %d, %d\n",
1360 plane_state->format,
1361 pipe_ctx->plane_res.scl_data.viewport.width,
1362 pipe_ctx->plane_res.scl_data.viewport.height,
1363 pipe_ctx->plane_res.scl_data.viewport.x,
1364 pipe_ctx->plane_res.scl_data.viewport.y,
1365 pipe_ctx->plane_res.scl_data.recout.width,
1366 pipe_ctx->plane_res.scl_data.recout.height,
1367 pipe_ctx->plane_res.scl_data.recout.x,
1368 pipe_ctx->plane_res.scl_data.recout.y);
1369 print_rq_dlg_ttu(dc, pipe_ctx);
1372 if (dc->config.gpu_vm_support)
1373 dcn10_program_pte_vm(hws, pipe_ctx->plane_res.hubp);
1375 if (dc->debug.sanity_checks) {
1376 dcn10_verify_allow_pstate_change_high(dc);
1380 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
1383 struct dpp_grph_csc_adjustment adjust;
1384 memset(&adjust, 0, sizeof(adjust));
1385 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
1388 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
1389 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
1390 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
1391 adjust.temperature_matrix[i] =
1392 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
1395 pipe_ctx->plane_res.dpp->funcs->dpp_set_gamut_remap(pipe_ctx->plane_res.dpp, &adjust);
1399 static void program_csc_matrix(struct pipe_ctx *pipe_ctx,
1400 enum dc_color_space colorspace,
1403 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1404 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1405 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment(pipe_ctx->plane_res.dpp, matrix);
1407 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default != NULL)
1408 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default(pipe_ctx->plane_res.dpp, colorspace);
1412 static void program_output_csc(struct dc *dc,
1413 struct pipe_ctx *pipe_ctx,
1414 enum dc_color_space colorspace,
1418 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1419 program_csc_matrix(pipe_ctx,
1424 static bool is_lower_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1426 if (pipe_ctx->plane_state->visible)
1428 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1433 static bool is_upper_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1435 if (pipe_ctx->plane_state->visible)
1437 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1442 static bool is_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1444 if (pipe_ctx->plane_state->visible)
1446 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1448 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1453 bool is_rgb_cspace(enum dc_color_space output_color_space)
1455 switch (output_color_space) {
1456 case COLOR_SPACE_SRGB:
1457 case COLOR_SPACE_SRGB_LIMITED:
1458 case COLOR_SPACE_2020_RGB_FULLRANGE:
1459 case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
1460 case COLOR_SPACE_ADOBERGB:
1462 case COLOR_SPACE_YCBCR601:
1463 case COLOR_SPACE_YCBCR709:
1464 case COLOR_SPACE_YCBCR601_LIMITED:
1465 case COLOR_SPACE_YCBCR709_LIMITED:
1466 case COLOR_SPACE_2020_YCBCR:
1469 /* Add a case to switch */
1470 BREAK_TO_DEBUGGER();
1475 static void dcn10_get_surface_visual_confirm_color(
1476 const struct pipe_ctx *pipe_ctx,
1477 struct tg_color *color)
1479 uint32_t color_value = MAX_TG_COLOR_VALUE;
1481 switch (pipe_ctx->plane_res.scl_data.format) {
1482 case PIXEL_FORMAT_ARGB8888:
1483 /* set boarder color to red */
1484 color->color_r_cr = color_value;
1487 case PIXEL_FORMAT_ARGB2101010:
1488 /* set boarder color to blue */
1489 color->color_b_cb = color_value;
1491 case PIXEL_FORMAT_420BPP8:
1492 /* set boarder color to green */
1493 color->color_g_y = color_value;
1495 case PIXEL_FORMAT_420BPP10:
1496 /* set boarder color to yellow */
1497 color->color_g_y = color_value;
1498 color->color_r_cr = color_value;
1500 case PIXEL_FORMAT_FP16:
1501 /* set boarder color to white */
1502 color->color_r_cr = color_value;
1503 color->color_b_cb = color_value;
1504 color->color_g_y = color_value;
1511 static uint16_t fixed_point_to_int_frac(
1512 struct fixed31_32 arg,
1513 uint8_t integer_bits,
1514 uint8_t fractional_bits)
1517 int32_t divisor = 1 << fractional_bits;
1521 uint16_t d = (uint16_t)dal_fixed31_32_floor(
1525 if (d <= (uint16_t)(1 << integer_bits) - (1 / (uint16_t)divisor))
1526 numerator = (uint16_t)dal_fixed31_32_floor(
1527 dal_fixed31_32_mul_int(
1531 numerator = dal_fixed31_32_floor(
1533 dal_fixed31_32_from_int(
1534 1LL << integer_bits),
1535 dal_fixed31_32_recip(
1536 dal_fixed31_32_from_int(
1541 result = (uint16_t)numerator;
1543 result = (uint16_t)(
1544 (1 << (integer_bits + fractional_bits + 1)) + numerator);
1546 if ((result != 0) && dal_fixed31_32_lt(
1547 arg, dal_fixed31_32_zero))
1548 result |= 1 << (integer_bits + fractional_bits);
1553 void build_prescale_params(struct dc_bias_and_scale *bias_and_scale,
1554 const struct dc_plane_state *plane_state)
1556 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1557 && plane_state->format != SURFACE_PIXEL_FORMAT_INVALID
1558 && plane_state->input_csc_color_matrix.enable_adjustment
1559 && plane_state->coeff_reduction_factor.value != 0) {
1560 bias_and_scale->scale_blue = fixed_point_to_int_frac(
1561 dal_fixed31_32_mul(plane_state->coeff_reduction_factor,
1562 dal_fixed31_32_from_fraction(256, 255)),
1565 bias_and_scale->scale_red = bias_and_scale->scale_blue;
1566 bias_and_scale->scale_green = bias_and_scale->scale_blue;
1568 bias_and_scale->scale_blue = 0x2000;
1569 bias_and_scale->scale_red = 0x2000;
1570 bias_and_scale->scale_green = 0x2000;
1574 static void update_dpp(struct dpp *dpp, struct dc_plane_state *plane_state)
1576 struct dc_bias_and_scale bns_params = {0};
1578 // program the input csc
1579 dpp->funcs->dpp_setup(dpp,
1580 plane_state->format,
1581 EXPANSION_MODE_ZERO,
1582 plane_state->input_csc_color_matrix,
1583 COLOR_SPACE_YCBCR601_LIMITED);
1585 //set scale and bias registers
1586 build_prescale_params(&bns_params, plane_state);
1587 if (dpp->funcs->dpp_program_bias_and_scale)
1588 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1592 static void update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
1594 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1595 struct mpcc_blnd_cfg blnd_cfg;
1596 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1598 struct mpcc *new_mpcc;
1599 struct mpc *mpc = dc->res_pool->mpc;
1600 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
1602 /* TODO: proper fix once fpga works */
1604 if (dc->debug.surface_visual_confirm)
1605 dcn10_get_surface_visual_confirm_color(
1606 pipe_ctx, &blnd_cfg.black_color);
1608 color_space_to_black_color(
1609 dc, pipe_ctx->stream->output_color_space,
1610 &blnd_cfg.black_color);
1612 if (per_pixel_alpha)
1613 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
1615 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
1617 blnd_cfg.overlap_only = false;
1618 blnd_cfg.global_alpha = 0xff;
1619 blnd_cfg.global_gain = 0xff;
1621 /* DCN1.0 has output CM before MPC which seems to screw with
1622 * pre-multiplied alpha.
1624 blnd_cfg.pre_multiplied_alpha = is_rgb_cspace(
1625 pipe_ctx->stream->output_color_space)
1630 * Note: currently there is a bug in init_hw such that
1631 * on resume from hibernate, BIOS sets up MPCC0, and
1632 * we do mpcc_remove but the mpcc cannot go to idle
1633 * after remove. This cause us to pick mpcc1 here,
1634 * which causes a pstate hang for yet unknown reason.
1636 mpcc_id = hubp->inst;
1638 /* check if this MPCC is already being used */
1639 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
1640 /* remove MPCC if being used */
1641 if (new_mpcc != NULL)
1642 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
1644 if (dc->debug.sanity_checks)
1645 mpc->funcs->assert_mpcc_idle_before_connect(
1646 dc->res_pool->mpc, mpcc_id);
1648 /* Call MPC to insert new plane */
1649 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
1657 ASSERT(new_mpcc != NULL);
1659 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
1660 hubp->mpcc_id = mpcc_id;
1663 static void update_scaler(struct pipe_ctx *pipe_ctx)
1665 bool per_pixel_alpha =
1666 pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1668 /* TODO: proper fix once fpga works */
1670 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = per_pixel_alpha;
1671 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1672 /* scaler configuration */
1673 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1674 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
1677 static void update_dchubp_dpp(
1679 struct pipe_ctx *pipe_ctx,
1680 struct dc_state *context)
1682 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1683 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1684 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1685 union plane_size size = plane_state->plane_size;
1687 /* depends on DML calculation, DPP clock value may change dynamically */
1688 if (plane_state->update_flags.bits.full_update) {
1689 dpp->funcs->dpp_dppclk_control(
1691 context->bw.dcn.calc_clk.max_dppclk_khz <
1692 context->bw.dcn.calc_clk.dispclk_khz,
1695 dc->current_state->bw.dcn.cur_clk.max_dppclk_khz =
1696 context->bw.dcn.calc_clk.max_dppclk_khz;
1697 context->bw.dcn.cur_clk.max_dppclk_khz = context->bw.dcn.calc_clk.max_dppclk_khz;
1700 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
1701 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
1702 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
1704 if (plane_state->update_flags.bits.full_update) {
1705 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst);
1707 hubp->funcs->hubp_setup(
1709 &pipe_ctx->dlg_regs,
1710 &pipe_ctx->ttu_regs,
1712 &pipe_ctx->pipe_dlg_param);
1715 size.grph.surface_size = pipe_ctx->plane_res.scl_data.viewport;
1717 if (plane_state->update_flags.bits.full_update ||
1718 plane_state->update_flags.bits.bpp_change)
1719 update_dpp(dpp, plane_state);
1721 if (plane_state->update_flags.bits.full_update ||
1722 plane_state->update_flags.bits.per_pixel_alpha_change)
1723 update_mpcc(dc, pipe_ctx);
1725 if (plane_state->update_flags.bits.full_update ||
1726 plane_state->update_flags.bits.per_pixel_alpha_change ||
1727 plane_state->update_flags.bits.scaling_change ||
1728 plane_state->update_flags.bits.position_change) {
1729 update_scaler(pipe_ctx);
1732 if (plane_state->update_flags.bits.full_update ||
1733 plane_state->update_flags.bits.scaling_change ||
1734 plane_state->update_flags.bits.position_change) {
1735 hubp->funcs->mem_program_viewport(
1737 &pipe_ctx->plane_res.scl_data.viewport,
1738 &pipe_ctx->plane_res.scl_data.viewport_c);
1741 if (pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
1742 dc->hwss.set_cursor_position(pipe_ctx);
1743 dc->hwss.set_cursor_attribute(pipe_ctx);
1746 if (plane_state->update_flags.bits.full_update) {
1748 program_gamut_remap(pipe_ctx);
1750 program_output_csc(dc,
1752 pipe_ctx->stream->output_color_space,
1753 pipe_ctx->stream->csc_color_matrix.matrix,
1757 if (plane_state->update_flags.bits.full_update ||
1758 plane_state->update_flags.bits.pixel_format_change ||
1759 plane_state->update_flags.bits.horizontal_mirror_change ||
1760 plane_state->update_flags.bits.rotation_change ||
1761 plane_state->update_flags.bits.swizzle_change ||
1762 plane_state->update_flags.bits.dcc_change ||
1763 plane_state->update_flags.bits.bpp_change ||
1764 plane_state->update_flags.bits.scaling_change) {
1765 hubp->funcs->hubp_program_surface_config(
1767 plane_state->format,
1768 &plane_state->tiling_info,
1770 plane_state->rotation,
1772 plane_state->horizontal_mirror);
1775 hubp->power_gated = false;
1777 dc->hwss.update_plane_addr(dc, pipe_ctx);
1779 if (is_pipe_tree_visible(pipe_ctx))
1780 hubp->funcs->set_blank(hubp, false);
1784 static void program_all_pipe_in_tree(
1786 struct pipe_ctx *pipe_ctx,
1787 struct dc_state *context)
1790 if (pipe_ctx->top_pipe == NULL) {
1792 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
1793 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
1794 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
1795 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
1796 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
1798 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1799 pipe_ctx->stream_res.tg);
1801 if (pipe_ctx->stream_res.tg->funcs->set_blank)
1802 pipe_ctx->stream_res.tg->funcs->set_blank(
1803 pipe_ctx->stream_res.tg,
1804 !is_pipe_tree_visible(pipe_ctx));
1807 if (pipe_ctx->plane_state != NULL) {
1808 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1809 dcn10_enable_plane(dc, pipe_ctx, context);
1811 update_dchubp_dpp(dc, pipe_ctx, context);
1813 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
1814 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
1815 pipe_ctx->plane_state->update_flags.bits.gamma_change)
1816 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
1818 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
1819 * only do gamma programming for full update.
1820 * TODO: This can be further optimized/cleaned up
1821 * Always call this for now since it does memcmp inside before
1822 * doing heavy calculation and programming
1824 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1825 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
1828 if (pipe_ctx->bottom_pipe != NULL && pipe_ctx->bottom_pipe != pipe_ctx) {
1829 program_all_pipe_in_tree(dc, pipe_ctx->bottom_pipe, context);
1833 static void dcn10_pplib_apply_display_requirements(
1835 struct dc_state *context)
1837 struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
1839 pp_display_cfg->all_displays_in_sync = false;/*todo*/
1840 pp_display_cfg->nb_pstate_switch_disable = false;
1841 pp_display_cfg->min_engine_clock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1842 pp_display_cfg->min_memory_clock_khz = context->bw.dcn.cur_clk.fclk_khz;
1843 pp_display_cfg->min_engine_clock_deep_sleep_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1844 pp_display_cfg->min_dcfc_deep_sleep_clock_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1845 pp_display_cfg->avail_mclk_switch_time_us =
1846 context->bw.dcn.cur_clk.dram_ccm_us > 0 ? context->bw.dcn.cur_clk.dram_ccm_us : 0;
1847 pp_display_cfg->avail_mclk_switch_time_in_disp_active_us =
1848 context->bw.dcn.cur_clk.min_active_dram_ccm_us > 0 ? context->bw.dcn.cur_clk.min_active_dram_ccm_us : 0;
1849 pp_display_cfg->min_dcfclock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1850 pp_display_cfg->disp_clk_khz = context->bw.dcn.cur_clk.dispclk_khz;
1851 dce110_fill_display_configs(context, pp_display_cfg);
1853 if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof(
1854 struct dm_pp_display_configuration)) != 0)
1855 dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
1857 dc->prev_display_config = *pp_display_cfg;
1860 static void optimize_shared_resources(struct dc *dc)
1862 if (dc->current_state->stream_count == 0) {
1864 dcn10_pplib_apply_display_requirements(dc, dc->current_state);
1867 if (dc->debug.pplib_wm_report_mode == WM_REPORT_OVERRIDE)
1868 dcn_bw_notify_pplib_of_wm_ranges(dc);
1871 static void ready_shared_resources(struct dc *dc, struct dc_state *context)
1874 if (dc->current_state->stream_count == 0 &&
1875 context->stream_count != 0)
1876 dcn10_pplib_apply_display_requirements(dc, context);
1879 static struct pipe_ctx *find_top_pipe_for_stream(
1881 struct dc_state *context,
1882 const struct dc_stream_state *stream)
1886 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1887 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1888 struct pipe_ctx *old_pipe_ctx =
1889 &dc->current_state->res_ctx.pipe_ctx[i];
1891 if (!pipe_ctx->plane_state && !old_pipe_ctx->plane_state)
1894 if (pipe_ctx->stream != stream)
1897 if (!pipe_ctx->top_pipe)
1903 static void dcn10_apply_ctx_for_surface(
1905 const struct dc_stream_state *stream,
1907 struct dc_state *context)
1910 struct timing_generator *tg;
1911 struct output_pixel_processor *opp;
1912 bool removed_pipe[4] = { false };
1913 unsigned int ref_clk_mhz = dc->res_pool->ref_clock_inKhz/1000;
1914 bool program_water_mark = false;
1915 struct dc_context *ctx = dc->ctx;
1917 struct pipe_ctx *top_pipe_to_program =
1918 find_top_pipe_for_stream(dc, context, stream);
1920 if (!top_pipe_to_program)
1923 opp = top_pipe_to_program->stream_res.opp;
1925 tg = top_pipe_to_program->stream_res.tg;
1927 dcn10_pipe_control_lock(dc, top_pipe_to_program, true);
1929 if (num_planes == 0) {
1931 /* OTG blank before remove all front end */
1932 if (tg->funcs->set_blank)
1933 tg->funcs->set_blank(tg, true);
1936 /* Disconnect unused mpcc */
1937 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1938 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1939 struct pipe_ctx *old_pipe_ctx =
1940 &dc->current_state->res_ctx.pipe_ctx[i];
1942 * Powergate reused pipes that are not powergated
1943 * fairly hacky right now, using opp_id as indicator
1944 * TODO: After move dc_post to dc_update, this will
1947 if (pipe_ctx->plane_state && !old_pipe_ctx->plane_state) {
1948 if (old_pipe_ctx->stream_res.tg == tg &&
1949 old_pipe_ctx->plane_res.hubp &&
1950 old_pipe_ctx->plane_res.hubp->opp_id != 0xf) {
1951 dcn10_disable_plane(dc, old_pipe_ctx);
1953 * power down fe will unlock when calling reset, need
1954 * to lock it back here. Messy, need rework.
1956 pipe_ctx->stream_res.tg->funcs->lock(pipe_ctx->stream_res.tg);
1960 if (!pipe_ctx->plane_state &&
1961 old_pipe_ctx->plane_state &&
1962 old_pipe_ctx->stream_res.tg == tg) {
1964 plane_atomic_disconnect(dc, old_pipe_ctx);
1965 removed_pipe[i] = true;
1968 "Reset mpcc for pipe %d\n",
1969 old_pipe_ctx->pipe_idx);
1974 program_all_pipe_in_tree(dc, top_pipe_to_program, context);
1976 dcn10_pipe_control_lock(dc, top_pipe_to_program, false);
1978 if (num_planes == 0)
1979 false_optc_underflow_wa(dc, stream, tg);
1981 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1982 struct pipe_ctx *old_pipe_ctx =
1983 &dc->current_state->res_ctx.pipe_ctx[i];
1984 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1986 if (pipe_ctx->stream == stream &&
1987 pipe_ctx->plane_state &&
1988 pipe_ctx->plane_state->update_flags.bits.full_update)
1989 program_water_mark = true;
1991 if (removed_pipe[i])
1992 dcn10_disable_plane(dc, old_pipe_ctx);
1995 if (program_water_mark) {
1996 if (dc->debug.sanity_checks) {
1997 /* pstate stuck check after watermark update */
1998 dcn10_verify_allow_pstate_change_high(dc);
2001 /* watermark is for all pipes */
2002 hubbub1_program_watermarks(dc->res_pool->hubbub,
2003 &context->bw.dcn.watermarks, ref_clk_mhz);
2005 if (dc->debug.sanity_checks) {
2006 /* pstate stuck check after watermark update */
2007 dcn10_verify_allow_pstate_change_high(dc);
2010 /* DC_LOG_BANDWIDTH_CALCS(dc->ctx->logger,
2011 "\n============== Watermark parameters ==============\n"
2012 "a.urgent_ns: %d \n"
2013 "a.cstate_enter_plus_exit: %d \n"
2014 "a.cstate_exit: %d \n"
2015 "a.pstate_change: %d \n"
2016 "a.pte_meta_urgent: %d \n"
2017 "b.urgent_ns: %d \n"
2018 "b.cstate_enter_plus_exit: %d \n"
2019 "b.cstate_exit: %d \n"
2020 "b.pstate_change: %d \n"
2021 "b.pte_meta_urgent: %d \n",
2022 context->bw.dcn.watermarks.a.urgent_ns,
2023 context->bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns,
2024 context->bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns,
2025 context->bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns,
2026 context->bw.dcn.watermarks.a.pte_meta_urgent_ns,
2027 context->bw.dcn.watermarks.b.urgent_ns,
2028 context->bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns,
2029 context->bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns,
2030 context->bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns,
2031 context->bw.dcn.watermarks.b.pte_meta_urgent_ns
2033 DC_LOG_BANDWIDTH_CALCS(dc->ctx->logger,
2034 "\nc.urgent_ns: %d \n"
2035 "c.cstate_enter_plus_exit: %d \n"
2036 "c.cstate_exit: %d \n"
2037 "c.pstate_change: %d \n"
2038 "c.pte_meta_urgent: %d \n"
2039 "d.urgent_ns: %d \n"
2040 "d.cstate_enter_plus_exit: %d \n"
2041 "d.cstate_exit: %d \n"
2042 "d.pstate_change: %d \n"
2043 "d.pte_meta_urgent: %d \n"
2044 "========================================================\n",
2045 context->bw.dcn.watermarks.c.urgent_ns,
2046 context->bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns,
2047 context->bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns,
2048 context->bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns,
2049 context->bw.dcn.watermarks.c.pte_meta_urgent_ns,
2050 context->bw.dcn.watermarks.d.urgent_ns,
2051 context->bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns,
2052 context->bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns,
2053 context->bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns,
2054 context->bw.dcn.watermarks.d.pte_meta_urgent_ns
2059 static void dcn10_set_bandwidth(
2061 struct dc_state *context,
2062 bool decrease_allowed)
2064 struct pp_smu_display_requirement_rv *smu_req_cur =
2065 &dc->res_pool->pp_smu_req;
2066 struct pp_smu_display_requirement_rv smu_req = *smu_req_cur;
2067 struct pp_smu_funcs_rv *pp_smu = dc->res_pool->pp_smu;
2069 if (dc->debug.sanity_checks) {
2070 dcn10_verify_allow_pstate_change_high(dc);
2073 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
2076 if (decrease_allowed || context->bw.dcn.calc_clk.dispclk_khz
2077 > dc->current_state->bw.dcn.cur_clk.dispclk_khz) {
2078 dc->res_pool->display_clock->funcs->set_clock(
2079 dc->res_pool->display_clock,
2080 context->bw.dcn.calc_clk.dispclk_khz);
2081 context->bw.dcn.cur_clk.dispclk_khz =
2082 context->bw.dcn.calc_clk.dispclk_khz;
2084 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_khz
2085 > dc->current_state->bw.dcn.cur_clk.dcfclk_khz) {
2086 context->bw.dcn.cur_clk.dcfclk_khz =
2087 context->bw.dcn.calc_clk.dcfclk_khz;
2088 smu_req.hard_min_dcefclk_khz =
2089 context->bw.dcn.calc_clk.dcfclk_khz;
2091 if (decrease_allowed || context->bw.dcn.calc_clk.fclk_khz
2092 > dc->current_state->bw.dcn.cur_clk.fclk_khz) {
2093 context->bw.dcn.cur_clk.fclk_khz =
2094 context->bw.dcn.calc_clk.fclk_khz;
2095 smu_req.hard_min_fclk_khz = context->bw.dcn.calc_clk.fclk_khz;
2097 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz
2098 > dc->current_state->bw.dcn.cur_clk.dcfclk_deep_sleep_khz) {
2099 context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz =
2100 context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz;
2103 smu_req.display_count = context->stream_count;
2105 if (pp_smu->set_display_requirement)
2106 pp_smu->set_display_requirement(&pp_smu->pp_smu, &smu_req);
2108 *smu_req_cur = smu_req;
2110 /* Decrease in freq is increase in period so opposite comparison for dram_ccm */
2111 if (decrease_allowed || context->bw.dcn.calc_clk.dram_ccm_us
2112 < dc->current_state->bw.dcn.cur_clk.dram_ccm_us) {
2113 context->bw.dcn.cur_clk.dram_ccm_us =
2114 context->bw.dcn.calc_clk.dram_ccm_us;
2116 if (decrease_allowed || context->bw.dcn.calc_clk.min_active_dram_ccm_us
2117 < dc->current_state->bw.dcn.cur_clk.min_active_dram_ccm_us) {
2118 context->bw.dcn.cur_clk.min_active_dram_ccm_us =
2119 context->bw.dcn.calc_clk.min_active_dram_ccm_us;
2121 dcn10_pplib_apply_display_requirements(dc, context);
2123 if (dc->debug.sanity_checks) {
2124 dcn10_verify_allow_pstate_change_high(dc);
2127 /* need to fix this function. not doing the right thing here */
2130 static void set_drr(struct pipe_ctx **pipe_ctx,
2131 int num_pipes, int vmin, int vmax)
2134 struct drr_params params = {0};
2136 params.vertical_total_max = vmax;
2137 params.vertical_total_min = vmin;
2139 /* TODO: If multiple pipes are to be supported, you need
2142 for (i = 0; i < num_pipes; i++) {
2143 pipe_ctx[i]->stream_res.tg->funcs->set_drr(pipe_ctx[i]->stream_res.tg, ¶ms);
2147 static void get_position(struct pipe_ctx **pipe_ctx,
2149 struct crtc_position *position)
2153 /* TODO: handle pipes > 1
2155 for (i = 0; i < num_pipes; i++)
2156 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2159 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2160 int num_pipes, const struct dc_static_screen_events *events)
2163 unsigned int value = 0;
2165 if (events->surface_update)
2167 if (events->cursor_update)
2169 if (events->force_trigger)
2172 for (i = 0; i < num_pipes; i++)
2173 pipe_ctx[i]->stream_res.tg->funcs->
2174 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
2177 static void set_plane_config(
2178 const struct dc *dc,
2179 struct pipe_ctx *pipe_ctx,
2180 struct resource_context *res_ctx)
2183 program_gamut_remap(pipe_ctx);
2186 static void dcn10_config_stereo_parameters(
2187 struct dc_stream_state *stream, struct crtc_stereo_flags *flags)
2189 enum view_3d_format view_format = stream->view_format;
2190 enum dc_timing_3d_format timing_3d_format =\
2191 stream->timing.timing_3d_format;
2192 bool non_stereo_timing = false;
2194 if (timing_3d_format == TIMING_3D_FORMAT_NONE ||
2195 timing_3d_format == TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2196 timing_3d_format == TIMING_3D_FORMAT_TOP_AND_BOTTOM)
2197 non_stereo_timing = true;
2199 if (non_stereo_timing == false &&
2200 view_format == VIEW_3D_FORMAT_FRAME_SEQUENTIAL) {
2202 flags->PROGRAM_STEREO = 1;
2203 flags->PROGRAM_POLARITY = 1;
2204 if (timing_3d_format == TIMING_3D_FORMAT_INBAND_FA ||
2205 timing_3d_format == TIMING_3D_FORMAT_DP_HDMI_INBAND_FA ||
2206 timing_3d_format == TIMING_3D_FORMAT_SIDEBAND_FA) {
2207 enum display_dongle_type dongle = \
2208 stream->sink->link->ddc->dongle_type;
2209 if (dongle == DISPLAY_DONGLE_DP_VGA_CONVERTER ||
2210 dongle == DISPLAY_DONGLE_DP_DVI_CONVERTER ||
2211 dongle == DISPLAY_DONGLE_DP_HDMI_CONVERTER)
2212 flags->DISABLE_STEREO_DP_SYNC = 1;
2214 flags->RIGHT_EYE_POLARITY =\
2215 stream->timing.flags.RIGHT_EYE_3D_POLARITY;
2216 if (timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2217 flags->FRAME_PACKED = 1;
2223 static void dcn10_setup_stereo(struct pipe_ctx *pipe_ctx, struct dc *dc)
2225 struct crtc_stereo_flags flags = { 0 };
2226 struct dc_stream_state *stream = pipe_ctx->stream;
2228 dcn10_config_stereo_parameters(stream, &flags);
2230 pipe_ctx->stream_res.opp->funcs->opp_program_stereo(
2231 pipe_ctx->stream_res.opp,
2232 flags.PROGRAM_STEREO == 1 ? true:false,
2235 pipe_ctx->stream_res.tg->funcs->program_stereo(
2236 pipe_ctx->stream_res.tg,
2243 static struct hubp *get_hubp_by_inst(struct resource_pool *res_pool, int mpcc_inst)
2247 for (i = 0; i < res_pool->pipe_count; i++) {
2248 if (res_pool->hubps[i]->inst == mpcc_inst)
2249 return res_pool->hubps[i];
2255 static void dcn10_wait_for_mpcc_disconnect(
2257 struct resource_pool *res_pool,
2258 struct pipe_ctx *pipe_ctx)
2262 if (dc->debug.sanity_checks) {
2263 dcn10_verify_allow_pstate_change_high(dc);
2266 if (!pipe_ctx->stream_res.opp)
2269 for (mpcc_inst = 0; mpcc_inst < MAX_PIPES; mpcc_inst++) {
2270 if (pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst]) {
2271 struct hubp *hubp = get_hubp_by_inst(res_pool, mpcc_inst);
2273 res_pool->mpc->funcs->wait_for_idle(res_pool->mpc, mpcc_inst);
2274 pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst] = false;
2275 hubp->funcs->set_blank(hubp, true);
2276 /*DC_LOG_ERROR(dc->ctx->logger,
2277 "[debug_mpo: wait_for_mpcc finished waiting on mpcc %d]\n",
2282 if (dc->debug.sanity_checks) {
2283 dcn10_verify_allow_pstate_change_high(dc);
2288 static bool dcn10_dummy_display_power_gating(
2290 uint8_t controller_id,
2291 struct dc_bios *dcb,
2292 enum pipe_gating_control power_gating)
2297 static void dcn10_update_pending_status(struct pipe_ctx *pipe_ctx)
2299 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2300 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2302 if (plane_state == NULL)
2305 plane_state->status.is_flip_pending =
2306 pipe_ctx->plane_res.hubp->funcs->hubp_is_flip_pending(
2307 pipe_ctx->plane_res.hubp);
2309 plane_state->status.current_address = pipe_ctx->plane_res.hubp->current_address;
2310 if (pipe_ctx->plane_res.hubp->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2311 tg->funcs->is_stereo_left_eye) {
2312 plane_state->status.is_right_eye =
2313 !tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2317 static void dcn10_update_dchub(struct dce_hwseq *hws, struct dchub_init_data *dh_data)
2319 if (hws->ctx->dc->res_pool->hubbub != NULL)
2320 hubbub1_update_dchub(hws->ctx->dc->res_pool->hubbub, dh_data);
2323 static void dcn10_set_cursor_position(struct pipe_ctx *pipe_ctx)
2325 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2326 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2327 struct dpp *dpp = pipe_ctx->plane_res.dpp;
2328 struct dc_cursor_mi_param param = {
2329 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_khz,
2330 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clock_inKhz,
2331 .viewport_x_start = pipe_ctx->plane_res.scl_data.viewport.x,
2332 .viewport_width = pipe_ctx->plane_res.scl_data.viewport.width,
2333 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz
2336 if (pipe_ctx->plane_state->address.type
2337 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2338 pos_cpy.enable = false;
2340 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2341 pos_cpy.enable = false;
2343 hubp->funcs->set_cursor_position(hubp, &pos_cpy, ¶m);
2344 dpp->funcs->set_cursor_position(dpp, &pos_cpy, ¶m, hubp->curs_attr.width);
2347 static void dcn10_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2349 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2351 pipe_ctx->plane_res.hubp->funcs->set_cursor_attributes(
2352 pipe_ctx->plane_res.hubp, attributes);
2353 pipe_ctx->plane_res.dpp->funcs->set_cursor_attributes(
2354 pipe_ctx->plane_res.dpp, attributes->color_format);
2357 static const struct hw_sequencer_funcs dcn10_funcs = {
2358 .program_gamut_remap = program_gamut_remap,
2359 .program_csc_matrix = program_csc_matrix,
2360 .init_hw = dcn10_init_hw,
2361 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2362 .apply_ctx_for_surface = dcn10_apply_ctx_for_surface,
2363 .set_plane_config = set_plane_config,
2364 .update_plane_addr = dcn10_update_plane_addr,
2365 .update_dchub = dcn10_update_dchub,
2366 .update_pending_status = dcn10_update_pending_status,
2367 .set_input_transfer_func = dcn10_set_input_transfer_func,
2368 .set_output_transfer_func = dcn10_set_output_transfer_func,
2369 .power_down = dce110_power_down,
2370 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2371 .enable_timing_synchronization = dcn10_enable_timing_synchronization,
2372 .enable_per_frame_crtc_position_reset = dcn10_enable_per_frame_crtc_position_reset,
2373 .update_info_frame = dce110_update_info_frame,
2374 .enable_stream = dce110_enable_stream,
2375 .disable_stream = dce110_disable_stream,
2376 .unblank_stream = dce110_unblank_stream,
2377 .blank_stream = dce110_blank_stream,
2378 .enable_display_power_gating = dcn10_dummy_display_power_gating,
2379 .disable_plane = dcn10_disable_plane,
2380 .pipe_control_lock = dcn10_pipe_control_lock,
2381 .set_bandwidth = dcn10_set_bandwidth,
2382 .reset_hw_ctx_wrap = reset_hw_ctx_wrap,
2383 .prog_pixclk_crtc_otg = dcn10_prog_pixclk_crtc_otg,
2385 .get_position = get_position,
2386 .set_static_screen_control = set_static_screen_control,
2387 .setup_stereo = dcn10_setup_stereo,
2388 .set_avmute = dce110_set_avmute,
2389 .log_hw_state = dcn10_log_hw_state,
2390 .wait_for_mpcc_disconnect = dcn10_wait_for_mpcc_disconnect,
2391 .ready_shared_resources = ready_shared_resources,
2392 .optimize_shared_resources = optimize_shared_resources,
2393 .pplib_apply_display_requirements =
2394 dcn10_pplib_apply_display_requirements,
2395 .edp_backlight_control = hwss_edp_backlight_control,
2396 .edp_power_control = hwss_edp_power_control,
2397 .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready,
2398 .set_cursor_position = dcn10_set_cursor_position,
2399 .set_cursor_attribute = dcn10_set_cursor_attribute
2403 void dcn10_hw_sequencer_construct(struct dc *dc)
2405 dc->hwss = dcn10_funcs;