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 unsigned int in_vga1_mode = 0;
242 unsigned int in_vga2_mode = 0;
243 unsigned int in_vga3_mode = 0;
244 unsigned int in_vga4_mode = 0;
246 REG_GET(D1VGA_CONTROL, D1VGA_MODE_ENABLE, &in_vga1_mode);
247 REG_GET(D2VGA_CONTROL, D2VGA_MODE_ENABLE, &in_vga2_mode);
248 REG_GET(D3VGA_CONTROL, D3VGA_MODE_ENABLE, &in_vga3_mode);
249 REG_GET(D4VGA_CONTROL, D4VGA_MODE_ENABLE, &in_vga4_mode);
251 if (in_vga1_mode == 0 && in_vga2_mode == 0 &&
252 in_vga3_mode == 0 && in_vga4_mode == 0)
255 REG_WRITE(D1VGA_CONTROL, 0);
256 REG_WRITE(D2VGA_CONTROL, 0);
257 REG_WRITE(D3VGA_CONTROL, 0);
258 REG_WRITE(D4VGA_CONTROL, 0);
260 /* HW Engineer's Notes:
261 * During switch from vga->extended, if we set the VGA_TEST_ENABLE and
262 * then hit the VGA_TEST_RENDER_START, then the DCHUBP timing gets updated correctly.
264 * Then vBIOS will have it poll for the VGA_TEST_RENDER_DONE and unset
265 * VGA_TEST_ENABLE, to leave it in the same state as before.
267 REG_UPDATE(VGA_TEST_CONTROL, VGA_TEST_ENABLE, 1);
268 REG_UPDATE(VGA_TEST_CONTROL, VGA_TEST_RENDER_START, 1);
271 static void dpp_pg_control(
272 struct dce_hwseq *hws,
273 unsigned int dpp_inst,
276 uint32_t power_gate = power_on ? 0 : 1;
277 uint32_t pwr_status = power_on ? 0 : 2;
279 if (hws->ctx->dc->debug.disable_dpp_power_gate)
284 REG_UPDATE(DOMAIN1_PG_CONFIG,
285 DOMAIN1_POWER_GATE, power_gate);
287 REG_WAIT(DOMAIN1_PG_STATUS,
288 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
292 REG_UPDATE(DOMAIN3_PG_CONFIG,
293 DOMAIN3_POWER_GATE, power_gate);
295 REG_WAIT(DOMAIN3_PG_STATUS,
296 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
300 REG_UPDATE(DOMAIN5_PG_CONFIG,
301 DOMAIN5_POWER_GATE, power_gate);
303 REG_WAIT(DOMAIN5_PG_STATUS,
304 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
308 REG_UPDATE(DOMAIN7_PG_CONFIG,
309 DOMAIN7_POWER_GATE, power_gate);
311 REG_WAIT(DOMAIN7_PG_STATUS,
312 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
321 static void hubp_pg_control(
322 struct dce_hwseq *hws,
323 unsigned int hubp_inst,
326 uint32_t power_gate = power_on ? 0 : 1;
327 uint32_t pwr_status = power_on ? 0 : 2;
329 if (hws->ctx->dc->debug.disable_hubp_power_gate)
333 case 0: /* DCHUBP0 */
334 REG_UPDATE(DOMAIN0_PG_CONFIG,
335 DOMAIN0_POWER_GATE, power_gate);
337 REG_WAIT(DOMAIN0_PG_STATUS,
338 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
341 case 1: /* DCHUBP1 */
342 REG_UPDATE(DOMAIN2_PG_CONFIG,
343 DOMAIN2_POWER_GATE, power_gate);
345 REG_WAIT(DOMAIN2_PG_STATUS,
346 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
349 case 2: /* DCHUBP2 */
350 REG_UPDATE(DOMAIN4_PG_CONFIG,
351 DOMAIN4_POWER_GATE, power_gate);
353 REG_WAIT(DOMAIN4_PG_STATUS,
354 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
357 case 3: /* DCHUBP3 */
358 REG_UPDATE(DOMAIN6_PG_CONFIG,
359 DOMAIN6_POWER_GATE, power_gate);
361 REG_WAIT(DOMAIN6_PG_STATUS,
362 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
371 static void power_on_plane(
372 struct dce_hwseq *hws,
375 if (REG(DC_IP_REQUEST_CNTL)) {
376 REG_SET(DC_IP_REQUEST_CNTL, 0,
378 dpp_pg_control(hws, plane_id, true);
379 hubp_pg_control(hws, plane_id, true);
380 REG_SET(DC_IP_REQUEST_CNTL, 0,
382 dm_logger_write(hws->ctx->logger, LOG_DEBUG,
383 "Un-gated front end for pipe %d\n", plane_id);
387 static void undo_DEGVIDCN10_253_wa(struct dc *dc)
389 struct dce_hwseq *hws = dc->hwseq;
390 struct hubp *hubp = dc->res_pool->hubps[0];
392 if (!hws->wa_state.DEGVIDCN10_253_applied)
395 hubp->funcs->set_blank(hubp, true);
397 REG_SET(DC_IP_REQUEST_CNTL, 0,
400 hubp_pg_control(hws, 0, false);
401 REG_SET(DC_IP_REQUEST_CNTL, 0,
404 hws->wa_state.DEGVIDCN10_253_applied = false;
407 static void apply_DEGVIDCN10_253_wa(struct dc *dc)
409 struct dce_hwseq *hws = dc->hwseq;
410 struct hubp *hubp = dc->res_pool->hubps[0];
413 if (dc->debug.disable_stutter)
416 if (!hws->wa.DEGVIDCN10_253)
419 for (i = 0; i < dc->res_pool->pipe_count; i++) {
420 if (!dc->res_pool->hubps[i]->power_gated)
424 /* all pipe power gated, apply work around to enable stutter. */
426 REG_SET(DC_IP_REQUEST_CNTL, 0,
429 hubp_pg_control(hws, 0, true);
430 REG_SET(DC_IP_REQUEST_CNTL, 0,
433 hubp->funcs->set_hubp_blank_en(hubp, false);
434 hws->wa_state.DEGVIDCN10_253_applied = true;
437 static void bios_golden_init(struct dc *dc)
439 struct dc_bios *bp = dc->ctx->dc_bios;
442 /* initialize dcn global */
443 bp->funcs->enable_disp_power_gating(bp,
444 CONTROLLER_ID_D0, ASIC_PIPE_INIT);
446 for (i = 0; i < dc->res_pool->pipe_count; i++) {
447 /* initialize dcn per pipe */
448 bp->funcs->enable_disp_power_gating(bp,
449 CONTROLLER_ID_D0 + i, ASIC_PIPE_DISABLE);
453 static void false_optc_underflow_wa(
455 const struct dc_stream_state *stream,
456 struct timing_generator *tg)
461 if (!dc->hwseq->wa.false_optc_underflow)
464 underflow = tg->funcs->is_optc_underflow_occurred(tg);
466 for (i = 0; i < dc->res_pool->pipe_count; i++) {
467 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
469 if (old_pipe_ctx->stream != stream)
472 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, old_pipe_ctx);
475 tg->funcs->set_blank_data_double_buffer(tg, true);
477 if (tg->funcs->is_optc_underflow_occurred(tg) && !underflow)
478 tg->funcs->clear_optc_underflow(tg);
481 static enum dc_status dcn10_prog_pixclk_crtc_otg(
482 struct pipe_ctx *pipe_ctx,
483 struct dc_state *context,
486 struct dc_stream_state *stream = pipe_ctx->stream;
487 enum dc_color_space color_space;
488 struct tg_color black_color = {0};
490 /* by upper caller loop, pipe0 is parent pipe and be called first.
491 * back end is set up by for pipe0. Other children pipe share back end
492 * with pipe 0. No program is needed.
494 if (pipe_ctx->top_pipe != NULL)
497 /* TODO check if timing_changed, disable stream if timing changed */
499 /* HW program guide assume display already disable
500 * by unplug sequence. OTG assume stop.
502 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
504 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
505 pipe_ctx->clock_source,
506 &pipe_ctx->stream_res.pix_clk_params,
507 &pipe_ctx->pll_settings)) {
509 return DC_ERROR_UNEXPECTED;
511 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
512 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
513 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
514 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
516 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
518 pipe_ctx->stream_res.tg->funcs->program_timing(
519 pipe_ctx->stream_res.tg,
523 #if 0 /* move to after enable_crtc */
524 /* TODO: OPP FMT, ABM. etc. should be done here. */
525 /* or FPGA now. instance 0 only. TODO: move to opp.c */
527 inst_offset = reg_offsets[pipe_ctx->stream_res.tg->inst].fmt;
529 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
530 pipe_ctx->stream_res.opp,
531 &stream->bit_depth_params,
534 /* program otg blank color */
535 color_space = stream->output_color_space;
536 color_space_to_black_color(dc, color_space, &black_color);
538 if (pipe_ctx->stream_res.tg->funcs->set_blank_color)
539 pipe_ctx->stream_res.tg->funcs->set_blank_color(
540 pipe_ctx->stream_res.tg,
543 if (pipe_ctx->stream_res.tg->funcs->is_blanked &&
544 !pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg)) {
545 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
546 hwss_wait_for_blank_complete(pipe_ctx->stream_res.tg);
547 false_optc_underflow_wa(dc, pipe_ctx->stream, pipe_ctx->stream_res.tg);
550 /* VTG is within DCHUB command block. DCFCLK is always on */
551 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
553 return DC_ERROR_UNEXPECTED;
556 /* TODO program crtc source select for non-virtual signal*/
557 /* TODO program FMT */
558 /* TODO setup link_enc */
559 /* TODO set stream attributes */
560 /* TODO program audio */
561 /* TODO enable stream if timing changed */
562 /* TODO unblank stream if DP */
567 static void reset_back_end_for_pipe(
569 struct pipe_ctx *pipe_ctx,
570 struct dc_state *context)
574 if (pipe_ctx->stream_res.stream_enc == NULL) {
575 pipe_ctx->stream = NULL;
579 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
580 /* DPMS may already disable */
581 if (!pipe_ctx->stream->dpms_off)
582 core_link_disable_stream(pipe_ctx, FREE_ACQUIRED_RESOURCE);
585 /* by upper caller loop, parent pipe: pipe0, will be reset last.
586 * back end share by all pipes and will be disable only when disable
589 if (pipe_ctx->top_pipe == NULL) {
590 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
592 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
595 for (i = 0; i < dc->res_pool->pipe_count; i++)
596 if (&dc->current_state->res_ctx.pipe_ctx[i] == pipe_ctx)
599 if (i == dc->res_pool->pipe_count)
602 pipe_ctx->stream = NULL;
603 dm_logger_write(dc->ctx->logger, LOG_DEBUG,
604 "Reset back end for pipe %d, tg:%d\n",
605 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
608 static void dcn10_verify_allow_pstate_change_high(struct dc *dc)
610 static bool should_log_hw_state; /* prevent hw state log by default */
612 if (!hubbub1_verify_allow_pstate_change_high(dc->res_pool->hubbub)) {
613 if (should_log_hw_state) {
614 dcn10_log_hw_state(dc);
621 /* trigger HW to start disconnect plane from stream on the next vsync */
622 static void plane_atomic_disconnect(struct dc *dc, struct pipe_ctx *pipe_ctx)
624 int fe_idx = pipe_ctx->pipe_idx;
625 struct hubp *hubp = dc->res_pool->hubps[fe_idx];
626 struct mpc *mpc = dc->res_pool->mpc;
628 struct mpc_tree *mpc_tree_params;
629 struct mpcc *mpcc_to_remove = NULL;
631 /* look at tree rather than mi here to know if we already reset */
632 for (opp_id = 0; opp_id < dc->res_pool->pipe_count; opp_id++) {
633 struct output_pixel_processor *opp = dc->res_pool->opps[opp_id];
635 mpc_tree_params = &(opp->mpc_tree_params);
636 mpcc_to_remove = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, fe_idx);
637 if (mpcc_to_remove != NULL)
642 if (opp_id == dc->res_pool->pipe_count)
645 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, mpcc_to_remove);
646 dc->res_pool->opps[opp_id]->mpcc_disconnect_pending[fe_idx] = true;
648 dc->optimized_required = true;
650 if (hubp->funcs->hubp_disconnect)
651 hubp->funcs->hubp_disconnect(hubp);
653 if (dc->debug.sanity_checks)
654 dcn10_verify_allow_pstate_change_high(dc);
657 static void plane_atomic_power_down(struct dc *dc, int fe_idx)
659 struct dce_hwseq *hws = dc->hwseq;
660 struct dpp *dpp = dc->res_pool->dpps[fe_idx];
662 if (REG(DC_IP_REQUEST_CNTL)) {
663 REG_SET(DC_IP_REQUEST_CNTL, 0,
665 dpp_pg_control(hws, fe_idx, false);
666 hubp_pg_control(hws, fe_idx, false);
667 dpp->funcs->dpp_reset(dpp);
668 REG_SET(DC_IP_REQUEST_CNTL, 0,
670 dm_logger_write(dc->ctx->logger, LOG_DEBUG,
671 "Power gated front end %d\n", fe_idx);
675 /* disable HW used by plane.
676 * note: cannot disable until disconnect is complete
678 static void plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
680 int fe_idx = pipe_ctx->pipe_idx;
681 struct dce_hwseq *hws = dc->hwseq;
682 struct hubp *hubp = dc->res_pool->hubps[fe_idx];
683 int opp_id = hubp->opp_id;
685 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
687 REG_UPDATE(HUBP_CLK_CNTL[fe_idx],
688 HUBP_CLOCK_ENABLE, 0);
689 REG_UPDATE(DPP_CONTROL[fe_idx],
690 DPP_CLOCK_ENABLE, 0);
692 if (opp_id != 0xf && dc->res_pool->opps[opp_id]->mpc_tree_params.opp_list == NULL)
693 REG_UPDATE(OPP_PIPE_CONTROL[opp_id],
694 OPP_PIPE_CLOCK_EN, 0);
696 hubp->power_gated = true;
697 dc->optimized_required = false; /* We're powering off, no need to optimize */
699 plane_atomic_power_down(dc, fe_idx);
701 pipe_ctx->stream = NULL;
702 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
703 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
704 pipe_ctx->top_pipe = NULL;
705 pipe_ctx->bottom_pipe = NULL;
706 pipe_ctx->plane_state = NULL;
709 static void dcn10_disable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx)
711 if (dc->res_pool->hubps[pipe_ctx->pipe_idx]->power_gated)
714 plane_atomic_disable(dc, pipe_ctx);
716 apply_DEGVIDCN10_253_wa(dc);
718 dm_logger_write(dc->ctx->logger, LOG_DC,
719 "Power down front end %d\n",
723 static void dcn10_init_hw(struct dc *dc)
726 struct abm *abm = dc->res_pool->abm;
727 struct dmcu *dmcu = dc->res_pool->dmcu;
728 struct dce_hwseq *hws = dc->hwseq;
729 struct dc_bios *dcb = dc->ctx->dc_bios;
730 struct dc_state *context = dc->current_state;
732 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
733 REG_WRITE(REFCLK_CNTL, 0);
734 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
735 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
737 if (!dc->debug.disable_clock_gate) {
738 /* enable all DCN clock gating */
739 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
741 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
743 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
746 enable_power_gating_plane(dc->hwseq, true);
749 /* end of FPGA. Below if real ASIC */
751 if (!dcb->funcs->is_accelerated_mode(dcb)) {
752 bios_golden_init(dc);
753 disable_vga(dc->hwseq);
756 for (i = 0; i < dc->link_count; i++) {
757 /* Power up AND update implementation according to the
758 * required signal (which may be different from the
759 * default signal on connector).
761 struct dc_link *link = dc->links[i];
763 if (link->link_enc->connector.id == CONNECTOR_ID_EDP)
764 dc->hwss.edp_power_control(link, true);
766 link->link_enc->funcs->hw_init(link->link_enc);
769 for (i = 0; i < dc->res_pool->pipe_count; i++) {
770 struct timing_generator *tg = dc->res_pool->timing_generators[i];
772 if (tg->funcs->is_tg_enabled(tg))
776 /* Blank controller using driver code instead of
779 for (i = 0; i < dc->res_pool->pipe_count; i++) {
780 struct timing_generator *tg = dc->res_pool->timing_generators[i];
782 if (tg->funcs->is_tg_enabled(tg)) {
783 tg->funcs->set_blank(tg, true);
784 hwss_wait_for_blank_complete(tg);
788 /* Reset all MPCC muxes */
789 dc->res_pool->mpc->funcs->mpc_init(dc->res_pool->mpc);
791 for (i = 0; i < dc->res_pool->pipe_count; i++) {
792 struct timing_generator *tg = dc->res_pool->timing_generators[i];
793 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
794 struct hubp *hubp = dc->res_pool->hubps[i];
796 pipe_ctx->stream_res.tg = tg;
797 pipe_ctx->pipe_idx = i;
799 pipe_ctx->plane_res.hubp = hubp;
802 hubp->power_gated = false;
804 dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
805 dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
806 dc->res_pool->opps[i]->mpcc_disconnect_pending[i] = true;
807 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
809 plane_atomic_disconnect(dc, pipe_ctx);
812 for (i = 0; i < dc->res_pool->pipe_count; i++) {
813 struct timing_generator *tg = dc->res_pool->timing_generators[i];
815 if (tg->funcs->is_tg_enabled(tg))
816 tg->funcs->unlock(tg);
819 for (i = 0; i < dc->res_pool->pipe_count; i++) {
820 struct timing_generator *tg = dc->res_pool->timing_generators[i];
821 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
823 dcn10_disable_plane(dc, pipe_ctx);
825 pipe_ctx->stream_res.tg = NULL;
826 pipe_ctx->plane_res.hubp = NULL;
828 tg->funcs->tg_init(tg);
831 for (i = 0; i < dc->res_pool->audio_count; i++) {
832 struct audio *audio = dc->res_pool->audios[i];
834 audio->funcs->hw_init(audio);
838 abm->funcs->init_backlight(abm);
839 abm->funcs->abm_init(abm);
843 dmcu->funcs->dmcu_init(dmcu);
845 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
846 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
848 if (!dc->debug.disable_clock_gate) {
849 /* enable all DCN clock gating */
850 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
852 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
854 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
857 enable_power_gating_plane(dc->hwseq, true);
860 static void reset_hw_ctx_wrap(
862 struct dc_state *context)
867 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
868 struct pipe_ctx *pipe_ctx_old =
869 &dc->current_state->res_ctx.pipe_ctx[i];
870 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
872 if (!pipe_ctx_old->stream)
875 if (pipe_ctx_old->top_pipe)
878 if (!pipe_ctx->stream ||
879 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
880 struct clock_source *old_clk = pipe_ctx_old->clock_source;
882 reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
884 old_clk->funcs->cs_power_down(old_clk);
890 static bool patch_address_for_sbs_tb_stereo(
891 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
893 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
894 bool sec_split = pipe_ctx->top_pipe &&
895 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
896 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
897 (pipe_ctx->stream->timing.timing_3d_format ==
898 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
899 pipe_ctx->stream->timing.timing_3d_format ==
900 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
901 *addr = plane_state->address.grph_stereo.left_addr;
902 plane_state->address.grph_stereo.left_addr =
903 plane_state->address.grph_stereo.right_addr;
906 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
907 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
908 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
909 plane_state->address.grph_stereo.right_addr =
910 plane_state->address.grph_stereo.left_addr;
918 static void dcn10_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
920 bool addr_patched = false;
921 PHYSICAL_ADDRESS_LOC addr;
922 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
924 if (plane_state == NULL)
926 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
927 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
928 pipe_ctx->plane_res.hubp,
929 &plane_state->address,
930 plane_state->flip_immediate);
931 plane_state->status.requested_address = plane_state->address;
933 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
936 static bool dcn10_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
937 const struct dc_plane_state *plane_state)
939 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
940 const struct dc_transfer_func *tf = NULL;
943 if (dpp_base == NULL)
946 if (plane_state->in_transfer_func)
947 tf = plane_state->in_transfer_func;
949 if (plane_state->gamma_correction && dce_use_lut(plane_state))
950 dpp_base->funcs->dpp_program_input_lut(dpp_base, plane_state->gamma_correction);
953 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
954 else if (tf->type == TF_TYPE_PREDEFINED) {
956 case TRANSFER_FUNCTION_SRGB:
957 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_sRGB);
959 case TRANSFER_FUNCTION_BT709:
960 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_HW_xvYCC);
962 case TRANSFER_FUNCTION_LINEAR:
963 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
965 case TRANSFER_FUNCTION_PQ:
970 } else if (tf->type == TF_TYPE_BYPASS) {
971 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_BYPASS);
973 /*TF_TYPE_DISTRIBUTED_POINTS*/
985 dcn10_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
986 const struct dc_stream_state *stream)
988 struct dpp *dpp = pipe_ctx->plane_res.dpp;
993 dpp->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
995 if (stream->out_transfer_func &&
996 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
997 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB)
998 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_SRGB);
1000 /* dcn10_translate_regamma_to_hw_format takes 750us, only do it when full
1003 else if (cm_helper_translate_curve_to_hw_format(
1004 stream->out_transfer_func,
1005 &dpp->regamma_params, false)) {
1006 dpp->funcs->dpp_program_regamma_pwl(
1008 &dpp->regamma_params, OPP_REGAMMA_USER);
1010 dpp->funcs->dpp_program_regamma_pwl(dpp, NULL, OPP_REGAMMA_BYPASS);
1015 static void dcn10_pipe_control_lock(
1017 struct pipe_ctx *pipe,
1020 struct hubp *hubp = NULL;
1021 hubp = dc->res_pool->hubps[pipe->pipe_idx];
1022 /* use TG master update lock to lock everything on the TG
1023 * therefore only top pipe need to lock
1028 if (dc->debug.sanity_checks)
1029 dcn10_verify_allow_pstate_change_high(dc);
1032 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1034 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1036 if (dc->debug.sanity_checks)
1037 dcn10_verify_allow_pstate_change_high(dc);
1040 static bool wait_for_reset_trigger_to_occur(
1041 struct dc_context *dc_ctx,
1042 struct timing_generator *tg)
1046 /* To avoid endless loop we wait at most
1047 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
1048 const uint32_t frames_to_wait_on_triggered_reset = 10;
1051 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
1053 if (!tg->funcs->is_counter_moving(tg)) {
1054 DC_ERROR("TG counter is not moving!\n");
1058 if (tg->funcs->did_triggered_reset_occur(tg)) {
1060 /* usually occurs at i=1 */
1061 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
1066 /* Wait for one frame. */
1067 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
1068 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
1072 DC_ERROR("GSL: Timeout on reset trigger!\n");
1077 static void dcn10_enable_timing_synchronization(
1081 struct pipe_ctx *grouped_pipes[])
1083 struct dc_context *dc_ctx = dc->ctx;
1086 DC_SYNC_INFO("Setting up OTG reset trigger\n");
1088 for (i = 1; i < group_size; i++)
1089 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
1090 grouped_pipes[i]->stream_res.tg,
1091 grouped_pipes[0]->stream_res.tg->inst);
1093 DC_SYNC_INFO("Waiting for trigger\n");
1095 /* Need to get only check 1 pipe for having reset as all the others are
1096 * synchronized. Look at last pipe programmed to reset.
1099 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[1]->stream_res.tg);
1100 for (i = 1; i < group_size; i++)
1101 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
1102 grouped_pipes[i]->stream_res.tg);
1104 DC_SYNC_INFO("Sync complete\n");
1107 static void dcn10_enable_per_frame_crtc_position_reset(
1110 struct pipe_ctx *grouped_pipes[])
1112 struct dc_context *dc_ctx = dc->ctx;
1115 DC_SYNC_INFO("Setting up\n");
1116 for (i = 0; i < group_size; i++)
1117 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
1118 grouped_pipes[i]->stream_res.tg,
1119 grouped_pipes[i]->stream->triggered_crtc_reset.event_source->status.primary_otg_inst,
1120 &grouped_pipes[i]->stream->triggered_crtc_reset);
1122 DC_SYNC_INFO("Waiting for trigger\n");
1124 for (i = 1; i < group_size; i++)
1125 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
1127 DC_SYNC_INFO("Multi-display sync is complete\n");
1130 /*static void print_rq_dlg_ttu(
1132 struct pipe_ctx *pipe_ctx)
1134 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1135 "\n============== DML TTU Output parameters [%d] ==============\n"
1136 "qos_level_low_wm: %d, \n"
1137 "qos_level_high_wm: %d, \n"
1138 "min_ttu_vblank: %d, \n"
1139 "qos_level_flip: %d, \n"
1140 "refcyc_per_req_delivery_l: %d, \n"
1141 "qos_level_fixed_l: %d, \n"
1142 "qos_ramp_disable_l: %d, \n"
1143 "refcyc_per_req_delivery_pre_l: %d, \n"
1144 "refcyc_per_req_delivery_c: %d, \n"
1145 "qos_level_fixed_c: %d, \n"
1146 "qos_ramp_disable_c: %d, \n"
1147 "refcyc_per_req_delivery_pre_c: %d\n"
1148 "=============================================================\n",
1150 pipe_ctx->ttu_regs.qos_level_low_wm,
1151 pipe_ctx->ttu_regs.qos_level_high_wm,
1152 pipe_ctx->ttu_regs.min_ttu_vblank,
1153 pipe_ctx->ttu_regs.qos_level_flip,
1154 pipe_ctx->ttu_regs.refcyc_per_req_delivery_l,
1155 pipe_ctx->ttu_regs.qos_level_fixed_l,
1156 pipe_ctx->ttu_regs.qos_ramp_disable_l,
1157 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_l,
1158 pipe_ctx->ttu_regs.refcyc_per_req_delivery_c,
1159 pipe_ctx->ttu_regs.qos_level_fixed_c,
1160 pipe_ctx->ttu_regs.qos_ramp_disable_c,
1161 pipe_ctx->ttu_regs.refcyc_per_req_delivery_pre_c
1164 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1165 "\n============== DML DLG Output parameters [%d] ==============\n"
1166 "refcyc_h_blank_end: %d, \n"
1167 "dlg_vblank_end: %d, \n"
1168 "min_dst_y_next_start: %d, \n"
1169 "refcyc_per_htotal: %d, \n"
1170 "refcyc_x_after_scaler: %d, \n"
1171 "dst_y_after_scaler: %d, \n"
1172 "dst_y_prefetch: %d, \n"
1173 "dst_y_per_vm_vblank: %d, \n"
1174 "dst_y_per_row_vblank: %d, \n"
1175 "ref_freq_to_pix_freq: %d, \n"
1176 "vratio_prefetch: %d, \n"
1177 "refcyc_per_pte_group_vblank_l: %d, \n"
1178 "refcyc_per_meta_chunk_vblank_l: %d, \n"
1179 "dst_y_per_pte_row_nom_l: %d, \n"
1180 "refcyc_per_pte_group_nom_l: %d, \n",
1182 pipe_ctx->dlg_regs.refcyc_h_blank_end,
1183 pipe_ctx->dlg_regs.dlg_vblank_end,
1184 pipe_ctx->dlg_regs.min_dst_y_next_start,
1185 pipe_ctx->dlg_regs.refcyc_per_htotal,
1186 pipe_ctx->dlg_regs.refcyc_x_after_scaler,
1187 pipe_ctx->dlg_regs.dst_y_after_scaler,
1188 pipe_ctx->dlg_regs.dst_y_prefetch,
1189 pipe_ctx->dlg_regs.dst_y_per_vm_vblank,
1190 pipe_ctx->dlg_regs.dst_y_per_row_vblank,
1191 pipe_ctx->dlg_regs.ref_freq_to_pix_freq,
1192 pipe_ctx->dlg_regs.vratio_prefetch,
1193 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_l,
1194 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_l,
1195 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_l,
1196 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_l
1199 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1200 "\ndst_y_per_meta_row_nom_l: %d, \n"
1201 "refcyc_per_meta_chunk_nom_l: %d, \n"
1202 "refcyc_per_line_delivery_pre_l: %d, \n"
1203 "refcyc_per_line_delivery_l: %d, \n"
1204 "vratio_prefetch_c: %d, \n"
1205 "refcyc_per_pte_group_vblank_c: %d, \n"
1206 "refcyc_per_meta_chunk_vblank_c: %d, \n"
1207 "dst_y_per_pte_row_nom_c: %d, \n"
1208 "refcyc_per_pte_group_nom_c: %d, \n"
1209 "dst_y_per_meta_row_nom_c: %d, \n"
1210 "refcyc_per_meta_chunk_nom_c: %d, \n"
1211 "refcyc_per_line_delivery_pre_c: %d, \n"
1212 "refcyc_per_line_delivery_c: %d \n"
1213 "========================================================\n",
1214 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_l,
1215 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_l,
1216 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_l,
1217 pipe_ctx->dlg_regs.refcyc_per_line_delivery_l,
1218 pipe_ctx->dlg_regs.vratio_prefetch_c,
1219 pipe_ctx->dlg_regs.refcyc_per_pte_group_vblank_c,
1220 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_vblank_c,
1221 pipe_ctx->dlg_regs.dst_y_per_pte_row_nom_c,
1222 pipe_ctx->dlg_regs.refcyc_per_pte_group_nom_c,
1223 pipe_ctx->dlg_regs.dst_y_per_meta_row_nom_c,
1224 pipe_ctx->dlg_regs.refcyc_per_meta_chunk_nom_c,
1225 pipe_ctx->dlg_regs.refcyc_per_line_delivery_pre_c,
1226 pipe_ctx->dlg_regs.refcyc_per_line_delivery_c
1229 dm_logger_write(core_dc->ctx->logger, LOG_BANDWIDTH_CALCS,
1230 "\n============== DML RQ Output parameters [%d] ==============\n"
1232 "min_chunk_size: %d \n"
1233 "meta_chunk_size: %d \n"
1234 "min_meta_chunk_size: %d \n"
1235 "dpte_group_size: %d \n"
1236 "mpte_group_size: %d \n"
1237 "swath_height: %d \n"
1238 "pte_row_height_linear: %d \n"
1239 "========================================================\n",
1241 pipe_ctx->rq_regs.rq_regs_l.chunk_size,
1242 pipe_ctx->rq_regs.rq_regs_l.min_chunk_size,
1243 pipe_ctx->rq_regs.rq_regs_l.meta_chunk_size,
1244 pipe_ctx->rq_regs.rq_regs_l.min_meta_chunk_size,
1245 pipe_ctx->rq_regs.rq_regs_l.dpte_group_size,
1246 pipe_ctx->rq_regs.rq_regs_l.mpte_group_size,
1247 pipe_ctx->rq_regs.rq_regs_l.swath_height,
1248 pipe_ctx->rq_regs.rq_regs_l.pte_row_height_linear
1253 static void mmhub_read_vm_system_aperture_settings(struct dcn10_hubp *hubp1,
1254 struct vm_system_aperture_param *apt,
1255 struct dce_hwseq *hws)
1257 PHYSICAL_ADDRESS_LOC physical_page_number;
1258 uint32_t logical_addr_low;
1259 uint32_t logical_addr_high;
1261 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
1262 PHYSICAL_PAGE_NUMBER_MSB, &physical_page_number.high_part);
1263 REG_GET(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
1264 PHYSICAL_PAGE_NUMBER_LSB, &physical_page_number.low_part);
1266 REG_GET(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1267 LOGICAL_ADDR, &logical_addr_low);
1269 REG_GET(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1270 LOGICAL_ADDR, &logical_addr_high);
1272 apt->sys_default.quad_part = physical_page_number.quad_part << 12;
1273 apt->sys_low.quad_part = (int64_t)logical_addr_low << 18;
1274 apt->sys_high.quad_part = (int64_t)logical_addr_high << 18;
1277 /* Temporary read settings, future will get values from kmd directly */
1278 static void mmhub_read_vm_context0_settings(struct dcn10_hubp *hubp1,
1279 struct vm_context0_param *vm0,
1280 struct dce_hwseq *hws)
1282 PHYSICAL_ADDRESS_LOC fb_base;
1283 PHYSICAL_ADDRESS_LOC fb_offset;
1284 uint32_t fb_base_value;
1285 uint32_t fb_offset_value;
1287 REG_GET(DCHUBBUB_SDPIF_FB_BASE, SDPIF_FB_BASE, &fb_base_value);
1288 REG_GET(DCHUBBUB_SDPIF_FB_OFFSET, SDPIF_FB_OFFSET, &fb_offset_value);
1290 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
1291 PAGE_DIRECTORY_ENTRY_HI32, &vm0->pte_base.high_part);
1292 REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
1293 PAGE_DIRECTORY_ENTRY_LO32, &vm0->pte_base.low_part);
1295 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
1296 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_start.high_part);
1297 REG_GET(VM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
1298 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_start.low_part);
1300 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
1301 LOGICAL_PAGE_NUMBER_HI4, &vm0->pte_end.high_part);
1302 REG_GET(VM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
1303 LOGICAL_PAGE_NUMBER_LO32, &vm0->pte_end.low_part);
1305 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
1306 PHYSICAL_PAGE_ADDR_HI4, &vm0->fault_default.high_part);
1307 REG_GET(VM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
1308 PHYSICAL_PAGE_ADDR_LO32, &vm0->fault_default.low_part);
1311 * The values in VM_CONTEXT0_PAGE_TABLE_BASE_ADDR is in UMA space.
1312 * Therefore we need to do
1313 * DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
1314 * - DCHUBBUB_SDPIF_FB_OFFSET + DCHUBBUB_SDPIF_FB_BASE
1316 fb_base.quad_part = (uint64_t)fb_base_value << 24;
1317 fb_offset.quad_part = (uint64_t)fb_offset_value << 24;
1318 vm0->pte_base.quad_part += fb_base.quad_part;
1319 vm0->pte_base.quad_part -= fb_offset.quad_part;
1323 static void dcn10_program_pte_vm(struct dce_hwseq *hws, struct hubp *hubp)
1325 struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
1326 struct vm_system_aperture_param apt = { {{ 0 } } };
1327 struct vm_context0_param vm0 = { { { 0 } } };
1329 mmhub_read_vm_system_aperture_settings(hubp1, &apt, hws);
1330 mmhub_read_vm_context0_settings(hubp1, &vm0, hws);
1332 hubp->funcs->hubp_set_vm_system_aperture_settings(hubp, &apt);
1333 hubp->funcs->hubp_set_vm_context0_settings(hubp, &vm0);
1336 static void dcn10_enable_plane(
1338 struct pipe_ctx *pipe_ctx,
1339 struct dc_state *context)
1341 struct dce_hwseq *hws = dc->hwseq;
1343 if (dc->debug.sanity_checks) {
1344 dcn10_verify_allow_pstate_change_high(dc);
1347 undo_DEGVIDCN10_253_wa(dc);
1349 power_on_plane(dc->hwseq,
1350 pipe_ctx->pipe_idx);
1352 /* enable DCFCLK current DCHUB */
1353 REG_UPDATE(HUBP_CLK_CNTL[pipe_ctx->pipe_idx],
1354 HUBP_CLOCK_ENABLE, 1);
1356 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1357 REG_UPDATE(OPP_PIPE_CONTROL[pipe_ctx->stream_res.tg->inst],
1358 OPP_PIPE_CLOCK_EN, 1);
1360 /* TODO: enable/disable in dm as per update type.
1362 dm_logger_write(dc->ctx->logger, LOG_DC,
1363 "Pipe:%d 0x%x: addr hi:0x%x, "
1366 " %d; dst: %d, %d, %d, %d;\n",
1369 plane_state->address.grph.addr.high_part,
1370 plane_state->address.grph.addr.low_part,
1371 plane_state->src_rect.x,
1372 plane_state->src_rect.y,
1373 plane_state->src_rect.width,
1374 plane_state->src_rect.height,
1375 plane_state->dst_rect.x,
1376 plane_state->dst_rect.y,
1377 plane_state->dst_rect.width,
1378 plane_state->dst_rect.height);
1380 dm_logger_write(dc->ctx->logger, LOG_DC,
1381 "Pipe %d: width, height, x, y format:%d\n"
1382 "viewport:%d, %d, %d, %d\n"
1383 "recout: %d, %d, %d, %d\n",
1385 plane_state->format,
1386 pipe_ctx->plane_res.scl_data.viewport.width,
1387 pipe_ctx->plane_res.scl_data.viewport.height,
1388 pipe_ctx->plane_res.scl_data.viewport.x,
1389 pipe_ctx->plane_res.scl_data.viewport.y,
1390 pipe_ctx->plane_res.scl_data.recout.width,
1391 pipe_ctx->plane_res.scl_data.recout.height,
1392 pipe_ctx->plane_res.scl_data.recout.x,
1393 pipe_ctx->plane_res.scl_data.recout.y);
1394 print_rq_dlg_ttu(dc, pipe_ctx);
1397 if (dc->config.gpu_vm_support)
1398 dcn10_program_pte_vm(hws, pipe_ctx->plane_res.hubp);
1400 if (dc->debug.sanity_checks) {
1401 dcn10_verify_allow_pstate_change_high(dc);
1405 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
1407 struct dpp_grph_csc_adjustment adjust;
1408 memset(&adjust, 0, sizeof(adjust));
1409 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
1412 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
1413 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
1414 adjust.temperature_matrix[0] =
1416 gamut_remap_matrix.matrix[0];
1417 adjust.temperature_matrix[1] =
1419 gamut_remap_matrix.matrix[1];
1420 adjust.temperature_matrix[2] =
1422 gamut_remap_matrix.matrix[2];
1423 adjust.temperature_matrix[3] =
1425 gamut_remap_matrix.matrix[4];
1426 adjust.temperature_matrix[4] =
1428 gamut_remap_matrix.matrix[5];
1429 adjust.temperature_matrix[5] =
1431 gamut_remap_matrix.matrix[6];
1432 adjust.temperature_matrix[6] =
1434 gamut_remap_matrix.matrix[8];
1435 adjust.temperature_matrix[7] =
1437 gamut_remap_matrix.matrix[9];
1438 adjust.temperature_matrix[8] =
1440 gamut_remap_matrix.matrix[10];
1443 pipe_ctx->plane_res.dpp->funcs->dpp_set_gamut_remap(pipe_ctx->plane_res.dpp, &adjust);
1447 static void program_csc_matrix(struct pipe_ctx *pipe_ctx,
1448 enum dc_color_space colorspace,
1451 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1452 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1453 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment(pipe_ctx->plane_res.dpp, matrix);
1455 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default != NULL)
1456 pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_default(pipe_ctx->plane_res.dpp, colorspace);
1460 static void program_output_csc(struct dc *dc,
1461 struct pipe_ctx *pipe_ctx,
1462 enum dc_color_space colorspace,
1466 if (pipe_ctx->plane_res.dpp->funcs->dpp_set_csc_adjustment != NULL)
1467 program_csc_matrix(pipe_ctx,
1472 static bool is_lower_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1474 if (pipe_ctx->plane_state->visible)
1476 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1481 static bool is_upper_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1483 if (pipe_ctx->plane_state->visible)
1485 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1490 static bool is_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
1492 if (pipe_ctx->plane_state->visible)
1494 if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
1496 if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
1501 static bool is_rgb_cspace(enum dc_color_space output_color_space)
1503 switch (output_color_space) {
1504 case COLOR_SPACE_SRGB:
1505 case COLOR_SPACE_SRGB_LIMITED:
1506 case COLOR_SPACE_2020_RGB_FULLRANGE:
1507 case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
1508 case COLOR_SPACE_ADOBERGB:
1510 case COLOR_SPACE_YCBCR601:
1511 case COLOR_SPACE_YCBCR709:
1512 case COLOR_SPACE_YCBCR601_LIMITED:
1513 case COLOR_SPACE_YCBCR709_LIMITED:
1514 case COLOR_SPACE_2020_YCBCR:
1517 /* Add a case to switch */
1518 BREAK_TO_DEBUGGER();
1523 static void dcn10_get_surface_visual_confirm_color(
1524 const struct pipe_ctx *pipe_ctx,
1525 struct tg_color *color)
1527 uint32_t color_value = MAX_TG_COLOR_VALUE;
1529 switch (pipe_ctx->plane_res.scl_data.format) {
1530 case PIXEL_FORMAT_ARGB8888:
1531 /* set boarder color to red */
1532 color->color_r_cr = color_value;
1535 case PIXEL_FORMAT_ARGB2101010:
1536 /* set boarder color to blue */
1537 color->color_b_cb = color_value;
1539 case PIXEL_FORMAT_420BPP8:
1540 /* set boarder color to green */
1541 color->color_g_y = color_value;
1543 case PIXEL_FORMAT_420BPP10:
1544 /* set boarder color to yellow */
1545 color->color_g_y = color_value;
1546 color->color_r_cr = color_value;
1548 case PIXEL_FORMAT_FP16:
1549 /* set boarder color to white */
1550 color->color_r_cr = color_value;
1551 color->color_b_cb = color_value;
1552 color->color_g_y = color_value;
1559 static uint16_t fixed_point_to_int_frac(
1560 struct fixed31_32 arg,
1561 uint8_t integer_bits,
1562 uint8_t fractional_bits)
1565 int32_t divisor = 1 << fractional_bits;
1569 uint16_t d = (uint16_t)dal_fixed31_32_floor(
1573 if (d <= (uint16_t)(1 << integer_bits) - (1 / (uint16_t)divisor))
1574 numerator = (uint16_t)dal_fixed31_32_floor(
1575 dal_fixed31_32_mul_int(
1579 numerator = dal_fixed31_32_floor(
1581 dal_fixed31_32_from_int(
1582 1LL << integer_bits),
1583 dal_fixed31_32_recip(
1584 dal_fixed31_32_from_int(
1589 result = (uint16_t)numerator;
1591 result = (uint16_t)(
1592 (1 << (integer_bits + fractional_bits + 1)) + numerator);
1594 if ((result != 0) && dal_fixed31_32_lt(
1595 arg, dal_fixed31_32_zero))
1596 result |= 1 << (integer_bits + fractional_bits);
1601 void build_prescale_params(struct dc_bias_and_scale *bias_and_scale,
1602 const struct dc_plane_state *plane_state)
1604 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1605 && plane_state->format != SURFACE_PIXEL_FORMAT_INVALID
1606 && plane_state->input_csc_color_matrix.enable_adjustment
1607 && plane_state->coeff_reduction_factor.value != 0) {
1608 bias_and_scale->scale_blue = fixed_point_to_int_frac(
1609 dal_fixed31_32_mul(plane_state->coeff_reduction_factor,
1610 dal_fixed31_32_from_fraction(256, 255)),
1613 bias_and_scale->scale_red = bias_and_scale->scale_blue;
1614 bias_and_scale->scale_green = bias_and_scale->scale_blue;
1616 bias_and_scale->scale_blue = 0x2000;
1617 bias_and_scale->scale_red = 0x2000;
1618 bias_and_scale->scale_green = 0x2000;
1622 static void update_dpp(struct dpp *dpp, struct dc_plane_state *plane_state)
1624 struct dc_bias_and_scale bns_params = {0};
1626 // program the input csc
1627 dpp->funcs->dpp_setup(dpp,
1628 plane_state->format,
1629 EXPANSION_MODE_ZERO,
1630 plane_state->input_csc_color_matrix,
1631 COLOR_SPACE_YCBCR601_LIMITED);
1633 //set scale and bias registers
1634 build_prescale_params(&bns_params, plane_state);
1635 if (dpp->funcs->dpp_program_bias_and_scale)
1636 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1639 static void update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
1641 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1642 struct mpcc_blnd_cfg blnd_cfg;
1643 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1645 struct mpcc *new_mpcc;
1646 struct mpc *mpc = dc->res_pool->mpc;
1647 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
1649 /* TODO: proper fix once fpga works */
1651 if (dc->debug.surface_visual_confirm)
1652 dcn10_get_surface_visual_confirm_color(
1653 pipe_ctx, &blnd_cfg.black_color);
1655 color_space_to_black_color(
1656 dc, pipe_ctx->stream->output_color_space,
1657 &blnd_cfg.black_color);
1659 if (per_pixel_alpha)
1660 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
1662 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
1664 blnd_cfg.overlap_only = false;
1665 blnd_cfg.global_alpha = 0xff;
1666 blnd_cfg.global_gain = 0xff;
1668 /* DCN1.0 has output CM before MPC which seems to screw with
1669 * pre-multiplied alpha.
1671 blnd_cfg.pre_multiplied_alpha = is_rgb_cspace(
1672 pipe_ctx->stream->output_color_space)
1677 * Note: currently there is a bug in init_hw such that
1678 * on resume from hibernate, BIOS sets up MPCC0, and
1679 * we do mpcc_remove but the mpcc cannot go to idle
1680 * after remove. This cause us to pick mpcc1 here,
1681 * which causes a pstate hang for yet unknown reason.
1683 mpcc_id = hubp->inst;
1685 /* check if this MPCC is already being used */
1686 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
1687 /* remove MPCC if being used */
1688 if (new_mpcc != NULL)
1689 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
1691 if (dc->debug.sanity_checks)
1692 mpc->funcs->assert_mpcc_idle_before_connect(
1693 dc->res_pool->mpc, mpcc_id);
1695 /* Call MPC to insert new plane */
1696 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
1704 ASSERT(new_mpcc != NULL);
1706 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
1707 hubp->mpcc_id = mpcc_id;
1710 static void update_scaler(struct pipe_ctx *pipe_ctx)
1712 bool per_pixel_alpha =
1713 pipe_ctx->plane_state->per_pixel_alpha && pipe_ctx->bottom_pipe;
1715 /* TODO: proper fix once fpga works */
1717 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = per_pixel_alpha;
1718 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1719 /* scaler configuration */
1720 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1721 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
1724 static void update_dchubp_dpp(
1726 struct pipe_ctx *pipe_ctx,
1727 struct dc_state *context)
1729 struct dce_hwseq *hws = dc->hwseq;
1730 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1731 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1732 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1733 union plane_size size = plane_state->plane_size;
1735 /* depends on DML calculation, DPP clock value may change dynamically */
1736 if (plane_state->update_flags.bits.full_update) {
1740 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk,
1741 context->bw.dcn.calc_clk.dppclk_div);
1742 dc->current_state->bw.dcn.cur_clk.dppclk_div =
1743 context->bw.dcn.calc_clk.dppclk_div;
1744 context->bw.dcn.cur_clk.dppclk_div = context->bw.dcn.calc_clk.dppclk_div;
1747 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
1748 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
1749 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
1751 if (plane_state->update_flags.bits.full_update) {
1752 REG_UPDATE(DCHUBP_CNTL[pipe_ctx->pipe_idx], HUBP_VTG_SEL, pipe_ctx->stream_res.tg->inst);
1754 hubp->funcs->hubp_setup(
1756 &pipe_ctx->dlg_regs,
1757 &pipe_ctx->ttu_regs,
1759 &pipe_ctx->pipe_dlg_param);
1762 size.grph.surface_size = pipe_ctx->plane_res.scl_data.viewport;
1764 if (plane_state->update_flags.bits.full_update ||
1765 plane_state->update_flags.bits.bpp_change)
1766 update_dpp(dpp, plane_state);
1768 if (plane_state->update_flags.bits.full_update ||
1769 plane_state->update_flags.bits.per_pixel_alpha_change)
1770 update_mpcc(dc, pipe_ctx);
1772 if (plane_state->update_flags.bits.full_update ||
1773 plane_state->update_flags.bits.per_pixel_alpha_change ||
1774 plane_state->update_flags.bits.scaling_change ||
1775 plane_state->update_flags.bits.position_change) {
1776 update_scaler(pipe_ctx);
1779 if (plane_state->update_flags.bits.full_update ||
1780 plane_state->update_flags.bits.scaling_change ||
1781 plane_state->update_flags.bits.position_change) {
1782 hubp->funcs->mem_program_viewport(
1784 &pipe_ctx->plane_res.scl_data.viewport,
1785 &pipe_ctx->plane_res.scl_data.viewport_c);
1788 if (pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
1789 dc->hwss.set_cursor_position(pipe_ctx);
1790 dc->hwss.set_cursor_attribute(pipe_ctx);
1793 if (plane_state->update_flags.bits.full_update) {
1795 program_gamut_remap(pipe_ctx);
1797 program_output_csc(dc,
1799 pipe_ctx->stream->output_color_space,
1800 pipe_ctx->stream->csc_color_matrix.matrix,
1804 if (plane_state->update_flags.bits.full_update ||
1805 plane_state->update_flags.bits.horizontal_mirror_change ||
1806 plane_state->update_flags.bits.rotation_change ||
1807 plane_state->update_flags.bits.swizzle_change ||
1808 plane_state->update_flags.bits.dcc_change ||
1809 plane_state->update_flags.bits.bpp_change ||
1810 plane_state->update_flags.bits.scaling_change) {
1811 hubp->funcs->hubp_program_surface_config(
1813 plane_state->format,
1814 &plane_state->tiling_info,
1816 plane_state->rotation,
1818 plane_state->horizontal_mirror);
1821 hubp->power_gated = false;
1823 dc->hwss.update_plane_addr(dc, pipe_ctx);
1825 if (is_pipe_tree_visible(pipe_ctx))
1826 hubp->funcs->set_blank(hubp, false);
1830 static void program_all_pipe_in_tree(
1832 struct pipe_ctx *pipe_ctx,
1833 struct dc_state *context)
1836 if (pipe_ctx->top_pipe == NULL) {
1838 pipe_ctx->stream_res.tg->dlg_otg_param.vready_offset = pipe_ctx->pipe_dlg_param.vready_offset;
1839 pipe_ctx->stream_res.tg->dlg_otg_param.vstartup_start = pipe_ctx->pipe_dlg_param.vstartup_start;
1840 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_offset = pipe_ctx->pipe_dlg_param.vupdate_offset;
1841 pipe_ctx->stream_res.tg->dlg_otg_param.vupdate_width = pipe_ctx->pipe_dlg_param.vupdate_width;
1842 pipe_ctx->stream_res.tg->dlg_otg_param.signal = pipe_ctx->stream->signal;
1844 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1845 pipe_ctx->stream_res.tg);
1847 if (pipe_ctx->stream_res.tg->funcs->set_blank)
1848 pipe_ctx->stream_res.tg->funcs->set_blank(
1849 pipe_ctx->stream_res.tg,
1850 !is_pipe_tree_visible(pipe_ctx));
1853 if (pipe_ctx->plane_state != NULL) {
1854 struct pipe_ctx *cur_pipe_ctx =
1855 &dc->current_state->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
1857 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1858 dcn10_enable_plane(dc, pipe_ctx, context);
1860 update_dchubp_dpp(dc, pipe_ctx, context);
1862 if (cur_pipe_ctx->plane_state != pipe_ctx->plane_state)
1863 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
1865 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
1866 * only do gamma programming for full update.
1867 * TODO: This can be further optimized/cleaned up
1868 * Always call this for now since it does memcmp inside before
1869 * doing heavy calculation and programming
1871 if (pipe_ctx->plane_state->update_flags.bits.full_update)
1872 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
1875 if (pipe_ctx->bottom_pipe != NULL && pipe_ctx->bottom_pipe != pipe_ctx)
1876 program_all_pipe_in_tree(dc, pipe_ctx->bottom_pipe, context);
1879 static void dcn10_pplib_apply_display_requirements(
1881 struct dc_state *context)
1883 struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
1885 pp_display_cfg->all_displays_in_sync = false;/*todo*/
1886 pp_display_cfg->nb_pstate_switch_disable = false;
1887 pp_display_cfg->min_engine_clock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1888 pp_display_cfg->min_memory_clock_khz = context->bw.dcn.cur_clk.fclk_khz;
1889 pp_display_cfg->min_engine_clock_deep_sleep_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1890 pp_display_cfg->min_dcfc_deep_sleep_clock_khz = context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz;
1891 pp_display_cfg->avail_mclk_switch_time_us =
1892 context->bw.dcn.cur_clk.dram_ccm_us > 0 ? context->bw.dcn.cur_clk.dram_ccm_us : 0;
1893 pp_display_cfg->avail_mclk_switch_time_in_disp_active_us =
1894 context->bw.dcn.cur_clk.min_active_dram_ccm_us > 0 ? context->bw.dcn.cur_clk.min_active_dram_ccm_us : 0;
1895 pp_display_cfg->min_dcfclock_khz = context->bw.dcn.cur_clk.dcfclk_khz;
1896 pp_display_cfg->disp_clk_khz = context->bw.dcn.cur_clk.dispclk_khz;
1897 dce110_fill_display_configs(context, pp_display_cfg);
1899 if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof(
1900 struct dm_pp_display_configuration)) != 0)
1901 dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
1903 dc->prev_display_config = *pp_display_cfg;
1906 static void optimize_shared_resources(struct dc *dc)
1908 if (dc->current_state->stream_count == 0) {
1910 dcn10_pplib_apply_display_requirements(dc, dc->current_state);
1913 if (dc->debug.pplib_wm_report_mode == WM_REPORT_OVERRIDE)
1914 dcn_bw_notify_pplib_of_wm_ranges(dc);
1917 static void ready_shared_resources(struct dc *dc, struct dc_state *context)
1920 if (dc->current_state->stream_count == 0 &&
1921 context->stream_count != 0)
1922 dcn10_pplib_apply_display_requirements(dc, context);
1925 static struct pipe_ctx *find_top_pipe_for_stream(
1927 struct dc_state *context,
1928 const struct dc_stream_state *stream)
1932 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1933 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1934 struct pipe_ctx *old_pipe_ctx =
1935 &dc->current_state->res_ctx.pipe_ctx[i];
1937 if (!pipe_ctx->plane_state && !old_pipe_ctx->plane_state)
1940 if (pipe_ctx->stream != stream)
1943 if (!pipe_ctx->top_pipe)
1949 static void dcn10_apply_ctx_for_surface(
1951 const struct dc_stream_state *stream,
1953 struct dc_state *context)
1956 struct timing_generator *tg;
1957 struct output_pixel_processor *opp;
1958 bool removed_pipe[4] = { false };
1959 unsigned int ref_clk_mhz = dc->res_pool->ref_clock_inKhz/1000;
1960 bool program_water_mark = false;
1962 struct pipe_ctx *top_pipe_to_program =
1963 find_top_pipe_for_stream(dc, context, stream);
1965 if (!top_pipe_to_program)
1968 opp = top_pipe_to_program->stream_res.opp;
1970 tg = top_pipe_to_program->stream_res.tg;
1972 tg->funcs->lock(tg);
1974 if (num_planes == 0) {
1976 /* OTG blank before remove all front end */
1977 if (tg->funcs->set_blank)
1978 tg->funcs->set_blank(tg, true);
1981 /* Disconnect unused mpcc */
1982 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1983 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1984 struct pipe_ctx *old_pipe_ctx =
1985 &dc->current_state->res_ctx.pipe_ctx[i];
1987 * Powergate reused pipes that are not powergated
1988 * fairly hacky right now, using opp_id as indicator
1989 * TODO: After move dc_post to dc_update, this will
1992 if (pipe_ctx->plane_state && !old_pipe_ctx->plane_state) {
1993 if (old_pipe_ctx->stream_res.tg == tg &&
1994 old_pipe_ctx->plane_res.hubp &&
1995 old_pipe_ctx->plane_res.hubp->opp_id != 0xf) {
1996 dcn10_disable_plane(dc, pipe_ctx);
1998 * power down fe will unlock when calling reset, need
1999 * to lock it back here. Messy, need rework.
2001 pipe_ctx->stream_res.tg->funcs->lock(pipe_ctx->stream_res.tg);
2005 if (!pipe_ctx->plane_state &&
2006 old_pipe_ctx->plane_state &&
2007 old_pipe_ctx->stream_res.tg == tg) {
2009 plane_atomic_disconnect(dc, old_pipe_ctx);
2010 removed_pipe[i] = true;
2012 dm_logger_write(dc->ctx->logger, LOG_DC,
2013 "Reset mpcc for pipe %d\n",
2014 old_pipe_ctx->pipe_idx);
2019 program_all_pipe_in_tree(dc, top_pipe_to_program, context);
2021 tg->funcs->unlock(tg);
2023 if (num_planes == 0)
2024 false_optc_underflow_wa(dc, stream, tg);
2026 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2027 struct pipe_ctx *old_pipe_ctx =
2028 &dc->current_state->res_ctx.pipe_ctx[i];
2029 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2031 if (pipe_ctx->stream == stream &&
2032 pipe_ctx->plane_state &&
2033 pipe_ctx->plane_state->update_flags.bits.full_update)
2034 program_water_mark = true;
2036 if (removed_pipe[i])
2037 dcn10_disable_plane(dc, old_pipe_ctx);
2040 if (program_water_mark) {
2041 if (dc->debug.sanity_checks) {
2042 /* pstate stuck check after watermark update */
2043 dcn10_verify_allow_pstate_change_high(dc);
2046 /* watermark is for all pipes */
2047 hubbub1_program_watermarks(dc->res_pool->hubbub,
2048 &context->bw.dcn.watermarks, ref_clk_mhz);
2050 if (dc->debug.sanity_checks) {
2051 /* pstate stuck check after watermark update */
2052 dcn10_verify_allow_pstate_change_high(dc);
2055 /* dm_logger_write(dc->ctx->logger, LOG_BANDWIDTH_CALCS,
2056 "\n============== Watermark parameters ==============\n"
2057 "a.urgent_ns: %d \n"
2058 "a.cstate_enter_plus_exit: %d \n"
2059 "a.cstate_exit: %d \n"
2060 "a.pstate_change: %d \n"
2061 "a.pte_meta_urgent: %d \n"
2062 "b.urgent_ns: %d \n"
2063 "b.cstate_enter_plus_exit: %d \n"
2064 "b.cstate_exit: %d \n"
2065 "b.pstate_change: %d \n"
2066 "b.pte_meta_urgent: %d \n",
2067 context->bw.dcn.watermarks.a.urgent_ns,
2068 context->bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns,
2069 context->bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns,
2070 context->bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns,
2071 context->bw.dcn.watermarks.a.pte_meta_urgent_ns,
2072 context->bw.dcn.watermarks.b.urgent_ns,
2073 context->bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns,
2074 context->bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns,
2075 context->bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns,
2076 context->bw.dcn.watermarks.b.pte_meta_urgent_ns
2078 dm_logger_write(dc->ctx->logger, LOG_BANDWIDTH_CALCS,
2079 "\nc.urgent_ns: %d \n"
2080 "c.cstate_enter_plus_exit: %d \n"
2081 "c.cstate_exit: %d \n"
2082 "c.pstate_change: %d \n"
2083 "c.pte_meta_urgent: %d \n"
2084 "d.urgent_ns: %d \n"
2085 "d.cstate_enter_plus_exit: %d \n"
2086 "d.cstate_exit: %d \n"
2087 "d.pstate_change: %d \n"
2088 "d.pte_meta_urgent: %d \n"
2089 "========================================================\n",
2090 context->bw.dcn.watermarks.c.urgent_ns,
2091 context->bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns,
2092 context->bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns,
2093 context->bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns,
2094 context->bw.dcn.watermarks.c.pte_meta_urgent_ns,
2095 context->bw.dcn.watermarks.d.urgent_ns,
2096 context->bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns,
2097 context->bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns,
2098 context->bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns,
2099 context->bw.dcn.watermarks.d.pte_meta_urgent_ns
2104 static void dcn10_set_bandwidth(
2106 struct dc_state *context,
2107 bool decrease_allowed)
2109 struct pp_smu_display_requirement_rv *smu_req_cur =
2110 &dc->res_pool->pp_smu_req;
2111 struct pp_smu_display_requirement_rv smu_req = *smu_req_cur;
2112 struct pp_smu_funcs_rv *pp_smu = dc->res_pool->pp_smu;
2114 if (dc->debug.sanity_checks) {
2115 dcn10_verify_allow_pstate_change_high(dc);
2118 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
2121 if (decrease_allowed || context->bw.dcn.calc_clk.dispclk_khz
2122 > dc->current_state->bw.dcn.cur_clk.dispclk_khz) {
2123 dc->res_pool->display_clock->funcs->set_clock(
2124 dc->res_pool->display_clock,
2125 context->bw.dcn.calc_clk.dispclk_khz);
2126 dc->current_state->bw.dcn.cur_clk.dispclk_khz =
2127 context->bw.dcn.calc_clk.dispclk_khz;
2129 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_khz
2130 > dc->current_state->bw.dcn.cur_clk.dcfclk_khz) {
2131 smu_req.hard_min_dcefclk_khz =
2132 context->bw.dcn.calc_clk.dcfclk_khz;
2134 if (decrease_allowed || context->bw.dcn.calc_clk.fclk_khz
2135 > dc->current_state->bw.dcn.cur_clk.fclk_khz) {
2136 smu_req.hard_min_fclk_khz = context->bw.dcn.calc_clk.fclk_khz;
2138 if (decrease_allowed || context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz
2139 > dc->current_state->bw.dcn.cur_clk.dcfclk_deep_sleep_khz) {
2140 dc->current_state->bw.dcn.calc_clk.dcfclk_deep_sleep_khz =
2141 context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz;
2142 context->bw.dcn.cur_clk.dcfclk_deep_sleep_khz =
2143 context->bw.dcn.calc_clk.dcfclk_deep_sleep_khz;
2146 smu_req.display_count = context->stream_count;
2148 if (pp_smu->set_display_requirement)
2149 pp_smu->set_display_requirement(&pp_smu->pp_smu, &smu_req);
2151 *smu_req_cur = smu_req;
2153 /* Decrease in freq is increase in period so opposite comparison for dram_ccm */
2154 if (decrease_allowed || context->bw.dcn.calc_clk.dram_ccm_us
2155 < dc->current_state->bw.dcn.cur_clk.dram_ccm_us) {
2156 dc->current_state->bw.dcn.calc_clk.dram_ccm_us =
2157 context->bw.dcn.calc_clk.dram_ccm_us;
2158 context->bw.dcn.cur_clk.dram_ccm_us =
2159 context->bw.dcn.calc_clk.dram_ccm_us;
2161 if (decrease_allowed || context->bw.dcn.calc_clk.min_active_dram_ccm_us
2162 < dc->current_state->bw.dcn.cur_clk.min_active_dram_ccm_us) {
2163 dc->current_state->bw.dcn.calc_clk.min_active_dram_ccm_us =
2164 context->bw.dcn.calc_clk.min_active_dram_ccm_us;
2165 context->bw.dcn.cur_clk.min_active_dram_ccm_us =
2166 context->bw.dcn.calc_clk.min_active_dram_ccm_us;
2168 dcn10_pplib_apply_display_requirements(dc, context);
2170 if (dc->debug.sanity_checks) {
2171 dcn10_verify_allow_pstate_change_high(dc);
2174 /* need to fix this function. not doing the right thing here */
2177 static void set_drr(struct pipe_ctx **pipe_ctx,
2178 int num_pipes, int vmin, int vmax)
2181 struct drr_params params = {0};
2183 params.vertical_total_max = vmax;
2184 params.vertical_total_min = vmin;
2186 /* TODO: If multiple pipes are to be supported, you need
2189 for (i = 0; i < num_pipes; i++) {
2190 pipe_ctx[i]->stream_res.tg->funcs->set_drr(pipe_ctx[i]->stream_res.tg, ¶ms);
2194 static void get_position(struct pipe_ctx **pipe_ctx,
2196 struct crtc_position *position)
2200 /* TODO: handle pipes > 1
2202 for (i = 0; i < num_pipes; i++)
2203 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2206 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2207 int num_pipes, const struct dc_static_screen_events *events)
2210 unsigned int value = 0;
2212 if (events->surface_update)
2214 if (events->cursor_update)
2217 for (i = 0; i < num_pipes; i++)
2218 pipe_ctx[i]->stream_res.tg->funcs->
2219 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
2222 static void set_plane_config(
2223 const struct dc *dc,
2224 struct pipe_ctx *pipe_ctx,
2225 struct resource_context *res_ctx)
2228 program_gamut_remap(pipe_ctx);
2231 static void dcn10_config_stereo_parameters(
2232 struct dc_stream_state *stream, struct crtc_stereo_flags *flags)
2234 enum view_3d_format view_format = stream->view_format;
2235 enum dc_timing_3d_format timing_3d_format =\
2236 stream->timing.timing_3d_format;
2237 bool non_stereo_timing = false;
2239 if (timing_3d_format == TIMING_3D_FORMAT_NONE ||
2240 timing_3d_format == TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2241 timing_3d_format == TIMING_3D_FORMAT_TOP_AND_BOTTOM)
2242 non_stereo_timing = true;
2244 if (non_stereo_timing == false &&
2245 view_format == VIEW_3D_FORMAT_FRAME_SEQUENTIAL) {
2247 flags->PROGRAM_STEREO = 1;
2248 flags->PROGRAM_POLARITY = 1;
2249 if (timing_3d_format == TIMING_3D_FORMAT_INBAND_FA ||
2250 timing_3d_format == TIMING_3D_FORMAT_DP_HDMI_INBAND_FA ||
2251 timing_3d_format == TIMING_3D_FORMAT_SIDEBAND_FA) {
2252 enum display_dongle_type dongle = \
2253 stream->sink->link->ddc->dongle_type;
2254 if (dongle == DISPLAY_DONGLE_DP_VGA_CONVERTER ||
2255 dongle == DISPLAY_DONGLE_DP_DVI_CONVERTER ||
2256 dongle == DISPLAY_DONGLE_DP_HDMI_CONVERTER)
2257 flags->DISABLE_STEREO_DP_SYNC = 1;
2259 flags->RIGHT_EYE_POLARITY =\
2260 stream->timing.flags.RIGHT_EYE_3D_POLARITY;
2261 if (timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2262 flags->FRAME_PACKED = 1;
2268 static void dcn10_setup_stereo(struct pipe_ctx *pipe_ctx, struct dc *dc)
2270 struct crtc_stereo_flags flags = { 0 };
2271 struct dc_stream_state *stream = pipe_ctx->stream;
2273 dcn10_config_stereo_parameters(stream, &flags);
2275 pipe_ctx->stream_res.opp->funcs->opp_program_stereo(
2276 pipe_ctx->stream_res.opp,
2277 flags.PROGRAM_STEREO == 1 ? true:false,
2280 pipe_ctx->stream_res.tg->funcs->program_stereo(
2281 pipe_ctx->stream_res.tg,
2288 static void dcn10_wait_for_mpcc_disconnect(
2290 struct resource_pool *res_pool,
2291 struct pipe_ctx *pipe_ctx)
2295 if (dc->debug.sanity_checks) {
2296 dcn10_verify_allow_pstate_change_high(dc);
2299 if (!pipe_ctx->stream_res.opp)
2302 for (i = 0; i < MAX_PIPES; i++) {
2303 if (pipe_ctx->stream_res.opp->mpcc_disconnect_pending[i]) {
2304 res_pool->mpc->funcs->wait_for_idle(res_pool->mpc, i);
2305 pipe_ctx->stream_res.opp->mpcc_disconnect_pending[i] = false;
2306 res_pool->hubps[i]->funcs->set_blank(res_pool->hubps[i], true);
2307 /*dm_logger_write(dc->ctx->logger, LOG_ERROR,
2308 "[debug_mpo: wait_for_mpcc finished waiting on mpcc %d]\n",
2313 if (dc->debug.sanity_checks) {
2314 dcn10_verify_allow_pstate_change_high(dc);
2319 static bool dcn10_dummy_display_power_gating(
2321 uint8_t controller_id,
2322 struct dc_bios *dcb,
2323 enum pipe_gating_control power_gating)
2328 static void dcn10_update_pending_status(struct pipe_ctx *pipe_ctx)
2330 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2331 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2333 if (plane_state == NULL)
2336 plane_state->status.is_flip_pending =
2337 pipe_ctx->plane_res.hubp->funcs->hubp_is_flip_pending(
2338 pipe_ctx->plane_res.hubp);
2340 plane_state->status.current_address = pipe_ctx->plane_res.hubp->current_address;
2341 if (pipe_ctx->plane_res.hubp->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2342 tg->funcs->is_stereo_left_eye) {
2343 plane_state->status.is_right_eye =
2344 !tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2348 static void dcn10_update_dchub(struct dce_hwseq *hws, struct dchub_init_data *dh_data)
2350 if (hws->ctx->dc->res_pool->hubbub != NULL)
2351 hubbub1_update_dchub(hws->ctx->dc->res_pool->hubbub, dh_data);
2354 static void dcn10_set_cursor_position(struct pipe_ctx *pipe_ctx)
2356 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2357 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2358 struct dpp *dpp = pipe_ctx->plane_res.dpp;
2359 struct dc_cursor_mi_param param = {
2360 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_khz,
2361 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clock_inKhz,
2362 .viewport_x_start = pipe_ctx->plane_res.scl_data.viewport.x,
2363 .viewport_width = pipe_ctx->plane_res.scl_data.viewport.width,
2364 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz
2367 if (pipe_ctx->plane_state->address.type
2368 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2369 pos_cpy.enable = false;
2371 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2372 pos_cpy.enable = false;
2374 hubp->funcs->set_cursor_position(hubp, &pos_cpy, ¶m);
2375 dpp->funcs->set_cursor_position(dpp, &pos_cpy, ¶m, hubp->curs_attr.width);
2378 static void dcn10_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2380 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2382 pipe_ctx->plane_res.hubp->funcs->set_cursor_attributes(
2383 pipe_ctx->plane_res.hubp, attributes);
2384 pipe_ctx->plane_res.dpp->funcs->set_cursor_attributes(
2385 pipe_ctx->plane_res.dpp, attributes->color_format);
2388 static const struct hw_sequencer_funcs dcn10_funcs = {
2389 .program_gamut_remap = program_gamut_remap,
2390 .program_csc_matrix = program_csc_matrix,
2391 .init_hw = dcn10_init_hw,
2392 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2393 .apply_ctx_for_surface = dcn10_apply_ctx_for_surface,
2394 .set_plane_config = set_plane_config,
2395 .update_plane_addr = dcn10_update_plane_addr,
2396 .update_dchub = dcn10_update_dchub,
2397 .update_pending_status = dcn10_update_pending_status,
2398 .set_input_transfer_func = dcn10_set_input_transfer_func,
2399 .set_output_transfer_func = dcn10_set_output_transfer_func,
2400 .power_down = dce110_power_down,
2401 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2402 .enable_timing_synchronization = dcn10_enable_timing_synchronization,
2403 .enable_per_frame_crtc_position_reset = dcn10_enable_per_frame_crtc_position_reset,
2404 .update_info_frame = dce110_update_info_frame,
2405 .enable_stream = dce110_enable_stream,
2406 .disable_stream = dce110_disable_stream,
2407 .unblank_stream = dce110_unblank_stream,
2408 .enable_display_power_gating = dcn10_dummy_display_power_gating,
2409 .disable_plane = dcn10_disable_plane,
2410 .pipe_control_lock = dcn10_pipe_control_lock,
2411 .set_bandwidth = dcn10_set_bandwidth,
2412 .reset_hw_ctx_wrap = reset_hw_ctx_wrap,
2413 .prog_pixclk_crtc_otg = dcn10_prog_pixclk_crtc_otg,
2415 .get_position = get_position,
2416 .set_static_screen_control = set_static_screen_control,
2417 .setup_stereo = dcn10_setup_stereo,
2418 .set_avmute = dce110_set_avmute,
2419 .log_hw_state = dcn10_log_hw_state,
2420 .wait_for_mpcc_disconnect = dcn10_wait_for_mpcc_disconnect,
2421 .ready_shared_resources = ready_shared_resources,
2422 .optimize_shared_resources = optimize_shared_resources,
2423 .pplib_apply_display_requirements =
2424 dcn10_pplib_apply_display_requirements,
2425 .edp_backlight_control = hwss_edp_backlight_control,
2426 .edp_power_control = hwss_edp_power_control,
2427 .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready,
2428 .set_cursor_position = dcn10_set_cursor_position,
2429 .set_cursor_attribute = dcn10_set_cursor_attribute
2433 void dcn10_hw_sequencer_construct(struct dc *dc)
2435 dc->hwss = dcn10_funcs;