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"
54 #define FN(reg_name, field_name) \
55 hws->shifts->field_name, hws->masks->field_name
57 #define DTN_INFO_MICRO_SEC(ref_cycle) \
58 print_microsec(dc_ctx, ref_cycle)
60 void print_microsec(struct dc_context *dc_ctx, uint32_t ref_cycle)
62 static const uint32_t ref_clk_mhz = 48;
63 static const unsigned int frac = 10;
64 uint32_t us_x10 = (ref_cycle * frac) / ref_clk_mhz;
72 static void log_mpc_crc(struct dc *dc)
74 struct dc_context *dc_ctx = dc->ctx;
75 struct dce_hwseq *hws = dc->hwseq;
77 if (REG(MPC_CRC_RESULT_GB))
78 DTN_INFO("MPC_CRC_RESULT_GB:%d MPC_CRC_RESULT_C:%d MPC_CRC_RESULT_AR:%d\n",
79 REG_READ(MPC_CRC_RESULT_GB), REG_READ(MPC_CRC_RESULT_C), REG_READ(MPC_CRC_RESULT_AR));
80 if (REG(DPP_TOP0_DPP_CRC_VAL_B_A))
81 DTN_INFO("DPP_TOP0_DPP_CRC_VAL_B_A:%d DPP_TOP0_DPP_CRC_VAL_R_G:%d\n",
82 REG_READ(DPP_TOP0_DPP_CRC_VAL_B_A), REG_READ(DPP_TOP0_DPP_CRC_VAL_R_G));
85 void dcn10_log_hubbub_state(struct dc *dc)
87 struct dc_context *dc_ctx = dc->ctx;
88 struct dcn_hubbub_wm wm;
91 hubbub1_wm_read_state(dc->res_pool->hubbub, &wm);
93 DTN_INFO("HUBBUB WM: \t data_urgent \t pte_meta_urgent \t "
94 "sr_enter \t sr_exit \t dram_clk_change \n");
96 for (i = 0; i < 4; i++) {
97 struct dcn_hubbub_wm_set *s;
100 DTN_INFO("WM_Set[%d]:\t ", s->wm_set);
101 DTN_INFO_MICRO_SEC(s->data_urgent);
102 DTN_INFO_MICRO_SEC(s->pte_meta_urgent);
103 DTN_INFO_MICRO_SEC(s->sr_enter);
104 DTN_INFO_MICRO_SEC(s->sr_exit);
105 DTN_INFO_MICRO_SEC(s->dram_clk_chanage);
112 void dcn10_log_hw_state(struct dc *dc)
114 struct dc_context *dc_ctx = dc->ctx;
115 struct resource_pool *pool = dc->res_pool;
120 dcn10_log_hubbub_state(dc);
122 DTN_INFO("HUBP:\t format \t addr_hi \t width \t height \t "
123 "rotation \t mirror \t sw_mode \t "
124 "dcc_en \t blank_en \t ttu_dis \t underflow \t "
125 "min_ttu_vblank \t qos_low_wm \t qos_high_wm \n");
127 for (i = 0; i < pool->pipe_count; i++) {
128 struct hubp *hubp = pool->hubps[i];
129 struct dcn_hubp_state s;
131 hubp1_read_state(TO_DCN10_HUBP(hubp), &s);
133 DTN_INFO("[%d]:\t %xh \t %xh \t %d \t %d \t "
134 "%xh \t %xh \t %xh \t "
135 "%d \t %d \t %d \t %xh \t",
148 DTN_INFO_MICRO_SEC(s.min_ttu_vblank);
149 DTN_INFO_MICRO_SEC(s.qos_level_low_wm);
150 DTN_INFO_MICRO_SEC(s.qos_level_high_wm);
155 DTN_INFO("OTG:\t v_bs \t v_be \t v_ss \t v_se \t vpol \t vmax \t vmin \t "
156 "h_bs \t h_be \t h_ss \t h_se \t hpol \t htot \t vtot \t underflow\n");
158 for (i = 0; i < pool->res_cap->num_timing_generator; i++) {
159 struct timing_generator *tg = pool->timing_generators[i];
160 struct dcn_otg_state s = {0};
162 optc1_read_otg_state(DCN10TG_FROM_TG(tg), &s);
164 //only print if OTG master is enabled
165 if ((s.otg_enabled & 1) == 0)
168 DTN_INFO("[%d]:\t %d \t %d \t %d \t %d \t "
169 "%d \t %d \t %d \t %d \t %d \t %d \t "
170 "%d \t %d \t %d \t %d \t %d \t ",
186 s.underflow_occurred_status);
196 static void enable_dppclk(
197 struct dce_hwseq *hws,
199 uint32_t requested_pix_clk,
202 dm_logger_write(hws->ctx->logger, LOG_SURFACE,
203 "dppclk_rate_control for pipe %d programed to %d\n",
207 if (hws->shifts->DPPCLK_RATE_CONTROL)
208 REG_UPDATE_2(DPP_CONTROL[plane_id],
209 DPPCLK_RATE_CONTROL, dppclk_div,
210 DPP_CLOCK_ENABLE, 1);
212 REG_UPDATE(DPP_CONTROL[plane_id],
213 DPP_CLOCK_ENABLE, 1);
216 static void enable_power_gating_plane(
217 struct dce_hwseq *hws,
220 bool force_on = 1; /* disable power gating */
226 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on);
227 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN2_POWER_FORCEON, force_on);
228 REG_UPDATE(DOMAIN4_PG_CONFIG, DOMAIN4_POWER_FORCEON, force_on);
229 REG_UPDATE(DOMAIN6_PG_CONFIG, DOMAIN6_POWER_FORCEON, force_on);
232 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN1_POWER_FORCEON, force_on);
233 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN3_POWER_FORCEON, force_on);
234 REG_UPDATE(DOMAIN5_PG_CONFIG, DOMAIN5_POWER_FORCEON, force_on);
235 REG_UPDATE(DOMAIN7_PG_CONFIG, DOMAIN7_POWER_FORCEON, force_on);
238 static void disable_vga(
239 struct dce_hwseq *hws)
241 REG_WRITE(D1VGA_CONTROL, 0);
242 REG_WRITE(D2VGA_CONTROL, 0);
243 REG_WRITE(D3VGA_CONTROL, 0);
244 REG_WRITE(D4VGA_CONTROL, 0);
247 static void dpp_pg_control(
248 struct dce_hwseq *hws,
249 unsigned int dpp_inst,
252 uint32_t power_gate = power_on ? 0 : 1;
253 uint32_t pwr_status = power_on ? 0 : 2;
255 if (hws->ctx->dc->debug.disable_dpp_power_gate)
260 REG_UPDATE(DOMAIN1_PG_CONFIG,
261 DOMAIN1_POWER_GATE, power_gate);
263 REG_WAIT(DOMAIN1_PG_STATUS,
264 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
268 REG_UPDATE(DOMAIN3_PG_CONFIG,
269 DOMAIN3_POWER_GATE, power_gate);
271 REG_WAIT(DOMAIN3_PG_STATUS,
272 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
276 REG_UPDATE(DOMAIN5_PG_CONFIG,
277 DOMAIN5_POWER_GATE, power_gate);
279 REG_WAIT(DOMAIN5_PG_STATUS,
280 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
284 REG_UPDATE(DOMAIN7_PG_CONFIG,
285 DOMAIN7_POWER_GATE, power_gate);
287 REG_WAIT(DOMAIN7_PG_STATUS,
288 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
297 static void hubp_pg_control(
298 struct dce_hwseq *hws,
299 unsigned int hubp_inst,
302 uint32_t power_gate = power_on ? 0 : 1;
303 uint32_t pwr_status = power_on ? 0 : 2;
305 if (hws->ctx->dc->debug.disable_hubp_power_gate)
309 case 0: /* DCHUBP0 */
310 REG_UPDATE(DOMAIN0_PG_CONFIG,
311 DOMAIN0_POWER_GATE, power_gate);
313 REG_WAIT(DOMAIN0_PG_STATUS,
314 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
317 case 1: /* DCHUBP1 */
318 REG_UPDATE(DOMAIN2_PG_CONFIG,
319 DOMAIN2_POWER_GATE, power_gate);
321 REG_WAIT(DOMAIN2_PG_STATUS,
322 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
325 case 2: /* DCHUBP2 */
326 REG_UPDATE(DOMAIN4_PG_CONFIG,
327 DOMAIN4_POWER_GATE, power_gate);
329 REG_WAIT(DOMAIN4_PG_STATUS,
330 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
333 case 3: /* DCHUBP3 */
334 REG_UPDATE(DOMAIN6_PG_CONFIG,
335 DOMAIN6_POWER_GATE, power_gate);
337 REG_WAIT(DOMAIN6_PG_STATUS,
338 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
347 static void power_on_plane(
348 struct dce_hwseq *hws,
351 if (REG(DC_IP_REQUEST_CNTL)) {
352 REG_SET(DC_IP_REQUEST_CNTL, 0,
354 dpp_pg_control(hws, plane_id, true);
355 hubp_pg_control(hws, plane_id, true);
356 REG_SET(DC_IP_REQUEST_CNTL, 0,
358 dm_logger_write(hws->ctx->logger, LOG_DEBUG,
359 "Un-gated front end for pipe %d\n", plane_id);
363 static void undo_DEGVIDCN10_253_wa(struct dc *dc)
365 struct dce_hwseq *hws = dc->hwseq;
366 struct hubp *hubp = dc->res_pool->hubps[0];
368 if (!hws->wa_state.DEGVIDCN10_253_applied)
371 hubp->funcs->set_blank(hubp, true);
373 REG_SET(DC_IP_REQUEST_CNTL, 0,
376 hubp_pg_control(hws, 0, false);
377 REG_SET(DC_IP_REQUEST_CNTL, 0,
380 hws->wa_state.DEGVIDCN10_253_applied = false;
383 static void apply_DEGVIDCN10_253_wa(struct dc *dc)
385 struct dce_hwseq *hws = dc->hwseq;
386 struct hubp *hubp = dc->res_pool->hubps[0];
389 if (dc->debug.disable_stutter)
392 if (!hws->wa.DEGVIDCN10_253)
395 for (i = 0; i < dc->res_pool->pipe_count; i++) {
396 if (!dc->res_pool->hubps[i]->power_gated)
400 /* all pipe power gated, apply work around to enable stutter. */
402 REG_SET(DC_IP_REQUEST_CNTL, 0,
405 hubp_pg_control(hws, 0, true);
406 REG_SET(DC_IP_REQUEST_CNTL, 0,
409 hubp->funcs->set_hubp_blank_en(hubp, false);
410 hws->wa_state.DEGVIDCN10_253_applied = true;
413 static void bios_golden_init(struct dc *dc)
415 struct dc_bios *bp = dc->ctx->dc_bios;
418 /* initialize dcn global */
419 bp->funcs->enable_disp_power_gating(bp,
420 CONTROLLER_ID_D0, ASIC_PIPE_INIT);
422 for (i = 0; i < dc->res_pool->pipe_count; i++) {
423 /* initialize dcn per pipe */
424 bp->funcs->enable_disp_power_gating(bp,
425 CONTROLLER_ID_D0 + i, ASIC_PIPE_DISABLE);
429 static void false_optc_underflow_wa(
431 const struct dc_stream_state *stream,
432 struct timing_generator *tg)
437 if (!dc->hwseq->wa.false_optc_underflow)
440 underflow = tg->funcs->is_optc_underflow_occurred(tg);
442 for (i = 0; i < dc->res_pool->pipe_count; i++) {
443 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
445 if (old_pipe_ctx->stream != stream)
448 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, old_pipe_ctx);
451 tg->funcs->set_blank_data_double_buffer(tg, true);
453 if (tg->funcs->is_optc_underflow_occurred(tg) && !underflow)
454 tg->funcs->clear_optc_underflow(tg);
457 static enum dc_status dcn10_prog_pixclk_crtc_otg(
458 struct pipe_ctx *pipe_ctx,
459 struct dc_state *context,
462 struct dc_stream_state *stream = pipe_ctx->stream;
463 enum dc_color_space color_space;
464 struct tg_color black_color = {0};
466 /* by upper caller loop, pipe0 is parent pipe and be called first.
467 * back end is set up by for pipe0. Other children pipe share back end
468 * with pipe 0. No program is needed.
470 if (pipe_ctx->top_pipe != NULL)
473 /* TODO check if timing_changed, disable stream if timing changed */
475 /* HW program guide assume display already disable
476 * by unplug sequence. OTG assume stop.
478 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
480 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
481 pipe_ctx->clock_source,
482 &pipe_ctx->stream_res.pix_clk_params,
483 &pipe_ctx->pll_settings)) {
485 return DC_ERROR_UNEXPECTED;
487 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
488 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
489 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
490 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
492 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
494 pipe_ctx->stream_res.tg->funcs->program_timing(
495 pipe_ctx->stream_res.tg,
499 #if 0 /* move to after enable_crtc */
500 /* TODO: OPP FMT, ABM. etc. should be done here. */
501 /* or FPGA now. instance 0 only. TODO: move to opp.c */
503 inst_offset = reg_offsets[pipe_ctx->stream_res.tg->inst].fmt;
505 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
506 pipe_ctx->stream_res.opp,
507 &stream->bit_depth_params,
510 /* program otg blank color */
511 color_space = stream->output_color_space;
512 color_space_to_black_color(dc, color_space, &black_color);
514 if (pipe_ctx->stream_res.tg->funcs->set_blank_color)
515 pipe_ctx->stream_res.tg->funcs->set_blank_color(
516 pipe_ctx->stream_res.tg,
519 if (pipe_ctx->stream_res.tg->funcs->is_blanked &&
520 !pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg)) {
521 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
522 hwss_wait_for_blank_complete(pipe_ctx->stream_res.tg);
523 false_optc_underflow_wa(dc, pipe_ctx->stream, pipe_ctx->stream_res.tg);
526 /* VTG is within DCHUB command block. DCFCLK is always on */
527 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
529 return DC_ERROR_UNEXPECTED;
532 /* TODO program crtc source select for non-virtual signal*/
533 /* TODO program FMT */
534 /* TODO setup link_enc */
535 /* TODO set stream attributes */
536 /* TODO program audio */
537 /* TODO enable stream if timing changed */
538 /* TODO unblank stream if DP */
543 static void reset_back_end_for_pipe(
545 struct pipe_ctx *pipe_ctx,
546 struct dc_state *context)
550 if (pipe_ctx->stream_res.stream_enc == NULL) {
551 pipe_ctx->stream = NULL;
555 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
556 /* DPMS may already disable */
557 if (!pipe_ctx->stream->dpms_off)
558 core_link_disable_stream(pipe_ctx, FREE_ACQUIRED_RESOURCE);
561 /* by upper caller loop, parent pipe: pipe0, will be reset last.
562 * back end share by all pipes and will be disable only when disable
565 if (pipe_ctx->top_pipe == NULL) {
566 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
568 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
571 for (i = 0; i < dc->res_pool->pipe_count; i++)
572 if (&dc->current_state->res_ctx.pipe_ctx[i] == pipe_ctx)
575 if (i == dc->res_pool->pipe_count)
578 pipe_ctx->stream = NULL;
579 dm_logger_write(dc->ctx->logger, LOG_DEBUG,
580 "Reset back end for pipe %d, tg:%d\n",
581 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
584 static void dcn10_verify_allow_pstate_change_high(struct dc *dc)
586 static bool should_log_hw_state; /* prevent hw state log by default */
588 if (!hubbub1_verify_allow_pstate_change_high(dc->res_pool->hubbub)) {
589 if (should_log_hw_state) {
590 dcn10_log_hw_state(dc);
597 /* trigger HW to start disconnect plane from stream on the next vsync */
598 static void plane_atomic_disconnect(struct dc *dc, struct pipe_ctx *pipe_ctx)
600 struct hubp *hubp = pipe_ctx->plane_res.hubp;
601 int dpp_id = pipe_ctx->plane_res.dpp->inst;
602 struct mpc *mpc = dc->res_pool->mpc;
604 struct mpc_tree *mpc_tree_params;
605 struct mpcc *mpcc_to_remove = NULL;
607 /* look at tree rather than mi here to know if we already reset */
608 for (opp_id = 0; opp_id < dc->res_pool->pipe_count; opp_id++) {
609 struct output_pixel_processor *opp = dc->res_pool->opps[opp_id];
611 mpc_tree_params = &(opp->mpc_tree_params);
612 mpcc_to_remove = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, dpp_id);
613 if (mpcc_to_remove != NULL)
618 if (opp_id == dc->res_pool->pipe_count)
621 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, mpcc_to_remove);
622 dc->res_pool->opps[opp_id]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
624 dc->optimized_required = true;
626 if (hubp->funcs->hubp_disconnect)
627 hubp->funcs->hubp_disconnect(hubp);
629 if (dc->debug.sanity_checks)
630 dcn10_verify_allow_pstate_change_high(dc);
633 static void plane_atomic_power_down(struct dc *dc, struct pipe_ctx *pipe_ctx)
635 struct dce_hwseq *hws = dc->hwseq;
636 struct dpp *dpp = pipe_ctx->plane_res.dpp;
638 if (REG(DC_IP_REQUEST_CNTL)) {
639 REG_SET(DC_IP_REQUEST_CNTL, 0,
641 dpp_pg_control(hws, dpp->inst, false);
642 hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, false);
643 dpp->funcs->dpp_reset(dpp);
644 REG_SET(DC_IP_REQUEST_CNTL, 0,
646 dm_logger_write(dc->ctx->logger, LOG_DEBUG,
647 "Power gated front end %d\n", pipe_ctx->pipe_idx);
651 /* disable HW used by plane.
652 * note: cannot disable until disconnect is complete
654 static void plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
656 struct dce_hwseq *hws = dc->hwseq;
657 struct hubp *hubp = pipe_ctx->plane_res.hubp;
658 int opp_id = hubp->opp_id;
659 int dpp_id = pipe_ctx->plane_res.dpp->inst;
661 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
663 hubp->funcs->hubp_clk_cntl(hubp, false);
665 REG_UPDATE(DPP_CONTROL[dpp_id],
666 DPP_CLOCK_ENABLE, 0);
668 if (opp_id != 0xf && dc->res_pool->opps[opp_id]->mpc_tree_params.opp_list == NULL)
669 REG_UPDATE(OPP_PIPE_CONTROL[opp_id],
670 OPP_PIPE_CLOCK_EN, 0);
672 hubp->power_gated = true;
673 dc->optimized_required = false; /* We're powering off, no need to optimize */
675 plane_atomic_power_down(dc, pipe_ctx);
677 pipe_ctx->stream = NULL;
678 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
679 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
680 pipe_ctx->top_pipe = NULL;
681 pipe_ctx->bottom_pipe = NULL;
682 pipe_ctx->plane_state = NULL;
685 static void dcn10_disable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx)
687 if (dc->res_pool->hubps[pipe_ctx->pipe_idx]->power_gated)
690 plane_atomic_disable(dc, pipe_ctx);
692 apply_DEGVIDCN10_253_wa(dc);
694 dm_logger_write(dc->ctx->logger, LOG_DC,
695 "Power down front end %d\n",
699 static void dcn10_init_hw(struct dc *dc)
702 struct abm *abm = dc->res_pool->abm;
703 struct dmcu *dmcu = dc->res_pool->dmcu;
704 struct dce_hwseq *hws = dc->hwseq;
705 struct dc_bios *dcb = dc->ctx->dc_bios;
706 struct dc_state *context = dc->current_state;
708 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
709 REG_WRITE(REFCLK_CNTL, 0);
710 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
711 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
713 if (!dc->debug.disable_clock_gate) {
714 /* enable all DCN clock gating */
715 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
717 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
719 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
722 enable_power_gating_plane(dc->hwseq, true);
725 /* end of FPGA. Below if real ASIC */
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);
745 for (i = 0; i < dc->res_pool->pipe_count; i++) {
746 struct timing_generator *tg = dc->res_pool->timing_generators[i];
748 if (tg->funcs->is_tg_enabled(tg))
752 /* Blank controller using driver code instead of
755 for (i = 0; i < dc->res_pool->pipe_count; i++) {
756 struct timing_generator *tg = dc->res_pool->timing_generators[i];
758 if (tg->funcs->is_tg_enabled(tg)) {
759 tg->funcs->set_blank(tg, true);
760 hwss_wait_for_blank_complete(tg);
764 /* Reset all MPCC muxes */
765 dc->res_pool->mpc->funcs->mpc_init(dc->res_pool->mpc);
767 for (i = 0; i < dc->res_pool->pipe_count; i++) {
768 struct timing_generator *tg = dc->res_pool->timing_generators[i];
769 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
770 struct hubp *hubp = dc->res_pool->hubps[i];
771 struct dpp *dpp = dc->res_pool->dpps[i];
773 pipe_ctx->stream_res.tg = tg;
774 pipe_ctx->pipe_idx = i;
776 pipe_ctx->plane_res.hubp = hubp;
777 pipe_ctx->plane_res.dpp = dpp;
778 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
779 hubp->mpcc_id = dpp->inst;
781 hubp->power_gated = false;
783 dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
784 dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
785 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
786 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
788 plane_atomic_disconnect(dc, pipe_ctx);
791 for (i = 0; i < dc->res_pool->pipe_count; i++) {
792 struct timing_generator *tg = dc->res_pool->timing_generators[i];
794 if (tg->funcs->is_tg_enabled(tg))
795 tg->funcs->unlock(tg);
798 for (i = 0; i < dc->res_pool->pipe_count; i++) {
799 struct timing_generator *tg = dc->res_pool->timing_generators[i];
800 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
802 dcn10_disable_plane(dc, pipe_ctx);
804 pipe_ctx->stream_res.tg = NULL;
805 pipe_ctx->plane_res.hubp = NULL;
807 tg->funcs->tg_init(tg);
810 for (i = 0; i < dc->res_pool->audio_count; i++) {
811 struct audio *audio = dc->res_pool->audios[i];
813 audio->funcs->hw_init(audio);
817 abm->funcs->init_backlight(abm);
818 abm->funcs->abm_init(abm);
822 dmcu->funcs->dmcu_init(dmcu);
824 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
825 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
827 if (!dc->debug.disable_clock_gate) {
828 /* enable all DCN clock gating */
829 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
831 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
833 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
836 enable_power_gating_plane(dc->hwseq, true);
839 static void reset_hw_ctx_wrap(
841 struct dc_state *context)
846 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
847 struct pipe_ctx *pipe_ctx_old =
848 &dc->current_state->res_ctx.pipe_ctx[i];
849 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
851 if (!pipe_ctx_old->stream)
854 if (pipe_ctx_old->top_pipe)
857 if (!pipe_ctx->stream ||
858 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
859 struct clock_source *old_clk = pipe_ctx_old->clock_source;
861 reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
863 old_clk->funcs->cs_power_down(old_clk);
869 static bool patch_address_for_sbs_tb_stereo(
870 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
872 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
873 bool sec_split = pipe_ctx->top_pipe &&
874 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
875 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
876 (pipe_ctx->stream->timing.timing_3d_format ==
877 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
878 pipe_ctx->stream->timing.timing_3d_format ==
879 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
880 *addr = plane_state->address.grph_stereo.left_addr;
881 plane_state->address.grph_stereo.left_addr =
882 plane_state->address.grph_stereo.right_addr;
885 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
886 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
887 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
888 plane_state->address.grph_stereo.right_addr =
889 plane_state->address.grph_stereo.left_addr;
897 static void dcn10_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
899 bool addr_patched = false;
900 PHYSICAL_ADDRESS_LOC addr;
901 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
903 if (plane_state == NULL)
905 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
906 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
907 pipe_ctx->plane_res.hubp,
908 &plane_state->address,
909 plane_state->flip_immediate);
910 plane_state->status.requested_address = plane_state->address;
912 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
915 static bool dcn10_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
916 const struct dc_plane_state *plane_state)
918 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
919 const struct dc_transfer_func *tf = NULL;
922 if (dpp_base == NULL)
925 if (plane_state->in_transfer_func)
926 tf = plane_state->in_transfer_func;
928 if (plane_state->gamma_correction && dce_use_lut(plane_state->format))
929 dpp_base->funcs->dpp_program_input_lut(dpp_base, plane_state->gamma_correction);
932 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
933 else if (tf->type == TF_TYPE_PREDEFINED) {
935 case TRANSFER_FUNCTION_SRGB:
936 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_sRGB);
938 case TRANSFER_FUNCTION_BT709:
939 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_xvYCC);
941 case TRANSFER_FUNCTION_LINEAR:
942 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
944 case TRANSFER_FUNCTION_PQ:
949 } else if (tf->type == TF_TYPE_BYPASS) {
950 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
952 /*TF_TYPE_DISTRIBUTED_POINTS*/
964 dcn10_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
965 const struct dc_stream_state *stream)
967 struct dpp *dpp = pipe_ctx->plane_res.dpp;
972 dpp->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
974 if (stream->out_transfer_func &&
975 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
976 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB)
977 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_SRGB);
979 /* dcn10_translate_regamma_to_hw_format takes 750us, only do it when full
982 else if (cm_helper_translate_curve_to_hw_format(
983 stream->out_transfer_func,
984 &dpp->regamma_params, false)) {
985 dpp->funcs->dpp_program_regamma_pwl(
987 &dpp->regamma_params, OPP_REGAMMA_USER);
989 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_BYPASS);
994 static void dcn10_pipe_control_lock(
996 struct pipe_ctx *pipe,
999 struct hubp *hubp = NULL;
1000 hubp = dc->res_pool->hubps[pipe->pipe_idx];
1001 /* use TG master update lock to lock everything on the TG
1002 * therefore only top pipe need to lock
1007 if (dc->debug.sanity_checks)
1008 dcn10_verify_allow_pstate_change_high(dc);
1011 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1013 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1015 if (dc->debug.sanity_checks)
1016 dcn10_verify_allow_pstate_change_high(dc);
1019 static bool wait_for_reset_trigger_to_occur(
1020 struct dc_context *dc_ctx,
1021 struct timing_generator *tg)
1025 /* To avoid endless loop we wait at most
1026 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
1027 const uint32_t frames_to_wait_on_triggered_reset = 10;
1030 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
1032 if (!tg->funcs->is_counter_moving(tg)) {
1033 DC_ERROR("TG counter is not moving!\n");
1037 if (tg->funcs->did_triggered_reset_occur(tg)) {
1039 /* usually occurs at i=1 */
1040 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
1045 /* Wait for one frame. */
1046 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
1047 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
1051 DC_ERROR("GSL: Timeout on reset trigger!\n");
1056 static void dcn10_enable_timing_synchronization(
1060 struct pipe_ctx *grouped_pipes[])
1062 struct dc_context *dc_ctx = dc->ctx;
1065 DC_SYNC_INFO("Setting up OTG reset trigger\n");
1067 for (i = 1; i < group_size; i++)
1068 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
1069 grouped_pipes[i]->stream_res.tg,
1070 grouped_pipes[0]->stream_res.tg->inst);
1072 DC_SYNC_INFO("Waiting for trigger\n");
1074 /* Need to get only check 1 pipe for having reset as all the others are
1075 * synchronized. Look at last pipe programmed to reset.
1078 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[1]->stream_res.tg);
1079 for (i = 1; i < group_size; i++)
1080 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
1081 grouped_pipes[i]->stream_res.tg);
1083 DC_SYNC_INFO("Sync complete\n");
1086 static void dcn10_enable_per_frame_crtc_position_reset(
1089 struct pipe_ctx *grouped_pipes[])
1091 struct dc_context *dc_ctx = dc->ctx;
1094 DC_SYNC_INFO("Setting up\n");
1095 for (i = 0; i < group_size; i++)
1096 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
1097 grouped_pipes[i]->stream_res.tg,
1098 grouped_pipes[i]->stream->triggered_crtc_reset.event_source->status.primary_otg_inst,
1099 &grouped_pipes[i]->stream->triggered_crtc_reset);
1101 DC_SYNC_INFO("Waiting for trigger\n");
1103 for (i = 0; i < group_size; i++)
1104 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
1106 DC_SYNC_INFO("Multi-display sync is complete\n");
1109 /*static void print_rq_dlg_ttu(
1111 struct pipe_ctx *pipe_ctx)
1113 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1114 "\n============== DML TTU Output parameters [%d] ==============\n"
1115 "qos_level_low_wm: %d, \n"
1116 "qos_level_high_wm: %d, \n"
1117 "min_ttu_vblank: %d, \n"
1118 "qos_level_flip: %d, \n"
1119 "refcyc_per_req_delivery_l: %d, \n"
1120 "qos_level_fixed_l: %d, \n"
1121 "qos_ramp_disable_l: %d, \n"
1122 "refcyc_per_req_delivery_pre_l: %d, \n"
1123 "refcyc_per_req_delivery_c: %d, \n"
1124 "qos_level_fixed_c: %d, \n"
1125 "qos_ramp_disable_c: %d, \n"
1126 "refcyc_per_req_delivery_pre_c: %d\n"
1127 "=============================================================\n",
1129 pipe_ctx->ttu_regs.qos_level_low_wm,
1130 pipe_ctx->ttu_regs.qos_level_high_wm,
1131 pipe_ctx->ttu_regs.min_ttu_vblank,
1132 pipe_ctx->ttu_regs.qos_level_flip,
1133 pipe_ctx->ttu_regs.refcyc_per_req_delivery_l,
1134 pipe_ctx->ttu_regs.qos_level_fixed_l,
1135 pipe_ctx->ttu_regs.qos_ramp_disable_l,
1136 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_l,
1137 pipe_ctx->ttu_regs.refcyc_per_req_delivery_c,
1138 pipe_ctx->ttu_regs.qos_level_fixed_c,
1139 pipe_ctx->ttu_regs.qos_ramp_disable_c,
1140 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_c
1143 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1144 "\n============== DML DLG Output parameters [%d] ==============\n"
1145 "refcyc_h_blank_end: %d, \n"
1146 "dlg_vblank_end: %d, \n"
1147 "min_dst_y_next_start: %d, \n"
1148 "refcyc_per_htotal: %d, \n"
1149 "refcyc_x_after_scaler: %d, \n"
1150 "dst_y_after_scaler: %d, \n"
1151 "dst_y_prefetch: %d, \n"
1152 "dst_y_per_vm_vblank: %d, \n"
1153 "dst_y_per_row_vblank: %d, \n"
1154 "ref_freq_to_pix_freq: %d, \n"
1155 "vratio_prefetch: %d, \n"
1156 "refcyc_per_pte_group_vblank_l: %d, \n"
1157 "refcyc_per_meta_chunk_vblank_l: %d, \n"
1158 "dst_y_per_pte_row_nom_l: %d, \n"
1159 "refcyc_per_pte_group_nom_l: %d, \n",
1161 pipe_ctx->dlg_regs.refcyc_h_blank_end,
1162 pipe_ctx->dlg_regs.dlg_vblank_end,
1163 pipe_ctx->dlg_regs.min_dst_y_next_start,
1164 pipe_ctx->dlg_regs.refcyc_per_htotal,
1165 pipe_ctx->dlg_regs.refcyc_x_after_scaler,
1166 pipe_ctx->dlg_regs.dst_y_after_scaler,
1167 pipe_ctx->dlg_regs.dst_y_prefetch,
1168 pipe_ctx->dlg_regs.dst_y_per_vm_vblank,
1169 pipe_ctx->dlg_regs.dst_y_per_row_vblank,
1170 pipe_ctx->dlg_regs.ref_freq_to_pix_freq,
1171 pipe_ctx->dlg_regs.vratio_prefetch,
1172 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_l,
1173 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_l,
1174 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_l,
1175 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_l
1178 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1179 "\ndst_y_per_meta_row_nom_l: %d, \n"
1180 "refcyc_per_meta_chunk_nom_l: %d, \n"
1181 "refcyc_per_line_delivery_pre_l: %d, \n"
1182 "refcyc_per_line_delivery_l: %d, \n"
1183 "vratio_prefetch_c: %d, \n"
1184 "refcyc_per_pte_group_vblank_c: %d, \n"
1185 "refcyc_per_meta_chunk_vblank_c: %d, \n"
1186 "dst_y_per_pte_row_nom_c: %d, \n"
1187 "refcyc_per_pte_group_nom_c: %d, \n"
1188 "dst_y_per_meta_row_nom_c: %d, \n"
1189 "refcyc_per_meta_chunk_nom_c: %d, \n"
1190 "refcyc_per_line_delivery_pre_c: %d, \n"
1191 "refcyc_per_line_delivery_c: %d \n"
1192 "========================================================\n",
1193 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_l,
1194 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_l,
1195 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_l,
1196 pipe_ctx->dlg_regs.refcyc_per_line_delivery_l,
1197 pipe_ctx->dlg_regs.vratio_prefetch_c,
1198 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_c,
1199 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_c,
1200 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_c,
1201 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_c,
1202 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_c,
1203 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_c,
1204 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_c,
1205 pipe_ctx->dlg_regs.refcyc_per_line_delivery_c
1208 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1209 "\n============== DML RQ Output parameters [%d] ==============\n"
1211 "min_chunk_size: %d \n"
1212 "meta_chunk_size: %d \n"
1213 "min_meta_chunk_size: %d \n"
1214 "dpte_group_size: %d \n"
1215 "mpte_group_size: %d \n"
1216 "swath_height: %d \n"
1217 "pte_row_height_linear: %d \n"
1218 "========================================================\n",
1220 pipe_ctx->rq_regs.rq_regs_l.chunk_size,
1221 pipe_ctx->rq_regs.rq_regs_l.min_chunk_size,
1222 pipe_ctx->rq_regs.rq_regs_l.meta_chunk_size,
1223 pipe_ctx->rq_regs.rq_regs_l.min_meta_chunk_size,
1224 pipe_ctx->rq_regs.rq_regs_l.dpte_group_size,
1225 pipe_ctx->rq_regs.rq_regs_l.mpte_group_size,
1226 pipe_ctx->rq_regs.rq_regs_l.swath_height,
1227 pipe_ctx->rq_regs.rq_regs_l.pte_row_height_linear
1232 static void mmhub_read_vm_system_aperture_settings(struct dcn10_hubp *hubp1,
1233 struct vm_system_aperture_param *apt,
1234 struct dce_hwseq *hws)
1236 PHYSICAL_ADDRESS_LOC physical_page_number;
1237 uint32_t logical_addr_low;
1238 uint32_t logical_addr_high;
1240 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
1241 PHYSICAL_PAGE_NUMBER_MSB, &physical_page_number.high_part);
1242 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
1243 PHYSICAL_PAGE_NUMBER_LSB, &physical_page_number.low_part);
1245 REG_GET(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1246 LOGICAL_ADDR, &logical_addr_low);
1248 REG_GET(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1249 LOGICAL_ADDR, &logical_addr_high);
1251 apt->sys_default.quad_part = physical_page_number.quad_part << 12;
1252 apt->sys_low.quad_part = (int64_t)logical_addr_low << 18;
1253 apt->sys_high.quad_part = (int64_t)logical_addr_high << 18;
1256 /* Temporary read settings, future will get values from kmd directly */
1257 static void mmhub_read_vm_context0_settings(struct dcn10_hubp *hubp1,
1258 struct vm_context0_param *vm0,
1259 struct dce_hwseq *hws)
1261 PHYSICAL_ADDRESS_LOC fb_base;
1262 PHYSICAL_ADDRESS_LOC fb_offset;
1263 uint32_t fb_base_value;
1264 uint32_t fb_offset_value;
1266 REG_GET(DCHUBBUB_SDPIF_FB_BASE, SDPIF_FB_BASE, &fb_base_value);
1267 REG_GET(DCHUBBUB_SDPIF_FB_OFFSET, SDPIF_FB_OFFSET, &fb_offset_value);
1269 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
1270 PAGE_DIRECTORY_ENTRY_HI32, &vm0->pte_base.high_part);
1271 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
1272 PAGE_DIRECTORY_ENTRY_LO32, &vm0->pte_base.low_part);
1274 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
1275 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_start.high_part);
1276 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
1277 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_start.low_part);
1279 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
1280 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_end.high_part);
1281 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
1282 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_end.low_part);
1284 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
1285 PHYSICAL_PAGE_ADDR_HI4, &vm0->fault_default.high_part);
1286 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
1287 PHYSICAL_PAGE_ADDR_LO32, &vm0->fault_default.low_part);
1290 * The values in VM_CONTEXT0_PAGE_TABLE_BASE_ADDR is in UMA space.
1291 * Therefore we need to do
1292 * DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
1293 * - DCHUBBUB_SDPIF_FB_OFFSET + DCHUBBUB_SDPIF_FB_BASE
1295 fb_base.quad_part = (uint64_t)fb_base_value << 24;
1296 fb_offset.quad_part = (uint64_t)fb_offset_value << 24;
1297 vm0->pte_base.quad_part += fb_base.quad_part;
1298 vm0->pte_base.quad_part -= fb_offset.quad_part;
1302 static void dcn10_program_pte_vm(struct dce_hwseq *hws, struct hubp *hubp)
1304 struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
1305 struct vm_system_aperture_param apt = { {{ 0 } } };
1306 struct vm_context0_param vm0 = { { { 0 } } };
1308 mmhub_read_vm_system_aperture_settings(hubp1, &apt, hws);
1309 mmhub_read_vm_context0_settings(hubp1, &vm0, hws);
1311 hubp->funcs->hubp_set_vm_system_aperture_settings(hubp, &apt);
1312 hubp->funcs->hubp_set_vm_context0_settings(hubp, &vm0);
1315 static void dcn10_enable_plane(
1317 struct pipe_ctx *pipe_ctx,
1318 struct dc_state *context)
1320 struct dce_hwseq *hws = dc->hwseq;
1322 if (dc->debug.sanity_checks) {
1323 dcn10_verify_allow_pstate_change_high(dc);
1326 undo_DEGVIDCN10_253_wa(dc);
1328 power_on_plane(dc->hwseq,
1329 pipe_ctx->plane_res.hubp->inst);
1331 /* enable DCFCLK current DCHUB */
1332 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true);
1334 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1335 REG_UPDATE(OPP_PIPE_CONTROL[pipe_ctx->stream_res.tg->inst],
1336 OPP_PIPE_CLOCK_EN, 1);
1338 /* TODO: enable/disable in dm as per update type.
1340 dm_logger_write(dc->ctx->logger, LOG_DC,
1341 "Pipe:%d 0x%x: addr hi:0x%x, "
1344 " %d; dst: %d, %d, %d, %d;\n",
1347 plane_state->address.grph.addr.high_part,
1348 plane_state->address.grph.addr.low_part,
1349 plane_state->src_rect.x,
1350 plane_state->src_rect.y,
1351 plane_state->src_rect.width,
1352 plane_state->src_rect.height,
1353 plane_state->dst_rect.x,
1354 plane_state->dst_rect.y,
1355 plane_state->dst_rect.width,
1356 plane_state->dst_rect.height);
1358 dm_logger_write(dc->ctx->logger, LOG_DC,
1359 "Pipe %d: width, height, x, y format:%d\n"
1360 "viewport:%d, %d, %d, %d\n"
1361 "recout: %d, %d, %d, %d\n",
1363 plane_state->format,
1364 pipe_ctx->plane_res.scl_data.viewport.width,
1365 pipe_ctx->plane_res.scl_data.viewport.height,
1366 pipe_ctx->plane_res.scl_data.viewport.x,
1367 pipe_ctx->plane_res.scl_data.viewport.y,
1368 pipe_ctx->plane_res.scl_data.recout.width,
1369 pipe_ctx->plane_res.scl_data.recout.height,
1370 pipe_ctx->plane_res.scl_data.recout.x,
1371 pipe_ctx->plane_res.scl_data.recout.y);
1372 print_rq_dlg_ttu(dc, pipe_ctx);
1375 if (dc->config.gpu_vm_support)
1376 dcn10_program_pte_vm(hws, pipe_ctx->plane_res.hubp);
1378 if (dc->debug.sanity_checks) {
1379 dcn10_verify_allow_pstate_change_high(dc);
1383 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
1386 struct dpp_grph_csc_adjustment adjust;
1387 memset(&adjust, 0, sizeof(adjust));
1388 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
1391 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
1392 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
1393 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
1394 adjust.temperature_matrix[i] =
1395 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
1398 pipe_ctx->plane_res.dpp->funcs->dpp_set_gamut_remap(pipe_ctx->plane_res.dpp, &adjust);
1402 static void program_csc_matrix(struct pipe_ctx *pipe_ctx,
1403 enum dc_color_space colorspace,
1406 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1407 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1408 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment(pipe_ctx->plane_res.dpp, matrix);
1410 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default != NULL)
1411 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default(pipe_ctx->plane_res.dpp, colorspace);
1415 static void program_output_csc(struct dc *dc,
1416 struct pipe_ctx *pipe_ctx,
1417 enum dc_color_space colorspace,
1421 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1422 program_csc_matrix(pipe_ctx,
1427 static bool is_lower_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1429 if (pipe_ctx->plane_state->visible)
1431 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1436 static bool is_upper_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1438 if (pipe_ctx->plane_state->visible)
1440 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1445 static bool is_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1447 if (pipe_ctx->plane_state->visible)
1449 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1451 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1456 static bool is_rgb_cspace(enum dc_color_space output_color_space)
1458 switch (output_color_space) {
1459 case COLOR_SPACE_SRGB:
1460 case COLOR_SPACE_SRGB_LIMITED:
1461 case COLOR_SPACE_2020_RGB_FULLRANGE:
1462 case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
1463 case COLOR_SPACE_ADOBERGB:
1465 case COLOR_SPACE_YCBCR601:
1466 case COLOR_SPACE_YCBCR709:
1467 case COLOR_SPACE_YCBCR601_LIMITED:
1468 case COLOR_SPACE_YCBCR709_LIMITED:
1469 case COLOR_SPACE_2020_YCBCR:
1472 /* Add a case to switch */
1473 BREAK_TO_DEBUGGER();
1478 static void dcn10_get_surface_visual_confirm_color(
1479 const struct pipe_ctx *pipe_ctx,
1480 struct tg_color *color)
1482 uint32_t color_value = MAX_TG_COLOR_VALUE;
1484 switch (pipe_ctx->plane_res.scl_data.format) {
1485 case PIXEL_FORMAT_ARGB8888:
1486 /* set boarder color to red */
1487 color->color_r_cr = color_value;
1490 case PIXEL_FORMAT_ARGB2101010:
1491 /* set boarder color to blue */
1492 color->color_b_cb = color_value;
1494 case PIXEL_FORMAT_420BPP8:
1495 /* set boarder color to green */
1496 color->color_g_y = color_value;
1498 case PIXEL_FORMAT_420BPP10:
1499 /* set boarder color to yellow */
1500 color->color_g_y = color_value;
1501 color->color_r_cr = color_value;
1503 case PIXEL_FORMAT_FP16:
1504 /* set boarder color to white */
1505 color->color_r_cr = color_value;
1506 color->color_b_cb = color_value;
1507 color->color_g_y = color_value;
1514 static uint16_t fixed_point_to_int_frac(
1515 struct fixed31_32 arg,
1516 uint8_t integer_bits,
1517 uint8_t fractional_bits)
1520 int32_t divisor = 1 << fractional_bits;
1524 uint16_t d = (uint16_t)dal_fixed31_32_floor(
1528 if (d <= (uint16_t)(1 << integer_bits) - (1 / (uint16_t)divisor))
1529 numerator = (uint16_t)dal_fixed31_32_floor(
1530 dal_fixed31_32_mul_int(
1534 numerator = dal_fixed31_32_floor(
1536 dal_fixed31_32_from_int(
1537 1LL << integer_bits),
1538 dal_fixed31_32_recip(
1539 dal_fixed31_32_from_int(
1544 result = (uint16_t)numerator;
1546 result = (uint16_t)(
1547 (1 << (integer_bits + fractional_bits + 1)) + numerator);
1549 if ((result != 0) && dal_fixed31_32_lt(
1550 arg, dal_fixed31_32_zero))
1551 result |= 1 << (integer_bits + fractional_bits);
1556 void build_prescale_params(struct dc_bias_and_scale *bias_and_scale,
1557 const struct dc_plane_state *plane_state)
1559 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1560 && plane_state->format != SURFACE_PIXEL_FORMAT_INVALID
1561 && plane_state->input_csc_color_matrix.enable_adjustment
1562 && plane_state->coeff_reduction_factor.value != 0) {
1563 bias_and_scale->scale_blue = fixed_point_to_int_frac(
1564 dal_fixed31_32_mul(plane_state->coeff_reduction_factor,
1565 dal_fixed31_32_from_fraction(256, 255)),
1568 bias_and_scale->scale_red = bias_and_scale->scale_blue;
1569 bias_and_scale->scale_green = bias_and_scale->scale_blue;
1571 bias_and_scale->scale_blue = 0x2000;
1572 bias_and_scale->scale_red = 0x2000;
1573 bias_and_scale->scale_green = 0x2000;
1577 static void update_dpp(struct dpp *dpp, struct dc_plane_state *plane_state)
1579 struct dc_bias_and_scale bns_params = {0};
1581 // program the input csc
1582 dpp->funcs->dpp_setup(dpp,
1583 plane_state->format,
1584 EXPANSION_MODE_ZERO,
1585 plane_state->input_csc_color_matrix,
1586 COLOR_SPACE_YCBCR601_LIMITED);
1588 //set scale and bias registers
1589 build_prescale_params(&bns_params, plane_state);
1590 if (dpp->funcs->dpp_program_bias_and_scale)
1591 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1594 static void update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
1596 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1597 struct mpcc_blnd_cfg blnd_cfg;
1598 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1600 struct mpcc *new_mpcc;
1601 struct mpc *mpc = dc->res_pool->mpc;
1602 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
1604 /* TODO: proper fix once fpga works */
1606 if (dc->debug.surface_visual_confirm)
1607 dcn10_get_surface_visual_confirm_color(
1608 pipe_ctx, &blnd_cfg.black_color);
1610 color_space_to_black_color(
1611 dc, pipe_ctx->stream->output_color_space,
1612 &blnd_cfg.black_color);
1614 if (per_pixel_alpha)
1615 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
1617 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
1619 blnd_cfg.overlap_only = false;
1620 blnd_cfg.global_alpha = 0xff;
1621 blnd_cfg.global_gain = 0xff;
1623 /* DCN1.0 has output CM before MPC which seems to screw with
1624 * pre-multiplied alpha.
1626 blnd_cfg.pre_multiplied_alpha = is_rgb_cspace(
1627 pipe_ctx->stream->output_color_space)
1632 * Note: currently there is a bug in init_hw such that
1633 * on resume from hibernate, BIOS sets up MPCC0, and
1634 * we do mpcc_remove but the mpcc cannot go to idle
1635 * after remove. This cause us to pick mpcc1 here,
1636 * which causes a pstate hang for yet unknown reason.
1638 mpcc_id = hubp->inst;
1640 /* check if this MPCC is already being used */
1641 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
1642 /* remove MPCC if being used */
1643 if (new_mpcc != NULL)
1644 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
1646 if (dc->debug.sanity_checks)
1647 mpc->funcs->assert_mpcc_idle_before_connect(
1648 dc->res_pool->mpc, mpcc_id);
1650 /* Call MPC to insert new plane */
1651 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
1659 ASSERT(new_mpcc != NULL);
1661 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
1662 hubp->mpcc_id = mpcc_id;
1665 static void update_scaler(struct pipe_ctx *pipe_ctx)
1667 bool per_pixel_alpha =
1668 pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1670 /* TODO: proper fix once fpga works */
1672 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = per_pixel_alpha;
1673 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1674 /* scaler configuration */
1675 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1676 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
1679 static void update_dchubp_dpp(
1681 struct pipe_ctx *pipe_ctx,
1682 struct dc_state *context)
1684 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1685 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1686 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1687 union plane_size size = plane_state->plane_size;
1689 /* depends on DML calculation, DPP clock value may change dynamically */
1690 if (plane_state->update_flags.bits.full_update) {
1693 pipe_ctx->plane_res.dpp->inst,
1694 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk,
1695 context->bw.dcn.calc_clk.dppclk_div);
1696 dc->current_state->bw.dcn.cur_clk.dppclk_div =
1697 context->bw.dcn.calc_clk.dppclk_div;
1698 context->bw.dcn.cur_clk.dppclk_div = context->bw.dcn.calc_clk.dppclk_div;
1701 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
1702 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
1703 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
1705 if (plane_state->update_flags.bits.full_update) {
1706 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst);
1708 hubp->funcs->hubp_setup(
1710 &pipe_ctx->dlg_regs,
1711 &pipe_ctx->ttu_regs,
1713 &pipe_ctx->pipe_dlg_param);
1716 size.grph.surface_size = pipe_ctx->plane_res.scl_data.viewport;
1718 if (plane_state->update_flags.bits.full_update ||
1719 plane_state->update_flags.bits.bpp_change)
1720 update_dpp(dpp, plane_state);
1722 if (plane_state->update_flags.bits.full_update ||
1723 plane_state->update_flags.bits.per_pixel_alpha_change)
1724 update_mpcc(dc, pipe_ctx);
1726 if (plane_state->update_flags.bits.full_update ||
1727 plane_state->update_flags.bits.per_pixel_alpha_change ||
1728 plane_state->update_flags.bits.scaling_change ||
1729 plane_state->update_flags.bits.position_change) {
1730 update_scaler(pipe_ctx);
1733 if (plane_state->update_flags.bits.full_update ||
1734 plane_state->update_flags.bits.scaling_change ||
1735 plane_state->update_flags.bits.position_change) {
1736 hubp->funcs->mem_program_viewport(
1738 &pipe_ctx->plane_res.scl_data.viewport,
1739 &pipe_ctx->plane_res.scl_data.viewport_c);
1742 if (plane_state->update_flags.bits.full_update) {
1744 program_gamut_remap(pipe_ctx);
1746 program_output_csc(dc,
1748 pipe_ctx->stream->output_color_space,
1749 pipe_ctx->stream->csc_color_matrix.matrix,
1753 if (plane_state->update_flags.bits.full_update ||
1754 plane_state->update_flags.bits.horizontal_mirror_change ||
1755 plane_state->update_flags.bits.rotation_change ||
1756 plane_state->update_flags.bits.swizzle_change ||
1757 plane_state->update_flags.bits.dcc_change ||
1758 plane_state->update_flags.bits.bpp_change ||
1759 plane_state->update_flags.bits.scaling_change) {
1760 hubp->funcs->hubp_program_surface_config(
1762 plane_state->format,
1763 &plane_state->tiling_info,
1765 plane_state->rotation,
1767 plane_state->horizontal_mirror);
1770 hubp->power_gated = false;
1772 dc->hwss.update_plane_addr(dc, pipe_ctx);
1774 if (is_pipe_tree_visible(pipe_ctx))
1775 hubp->funcs->set_blank(hubp, false);
1779 static void program_all_pipe_in_tree(
1781 struct pipe_ctx *pipe_ctx,
1782 struct dc_state *context)
1785 if (pipe_ctx->top_pipe == NULL) {
1787 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
1788 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
1789 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
1790 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
1791 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
1793 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1794 pipe_ctx->stream_res.tg);
1796 if (pipe_ctx->stream_res.tg->funcs->set_blank)
1797 pipe_ctx->stream_res.tg->funcs->set_blank(
1798 pipe_ctx->stream_res.tg,
1799 !is_pipe_tree_visible(pipe_ctx));
1802 if (pipe_ctx->plane_state != NULL) {
1803 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1804 dcn10_enable_plane(dc, pipe_ctx, context);
1806 update_dchubp_dpp(dc, pipe_ctx, context);
1808 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
1809 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
1810 pipe_ctx->plane_state->update_flags.bits.gamma_change)
1811 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
1813 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
1814 * only do gamma programming for full update.
1815 * TODO: This can be further optimized/cleaned up
1816 * Always call this for now since it does memcmp inside before
1817 * doing heavy calculation and programming
1819 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1820 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
1823 if (pipe_ctx->bottom_pipe != NULL && pipe_ctx->bottom_pipe != pipe_ctx)
1824 program_all_pipe_in_tree(dc, pipe_ctx->bottom_pipe, context);
1827 static void dcn10_pplib_apply_display_requirements(
1829 struct dc_state *context)
1831 struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
1833 pp_display_cfg->all_displays_in_sync = false;/*todo*/
1834 pp_display_cfg->nb_pstate_switch_disable = false;
1835 pp_display_cfg->min_engine_clock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1836 pp_display_cfg->min_memory_clock_khz = context->bw.dcn.cur_clk.fclk_khz;
1837 pp_display_cfg->min_engine_clock_deep_sleep_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1838 pp_display_cfg->min_dcfc_deep_sleep_clock_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1839 pp_display_cfg->avail_mclk_switch_time_us =
1840 context->bw.dcn.cur_clk.dram_ccm_us > 0 ? context->bw.dcn.cur_clk.dram_ccm_us : 0;
1841 pp_display_cfg->avail_mclk_switch_time_in_disp_active_us =
1842 context->bw.dcn.cur_clk.min_active_dram_ccm_us > 0 ? context->bw.dcn.cur_clk.min_active_dram_ccm_us : 0;
1843 pp_display_cfg->min_dcfclock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1844 pp_display_cfg->disp_clk_khz = context->bw.dcn.cur_clk.dispclk_khz;
1845 dce110_fill_display_configs(context, pp_display_cfg);
1847 if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof(
1848 struct dm_pp_display_configuration)) != 0)
1849 dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
1851 dc->prev_display_config = *pp_display_cfg;
1854 static void optimize_shared_resources(struct dc *dc)
1856 if (dc->current_state->stream_count == 0) {
1858 dcn10_pplib_apply_display_requirements(dc, dc->current_state);
1861 if (dc->debug.pplib_wm_report_mode == WM_REPORT_OVERRIDE)
1862 dcn_bw_notify_pplib_of_wm_ranges(dc);
1865 static void ready_shared_resources(struct dc *dc, struct dc_state *context)
1868 if (dc->current_state->stream_count == 0 &&
1869 context->stream_count != 0)
1870 dcn10_pplib_apply_display_requirements(dc, context);
1873 static struct pipe_ctx *find_top_pipe_for_stream(
1875 struct dc_state *context,
1876 const struct dc_stream_state *stream)
1880 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1881 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1882 struct pipe_ctx *old_pipe_ctx =
1883 &dc->current_state->res_ctx.pipe_ctx[i];
1885 if (!pipe_ctx->plane_state && !old_pipe_ctx->plane_state)
1888 if (pipe_ctx->stream != stream)
1891 if (!pipe_ctx->top_pipe)
1897 static void dcn10_apply_ctx_for_surface(
1899 const struct dc_stream_state *stream,
1901 struct dc_state *context)
1904 struct timing_generator *tg;
1905 struct output_pixel_processor *opp;
1906 bool removed_pipe[4] = { false };
1907 unsigned int ref_clk_mhz = dc->res_pool->ref_clock_inKhz/1000;
1908 bool program_water_mark = false;
1910 struct pipe_ctx *top_pipe_to_program =
1911 find_top_pipe_for_stream(dc, context, stream);
1913 if (!top_pipe_to_program)
1916 opp = top_pipe_to_program->stream_res.opp;
1918 tg = top_pipe_to_program->stream_res.tg;
1920 dcn10_pipe_control_lock(dc, top_pipe_to_program, true);
1922 if (num_planes == 0) {
1924 /* OTG blank before remove all front end */
1925 if (tg->funcs->set_blank)
1926 tg->funcs->set_blank(tg, true);
1929 /* Disconnect unused mpcc */
1930 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1931 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1932 struct pipe_ctx *old_pipe_ctx =
1933 &dc->current_state->res_ctx.pipe_ctx[i];
1935 * Powergate reused pipes that are not powergated
1936 * fairly hacky right now, using opp_id as indicator
1937 * TODO: After move dc_post to dc_update, this will
1940 if (pipe_ctx->plane_state && !old_pipe_ctx->plane_state) {
1941 if (old_pipe_ctx->stream_res.tg == tg &&
1942 old_pipe_ctx->plane_res.hubp &&
1943 old_pipe_ctx->plane_res.hubp->opp_id != 0xf) {
1944 dcn10_disable_plane(dc, pipe_ctx);
1946 * power down fe will unlock when calling reset, need
1947 * to lock it back here. Messy, need rework.
1949 pipe_ctx->stream_res.tg->funcs->lock(pipe_ctx->stream_res.tg);
1953 if (!pipe_ctx->plane_state &&
1954 old_pipe_ctx->plane_state &&
1955 old_pipe_ctx->stream_res.tg == tg) {
1957 plane_atomic_disconnect(dc, old_pipe_ctx);
1958 removed_pipe[i] = true;
1960 dm_logger_write(dc->ctx->logger, LOG_DC,
1961 "Reset mpcc for pipe %d\n",
1962 old_pipe_ctx->pipe_idx);
1967 program_all_pipe_in_tree(dc, top_pipe_to_program, context);
1969 dcn10_pipe_control_lock(dc, top_pipe_to_program, false);
1971 if (num_planes == 0)
1972 false_optc_underflow_wa(dc, stream, tg);
1974 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1975 struct pipe_ctx *old_pipe_ctx =
1976 &dc->current_state->res_ctx.pipe_ctx[i];
1977 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1979 if (pipe_ctx->stream == stream &&
1980 pipe_ctx->plane_state &&
1981 pipe_ctx->plane_state->update_flags.bits.full_update)
1982 program_water_mark = true;
1984 if (removed_pipe[i])
1985 dcn10_disable_plane(dc, old_pipe_ctx);
1988 if (program_water_mark) {
1989 if (dc->debug.sanity_checks) {
1990 /* pstate stuck check after watermark update */
1991 dcn10_verify_allow_pstate_change_high(dc);
1994 /* watermark is for all pipes */
1995 hubbub1_program_watermarks(dc->res_pool->hubbub,
1996 &context->bw.dcn.watermarks, ref_clk_mhz);
1998 if (dc->debug.sanity_checks) {
1999 /* pstate stuck check after watermark update */
2000 dcn10_verify_allow_pstate_change_high(dc);
2003 /* dm_logger_write(dc->ctx->logger, LOG_BANDWIDTH_CALCS,
2004 "\n============== Watermark parameters ==============\n"
2005 "a.urgent_ns: %d \n"
2006 "a.cstate_enter_plus_exit: %d \n"
2007 "a.cstate_exit: %d \n"
2008 "a.pstate_change: %d \n"
2009 "a.pte_meta_urgent: %d \n"
2010 "b.urgent_ns: %d \n"
2011 "b.cstate_enter_plus_exit: %d \n"
2012 "b.cstate_exit: %d \n"
2013 "b.pstate_change: %d \n"
2014 "b.pte_meta_urgent: %d \n",
2015 context->bw.dcn.watermarks.a.urgent_ns,
2016 context->bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns,
2017 context->bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns,
2018 context->bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns,
2019 context->bw.dcn.watermarks.a.pte_meta_urgent_ns,
2020 context->bw.dcn.watermarks.b.urgent_ns,
2021 context->bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns,
2022 context->bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns,
2023 context->bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns,
2024 context->bw.dcn.watermarks.b.pte_meta_urgent_ns
2026 dm_logger_write(dc->ctx->logger, LOG_BANDWIDTH_CALCS,
2027 "\nc.urgent_ns: %d \n"
2028 "c.cstate_enter_plus_exit: %d \n"
2029 "c.cstate_exit: %d \n"
2030 "c.pstate_change: %d \n"
2031 "c.pte_meta_urgent: %d \n"
2032 "d.urgent_ns: %d \n"
2033 "d.cstate_enter_plus_exit: %d \n"
2034 "d.cstate_exit: %d \n"
2035 "d.pstate_change: %d \n"
2036 "d.pte_meta_urgent: %d \n"
2037 "========================================================\n",
2038 context->bw.dcn.watermarks.c.urgent_ns,
2039 context->bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns,
2040 context->bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns,
2041 context->bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns,
2042 context->bw.dcn.watermarks.c.pte_meta_urgent_ns,
2043 context->bw.dcn.watermarks.d.urgent_ns,
2044 context->bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns,
2045 context->bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns,
2046 context->bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns,
2047 context->bw.dcn.watermarks.d.pte_meta_urgent_ns
2052 static void dcn10_set_bandwidth(
2054 struct dc_state *context,
2055 bool decrease_allowed)
2057 struct pp_smu_display_requirement_rv *smu_req_cur =
2058 &dc->res_pool->pp_smu_req;
2059 struct pp_smu_display_requirement_rv smu_req = *smu_req_cur;
2060 struct pp_smu_funcs_rv *pp_smu = dc->res_pool->pp_smu;
2062 if (dc->debug.sanity_checks) {
2063 dcn10_verify_allow_pstate_change_high(dc);
2066 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
2069 if (decrease_allowed || context->bw.dcn.calc_clk.dispclk_khz
2070 > dc->current_state->bw.dcn.cur_clk.dispclk_khz) {
2071 dc->res_pool->display_clock->funcs->set_clock(
2072 dc->res_pool->display_clock,
2073 context->bw.dcn.calc_clk.dispclk_khz);
2074 dc->current_state->bw.dcn.cur_clk.dispclk_khz =
2075 context->bw.dcn.calc_clk.dispclk_khz;
2077 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_khz
2078 > dc->current_state->bw.dcn.cur_clk.dcfclk_khz) {
2079 smu_req.hard_min_dcefclk_khz =
2080 context->bw.dcn.calc_clk.dcfclk_khz;
2082 if (decrease_allowed || context->bw.dcn.calc_clk.fclk_khz
2083 > dc->current_state->bw.dcn.cur_clk.fclk_khz) {
2084 smu_req.hard_min_fclk_khz = context->bw.dcn.calc_clk.fclk_khz;
2086 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz
2087 > dc->current_state->bw.dcn.cur_clk.dcfclk_deep_sleep_khz) {
2088 dc->current_state->bw.dcn.calc_clk.dcfclk_deep_sleep_khz =
2089 context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz;
2090 context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz =
2091 context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz;
2094 smu_req.display_count = context->stream_count;
2096 if (pp_smu->set_display_requirement)
2097 pp_smu->set_display_requirement(&pp_smu->pp_smu, &smu_req);
2099 *smu_req_cur = smu_req;
2101 /* Decrease in freq is increase in period so opposite comparison for dram_ccm */
2102 if (decrease_allowed || context->bw.dcn.calc_clk.dram_ccm_us
2103 < dc->current_state->bw.dcn.cur_clk.dram_ccm_us) {
2104 dc->current_state->bw.dcn.calc_clk.dram_ccm_us =
2105 context->bw.dcn.calc_clk.dram_ccm_us;
2106 context->bw.dcn.cur_clk.dram_ccm_us =
2107 context->bw.dcn.calc_clk.dram_ccm_us;
2109 if (decrease_allowed || context->bw.dcn.calc_clk.min_active_dram_ccm_us
2110 < dc->current_state->bw.dcn.cur_clk.min_active_dram_ccm_us) {
2111 dc->current_state->bw.dcn.calc_clk.min_active_dram_ccm_us =
2112 context->bw.dcn.calc_clk.min_active_dram_ccm_us;
2113 context->bw.dcn.cur_clk.min_active_dram_ccm_us =
2114 context->bw.dcn.calc_clk.min_active_dram_ccm_us;
2116 dcn10_pplib_apply_display_requirements(dc, context);
2118 if (dc->debug.sanity_checks) {
2119 dcn10_verify_allow_pstate_change_high(dc);
2122 /* need to fix this function. not doing the right thing here */
2125 static void set_drr(struct pipe_ctx **pipe_ctx,
2126 int num_pipes, int vmin, int vmax)
2129 struct drr_params params = {0};
2131 params.vertical_total_max = vmax;
2132 params.vertical_total_min = vmin;
2134 /* TODO: If multiple pipes are to be supported, you need
2137 for (i = 0; i < num_pipes; i++) {
2138 pipe_ctx[i]->stream_res.tg->funcs->set_drr(pipe_ctx[i]->stream_res.tg, ¶ms);
2142 static void get_position(struct pipe_ctx **pipe_ctx,
2144 struct crtc_position *position)
2148 /* TODO: handle pipes > 1
2150 for (i = 0; i < num_pipes; i++)
2151 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2154 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2155 int num_pipes, const struct dc_static_screen_events *events)
2158 unsigned int value = 0;
2160 if (events->surface_update)
2162 if (events->cursor_update)
2165 for (i = 0; i < num_pipes; i++)
2166 pipe_ctx[i]->stream_res.tg->funcs->
2167 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
2170 static void set_plane_config(
2171 const struct dc *dc,
2172 struct pipe_ctx *pipe_ctx,
2173 struct resource_context *res_ctx)
2176 program_gamut_remap(pipe_ctx);
2179 static void dcn10_config_stereo_parameters(
2180 struct dc_stream_state *stream, struct crtc_stereo_flags *flags)
2182 enum view_3d_format view_format = stream->view_format;
2183 enum dc_timing_3d_format timing_3d_format =\
2184 stream->timing.timing_3d_format;
2185 bool non_stereo_timing = false;
2187 if (timing_3d_format == TIMING_3D_FORMAT_NONE ||
2188 timing_3d_format == TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2189 timing_3d_format == TIMING_3D_FORMAT_TOP_AND_BOTTOM)
2190 non_stereo_timing = true;
2192 if (non_stereo_timing == false &&
2193 view_format == VIEW_3D_FORMAT_FRAME_SEQUENTIAL) {
2195 flags->PROGRAM_STEREO = 1;
2196 flags->PROGRAM_POLARITY = 1;
2197 if (timing_3d_format == TIMING_3D_FORMAT_INBAND_FA ||
2198 timing_3d_format == TIMING_3D_FORMAT_DP_HDMI_INBAND_FA ||
2199 timing_3d_format == TIMING_3D_FORMAT_SIDEBAND_FA) {
2200 enum display_dongle_type dongle = \
2201 stream->sink->link->ddc->dongle_type;
2202 if (dongle == DISPLAY_DONGLE_DP_VGA_CONVERTER ||
2203 dongle == DISPLAY_DONGLE_DP_DVI_CONVERTER ||
2204 dongle == DISPLAY_DONGLE_DP_HDMI_CONVERTER)
2205 flags->DISABLE_STEREO_DP_SYNC = 1;
2207 flags->RIGHT_EYE_POLARITY =\
2208 stream->timing.flags.RIGHT_EYE_3D_POLARITY;
2209 if (timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2210 flags->FRAME_PACKED = 1;
2216 static void dcn10_setup_stereo(struct pipe_ctx *pipe_ctx, struct dc *dc)
2218 struct crtc_stereo_flags flags = { 0 };
2219 struct dc_stream_state *stream = pipe_ctx->stream;
2221 dcn10_config_stereo_parameters(stream, &flags);
2223 pipe_ctx->stream_res.opp->funcs->opp_program_stereo(
2224 pipe_ctx->stream_res.opp,
2225 flags.PROGRAM_STEREO == 1 ? true:false,
2228 pipe_ctx->stream_res.tg->funcs->program_stereo(
2229 pipe_ctx->stream_res.tg,
2236 static struct hubp *get_hubp_by_inst(struct resource_pool *res_pool, int mpcc_inst)
2240 for (i = 0; i < res_pool->pipe_count; i++) {
2241 if (res_pool->hubps[i]->inst == mpcc_inst)
2242 return res_pool->hubps[i];
2248 static void dcn10_wait_for_mpcc_disconnect(
2250 struct resource_pool *res_pool,
2251 struct pipe_ctx *pipe_ctx)
2255 if (dc->debug.sanity_checks) {
2256 dcn10_verify_allow_pstate_change_high(dc);
2259 if (!pipe_ctx->stream_res.opp)
2262 for (mpcc_inst = 0; mpcc_inst < MAX_PIPES; mpcc_inst++) {
2263 if (pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst]) {
2264 struct hubp *hubp = get_hubp_by_inst(res_pool, mpcc_inst);
2266 res_pool->mpc->funcs->wait_for_idle(res_pool->mpc, mpcc_inst);
2267 pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst] = false;
2268 hubp->funcs->set_blank(hubp, true);
2269 /*dm_logger_write(dc->ctx->logger, LOG_ERROR,
2270 "[debug_mpo: wait_for_mpcc finished waiting on mpcc %d]\n",
2275 if (dc->debug.sanity_checks) {
2276 dcn10_verify_allow_pstate_change_high(dc);
2281 static bool dcn10_dummy_display_power_gating(
2283 uint8_t controller_id,
2284 struct dc_bios *dcb,
2285 enum pipe_gating_control power_gating)
2290 void dcn10_update_pending_status(struct pipe_ctx *pipe_ctx)
2292 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2293 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2295 if (plane_state == NULL)
2298 plane_state->status.is_flip_pending =
2299 pipe_ctx->plane_res.hubp->funcs->hubp_is_flip_pending(
2300 pipe_ctx->plane_res.hubp);
2302 plane_state->status.current_address = pipe_ctx->plane_res.hubp->current_address;
2303 if (pipe_ctx->plane_res.hubp->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2304 tg->funcs->is_stereo_left_eye) {
2305 plane_state->status.is_right_eye =
2306 !tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2310 void dcn10_update_dchub(struct dce_hwseq *hws, struct dchub_init_data *dh_data)
2312 if (hws->ctx->dc->res_pool->hubbub != NULL)
2313 hubbub1_update_dchub(hws->ctx->dc->res_pool->hubbub, dh_data);
2316 static const struct hw_sequencer_funcs dcn10_funcs = {
2317 .program_gamut_remap = program_gamut_remap,
2318 .program_csc_matrix = program_csc_matrix,
2319 .init_hw = dcn10_init_hw,
2320 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2321 .apply_ctx_for_surface = dcn10_apply_ctx_for_surface,
2322 .set_plane_config = set_plane_config,
2323 .update_plane_addr = dcn10_update_plane_addr,
2324 .update_dchub = dcn10_update_dchub,
2325 .update_pending_status = dcn10_update_pending_status,
2326 .set_input_transfer_func = dcn10_set_input_transfer_func,
2327 .set_output_transfer_func = dcn10_set_output_transfer_func,
2328 .power_down = dce110_power_down,
2329 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2330 .enable_timing_synchronization = dcn10_enable_timing_synchronization,
2331 .enable_per_frame_crtc_position_reset = dcn10_enable_per_frame_crtc_position_reset,
2332 .update_info_frame = dce110_update_info_frame,
2333 .enable_stream = dce110_enable_stream,
2334 .disable_stream = dce110_disable_stream,
2335 .unblank_stream = dce110_unblank_stream,
2336 .enable_display_power_gating = dcn10_dummy_display_power_gating,
2337 .disable_plane = dcn10_disable_plane,
2338 .pipe_control_lock = dcn10_pipe_control_lock,
2339 .set_bandwidth = dcn10_set_bandwidth,
2340 .reset_hw_ctx_wrap = reset_hw_ctx_wrap,
2341 .prog_pixclk_crtc_otg = dcn10_prog_pixclk_crtc_otg,
2343 .get_position = get_position,
2344 .set_static_screen_control = set_static_screen_control,
2345 .setup_stereo = dcn10_setup_stereo,
2346 .set_avmute = dce110_set_avmute,
2347 .log_hw_state = dcn10_log_hw_state,
2348 .wait_for_mpcc_disconnect = dcn10_wait_for_mpcc_disconnect,
2349 .ready_shared_resources = ready_shared_resources,
2350 .optimize_shared_resources = optimize_shared_resources,
2351 .pplib_apply_display_requirements =
2352 dcn10_pplib_apply_display_requirements,
2353 .edp_backlight_control = hwss_edp_backlight_control,
2354 .edp_power_control = hwss_edp_power_control,
2355 .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready,
2359 void dcn10_hw_sequencer_construct(struct dc *dc)
2361 dc->hwss = dcn10_funcs;