1 /* 2 * Copyright 2016 Advanced Micro Devices, Inc. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 * Authors: AMD 23 * 24 */ 25 #include <linux/delay.h> 26 27 #include "dm_services.h" 28 #include "basics/dc_common.h" 29 #include "dm_helpers.h" 30 #include "core_types.h" 31 #include "resource.h" 32 #include "dcn20_resource.h" 33 #include "dcn20_hwseq.h" 34 #include "dce/dce_hwseq.h" 35 #include "dcn20_dsc.h" 36 #include "dcn20_optc.h" 37 #include "abm.h" 38 #include "clk_mgr.h" 39 #include "dmcu.h" 40 #include "hubp.h" 41 #include "timing_generator.h" 42 #include "opp.h" 43 #include "ipp.h" 44 #include "mpc.h" 45 #include "mcif_wb.h" 46 #include "dchubbub.h" 47 #include "reg_helper.h" 48 #include "dcn10/dcn10_cm_common.h" 49 #include "dc_link_dp.h" 50 #include "vm_helper.h" 51 #include "dccg.h" 52 #include "dc_dmub_srv.h" 53 #include "dce/dmub_hw_lock_mgr.h" 54 #include "hw_sequencer.h" 55 #include "inc/link_dpcd.h" 56 #include "dpcd_defs.h" 57 #include "inc/link_enc_cfg.h" 58 59 #define DC_LOGGER_INIT(logger) 60 61 #define CTX \ 62 hws->ctx 63 #define REG(reg)\ 64 hws->regs->reg 65 66 #undef FN 67 #define FN(reg_name, field_name) \ 68 hws->shifts->field_name, hws->masks->field_name 69 70 static int find_free_gsl_group(const struct dc *dc) 71 { 72 if (dc->res_pool->gsl_groups.gsl_0 == 0) 73 return 1; 74 if (dc->res_pool->gsl_groups.gsl_1 == 0) 75 return 2; 76 if (dc->res_pool->gsl_groups.gsl_2 == 0) 77 return 3; 78 79 return 0; 80 } 81 82 /* NOTE: This is not a generic setup_gsl function (hence the suffix as_lock) 83 * This is only used to lock pipes in pipe splitting case with immediate flip 84 * Ordinary MPC/OTG locks suppress VUPDATE which doesn't help with immediate, 85 * so we get tearing with freesync since we cannot flip multiple pipes 86 * atomically. 87 * We use GSL for this: 88 * - immediate flip: find first available GSL group if not already assigned 89 * program gsl with that group, set current OTG as master 90 * and always us 0x4 = AND of flip_ready from all pipes 91 * - vsync flip: disable GSL if used 92 * 93 * Groups in stream_res are stored as +1 from HW registers, i.e. 94 * gsl_0 <=> pipe_ctx->stream_res.gsl_group == 1 95 * Using a magic value like -1 would require tracking all inits/resets 96 */ 97 static void dcn20_setup_gsl_group_as_lock( 98 const struct dc *dc, 99 struct pipe_ctx *pipe_ctx, 100 bool enable) 101 { 102 struct gsl_params gsl; 103 int group_idx; 104 105 memset(&gsl, 0, sizeof(struct gsl_params)); 106 107 if (enable) { 108 /* return if group already assigned since GSL was set up 109 * for vsync flip, we would unassign so it can't be "left over" 110 */ 111 if (pipe_ctx->stream_res.gsl_group > 0) 112 return; 113 114 group_idx = find_free_gsl_group(dc); 115 ASSERT(group_idx != 0); 116 pipe_ctx->stream_res.gsl_group = group_idx; 117 118 /* set gsl group reg field and mark resource used */ 119 switch (group_idx) { 120 case 1: 121 gsl.gsl0_en = 1; 122 dc->res_pool->gsl_groups.gsl_0 = 1; 123 break; 124 case 2: 125 gsl.gsl1_en = 1; 126 dc->res_pool->gsl_groups.gsl_1 = 1; 127 break; 128 case 3: 129 gsl.gsl2_en = 1; 130 dc->res_pool->gsl_groups.gsl_2 = 1; 131 break; 132 default: 133 BREAK_TO_DEBUGGER(); 134 return; // invalid case 135 } 136 gsl.gsl_master_en = 1; 137 } else { 138 group_idx = pipe_ctx->stream_res.gsl_group; 139 if (group_idx == 0) 140 return; // if not in use, just return 141 142 pipe_ctx->stream_res.gsl_group = 0; 143 144 /* unset gsl group reg field and mark resource free */ 145 switch (group_idx) { 146 case 1: 147 gsl.gsl0_en = 0; 148 dc->res_pool->gsl_groups.gsl_0 = 0; 149 break; 150 case 2: 151 gsl.gsl1_en = 0; 152 dc->res_pool->gsl_groups.gsl_1 = 0; 153 break; 154 case 3: 155 gsl.gsl2_en = 0; 156 dc->res_pool->gsl_groups.gsl_2 = 0; 157 break; 158 default: 159 BREAK_TO_DEBUGGER(); 160 return; 161 } 162 gsl.gsl_master_en = 0; 163 } 164 165 /* at this point we want to program whether it's to enable or disable */ 166 if (pipe_ctx->stream_res.tg->funcs->set_gsl != NULL && 167 pipe_ctx->stream_res.tg->funcs->set_gsl_source_select != NULL) { 168 pipe_ctx->stream_res.tg->funcs->set_gsl( 169 pipe_ctx->stream_res.tg, 170 &gsl); 171 172 pipe_ctx->stream_res.tg->funcs->set_gsl_source_select( 173 pipe_ctx->stream_res.tg, group_idx, enable ? 4 : 0); 174 } else 175 BREAK_TO_DEBUGGER(); 176 } 177 178 void dcn20_set_flip_control_gsl( 179 struct pipe_ctx *pipe_ctx, 180 bool flip_immediate) 181 { 182 if (pipe_ctx && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl) 183 pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl( 184 pipe_ctx->plane_res.hubp, flip_immediate); 185 186 } 187 188 void dcn20_enable_power_gating_plane( 189 struct dce_hwseq *hws, 190 bool enable) 191 { 192 bool force_on = true; /* disable power gating */ 193 194 if (enable) 195 force_on = false; 196 197 /* DCHUBP0/1/2/3/4/5 */ 198 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on); 199 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN2_POWER_FORCEON, force_on); 200 REG_UPDATE(DOMAIN4_PG_CONFIG, DOMAIN4_POWER_FORCEON, force_on); 201 REG_UPDATE(DOMAIN6_PG_CONFIG, DOMAIN6_POWER_FORCEON, force_on); 202 if (REG(DOMAIN8_PG_CONFIG)) 203 REG_UPDATE(DOMAIN8_PG_CONFIG, DOMAIN8_POWER_FORCEON, force_on); 204 if (REG(DOMAIN10_PG_CONFIG)) 205 REG_UPDATE(DOMAIN10_PG_CONFIG, DOMAIN8_POWER_FORCEON, force_on); 206 207 /* DPP0/1/2/3/4/5 */ 208 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN1_POWER_FORCEON, force_on); 209 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN3_POWER_FORCEON, force_on); 210 REG_UPDATE(DOMAIN5_PG_CONFIG, DOMAIN5_POWER_FORCEON, force_on); 211 REG_UPDATE(DOMAIN7_PG_CONFIG, DOMAIN7_POWER_FORCEON, force_on); 212 if (REG(DOMAIN9_PG_CONFIG)) 213 REG_UPDATE(DOMAIN9_PG_CONFIG, DOMAIN9_POWER_FORCEON, force_on); 214 if (REG(DOMAIN11_PG_CONFIG)) 215 REG_UPDATE(DOMAIN11_PG_CONFIG, DOMAIN9_POWER_FORCEON, force_on); 216 217 /* DCS0/1/2/3/4/5 */ 218 REG_UPDATE(DOMAIN16_PG_CONFIG, DOMAIN16_POWER_FORCEON, force_on); 219 REG_UPDATE(DOMAIN17_PG_CONFIG, DOMAIN17_POWER_FORCEON, force_on); 220 REG_UPDATE(DOMAIN18_PG_CONFIG, DOMAIN18_POWER_FORCEON, force_on); 221 if (REG(DOMAIN19_PG_CONFIG)) 222 REG_UPDATE(DOMAIN19_PG_CONFIG, DOMAIN19_POWER_FORCEON, force_on); 223 if (REG(DOMAIN20_PG_CONFIG)) 224 REG_UPDATE(DOMAIN20_PG_CONFIG, DOMAIN20_POWER_FORCEON, force_on); 225 if (REG(DOMAIN21_PG_CONFIG)) 226 REG_UPDATE(DOMAIN21_PG_CONFIG, DOMAIN21_POWER_FORCEON, force_on); 227 } 228 229 void dcn20_dccg_init(struct dce_hwseq *hws) 230 { 231 /* 232 * set MICROSECOND_TIME_BASE_DIV 233 * 100Mhz refclk -> 0x120264 234 * 27Mhz refclk -> 0x12021b 235 * 48Mhz refclk -> 0x120230 236 * 237 */ 238 REG_WRITE(MICROSECOND_TIME_BASE_DIV, 0x120264); 239 240 /* 241 * set MILLISECOND_TIME_BASE_DIV 242 * 100Mhz refclk -> 0x1186a0 243 * 27Mhz refclk -> 0x106978 244 * 48Mhz refclk -> 0x10bb80 245 * 246 */ 247 REG_WRITE(MILLISECOND_TIME_BASE_DIV, 0x1186a0); 248 249 /* This value is dependent on the hardware pipeline delay so set once per SOC */ 250 REG_WRITE(DISPCLK_FREQ_CHANGE_CNTL, 0xe01003c); 251 } 252 253 void dcn20_disable_vga( 254 struct dce_hwseq *hws) 255 { 256 REG_WRITE(D1VGA_CONTROL, 0); 257 REG_WRITE(D2VGA_CONTROL, 0); 258 REG_WRITE(D3VGA_CONTROL, 0); 259 REG_WRITE(D4VGA_CONTROL, 0); 260 REG_WRITE(D5VGA_CONTROL, 0); 261 REG_WRITE(D6VGA_CONTROL, 0); 262 } 263 264 void dcn20_program_triple_buffer( 265 const struct dc *dc, 266 struct pipe_ctx *pipe_ctx, 267 bool enable_triple_buffer) 268 { 269 if (pipe_ctx->plane_res.hubp && pipe_ctx->plane_res.hubp->funcs) { 270 pipe_ctx->plane_res.hubp->funcs->hubp_enable_tripleBuffer( 271 pipe_ctx->plane_res.hubp, 272 enable_triple_buffer); 273 } 274 } 275 276 /* Blank pixel data during initialization */ 277 void dcn20_init_blank( 278 struct dc *dc, 279 struct timing_generator *tg) 280 { 281 struct dce_hwseq *hws = dc->hwseq; 282 enum dc_color_space color_space; 283 struct tg_color black_color = {0}; 284 struct output_pixel_processor *opp = NULL; 285 struct output_pixel_processor *bottom_opp = NULL; 286 uint32_t num_opps, opp_id_src0, opp_id_src1; 287 uint32_t otg_active_width, otg_active_height; 288 289 /* program opp dpg blank color */ 290 color_space = COLOR_SPACE_SRGB; 291 color_space_to_black_color(dc, color_space, &black_color); 292 293 /* get the OTG active size */ 294 tg->funcs->get_otg_active_size(tg, 295 &otg_active_width, 296 &otg_active_height); 297 298 /* get the OPTC source */ 299 tg->funcs->get_optc_source(tg, &num_opps, &opp_id_src0, &opp_id_src1); 300 301 if (opp_id_src0 >= dc->res_pool->res_cap->num_opp) { 302 ASSERT(false); 303 return; 304 } 305 opp = dc->res_pool->opps[opp_id_src0]; 306 307 if (num_opps == 2) { 308 otg_active_width = otg_active_width / 2; 309 310 if (opp_id_src1 >= dc->res_pool->res_cap->num_opp) { 311 ASSERT(false); 312 return; 313 } 314 bottom_opp = dc->res_pool->opps[opp_id_src1]; 315 } 316 317 opp->funcs->opp_set_disp_pattern_generator( 318 opp, 319 CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR, 320 CONTROLLER_DP_COLOR_SPACE_UDEFINED, 321 COLOR_DEPTH_UNDEFINED, 322 &black_color, 323 otg_active_width, 324 otg_active_height, 325 0); 326 327 if (num_opps == 2) { 328 bottom_opp->funcs->opp_set_disp_pattern_generator( 329 bottom_opp, 330 CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR, 331 CONTROLLER_DP_COLOR_SPACE_UDEFINED, 332 COLOR_DEPTH_UNDEFINED, 333 &black_color, 334 otg_active_width, 335 otg_active_height, 336 0); 337 } 338 339 hws->funcs.wait_for_blank_complete(opp); 340 } 341 342 void dcn20_dsc_pg_control( 343 struct dce_hwseq *hws, 344 unsigned int dsc_inst, 345 bool power_on) 346 { 347 uint32_t power_gate = power_on ? 0 : 1; 348 uint32_t pwr_status = power_on ? 0 : 2; 349 uint32_t org_ip_request_cntl = 0; 350 351 if (hws->ctx->dc->debug.disable_dsc_power_gate) 352 return; 353 354 if (REG(DOMAIN16_PG_CONFIG) == 0) 355 return; 356 357 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl); 358 if (org_ip_request_cntl == 0) 359 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1); 360 361 switch (dsc_inst) { 362 case 0: /* DSC0 */ 363 REG_UPDATE(DOMAIN16_PG_CONFIG, 364 DOMAIN16_POWER_GATE, power_gate); 365 366 REG_WAIT(DOMAIN16_PG_STATUS, 367 DOMAIN16_PGFSM_PWR_STATUS, pwr_status, 368 1, 1000); 369 break; 370 case 1: /* DSC1 */ 371 REG_UPDATE(DOMAIN17_PG_CONFIG, 372 DOMAIN17_POWER_GATE, power_gate); 373 374 REG_WAIT(DOMAIN17_PG_STATUS, 375 DOMAIN17_PGFSM_PWR_STATUS, pwr_status, 376 1, 1000); 377 break; 378 case 2: /* DSC2 */ 379 REG_UPDATE(DOMAIN18_PG_CONFIG, 380 DOMAIN18_POWER_GATE, power_gate); 381 382 REG_WAIT(DOMAIN18_PG_STATUS, 383 DOMAIN18_PGFSM_PWR_STATUS, pwr_status, 384 1, 1000); 385 break; 386 case 3: /* DSC3 */ 387 REG_UPDATE(DOMAIN19_PG_CONFIG, 388 DOMAIN19_POWER_GATE, power_gate); 389 390 REG_WAIT(DOMAIN19_PG_STATUS, 391 DOMAIN19_PGFSM_PWR_STATUS, pwr_status, 392 1, 1000); 393 break; 394 case 4: /* DSC4 */ 395 REG_UPDATE(DOMAIN20_PG_CONFIG, 396 DOMAIN20_POWER_GATE, power_gate); 397 398 REG_WAIT(DOMAIN20_PG_STATUS, 399 DOMAIN20_PGFSM_PWR_STATUS, pwr_status, 400 1, 1000); 401 break; 402 case 5: /* DSC5 */ 403 REG_UPDATE(DOMAIN21_PG_CONFIG, 404 DOMAIN21_POWER_GATE, power_gate); 405 406 REG_WAIT(DOMAIN21_PG_STATUS, 407 DOMAIN21_PGFSM_PWR_STATUS, pwr_status, 408 1, 1000); 409 break; 410 default: 411 BREAK_TO_DEBUGGER(); 412 break; 413 } 414 415 if (org_ip_request_cntl == 0) 416 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0); 417 } 418 419 void dcn20_dpp_pg_control( 420 struct dce_hwseq *hws, 421 unsigned int dpp_inst, 422 bool power_on) 423 { 424 uint32_t power_gate = power_on ? 0 : 1; 425 uint32_t pwr_status = power_on ? 0 : 2; 426 427 if (hws->ctx->dc->debug.disable_dpp_power_gate) 428 return; 429 if (REG(DOMAIN1_PG_CONFIG) == 0) 430 return; 431 432 switch (dpp_inst) { 433 case 0: /* DPP0 */ 434 REG_UPDATE(DOMAIN1_PG_CONFIG, 435 DOMAIN1_POWER_GATE, power_gate); 436 437 REG_WAIT(DOMAIN1_PG_STATUS, 438 DOMAIN1_PGFSM_PWR_STATUS, pwr_status, 439 1, 1000); 440 break; 441 case 1: /* DPP1 */ 442 REG_UPDATE(DOMAIN3_PG_CONFIG, 443 DOMAIN3_POWER_GATE, power_gate); 444 445 REG_WAIT(DOMAIN3_PG_STATUS, 446 DOMAIN3_PGFSM_PWR_STATUS, pwr_status, 447 1, 1000); 448 break; 449 case 2: /* DPP2 */ 450 REG_UPDATE(DOMAIN5_PG_CONFIG, 451 DOMAIN5_POWER_GATE, power_gate); 452 453 REG_WAIT(DOMAIN5_PG_STATUS, 454 DOMAIN5_PGFSM_PWR_STATUS, pwr_status, 455 1, 1000); 456 break; 457 case 3: /* DPP3 */ 458 REG_UPDATE(DOMAIN7_PG_CONFIG, 459 DOMAIN7_POWER_GATE, power_gate); 460 461 REG_WAIT(DOMAIN7_PG_STATUS, 462 DOMAIN7_PGFSM_PWR_STATUS, pwr_status, 463 1, 1000); 464 break; 465 case 4: /* DPP4 */ 466 REG_UPDATE(DOMAIN9_PG_CONFIG, 467 DOMAIN9_POWER_GATE, power_gate); 468 469 REG_WAIT(DOMAIN9_PG_STATUS, 470 DOMAIN9_PGFSM_PWR_STATUS, pwr_status, 471 1, 1000); 472 break; 473 case 5: /* DPP5 */ 474 /* 475 * Do not power gate DPP5, should be left at HW default, power on permanently. 476 * PG on Pipe5 is De-featured, attempting to put it to PG state may result in hard 477 * reset. 478 * REG_UPDATE(DOMAIN11_PG_CONFIG, 479 * DOMAIN11_POWER_GATE, power_gate); 480 * 481 * REG_WAIT(DOMAIN11_PG_STATUS, 482 * DOMAIN11_PGFSM_PWR_STATUS, pwr_status, 483 * 1, 1000); 484 */ 485 break; 486 default: 487 BREAK_TO_DEBUGGER(); 488 break; 489 } 490 } 491 492 493 void dcn20_hubp_pg_control( 494 struct dce_hwseq *hws, 495 unsigned int hubp_inst, 496 bool power_on) 497 { 498 uint32_t power_gate = power_on ? 0 : 1; 499 uint32_t pwr_status = power_on ? 0 : 2; 500 501 if (hws->ctx->dc->debug.disable_hubp_power_gate) 502 return; 503 if (REG(DOMAIN0_PG_CONFIG) == 0) 504 return; 505 506 switch (hubp_inst) { 507 case 0: /* DCHUBP0 */ 508 REG_UPDATE(DOMAIN0_PG_CONFIG, 509 DOMAIN0_POWER_GATE, power_gate); 510 511 REG_WAIT(DOMAIN0_PG_STATUS, 512 DOMAIN0_PGFSM_PWR_STATUS, pwr_status, 513 1, 1000); 514 break; 515 case 1: /* DCHUBP1 */ 516 REG_UPDATE(DOMAIN2_PG_CONFIG, 517 DOMAIN2_POWER_GATE, power_gate); 518 519 REG_WAIT(DOMAIN2_PG_STATUS, 520 DOMAIN2_PGFSM_PWR_STATUS, pwr_status, 521 1, 1000); 522 break; 523 case 2: /* DCHUBP2 */ 524 REG_UPDATE(DOMAIN4_PG_CONFIG, 525 DOMAIN4_POWER_GATE, power_gate); 526 527 REG_WAIT(DOMAIN4_PG_STATUS, 528 DOMAIN4_PGFSM_PWR_STATUS, pwr_status, 529 1, 1000); 530 break; 531 case 3: /* DCHUBP3 */ 532 REG_UPDATE(DOMAIN6_PG_CONFIG, 533 DOMAIN6_POWER_GATE, power_gate); 534 535 REG_WAIT(DOMAIN6_PG_STATUS, 536 DOMAIN6_PGFSM_PWR_STATUS, pwr_status, 537 1, 1000); 538 break; 539 case 4: /* DCHUBP4 */ 540 REG_UPDATE(DOMAIN8_PG_CONFIG, 541 DOMAIN8_POWER_GATE, power_gate); 542 543 REG_WAIT(DOMAIN8_PG_STATUS, 544 DOMAIN8_PGFSM_PWR_STATUS, pwr_status, 545 1, 1000); 546 break; 547 case 5: /* DCHUBP5 */ 548 /* 549 * Do not power gate DCHUB5, should be left at HW default, power on permanently. 550 * PG on Pipe5 is De-featured, attempting to put it to PG state may result in hard 551 * reset. 552 * REG_UPDATE(DOMAIN10_PG_CONFIG, 553 * DOMAIN10_POWER_GATE, power_gate); 554 * 555 * REG_WAIT(DOMAIN10_PG_STATUS, 556 * DOMAIN10_PGFSM_PWR_STATUS, pwr_status, 557 * 1, 1000); 558 */ 559 break; 560 default: 561 BREAK_TO_DEBUGGER(); 562 break; 563 } 564 } 565 566 567 /* disable HW used by plane. 568 * note: cannot disable until disconnect is complete 569 */ 570 void dcn20_plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx) 571 { 572 struct dce_hwseq *hws = dc->hwseq; 573 struct hubp *hubp = pipe_ctx->plane_res.hubp; 574 struct dpp *dpp = pipe_ctx->plane_res.dpp; 575 576 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx); 577 578 /* In flip immediate with pipe splitting case GSL is used for 579 * synchronization so we must disable it when the plane is disabled. 580 */ 581 if (pipe_ctx->stream_res.gsl_group != 0) 582 dcn20_setup_gsl_group_as_lock(dc, pipe_ctx, false); 583 584 dc->hwss.set_flip_control_gsl(pipe_ctx, false); 585 586 hubp->funcs->hubp_clk_cntl(hubp, false); 587 588 dpp->funcs->dpp_dppclk_control(dpp, false, false); 589 590 hubp->power_gated = true; 591 592 hws->funcs.plane_atomic_power_down(dc, 593 pipe_ctx->plane_res.dpp, 594 pipe_ctx->plane_res.hubp); 595 596 pipe_ctx->stream = NULL; 597 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res)); 598 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res)); 599 pipe_ctx->top_pipe = NULL; 600 pipe_ctx->bottom_pipe = NULL; 601 pipe_ctx->plane_state = NULL; 602 } 603 604 605 void dcn20_disable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx) 606 { 607 DC_LOGGER_INIT(dc->ctx->logger); 608 609 if (!pipe_ctx->plane_res.hubp || pipe_ctx->plane_res.hubp->power_gated) 610 return; 611 612 dcn20_plane_atomic_disable(dc, pipe_ctx); 613 614 DC_LOG_DC("Power down front end %d\n", 615 pipe_ctx->pipe_idx); 616 } 617 618 void dcn20_disable_pixel_data(struct dc *dc, struct pipe_ctx *pipe_ctx, bool blank) 619 { 620 dcn20_blank_pixel_data(dc, pipe_ctx, blank); 621 } 622 623 static int calc_mpc_flow_ctrl_cnt(const struct dc_stream_state *stream, 624 int opp_cnt) 625 { 626 bool hblank_halved = optc2_is_two_pixels_per_containter(&stream->timing); 627 int flow_ctrl_cnt; 628 629 if (opp_cnt >= 2) 630 hblank_halved = true; 631 632 flow_ctrl_cnt = stream->timing.h_total - stream->timing.h_addressable - 633 stream->timing.h_border_left - 634 stream->timing.h_border_right; 635 636 if (hblank_halved) 637 flow_ctrl_cnt /= 2; 638 639 /* ODM combine 4:1 case */ 640 if (opp_cnt == 4) 641 flow_ctrl_cnt /= 2; 642 643 return flow_ctrl_cnt; 644 } 645 646 enum dc_status dcn20_enable_stream_timing( 647 struct pipe_ctx *pipe_ctx, 648 struct dc_state *context, 649 struct dc *dc) 650 { 651 struct dce_hwseq *hws = dc->hwseq; 652 struct dc_stream_state *stream = pipe_ctx->stream; 653 struct drr_params params = {0}; 654 unsigned int event_triggers = 0; 655 struct pipe_ctx *odm_pipe; 656 int opp_cnt = 1; 657 int opp_inst[MAX_PIPES] = { pipe_ctx->stream_res.opp->inst }; 658 bool interlace = stream->timing.flags.INTERLACE; 659 int i; 660 struct mpc_dwb_flow_control flow_control; 661 struct mpc *mpc = dc->res_pool->mpc; 662 bool rate_control_2x_pclk = (interlace || optc2_is_two_pixels_per_containter(&stream->timing)); 663 664 /* by upper caller loop, pipe0 is parent pipe and be called first. 665 * back end is set up by for pipe0. Other children pipe share back end 666 * with pipe 0. No program is needed. 667 */ 668 if (pipe_ctx->top_pipe != NULL) 669 return DC_OK; 670 671 /* TODO check if timing_changed, disable stream if timing changed */ 672 673 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) { 674 opp_inst[opp_cnt] = odm_pipe->stream_res.opp->inst; 675 opp_cnt++; 676 } 677 678 if (opp_cnt > 1) 679 pipe_ctx->stream_res.tg->funcs->set_odm_combine( 680 pipe_ctx->stream_res.tg, 681 opp_inst, opp_cnt, 682 &pipe_ctx->stream->timing); 683 684 /* HW program guide assume display already disable 685 * by unplug sequence. OTG assume stop. 686 */ 687 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true); 688 689 if (false == pipe_ctx->clock_source->funcs->program_pix_clk( 690 pipe_ctx->clock_source, 691 &pipe_ctx->stream_res.pix_clk_params, 692 &pipe_ctx->pll_settings)) { 693 BREAK_TO_DEBUGGER(); 694 return DC_ERROR_UNEXPECTED; 695 } 696 697 if (dc->hwseq->funcs.PLAT_58856_wa && (!dc_is_dp_signal(stream->signal))) 698 dc->hwseq->funcs.PLAT_58856_wa(context, pipe_ctx); 699 700 pipe_ctx->stream_res.tg->funcs->program_timing( 701 pipe_ctx->stream_res.tg, 702 &stream->timing, 703 pipe_ctx->pipe_dlg_param.vready_offset, 704 pipe_ctx->pipe_dlg_param.vstartup_start, 705 pipe_ctx->pipe_dlg_param.vupdate_offset, 706 pipe_ctx->pipe_dlg_param.vupdate_width, 707 pipe_ctx->stream->signal, 708 true); 709 710 rate_control_2x_pclk = rate_control_2x_pclk || opp_cnt > 1; 711 flow_control.flow_ctrl_mode = 0; 712 flow_control.flow_ctrl_cnt0 = 0x80; 713 flow_control.flow_ctrl_cnt1 = calc_mpc_flow_ctrl_cnt(stream, opp_cnt); 714 if (mpc->funcs->set_out_rate_control) { 715 for (i = 0; i < opp_cnt; ++i) { 716 mpc->funcs->set_out_rate_control( 717 mpc, opp_inst[i], 718 true, 719 rate_control_2x_pclk, 720 &flow_control); 721 } 722 } 723 724 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) 725 odm_pipe->stream_res.opp->funcs->opp_pipe_clock_control( 726 odm_pipe->stream_res.opp, 727 true); 728 729 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control( 730 pipe_ctx->stream_res.opp, 731 true); 732 733 hws->funcs.blank_pixel_data(dc, pipe_ctx, true); 734 735 /* VTG is within DCHUB command block. DCFCLK is always on */ 736 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) { 737 BREAK_TO_DEBUGGER(); 738 return DC_ERROR_UNEXPECTED; 739 } 740 741 hws->funcs.wait_for_blank_complete(pipe_ctx->stream_res.opp); 742 743 params.vertical_total_min = stream->adjust.v_total_min; 744 params.vertical_total_max = stream->adjust.v_total_max; 745 params.vertical_total_mid = stream->adjust.v_total_mid; 746 params.vertical_total_mid_frame_num = stream->adjust.v_total_mid_frame_num; 747 if (pipe_ctx->stream_res.tg->funcs->set_drr) 748 pipe_ctx->stream_res.tg->funcs->set_drr( 749 pipe_ctx->stream_res.tg, ¶ms); 750 751 // DRR should set trigger event to monitor surface update event 752 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0) 753 event_triggers = 0x80; 754 /* Event triggers and num frames initialized for DRR, but can be 755 * later updated for PSR use. Note DRR trigger events are generated 756 * regardless of whether num frames met. 757 */ 758 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control) 759 pipe_ctx->stream_res.tg->funcs->set_static_screen_control( 760 pipe_ctx->stream_res.tg, event_triggers, 2); 761 762 /* TODO program crtc source select for non-virtual signal*/ 763 /* TODO program FMT */ 764 /* TODO setup link_enc */ 765 /* TODO set stream attributes */ 766 /* TODO program audio */ 767 /* TODO enable stream if timing changed */ 768 /* TODO unblank stream if DP */ 769 770 return DC_OK; 771 } 772 773 void dcn20_program_output_csc(struct dc *dc, 774 struct pipe_ctx *pipe_ctx, 775 enum dc_color_space colorspace, 776 uint16_t *matrix, 777 int opp_id) 778 { 779 struct mpc *mpc = dc->res_pool->mpc; 780 enum mpc_output_csc_mode ocsc_mode = MPC_OUTPUT_CSC_COEF_A; 781 int mpcc_id = pipe_ctx->plane_res.hubp->inst; 782 783 if (mpc->funcs->power_on_mpc_mem_pwr) 784 mpc->funcs->power_on_mpc_mem_pwr(mpc, mpcc_id, true); 785 786 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) { 787 if (mpc->funcs->set_output_csc != NULL) 788 mpc->funcs->set_output_csc(mpc, 789 opp_id, 790 matrix, 791 ocsc_mode); 792 } else { 793 if (mpc->funcs->set_ocsc_default != NULL) 794 mpc->funcs->set_ocsc_default(mpc, 795 opp_id, 796 colorspace, 797 ocsc_mode); 798 } 799 } 800 801 bool dcn20_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx, 802 const struct dc_stream_state *stream) 803 { 804 int mpcc_id = pipe_ctx->plane_res.hubp->inst; 805 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc; 806 struct pwl_params *params = NULL; 807 /* 808 * program OGAM only for the top pipe 809 * if there is a pipe split then fix diagnostic is required: 810 * how to pass OGAM parameter for stream. 811 * if programming for all pipes is required then remove condition 812 * pipe_ctx->top_pipe == NULL ,but then fix the diagnostic. 813 */ 814 if (mpc->funcs->power_on_mpc_mem_pwr) 815 mpc->funcs->power_on_mpc_mem_pwr(mpc, mpcc_id, true); 816 if (pipe_ctx->top_pipe == NULL 817 && mpc->funcs->set_output_gamma && stream->out_transfer_func) { 818 if (stream->out_transfer_func->type == TF_TYPE_HWPWL) 819 params = &stream->out_transfer_func->pwl; 820 else if (pipe_ctx->stream->out_transfer_func->type == 821 TF_TYPE_DISTRIBUTED_POINTS && 822 cm_helper_translate_curve_to_hw_format( 823 stream->out_transfer_func, 824 &mpc->blender_params, false)) 825 params = &mpc->blender_params; 826 /* 827 * there is no ROM 828 */ 829 if (stream->out_transfer_func->type == TF_TYPE_PREDEFINED) 830 BREAK_TO_DEBUGGER(); 831 } 832 /* 833 * if above if is not executed then 'params' equal to 0 and set in bypass 834 */ 835 mpc->funcs->set_output_gamma(mpc, mpcc_id, params); 836 837 return true; 838 } 839 840 bool dcn20_set_blend_lut( 841 struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state) 842 { 843 struct dpp *dpp_base = pipe_ctx->plane_res.dpp; 844 bool result = true; 845 struct pwl_params *blend_lut = NULL; 846 847 if (plane_state->blend_tf) { 848 if (plane_state->blend_tf->type == TF_TYPE_HWPWL) 849 blend_lut = &plane_state->blend_tf->pwl; 850 else if (plane_state->blend_tf->type == TF_TYPE_DISTRIBUTED_POINTS) { 851 cm_helper_translate_curve_to_hw_format( 852 plane_state->blend_tf, 853 &dpp_base->regamma_params, false); 854 blend_lut = &dpp_base->regamma_params; 855 } 856 } 857 result = dpp_base->funcs->dpp_program_blnd_lut(dpp_base, blend_lut); 858 859 return result; 860 } 861 862 bool dcn20_set_shaper_3dlut( 863 struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state) 864 { 865 struct dpp *dpp_base = pipe_ctx->plane_res.dpp; 866 bool result = true; 867 struct pwl_params *shaper_lut = NULL; 868 869 if (plane_state->in_shaper_func) { 870 if (plane_state->in_shaper_func->type == TF_TYPE_HWPWL) 871 shaper_lut = &plane_state->in_shaper_func->pwl; 872 else if (plane_state->in_shaper_func->type == TF_TYPE_DISTRIBUTED_POINTS) { 873 cm_helper_translate_curve_to_hw_format( 874 plane_state->in_shaper_func, 875 &dpp_base->shaper_params, true); 876 shaper_lut = &dpp_base->shaper_params; 877 } 878 } 879 880 result = dpp_base->funcs->dpp_program_shaper_lut(dpp_base, shaper_lut); 881 if (plane_state->lut3d_func && 882 plane_state->lut3d_func->state.bits.initialized == 1) 883 result = dpp_base->funcs->dpp_program_3dlut(dpp_base, 884 &plane_state->lut3d_func->lut_3d); 885 else 886 result = dpp_base->funcs->dpp_program_3dlut(dpp_base, NULL); 887 888 return result; 889 } 890 891 bool dcn20_set_input_transfer_func(struct dc *dc, 892 struct pipe_ctx *pipe_ctx, 893 const struct dc_plane_state *plane_state) 894 { 895 struct dce_hwseq *hws = dc->hwseq; 896 struct dpp *dpp_base = pipe_ctx->plane_res.dpp; 897 const struct dc_transfer_func *tf = NULL; 898 bool result = true; 899 bool use_degamma_ram = false; 900 901 if (dpp_base == NULL || plane_state == NULL) 902 return false; 903 904 hws->funcs.set_shaper_3dlut(pipe_ctx, plane_state); 905 hws->funcs.set_blend_lut(pipe_ctx, plane_state); 906 907 if (plane_state->in_transfer_func) 908 tf = plane_state->in_transfer_func; 909 910 911 if (tf == NULL) { 912 dpp_base->funcs->dpp_set_degamma(dpp_base, 913 IPP_DEGAMMA_MODE_BYPASS); 914 return true; 915 } 916 917 if (tf->type == TF_TYPE_HWPWL || tf->type == TF_TYPE_DISTRIBUTED_POINTS) 918 use_degamma_ram = true; 919 920 if (use_degamma_ram == true) { 921 if (tf->type == TF_TYPE_HWPWL) 922 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base, 923 &tf->pwl); 924 else if (tf->type == TF_TYPE_DISTRIBUTED_POINTS) { 925 cm_helper_translate_curve_to_degamma_hw_format(tf, 926 &dpp_base->degamma_params); 927 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base, 928 &dpp_base->degamma_params); 929 } 930 return true; 931 } 932 /* handle here the optimized cases when de-gamma ROM could be used. 933 * 934 */ 935 if (tf->type == TF_TYPE_PREDEFINED) { 936 switch (tf->tf) { 937 case TRANSFER_FUNCTION_SRGB: 938 dpp_base->funcs->dpp_set_degamma(dpp_base, 939 IPP_DEGAMMA_MODE_HW_sRGB); 940 break; 941 case TRANSFER_FUNCTION_BT709: 942 dpp_base->funcs->dpp_set_degamma(dpp_base, 943 IPP_DEGAMMA_MODE_HW_xvYCC); 944 break; 945 case TRANSFER_FUNCTION_LINEAR: 946 dpp_base->funcs->dpp_set_degamma(dpp_base, 947 IPP_DEGAMMA_MODE_BYPASS); 948 break; 949 case TRANSFER_FUNCTION_PQ: 950 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_USER_PWL); 951 cm_helper_translate_curve_to_degamma_hw_format(tf, &dpp_base->degamma_params); 952 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base, &dpp_base->degamma_params); 953 result = true; 954 break; 955 default: 956 result = false; 957 break; 958 } 959 } else if (tf->type == TF_TYPE_BYPASS) 960 dpp_base->funcs->dpp_set_degamma(dpp_base, 961 IPP_DEGAMMA_MODE_BYPASS); 962 else { 963 /* 964 * if we are here, we did not handle correctly. 965 * fix is required for this use case 966 */ 967 BREAK_TO_DEBUGGER(); 968 dpp_base->funcs->dpp_set_degamma(dpp_base, 969 IPP_DEGAMMA_MODE_BYPASS); 970 } 971 972 return result; 973 } 974 975 void dcn20_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx) 976 { 977 struct pipe_ctx *odm_pipe; 978 int opp_cnt = 1; 979 int opp_inst[MAX_PIPES] = { pipe_ctx->stream_res.opp->inst }; 980 981 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) { 982 opp_inst[opp_cnt] = odm_pipe->stream_res.opp->inst; 983 opp_cnt++; 984 } 985 986 if (opp_cnt > 1) 987 pipe_ctx->stream_res.tg->funcs->set_odm_combine( 988 pipe_ctx->stream_res.tg, 989 opp_inst, opp_cnt, 990 &pipe_ctx->stream->timing); 991 else 992 pipe_ctx->stream_res.tg->funcs->set_odm_bypass( 993 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing); 994 } 995 996 void dcn20_blank_pixel_data( 997 struct dc *dc, 998 struct pipe_ctx *pipe_ctx, 999 bool blank) 1000 { 1001 struct tg_color black_color = {0}; 1002 struct stream_resource *stream_res = &pipe_ctx->stream_res; 1003 struct dc_stream_state *stream = pipe_ctx->stream; 1004 enum dc_color_space color_space = stream->output_color_space; 1005 enum controller_dp_test_pattern test_pattern = CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR; 1006 enum controller_dp_color_space test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED; 1007 struct pipe_ctx *odm_pipe; 1008 int odm_cnt = 1; 1009 1010 int width = stream->timing.h_addressable + stream->timing.h_border_left + stream->timing.h_border_right; 1011 int height = stream->timing.v_addressable + stream->timing.v_border_bottom + stream->timing.v_border_top; 1012 1013 if (stream->link->test_pattern_enabled) 1014 return; 1015 1016 /* get opp dpg blank color */ 1017 color_space_to_black_color(dc, color_space, &black_color); 1018 1019 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) 1020 odm_cnt++; 1021 1022 width = width / odm_cnt; 1023 1024 if (blank) { 1025 dc->hwss.set_abm_immediate_disable(pipe_ctx); 1026 1027 if (dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE) { 1028 test_pattern = CONTROLLER_DP_TEST_PATTERN_COLORSQUARES; 1029 test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_RGB; 1030 } 1031 } else { 1032 test_pattern = CONTROLLER_DP_TEST_PATTERN_VIDEOMODE; 1033 } 1034 1035 dc->hwss.set_disp_pattern_generator(dc, 1036 pipe_ctx, 1037 test_pattern, 1038 test_pattern_color_space, 1039 stream->timing.display_color_depth, 1040 &black_color, 1041 width, 1042 height, 1043 0); 1044 1045 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) { 1046 dc->hwss.set_disp_pattern_generator(dc, 1047 odm_pipe, 1048 dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE && blank ? 1049 CONTROLLER_DP_TEST_PATTERN_COLORRAMP : test_pattern, 1050 test_pattern_color_space, 1051 stream->timing.display_color_depth, 1052 &black_color, 1053 width, 1054 height, 1055 0); 1056 } 1057 1058 if (!blank) 1059 if (stream_res->abm) { 1060 dc->hwss.set_pipe(pipe_ctx); 1061 stream_res->abm->funcs->set_abm_level(stream_res->abm, stream->abm_level); 1062 } 1063 } 1064 1065 1066 static void dcn20_power_on_plane( 1067 struct dce_hwseq *hws, 1068 struct pipe_ctx *pipe_ctx) 1069 { 1070 DC_LOGGER_INIT(hws->ctx->logger); 1071 if (REG(DC_IP_REQUEST_CNTL)) { 1072 REG_SET(DC_IP_REQUEST_CNTL, 0, 1073 IP_REQUEST_EN, 1); 1074 1075 if (hws->funcs.dpp_pg_control) 1076 hws->funcs.dpp_pg_control(hws, pipe_ctx->plane_res.dpp->inst, true); 1077 1078 if (hws->funcs.hubp_pg_control) 1079 hws->funcs.hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, true); 1080 1081 REG_SET(DC_IP_REQUEST_CNTL, 0, 1082 IP_REQUEST_EN, 0); 1083 DC_LOG_DEBUG( 1084 "Un-gated front end for pipe %d\n", pipe_ctx->plane_res.hubp->inst); 1085 } 1086 } 1087 1088 static void dcn20_enable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx, 1089 struct dc_state *context) 1090 { 1091 //if (dc->debug.sanity_checks) { 1092 // dcn10_verify_allow_pstate_change_high(dc); 1093 //} 1094 dcn20_power_on_plane(dc->hwseq, pipe_ctx); 1095 1096 /* enable DCFCLK current DCHUB */ 1097 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true); 1098 1099 /* initialize HUBP on power up */ 1100 pipe_ctx->plane_res.hubp->funcs->hubp_init(pipe_ctx->plane_res.hubp); 1101 1102 /* make sure OPP_PIPE_CLOCK_EN = 1 */ 1103 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control( 1104 pipe_ctx->stream_res.opp, 1105 true); 1106 1107 /* TODO: enable/disable in dm as per update type. 1108 if (plane_state) { 1109 DC_LOG_DC(dc->ctx->logger, 1110 "Pipe:%d 0x%x: addr hi:0x%x, " 1111 "addr low:0x%x, " 1112 "src: %d, %d, %d," 1113 " %d; dst: %d, %d, %d, %d;\n", 1114 pipe_ctx->pipe_idx, 1115 plane_state, 1116 plane_state->address.grph.addr.high_part, 1117 plane_state->address.grph.addr.low_part, 1118 plane_state->src_rect.x, 1119 plane_state->src_rect.y, 1120 plane_state->src_rect.width, 1121 plane_state->src_rect.height, 1122 plane_state->dst_rect.x, 1123 plane_state->dst_rect.y, 1124 plane_state->dst_rect.width, 1125 plane_state->dst_rect.height); 1126 1127 DC_LOG_DC(dc->ctx->logger, 1128 "Pipe %d: width, height, x, y format:%d\n" 1129 "viewport:%d, %d, %d, %d\n" 1130 "recout: %d, %d, %d, %d\n", 1131 pipe_ctx->pipe_idx, 1132 plane_state->format, 1133 pipe_ctx->plane_res.scl_data.viewport.width, 1134 pipe_ctx->plane_res.scl_data.viewport.height, 1135 pipe_ctx->plane_res.scl_data.viewport.x, 1136 pipe_ctx->plane_res.scl_data.viewport.y, 1137 pipe_ctx->plane_res.scl_data.recout.width, 1138 pipe_ctx->plane_res.scl_data.recout.height, 1139 pipe_ctx->plane_res.scl_data.recout.x, 1140 pipe_ctx->plane_res.scl_data.recout.y); 1141 print_rq_dlg_ttu(dc, pipe_ctx); 1142 } 1143 */ 1144 if (dc->vm_pa_config.valid) { 1145 struct vm_system_aperture_param apt; 1146 1147 apt.sys_default.quad_part = 0; 1148 1149 apt.sys_low.quad_part = dc->vm_pa_config.system_aperture.start_addr; 1150 apt.sys_high.quad_part = dc->vm_pa_config.system_aperture.end_addr; 1151 1152 // Program system aperture settings 1153 pipe_ctx->plane_res.hubp->funcs->hubp_set_vm_system_aperture_settings(pipe_ctx->plane_res.hubp, &apt); 1154 } 1155 1156 if (!pipe_ctx->top_pipe 1157 && pipe_ctx->plane_state 1158 && pipe_ctx->plane_state->flip_int_enabled 1159 && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_int) 1160 pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_int(pipe_ctx->plane_res.hubp); 1161 1162 // if (dc->debug.sanity_checks) { 1163 // dcn10_verify_allow_pstate_change_high(dc); 1164 // } 1165 } 1166 1167 void dcn20_pipe_control_lock( 1168 struct dc *dc, 1169 struct pipe_ctx *pipe, 1170 bool lock) 1171 { 1172 struct pipe_ctx *temp_pipe; 1173 bool flip_immediate = false; 1174 1175 /* use TG master update lock to lock everything on the TG 1176 * therefore only top pipe need to lock 1177 */ 1178 if (!pipe || pipe->top_pipe) 1179 return; 1180 1181 if (pipe->plane_state != NULL) 1182 flip_immediate = pipe->plane_state->flip_immediate; 1183 1184 if (pipe->stream_res.gsl_group > 0) { 1185 temp_pipe = pipe->bottom_pipe; 1186 while (!flip_immediate && temp_pipe) { 1187 if (temp_pipe->plane_state != NULL) 1188 flip_immediate = temp_pipe->plane_state->flip_immediate; 1189 temp_pipe = temp_pipe->bottom_pipe; 1190 } 1191 } 1192 1193 if (flip_immediate && lock) { 1194 const int TIMEOUT_FOR_FLIP_PENDING = 100000; 1195 int i; 1196 1197 temp_pipe = pipe; 1198 while (temp_pipe) { 1199 if (temp_pipe->plane_state && temp_pipe->plane_state->flip_immediate) { 1200 for (i = 0; i < TIMEOUT_FOR_FLIP_PENDING; ++i) { 1201 if (!temp_pipe->plane_res.hubp->funcs->hubp_is_flip_pending(temp_pipe->plane_res.hubp)) 1202 break; 1203 udelay(1); 1204 } 1205 1206 /* no reason it should take this long for immediate flips */ 1207 ASSERT(i != TIMEOUT_FOR_FLIP_PENDING); 1208 } 1209 temp_pipe = temp_pipe->bottom_pipe; 1210 } 1211 } 1212 1213 /* In flip immediate and pipe splitting case, we need to use GSL 1214 * for synchronization. Only do setup on locking and on flip type change. 1215 */ 1216 if (lock && (pipe->bottom_pipe != NULL || !flip_immediate)) 1217 if ((flip_immediate && pipe->stream_res.gsl_group == 0) || 1218 (!flip_immediate && pipe->stream_res.gsl_group > 0)) 1219 dcn20_setup_gsl_group_as_lock(dc, pipe, flip_immediate); 1220 1221 if (pipe->plane_state != NULL) 1222 flip_immediate = pipe->plane_state->flip_immediate; 1223 1224 temp_pipe = pipe->bottom_pipe; 1225 while (flip_immediate && temp_pipe) { 1226 if (temp_pipe->plane_state != NULL) 1227 flip_immediate = temp_pipe->plane_state->flip_immediate; 1228 temp_pipe = temp_pipe->bottom_pipe; 1229 } 1230 1231 if (!lock && pipe->stream_res.gsl_group > 0 && pipe->plane_state && 1232 !flip_immediate) 1233 dcn20_setup_gsl_group_as_lock(dc, pipe, false); 1234 1235 if (pipe->stream && should_use_dmub_lock(pipe->stream->link)) { 1236 union dmub_hw_lock_flags hw_locks = { 0 }; 1237 struct dmub_hw_lock_inst_flags inst_flags = { 0 }; 1238 1239 hw_locks.bits.lock_pipe = 1; 1240 inst_flags.otg_inst = pipe->stream_res.tg->inst; 1241 1242 if (pipe->plane_state != NULL) 1243 hw_locks.bits.triple_buffer_lock = pipe->plane_state->triplebuffer_flips; 1244 1245 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv, 1246 lock, 1247 &hw_locks, 1248 &inst_flags); 1249 } else if (pipe->plane_state != NULL && pipe->plane_state->triplebuffer_flips) { 1250 if (lock) 1251 pipe->stream_res.tg->funcs->triplebuffer_lock(pipe->stream_res.tg); 1252 else 1253 pipe->stream_res.tg->funcs->triplebuffer_unlock(pipe->stream_res.tg); 1254 } else { 1255 if (lock) 1256 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg); 1257 else 1258 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg); 1259 } 1260 } 1261 1262 static void dcn20_detect_pipe_changes(struct pipe_ctx *old_pipe, struct pipe_ctx *new_pipe) 1263 { 1264 new_pipe->update_flags.raw = 0; 1265 1266 /* Exit on unchanged, unused pipe */ 1267 if (!old_pipe->plane_state && !new_pipe->plane_state) 1268 return; 1269 /* Detect pipe enable/disable */ 1270 if (!old_pipe->plane_state && new_pipe->plane_state) { 1271 new_pipe->update_flags.bits.enable = 1; 1272 new_pipe->update_flags.bits.mpcc = 1; 1273 new_pipe->update_flags.bits.dppclk = 1; 1274 new_pipe->update_flags.bits.hubp_interdependent = 1; 1275 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1; 1276 new_pipe->update_flags.bits.gamut_remap = 1; 1277 new_pipe->update_flags.bits.scaler = 1; 1278 new_pipe->update_flags.bits.viewport = 1; 1279 new_pipe->update_flags.bits.det_size = 1; 1280 if (!new_pipe->top_pipe && !new_pipe->prev_odm_pipe) { 1281 new_pipe->update_flags.bits.odm = 1; 1282 new_pipe->update_flags.bits.global_sync = 1; 1283 } 1284 return; 1285 } 1286 if (old_pipe->plane_state && !new_pipe->plane_state) { 1287 new_pipe->update_flags.bits.disable = 1; 1288 return; 1289 } 1290 1291 /* Detect plane change */ 1292 if (old_pipe->plane_state != new_pipe->plane_state) { 1293 new_pipe->update_flags.bits.plane_changed = true; 1294 } 1295 1296 /* Detect top pipe only changes */ 1297 if (!new_pipe->top_pipe && !new_pipe->prev_odm_pipe) { 1298 /* Detect odm changes */ 1299 if ((old_pipe->next_odm_pipe && new_pipe->next_odm_pipe 1300 && old_pipe->next_odm_pipe->pipe_idx != new_pipe->next_odm_pipe->pipe_idx) 1301 || (!old_pipe->next_odm_pipe && new_pipe->next_odm_pipe) 1302 || (old_pipe->next_odm_pipe && !new_pipe->next_odm_pipe) 1303 || old_pipe->stream_res.opp != new_pipe->stream_res.opp) 1304 new_pipe->update_flags.bits.odm = 1; 1305 1306 /* Detect global sync changes */ 1307 if (old_pipe->pipe_dlg_param.vready_offset != new_pipe->pipe_dlg_param.vready_offset 1308 || old_pipe->pipe_dlg_param.vstartup_start != new_pipe->pipe_dlg_param.vstartup_start 1309 || old_pipe->pipe_dlg_param.vupdate_offset != new_pipe->pipe_dlg_param.vupdate_offset 1310 || old_pipe->pipe_dlg_param.vupdate_width != new_pipe->pipe_dlg_param.vupdate_width) 1311 new_pipe->update_flags.bits.global_sync = 1; 1312 } 1313 1314 if (old_pipe->det_buffer_size_kb != new_pipe->det_buffer_size_kb) 1315 new_pipe->update_flags.bits.det_size = 1; 1316 1317 /* 1318 * Detect opp / tg change, only set on change, not on enable 1319 * Assume mpcc inst = pipe index, if not this code needs to be updated 1320 * since mpcc is what is affected by these. In fact all of our sequence 1321 * makes this assumption at the moment with how hubp reset is matched to 1322 * same index mpcc reset. 1323 */ 1324 if (old_pipe->stream_res.opp != new_pipe->stream_res.opp) 1325 new_pipe->update_flags.bits.opp_changed = 1; 1326 if (old_pipe->stream_res.tg != new_pipe->stream_res.tg) 1327 new_pipe->update_flags.bits.tg_changed = 1; 1328 1329 /* 1330 * Detect mpcc blending changes, only dpp inst and opp matter here, 1331 * mpccs getting removed/inserted update connected ones during their own 1332 * programming 1333 */ 1334 if (old_pipe->plane_res.dpp != new_pipe->plane_res.dpp 1335 || old_pipe->stream_res.opp != new_pipe->stream_res.opp) 1336 new_pipe->update_flags.bits.mpcc = 1; 1337 1338 /* Detect dppclk change */ 1339 if (old_pipe->plane_res.bw.dppclk_khz != new_pipe->plane_res.bw.dppclk_khz) 1340 new_pipe->update_flags.bits.dppclk = 1; 1341 1342 /* Check for scl update */ 1343 if (memcmp(&old_pipe->plane_res.scl_data, &new_pipe->plane_res.scl_data, sizeof(struct scaler_data))) 1344 new_pipe->update_flags.bits.scaler = 1; 1345 /* Check for vp update */ 1346 if (memcmp(&old_pipe->plane_res.scl_data.viewport, &new_pipe->plane_res.scl_data.viewport, sizeof(struct rect)) 1347 || memcmp(&old_pipe->plane_res.scl_data.viewport_c, 1348 &new_pipe->plane_res.scl_data.viewport_c, sizeof(struct rect))) 1349 new_pipe->update_flags.bits.viewport = 1; 1350 1351 /* Detect dlg/ttu/rq updates */ 1352 { 1353 struct _vcs_dpi_display_dlg_regs_st old_dlg_attr = old_pipe->dlg_regs; 1354 struct _vcs_dpi_display_ttu_regs_st old_ttu_attr = old_pipe->ttu_regs; 1355 struct _vcs_dpi_display_dlg_regs_st *new_dlg_attr = &new_pipe->dlg_regs; 1356 struct _vcs_dpi_display_ttu_regs_st *new_ttu_attr = &new_pipe->ttu_regs; 1357 1358 /* Detect pipe interdependent updates */ 1359 if (old_dlg_attr.dst_y_prefetch != new_dlg_attr->dst_y_prefetch || 1360 old_dlg_attr.vratio_prefetch != new_dlg_attr->vratio_prefetch || 1361 old_dlg_attr.vratio_prefetch_c != new_dlg_attr->vratio_prefetch_c || 1362 old_dlg_attr.dst_y_per_vm_vblank != new_dlg_attr->dst_y_per_vm_vblank || 1363 old_dlg_attr.dst_y_per_row_vblank != new_dlg_attr->dst_y_per_row_vblank || 1364 old_dlg_attr.dst_y_per_vm_flip != new_dlg_attr->dst_y_per_vm_flip || 1365 old_dlg_attr.dst_y_per_row_flip != new_dlg_attr->dst_y_per_row_flip || 1366 old_dlg_attr.refcyc_per_meta_chunk_vblank_l != new_dlg_attr->refcyc_per_meta_chunk_vblank_l || 1367 old_dlg_attr.refcyc_per_meta_chunk_vblank_c != new_dlg_attr->refcyc_per_meta_chunk_vblank_c || 1368 old_dlg_attr.refcyc_per_meta_chunk_flip_l != new_dlg_attr->refcyc_per_meta_chunk_flip_l || 1369 old_dlg_attr.refcyc_per_line_delivery_pre_l != new_dlg_attr->refcyc_per_line_delivery_pre_l || 1370 old_dlg_attr.refcyc_per_line_delivery_pre_c != new_dlg_attr->refcyc_per_line_delivery_pre_c || 1371 old_ttu_attr.refcyc_per_req_delivery_pre_l != new_ttu_attr->refcyc_per_req_delivery_pre_l || 1372 old_ttu_attr.refcyc_per_req_delivery_pre_c != new_ttu_attr->refcyc_per_req_delivery_pre_c || 1373 old_ttu_attr.refcyc_per_req_delivery_pre_cur0 != new_ttu_attr->refcyc_per_req_delivery_pre_cur0 || 1374 old_ttu_attr.refcyc_per_req_delivery_pre_cur1 != new_ttu_attr->refcyc_per_req_delivery_pre_cur1 || 1375 old_ttu_attr.min_ttu_vblank != new_ttu_attr->min_ttu_vblank || 1376 old_ttu_attr.qos_level_flip != new_ttu_attr->qos_level_flip) { 1377 old_dlg_attr.dst_y_prefetch = new_dlg_attr->dst_y_prefetch; 1378 old_dlg_attr.vratio_prefetch = new_dlg_attr->vratio_prefetch; 1379 old_dlg_attr.vratio_prefetch_c = new_dlg_attr->vratio_prefetch_c; 1380 old_dlg_attr.dst_y_per_vm_vblank = new_dlg_attr->dst_y_per_vm_vblank; 1381 old_dlg_attr.dst_y_per_row_vblank = new_dlg_attr->dst_y_per_row_vblank; 1382 old_dlg_attr.dst_y_per_vm_flip = new_dlg_attr->dst_y_per_vm_flip; 1383 old_dlg_attr.dst_y_per_row_flip = new_dlg_attr->dst_y_per_row_flip; 1384 old_dlg_attr.refcyc_per_meta_chunk_vblank_l = new_dlg_attr->refcyc_per_meta_chunk_vblank_l; 1385 old_dlg_attr.refcyc_per_meta_chunk_vblank_c = new_dlg_attr->refcyc_per_meta_chunk_vblank_c; 1386 old_dlg_attr.refcyc_per_meta_chunk_flip_l = new_dlg_attr->refcyc_per_meta_chunk_flip_l; 1387 old_dlg_attr.refcyc_per_line_delivery_pre_l = new_dlg_attr->refcyc_per_line_delivery_pre_l; 1388 old_dlg_attr.refcyc_per_line_delivery_pre_c = new_dlg_attr->refcyc_per_line_delivery_pre_c; 1389 old_ttu_attr.refcyc_per_req_delivery_pre_l = new_ttu_attr->refcyc_per_req_delivery_pre_l; 1390 old_ttu_attr.refcyc_per_req_delivery_pre_c = new_ttu_attr->refcyc_per_req_delivery_pre_c; 1391 old_ttu_attr.refcyc_per_req_delivery_pre_cur0 = new_ttu_attr->refcyc_per_req_delivery_pre_cur0; 1392 old_ttu_attr.refcyc_per_req_delivery_pre_cur1 = new_ttu_attr->refcyc_per_req_delivery_pre_cur1; 1393 old_ttu_attr.min_ttu_vblank = new_ttu_attr->min_ttu_vblank; 1394 old_ttu_attr.qos_level_flip = new_ttu_attr->qos_level_flip; 1395 new_pipe->update_flags.bits.hubp_interdependent = 1; 1396 } 1397 /* Detect any other updates to ttu/rq/dlg */ 1398 if (memcmp(&old_dlg_attr, &new_pipe->dlg_regs, sizeof(old_dlg_attr)) || 1399 memcmp(&old_ttu_attr, &new_pipe->ttu_regs, sizeof(old_ttu_attr)) || 1400 memcmp(&old_pipe->rq_regs, &new_pipe->rq_regs, sizeof(old_pipe->rq_regs))) 1401 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1; 1402 } 1403 } 1404 1405 static void dcn20_update_dchubp_dpp( 1406 struct dc *dc, 1407 struct pipe_ctx *pipe_ctx, 1408 struct dc_state *context) 1409 { 1410 struct dce_hwseq *hws = dc->hwseq; 1411 struct hubp *hubp = pipe_ctx->plane_res.hubp; 1412 struct dpp *dpp = pipe_ctx->plane_res.dpp; 1413 struct dc_plane_state *plane_state = pipe_ctx->plane_state; 1414 bool viewport_changed = false; 1415 1416 if (pipe_ctx->update_flags.bits.dppclk) 1417 dpp->funcs->dpp_dppclk_control(dpp, false, true); 1418 1419 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG 1420 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP. 1421 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG 1422 */ 1423 if (pipe_ctx->update_flags.bits.hubp_rq_dlg_ttu) { 1424 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst); 1425 1426 hubp->funcs->hubp_setup( 1427 hubp, 1428 &pipe_ctx->dlg_regs, 1429 &pipe_ctx->ttu_regs, 1430 &pipe_ctx->rq_regs, 1431 &pipe_ctx->pipe_dlg_param); 1432 1433 if (hubp->funcs->set_unbounded_requesting) 1434 hubp->funcs->set_unbounded_requesting(hubp, pipe_ctx->unbounded_req); 1435 } 1436 if (pipe_ctx->update_flags.bits.hubp_interdependent) 1437 hubp->funcs->hubp_setup_interdependent( 1438 hubp, 1439 &pipe_ctx->dlg_regs, 1440 &pipe_ctx->ttu_regs); 1441 1442 if (pipe_ctx->update_flags.bits.enable || 1443 pipe_ctx->update_flags.bits.plane_changed || 1444 plane_state->update_flags.bits.bpp_change || 1445 plane_state->update_flags.bits.input_csc_change || 1446 plane_state->update_flags.bits.color_space_change || 1447 plane_state->update_flags.bits.coeff_reduction_change) { 1448 struct dc_bias_and_scale bns_params = {0}; 1449 1450 // program the input csc 1451 dpp->funcs->dpp_setup(dpp, 1452 plane_state->format, 1453 EXPANSION_MODE_ZERO, 1454 plane_state->input_csc_color_matrix, 1455 plane_state->color_space, 1456 NULL); 1457 1458 if (dpp->funcs->dpp_program_bias_and_scale) { 1459 //TODO :for CNVC set scale and bias registers if necessary 1460 build_prescale_params(&bns_params, plane_state); 1461 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params); 1462 } 1463 } 1464 1465 if (pipe_ctx->update_flags.bits.mpcc 1466 || pipe_ctx->update_flags.bits.plane_changed 1467 || plane_state->update_flags.bits.global_alpha_change 1468 || plane_state->update_flags.bits.per_pixel_alpha_change) { 1469 // MPCC inst is equal to pipe index in practice 1470 int mpcc_inst = hubp->inst; 1471 int opp_inst; 1472 int opp_count = dc->res_pool->pipe_count; 1473 1474 for (opp_inst = 0; opp_inst < opp_count; opp_inst++) { 1475 if (dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst]) { 1476 dc->res_pool->mpc->funcs->wait_for_idle(dc->res_pool->mpc, mpcc_inst); 1477 dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst] = false; 1478 break; 1479 } 1480 } 1481 hws->funcs.update_mpcc(dc, pipe_ctx); 1482 } 1483 1484 if (pipe_ctx->update_flags.bits.scaler || 1485 plane_state->update_flags.bits.scaling_change || 1486 plane_state->update_flags.bits.position_change || 1487 plane_state->update_flags.bits.per_pixel_alpha_change || 1488 pipe_ctx->stream->update_flags.bits.scaling) { 1489 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->plane_state->per_pixel_alpha; 1490 ASSERT(pipe_ctx->plane_res.scl_data.lb_params.depth == LB_PIXEL_DEPTH_36BPP); 1491 /* scaler configuration */ 1492 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler( 1493 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data); 1494 } 1495 1496 if (pipe_ctx->update_flags.bits.viewport || 1497 (context == dc->current_state && plane_state->update_flags.bits.position_change) || 1498 (context == dc->current_state && plane_state->update_flags.bits.scaling_change) || 1499 (context == dc->current_state && pipe_ctx->stream->update_flags.bits.scaling)) { 1500 1501 hubp->funcs->mem_program_viewport( 1502 hubp, 1503 &pipe_ctx->plane_res.scl_data.viewport, 1504 &pipe_ctx->plane_res.scl_data.viewport_c); 1505 viewport_changed = true; 1506 } 1507 1508 /* Any updates are handled in dc interface, just need to apply existing for plane enable */ 1509 if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed || 1510 pipe_ctx->update_flags.bits.scaler || viewport_changed == true) && 1511 pipe_ctx->stream->cursor_attributes.address.quad_part != 0) { 1512 dc->hwss.set_cursor_position(pipe_ctx); 1513 dc->hwss.set_cursor_attribute(pipe_ctx); 1514 1515 if (dc->hwss.set_cursor_sdr_white_level) 1516 dc->hwss.set_cursor_sdr_white_level(pipe_ctx); 1517 } 1518 1519 /* Any updates are handled in dc interface, just need 1520 * to apply existing for plane enable / opp change */ 1521 if (pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed 1522 || pipe_ctx->stream->update_flags.bits.gamut_remap 1523 || pipe_ctx->stream->update_flags.bits.out_csc) { 1524 /* dpp/cm gamut remap*/ 1525 dc->hwss.program_gamut_remap(pipe_ctx); 1526 1527 /*call the dcn2 method which uses mpc csc*/ 1528 dc->hwss.program_output_csc(dc, 1529 pipe_ctx, 1530 pipe_ctx->stream->output_color_space, 1531 pipe_ctx->stream->csc_color_matrix.matrix, 1532 hubp->opp_id); 1533 } 1534 1535 if (pipe_ctx->update_flags.bits.enable || 1536 pipe_ctx->update_flags.bits.plane_changed || 1537 pipe_ctx->update_flags.bits.opp_changed || 1538 plane_state->update_flags.bits.pixel_format_change || 1539 plane_state->update_flags.bits.horizontal_mirror_change || 1540 plane_state->update_flags.bits.rotation_change || 1541 plane_state->update_flags.bits.swizzle_change || 1542 plane_state->update_flags.bits.dcc_change || 1543 plane_state->update_flags.bits.bpp_change || 1544 plane_state->update_flags.bits.scaling_change || 1545 plane_state->update_flags.bits.plane_size_change) { 1546 struct plane_size size = plane_state->plane_size; 1547 1548 size.surface_size = pipe_ctx->plane_res.scl_data.viewport; 1549 hubp->funcs->hubp_program_surface_config( 1550 hubp, 1551 plane_state->format, 1552 &plane_state->tiling_info, 1553 &size, 1554 plane_state->rotation, 1555 &plane_state->dcc, 1556 plane_state->horizontal_mirror, 1557 0); 1558 hubp->power_gated = false; 1559 } 1560 1561 if (pipe_ctx->update_flags.bits.enable || 1562 pipe_ctx->update_flags.bits.plane_changed || 1563 plane_state->update_flags.bits.addr_update) 1564 hws->funcs.update_plane_addr(dc, pipe_ctx); 1565 1566 1567 1568 if (pipe_ctx->update_flags.bits.enable) 1569 hubp->funcs->set_blank(hubp, false); 1570 } 1571 1572 1573 static void dcn20_program_pipe( 1574 struct dc *dc, 1575 struct pipe_ctx *pipe_ctx, 1576 struct dc_state *context) 1577 { 1578 struct dce_hwseq *hws = dc->hwseq; 1579 /* Only need to unblank on top pipe */ 1580 if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->stream->update_flags.bits.abm_level) 1581 && !pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe) 1582 hws->funcs.blank_pixel_data(dc, pipe_ctx, !pipe_ctx->plane_state->visible); 1583 1584 /* Only update TG on top pipe */ 1585 if (pipe_ctx->update_flags.bits.global_sync && !pipe_ctx->top_pipe 1586 && !pipe_ctx->prev_odm_pipe) { 1587 1588 pipe_ctx->stream_res.tg->funcs->program_global_sync( 1589 pipe_ctx->stream_res.tg, 1590 pipe_ctx->pipe_dlg_param.vready_offset, 1591 pipe_ctx->pipe_dlg_param.vstartup_start, 1592 pipe_ctx->pipe_dlg_param.vupdate_offset, 1593 pipe_ctx->pipe_dlg_param.vupdate_width); 1594 1595 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VBLANK); 1596 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE); 1597 1598 pipe_ctx->stream_res.tg->funcs->set_vtg_params( 1599 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, true); 1600 1601 if (hws->funcs.setup_vupdate_interrupt) 1602 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx); 1603 } 1604 1605 if (pipe_ctx->update_flags.bits.odm) 1606 hws->funcs.update_odm(dc, context, pipe_ctx); 1607 1608 if (pipe_ctx->update_flags.bits.enable) { 1609 dcn20_enable_plane(dc, pipe_ctx, context); 1610 if (dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes) 1611 dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes(dc->res_pool->hubbub); 1612 } 1613 1614 if (dc->res_pool->hubbub->funcs->program_det_size && pipe_ctx->update_flags.bits.det_size) 1615 dc->res_pool->hubbub->funcs->program_det_size( 1616 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->det_buffer_size_kb); 1617 1618 if (pipe_ctx->update_flags.raw || pipe_ctx->plane_state->update_flags.raw || pipe_ctx->stream->update_flags.raw) 1619 dcn20_update_dchubp_dpp(dc, pipe_ctx, context); 1620 1621 if (pipe_ctx->update_flags.bits.enable 1622 || pipe_ctx->plane_state->update_flags.bits.hdr_mult) 1623 hws->funcs.set_hdr_multiplier(pipe_ctx); 1624 1625 if (pipe_ctx->update_flags.bits.enable || 1626 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change || 1627 pipe_ctx->plane_state->update_flags.bits.gamma_change) 1628 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state); 1629 1630 /* dcn10_translate_regamma_to_hw_format takes 750us to finish 1631 * only do gamma programming for powering on, internal memcmp to avoid 1632 * updating on slave planes 1633 */ 1634 if (pipe_ctx->update_flags.bits.enable || pipe_ctx->stream->update_flags.bits.out_tf) 1635 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream); 1636 1637 /* If the pipe has been enabled or has a different opp, we 1638 * should reprogram the fmt. This deals with cases where 1639 * interation between mpc and odm combine on different streams 1640 * causes a different pipe to be chosen to odm combine with. 1641 */ 1642 if (pipe_ctx->update_flags.bits.enable 1643 || pipe_ctx->update_flags.bits.opp_changed) { 1644 1645 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion( 1646 pipe_ctx->stream_res.opp, 1647 COLOR_SPACE_YCBCR601, 1648 pipe_ctx->stream->timing.display_color_depth, 1649 pipe_ctx->stream->signal); 1650 1651 pipe_ctx->stream_res.opp->funcs->opp_program_fmt( 1652 pipe_ctx->stream_res.opp, 1653 &pipe_ctx->stream->bit_depth_params, 1654 &pipe_ctx->stream->clamping); 1655 } 1656 } 1657 1658 void dcn20_program_front_end_for_ctx( 1659 struct dc *dc, 1660 struct dc_state *context) 1661 { 1662 int i; 1663 struct dce_hwseq *hws = dc->hwseq; 1664 DC_LOGGER_INIT(dc->ctx->logger); 1665 1666 /* Carry over GSL groups in case the context is changing. */ 1667 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1668 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 1669 struct pipe_ctx *old_pipe_ctx = 1670 &dc->current_state->res_ctx.pipe_ctx[i]; 1671 1672 if (pipe_ctx->stream == old_pipe_ctx->stream) 1673 pipe_ctx->stream_res.gsl_group = 1674 old_pipe_ctx->stream_res.gsl_group; 1675 } 1676 1677 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) { 1678 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1679 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 1680 1681 if (!pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe && pipe_ctx->plane_state) { 1682 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips); 1683 /*turn off triple buffer for full update*/ 1684 dc->hwss.program_triplebuffer( 1685 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips); 1686 } 1687 } 1688 } 1689 1690 /* Set pipe update flags and lock pipes */ 1691 for (i = 0; i < dc->res_pool->pipe_count; i++) 1692 dcn20_detect_pipe_changes(&dc->current_state->res_ctx.pipe_ctx[i], 1693 &context->res_ctx.pipe_ctx[i]); 1694 1695 /* OTG blank before disabling all front ends */ 1696 for (i = 0; i < dc->res_pool->pipe_count; i++) 1697 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable 1698 && !context->res_ctx.pipe_ctx[i].top_pipe 1699 && !context->res_ctx.pipe_ctx[i].prev_odm_pipe 1700 && context->res_ctx.pipe_ctx[i].stream) 1701 hws->funcs.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true); 1702 1703 1704 /* Disconnect mpcc */ 1705 for (i = 0; i < dc->res_pool->pipe_count; i++) 1706 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable 1707 || context->res_ctx.pipe_ctx[i].update_flags.bits.opp_changed) { 1708 struct hubbub *hubbub = dc->res_pool->hubbub; 1709 1710 if (hubbub->funcs->program_det_size && context->res_ctx.pipe_ctx[i].update_flags.bits.disable) 1711 hubbub->funcs->program_det_size(hubbub, dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0); 1712 hws->funcs.plane_atomic_disconnect(dc, &dc->current_state->res_ctx.pipe_ctx[i]); 1713 DC_LOG_DC("Reset mpcc for pipe %d\n", dc->current_state->res_ctx.pipe_ctx[i].pipe_idx); 1714 } 1715 1716 /* 1717 * Program all updated pipes, order matters for mpcc setup. Start with 1718 * top pipe and program all pipes that follow in order 1719 */ 1720 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1721 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1722 1723 if (pipe->plane_state && !pipe->top_pipe) { 1724 while (pipe) { 1725 if (hws->funcs.program_pipe) 1726 hws->funcs.program_pipe(dc, pipe, context); 1727 else 1728 dcn20_program_pipe(dc, pipe, context); 1729 1730 pipe = pipe->bottom_pipe; 1731 } 1732 } 1733 /* Program secondary blending tree and writeback pipes */ 1734 pipe = &context->res_ctx.pipe_ctx[i]; 1735 if (!pipe->top_pipe && !pipe->prev_odm_pipe 1736 && pipe->stream && pipe->stream->num_wb_info > 0 1737 && (pipe->update_flags.raw || (pipe->plane_state && pipe->plane_state->update_flags.raw) 1738 || pipe->stream->update_flags.raw) 1739 && hws->funcs.program_all_writeback_pipes_in_tree) 1740 hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context); 1741 } 1742 } 1743 1744 void dcn20_post_unlock_program_front_end( 1745 struct dc *dc, 1746 struct dc_state *context) 1747 { 1748 int i; 1749 const unsigned int TIMEOUT_FOR_PIPE_ENABLE_MS = 100; 1750 struct dce_hwseq *hwseq = dc->hwseq; 1751 1752 DC_LOGGER_INIT(dc->ctx->logger); 1753 1754 for (i = 0; i < dc->res_pool->pipe_count; i++) 1755 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable) 1756 dc->hwss.disable_plane(dc, &dc->current_state->res_ctx.pipe_ctx[i]); 1757 1758 /* 1759 * If we are enabling a pipe, we need to wait for pending clear as this is a critical 1760 * part of the enable operation otherwise, DM may request an immediate flip which 1761 * will cause HW to perform an "immediate enable" (as opposed to "vsync enable") which 1762 * is unsupported on DCN. 1763 */ 1764 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1765 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1766 1767 if (pipe->plane_state && !pipe->top_pipe && pipe->update_flags.bits.enable) { 1768 struct hubp *hubp = pipe->plane_res.hubp; 1769 int j = 0; 1770 1771 for (j = 0; j < TIMEOUT_FOR_PIPE_ENABLE_MS*1000 1772 && hubp->funcs->hubp_is_flip_pending(hubp); j++) 1773 mdelay(1); 1774 } 1775 } 1776 1777 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1778 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1779 struct pipe_ctx *mpcc_pipe; 1780 1781 if (pipe->vtp_locked) { 1782 dc->hwseq->funcs.wait_for_blank_complete(pipe->stream_res.opp); 1783 pipe->plane_res.hubp->funcs->set_blank(pipe->plane_res.hubp, true); 1784 pipe->vtp_locked = false; 1785 1786 for (mpcc_pipe = pipe->bottom_pipe; mpcc_pipe; mpcc_pipe = mpcc_pipe->bottom_pipe) 1787 mpcc_pipe->plane_res.hubp->funcs->set_blank(mpcc_pipe->plane_res.hubp, true); 1788 1789 for (i = 0; i < dc->res_pool->pipe_count; i++) 1790 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable) 1791 dc->hwss.disable_plane(dc, &dc->current_state->res_ctx.pipe_ctx[i]); 1792 } 1793 } 1794 /* WA to apply WM setting*/ 1795 if (hwseq->wa.DEGVIDCN21) 1796 dc->res_pool->hubbub->funcs->apply_DEDCN21_147_wa(dc->res_pool->hubbub); 1797 1798 1799 /* WA for stutter underflow during MPO transitions when adding 2nd plane */ 1800 if (hwseq->wa.disallow_self_refresh_during_multi_plane_transition) { 1801 1802 if (dc->current_state->stream_status[0].plane_count == 1 && 1803 context->stream_status[0].plane_count > 1) { 1804 1805 struct timing_generator *tg = dc->res_pool->timing_generators[0]; 1806 1807 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub, false); 1808 1809 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied = true; 1810 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied_on_frame = tg->funcs->get_frame_count(tg); 1811 } 1812 } 1813 } 1814 1815 void dcn20_prepare_bandwidth( 1816 struct dc *dc, 1817 struct dc_state *context) 1818 { 1819 struct hubbub *hubbub = dc->res_pool->hubbub; 1820 1821 dc->clk_mgr->funcs->update_clocks( 1822 dc->clk_mgr, 1823 context, 1824 false); 1825 1826 /* program dchubbub watermarks */ 1827 dc->wm_optimized_required = hubbub->funcs->program_watermarks(hubbub, 1828 &context->bw_ctx.bw.dcn.watermarks, 1829 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000, 1830 false); 1831 /* decrease compbuf size */ 1832 if (hubbub->funcs->program_compbuf_size) 1833 hubbub->funcs->program_compbuf_size(hubbub, context->bw_ctx.bw.dcn.compbuf_size_kb, false); 1834 } 1835 1836 void dcn20_optimize_bandwidth( 1837 struct dc *dc, 1838 struct dc_state *context) 1839 { 1840 struct hubbub *hubbub = dc->res_pool->hubbub; 1841 1842 /* program dchubbub watermarks */ 1843 hubbub->funcs->program_watermarks(hubbub, 1844 &context->bw_ctx.bw.dcn.watermarks, 1845 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000, 1846 true); 1847 1848 if (dc->clk_mgr->dc_mode_softmax_enabled) 1849 if (dc->clk_mgr->clks.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 && 1850 context->bw_ctx.bw.dcn.clk.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000) 1851 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->dc_mode_softmax_memclk); 1852 1853 dc->clk_mgr->funcs->update_clocks( 1854 dc->clk_mgr, 1855 context, 1856 true); 1857 /* increase compbuf size */ 1858 if (hubbub->funcs->program_compbuf_size) 1859 hubbub->funcs->program_compbuf_size(hubbub, context->bw_ctx.bw.dcn.compbuf_size_kb, true); 1860 } 1861 1862 bool dcn20_update_bandwidth( 1863 struct dc *dc, 1864 struct dc_state *context) 1865 { 1866 int i; 1867 struct dce_hwseq *hws = dc->hwseq; 1868 1869 /* recalculate DML parameters */ 1870 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) 1871 return false; 1872 1873 /* apply updated bandwidth parameters */ 1874 dc->hwss.prepare_bandwidth(dc, context); 1875 1876 /* update hubp configs for all pipes */ 1877 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1878 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 1879 1880 if (pipe_ctx->plane_state == NULL) 1881 continue; 1882 1883 if (pipe_ctx->top_pipe == NULL) { 1884 bool blank = !is_pipe_tree_visible(pipe_ctx); 1885 1886 pipe_ctx->stream_res.tg->funcs->program_global_sync( 1887 pipe_ctx->stream_res.tg, 1888 pipe_ctx->pipe_dlg_param.vready_offset, 1889 pipe_ctx->pipe_dlg_param.vstartup_start, 1890 pipe_ctx->pipe_dlg_param.vupdate_offset, 1891 pipe_ctx->pipe_dlg_param.vupdate_width); 1892 1893 pipe_ctx->stream_res.tg->funcs->set_vtg_params( 1894 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, false); 1895 1896 if (pipe_ctx->prev_odm_pipe == NULL) 1897 hws->funcs.blank_pixel_data(dc, pipe_ctx, blank); 1898 1899 if (hws->funcs.setup_vupdate_interrupt) 1900 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx); 1901 } 1902 1903 pipe_ctx->plane_res.hubp->funcs->hubp_setup( 1904 pipe_ctx->plane_res.hubp, 1905 &pipe_ctx->dlg_regs, 1906 &pipe_ctx->ttu_regs, 1907 &pipe_ctx->rq_regs, 1908 &pipe_ctx->pipe_dlg_param); 1909 } 1910 1911 return true; 1912 } 1913 1914 void dcn20_enable_writeback( 1915 struct dc *dc, 1916 struct dc_writeback_info *wb_info, 1917 struct dc_state *context) 1918 { 1919 struct dwbc *dwb; 1920 struct mcif_wb *mcif_wb; 1921 struct timing_generator *optc; 1922 1923 ASSERT(wb_info->dwb_pipe_inst < MAX_DWB_PIPES); 1924 ASSERT(wb_info->wb_enabled); 1925 dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst]; 1926 mcif_wb = dc->res_pool->mcif_wb[wb_info->dwb_pipe_inst]; 1927 1928 /* set the OPTC source mux */ 1929 optc = dc->res_pool->timing_generators[dwb->otg_inst]; 1930 optc->funcs->set_dwb_source(optc, wb_info->dwb_pipe_inst); 1931 /* set MCIF_WB buffer and arbitration configuration */ 1932 mcif_wb->funcs->config_mcif_buf(mcif_wb, &wb_info->mcif_buf_params, wb_info->dwb_params.dest_height); 1933 mcif_wb->funcs->config_mcif_arb(mcif_wb, &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[wb_info->dwb_pipe_inst]); 1934 /* Enable MCIF_WB */ 1935 mcif_wb->funcs->enable_mcif(mcif_wb); 1936 /* Enable DWB */ 1937 dwb->funcs->enable(dwb, &wb_info->dwb_params); 1938 /* TODO: add sequence to enable/disable warmup */ 1939 } 1940 1941 void dcn20_disable_writeback( 1942 struct dc *dc, 1943 unsigned int dwb_pipe_inst) 1944 { 1945 struct dwbc *dwb; 1946 struct mcif_wb *mcif_wb; 1947 1948 ASSERT(dwb_pipe_inst < MAX_DWB_PIPES); 1949 dwb = dc->res_pool->dwbc[dwb_pipe_inst]; 1950 mcif_wb = dc->res_pool->mcif_wb[dwb_pipe_inst]; 1951 1952 dwb->funcs->disable(dwb); 1953 mcif_wb->funcs->disable_mcif(mcif_wb); 1954 } 1955 1956 bool dcn20_wait_for_blank_complete( 1957 struct output_pixel_processor *opp) 1958 { 1959 int counter; 1960 1961 for (counter = 0; counter < 1000; counter++) { 1962 if (opp->funcs->dpg_is_blanked(opp)) 1963 break; 1964 1965 udelay(100); 1966 } 1967 1968 if (counter == 1000) { 1969 dm_error("DC: failed to blank crtc!\n"); 1970 return false; 1971 } 1972 1973 return true; 1974 } 1975 1976 bool dcn20_dmdata_status_done(struct pipe_ctx *pipe_ctx) 1977 { 1978 struct hubp *hubp = pipe_ctx->plane_res.hubp; 1979 1980 if (!hubp) 1981 return false; 1982 return hubp->funcs->dmdata_status_done(hubp); 1983 } 1984 1985 void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx) 1986 { 1987 struct dce_hwseq *hws = dc->hwseq; 1988 1989 if (pipe_ctx->stream_res.dsc) { 1990 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe; 1991 1992 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, true); 1993 while (odm_pipe) { 1994 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, true); 1995 odm_pipe = odm_pipe->next_odm_pipe; 1996 } 1997 } 1998 } 1999 2000 void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx) 2001 { 2002 struct dce_hwseq *hws = dc->hwseq; 2003 2004 if (pipe_ctx->stream_res.dsc) { 2005 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe; 2006 2007 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, false); 2008 while (odm_pipe) { 2009 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, false); 2010 odm_pipe = odm_pipe->next_odm_pipe; 2011 } 2012 } 2013 } 2014 2015 void dcn20_set_dmdata_attributes(struct pipe_ctx *pipe_ctx) 2016 { 2017 struct dc_dmdata_attributes attr = { 0 }; 2018 struct hubp *hubp = pipe_ctx->plane_res.hubp; 2019 2020 attr.dmdata_mode = DMDATA_HW_MODE; 2021 attr.dmdata_size = 2022 dc_is_hdmi_signal(pipe_ctx->stream->signal) ? 32 : 36; 2023 attr.address.quad_part = 2024 pipe_ctx->stream->dmdata_address.quad_part; 2025 attr.dmdata_dl_delta = 0; 2026 attr.dmdata_qos_mode = 0; 2027 attr.dmdata_qos_level = 0; 2028 attr.dmdata_repeat = 1; /* always repeat */ 2029 attr.dmdata_updated = 1; 2030 attr.dmdata_sw_data = NULL; 2031 2032 hubp->funcs->dmdata_set_attributes(hubp, &attr); 2033 } 2034 2035 void dcn20_init_vm_ctx( 2036 struct dce_hwseq *hws, 2037 struct dc *dc, 2038 struct dc_virtual_addr_space_config *va_config, 2039 int vmid) 2040 { 2041 struct dcn_hubbub_virt_addr_config config; 2042 2043 if (vmid == 0) { 2044 ASSERT(0); /* VMID cannot be 0 for vm context */ 2045 return; 2046 } 2047 2048 config.page_table_start_addr = va_config->page_table_start_addr; 2049 config.page_table_end_addr = va_config->page_table_end_addr; 2050 config.page_table_block_size = va_config->page_table_block_size_in_bytes; 2051 config.page_table_depth = va_config->page_table_depth; 2052 config.page_table_base_addr = va_config->page_table_base_addr; 2053 2054 dc->res_pool->hubbub->funcs->init_vm_ctx(dc->res_pool->hubbub, &config, vmid); 2055 } 2056 2057 int dcn20_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config) 2058 { 2059 struct dcn_hubbub_phys_addr_config config; 2060 2061 config.system_aperture.fb_top = pa_config->system_aperture.fb_top; 2062 config.system_aperture.fb_offset = pa_config->system_aperture.fb_offset; 2063 config.system_aperture.fb_base = pa_config->system_aperture.fb_base; 2064 config.system_aperture.agp_top = pa_config->system_aperture.agp_top; 2065 config.system_aperture.agp_bot = pa_config->system_aperture.agp_bot; 2066 config.system_aperture.agp_base = pa_config->system_aperture.agp_base; 2067 config.gart_config.page_table_start_addr = pa_config->gart_config.page_table_start_addr; 2068 config.gart_config.page_table_end_addr = pa_config->gart_config.page_table_end_addr; 2069 config.gart_config.page_table_base_addr = pa_config->gart_config.page_table_base_addr; 2070 config.page_table_default_page_addr = pa_config->page_table_default_page_addr; 2071 2072 return dc->res_pool->hubbub->funcs->init_dchub_sys_ctx(dc->res_pool->hubbub, &config); 2073 } 2074 2075 static bool patch_address_for_sbs_tb_stereo( 2076 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr) 2077 { 2078 struct dc_plane_state *plane_state = pipe_ctx->plane_state; 2079 bool sec_split = pipe_ctx->top_pipe && 2080 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state; 2081 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO && 2082 (pipe_ctx->stream->timing.timing_3d_format == 2083 TIMING_3D_FORMAT_SIDE_BY_SIDE || 2084 pipe_ctx->stream->timing.timing_3d_format == 2085 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) { 2086 *addr = plane_state->address.grph_stereo.left_addr; 2087 plane_state->address.grph_stereo.left_addr = 2088 plane_state->address.grph_stereo.right_addr; 2089 return true; 2090 } 2091 2092 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE && 2093 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) { 2094 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO; 2095 plane_state->address.grph_stereo.right_addr = 2096 plane_state->address.grph_stereo.left_addr; 2097 plane_state->address.grph_stereo.right_meta_addr = 2098 plane_state->address.grph_stereo.left_meta_addr; 2099 } 2100 return false; 2101 } 2102 2103 void dcn20_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx) 2104 { 2105 bool addr_patched = false; 2106 PHYSICAL_ADDRESS_LOC addr; 2107 struct dc_plane_state *plane_state = pipe_ctx->plane_state; 2108 2109 if (plane_state == NULL) 2110 return; 2111 2112 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr); 2113 2114 // Call Helper to track VMID use 2115 vm_helper_mark_vmid_used(dc->vm_helper, plane_state->address.vmid, pipe_ctx->plane_res.hubp->inst); 2116 2117 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr( 2118 pipe_ctx->plane_res.hubp, 2119 &plane_state->address, 2120 plane_state->flip_immediate); 2121 2122 plane_state->status.requested_address = plane_state->address; 2123 2124 if (plane_state->flip_immediate) 2125 plane_state->status.current_address = plane_state->address; 2126 2127 if (addr_patched) 2128 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr; 2129 } 2130 2131 void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx, 2132 struct dc_link_settings *link_settings) 2133 { 2134 struct encoder_unblank_param params = {0}; 2135 struct dc_stream_state *stream = pipe_ctx->stream; 2136 struct dc_link *link = stream->link; 2137 struct dce_hwseq *hws = link->dc->hwseq; 2138 struct pipe_ctx *odm_pipe; 2139 2140 params.opp_cnt = 1; 2141 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) { 2142 params.opp_cnt++; 2143 } 2144 /* only 3 items below are used by unblank */ 2145 params.timing = pipe_ctx->stream->timing; 2146 2147 params.link_settings.link_rate = link_settings->link_rate; 2148 2149 if (is_dp_128b_132b_signal(pipe_ctx)) { 2150 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */ 2151 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_unblank( 2152 pipe_ctx->stream_res.hpo_dp_stream_enc, 2153 pipe_ctx->stream_res.tg->inst); 2154 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) { 2155 if (optc2_is_two_pixels_per_containter(&stream->timing) || params.opp_cnt > 1) 2156 params.timing.pix_clk_100hz /= 2; 2157 pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine( 2158 pipe_ctx->stream_res.stream_enc, params.opp_cnt > 1); 2159 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms); 2160 } 2161 2162 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) { 2163 hws->funcs.edp_backlight_control(link, true); 2164 } 2165 } 2166 2167 void dcn20_setup_vupdate_interrupt(struct dc *dc, struct pipe_ctx *pipe_ctx) 2168 { 2169 struct timing_generator *tg = pipe_ctx->stream_res.tg; 2170 int start_line = dc->hwss.get_vupdate_offset_from_vsync(pipe_ctx); 2171 2172 if (start_line < 0) 2173 start_line = 0; 2174 2175 if (tg->funcs->setup_vertical_interrupt2) 2176 tg->funcs->setup_vertical_interrupt2(tg, start_line); 2177 } 2178 2179 static void dcn20_reset_back_end_for_pipe( 2180 struct dc *dc, 2181 struct pipe_ctx *pipe_ctx, 2182 struct dc_state *context) 2183 { 2184 int i; 2185 struct dc_link *link; 2186 DC_LOGGER_INIT(dc->ctx->logger); 2187 if (pipe_ctx->stream_res.stream_enc == NULL) { 2188 pipe_ctx->stream = NULL; 2189 return; 2190 } 2191 2192 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) { 2193 link = pipe_ctx->stream->link; 2194 /* DPMS may already disable or */ 2195 /* dpms_off status is incorrect due to fastboot 2196 * feature. When system resume from S4 with second 2197 * screen only, the dpms_off would be true but 2198 * VBIOS lit up eDP, so check link status too. 2199 */ 2200 if (!pipe_ctx->stream->dpms_off || link->link_status.link_active) 2201 core_link_disable_stream(pipe_ctx); 2202 else if (pipe_ctx->stream_res.audio) 2203 dc->hwss.disable_audio_stream(pipe_ctx); 2204 2205 /* free acquired resources */ 2206 if (pipe_ctx->stream_res.audio) { 2207 /*disable az_endpoint*/ 2208 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio); 2209 2210 /*free audio*/ 2211 if (dc->caps.dynamic_audio == true) { 2212 /*we have to dynamic arbitrate the audio endpoints*/ 2213 /*we free the resource, need reset is_audio_acquired*/ 2214 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool, 2215 pipe_ctx->stream_res.audio, false); 2216 pipe_ctx->stream_res.audio = NULL; 2217 } 2218 } 2219 } 2220 else if (pipe_ctx->stream_res.dsc) { 2221 dp_set_dsc_enable(pipe_ctx, false); 2222 } 2223 2224 /* by upper caller loop, parent pipe: pipe0, will be reset last. 2225 * back end share by all pipes and will be disable only when disable 2226 * parent pipe. 2227 */ 2228 if (pipe_ctx->top_pipe == NULL) { 2229 2230 dc->hwss.set_abm_immediate_disable(pipe_ctx); 2231 2232 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg); 2233 2234 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false); 2235 if (pipe_ctx->stream_res.tg->funcs->set_odm_bypass) 2236 pipe_ctx->stream_res.tg->funcs->set_odm_bypass( 2237 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing); 2238 2239 if (pipe_ctx->stream_res.tg->funcs->set_drr) 2240 pipe_ctx->stream_res.tg->funcs->set_drr( 2241 pipe_ctx->stream_res.tg, NULL); 2242 } 2243 2244 for (i = 0; i < dc->res_pool->pipe_count; i++) 2245 if (&dc->current_state->res_ctx.pipe_ctx[i] == pipe_ctx) 2246 break; 2247 2248 if (i == dc->res_pool->pipe_count) 2249 return; 2250 2251 pipe_ctx->stream = NULL; 2252 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n", 2253 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst); 2254 } 2255 2256 void dcn20_reset_hw_ctx_wrap( 2257 struct dc *dc, 2258 struct dc_state *context) 2259 { 2260 int i; 2261 struct dce_hwseq *hws = dc->hwseq; 2262 2263 /* Reset Back End*/ 2264 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) { 2265 struct pipe_ctx *pipe_ctx_old = 2266 &dc->current_state->res_ctx.pipe_ctx[i]; 2267 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 2268 2269 if (!pipe_ctx_old->stream) 2270 continue; 2271 2272 if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe) 2273 continue; 2274 2275 if (!pipe_ctx->stream || 2276 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) { 2277 struct clock_source *old_clk = pipe_ctx_old->clock_source; 2278 2279 dcn20_reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state); 2280 if (hws->funcs.enable_stream_gating) 2281 hws->funcs.enable_stream_gating(dc, pipe_ctx_old); 2282 if (old_clk) 2283 old_clk->funcs->cs_power_down(old_clk); 2284 } 2285 } 2286 } 2287 2288 void dcn20_update_visual_confirm_color(struct dc *dc, struct pipe_ctx *pipe_ctx, struct tg_color *color, int mpcc_id) 2289 { 2290 struct mpc *mpc = dc->res_pool->mpc; 2291 2292 // input to MPCC is always RGB, by default leave black_color at 0 2293 if (dc->debug.visual_confirm == VISUAL_CONFIRM_HDR) 2294 get_hdr_visual_confirm_color(pipe_ctx, color); 2295 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE) 2296 get_surface_visual_confirm_color(pipe_ctx, color); 2297 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_MPCTREE) 2298 get_mpctree_visual_confirm_color(pipe_ctx, color); 2299 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SWIZZLE) 2300 get_surface_tile_visual_confirm_color(pipe_ctx, color); 2301 2302 if (mpc->funcs->set_bg_color) 2303 mpc->funcs->set_bg_color(mpc, color, mpcc_id); 2304 } 2305 2306 void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx) 2307 { 2308 struct hubp *hubp = pipe_ctx->plane_res.hubp; 2309 struct mpcc_blnd_cfg blnd_cfg = {0}; 2310 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha; 2311 int mpcc_id; 2312 struct mpcc *new_mpcc; 2313 struct mpc *mpc = dc->res_pool->mpc; 2314 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params); 2315 2316 if (per_pixel_alpha) 2317 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA; 2318 else 2319 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA; 2320 2321 blnd_cfg.overlap_only = false; 2322 blnd_cfg.global_gain = 0xff; 2323 2324 if (pipe_ctx->plane_state->global_alpha) 2325 blnd_cfg.global_alpha = pipe_ctx->plane_state->global_alpha_value; 2326 else 2327 blnd_cfg.global_alpha = 0xff; 2328 2329 blnd_cfg.background_color_bpc = 4; 2330 blnd_cfg.bottom_gain_mode = 0; 2331 blnd_cfg.top_gain = 0x1f000; 2332 blnd_cfg.bottom_inside_gain = 0x1f000; 2333 blnd_cfg.bottom_outside_gain = 0x1f000; 2334 blnd_cfg.pre_multiplied_alpha = per_pixel_alpha; 2335 if (pipe_ctx->plane_state->format 2336 == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA) 2337 blnd_cfg.pre_multiplied_alpha = false; 2338 2339 /* 2340 * TODO: remove hack 2341 * Note: currently there is a bug in init_hw such that 2342 * on resume from hibernate, BIOS sets up MPCC0, and 2343 * we do mpcc_remove but the mpcc cannot go to idle 2344 * after remove. This cause us to pick mpcc1 here, 2345 * which causes a pstate hang for yet unknown reason. 2346 */ 2347 mpcc_id = hubp->inst; 2348 2349 /* If there is no full update, don't need to touch MPC tree*/ 2350 if (!pipe_ctx->plane_state->update_flags.bits.full_update && 2351 !pipe_ctx->update_flags.bits.mpcc) { 2352 mpc->funcs->update_blending(mpc, &blnd_cfg, mpcc_id); 2353 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, &blnd_cfg.black_color, mpcc_id); 2354 return; 2355 } 2356 2357 /* check if this MPCC is already being used */ 2358 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id); 2359 /* remove MPCC if being used */ 2360 if (new_mpcc != NULL) 2361 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc); 2362 else 2363 if (dc->debug.sanity_checks) 2364 mpc->funcs->assert_mpcc_idle_before_connect( 2365 dc->res_pool->mpc, mpcc_id); 2366 2367 /* Call MPC to insert new plane */ 2368 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc, 2369 mpc_tree_params, 2370 &blnd_cfg, 2371 NULL, 2372 NULL, 2373 hubp->inst, 2374 mpcc_id); 2375 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, &blnd_cfg.black_color, mpcc_id); 2376 2377 ASSERT(new_mpcc != NULL); 2378 hubp->opp_id = pipe_ctx->stream_res.opp->inst; 2379 hubp->mpcc_id = mpcc_id; 2380 } 2381 2382 void dcn20_enable_stream(struct pipe_ctx *pipe_ctx) 2383 { 2384 enum dc_lane_count lane_count = 2385 pipe_ctx->stream->link->cur_link_settings.lane_count; 2386 2387 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing; 2388 struct dc_link *link = pipe_ctx->stream->link; 2389 2390 uint32_t active_total_with_borders; 2391 uint32_t early_control = 0; 2392 struct timing_generator *tg = pipe_ctx->stream_res.tg; 2393 struct link_encoder *link_enc; 2394 2395 if (link->is_dig_mapping_flexible && 2396 link->dc->res_pool->funcs->link_encs_assign) 2397 link_enc = link_enc_cfg_get_link_enc_used_by_stream(link->ctx->dc, pipe_ctx->stream); 2398 else 2399 link_enc = link->link_enc; 2400 ASSERT(link_enc); 2401 2402 /* For MST, there are multiply stream go to only one link. 2403 * connect DIG back_end to front_end while enable_stream and 2404 * disconnect them during disable_stream 2405 * BY this, it is logic clean to separate stream and link 2406 */ 2407 if (is_dp_128b_132b_signal(pipe_ctx)) { 2408 if (pipe_ctx->stream->ctx->dc->hwseq->funcs.setup_hpo_hw_control) 2409 pipe_ctx->stream->ctx->dc->hwseq->funcs.setup_hpo_hw_control( 2410 pipe_ctx->stream->ctx->dc->hwseq, true); 2411 setup_dp_hpo_stream(pipe_ctx, true); 2412 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->enable_stream( 2413 pipe_ctx->stream_res.hpo_dp_stream_enc); 2414 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->map_stream_to_link( 2415 pipe_ctx->stream_res.hpo_dp_stream_enc, 2416 pipe_ctx->stream_res.hpo_dp_stream_enc->inst, 2417 pipe_ctx->link_res.hpo_dp_link_enc->inst); 2418 } 2419 2420 if (!is_dp_128b_132b_signal(pipe_ctx) && link_enc) 2421 link_enc->funcs->connect_dig_be_to_fe( 2422 link_enc, pipe_ctx->stream_res.stream_enc->id, true); 2423 2424 if (dc_is_dp_signal(pipe_ctx->stream->signal)) 2425 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_BE); 2426 2427 if (pipe_ctx->plane_state && pipe_ctx->plane_state->flip_immediate != 1) { 2428 if (link->dc->hwss.program_dmdata_engine) 2429 link->dc->hwss.program_dmdata_engine(pipe_ctx); 2430 } 2431 2432 link->dc->hwss.update_info_frame(pipe_ctx); 2433 2434 if (dc_is_dp_signal(pipe_ctx->stream->signal)) 2435 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME); 2436 2437 /* enable early control to avoid corruption on DP monitor*/ 2438 active_total_with_borders = 2439 timing->h_addressable 2440 + timing->h_border_left 2441 + timing->h_border_right; 2442 2443 if (lane_count != 0) 2444 early_control = active_total_with_borders % lane_count; 2445 2446 if (early_control == 0) 2447 early_control = lane_count; 2448 2449 tg->funcs->set_early_control(tg, early_control); 2450 2451 /* enable audio only within mode set */ 2452 if (pipe_ctx->stream_res.audio != NULL) { 2453 if (is_dp_128b_132b_signal(pipe_ctx)) 2454 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.hpo_dp_stream_enc); 2455 else if (dc_is_dp_signal(pipe_ctx->stream->signal)) 2456 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc); 2457 } 2458 } 2459 2460 void dcn20_program_dmdata_engine(struct pipe_ctx *pipe_ctx) 2461 { 2462 struct dc_stream_state *stream = pipe_ctx->stream; 2463 struct hubp *hubp = pipe_ctx->plane_res.hubp; 2464 bool enable = false; 2465 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc; 2466 enum dynamic_metadata_mode mode = dc_is_dp_signal(stream->signal) 2467 ? dmdata_dp 2468 : dmdata_hdmi; 2469 2470 /* if using dynamic meta, don't set up generic infopackets */ 2471 if (pipe_ctx->stream->dmdata_address.quad_part != 0) { 2472 pipe_ctx->stream_res.encoder_info_frame.hdrsmd.valid = false; 2473 enable = true; 2474 } 2475 2476 if (!hubp) 2477 return; 2478 2479 if (!stream_enc || !stream_enc->funcs->set_dynamic_metadata) 2480 return; 2481 2482 stream_enc->funcs->set_dynamic_metadata(stream_enc, enable, 2483 hubp->inst, mode); 2484 } 2485 2486 void dcn20_fpga_init_hw(struct dc *dc) 2487 { 2488 int i, j; 2489 struct dce_hwseq *hws = dc->hwseq; 2490 struct resource_pool *res_pool = dc->res_pool; 2491 struct dc_state *context = dc->current_state; 2492 2493 if (dc->clk_mgr && dc->clk_mgr->funcs->init_clocks) 2494 dc->clk_mgr->funcs->init_clocks(dc->clk_mgr); 2495 2496 // Initialize the dccg 2497 if (res_pool->dccg->funcs->dccg_init) 2498 res_pool->dccg->funcs->dccg_init(res_pool->dccg); 2499 2500 //Enable ability to power gate / don't force power on permanently 2501 hws->funcs.enable_power_gating_plane(hws, true); 2502 2503 // Specific to FPGA dccg and registers 2504 REG_WRITE(RBBMIF_TIMEOUT_DIS, 0xFFFFFFFF); 2505 REG_WRITE(RBBMIF_TIMEOUT_DIS_2, 0xFFFFFFFF); 2506 2507 hws->funcs.dccg_init(hws); 2508 2509 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, 2); 2510 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1); 2511 if (REG(REFCLK_CNTL)) 2512 REG_WRITE(REFCLK_CNTL, 0); 2513 // 2514 2515 2516 /* Blank pixel data with OPP DPG */ 2517 for (i = 0; i < dc->res_pool->timing_generator_count; i++) { 2518 struct timing_generator *tg = dc->res_pool->timing_generators[i]; 2519 2520 if (tg->funcs->is_tg_enabled(tg)) 2521 dcn20_init_blank(dc, tg); 2522 } 2523 2524 for (i = 0; i < res_pool->timing_generator_count; i++) { 2525 struct timing_generator *tg = dc->res_pool->timing_generators[i]; 2526 2527 if (tg->funcs->is_tg_enabled(tg)) 2528 tg->funcs->lock(tg); 2529 } 2530 2531 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2532 struct dpp *dpp = res_pool->dpps[i]; 2533 2534 dpp->funcs->dpp_reset(dpp); 2535 } 2536 2537 /* Reset all MPCC muxes */ 2538 res_pool->mpc->funcs->mpc_init(res_pool->mpc); 2539 2540 /* initialize OPP mpc_tree parameter */ 2541 for (i = 0; i < dc->res_pool->res_cap->num_opp; i++) { 2542 res_pool->opps[i]->mpc_tree_params.opp_id = res_pool->opps[i]->inst; 2543 res_pool->opps[i]->mpc_tree_params.opp_list = NULL; 2544 for (j = 0; j < MAX_PIPES; j++) 2545 res_pool->opps[i]->mpcc_disconnect_pending[j] = false; 2546 } 2547 2548 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2549 struct timing_generator *tg = dc->res_pool->timing_generators[i]; 2550 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 2551 struct hubp *hubp = dc->res_pool->hubps[i]; 2552 struct dpp *dpp = dc->res_pool->dpps[i]; 2553 2554 pipe_ctx->stream_res.tg = tg; 2555 pipe_ctx->pipe_idx = i; 2556 2557 pipe_ctx->plane_res.hubp = hubp; 2558 pipe_ctx->plane_res.dpp = dpp; 2559 pipe_ctx->plane_res.mpcc_inst = dpp->inst; 2560 hubp->mpcc_id = dpp->inst; 2561 hubp->opp_id = OPP_ID_INVALID; 2562 hubp->power_gated = false; 2563 pipe_ctx->stream_res.opp = NULL; 2564 2565 hubp->funcs->hubp_init(hubp); 2566 2567 //dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst; 2568 //dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL; 2569 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true; 2570 pipe_ctx->stream_res.opp = dc->res_pool->opps[i]; 2571 /*to do*/ 2572 hws->funcs.plane_atomic_disconnect(dc, pipe_ctx); 2573 } 2574 2575 /* initialize DWB pointer to MCIF_WB */ 2576 for (i = 0; i < res_pool->res_cap->num_dwb; i++) 2577 res_pool->dwbc[i]->mcif = res_pool->mcif_wb[i]; 2578 2579 for (i = 0; i < dc->res_pool->timing_generator_count; i++) { 2580 struct timing_generator *tg = dc->res_pool->timing_generators[i]; 2581 2582 if (tg->funcs->is_tg_enabled(tg)) 2583 tg->funcs->unlock(tg); 2584 } 2585 2586 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2587 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 2588 2589 dc->hwss.disable_plane(dc, pipe_ctx); 2590 2591 pipe_ctx->stream_res.tg = NULL; 2592 pipe_ctx->plane_res.hubp = NULL; 2593 } 2594 2595 for (i = 0; i < dc->res_pool->timing_generator_count; i++) { 2596 struct timing_generator *tg = dc->res_pool->timing_generators[i]; 2597 2598 tg->funcs->tg_init(tg); 2599 } 2600 2601 if (dc->res_pool->hubbub->funcs->init_crb) 2602 dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub); 2603 } 2604 #ifndef TRIM_FSFT 2605 bool dcn20_optimize_timing_for_fsft(struct dc *dc, 2606 struct dc_crtc_timing *timing, 2607 unsigned int max_input_rate_in_khz) 2608 { 2609 unsigned int old_v_front_porch; 2610 unsigned int old_v_total; 2611 unsigned int max_input_rate_in_100hz; 2612 unsigned long long new_v_total; 2613 2614 max_input_rate_in_100hz = max_input_rate_in_khz * 10; 2615 if (max_input_rate_in_100hz < timing->pix_clk_100hz) 2616 return false; 2617 2618 old_v_total = timing->v_total; 2619 old_v_front_porch = timing->v_front_porch; 2620 2621 timing->fast_transport_output_rate_100hz = timing->pix_clk_100hz; 2622 timing->pix_clk_100hz = max_input_rate_in_100hz; 2623 2624 new_v_total = div_u64((unsigned long long)old_v_total * max_input_rate_in_100hz, timing->pix_clk_100hz); 2625 2626 timing->v_total = new_v_total; 2627 timing->v_front_porch = old_v_front_porch + (timing->v_total - old_v_total); 2628 return true; 2629 } 2630 #endif 2631 2632 void dcn20_set_disp_pattern_generator(const struct dc *dc, 2633 struct pipe_ctx *pipe_ctx, 2634 enum controller_dp_test_pattern test_pattern, 2635 enum controller_dp_color_space color_space, 2636 enum dc_color_depth color_depth, 2637 const struct tg_color *solid_color, 2638 int width, int height, int offset) 2639 { 2640 pipe_ctx->stream_res.opp->funcs->opp_set_disp_pattern_generator(pipe_ctx->stream_res.opp, test_pattern, 2641 color_space, color_depth, solid_color, width, height, offset); 2642 } 2643