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);
228 /* HW Engineer's Notes:
229 * During switch from vga->extended, if we set the VGA_TEST_ENABLE and
230 * then hit the VGA_TEST_RENDER_START, then the DCHUBP timing gets updated correctly.
232 * Then vBIOS will have it poll for the VGA_TEST_RENDER_DONE and unset
233 * VGA_TEST_ENABLE, to leave it in the same state as before.
235 REG_UPDATE(VGA_TEST_CONTROL, VGA_TEST_ENABLE, 1);
236 REG_UPDATE(VGA_TEST_CONTROL, VGA_TEST_RENDER_START, 1);
239 static void dpp_pg_control(
240 struct dce_hwseq *hws,
241 unsigned int dpp_inst,
244 uint32_t power_gate = power_on ? 0 : 1;
245 uint32_t pwr_status = power_on ? 0 : 2;
247 if (hws->ctx->dc->debug.disable_dpp_power_gate)
252 REG_UPDATE(DOMAIN1_PG_CONFIG,
253 DOMAIN1_POWER_GATE, power_gate);
255 REG_WAIT(DOMAIN1_PG_STATUS,
256 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
260 REG_UPDATE(DOMAIN3_PG_CONFIG,
261 DOMAIN3_POWER_GATE, power_gate);
263 REG_WAIT(DOMAIN3_PG_STATUS,
264 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
268 REG_UPDATE(DOMAIN5_PG_CONFIG,
269 DOMAIN5_POWER_GATE, power_gate);
271 REG_WAIT(DOMAIN5_PG_STATUS,
272 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
276 REG_UPDATE(DOMAIN7_PG_CONFIG,
277 DOMAIN7_POWER_GATE, power_gate);
279 REG_WAIT(DOMAIN7_PG_STATUS,
280 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
289 static void hubp_pg_control(
290 struct dce_hwseq *hws,
291 unsigned int hubp_inst,
294 uint32_t power_gate = power_on ? 0 : 1;
295 uint32_t pwr_status = power_on ? 0 : 2;
297 if (hws->ctx->dc->debug.disable_hubp_power_gate)
301 case 0: /* DCHUBP0 */
302 REG_UPDATE(DOMAIN0_PG_CONFIG,
303 DOMAIN0_POWER_GATE, power_gate);
305 REG_WAIT(DOMAIN0_PG_STATUS,
306 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
309 case 1: /* DCHUBP1 */
310 REG_UPDATE(DOMAIN2_PG_CONFIG,
311 DOMAIN2_POWER_GATE, power_gate);
313 REG_WAIT(DOMAIN2_PG_STATUS,
314 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
317 case 2: /* DCHUBP2 */
318 REG_UPDATE(DOMAIN4_PG_CONFIG,
319 DOMAIN4_POWER_GATE, power_gate);
321 REG_WAIT(DOMAIN4_PG_STATUS,
322 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
325 case 3: /* DCHUBP3 */
326 REG_UPDATE(DOMAIN6_PG_CONFIG,
327 DOMAIN6_POWER_GATE, power_gate);
329 REG_WAIT(DOMAIN6_PG_STATUS,
330 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
339 static void power_on_plane(
340 struct dce_hwseq *hws,
343 struct dc_context *ctx = hws->ctx;
344 if (REG(DC_IP_REQUEST_CNTL)) {
345 REG_SET(DC_IP_REQUEST_CNTL, 0,
347 dpp_pg_control(hws, plane_id, true);
348 hubp_pg_control(hws, plane_id, true);
349 REG_SET(DC_IP_REQUEST_CNTL, 0,
352 "Un-gated front end for pipe %d\n", plane_id);
356 static void undo_DEGVIDCN10_253_wa(struct dc *dc)
358 struct dce_hwseq *hws = dc->hwseq;
359 struct hubp *hubp = dc->res_pool->hubps[0];
361 if (!hws->wa_state.DEGVIDCN10_253_applied)
364 hubp->funcs->set_blank(hubp, true);
366 REG_SET(DC_IP_REQUEST_CNTL, 0,
369 hubp_pg_control(hws, 0, false);
370 REG_SET(DC_IP_REQUEST_CNTL, 0,
373 hws->wa_state.DEGVIDCN10_253_applied = false;
376 static void apply_DEGVIDCN10_253_wa(struct dc *dc)
378 struct dce_hwseq *hws = dc->hwseq;
379 struct hubp *hubp = dc->res_pool->hubps[0];
382 if (dc->debug.disable_stutter)
385 if (!hws->wa.DEGVIDCN10_253)
388 for (i = 0; i < dc->res_pool->pipe_count; i++) {
389 if (!dc->res_pool->hubps[i]->power_gated)
393 /* all pipe power gated, apply work around to enable stutter. */
395 REG_SET(DC_IP_REQUEST_CNTL, 0,
398 hubp_pg_control(hws, 0, true);
399 REG_SET(DC_IP_REQUEST_CNTL, 0,
402 hubp->funcs->set_hubp_blank_en(hubp, false);
403 hws->wa_state.DEGVIDCN10_253_applied = true;
406 static void bios_golden_init(struct dc *dc)
408 struct dc_bios *bp = dc->ctx->dc_bios;
411 /* initialize dcn global */
412 bp->funcs->enable_disp_power_gating(bp,
413 CONTROLLER_ID_D0, ASIC_PIPE_INIT);
415 for (i = 0; i < dc->res_pool->pipe_count; i++) {
416 /* initialize dcn per pipe */
417 bp->funcs->enable_disp_power_gating(bp,
418 CONTROLLER_ID_D0 + i, ASIC_PIPE_DISABLE);
422 static void false_optc_underflow_wa(
424 const struct dc_stream_state *stream,
425 struct timing_generator *tg)
430 if (!dc->hwseq->wa.false_optc_underflow)
433 underflow = tg->funcs->is_optc_underflow_occurred(tg);
435 for (i = 0; i < dc->res_pool->pipe_count; i++) {
436 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
438 if (old_pipe_ctx->stream != stream)
441 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, old_pipe_ctx);
444 tg->funcs->set_blank_data_double_buffer(tg, true);
446 if (tg->funcs->is_optc_underflow_occurred(tg) && !underflow)
447 tg->funcs->clear_optc_underflow(tg);
450 static enum dc_status dcn10_prog_pixclk_crtc_otg(
451 struct pipe_ctx *pipe_ctx,
452 struct dc_state *context,
455 struct dc_stream_state *stream = pipe_ctx->stream;
456 enum dc_color_space color_space;
457 struct tg_color black_color = {0};
459 /* by upper caller loop, pipe0 is parent pipe and be called first.
460 * back end is set up by for pipe0. Other children pipe share back end
461 * with pipe 0. No program is needed.
463 if (pipe_ctx->top_pipe != NULL)
466 /* TODO check if timing_changed, disable stream if timing changed */
468 /* HW program guide assume display already disable
469 * by unplug sequence. OTG assume stop.
471 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
473 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
474 pipe_ctx->clock_source,
475 &pipe_ctx->stream_res.pix_clk_params,
476 &pipe_ctx->pll_settings)) {
478 return DC_ERROR_UNEXPECTED;
480 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
481 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
482 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
483 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
485 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
487 pipe_ctx->stream_res.tg->funcs->program_timing(
488 pipe_ctx->stream_res.tg,
492 #if 0 /* move to after enable_crtc */
493 /* TODO: OPP FMT, ABM. etc. should be done here. */
494 /* or FPGA now. instance 0 only. TODO: move to opp.c */
496 inst_offset = reg_offsets[pipe_ctx->stream_res.tg->inst].fmt;
498 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
499 pipe_ctx->stream_res.opp,
500 &stream->bit_depth_params,
503 /* program otg blank color */
504 color_space = stream->output_color_space;
505 color_space_to_black_color(dc, color_space, &black_color);
507 if (pipe_ctx->stream_res.tg->funcs->set_blank_color)
508 pipe_ctx->stream_res.tg->funcs->set_blank_color(
509 pipe_ctx->stream_res.tg,
512 if (pipe_ctx->stream_res.tg->funcs->is_blanked &&
513 !pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg)) {
514 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
515 hwss_wait_for_blank_complete(pipe_ctx->stream_res.tg);
516 false_optc_underflow_wa(dc, pipe_ctx->stream, pipe_ctx->stream_res.tg);
519 /* VTG is within DCHUB command block. DCFCLK is always on */
520 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
522 return DC_ERROR_UNEXPECTED;
525 /* TODO program crtc source select for non-virtual signal*/
526 /* TODO program FMT */
527 /* TODO setup link_enc */
528 /* TODO set stream attributes */
529 /* TODO program audio */
530 /* TODO enable stream if timing changed */
531 /* TODO unblank stream if DP */
536 static void reset_back_end_for_pipe(
538 struct pipe_ctx *pipe_ctx,
539 struct dc_state *context)
542 struct dc_context *ctx = dc->ctx;
543 if (pipe_ctx->stream_res.stream_enc == NULL) {
544 pipe_ctx->stream = NULL;
548 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
549 /* DPMS may already disable */
550 if (!pipe_ctx->stream->dpms_off)
551 core_link_disable_stream(pipe_ctx, FREE_ACQUIRED_RESOURCE);
552 else if (pipe_ctx->stream_res.audio) {
554 * if stream is already disabled outside of commit streams path,
555 * audio disable was skipped. Need to do it here
557 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
559 if (dc->caps.dynamic_audio == true) {
560 /*we have to dynamic arbitrate the audio endpoints*/
561 pipe_ctx->stream_res.audio = NULL;
562 /*we free the resource, need reset is_audio_acquired*/
563 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool, pipe_ctx->stream_res.audio, false);
570 /* by upper caller loop, parent pipe: pipe0, will be reset last.
571 * back end share by all pipes and will be disable only when disable
574 if (pipe_ctx->top_pipe == NULL) {
575 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
577 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
580 for (i = 0; i < dc->res_pool->pipe_count; i++)
581 if (&dc->current_state->res_ctx.pipe_ctx[i] == pipe_ctx)
584 if (i == dc->res_pool->pipe_count)
587 pipe_ctx->stream = NULL;
588 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
589 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
592 static void dcn10_verify_allow_pstate_change_high(struct dc *dc)
594 static bool should_log_hw_state; /* prevent hw state log by default */
596 if (!hubbub1_verify_allow_pstate_change_high(dc->res_pool->hubbub)) {
597 if (should_log_hw_state) {
598 dcn10_log_hw_state(dc);
605 /* trigger HW to start disconnect plane from stream on the next vsync */
606 static void plane_atomic_disconnect(struct dc *dc, struct pipe_ctx *pipe_ctx)
608 struct hubp *hubp = pipe_ctx->plane_res.hubp;
609 int dpp_id = pipe_ctx->plane_res.dpp->inst;
610 struct mpc *mpc = dc->res_pool->mpc;
611 struct mpc_tree *mpc_tree_params;
612 struct mpcc *mpcc_to_remove = NULL;
613 struct output_pixel_processor *opp = pipe_ctx->stream_res.opp;
615 mpc_tree_params = &(opp->mpc_tree_params);
616 mpcc_to_remove = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, dpp_id);
619 if (mpcc_to_remove == NULL)
622 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, mpcc_to_remove);
623 opp->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
625 dc->optimized_required = true;
627 if (hubp->funcs->hubp_disconnect)
628 hubp->funcs->hubp_disconnect(hubp);
630 if (dc->debug.sanity_checks)
631 dcn10_verify_allow_pstate_change_high(dc);
634 static void plane_atomic_power_down(struct dc *dc, struct pipe_ctx *pipe_ctx)
636 struct dce_hwseq *hws = dc->hwseq;
637 struct dpp *dpp = pipe_ctx->plane_res.dpp;
638 struct dc_context *ctx = dc->ctx;
640 if (REG(DC_IP_REQUEST_CNTL)) {
641 REG_SET(DC_IP_REQUEST_CNTL, 0,
643 dpp_pg_control(hws, dpp->inst, false);
644 hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, false);
645 dpp->funcs->dpp_reset(dpp);
646 REG_SET(DC_IP_REQUEST_CNTL, 0,
649 "Power gated front end %d\n", pipe_ctx->pipe_idx);
653 /* disable HW used by plane.
654 * note: cannot disable until disconnect is complete
656 static void plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
658 struct hubp *hubp = pipe_ctx->plane_res.hubp;
659 struct dpp *dpp = pipe_ctx->plane_res.dpp;
660 int opp_id = hubp->opp_id;
662 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
664 hubp->funcs->hubp_clk_cntl(hubp, false);
666 dpp->funcs->dpp_dppclk_control(dpp, false, false);
668 if (opp_id != 0xf && pipe_ctx->stream_res.opp->mpc_tree_params.opp_list == NULL)
669 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
670 pipe_ctx->stream_res.opp,
673 hubp->power_gated = true;
674 dc->optimized_required = false; /* We're powering off, no need to optimize */
676 plane_atomic_power_down(dc, pipe_ctx);
678 pipe_ctx->stream = NULL;
679 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
680 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
681 pipe_ctx->top_pipe = NULL;
682 pipe_ctx->bottom_pipe = NULL;
683 pipe_ctx->plane_state = NULL;
686 static void dcn10_disable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx)
688 struct dc_context *ctx = dc->ctx;
690 if (!pipe_ctx->plane_res.hubp || pipe_ctx->plane_res.hubp->power_gated)
693 plane_atomic_disable(dc, pipe_ctx);
695 apply_DEGVIDCN10_253_wa(dc);
697 DC_LOG_DC("Power down front end %d\n",
701 static void dcn10_init_hw(struct dc *dc)
704 struct abm *abm = dc->res_pool->abm;
705 struct dmcu *dmcu = dc->res_pool->dmcu;
706 struct dce_hwseq *hws = dc->hwseq;
707 struct dc_bios *dcb = dc->ctx->dc_bios;
708 struct dc_state *context = dc->current_state;
710 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
711 REG_WRITE(REFCLK_CNTL, 0);
712 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
713 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
715 if (!dc->debug.disable_clock_gate) {
716 /* enable all DCN clock gating */
717 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
719 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
721 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
724 enable_power_gating_plane(dc->hwseq, true);
727 if (!dcb->funcs->is_accelerated_mode(dcb)) {
728 bios_golden_init(dc);
729 disable_vga(dc->hwseq);
732 for (i = 0; i < dc->link_count; i++) {
733 /* Power up AND update implementation according to the
734 * required signal (which may be different from the
735 * default signal on connector).
737 struct dc_link *link = dc->links[i];
739 if (link->link_enc->connector.id == CONNECTOR_ID_EDP)
740 dc->hwss.edp_power_control(link, true);
742 link->link_enc->funcs->hw_init(link->link_enc);
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))
753 /* Blank controller using driver code instead of
756 for (i = 0; i < dc->res_pool->pipe_count; i++) {
757 struct timing_generator *tg = dc->res_pool->timing_generators[i];
759 if (tg->funcs->is_tg_enabled(tg)) {
760 tg->funcs->set_blank(tg, true);
761 hwss_wait_for_blank_complete(tg);
765 /* Reset all MPCC muxes */
766 dc->res_pool->mpc->funcs->mpc_init(dc->res_pool->mpc);
768 for (i = 0; i < dc->res_pool->pipe_count; i++) {
769 struct timing_generator *tg = dc->res_pool->timing_generators[i];
770 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
771 struct hubp *hubp = dc->res_pool->hubps[i];
772 struct dpp *dpp = dc->res_pool->dpps[i];
774 pipe_ctx->stream_res.tg = tg;
775 pipe_ctx->pipe_idx = i;
777 pipe_ctx->plane_res.hubp = hubp;
778 pipe_ctx->plane_res.dpp = dpp;
779 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
780 hubp->mpcc_id = dpp->inst;
782 hubp->power_gated = false;
784 dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
785 dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
786 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
787 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
789 plane_atomic_disconnect(dc, pipe_ctx);
792 for (i = 0; i < dc->res_pool->pipe_count; i++) {
793 struct timing_generator *tg = dc->res_pool->timing_generators[i];
795 if (tg->funcs->is_tg_enabled(tg))
796 tg->funcs->unlock(tg);
799 for (i = 0; i < dc->res_pool->pipe_count; i++) {
800 struct timing_generator *tg = dc->res_pool->timing_generators[i];
801 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
803 dcn10_disable_plane(dc, pipe_ctx);
805 pipe_ctx->stream_res.tg = NULL;
806 pipe_ctx->plane_res.hubp = NULL;
808 tg->funcs->tg_init(tg);
811 /* end of FPGA. Below if real ASIC */
812 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
815 for (i = 0; i < dc->res_pool->audio_count; i++) {
816 struct audio *audio = dc->res_pool->audios[i];
818 audio->funcs->hw_init(audio);
822 abm->funcs->init_backlight(abm);
823 abm->funcs->abm_init(abm);
827 dmcu->funcs->dmcu_init(dmcu);
829 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
830 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
832 if (!dc->debug.disable_clock_gate) {
833 /* enable all DCN clock gating */
834 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
836 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
838 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
841 enable_power_gating_plane(dc->hwseq, true);
844 static void reset_hw_ctx_wrap(
846 struct dc_state *context)
851 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
852 struct pipe_ctx *pipe_ctx_old =
853 &dc->current_state->res_ctx.pipe_ctx[i];
854 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
856 if (!pipe_ctx_old->stream)
859 if (pipe_ctx_old->top_pipe)
862 if (!pipe_ctx->stream ||
863 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
864 struct clock_source *old_clk = pipe_ctx_old->clock_source;
866 reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
868 old_clk->funcs->cs_power_down(old_clk);
874 static bool patch_address_for_sbs_tb_stereo(
875 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
877 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
878 bool sec_split = pipe_ctx->top_pipe &&
879 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
880 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
881 (pipe_ctx->stream->timing.timing_3d_format ==
882 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
883 pipe_ctx->stream->timing.timing_3d_format ==
884 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
885 *addr = plane_state->address.grph_stereo.left_addr;
886 plane_state->address.grph_stereo.left_addr =
887 plane_state->address.grph_stereo.right_addr;
890 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
891 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
892 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
893 plane_state->address.grph_stereo.right_addr =
894 plane_state->address.grph_stereo.left_addr;
902 static void dcn10_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
904 bool addr_patched = false;
905 PHYSICAL_ADDRESS_LOC addr;
906 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
908 if (plane_state == NULL)
910 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
911 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
912 pipe_ctx->plane_res.hubp,
913 &plane_state->address,
914 plane_state->flip_immediate);
915 plane_state->status.requested_address = plane_state->address;
917 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
920 static bool dcn10_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
921 const struct dc_plane_state *plane_state)
923 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
924 const struct dc_transfer_func *tf = NULL;
927 if (dpp_base == NULL)
930 if (plane_state->in_transfer_func)
931 tf = plane_state->in_transfer_func;
933 if (plane_state->gamma_correction &&
934 plane_state->gamma_correction->is_identity)
935 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
936 else if (plane_state->gamma_correction && dce_use_lut(plane_state->format))
937 dpp_base->funcs->dpp_program_input_lut(dpp_base, plane_state->gamma_correction);
940 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
941 else if (tf->type == TF_TYPE_PREDEFINED) {
943 case TRANSFER_FUNCTION_SRGB:
944 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_sRGB);
946 case TRANSFER_FUNCTION_BT709:
947 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_xvYCC);
949 case TRANSFER_FUNCTION_LINEAR:
950 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
952 case TRANSFER_FUNCTION_PQ:
957 } else if (tf->type == TF_TYPE_BYPASS) {
958 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
960 /*TF_TYPE_DISTRIBUTED_POINTS*/
972 dcn10_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
973 const struct dc_stream_state *stream)
975 struct dpp *dpp = pipe_ctx->plane_res.dpp;
980 dpp->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
982 if (stream->out_transfer_func &&
983 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
984 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB)
985 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_SRGB);
987 /* dcn10_translate_regamma_to_hw_format takes 750us, only do it when full
990 else if (cm_helper_translate_curve_to_hw_format(
991 stream->out_transfer_func,
992 &dpp->regamma_params, false)) {
993 dpp->funcs->dpp_program_regamma_pwl(
995 &dpp->regamma_params, OPP_REGAMMA_USER);
997 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_BYPASS);
1002 static void dcn10_pipe_control_lock(
1004 struct pipe_ctx *pipe,
1007 /* use TG master update lock to lock everything on the TG
1008 * therefore only top pipe need to lock
1013 if (dc->debug.sanity_checks)
1014 dcn10_verify_allow_pstate_change_high(dc);
1017 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1019 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1021 if (dc->debug.sanity_checks)
1022 dcn10_verify_allow_pstate_change_high(dc);
1025 static bool wait_for_reset_trigger_to_occur(
1026 struct dc_context *dc_ctx,
1027 struct timing_generator *tg)
1031 /* To avoid endless loop we wait at most
1032 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
1033 const uint32_t frames_to_wait_on_triggered_reset = 10;
1036 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
1038 if (!tg->funcs->is_counter_moving(tg)) {
1039 DC_ERROR("TG counter is not moving!\n");
1043 if (tg->funcs->did_triggered_reset_occur(tg)) {
1045 /* usually occurs at i=1 */
1046 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
1051 /* Wait for one frame. */
1052 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
1053 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
1057 DC_ERROR("GSL: Timeout on reset trigger!\n");
1062 static void dcn10_enable_timing_synchronization(
1066 struct pipe_ctx *grouped_pipes[])
1068 struct dc_context *dc_ctx = dc->ctx;
1071 DC_SYNC_INFO("Setting up OTG reset trigger\n");
1073 for (i = 1; i < group_size; i++)
1074 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
1075 grouped_pipes[i]->stream_res.tg,
1076 grouped_pipes[0]->stream_res.tg->inst);
1078 DC_SYNC_INFO("Waiting for trigger\n");
1080 /* Need to get only check 1 pipe for having reset as all the others are
1081 * synchronized. Look at last pipe programmed to reset.
1084 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[1]->stream_res.tg);
1085 for (i = 1; i < group_size; i++)
1086 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
1087 grouped_pipes[i]->stream_res.tg);
1089 DC_SYNC_INFO("Sync complete\n");
1092 static void dcn10_enable_per_frame_crtc_position_reset(
1095 struct pipe_ctx *grouped_pipes[])
1097 struct dc_context *dc_ctx = dc->ctx;
1100 DC_SYNC_INFO("Setting up\n");
1101 for (i = 0; i < group_size; i++)
1102 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
1103 grouped_pipes[i]->stream_res.tg,
1104 grouped_pipes[i]->stream->triggered_crtc_reset.event_source->status.primary_otg_inst,
1105 &grouped_pipes[i]->stream->triggered_crtc_reset);
1107 DC_SYNC_INFO("Waiting for trigger\n");
1109 for (i = 0; i < group_size; i++)
1110 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
1112 DC_SYNC_INFO("Multi-display sync is complete\n");
1115 /*static void print_rq_dlg_ttu(
1117 struct pipe_ctx *pipe_ctx)
1119 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1120 "\n============== DML TTU Output parameters [%d] ==============\n"
1121 "qos_level_low_wm: %d, \n"
1122 "qos_level_high_wm: %d, \n"
1123 "min_ttu_vblank: %d, \n"
1124 "qos_level_flip: %d, \n"
1125 "refcyc_per_req_delivery_l: %d, \n"
1126 "qos_level_fixed_l: %d, \n"
1127 "qos_ramp_disable_l: %d, \n"
1128 "refcyc_per_req_delivery_pre_l: %d, \n"
1129 "refcyc_per_req_delivery_c: %d, \n"
1130 "qos_level_fixed_c: %d, \n"
1131 "qos_ramp_disable_c: %d, \n"
1132 "refcyc_per_req_delivery_pre_c: %d\n"
1133 "=============================================================\n",
1135 pipe_ctx->ttu_regs.qos_level_low_wm,
1136 pipe_ctx->ttu_regs.qos_level_high_wm,
1137 pipe_ctx->ttu_regs.min_ttu_vblank,
1138 pipe_ctx->ttu_regs.qos_level_flip,
1139 pipe_ctx->ttu_regs.refcyc_per_req_delivery_l,
1140 pipe_ctx->ttu_regs.qos_level_fixed_l,
1141 pipe_ctx->ttu_regs.qos_ramp_disable_l,
1142 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_l,
1143 pipe_ctx->ttu_regs.refcyc_per_req_delivery_c,
1144 pipe_ctx->ttu_regs.qos_level_fixed_c,
1145 pipe_ctx->ttu_regs.qos_ramp_disable_c,
1146 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_c
1149 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1150 "\n============== DML DLG Output parameters [%d] ==============\n"
1151 "refcyc_h_blank_end: %d, \n"
1152 "dlg_vblank_end: %d, \n"
1153 "min_dst_y_next_start: %d, \n"
1154 "refcyc_per_htotal: %d, \n"
1155 "refcyc_x_after_scaler: %d, \n"
1156 "dst_y_after_scaler: %d, \n"
1157 "dst_y_prefetch: %d, \n"
1158 "dst_y_per_vm_vblank: %d, \n"
1159 "dst_y_per_row_vblank: %d, \n"
1160 "ref_freq_to_pix_freq: %d, \n"
1161 "vratio_prefetch: %d, \n"
1162 "refcyc_per_pte_group_vblank_l: %d, \n"
1163 "refcyc_per_meta_chunk_vblank_l: %d, \n"
1164 "dst_y_per_pte_row_nom_l: %d, \n"
1165 "refcyc_per_pte_group_nom_l: %d, \n",
1167 pipe_ctx->dlg_regs.refcyc_h_blank_end,
1168 pipe_ctx->dlg_regs.dlg_vblank_end,
1169 pipe_ctx->dlg_regs.min_dst_y_next_start,
1170 pipe_ctx->dlg_regs.refcyc_per_htotal,
1171 pipe_ctx->dlg_regs.refcyc_x_after_scaler,
1172 pipe_ctx->dlg_regs.dst_y_after_scaler,
1173 pipe_ctx->dlg_regs.dst_y_prefetch,
1174 pipe_ctx->dlg_regs.dst_y_per_vm_vblank,
1175 pipe_ctx->dlg_regs.dst_y_per_row_vblank,
1176 pipe_ctx->dlg_regs.ref_freq_to_pix_freq,
1177 pipe_ctx->dlg_regs.vratio_prefetch,
1178 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_l,
1179 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_l,
1180 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_l,
1181 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_l
1184 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1185 "\ndst_y_per_meta_row_nom_l: %d, \n"
1186 "refcyc_per_meta_chunk_nom_l: %d, \n"
1187 "refcyc_per_line_delivery_pre_l: %d, \n"
1188 "refcyc_per_line_delivery_l: %d, \n"
1189 "vratio_prefetch_c: %d, \n"
1190 "refcyc_per_pte_group_vblank_c: %d, \n"
1191 "refcyc_per_meta_chunk_vblank_c: %d, \n"
1192 "dst_y_per_pte_row_nom_c: %d, \n"
1193 "refcyc_per_pte_group_nom_c: %d, \n"
1194 "dst_y_per_meta_row_nom_c: %d, \n"
1195 "refcyc_per_meta_chunk_nom_c: %d, \n"
1196 "refcyc_per_line_delivery_pre_c: %d, \n"
1197 "refcyc_per_line_delivery_c: %d \n"
1198 "========================================================\n",
1199 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_l,
1200 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_l,
1201 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_l,
1202 pipe_ctx->dlg_regs.refcyc_per_line_delivery_l,
1203 pipe_ctx->dlg_regs.vratio_prefetch_c,
1204 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_c,
1205 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_c,
1206 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_c,
1207 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_c,
1208 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_c,
1209 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_c,
1210 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_c,
1211 pipe_ctx->dlg_regs.refcyc_per_line_delivery_c
1214 DC_LOG_BANDWIDTH_CALCS(core_dc->ctx->logger,
1215 "\n============== DML RQ Output parameters [%d] ==============\n"
1217 "min_chunk_size: %d \n"
1218 "meta_chunk_size: %d \n"
1219 "min_meta_chunk_size: %d \n"
1220 "dpte_group_size: %d \n"
1221 "mpte_group_size: %d \n"
1222 "swath_height: %d \n"
1223 "pte_row_height_linear: %d \n"
1224 "========================================================\n",
1226 pipe_ctx->rq_regs.rq_regs_l.chunk_size,
1227 pipe_ctx->rq_regs.rq_regs_l.min_chunk_size,
1228 pipe_ctx->rq_regs.rq_regs_l.meta_chunk_size,
1229 pipe_ctx->rq_regs.rq_regs_l.min_meta_chunk_size,
1230 pipe_ctx->rq_regs.rq_regs_l.dpte_group_size,
1231 pipe_ctx->rq_regs.rq_regs_l.mpte_group_size,
1232 pipe_ctx->rq_regs.rq_regs_l.swath_height,
1233 pipe_ctx->rq_regs.rq_regs_l.pte_row_height_linear
1238 static void mmhub_read_vm_system_aperture_settings(struct dcn10_hubp *hubp1,
1239 struct vm_system_aperture_param *apt,
1240 struct dce_hwseq *hws)
1242 PHYSICAL_ADDRESS_LOC physical_page_number;
1243 uint32_t logical_addr_low;
1244 uint32_t logical_addr_high;
1246 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
1247 PHYSICAL_PAGE_NUMBER_MSB, &physical_page_number.high_part);
1248 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
1249 PHYSICAL_PAGE_NUMBER_LSB, &physical_page_number.low_part);
1251 REG_GET(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1252 LOGICAL_ADDR, &logical_addr_low);
1254 REG_GET(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1255 LOGICAL_ADDR, &logical_addr_high);
1257 apt->sys_default.quad_part = physical_page_number.quad_part << 12;
1258 apt->sys_low.quad_part = (int64_t)logical_addr_low << 18;
1259 apt->sys_high.quad_part = (int64_t)logical_addr_high << 18;
1262 /* Temporary read settings, future will get values from kmd directly */
1263 static void mmhub_read_vm_context0_settings(struct dcn10_hubp *hubp1,
1264 struct vm_context0_param *vm0,
1265 struct dce_hwseq *hws)
1267 PHYSICAL_ADDRESS_LOC fb_base;
1268 PHYSICAL_ADDRESS_LOC fb_offset;
1269 uint32_t fb_base_value;
1270 uint32_t fb_offset_value;
1272 REG_GET(DCHUBBUB_SDPIF_FB_BASE, SDPIF_FB_BASE, &fb_base_value);
1273 REG_GET(DCHUBBUB_SDPIF_FB_OFFSET, SDPIF_FB_OFFSET, &fb_offset_value);
1275 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
1276 PAGE_DIRECTORY_ENTRY_HI32, &vm0->pte_base.high_part);
1277 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
1278 PAGE_DIRECTORY_ENTRY_LO32, &vm0->pte_base.low_part);
1280 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
1281 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_start.high_part);
1282 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
1283 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_start.low_part);
1285 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
1286 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_end.high_part);
1287 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
1288 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_end.low_part);
1290 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
1291 PHYSICAL_PAGE_ADDR_HI4, &vm0->fault_default.high_part);
1292 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
1293 PHYSICAL_PAGE_ADDR_LO32, &vm0->fault_default.low_part);
1296 * The values in VM_CONTEXT0_PAGE_TABLE_BASE_ADDR is in UMA space.
1297 * Therefore we need to do
1298 * DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
1299 * - DCHUBBUB_SDPIF_FB_OFFSET + DCHUBBUB_SDPIF_FB_BASE
1301 fb_base.quad_part = (uint64_t)fb_base_value << 24;
1302 fb_offset.quad_part = (uint64_t)fb_offset_value << 24;
1303 vm0->pte_base.quad_part += fb_base.quad_part;
1304 vm0->pte_base.quad_part -= fb_offset.quad_part;
1308 static void dcn10_program_pte_vm(struct dce_hwseq *hws, struct hubp *hubp)
1310 struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
1311 struct vm_system_aperture_param apt = { {{ 0 } } };
1312 struct vm_context0_param vm0 = { { { 0 } } };
1314 mmhub_read_vm_system_aperture_settings(hubp1, &apt, hws);
1315 mmhub_read_vm_context0_settings(hubp1, &vm0, hws);
1317 hubp->funcs->hubp_set_vm_system_aperture_settings(hubp, &apt);
1318 hubp->funcs->hubp_set_vm_context0_settings(hubp, &vm0);
1321 static void dcn10_enable_plane(
1323 struct pipe_ctx *pipe_ctx,
1324 struct dc_state *context)
1326 struct dce_hwseq *hws = dc->hwseq;
1328 if (dc->debug.sanity_checks) {
1329 dcn10_verify_allow_pstate_change_high(dc);
1332 undo_DEGVIDCN10_253_wa(dc);
1334 power_on_plane(dc->hwseq,
1335 pipe_ctx->plane_res.hubp->inst);
1337 /* enable DCFCLK current DCHUB */
1338 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true);
1340 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1341 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
1342 pipe_ctx->stream_res.opp,
1345 /* TODO: enable/disable in dm as per update type.
1347 DC_LOG_DC(dc->ctx->logger,
1348 "Pipe:%d 0x%x: addr hi:0x%x, "
1351 " %d; dst: %d, %d, %d, %d;\n",
1354 plane_state->address.grph.addr.high_part,
1355 plane_state->address.grph.addr.low_part,
1356 plane_state->src_rect.x,
1357 plane_state->src_rect.y,
1358 plane_state->src_rect.width,
1359 plane_state->src_rect.height,
1360 plane_state->dst_rect.x,
1361 plane_state->dst_rect.y,
1362 plane_state->dst_rect.width,
1363 plane_state->dst_rect.height);
1365 DC_LOG_DC(dc->ctx->logger,
1366 "Pipe %d: width, height, x, y format:%d\n"
1367 "viewport:%d, %d, %d, %d\n"
1368 "recout: %d, %d, %d, %d\n",
1370 plane_state->format,
1371 pipe_ctx->plane_res.scl_data.viewport.width,
1372 pipe_ctx->plane_res.scl_data.viewport.height,
1373 pipe_ctx->plane_res.scl_data.viewport.x,
1374 pipe_ctx->plane_res.scl_data.viewport.y,
1375 pipe_ctx->plane_res.scl_data.recout.width,
1376 pipe_ctx->plane_res.scl_data.recout.height,
1377 pipe_ctx->plane_res.scl_data.recout.x,
1378 pipe_ctx->plane_res.scl_data.recout.y);
1379 print_rq_dlg_ttu(dc, pipe_ctx);
1382 if (dc->config.gpu_vm_support)
1383 dcn10_program_pte_vm(hws, pipe_ctx->plane_res.hubp);
1385 if (dc->debug.sanity_checks) {
1386 dcn10_verify_allow_pstate_change_high(dc);
1390 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
1393 struct dpp_grph_csc_adjustment adjust;
1394 memset(&adjust, 0, sizeof(adjust));
1395 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
1398 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
1399 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
1400 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
1401 adjust.temperature_matrix[i] =
1402 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
1405 pipe_ctx->plane_res.dpp->funcs->dpp_set_gamut_remap(pipe_ctx->plane_res.dpp, &adjust);
1409 static void program_csc_matrix(struct pipe_ctx *pipe_ctx,
1410 enum dc_color_space colorspace,
1413 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1414 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1415 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment(pipe_ctx->plane_res.dpp, matrix);
1417 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default != NULL)
1418 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default(pipe_ctx->plane_res.dpp, colorspace);
1422 static void program_output_csc(struct dc *dc,
1423 struct pipe_ctx *pipe_ctx,
1424 enum dc_color_space colorspace,
1428 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1429 program_csc_matrix(pipe_ctx,
1434 static bool is_lower_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1436 if (pipe_ctx->plane_state->visible)
1438 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1443 static bool is_upper_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1445 if (pipe_ctx->plane_state->visible)
1447 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1452 static bool is_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1454 if (pipe_ctx->plane_state->visible)
1456 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1458 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1463 bool is_rgb_cspace(enum dc_color_space output_color_space)
1465 switch (output_color_space) {
1466 case COLOR_SPACE_SRGB:
1467 case COLOR_SPACE_SRGB_LIMITED:
1468 case COLOR_SPACE_2020_RGB_FULLRANGE:
1469 case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
1470 case COLOR_SPACE_ADOBERGB:
1472 case COLOR_SPACE_YCBCR601:
1473 case COLOR_SPACE_YCBCR709:
1474 case COLOR_SPACE_YCBCR601_LIMITED:
1475 case COLOR_SPACE_YCBCR709_LIMITED:
1476 case COLOR_SPACE_2020_YCBCR:
1479 /* Add a case to switch */
1480 BREAK_TO_DEBUGGER();
1485 static void dcn10_get_surface_visual_confirm_color(
1486 const struct pipe_ctx *pipe_ctx,
1487 struct tg_color *color)
1489 uint32_t color_value = MAX_TG_COLOR_VALUE;
1491 switch (pipe_ctx->plane_res.scl_data.format) {
1492 case PIXEL_FORMAT_ARGB8888:
1493 /* set boarder color to red */
1494 color->color_r_cr = color_value;
1497 case PIXEL_FORMAT_ARGB2101010:
1498 /* set boarder color to blue */
1499 color->color_b_cb = color_value;
1501 case PIXEL_FORMAT_420BPP8:
1502 /* set boarder color to green */
1503 color->color_g_y = color_value;
1505 case PIXEL_FORMAT_420BPP10:
1506 /* set boarder color to yellow */
1507 color->color_g_y = color_value;
1508 color->color_r_cr = color_value;
1510 case PIXEL_FORMAT_FP16:
1511 /* set boarder color to white */
1512 color->color_r_cr = color_value;
1513 color->color_b_cb = color_value;
1514 color->color_g_y = color_value;
1521 static uint16_t fixed_point_to_int_frac(
1522 struct fixed31_32 arg,
1523 uint8_t integer_bits,
1524 uint8_t fractional_bits)
1527 int32_t divisor = 1 << fractional_bits;
1531 uint16_t d = (uint16_t)dal_fixed31_32_floor(
1535 if (d <= (uint16_t)(1 << integer_bits) - (1 / (uint16_t)divisor))
1536 numerator = (uint16_t)dal_fixed31_32_floor(
1537 dal_fixed31_32_mul_int(
1541 numerator = dal_fixed31_32_floor(
1543 dal_fixed31_32_from_int(
1544 1LL << integer_bits),
1545 dal_fixed31_32_recip(
1546 dal_fixed31_32_from_int(
1551 result = (uint16_t)numerator;
1553 result = (uint16_t)(
1554 (1 << (integer_bits + fractional_bits + 1)) + numerator);
1556 if ((result != 0) && dal_fixed31_32_lt(
1557 arg, dal_fixed31_32_zero))
1558 result |= 1 << (integer_bits + fractional_bits);
1563 void build_prescale_params(struct dc_bias_and_scale *bias_and_scale,
1564 const struct dc_plane_state *plane_state)
1566 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1567 && plane_state->format != SURFACE_PIXEL_FORMAT_INVALID
1568 && plane_state->input_csc_color_matrix.enable_adjustment
1569 && plane_state->coeff_reduction_factor.value != 0) {
1570 bias_and_scale->scale_blue = fixed_point_to_int_frac(
1571 dal_fixed31_32_mul(plane_state->coeff_reduction_factor,
1572 dal_fixed31_32_from_fraction(256, 255)),
1575 bias_and_scale->scale_red = bias_and_scale->scale_blue;
1576 bias_and_scale->scale_green = bias_and_scale->scale_blue;
1578 bias_and_scale->scale_blue = 0x2000;
1579 bias_and_scale->scale_red = 0x2000;
1580 bias_and_scale->scale_green = 0x2000;
1584 static void update_dpp(struct dpp *dpp, struct dc_plane_state *plane_state)
1586 struct dc_bias_and_scale bns_params = {0};
1588 // program the input csc
1589 dpp->funcs->dpp_setup(dpp,
1590 plane_state->format,
1591 EXPANSION_MODE_ZERO,
1592 plane_state->input_csc_color_matrix,
1593 COLOR_SPACE_YCBCR601_LIMITED);
1595 //set scale and bias registers
1596 build_prescale_params(&bns_params, plane_state);
1597 if (dpp->funcs->dpp_program_bias_and_scale)
1598 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1602 static void update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
1604 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1605 struct mpcc_blnd_cfg blnd_cfg;
1606 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1608 struct mpcc *new_mpcc;
1609 struct mpc *mpc = dc->res_pool->mpc;
1610 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
1612 /* TODO: proper fix once fpga works */
1614 if (dc->debug.surface_visual_confirm)
1615 dcn10_get_surface_visual_confirm_color(
1616 pipe_ctx, &blnd_cfg.black_color);
1618 color_space_to_black_color(
1619 dc, pipe_ctx->stream->output_color_space,
1620 &blnd_cfg.black_color);
1622 if (per_pixel_alpha)
1623 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
1625 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
1627 blnd_cfg.overlap_only = false;
1628 blnd_cfg.global_alpha = 0xff;
1629 blnd_cfg.global_gain = 0xff;
1631 /* DCN1.0 has output CM before MPC which seems to screw with
1632 * pre-multiplied alpha.
1634 blnd_cfg.pre_multiplied_alpha = is_rgb_cspace(
1635 pipe_ctx->stream->output_color_space)
1640 * Note: currently there is a bug in init_hw such that
1641 * on resume from hibernate, BIOS sets up MPCC0, and
1642 * we do mpcc_remove but the mpcc cannot go to idle
1643 * after remove. This cause us to pick mpcc1 here,
1644 * which causes a pstate hang for yet unknown reason.
1646 mpcc_id = hubp->inst;
1648 /* check if this MPCC is already being used */
1649 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
1650 /* remove MPCC if being used */
1651 if (new_mpcc != NULL)
1652 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
1654 if (dc->debug.sanity_checks)
1655 mpc->funcs->assert_mpcc_idle_before_connect(
1656 dc->res_pool->mpc, mpcc_id);
1658 /* Call MPC to insert new plane */
1659 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
1667 ASSERT(new_mpcc != NULL);
1669 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
1670 hubp->mpcc_id = mpcc_id;
1673 static void update_scaler(struct pipe_ctx *pipe_ctx)
1675 bool per_pixel_alpha =
1676 pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1678 /* TODO: proper fix once fpga works */
1680 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = per_pixel_alpha;
1681 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1682 /* scaler configuration */
1683 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1684 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
1687 static void update_dchubp_dpp(
1689 struct pipe_ctx *pipe_ctx,
1690 struct dc_state *context)
1692 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1693 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1694 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1695 union plane_size size = plane_state->plane_size;
1697 /* depends on DML calculation, DPP clock value may change dynamically */
1698 if (plane_state->update_flags.bits.full_update) {
1699 dpp->funcs->dpp_dppclk_control(
1701 context->bw.dcn.calc_clk.max_dppclk_khz <
1702 context->bw.dcn.calc_clk.dispclk_khz,
1705 dc->current_state->bw.dcn.cur_clk.max_dppclk_khz =
1706 context->bw.dcn.calc_clk.max_dppclk_khz;
1707 context->bw.dcn.cur_clk.max_dppclk_khz = context->bw.dcn.calc_clk.max_dppclk_khz;
1710 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
1711 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
1712 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
1714 if (plane_state->update_flags.bits.full_update) {
1715 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst);
1717 hubp->funcs->hubp_setup(
1719 &pipe_ctx->dlg_regs,
1720 &pipe_ctx->ttu_regs,
1722 &pipe_ctx->pipe_dlg_param);
1725 size.grph.surface_size = pipe_ctx->plane_res.scl_data.viewport;
1727 if (plane_state->update_flags.bits.full_update ||
1728 plane_state->update_flags.bits.bpp_change)
1729 update_dpp(dpp, plane_state);
1731 if (plane_state->update_flags.bits.full_update ||
1732 plane_state->update_flags.bits.per_pixel_alpha_change)
1733 update_mpcc(dc, pipe_ctx);
1735 if (plane_state->update_flags.bits.full_update ||
1736 plane_state->update_flags.bits.per_pixel_alpha_change ||
1737 plane_state->update_flags.bits.scaling_change ||
1738 plane_state->update_flags.bits.position_change) {
1739 update_scaler(pipe_ctx);
1742 if (plane_state->update_flags.bits.full_update ||
1743 plane_state->update_flags.bits.scaling_change ||
1744 plane_state->update_flags.bits.position_change) {
1745 hubp->funcs->mem_program_viewport(
1747 &pipe_ctx->plane_res.scl_data.viewport,
1748 &pipe_ctx->plane_res.scl_data.viewport_c);
1751 if (pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
1752 dc->hwss.set_cursor_position(pipe_ctx);
1753 dc->hwss.set_cursor_attribute(pipe_ctx);
1756 if (plane_state->update_flags.bits.full_update) {
1758 program_gamut_remap(pipe_ctx);
1760 program_output_csc(dc,
1762 pipe_ctx->stream->output_color_space,
1763 pipe_ctx->stream->csc_color_matrix.matrix,
1767 if (plane_state->update_flags.bits.full_update ||
1768 plane_state->update_flags.bits.pixel_format_change ||
1769 plane_state->update_flags.bits.horizontal_mirror_change ||
1770 plane_state->update_flags.bits.rotation_change ||
1771 plane_state->update_flags.bits.swizzle_change ||
1772 plane_state->update_flags.bits.dcc_change ||
1773 plane_state->update_flags.bits.bpp_change ||
1774 plane_state->update_flags.bits.scaling_change) {
1775 hubp->funcs->hubp_program_surface_config(
1777 plane_state->format,
1778 &plane_state->tiling_info,
1780 plane_state->rotation,
1782 plane_state->horizontal_mirror);
1785 hubp->power_gated = false;
1787 dc->hwss.update_plane_addr(dc, pipe_ctx);
1789 if (is_pipe_tree_visible(pipe_ctx))
1790 hubp->funcs->set_blank(hubp, false);
1793 static void dcn10_otg_blank(
1795 struct stream_resource stream_res,
1796 struct dc_stream_state *stream,
1799 enum dc_color_space color_space;
1800 struct tg_color black_color = {0};
1802 /* program otg blank color */
1803 color_space = stream->output_color_space;
1804 color_space_to_black_color(dc, color_space, &black_color);
1806 if (stream_res.tg->funcs->set_blank_color)
1807 stream_res.tg->funcs->set_blank_color(
1812 if (stream_res.tg->funcs->set_blank)
1813 stream_res.tg->funcs->set_blank(stream_res.tg, blank);
1815 stream_res.abm->funcs->set_abm_level(stream_res.abm, stream->abm_level);
1818 stream_res.abm->funcs->set_abm_immediate_disable(stream_res.abm);
1819 if (stream_res.tg->funcs->set_blank)
1820 stream_res.tg->funcs->set_blank(stream_res.tg, blank);
1824 static void program_all_pipe_in_tree(
1826 struct pipe_ctx *pipe_ctx,
1827 struct dc_state *context)
1829 if (pipe_ctx->top_pipe == NULL) {
1830 bool blank = !is_pipe_tree_visible(pipe_ctx);
1832 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
1833 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
1834 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
1835 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
1836 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
1838 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1839 pipe_ctx->stream_res.tg);
1841 dcn10_otg_blank(dc, pipe_ctx->stream_res,
1842 pipe_ctx->stream, blank);
1845 if (pipe_ctx->plane_state != NULL) {
1846 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1847 dcn10_enable_plane(dc, pipe_ctx, context);
1849 update_dchubp_dpp(dc, pipe_ctx, context);
1851 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
1852 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
1853 pipe_ctx->plane_state->update_flags.bits.gamma_change)
1854 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
1856 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
1857 * only do gamma programming for full update.
1858 * TODO: This can be further optimized/cleaned up
1859 * Always call this for now since it does memcmp inside before
1860 * doing heavy calculation and programming
1862 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1863 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
1866 if (pipe_ctx->bottom_pipe != NULL && pipe_ctx->bottom_pipe != pipe_ctx) {
1867 program_all_pipe_in_tree(dc, pipe_ctx->bottom_pipe, context);
1871 static void dcn10_pplib_apply_display_requirements(
1873 struct dc_state *context)
1875 struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
1877 pp_display_cfg->all_displays_in_sync = false;/*todo*/
1878 pp_display_cfg->nb_pstate_switch_disable = false;
1879 pp_display_cfg->min_engine_clock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1880 pp_display_cfg->min_memory_clock_khz = context->bw.dcn.cur_clk.fclk_khz;
1881 pp_display_cfg->min_engine_clock_deep_sleep_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1882 pp_display_cfg->min_dcfc_deep_sleep_clock_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1883 pp_display_cfg->avail_mclk_switch_time_us =
1884 context->bw.dcn.cur_clk.dram_ccm_us > 0 ? context->bw.dcn.cur_clk.dram_ccm_us : 0;
1885 pp_display_cfg->avail_mclk_switch_time_in_disp_active_us =
1886 context->bw.dcn.cur_clk.min_active_dram_ccm_us > 0 ? context->bw.dcn.cur_clk.min_active_dram_ccm_us : 0;
1887 pp_display_cfg->min_dcfclock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1888 pp_display_cfg->disp_clk_khz = context->bw.dcn.cur_clk.dispclk_khz;
1889 dce110_fill_display_configs(context, pp_display_cfg);
1891 if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof(
1892 struct dm_pp_display_configuration)) != 0)
1893 dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
1895 dc->prev_display_config = *pp_display_cfg;
1898 static void optimize_shared_resources(struct dc *dc)
1900 if (dc->current_state->stream_count == 0) {
1902 dcn10_pplib_apply_display_requirements(dc, dc->current_state);
1905 if (dc->debug.pplib_wm_report_mode == WM_REPORT_OVERRIDE)
1906 dcn_bw_notify_pplib_of_wm_ranges(dc);
1909 static void ready_shared_resources(struct dc *dc, struct dc_state *context)
1912 if (dc->current_state->stream_count == 0 &&
1913 context->stream_count != 0)
1914 dcn10_pplib_apply_display_requirements(dc, context);
1917 static struct pipe_ctx *find_top_pipe_for_stream(
1919 struct dc_state *context,
1920 const struct dc_stream_state *stream)
1924 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1925 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1926 struct pipe_ctx *old_pipe_ctx =
1927 &dc->current_state->res_ctx.pipe_ctx[i];
1929 if (!pipe_ctx->plane_state && !old_pipe_ctx->plane_state)
1932 if (pipe_ctx->stream != stream)
1935 if (!pipe_ctx->top_pipe)
1941 static void dcn10_apply_ctx_for_surface(
1943 const struct dc_stream_state *stream,
1945 struct dc_state *context)
1948 struct timing_generator *tg;
1949 bool removed_pipe[4] = { false };
1950 unsigned int ref_clk_mhz = dc->res_pool->ref_clock_inKhz/1000;
1951 bool program_water_mark = false;
1952 struct dc_context *ctx = dc->ctx;
1953 struct pipe_ctx *top_pipe_to_program =
1954 find_top_pipe_for_stream(dc, context, stream);
1956 if (!top_pipe_to_program)
1959 tg = top_pipe_to_program->stream_res.tg;
1961 dcn10_pipe_control_lock(dc, top_pipe_to_program, true);
1963 if (num_planes == 0) {
1964 /* OTG blank before remove all front end */
1965 dcn10_otg_blank(dc, top_pipe_to_program->stream_res, top_pipe_to_program->stream, true);
1968 /* Disconnect unused mpcc */
1969 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1970 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1971 struct pipe_ctx *old_pipe_ctx =
1972 &dc->current_state->res_ctx.pipe_ctx[i];
1974 * Powergate reused pipes that are not powergated
1975 * fairly hacky right now, using opp_id as indicator
1976 * TODO: After move dc_post to dc_update, this will
1979 if (pipe_ctx->plane_state && !old_pipe_ctx->plane_state) {
1980 if (old_pipe_ctx->stream_res.tg == tg &&
1981 old_pipe_ctx->plane_res.hubp &&
1982 old_pipe_ctx->plane_res.hubp->opp_id != 0xf) {
1983 dcn10_disable_plane(dc, old_pipe_ctx);
1985 * power down fe will unlock when calling reset, need
1986 * to lock it back here. Messy, need rework.
1988 pipe_ctx->stream_res.tg->funcs->lock(pipe_ctx->stream_res.tg);
1992 if (!pipe_ctx->plane_state &&
1993 old_pipe_ctx->plane_state &&
1994 old_pipe_ctx->stream_res.tg == tg) {
1996 plane_atomic_disconnect(dc, old_pipe_ctx);
1997 removed_pipe[i] = true;
2000 "Reset mpcc for pipe %d\n",
2001 old_pipe_ctx->pipe_idx);
2006 program_all_pipe_in_tree(dc, top_pipe_to_program, context);
2008 dcn10_pipe_control_lock(dc, top_pipe_to_program, false);
2010 if (num_planes == 0)
2011 false_optc_underflow_wa(dc, stream, tg);
2013 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2014 struct pipe_ctx *old_pipe_ctx =
2015 &dc->current_state->res_ctx.pipe_ctx[i];
2016 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2018 if (pipe_ctx->stream == stream &&
2019 pipe_ctx->plane_state &&
2020 pipe_ctx->plane_state->update_flags.bits.full_update)
2021 program_water_mark = true;
2023 if (removed_pipe[i])
2024 dcn10_disable_plane(dc, old_pipe_ctx);
2027 if (program_water_mark) {
2028 if (dc->debug.sanity_checks) {
2029 /* pstate stuck check after watermark update */
2030 dcn10_verify_allow_pstate_change_high(dc);
2033 /* watermark is for all pipes */
2034 hubbub1_program_watermarks(dc->res_pool->hubbub,
2035 &context->bw.dcn.watermarks, ref_clk_mhz);
2037 if (dc->debug.sanity_checks) {
2038 /* pstate stuck check after watermark update */
2039 dcn10_verify_allow_pstate_change_high(dc);
2042 /* DC_LOG_BANDWIDTH_CALCS(dc->ctx->logger,
2043 "\n============== Watermark parameters ==============\n"
2044 "a.urgent_ns: %d \n"
2045 "a.cstate_enter_plus_exit: %d \n"
2046 "a.cstate_exit: %d \n"
2047 "a.pstate_change: %d \n"
2048 "a.pte_meta_urgent: %d \n"
2049 "b.urgent_ns: %d \n"
2050 "b.cstate_enter_plus_exit: %d \n"
2051 "b.cstate_exit: %d \n"
2052 "b.pstate_change: %d \n"
2053 "b.pte_meta_urgent: %d \n",
2054 context->bw.dcn.watermarks.a.urgent_ns,
2055 context->bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns,
2056 context->bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns,
2057 context->bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns,
2058 context->bw.dcn.watermarks.a.pte_meta_urgent_ns,
2059 context->bw.dcn.watermarks.b.urgent_ns,
2060 context->bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns,
2061 context->bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns,
2062 context->bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns,
2063 context->bw.dcn.watermarks.b.pte_meta_urgent_ns
2065 DC_LOG_BANDWIDTH_CALCS(dc->ctx->logger,
2066 "\nc.urgent_ns: %d \n"
2067 "c.cstate_enter_plus_exit: %d \n"
2068 "c.cstate_exit: %d \n"
2069 "c.pstate_change: %d \n"
2070 "c.pte_meta_urgent: %d \n"
2071 "d.urgent_ns: %d \n"
2072 "d.cstate_enter_plus_exit: %d \n"
2073 "d.cstate_exit: %d \n"
2074 "d.pstate_change: %d \n"
2075 "d.pte_meta_urgent: %d \n"
2076 "========================================================\n",
2077 context->bw.dcn.watermarks.c.urgent_ns,
2078 context->bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns,
2079 context->bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns,
2080 context->bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns,
2081 context->bw.dcn.watermarks.c.pte_meta_urgent_ns,
2082 context->bw.dcn.watermarks.d.urgent_ns,
2083 context->bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns,
2084 context->bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns,
2085 context->bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns,
2086 context->bw.dcn.watermarks.d.pte_meta_urgent_ns
2091 static void dcn10_set_bandwidth(
2093 struct dc_state *context,
2094 bool decrease_allowed)
2096 struct pp_smu_display_requirement_rv *smu_req_cur =
2097 &dc->res_pool->pp_smu_req;
2098 struct pp_smu_display_requirement_rv smu_req = *smu_req_cur;
2099 struct pp_smu_funcs_rv *pp_smu = dc->res_pool->pp_smu;
2101 if (dc->debug.sanity_checks) {
2102 dcn10_verify_allow_pstate_change_high(dc);
2105 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
2108 if (decrease_allowed || context->bw.dcn.calc_clk.dispclk_khz
2109 > dc->current_state->bw.dcn.cur_clk.dispclk_khz) {
2110 dc->res_pool->display_clock->funcs->set_clock(
2111 dc->res_pool->display_clock,
2112 context->bw.dcn.calc_clk.dispclk_khz);
2113 context->bw.dcn.cur_clk.dispclk_khz =
2114 context->bw.dcn.calc_clk.dispclk_khz;
2116 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_khz
2117 > dc->current_state->bw.dcn.cur_clk.dcfclk_khz) {
2118 context->bw.dcn.cur_clk.dcfclk_khz =
2119 context->bw.dcn.calc_clk.dcfclk_khz;
2120 smu_req.hard_min_dcefclk_khz =
2121 context->bw.dcn.calc_clk.dcfclk_khz;
2123 if (decrease_allowed || context->bw.dcn.calc_clk.fclk_khz
2124 > dc->current_state->bw.dcn.cur_clk.fclk_khz) {
2125 context->bw.dcn.cur_clk.fclk_khz =
2126 context->bw.dcn.calc_clk.fclk_khz;
2127 smu_req.hard_min_fclk_khz = context->bw.dcn.calc_clk.fclk_khz;
2129 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz
2130 > dc->current_state->bw.dcn.cur_clk.dcfclk_deep_sleep_khz) {
2131 context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz =
2132 context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz;
2135 smu_req.display_count = context->stream_count;
2137 if (pp_smu->set_display_requirement)
2138 pp_smu->set_display_requirement(&pp_smu->pp_smu, &smu_req);
2140 *smu_req_cur = smu_req;
2142 /* Decrease in freq is increase in period so opposite comparison for dram_ccm */
2143 if (decrease_allowed || context->bw.dcn.calc_clk.dram_ccm_us
2144 < dc->current_state->bw.dcn.cur_clk.dram_ccm_us) {
2145 context->bw.dcn.cur_clk.dram_ccm_us =
2146 context->bw.dcn.calc_clk.dram_ccm_us;
2148 if (decrease_allowed || context->bw.dcn.calc_clk.min_active_dram_ccm_us
2149 < dc->current_state->bw.dcn.cur_clk.min_active_dram_ccm_us) {
2150 context->bw.dcn.cur_clk.min_active_dram_ccm_us =
2151 context->bw.dcn.calc_clk.min_active_dram_ccm_us;
2153 dcn10_pplib_apply_display_requirements(dc, context);
2155 if (dc->debug.sanity_checks) {
2156 dcn10_verify_allow_pstate_change_high(dc);
2159 /* need to fix this function. not doing the right thing here */
2162 static void set_drr(struct pipe_ctx **pipe_ctx,
2163 int num_pipes, int vmin, int vmax)
2166 struct drr_params params = {0};
2168 params.vertical_total_max = vmax;
2169 params.vertical_total_min = vmin;
2171 /* TODO: If multiple pipes are to be supported, you need
2174 for (i = 0; i < num_pipes; i++) {
2175 pipe_ctx[i]->stream_res.tg->funcs->set_drr(pipe_ctx[i]->stream_res.tg, ¶ms);
2179 static void get_position(struct pipe_ctx **pipe_ctx,
2181 struct crtc_position *position)
2185 /* TODO: handle pipes > 1
2187 for (i = 0; i < num_pipes; i++)
2188 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2191 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2192 int num_pipes, const struct dc_static_screen_events *events)
2195 unsigned int value = 0;
2197 if (events->surface_update)
2199 if (events->cursor_update)
2201 if (events->force_trigger)
2204 for (i = 0; i < num_pipes; i++)
2205 pipe_ctx[i]->stream_res.tg->funcs->
2206 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
2209 static void set_plane_config(
2210 const struct dc *dc,
2211 struct pipe_ctx *pipe_ctx,
2212 struct resource_context *res_ctx)
2215 program_gamut_remap(pipe_ctx);
2218 static void dcn10_config_stereo_parameters(
2219 struct dc_stream_state *stream, struct crtc_stereo_flags *flags)
2221 enum view_3d_format view_format = stream->view_format;
2222 enum dc_timing_3d_format timing_3d_format =\
2223 stream->timing.timing_3d_format;
2224 bool non_stereo_timing = false;
2226 if (timing_3d_format == TIMING_3D_FORMAT_NONE ||
2227 timing_3d_format == TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2228 timing_3d_format == TIMING_3D_FORMAT_TOP_AND_BOTTOM)
2229 non_stereo_timing = true;
2231 if (non_stereo_timing == false &&
2232 view_format == VIEW_3D_FORMAT_FRAME_SEQUENTIAL) {
2234 flags->PROGRAM_STEREO = 1;
2235 flags->PROGRAM_POLARITY = 1;
2236 if (timing_3d_format == TIMING_3D_FORMAT_INBAND_FA ||
2237 timing_3d_format == TIMING_3D_FORMAT_DP_HDMI_INBAND_FA ||
2238 timing_3d_format == TIMING_3D_FORMAT_SIDEBAND_FA) {
2239 enum display_dongle_type dongle = \
2240 stream->sink->link->ddc->dongle_type;
2241 if (dongle == DISPLAY_DONGLE_DP_VGA_CONVERTER ||
2242 dongle == DISPLAY_DONGLE_DP_DVI_CONVERTER ||
2243 dongle == DISPLAY_DONGLE_DP_HDMI_CONVERTER)
2244 flags->DISABLE_STEREO_DP_SYNC = 1;
2246 flags->RIGHT_EYE_POLARITY =\
2247 stream->timing.flags.RIGHT_EYE_3D_POLARITY;
2248 if (timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2249 flags->FRAME_PACKED = 1;
2255 static void dcn10_setup_stereo(struct pipe_ctx *pipe_ctx, struct dc *dc)
2257 struct crtc_stereo_flags flags = { 0 };
2258 struct dc_stream_state *stream = pipe_ctx->stream;
2260 dcn10_config_stereo_parameters(stream, &flags);
2262 pipe_ctx->stream_res.opp->funcs->opp_program_stereo(
2263 pipe_ctx->stream_res.opp,
2264 flags.PROGRAM_STEREO == 1 ? true:false,
2267 pipe_ctx->stream_res.tg->funcs->program_stereo(
2268 pipe_ctx->stream_res.tg,
2275 static struct hubp *get_hubp_by_inst(struct resource_pool *res_pool, int mpcc_inst)
2279 for (i = 0; i < res_pool->pipe_count; i++) {
2280 if (res_pool->hubps[i]->inst == mpcc_inst)
2281 return res_pool->hubps[i];
2287 static void dcn10_wait_for_mpcc_disconnect(
2289 struct resource_pool *res_pool,
2290 struct pipe_ctx *pipe_ctx)
2294 if (dc->debug.sanity_checks) {
2295 dcn10_verify_allow_pstate_change_high(dc);
2298 if (!pipe_ctx->stream_res.opp)
2301 for (mpcc_inst = 0; mpcc_inst < MAX_PIPES; mpcc_inst++) {
2302 if (pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst]) {
2303 struct hubp *hubp = get_hubp_by_inst(res_pool, mpcc_inst);
2305 res_pool->mpc->funcs->wait_for_idle(res_pool->mpc, mpcc_inst);
2306 pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst] = false;
2307 hubp->funcs->set_blank(hubp, true);
2308 /*DC_LOG_ERROR(dc->ctx->logger,
2309 "[debug_mpo: wait_for_mpcc finished waiting on mpcc %d]\n",
2314 if (dc->debug.sanity_checks) {
2315 dcn10_verify_allow_pstate_change_high(dc);
2320 static bool dcn10_dummy_display_power_gating(
2322 uint8_t controller_id,
2323 struct dc_bios *dcb,
2324 enum pipe_gating_control power_gating)
2329 static void dcn10_update_pending_status(struct pipe_ctx *pipe_ctx)
2331 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2332 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2334 if (plane_state == NULL)
2337 plane_state->status.is_flip_pending =
2338 pipe_ctx->plane_res.hubp->funcs->hubp_is_flip_pending(
2339 pipe_ctx->plane_res.hubp);
2341 plane_state->status.current_address = pipe_ctx->plane_res.hubp->current_address;
2342 if (pipe_ctx->plane_res.hubp->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2343 tg->funcs->is_stereo_left_eye) {
2344 plane_state->status.is_right_eye =
2345 !tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2349 static void dcn10_update_dchub(struct dce_hwseq *hws, struct dchub_init_data *dh_data)
2351 if (hws->ctx->dc->res_pool->hubbub != NULL)
2352 hubbub1_update_dchub(hws->ctx->dc->res_pool->hubbub, dh_data);
2355 static void dcn10_set_cursor_position(struct pipe_ctx *pipe_ctx)
2357 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2358 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2359 struct dpp *dpp = pipe_ctx->plane_res.dpp;
2360 struct dc_cursor_mi_param param = {
2361 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_khz,
2362 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clock_inKhz,
2363 .viewport_x_start = pipe_ctx->plane_res.scl_data.viewport.x,
2364 .viewport_width = pipe_ctx->plane_res.scl_data.viewport.width,
2365 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz
2368 if (pipe_ctx->plane_state->address.type
2369 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2370 pos_cpy.enable = false;
2372 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2373 pos_cpy.enable = false;
2375 hubp->funcs->set_cursor_position(hubp, &pos_cpy, ¶m);
2376 dpp->funcs->set_cursor_position(dpp, &pos_cpy, ¶m, hubp->curs_attr.width);
2379 static void dcn10_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2381 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2383 pipe_ctx->plane_res.hubp->funcs->set_cursor_attributes(
2384 pipe_ctx->plane_res.hubp, attributes);
2385 pipe_ctx->plane_res.dpp->funcs->set_cursor_attributes(
2386 pipe_ctx->plane_res.dpp, attributes->color_format);
2389 static const struct hw_sequencer_funcs dcn10_funcs = {
2390 .program_gamut_remap = program_gamut_remap,
2391 .program_csc_matrix = program_csc_matrix,
2392 .init_hw = dcn10_init_hw,
2393 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2394 .apply_ctx_for_surface = dcn10_apply_ctx_for_surface,
2395 .set_plane_config = set_plane_config,
2396 .update_plane_addr = dcn10_update_plane_addr,
2397 .update_dchub = dcn10_update_dchub,
2398 .update_pending_status = dcn10_update_pending_status,
2399 .set_input_transfer_func = dcn10_set_input_transfer_func,
2400 .set_output_transfer_func = dcn10_set_output_transfer_func,
2401 .power_down = dce110_power_down,
2402 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2403 .enable_timing_synchronization = dcn10_enable_timing_synchronization,
2404 .enable_per_frame_crtc_position_reset = dcn10_enable_per_frame_crtc_position_reset,
2405 .update_info_frame = dce110_update_info_frame,
2406 .enable_stream = dce110_enable_stream,
2407 .disable_stream = dce110_disable_stream,
2408 .unblank_stream = dce110_unblank_stream,
2409 .blank_stream = dce110_blank_stream,
2410 .enable_display_power_gating = dcn10_dummy_display_power_gating,
2411 .disable_plane = dcn10_disable_plane,
2412 .pipe_control_lock = dcn10_pipe_control_lock,
2413 .set_bandwidth = dcn10_set_bandwidth,
2414 .reset_hw_ctx_wrap = reset_hw_ctx_wrap,
2415 .prog_pixclk_crtc_otg = dcn10_prog_pixclk_crtc_otg,
2417 .get_position = get_position,
2418 .set_static_screen_control = set_static_screen_control,
2419 .setup_stereo = dcn10_setup_stereo,
2420 .set_avmute = dce110_set_avmute,
2421 .log_hw_state = dcn10_log_hw_state,
2422 .wait_for_mpcc_disconnect = dcn10_wait_for_mpcc_disconnect,
2423 .ready_shared_resources = ready_shared_resources,
2424 .optimize_shared_resources = optimize_shared_resources,
2425 .pplib_apply_display_requirements =
2426 dcn10_pplib_apply_display_requirements,
2427 .edp_backlight_control = hwss_edp_backlight_control,
2428 .edp_power_control = hwss_edp_power_control,
2429 .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready,
2430 .set_cursor_position = dcn10_set_cursor_position,
2431 .set_cursor_attribute = dcn10_set_cursor_attribute
2435 void dcn10_hw_sequencer_construct(struct dc *dc)
2437 dc->hwss = dcn10_funcs;