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/dcn20_resource.h"
33 #include "dcn20_hwseq.h"
34 #include "dce/dce_hwseq.h"
35 #include "dcn20/dcn20_dsc.h"
36 #include "dcn20/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 "vm_helper.h"
50 #include "dccg.h"
51 #include "dc_dmub_srv.h"
52 #include "dce/dmub_hw_lock_mgr.h"
53 #include "hw_sequencer.h"
54 #include "dpcd_defs.h"
55 #include "inc/link_enc_cfg.h"
56 #include "link_hwss.h"
57 #include "link.h"
58 #include "dc_state_priv.h"
59
60 #define DC_LOGGER \
61 dc_logger
62 #define DC_LOGGER_INIT(logger) \
63 struct dal_logger *dc_logger = logger
64
65 #define CTX \
66 hws->ctx
67 #define REG(reg)\
68 hws->regs->reg
69
70 #undef FN
71 #define FN(reg_name, field_name) \
72 hws->shifts->field_name, hws->masks->field_name
73
dcn20_log_color_state(struct dc * dc,struct dc_log_buffer_ctx * log_ctx)74 void dcn20_log_color_state(struct dc *dc,
75 struct dc_log_buffer_ctx *log_ctx)
76 {
77 struct dc_context *dc_ctx = dc->ctx;
78 struct resource_pool *pool = dc->res_pool;
79 bool is_gamut_remap_available = false;
80 int i;
81
82 DTN_INFO("DPP: DGAM mode SHAPER mode 3DLUT mode 3DLUT bit depth"
83 " 3DLUT size RGAM mode GAMUT adjust "
84 "C11 C12 C13 C14 "
85 "C21 C22 C23 C24 "
86 "C31 C32 C33 C34 \n");
87
88 for (i = 0; i < pool->pipe_count; i++) {
89 struct dpp *dpp = pool->dpps[i];
90 struct dcn_dpp_state s = {0};
91
92 dpp->funcs->dpp_read_state(dpp, &s);
93 if (dpp->funcs->dpp_get_gamut_remap) {
94 dpp->funcs->dpp_get_gamut_remap(dpp, &s.gamut_remap);
95 is_gamut_remap_available = true;
96 }
97
98 if (!s.is_enabled)
99 continue;
100
101 DTN_INFO("[%2d]: %8s %11s %10s %15s %10s %9s",
102 dpp->inst,
103 (s.dgam_lut_mode == 0) ? "Bypass" :
104 ((s.dgam_lut_mode == 1) ? "sRGB" :
105 ((s.dgam_lut_mode == 2) ? "Ycc" :
106 ((s.dgam_lut_mode == 3) ? "RAM" :
107 ((s.dgam_lut_mode == 4) ? "RAM" :
108 "Unknown")))),
109 (s.shaper_lut_mode == 1) ? "RAM A" :
110 ((s.shaper_lut_mode == 2) ? "RAM B" :
111 "Bypass"),
112 (s.lut3d_mode == 1) ? "RAM A" :
113 ((s.lut3d_mode == 2) ? "RAM B" :
114 "Bypass"),
115 (s.lut3d_bit_depth <= 0) ? "12-bit" : "10-bit",
116 (s.lut3d_size == 0) ? "17x17x17" : "9x9x9",
117 (s.rgam_lut_mode == 1) ? "RAM A" :
118 ((s.rgam_lut_mode == 1) ? "RAM B" : "Bypass"));
119
120 if (is_gamut_remap_available) {
121 DTN_INFO(" %12s "
122 "%010lld %010lld %010lld %010lld "
123 "%010lld %010lld %010lld %010lld "
124 "%010lld %010lld %010lld %010lld",
125
126 (s.gamut_remap.gamut_adjust_type == 0) ? "Bypass" :
127 ((s.gamut_remap.gamut_adjust_type == 1) ? "HW" :
128 "SW"),
129 s.gamut_remap.temperature_matrix[0].value,
130 s.gamut_remap.temperature_matrix[1].value,
131 s.gamut_remap.temperature_matrix[2].value,
132 s.gamut_remap.temperature_matrix[3].value,
133 s.gamut_remap.temperature_matrix[4].value,
134 s.gamut_remap.temperature_matrix[5].value,
135 s.gamut_remap.temperature_matrix[6].value,
136 s.gamut_remap.temperature_matrix[7].value,
137 s.gamut_remap.temperature_matrix[8].value,
138 s.gamut_remap.temperature_matrix[9].value,
139 s.gamut_remap.temperature_matrix[10].value,
140 s.gamut_remap.temperature_matrix[11].value);
141 }
142
143 DTN_INFO("\n");
144 }
145 DTN_INFO("\n");
146 DTN_INFO("DPP Color Caps: input_lut_shared:%d icsc:%d"
147 " dgam_ram:%d dgam_rom: srgb:%d,bt2020:%d,gamma2_2:%d,pq:%d,hlg:%d"
148 " post_csc:%d gamcor:%d dgam_rom_for_yuv:%d 3d_lut:%d"
149 " blnd_lut:%d oscs:%d\n\n",
150 dc->caps.color.dpp.input_lut_shared,
151 dc->caps.color.dpp.icsc,
152 dc->caps.color.dpp.dgam_ram,
153 dc->caps.color.dpp.dgam_rom_caps.srgb,
154 dc->caps.color.dpp.dgam_rom_caps.bt2020,
155 dc->caps.color.dpp.dgam_rom_caps.gamma2_2,
156 dc->caps.color.dpp.dgam_rom_caps.pq,
157 dc->caps.color.dpp.dgam_rom_caps.hlg,
158 dc->caps.color.dpp.post_csc,
159 dc->caps.color.dpp.gamma_corr,
160 dc->caps.color.dpp.dgam_rom_for_yuv,
161 dc->caps.color.dpp.hw_3d_lut,
162 dc->caps.color.dpp.ogam_ram,
163 dc->caps.color.dpp.ocsc);
164
165 DTN_INFO("MPCC: OPP DPP MPCCBOT MODE ALPHA_MODE PREMULT OVERLAP_ONLY IDLE"
166 " OGAM mode\n");
167
168 for (i = 0; i < pool->mpcc_count; i++) {
169 struct mpcc_state s = {0};
170
171 pool->mpc->funcs->read_mpcc_state(pool->mpc, i, &s);
172 if (s.opp_id != 0xf)
173 DTN_INFO("[%2d]: %2xh %2xh %6xh %4d %10d %7d %12d %4d %9s\n",
174 i, s.opp_id, s.dpp_id, s.bot_mpcc_id,
175 s.mode, s.alpha_mode, s.pre_multiplied_alpha, s.overlap_only,
176 s.idle,
177 (s.rgam_mode == 1) ? "RAM A" :
178 ((s.rgam_mode == 2) ? "RAM B" :
179 "Bypass"));
180 }
181 DTN_INFO("\n");
182 DTN_INFO("MPC Color Caps: gamut_remap:%d, 3dlut:%d, ogam_ram:%d, ocsc:%d\n\n",
183 dc->caps.color.mpc.gamut_remap,
184 dc->caps.color.mpc.num_3dluts,
185 dc->caps.color.mpc.ogam_ram,
186 dc->caps.color.mpc.ocsc);
187 }
188
189
find_free_gsl_group(const struct dc * dc)190 static int find_free_gsl_group(const struct dc *dc)
191 {
192 if (dc->res_pool->gsl_groups.gsl_0 == 0)
193 return 1;
194 if (dc->res_pool->gsl_groups.gsl_1 == 0)
195 return 2;
196 if (dc->res_pool->gsl_groups.gsl_2 == 0)
197 return 3;
198
199 return 0;
200 }
201
202 /* NOTE: This is not a generic setup_gsl function (hence the suffix as_lock)
203 * This is only used to lock pipes in pipe splitting case with immediate flip
204 * Ordinary MPC/OTG locks suppress VUPDATE which doesn't help with immediate,
205 * so we get tearing with freesync since we cannot flip multiple pipes
206 * atomically.
207 * We use GSL for this:
208 * - immediate flip: find first available GSL group if not already assigned
209 * program gsl with that group, set current OTG as master
210 * and always us 0x4 = AND of flip_ready from all pipes
211 * - vsync flip: disable GSL if used
212 *
213 * Groups in stream_res are stored as +1 from HW registers, i.e.
214 * gsl_0 <=> pipe_ctx->stream_res.gsl_group == 1
215 * Using a magic value like -1 would require tracking all inits/resets
216 */
dcn20_setup_gsl_group_as_lock(const struct dc * dc,struct pipe_ctx * pipe_ctx,bool enable)217 void dcn20_setup_gsl_group_as_lock(
218 const struct dc *dc,
219 struct pipe_ctx *pipe_ctx,
220 bool enable)
221 {
222 struct gsl_params gsl;
223 int group_idx;
224
225 memset(&gsl, 0, sizeof(struct gsl_params));
226
227 if (enable) {
228 /* return if group already assigned since GSL was set up
229 * for vsync flip, we would unassign so it can't be "left over"
230 */
231 if (pipe_ctx->stream_res.gsl_group > 0)
232 return;
233
234 group_idx = find_free_gsl_group(dc);
235 ASSERT(group_idx != 0);
236 pipe_ctx->stream_res.gsl_group = group_idx;
237
238 /* set gsl group reg field and mark resource used */
239 switch (group_idx) {
240 case 1:
241 gsl.gsl0_en = 1;
242 dc->res_pool->gsl_groups.gsl_0 = 1;
243 break;
244 case 2:
245 gsl.gsl1_en = 1;
246 dc->res_pool->gsl_groups.gsl_1 = 1;
247 break;
248 case 3:
249 gsl.gsl2_en = 1;
250 dc->res_pool->gsl_groups.gsl_2 = 1;
251 break;
252 default:
253 BREAK_TO_DEBUGGER();
254 return; // invalid case
255 }
256 gsl.gsl_master_en = 1;
257 } else {
258 group_idx = pipe_ctx->stream_res.gsl_group;
259 if (group_idx == 0)
260 return; // if not in use, just return
261
262 pipe_ctx->stream_res.gsl_group = 0;
263
264 /* unset gsl group reg field and mark resource free */
265 switch (group_idx) {
266 case 1:
267 gsl.gsl0_en = 0;
268 dc->res_pool->gsl_groups.gsl_0 = 0;
269 break;
270 case 2:
271 gsl.gsl1_en = 0;
272 dc->res_pool->gsl_groups.gsl_1 = 0;
273 break;
274 case 3:
275 gsl.gsl2_en = 0;
276 dc->res_pool->gsl_groups.gsl_2 = 0;
277 break;
278 default:
279 BREAK_TO_DEBUGGER();
280 return;
281 }
282 gsl.gsl_master_en = 0;
283 }
284
285 /* at this point we want to program whether it's to enable or disable */
286 if (pipe_ctx->stream_res.tg->funcs->set_gsl != NULL) {
287 pipe_ctx->stream_res.tg->funcs->set_gsl(
288 pipe_ctx->stream_res.tg,
289 &gsl);
290 if (pipe_ctx->stream_res.tg->funcs->set_gsl_source_select != NULL)
291 pipe_ctx->stream_res.tg->funcs->set_gsl_source_select(
292 pipe_ctx->stream_res.tg, group_idx, enable ? 4 : 0);
293 } else
294 BREAK_TO_DEBUGGER();
295 }
296
dcn20_set_flip_control_gsl(struct pipe_ctx * pipe_ctx,bool flip_immediate)297 void dcn20_set_flip_control_gsl(
298 struct pipe_ctx *pipe_ctx,
299 bool flip_immediate)
300 {
301 if (pipe_ctx && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl)
302 pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl(
303 pipe_ctx->plane_res.hubp, flip_immediate);
304
305 }
306
dcn20_enable_power_gating_plane(struct dce_hwseq * hws,bool enable)307 void dcn20_enable_power_gating_plane(
308 struct dce_hwseq *hws,
309 bool enable)
310 {
311 bool force_on = true; /* disable power gating */
312 uint32_t org_ip_request_cntl = 0;
313
314 if (enable)
315 force_on = false;
316
317 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
318 if (org_ip_request_cntl == 0)
319 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
320
321 /* DCHUBP0/1/2/3/4/5 */
322 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on);
323 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN2_POWER_FORCEON, force_on);
324 REG_UPDATE(DOMAIN4_PG_CONFIG, DOMAIN4_POWER_FORCEON, force_on);
325 REG_UPDATE(DOMAIN6_PG_CONFIG, DOMAIN6_POWER_FORCEON, force_on);
326 if (REG(DOMAIN8_PG_CONFIG))
327 REG_UPDATE(DOMAIN8_PG_CONFIG, DOMAIN8_POWER_FORCEON, force_on);
328 if (REG(DOMAIN10_PG_CONFIG))
329 REG_UPDATE(DOMAIN10_PG_CONFIG, DOMAIN8_POWER_FORCEON, force_on);
330
331 /* DPP0/1/2/3/4/5 */
332 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN1_POWER_FORCEON, force_on);
333 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN3_POWER_FORCEON, force_on);
334 REG_UPDATE(DOMAIN5_PG_CONFIG, DOMAIN5_POWER_FORCEON, force_on);
335 REG_UPDATE(DOMAIN7_PG_CONFIG, DOMAIN7_POWER_FORCEON, force_on);
336 if (REG(DOMAIN9_PG_CONFIG))
337 REG_UPDATE(DOMAIN9_PG_CONFIG, DOMAIN9_POWER_FORCEON, force_on);
338 if (REG(DOMAIN11_PG_CONFIG))
339 REG_UPDATE(DOMAIN11_PG_CONFIG, DOMAIN9_POWER_FORCEON, force_on);
340
341 /* DCS0/1/2/3/4/5 */
342 REG_UPDATE(DOMAIN16_PG_CONFIG, DOMAIN16_POWER_FORCEON, force_on);
343 REG_UPDATE(DOMAIN17_PG_CONFIG, DOMAIN17_POWER_FORCEON, force_on);
344 REG_UPDATE(DOMAIN18_PG_CONFIG, DOMAIN18_POWER_FORCEON, force_on);
345 if (REG(DOMAIN19_PG_CONFIG))
346 REG_UPDATE(DOMAIN19_PG_CONFIG, DOMAIN19_POWER_FORCEON, force_on);
347 if (REG(DOMAIN20_PG_CONFIG))
348 REG_UPDATE(DOMAIN20_PG_CONFIG, DOMAIN20_POWER_FORCEON, force_on);
349 if (REG(DOMAIN21_PG_CONFIG))
350 REG_UPDATE(DOMAIN21_PG_CONFIG, DOMAIN21_POWER_FORCEON, force_on);
351
352 if (org_ip_request_cntl == 0)
353 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
354
355 }
356
dcn20_dccg_init(struct dce_hwseq * hws)357 void dcn20_dccg_init(struct dce_hwseq *hws)
358 {
359 /*
360 * set MICROSECOND_TIME_BASE_DIV
361 * 100Mhz refclk -> 0x120264
362 * 27Mhz refclk -> 0x12021b
363 * 48Mhz refclk -> 0x120230
364 *
365 */
366 REG_WRITE(MICROSECOND_TIME_BASE_DIV, 0x120264);
367
368 /*
369 * set MILLISECOND_TIME_BASE_DIV
370 * 100Mhz refclk -> 0x1186a0
371 * 27Mhz refclk -> 0x106978
372 * 48Mhz refclk -> 0x10bb80
373 *
374 */
375 REG_WRITE(MILLISECOND_TIME_BASE_DIV, 0x1186a0);
376
377 /* This value is dependent on the hardware pipeline delay so set once per SOC */
378 REG_WRITE(DISPCLK_FREQ_CHANGE_CNTL, 0xe01003c);
379 }
380
dcn20_disable_vga(struct dce_hwseq * hws)381 void dcn20_disable_vga(
382 struct dce_hwseq *hws)
383 {
384 REG_WRITE(D1VGA_CONTROL, 0);
385 REG_WRITE(D2VGA_CONTROL, 0);
386 REG_WRITE(D3VGA_CONTROL, 0);
387 REG_WRITE(D4VGA_CONTROL, 0);
388 REG_WRITE(D5VGA_CONTROL, 0);
389 REG_WRITE(D6VGA_CONTROL, 0);
390 }
391
dcn20_program_triple_buffer(const struct dc * dc,struct pipe_ctx * pipe_ctx,bool enable_triple_buffer)392 void dcn20_program_triple_buffer(
393 const struct dc *dc,
394 struct pipe_ctx *pipe_ctx,
395 bool enable_triple_buffer)
396 {
397 if (pipe_ctx->plane_res.hubp && pipe_ctx->plane_res.hubp->funcs) {
398 pipe_ctx->plane_res.hubp->funcs->hubp_enable_tripleBuffer(
399 pipe_ctx->plane_res.hubp,
400 enable_triple_buffer);
401 }
402 }
403
404 /* Blank pixel data during initialization */
dcn20_init_blank(struct dc * dc,struct timing_generator * tg)405 void dcn20_init_blank(
406 struct dc *dc,
407 struct timing_generator *tg)
408 {
409 struct dce_hwseq *hws = dc->hwseq;
410 enum dc_color_space color_space;
411 struct tg_color black_color = {0};
412 struct output_pixel_processor *opp = NULL;
413 struct output_pixel_processor *bottom_opp = NULL;
414 uint32_t num_opps, opp_id_src0, opp_id_src1;
415 uint32_t otg_active_width = 0, otg_active_height = 0;
416
417 /* program opp dpg blank color */
418 color_space = COLOR_SPACE_SRGB;
419 color_space_to_black_color(dc, color_space, &black_color);
420
421 /* get the OTG active size */
422 tg->funcs->get_otg_active_size(tg,
423 &otg_active_width,
424 &otg_active_height);
425
426 /* get the OPTC source */
427 tg->funcs->get_optc_source(tg, &num_opps, &opp_id_src0, &opp_id_src1);
428
429 if (opp_id_src0 >= dc->res_pool->res_cap->num_opp) {
430 ASSERT(false);
431 return;
432 }
433 opp = dc->res_pool->opps[opp_id_src0];
434
435 /* don't override the blank pattern if already enabled with the correct one. */
436 if (opp->funcs->dpg_is_blanked && opp->funcs->dpg_is_blanked(opp))
437 return;
438
439 if (num_opps == 2) {
440 otg_active_width = otg_active_width / 2;
441
442 if (opp_id_src1 >= dc->res_pool->res_cap->num_opp) {
443 ASSERT(false);
444 return;
445 }
446 bottom_opp = dc->res_pool->opps[opp_id_src1];
447 }
448
449 opp->funcs->opp_set_disp_pattern_generator(
450 opp,
451 CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
452 CONTROLLER_DP_COLOR_SPACE_UDEFINED,
453 COLOR_DEPTH_UNDEFINED,
454 &black_color,
455 otg_active_width,
456 otg_active_height,
457 0);
458
459 if (num_opps == 2) {
460 bottom_opp->funcs->opp_set_disp_pattern_generator(
461 bottom_opp,
462 CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
463 CONTROLLER_DP_COLOR_SPACE_UDEFINED,
464 COLOR_DEPTH_UNDEFINED,
465 &black_color,
466 otg_active_width,
467 otg_active_height,
468 0);
469 }
470
471 hws->funcs.wait_for_blank_complete(opp);
472 }
473
dcn20_dsc_pg_control(struct dce_hwseq * hws,unsigned int dsc_inst,bool power_on)474 void dcn20_dsc_pg_control(
475 struct dce_hwseq *hws,
476 unsigned int dsc_inst,
477 bool power_on)
478 {
479 uint32_t power_gate = power_on ? 0 : 1;
480 uint32_t pwr_status = power_on ? 0 : 2;
481 uint32_t org_ip_request_cntl = 0;
482
483 if (hws->ctx->dc->debug.disable_dsc_power_gate)
484 return;
485
486 if (REG(DOMAIN16_PG_CONFIG) == 0)
487 return;
488
489 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
490 if (org_ip_request_cntl == 0)
491 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
492
493 switch (dsc_inst) {
494 case 0: /* DSC0 */
495 REG_UPDATE(DOMAIN16_PG_CONFIG,
496 DOMAIN16_POWER_GATE, power_gate);
497
498 REG_WAIT(DOMAIN16_PG_STATUS,
499 DOMAIN16_PGFSM_PWR_STATUS, pwr_status,
500 1, 1000);
501 break;
502 case 1: /* DSC1 */
503 REG_UPDATE(DOMAIN17_PG_CONFIG,
504 DOMAIN17_POWER_GATE, power_gate);
505
506 REG_WAIT(DOMAIN17_PG_STATUS,
507 DOMAIN17_PGFSM_PWR_STATUS, pwr_status,
508 1, 1000);
509 break;
510 case 2: /* DSC2 */
511 REG_UPDATE(DOMAIN18_PG_CONFIG,
512 DOMAIN18_POWER_GATE, power_gate);
513
514 REG_WAIT(DOMAIN18_PG_STATUS,
515 DOMAIN18_PGFSM_PWR_STATUS, pwr_status,
516 1, 1000);
517 break;
518 case 3: /* DSC3 */
519 REG_UPDATE(DOMAIN19_PG_CONFIG,
520 DOMAIN19_POWER_GATE, power_gate);
521
522 REG_WAIT(DOMAIN19_PG_STATUS,
523 DOMAIN19_PGFSM_PWR_STATUS, pwr_status,
524 1, 1000);
525 break;
526 case 4: /* DSC4 */
527 REG_UPDATE(DOMAIN20_PG_CONFIG,
528 DOMAIN20_POWER_GATE, power_gate);
529
530 REG_WAIT(DOMAIN20_PG_STATUS,
531 DOMAIN20_PGFSM_PWR_STATUS, pwr_status,
532 1, 1000);
533 break;
534 case 5: /* DSC5 */
535 REG_UPDATE(DOMAIN21_PG_CONFIG,
536 DOMAIN21_POWER_GATE, power_gate);
537
538 REG_WAIT(DOMAIN21_PG_STATUS,
539 DOMAIN21_PGFSM_PWR_STATUS, pwr_status,
540 1, 1000);
541 break;
542 default:
543 BREAK_TO_DEBUGGER();
544 break;
545 }
546
547 if (org_ip_request_cntl == 0)
548 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
549 }
550
dcn20_dpp_pg_control(struct dce_hwseq * hws,unsigned int dpp_inst,bool power_on)551 void dcn20_dpp_pg_control(
552 struct dce_hwseq *hws,
553 unsigned int dpp_inst,
554 bool power_on)
555 {
556 uint32_t power_gate = power_on ? 0 : 1;
557 uint32_t pwr_status = power_on ? 0 : 2;
558
559 if (hws->ctx->dc->debug.disable_dpp_power_gate)
560 return;
561 if (REG(DOMAIN1_PG_CONFIG) == 0)
562 return;
563
564 switch (dpp_inst) {
565 case 0: /* DPP0 */
566 REG_UPDATE(DOMAIN1_PG_CONFIG,
567 DOMAIN1_POWER_GATE, power_gate);
568
569 REG_WAIT(DOMAIN1_PG_STATUS,
570 DOMAIN1_PGFSM_PWR_STATUS, pwr_status,
571 1, 1000);
572 break;
573 case 1: /* DPP1 */
574 REG_UPDATE(DOMAIN3_PG_CONFIG,
575 DOMAIN3_POWER_GATE, power_gate);
576
577 REG_WAIT(DOMAIN3_PG_STATUS,
578 DOMAIN3_PGFSM_PWR_STATUS, pwr_status,
579 1, 1000);
580 break;
581 case 2: /* DPP2 */
582 REG_UPDATE(DOMAIN5_PG_CONFIG,
583 DOMAIN5_POWER_GATE, power_gate);
584
585 REG_WAIT(DOMAIN5_PG_STATUS,
586 DOMAIN5_PGFSM_PWR_STATUS, pwr_status,
587 1, 1000);
588 break;
589 case 3: /* DPP3 */
590 REG_UPDATE(DOMAIN7_PG_CONFIG,
591 DOMAIN7_POWER_GATE, power_gate);
592
593 REG_WAIT(DOMAIN7_PG_STATUS,
594 DOMAIN7_PGFSM_PWR_STATUS, pwr_status,
595 1, 1000);
596 break;
597 case 4: /* DPP4 */
598 REG_UPDATE(DOMAIN9_PG_CONFIG,
599 DOMAIN9_POWER_GATE, power_gate);
600
601 REG_WAIT(DOMAIN9_PG_STATUS,
602 DOMAIN9_PGFSM_PWR_STATUS, pwr_status,
603 1, 1000);
604 break;
605 case 5: /* DPP5 */
606 /*
607 * Do not power gate DPP5, should be left at HW default, power on permanently.
608 * PG on Pipe5 is De-featured, attempting to put it to PG state may result in hard
609 * reset.
610 * REG_UPDATE(DOMAIN11_PG_CONFIG,
611 * DOMAIN11_POWER_GATE, power_gate);
612 *
613 * REG_WAIT(DOMAIN11_PG_STATUS,
614 * DOMAIN11_PGFSM_PWR_STATUS, pwr_status,
615 * 1, 1000);
616 */
617 break;
618 default:
619 BREAK_TO_DEBUGGER();
620 break;
621 }
622 }
623
624
dcn20_hubp_pg_control(struct dce_hwseq * hws,unsigned int hubp_inst,bool power_on)625 void dcn20_hubp_pg_control(
626 struct dce_hwseq *hws,
627 unsigned int hubp_inst,
628 bool power_on)
629 {
630 uint32_t power_gate = power_on ? 0 : 1;
631 uint32_t pwr_status = power_on ? 0 : 2;
632
633 if (hws->ctx->dc->debug.disable_hubp_power_gate)
634 return;
635 if (REG(DOMAIN0_PG_CONFIG) == 0)
636 return;
637
638 switch (hubp_inst) {
639 case 0: /* DCHUBP0 */
640 REG_UPDATE(DOMAIN0_PG_CONFIG,
641 DOMAIN0_POWER_GATE, power_gate);
642
643 REG_WAIT(DOMAIN0_PG_STATUS,
644 DOMAIN0_PGFSM_PWR_STATUS, pwr_status,
645 1, 1000);
646 break;
647 case 1: /* DCHUBP1 */
648 REG_UPDATE(DOMAIN2_PG_CONFIG,
649 DOMAIN2_POWER_GATE, power_gate);
650
651 REG_WAIT(DOMAIN2_PG_STATUS,
652 DOMAIN2_PGFSM_PWR_STATUS, pwr_status,
653 1, 1000);
654 break;
655 case 2: /* DCHUBP2 */
656 REG_UPDATE(DOMAIN4_PG_CONFIG,
657 DOMAIN4_POWER_GATE, power_gate);
658
659 REG_WAIT(DOMAIN4_PG_STATUS,
660 DOMAIN4_PGFSM_PWR_STATUS, pwr_status,
661 1, 1000);
662 break;
663 case 3: /* DCHUBP3 */
664 REG_UPDATE(DOMAIN6_PG_CONFIG,
665 DOMAIN6_POWER_GATE, power_gate);
666
667 REG_WAIT(DOMAIN6_PG_STATUS,
668 DOMAIN6_PGFSM_PWR_STATUS, pwr_status,
669 1, 1000);
670 break;
671 case 4: /* DCHUBP4 */
672 REG_UPDATE(DOMAIN8_PG_CONFIG,
673 DOMAIN8_POWER_GATE, power_gate);
674
675 REG_WAIT(DOMAIN8_PG_STATUS,
676 DOMAIN8_PGFSM_PWR_STATUS, pwr_status,
677 1, 1000);
678 break;
679 case 5: /* DCHUBP5 */
680 /*
681 * Do not power gate DCHUB5, should be left at HW default, power on permanently.
682 * PG on Pipe5 is De-featured, attempting to put it to PG state may result in hard
683 * reset.
684 * REG_UPDATE(DOMAIN10_PG_CONFIG,
685 * DOMAIN10_POWER_GATE, power_gate);
686 *
687 * REG_WAIT(DOMAIN10_PG_STATUS,
688 * DOMAIN10_PGFSM_PWR_STATUS, pwr_status,
689 * 1, 1000);
690 */
691 break;
692 default:
693 BREAK_TO_DEBUGGER();
694 break;
695 }
696 }
697
698
699 /* disable HW used by plane.
700 * note: cannot disable until disconnect is complete
701 */
dcn20_plane_atomic_disable(struct dc * dc,struct pipe_ctx * pipe_ctx)702 void dcn20_plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
703 {
704 struct dce_hwseq *hws = dc->hwseq;
705 struct hubp *hubp = pipe_ctx->plane_res.hubp;
706 struct dpp *dpp = pipe_ctx->plane_res.dpp;
707
708 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe_ctx);
709
710 /* In flip immediate with pipe splitting case GSL is used for
711 * synchronization so we must disable it when the plane is disabled.
712 */
713 if (pipe_ctx->stream_res.gsl_group != 0)
714 dcn20_setup_gsl_group_as_lock(dc, pipe_ctx, false);
715
716 if (hubp->funcs->hubp_update_mall_sel)
717 hubp->funcs->hubp_update_mall_sel(hubp, 0, false);
718
719 dc->hwss.set_flip_control_gsl(pipe_ctx, false);
720
721 hubp->funcs->hubp_clk_cntl(hubp, false);
722
723 dpp->funcs->dpp_dppclk_control(dpp, false, false);
724
725 hubp->power_gated = true;
726
727 hws->funcs.plane_atomic_power_down(dc,
728 pipe_ctx->plane_res.dpp,
729 pipe_ctx->plane_res.hubp);
730
731 pipe_ctx->stream = NULL;
732 memset(&pipe_ctx->stream_res, 0, sizeof(pipe_ctx->stream_res));
733 memset(&pipe_ctx->plane_res, 0, sizeof(pipe_ctx->plane_res));
734 pipe_ctx->top_pipe = NULL;
735 pipe_ctx->bottom_pipe = NULL;
736 pipe_ctx->prev_odm_pipe = NULL;
737 pipe_ctx->next_odm_pipe = NULL;
738 pipe_ctx->plane_state = NULL;
739 }
740
741
dcn20_disable_plane(struct dc * dc,struct dc_state * state,struct pipe_ctx * pipe_ctx)742 void dcn20_disable_plane(struct dc *dc, struct dc_state *state, struct pipe_ctx *pipe_ctx)
743 {
744 bool is_phantom = dc_state_get_pipe_subvp_type(state, pipe_ctx) == SUBVP_PHANTOM;
745 struct timing_generator *tg = is_phantom ? pipe_ctx->stream_res.tg : NULL;
746
747 DC_LOGGER_INIT(dc->ctx->logger);
748
749 if (!pipe_ctx->plane_res.hubp || pipe_ctx->plane_res.hubp->power_gated)
750 return;
751
752 dcn20_plane_atomic_disable(dc, pipe_ctx);
753
754 /* Turn back off the phantom OTG after the phantom plane is fully disabled
755 */
756 if (is_phantom)
757 if (tg && tg->funcs->disable_phantom_crtc)
758 tg->funcs->disable_phantom_crtc(tg);
759
760 DC_LOG_DC("Power down front end %d\n",
761 pipe_ctx->pipe_idx);
762 }
763
dcn20_disable_pixel_data(struct dc * dc,struct pipe_ctx * pipe_ctx,bool blank)764 void dcn20_disable_pixel_data(struct dc *dc, struct pipe_ctx *pipe_ctx, bool blank)
765 {
766 dcn20_blank_pixel_data(dc, pipe_ctx, blank);
767 }
768
calc_mpc_flow_ctrl_cnt(const struct dc_stream_state * stream,int opp_cnt,bool is_two_pixels_per_container)769 static int calc_mpc_flow_ctrl_cnt(const struct dc_stream_state *stream,
770 int opp_cnt, bool is_two_pixels_per_container)
771 {
772 bool hblank_halved = is_two_pixels_per_container;
773 int flow_ctrl_cnt;
774
775 if (opp_cnt >= 2)
776 hblank_halved = true;
777
778 flow_ctrl_cnt = stream->timing.h_total - stream->timing.h_addressable -
779 stream->timing.h_border_left -
780 stream->timing.h_border_right;
781
782 if (hblank_halved)
783 flow_ctrl_cnt /= 2;
784
785 /* ODM combine 4:1 case */
786 if (opp_cnt == 4)
787 flow_ctrl_cnt /= 2;
788
789 return flow_ctrl_cnt;
790 }
791
get_phyd32clk_src(struct dc_link * link)792 static enum phyd32clk_clock_source get_phyd32clk_src(struct dc_link *link)
793 {
794 switch (link->link_enc->transmitter) {
795 case TRANSMITTER_UNIPHY_A:
796 return PHYD32CLKA;
797 case TRANSMITTER_UNIPHY_B:
798 return PHYD32CLKB;
799 case TRANSMITTER_UNIPHY_C:
800 return PHYD32CLKC;
801 case TRANSMITTER_UNIPHY_D:
802 return PHYD32CLKD;
803 case TRANSMITTER_UNIPHY_E:
804 return PHYD32CLKE;
805 default:
806 return PHYD32CLKA;
807 }
808 }
809
get_odm_segment_count(struct pipe_ctx * pipe_ctx)810 static int get_odm_segment_count(struct pipe_ctx *pipe_ctx)
811 {
812 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
813 int count = 1;
814
815 while (odm_pipe != NULL) {
816 count++;
817 odm_pipe = odm_pipe->next_odm_pipe;
818 }
819
820 return count;
821 }
822
dcn20_enable_stream_timing(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc)823 enum dc_status dcn20_enable_stream_timing(
824 struct pipe_ctx *pipe_ctx,
825 struct dc_state *context,
826 struct dc *dc)
827 {
828 struct dce_hwseq *hws = dc->hwseq;
829 struct dc_stream_state *stream = pipe_ctx->stream;
830 struct drr_params params = {0};
831 unsigned int event_triggers = 0;
832 int opp_cnt = 1;
833 int opp_inst[MAX_PIPES] = {0};
834 bool interlace = stream->timing.flags.INTERLACE;
835 int i;
836 struct mpc_dwb_flow_control flow_control;
837 struct mpc *mpc = dc->res_pool->mpc;
838 bool is_two_pixels_per_container =
839 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing);
840 bool rate_control_2x_pclk = (interlace || is_two_pixels_per_container);
841 int odm_slice_width;
842 int last_odm_slice_width;
843 struct pipe_ctx *opp_heads[MAX_PIPES];
844
845 if (dc->res_pool->dccg->funcs->set_pixel_rate_div)
846 dc->res_pool->dccg->funcs->set_pixel_rate_div(
847 dc->res_pool->dccg,
848 pipe_ctx->stream_res.tg->inst,
849 pipe_ctx->pixel_rate_divider.div_factor1,
850 pipe_ctx->pixel_rate_divider.div_factor2);
851
852 /* by upper caller loop, pipe0 is parent pipe and be called first.
853 * back end is set up by for pipe0. Other children pipe share back end
854 * with pipe 0. No program is needed.
855 */
856 if (pipe_ctx->top_pipe != NULL)
857 return DC_OK;
858
859 /* TODO check if timing_changed, disable stream if timing changed */
860
861 opp_cnt = resource_get_opp_heads_for_otg_master(pipe_ctx, &context->res_ctx, opp_heads);
862 for (i = 0; i < opp_cnt; i++)
863 opp_inst[i] = opp_heads[i]->stream_res.opp->inst;
864
865 odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, false);
866 last_odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, true);
867 if (opp_cnt > 1)
868 pipe_ctx->stream_res.tg->funcs->set_odm_combine(
869 pipe_ctx->stream_res.tg,
870 opp_inst, opp_cnt, odm_slice_width,
871 last_odm_slice_width);
872
873 /* HW program guide assume display already disable
874 * by unplug sequence. OTG assume stop.
875 */
876 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
877
878 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
879 pipe_ctx->clock_source,
880 &pipe_ctx->stream_res.pix_clk_params,
881 dc->link_srv->dp_get_encoding_format(&pipe_ctx->link_config.dp_link_settings),
882 &pipe_ctx->pll_settings)) {
883 BREAK_TO_DEBUGGER();
884 return DC_ERROR_UNEXPECTED;
885 }
886
887 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
888 struct dccg *dccg = dc->res_pool->dccg;
889 struct timing_generator *tg = pipe_ctx->stream_res.tg;
890 struct dtbclk_dto_params dto_params = {0};
891
892 if (dccg->funcs->set_dtbclk_p_src)
893 dccg->funcs->set_dtbclk_p_src(dccg, DTBCLK0, tg->inst);
894
895 dto_params.otg_inst = tg->inst;
896 dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10;
897 dto_params.num_odm_segments = get_odm_segment_count(pipe_ctx);
898 dto_params.timing = &pipe_ctx->stream->timing;
899 dto_params.ref_dtbclk_khz = dc->clk_mgr->funcs->get_dtb_ref_clk_frequency(dc->clk_mgr);
900 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
901 }
902
903 if (dc_is_hdmi_tmds_signal(stream->signal)) {
904 stream->link->phy_state.symclk_ref_cnts.otg = 1;
905 if (stream->link->phy_state.symclk_state == SYMCLK_OFF_TX_OFF)
906 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
907 else
908 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
909 }
910
911 if (dc->hwseq->funcs.PLAT_58856_wa && (!dc_is_dp_signal(stream->signal)))
912 dc->hwseq->funcs.PLAT_58856_wa(context, pipe_ctx);
913
914 pipe_ctx->stream_res.tg->funcs->program_timing(
915 pipe_ctx->stream_res.tg,
916 &stream->timing,
917 pipe_ctx->pipe_dlg_param.vready_offset,
918 pipe_ctx->pipe_dlg_param.vstartup_start,
919 pipe_ctx->pipe_dlg_param.vupdate_offset,
920 pipe_ctx->pipe_dlg_param.vupdate_width,
921 pipe_ctx->pipe_dlg_param.pstate_keepout,
922 pipe_ctx->stream->signal,
923 true);
924
925 rate_control_2x_pclk = rate_control_2x_pclk || opp_cnt > 1;
926 flow_control.flow_ctrl_mode = 0;
927 flow_control.flow_ctrl_cnt0 = 0x80;
928 flow_control.flow_ctrl_cnt1 = calc_mpc_flow_ctrl_cnt(stream, opp_cnt,
929 is_two_pixels_per_container);
930 if (mpc->funcs->set_out_rate_control) {
931 for (i = 0; i < opp_cnt; ++i) {
932 mpc->funcs->set_out_rate_control(
933 mpc, opp_inst[i],
934 true,
935 rate_control_2x_pclk,
936 &flow_control);
937 }
938 }
939
940 for (i = 0; i < opp_cnt; i++) {
941 opp_heads[i]->stream_res.opp->funcs->opp_pipe_clock_control(
942 opp_heads[i]->stream_res.opp,
943 true);
944 opp_heads[i]->stream_res.opp->funcs->opp_program_left_edge_extra_pixel(
945 opp_heads[i]->stream_res.opp,
946 stream->timing.pixel_encoding,
947 resource_is_pipe_type(opp_heads[i], OTG_MASTER));
948 }
949
950 hws->funcs.blank_pixel_data(dc, pipe_ctx, true);
951
952 /* VTG is within DCHUB command block. DCFCLK is always on */
953 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
954 BREAK_TO_DEBUGGER();
955 return DC_ERROR_UNEXPECTED;
956 }
957
958 fsleep(stream->timing.v_total * (stream->timing.h_total * 10000u / stream->timing.pix_clk_100hz));
959
960 params.vertical_total_min = stream->adjust.v_total_min;
961 params.vertical_total_max = stream->adjust.v_total_max;
962 params.vertical_total_mid = stream->adjust.v_total_mid;
963 params.vertical_total_mid_frame_num = stream->adjust.v_total_mid_frame_num;
964 set_drr_and_clear_adjust_pending(pipe_ctx, stream, ¶ms);
965
966 // DRR should set trigger event to monitor surface update event
967 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
968 event_triggers = 0x80;
969 /* Event triggers and num frames initialized for DRR, but can be
970 * later updated for PSR use. Note DRR trigger events are generated
971 * regardless of whether num frames met.
972 */
973 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
974 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
975 pipe_ctx->stream_res.tg, event_triggers, 2);
976
977 /* TODO program crtc source select for non-virtual signal*/
978 /* TODO program FMT */
979 /* TODO setup link_enc */
980 /* TODO set stream attributes */
981 /* TODO program audio */
982 /* TODO enable stream if timing changed */
983 /* TODO unblank stream if DP */
984
985 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) == SUBVP_PHANTOM) {
986 if (pipe_ctx->stream_res.tg->funcs->phantom_crtc_post_enable)
987 pipe_ctx->stream_res.tg->funcs->phantom_crtc_post_enable(pipe_ctx->stream_res.tg);
988 }
989
990 return DC_OK;
991 }
992
dcn20_program_output_csc(struct dc * dc,struct pipe_ctx * pipe_ctx,enum dc_color_space colorspace,uint16_t * matrix,int opp_id)993 void dcn20_program_output_csc(struct dc *dc,
994 struct pipe_ctx *pipe_ctx,
995 enum dc_color_space colorspace,
996 uint16_t *matrix,
997 int opp_id)
998 {
999 struct mpc *mpc = dc->res_pool->mpc;
1000 enum mpc_output_csc_mode ocsc_mode = MPC_OUTPUT_CSC_COEF_A;
1001 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
1002
1003 if (mpc->funcs->power_on_mpc_mem_pwr)
1004 mpc->funcs->power_on_mpc_mem_pwr(mpc, mpcc_id, true);
1005
1006 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
1007 if (mpc->funcs->set_output_csc != NULL)
1008 mpc->funcs->set_output_csc(mpc,
1009 opp_id,
1010 matrix,
1011 ocsc_mode);
1012 } else {
1013 if (mpc->funcs->set_ocsc_default != NULL)
1014 mpc->funcs->set_ocsc_default(mpc,
1015 opp_id,
1016 colorspace,
1017 ocsc_mode);
1018 }
1019 }
1020
dcn20_set_output_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_stream_state * stream)1021 bool dcn20_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
1022 const struct dc_stream_state *stream)
1023 {
1024 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
1025 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
1026 const struct pwl_params *params = NULL;
1027 /*
1028 * program OGAM only for the top pipe
1029 * if there is a pipe split then fix diagnostic is required:
1030 * how to pass OGAM parameter for stream.
1031 * if programming for all pipes is required then remove condition
1032 * pipe_ctx->top_pipe == NULL ,but then fix the diagnostic.
1033 */
1034 if (mpc->funcs->power_on_mpc_mem_pwr)
1035 mpc->funcs->power_on_mpc_mem_pwr(mpc, mpcc_id, true);
1036 if (pipe_ctx->top_pipe == NULL
1037 && mpc->funcs->set_output_gamma) {
1038 if (stream->out_transfer_func.type == TF_TYPE_HWPWL)
1039 params = &stream->out_transfer_func.pwl;
1040 else if (pipe_ctx->stream->out_transfer_func.type ==
1041 TF_TYPE_DISTRIBUTED_POINTS &&
1042 cm_helper_translate_curve_to_hw_format(dc->ctx,
1043 &stream->out_transfer_func,
1044 &mpc->blender_params, false))
1045 params = &mpc->blender_params;
1046 /*
1047 * there is no ROM
1048 */
1049 if (stream->out_transfer_func.type == TF_TYPE_PREDEFINED)
1050 BREAK_TO_DEBUGGER();
1051 }
1052 /*
1053 * if above if is not executed then 'params' equal to 0 and set in bypass
1054 */
1055 if (mpc->funcs->set_output_gamma)
1056 mpc->funcs->set_output_gamma(mpc, mpcc_id, params);
1057
1058 return true;
1059 }
1060
dcn20_set_blend_lut(struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)1061 bool dcn20_set_blend_lut(
1062 struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state)
1063 {
1064 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1065 bool result = true;
1066 const struct pwl_params *blend_lut = NULL;
1067
1068 if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
1069 blend_lut = &plane_state->blend_tf.pwl;
1070 else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
1071 cm_helper_translate_curve_to_hw_format(plane_state->ctx,
1072 &plane_state->blend_tf,
1073 &dpp_base->regamma_params, false);
1074 blend_lut = &dpp_base->regamma_params;
1075 }
1076 result = dpp_base->funcs->dpp_program_blnd_lut(dpp_base, blend_lut);
1077
1078 return result;
1079 }
1080
dcn20_set_shaper_3dlut(struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)1081 bool dcn20_set_shaper_3dlut(
1082 struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state)
1083 {
1084 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1085 bool result = true;
1086 const struct pwl_params *shaper_lut = NULL;
1087
1088 if (plane_state->in_shaper_func.type == TF_TYPE_HWPWL)
1089 shaper_lut = &plane_state->in_shaper_func.pwl;
1090 else if (plane_state->in_shaper_func.type == TF_TYPE_DISTRIBUTED_POINTS) {
1091 cm_helper_translate_curve_to_hw_format(plane_state->ctx,
1092 &plane_state->in_shaper_func,
1093 &dpp_base->shaper_params, true);
1094 shaper_lut = &dpp_base->shaper_params;
1095 }
1096
1097 result = dpp_base->funcs->dpp_program_shaper_lut(dpp_base, shaper_lut);
1098 if (plane_state->lut3d_func.state.bits.initialized == 1)
1099 result = dpp_base->funcs->dpp_program_3dlut(dpp_base,
1100 &plane_state->lut3d_func.lut_3d);
1101 else
1102 result = dpp_base->funcs->dpp_program_3dlut(dpp_base, NULL);
1103
1104 return result;
1105 }
1106
dcn20_set_input_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)1107 bool dcn20_set_input_transfer_func(struct dc *dc,
1108 struct pipe_ctx *pipe_ctx,
1109 const struct dc_plane_state *plane_state)
1110 {
1111 struct dce_hwseq *hws = dc->hwseq;
1112 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
1113 const struct dc_transfer_func *tf = NULL;
1114 bool result = true;
1115 bool use_degamma_ram = false;
1116
1117 if (dpp_base == NULL || plane_state == NULL)
1118 return false;
1119
1120 hws->funcs.set_shaper_3dlut(pipe_ctx, plane_state);
1121 hws->funcs.set_blend_lut(pipe_ctx, plane_state);
1122
1123 tf = &plane_state->in_transfer_func;
1124
1125 if (tf->type == TF_TYPE_HWPWL || tf->type == TF_TYPE_DISTRIBUTED_POINTS)
1126 use_degamma_ram = true;
1127
1128 if (use_degamma_ram == true) {
1129 if (tf->type == TF_TYPE_HWPWL)
1130 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base,
1131 &tf->pwl);
1132 else if (tf->type == TF_TYPE_DISTRIBUTED_POINTS) {
1133 cm_helper_translate_curve_to_degamma_hw_format(tf,
1134 &dpp_base->degamma_params);
1135 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base,
1136 &dpp_base->degamma_params);
1137 }
1138 return true;
1139 }
1140 /* handle here the optimized cases when de-gamma ROM could be used.
1141 *
1142 */
1143 if (tf->type == TF_TYPE_PREDEFINED) {
1144 switch (tf->tf) {
1145 case TRANSFER_FUNCTION_SRGB:
1146 dpp_base->funcs->dpp_set_degamma(dpp_base,
1147 IPP_DEGAMMA_MODE_HW_sRGB);
1148 break;
1149 case TRANSFER_FUNCTION_BT709:
1150 dpp_base->funcs->dpp_set_degamma(dpp_base,
1151 IPP_DEGAMMA_MODE_HW_xvYCC);
1152 break;
1153 case TRANSFER_FUNCTION_LINEAR:
1154 dpp_base->funcs->dpp_set_degamma(dpp_base,
1155 IPP_DEGAMMA_MODE_BYPASS);
1156 break;
1157 case TRANSFER_FUNCTION_PQ:
1158 dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_USER_PWL);
1159 cm_helper_translate_curve_to_degamma_hw_format(tf, &dpp_base->degamma_params);
1160 dpp_base->funcs->dpp_program_degamma_pwl(dpp_base, &dpp_base->degamma_params);
1161 result = true;
1162 break;
1163 default:
1164 result = false;
1165 break;
1166 }
1167 } else if (tf->type == TF_TYPE_BYPASS)
1168 dpp_base->funcs->dpp_set_degamma(dpp_base,
1169 IPP_DEGAMMA_MODE_BYPASS);
1170 else {
1171 /*
1172 * if we are here, we did not handle correctly.
1173 * fix is required for this use case
1174 */
1175 BREAK_TO_DEBUGGER();
1176 dpp_base->funcs->dpp_set_degamma(dpp_base,
1177 IPP_DEGAMMA_MODE_BYPASS);
1178 }
1179
1180 return result;
1181 }
1182
dcn20_update_odm(struct dc * dc,struct dc_state * context,struct pipe_ctx * pipe_ctx)1183 void dcn20_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
1184 {
1185 struct pipe_ctx *odm_pipe;
1186 int opp_cnt = 1;
1187 int opp_inst[MAX_PIPES] = { pipe_ctx->stream_res.opp->inst };
1188 int odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, false);
1189 int last_odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, true);
1190
1191 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
1192 opp_inst[opp_cnt] = odm_pipe->stream_res.opp->inst;
1193 opp_cnt++;
1194 }
1195
1196 if (opp_cnt > 1)
1197 pipe_ctx->stream_res.tg->funcs->set_odm_combine(
1198 pipe_ctx->stream_res.tg,
1199 opp_inst, opp_cnt,
1200 odm_slice_width, last_odm_slice_width);
1201 else
1202 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
1203 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
1204 }
1205
dcn20_blank_pixel_data(struct dc * dc,struct pipe_ctx * pipe_ctx,bool blank)1206 void dcn20_blank_pixel_data(
1207 struct dc *dc,
1208 struct pipe_ctx *pipe_ctx,
1209 bool blank)
1210 {
1211 struct tg_color black_color = {0};
1212 struct stream_resource *stream_res = &pipe_ctx->stream_res;
1213 struct dc_stream_state *stream = pipe_ctx->stream;
1214 enum dc_color_space color_space = stream->output_color_space;
1215 enum controller_dp_test_pattern test_pattern = CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR;
1216 enum controller_dp_color_space test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED;
1217 struct pipe_ctx *odm_pipe;
1218 struct rect odm_slice_src;
1219
1220 if (stream->link->test_pattern_enabled)
1221 return;
1222
1223 /* get opp dpg blank color */
1224 color_space_to_black_color(dc, color_space, &black_color);
1225
1226 if (blank) {
1227 dc->hwss.set_abm_immediate_disable(pipe_ctx);
1228
1229 if (dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE) {
1230 test_pattern = CONTROLLER_DP_TEST_PATTERN_COLORSQUARES;
1231 test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_RGB;
1232 }
1233 } else {
1234 test_pattern = CONTROLLER_DP_TEST_PATTERN_VIDEOMODE;
1235 }
1236
1237 odm_pipe = pipe_ctx;
1238
1239 while (odm_pipe->next_odm_pipe) {
1240 odm_slice_src = resource_get_odm_slice_src_rect(odm_pipe);
1241 dc->hwss.set_disp_pattern_generator(dc,
1242 odm_pipe,
1243 test_pattern,
1244 test_pattern_color_space,
1245 stream->timing.display_color_depth,
1246 &black_color,
1247 odm_slice_src.width,
1248 odm_slice_src.height,
1249 odm_slice_src.x);
1250 odm_pipe = odm_pipe->next_odm_pipe;
1251 }
1252
1253 odm_slice_src = resource_get_odm_slice_src_rect(odm_pipe);
1254 dc->hwss.set_disp_pattern_generator(dc,
1255 odm_pipe,
1256 test_pattern,
1257 test_pattern_color_space,
1258 stream->timing.display_color_depth,
1259 &black_color,
1260 odm_slice_src.width,
1261 odm_slice_src.height,
1262 odm_slice_src.x);
1263
1264 if (!blank)
1265 if (stream_res->abm) {
1266 dc->hwss.set_pipe(pipe_ctx);
1267 stream_res->abm->funcs->set_abm_level(stream_res->abm, stream->abm_level);
1268 }
1269 }
1270
1271
dcn20_power_on_plane_resources(struct dce_hwseq * hws,struct pipe_ctx * pipe_ctx)1272 static void dcn20_power_on_plane_resources(
1273 struct dce_hwseq *hws,
1274 struct pipe_ctx *pipe_ctx)
1275 {
1276 uint32_t org_ip_request_cntl = 0;
1277
1278 DC_LOGGER_INIT(hws->ctx->logger);
1279
1280 if (hws->funcs.dpp_root_clock_control)
1281 hws->funcs.dpp_root_clock_control(hws, pipe_ctx->plane_res.dpp->inst, true);
1282
1283 if (REG(DC_IP_REQUEST_CNTL)) {
1284 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
1285 if (org_ip_request_cntl == 0)
1286 REG_SET(DC_IP_REQUEST_CNTL, 0,
1287 IP_REQUEST_EN, 1);
1288
1289 if (hws->funcs.dpp_pg_control)
1290 hws->funcs.dpp_pg_control(hws, pipe_ctx->plane_res.dpp->inst, true);
1291
1292 if (hws->funcs.hubp_pg_control)
1293 hws->funcs.hubp_pg_control(hws, pipe_ctx->plane_res.hubp->inst, true);
1294
1295 if (org_ip_request_cntl == 0)
1296 REG_SET(DC_IP_REQUEST_CNTL, 0,
1297 IP_REQUEST_EN, 0);
1298
1299 DC_LOG_DEBUG(
1300 "Un-gated front end for pipe %d\n", pipe_ctx->plane_res.hubp->inst);
1301 }
1302 }
1303
dcn20_enable_plane(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)1304 void dcn20_enable_plane(struct dc *dc, struct pipe_ctx *pipe_ctx,
1305 struct dc_state *context)
1306 {
1307 //if (dc->debug.sanity_checks) {
1308 // dcn10_verify_allow_pstate_change_high(dc);
1309 //}
1310 dcn20_power_on_plane_resources(dc->hwseq, pipe_ctx);
1311
1312 /* enable DCFCLK current DCHUB */
1313 pipe_ctx->plane_res.hubp->funcs->hubp_clk_cntl(pipe_ctx->plane_res.hubp, true);
1314
1315 /* initialize HUBP on power up */
1316 pipe_ctx->plane_res.hubp->funcs->hubp_init(pipe_ctx->plane_res.hubp);
1317
1318 /* make sure OPP_PIPE_CLOCK_EN = 1 */
1319 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
1320 pipe_ctx->stream_res.opp,
1321 true);
1322
1323 /* TODO: enable/disable in dm as per update type.
1324 if (plane_state) {
1325 DC_LOG_DC(dc->ctx->logger,
1326 "Pipe:%d 0x%x: addr hi:0x%x, "
1327 "addr low:0x%x, "
1328 "src: %d, %d, %d,"
1329 " %d; dst: %d, %d, %d, %d;\n",
1330 pipe_ctx->pipe_idx,
1331 plane_state,
1332 plane_state->address.grph.addr.high_part,
1333 plane_state->address.grph.addr.low_part,
1334 plane_state->src_rect.x,
1335 plane_state->src_rect.y,
1336 plane_state->src_rect.width,
1337 plane_state->src_rect.height,
1338 plane_state->dst_rect.x,
1339 plane_state->dst_rect.y,
1340 plane_state->dst_rect.width,
1341 plane_state->dst_rect.height);
1342
1343 DC_LOG_DC(dc->ctx->logger,
1344 "Pipe %d: width, height, x, y format:%d\n"
1345 "viewport:%d, %d, %d, %d\n"
1346 "recout: %d, %d, %d, %d\n",
1347 pipe_ctx->pipe_idx,
1348 plane_state->format,
1349 pipe_ctx->plane_res.scl_data.viewport.width,
1350 pipe_ctx->plane_res.scl_data.viewport.height,
1351 pipe_ctx->plane_res.scl_data.viewport.x,
1352 pipe_ctx->plane_res.scl_data.viewport.y,
1353 pipe_ctx->plane_res.scl_data.recout.width,
1354 pipe_ctx->plane_res.scl_data.recout.height,
1355 pipe_ctx->plane_res.scl_data.recout.x,
1356 pipe_ctx->plane_res.scl_data.recout.y);
1357 print_rq_dlg_ttu(dc, pipe_ctx);
1358 }
1359 */
1360 if (dc->vm_pa_config.valid) {
1361 struct vm_system_aperture_param apt;
1362
1363 apt.sys_default.quad_part = 0;
1364
1365 apt.sys_low.quad_part = dc->vm_pa_config.system_aperture.start_addr;
1366 apt.sys_high.quad_part = dc->vm_pa_config.system_aperture.end_addr;
1367
1368 // Program system aperture settings
1369 pipe_ctx->plane_res.hubp->funcs->hubp_set_vm_system_aperture_settings(pipe_ctx->plane_res.hubp, &apt);
1370 }
1371
1372 if (!pipe_ctx->top_pipe
1373 && pipe_ctx->plane_state
1374 && pipe_ctx->plane_state->flip_int_enabled
1375 && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_int)
1376 pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_int(pipe_ctx->plane_res.hubp);
1377
1378 // if (dc->debug.sanity_checks) {
1379 // dcn10_verify_allow_pstate_change_high(dc);
1380 // }
1381 }
1382
dcn20_pipe_control_lock(struct dc * dc,struct pipe_ctx * pipe,bool lock)1383 void dcn20_pipe_control_lock(
1384 struct dc *dc,
1385 struct pipe_ctx *pipe,
1386 bool lock)
1387 {
1388 struct pipe_ctx *temp_pipe;
1389 bool flip_immediate = false;
1390
1391 /* use TG master update lock to lock everything on the TG
1392 * therefore only top pipe need to lock
1393 */
1394 if (!pipe || pipe->top_pipe)
1395 return;
1396
1397 if (pipe->plane_state != NULL)
1398 flip_immediate = pipe->plane_state->flip_immediate;
1399
1400 if (pipe->stream_res.gsl_group > 0) {
1401 temp_pipe = pipe->bottom_pipe;
1402 while (!flip_immediate && temp_pipe) {
1403 if (temp_pipe->plane_state != NULL)
1404 flip_immediate = temp_pipe->plane_state->flip_immediate;
1405 temp_pipe = temp_pipe->bottom_pipe;
1406 }
1407 }
1408
1409 if (flip_immediate && lock) {
1410 const int TIMEOUT_FOR_FLIP_PENDING_US = 100000;
1411 unsigned int polling_interval_us = 1;
1412 int i;
1413
1414 temp_pipe = pipe;
1415 while (temp_pipe) {
1416 if (temp_pipe->plane_state && temp_pipe->plane_state->flip_immediate) {
1417 for (i = 0; i < TIMEOUT_FOR_FLIP_PENDING_US / polling_interval_us; ++i) {
1418 if (!temp_pipe->plane_res.hubp->funcs->hubp_is_flip_pending(temp_pipe->plane_res.hubp))
1419 break;
1420 udelay(polling_interval_us);
1421 }
1422
1423 /* no reason it should take this long for immediate flips */
1424 ASSERT(i != TIMEOUT_FOR_FLIP_PENDING_US);
1425 }
1426 temp_pipe = temp_pipe->bottom_pipe;
1427 }
1428 }
1429
1430 /* In flip immediate and pipe splitting case, we need to use GSL
1431 * for synchronization. Only do setup on locking and on flip type change.
1432 */
1433 if (lock && (pipe->bottom_pipe != NULL || !flip_immediate))
1434 if ((flip_immediate && pipe->stream_res.gsl_group == 0) ||
1435 (!flip_immediate && pipe->stream_res.gsl_group > 0))
1436 dcn20_setup_gsl_group_as_lock(dc, pipe, flip_immediate);
1437
1438 if (pipe->plane_state != NULL)
1439 flip_immediate = pipe->plane_state->flip_immediate;
1440
1441 temp_pipe = pipe->bottom_pipe;
1442 while (flip_immediate && temp_pipe) {
1443 if (temp_pipe->plane_state != NULL)
1444 flip_immediate = temp_pipe->plane_state->flip_immediate;
1445 temp_pipe = temp_pipe->bottom_pipe;
1446 }
1447
1448 if (!lock && pipe->stream_res.gsl_group > 0 && pipe->plane_state &&
1449 !flip_immediate)
1450 dcn20_setup_gsl_group_as_lock(dc, pipe, false);
1451
1452 if (pipe->stream && should_use_dmub_lock(pipe->stream->link)) {
1453 union dmub_hw_lock_flags hw_locks = { 0 };
1454 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
1455
1456 hw_locks.bits.lock_pipe = 1;
1457 inst_flags.otg_inst = pipe->stream_res.tg->inst;
1458
1459 if (pipe->plane_state != NULL)
1460 hw_locks.bits.triple_buffer_lock = pipe->plane_state->triplebuffer_flips;
1461
1462 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
1463 lock,
1464 &hw_locks,
1465 &inst_flags);
1466 } else if (pipe->plane_state != NULL && pipe->plane_state->triplebuffer_flips) {
1467 if (lock)
1468 pipe->stream_res.tg->funcs->triplebuffer_lock(pipe->stream_res.tg);
1469 else
1470 pipe->stream_res.tg->funcs->triplebuffer_unlock(pipe->stream_res.tg);
1471 } else {
1472 if (lock)
1473 pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
1474 else {
1475 if (dc->hwseq->funcs.perform_3dlut_wa_unlock)
1476 dc->hwseq->funcs.perform_3dlut_wa_unlock(pipe);
1477 else
1478 pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
1479 }
1480 }
1481 }
1482
dcn20_detect_pipe_changes(struct dc_state * old_state,struct dc_state * new_state,struct pipe_ctx * old_pipe,struct pipe_ctx * new_pipe)1483 void dcn20_detect_pipe_changes(struct dc_state *old_state,
1484 struct dc_state *new_state,
1485 struct pipe_ctx *old_pipe,
1486 struct pipe_ctx *new_pipe)
1487 {
1488 bool old_is_phantom = dc_state_get_pipe_subvp_type(old_state, old_pipe) == SUBVP_PHANTOM;
1489 bool new_is_phantom = dc_state_get_pipe_subvp_type(new_state, new_pipe) == SUBVP_PHANTOM;
1490
1491 new_pipe->update_flags.raw = 0;
1492
1493 /* If non-phantom pipe is being transitioned to a phantom pipe,
1494 * set disable and return immediately. This is because the pipe
1495 * that was previously in use must be fully disabled before we
1496 * can "enable" it as a phantom pipe (since the OTG will certainly
1497 * be different). The post_unlock sequence will set the correct
1498 * update flags to enable the phantom pipe.
1499 */
1500 if (old_pipe->plane_state && !old_is_phantom &&
1501 new_pipe->plane_state && new_is_phantom) {
1502 new_pipe->update_flags.bits.disable = 1;
1503 return;
1504 }
1505
1506 if (resource_is_pipe_type(new_pipe, OTG_MASTER) &&
1507 resource_is_odm_topology_changed(new_pipe, old_pipe))
1508 /* Detect odm changes */
1509 new_pipe->update_flags.bits.odm = 1;
1510
1511 /* Exit on unchanged, unused pipe */
1512 if (!old_pipe->plane_state && !new_pipe->plane_state)
1513 return;
1514 /* Detect pipe enable/disable */
1515 if (!old_pipe->plane_state && new_pipe->plane_state) {
1516 new_pipe->update_flags.bits.enable = 1;
1517 new_pipe->update_flags.bits.mpcc = 1;
1518 new_pipe->update_flags.bits.dppclk = 1;
1519 new_pipe->update_flags.bits.hubp_interdependent = 1;
1520 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
1521 new_pipe->update_flags.bits.unbounded_req = 1;
1522 new_pipe->update_flags.bits.gamut_remap = 1;
1523 new_pipe->update_flags.bits.scaler = 1;
1524 new_pipe->update_flags.bits.viewport = 1;
1525 new_pipe->update_flags.bits.det_size = 1;
1526 if (new_pipe->stream->test_pattern.type != DP_TEST_PATTERN_VIDEO_MODE &&
1527 new_pipe->stream_res.test_pattern_params.width != 0 &&
1528 new_pipe->stream_res.test_pattern_params.height != 0)
1529 new_pipe->update_flags.bits.test_pattern_changed = 1;
1530 if (!new_pipe->top_pipe && !new_pipe->prev_odm_pipe) {
1531 new_pipe->update_flags.bits.odm = 1;
1532 new_pipe->update_flags.bits.global_sync = 1;
1533 }
1534 return;
1535 }
1536
1537 /* For SubVP we need to unconditionally enable because any phantom pipes are
1538 * always removed then newly added for every full updates whenever SubVP is in use.
1539 * The remove-add sequence of the phantom pipe always results in the pipe
1540 * being blanked in enable_stream_timing (DPG).
1541 */
1542 if (new_pipe->stream && dc_state_get_pipe_subvp_type(new_state, new_pipe) == SUBVP_PHANTOM)
1543 new_pipe->update_flags.bits.enable = 1;
1544
1545 /* Phantom pipes are effectively disabled, if the pipe was previously phantom
1546 * we have to enable
1547 */
1548 if (old_pipe->plane_state && old_is_phantom &&
1549 new_pipe->plane_state && !new_is_phantom)
1550 new_pipe->update_flags.bits.enable = 1;
1551
1552 if (old_pipe->plane_state && !new_pipe->plane_state) {
1553 new_pipe->update_flags.bits.disable = 1;
1554 return;
1555 }
1556
1557 /* Detect plane change */
1558 if (old_pipe->plane_state != new_pipe->plane_state) {
1559 new_pipe->update_flags.bits.plane_changed = true;
1560 }
1561
1562 /* Detect top pipe only changes */
1563 if (resource_is_pipe_type(new_pipe, OTG_MASTER)) {
1564 /* Detect global sync changes */
1565 if (old_pipe->pipe_dlg_param.vready_offset != new_pipe->pipe_dlg_param.vready_offset
1566 || old_pipe->pipe_dlg_param.vstartup_start != new_pipe->pipe_dlg_param.vstartup_start
1567 || old_pipe->pipe_dlg_param.vupdate_offset != new_pipe->pipe_dlg_param.vupdate_offset
1568 || old_pipe->pipe_dlg_param.vupdate_width != new_pipe->pipe_dlg_param.vupdate_width)
1569 new_pipe->update_flags.bits.global_sync = 1;
1570 }
1571
1572 if (old_pipe->det_buffer_size_kb != new_pipe->det_buffer_size_kb)
1573 new_pipe->update_flags.bits.det_size = 1;
1574
1575 /*
1576 * Detect opp / tg change, only set on change, not on enable
1577 * Assume mpcc inst = pipe index, if not this code needs to be updated
1578 * since mpcc is what is affected by these. In fact all of our sequence
1579 * makes this assumption at the moment with how hubp reset is matched to
1580 * same index mpcc reset.
1581 */
1582 if (old_pipe->stream_res.opp != new_pipe->stream_res.opp)
1583 new_pipe->update_flags.bits.opp_changed = 1;
1584 if (old_pipe->stream_res.tg != new_pipe->stream_res.tg)
1585 new_pipe->update_flags.bits.tg_changed = 1;
1586
1587 /*
1588 * Detect mpcc blending changes, only dpp inst and opp matter here,
1589 * mpccs getting removed/inserted update connected ones during their own
1590 * programming
1591 */
1592 if (old_pipe->plane_res.dpp != new_pipe->plane_res.dpp
1593 || old_pipe->stream_res.opp != new_pipe->stream_res.opp)
1594 new_pipe->update_flags.bits.mpcc = 1;
1595
1596 /* Detect dppclk change */
1597 if (old_pipe->plane_res.bw.dppclk_khz != new_pipe->plane_res.bw.dppclk_khz)
1598 new_pipe->update_flags.bits.dppclk = 1;
1599
1600 /* Check for scl update */
1601 if (memcmp(&old_pipe->plane_res.scl_data, &new_pipe->plane_res.scl_data, sizeof(struct scaler_data)))
1602 new_pipe->update_flags.bits.scaler = 1;
1603 /* Check for vp update */
1604 if (memcmp(&old_pipe->plane_res.scl_data.viewport, &new_pipe->plane_res.scl_data.viewport, sizeof(struct rect))
1605 || memcmp(&old_pipe->plane_res.scl_data.viewport_c,
1606 &new_pipe->plane_res.scl_data.viewport_c, sizeof(struct rect)))
1607 new_pipe->update_flags.bits.viewport = 1;
1608
1609 /* Detect dlg/ttu/rq updates */
1610 {
1611 struct _vcs_dpi_display_dlg_regs_st old_dlg_attr = old_pipe->dlg_regs;
1612 struct _vcs_dpi_display_ttu_regs_st old_ttu_attr = old_pipe->ttu_regs;
1613 struct _vcs_dpi_display_dlg_regs_st *new_dlg_attr = &new_pipe->dlg_regs;
1614 struct _vcs_dpi_display_ttu_regs_st *new_ttu_attr = &new_pipe->ttu_regs;
1615
1616 /* Detect pipe interdependent updates */
1617 if (old_dlg_attr.dst_y_prefetch != new_dlg_attr->dst_y_prefetch ||
1618 old_dlg_attr.vratio_prefetch != new_dlg_attr->vratio_prefetch ||
1619 old_dlg_attr.vratio_prefetch_c != new_dlg_attr->vratio_prefetch_c ||
1620 old_dlg_attr.dst_y_per_vm_vblank != new_dlg_attr->dst_y_per_vm_vblank ||
1621 old_dlg_attr.dst_y_per_row_vblank != new_dlg_attr->dst_y_per_row_vblank ||
1622 old_dlg_attr.dst_y_per_vm_flip != new_dlg_attr->dst_y_per_vm_flip ||
1623 old_dlg_attr.dst_y_per_row_flip != new_dlg_attr->dst_y_per_row_flip ||
1624 old_dlg_attr.refcyc_per_meta_chunk_vblank_l != new_dlg_attr->refcyc_per_meta_chunk_vblank_l ||
1625 old_dlg_attr.refcyc_per_meta_chunk_vblank_c != new_dlg_attr->refcyc_per_meta_chunk_vblank_c ||
1626 old_dlg_attr.refcyc_per_meta_chunk_flip_l != new_dlg_attr->refcyc_per_meta_chunk_flip_l ||
1627 old_dlg_attr.refcyc_per_line_delivery_pre_l != new_dlg_attr->refcyc_per_line_delivery_pre_l ||
1628 old_dlg_attr.refcyc_per_line_delivery_pre_c != new_dlg_attr->refcyc_per_line_delivery_pre_c ||
1629 old_ttu_attr.refcyc_per_req_delivery_pre_l != new_ttu_attr->refcyc_per_req_delivery_pre_l ||
1630 old_ttu_attr.refcyc_per_req_delivery_pre_c != new_ttu_attr->refcyc_per_req_delivery_pre_c ||
1631 old_ttu_attr.refcyc_per_req_delivery_pre_cur0 != new_ttu_attr->refcyc_per_req_delivery_pre_cur0 ||
1632 old_ttu_attr.refcyc_per_req_delivery_pre_cur1 != new_ttu_attr->refcyc_per_req_delivery_pre_cur1 ||
1633 old_ttu_attr.min_ttu_vblank != new_ttu_attr->min_ttu_vblank ||
1634 old_ttu_attr.qos_level_flip != new_ttu_attr->qos_level_flip) {
1635 old_dlg_attr.dst_y_prefetch = new_dlg_attr->dst_y_prefetch;
1636 old_dlg_attr.vratio_prefetch = new_dlg_attr->vratio_prefetch;
1637 old_dlg_attr.vratio_prefetch_c = new_dlg_attr->vratio_prefetch_c;
1638 old_dlg_attr.dst_y_per_vm_vblank = new_dlg_attr->dst_y_per_vm_vblank;
1639 old_dlg_attr.dst_y_per_row_vblank = new_dlg_attr->dst_y_per_row_vblank;
1640 old_dlg_attr.dst_y_per_vm_flip = new_dlg_attr->dst_y_per_vm_flip;
1641 old_dlg_attr.dst_y_per_row_flip = new_dlg_attr->dst_y_per_row_flip;
1642 old_dlg_attr.refcyc_per_meta_chunk_vblank_l = new_dlg_attr->refcyc_per_meta_chunk_vblank_l;
1643 old_dlg_attr.refcyc_per_meta_chunk_vblank_c = new_dlg_attr->refcyc_per_meta_chunk_vblank_c;
1644 old_dlg_attr.refcyc_per_meta_chunk_flip_l = new_dlg_attr->refcyc_per_meta_chunk_flip_l;
1645 old_dlg_attr.refcyc_per_line_delivery_pre_l = new_dlg_attr->refcyc_per_line_delivery_pre_l;
1646 old_dlg_attr.refcyc_per_line_delivery_pre_c = new_dlg_attr->refcyc_per_line_delivery_pre_c;
1647 old_ttu_attr.refcyc_per_req_delivery_pre_l = new_ttu_attr->refcyc_per_req_delivery_pre_l;
1648 old_ttu_attr.refcyc_per_req_delivery_pre_c = new_ttu_attr->refcyc_per_req_delivery_pre_c;
1649 old_ttu_attr.refcyc_per_req_delivery_pre_cur0 = new_ttu_attr->refcyc_per_req_delivery_pre_cur0;
1650 old_ttu_attr.refcyc_per_req_delivery_pre_cur1 = new_ttu_attr->refcyc_per_req_delivery_pre_cur1;
1651 old_ttu_attr.min_ttu_vblank = new_ttu_attr->min_ttu_vblank;
1652 old_ttu_attr.qos_level_flip = new_ttu_attr->qos_level_flip;
1653 new_pipe->update_flags.bits.hubp_interdependent = 1;
1654 }
1655 /* Detect any other updates to ttu/rq/dlg */
1656 if (memcmp(&old_dlg_attr, &new_pipe->dlg_regs, sizeof(old_dlg_attr)) ||
1657 memcmp(&old_ttu_attr, &new_pipe->ttu_regs, sizeof(old_ttu_attr)) ||
1658 memcmp(&old_pipe->rq_regs, &new_pipe->rq_regs, sizeof(old_pipe->rq_regs)))
1659 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
1660 }
1661
1662 if (old_pipe->unbounded_req != new_pipe->unbounded_req)
1663 new_pipe->update_flags.bits.unbounded_req = 1;
1664
1665 if (memcmp(&old_pipe->stream_res.test_pattern_params,
1666 &new_pipe->stream_res.test_pattern_params, sizeof(struct test_pattern_params))) {
1667 new_pipe->update_flags.bits.test_pattern_changed = 1;
1668 }
1669 }
1670
dcn20_update_dchubp_dpp(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)1671 void dcn20_update_dchubp_dpp(
1672 struct dc *dc,
1673 struct pipe_ctx *pipe_ctx,
1674 struct dc_state *context)
1675 {
1676 struct dce_hwseq *hws = dc->hwseq;
1677 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1678 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1679 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1680 struct dccg *dccg = dc->res_pool->dccg;
1681 bool viewport_changed = false;
1682 enum mall_stream_type pipe_mall_type = dc_state_get_pipe_subvp_type(context, pipe_ctx);
1683
1684 if (pipe_ctx->update_flags.bits.dppclk)
1685 dpp->funcs->dpp_dppclk_control(dpp, false, true);
1686
1687 if (pipe_ctx->update_flags.bits.enable)
1688 dccg->funcs->update_dpp_dto(dccg, dpp->inst, pipe_ctx->plane_res.bw.dppclk_khz);
1689
1690 /* TODO: Need input parameter to tell current DCHUB pipe tie to which OTG
1691 * VTG is within DCHUBBUB which is commond block share by each pipe HUBP.
1692 * VTG is 1:1 mapping with OTG. Each pipe HUBP will select which VTG
1693 */
1694
1695 if (pipe_ctx->update_flags.bits.hubp_rq_dlg_ttu) {
1696 hubp->funcs->hubp_vtg_sel(hubp, pipe_ctx->stream_res.tg->inst);
1697
1698 if (hubp->funcs->hubp_setup2) {
1699 hubp->funcs->hubp_setup2(
1700 hubp,
1701 &pipe_ctx->hubp_regs,
1702 &pipe_ctx->global_sync,
1703 &pipe_ctx->stream->timing);
1704 } else {
1705 hubp->funcs->hubp_setup(
1706 hubp,
1707 &pipe_ctx->dlg_regs,
1708 &pipe_ctx->ttu_regs,
1709 &pipe_ctx->rq_regs,
1710 &pipe_ctx->pipe_dlg_param);
1711 }
1712 }
1713
1714 if (pipe_ctx->update_flags.bits.unbounded_req && hubp->funcs->set_unbounded_requesting)
1715 hubp->funcs->set_unbounded_requesting(hubp, pipe_ctx->unbounded_req);
1716
1717 if (pipe_ctx->update_flags.bits.hubp_interdependent) {
1718 if (hubp->funcs->hubp_setup_interdependent2) {
1719 hubp->funcs->hubp_setup_interdependent2(
1720 hubp,
1721 &pipe_ctx->hubp_regs);
1722 } else {
1723 hubp->funcs->hubp_setup_interdependent(
1724 hubp,
1725 &pipe_ctx->dlg_regs,
1726 &pipe_ctx->ttu_regs);
1727 }
1728 }
1729
1730 if (pipe_ctx->update_flags.bits.enable ||
1731 pipe_ctx->update_flags.bits.plane_changed ||
1732 plane_state->update_flags.bits.bpp_change ||
1733 plane_state->update_flags.bits.input_csc_change ||
1734 plane_state->update_flags.bits.color_space_change ||
1735 plane_state->update_flags.bits.coeff_reduction_change) {
1736 struct dc_bias_and_scale bns_params = plane_state->bias_and_scale;
1737
1738 // program the input csc
1739 dpp->funcs->dpp_setup(dpp,
1740 plane_state->format,
1741 EXPANSION_MODE_ZERO,
1742 plane_state->input_csc_color_matrix,
1743 plane_state->color_space,
1744 NULL);
1745
1746 if (dpp->funcs->set_cursor_matrix) {
1747 dpp->funcs->set_cursor_matrix(dpp,
1748 plane_state->color_space,
1749 plane_state->cursor_csc_color_matrix);
1750 }
1751 if (dpp->funcs->dpp_program_bias_and_scale) {
1752 //TODO :for CNVC set scale and bias registers if necessary
1753 dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
1754 }
1755 }
1756
1757 if (pipe_ctx->update_flags.bits.mpcc
1758 || pipe_ctx->update_flags.bits.plane_changed
1759 || plane_state->update_flags.bits.global_alpha_change
1760 || plane_state->update_flags.bits.per_pixel_alpha_change) {
1761 // MPCC inst is equal to pipe index in practice
1762 hws->funcs.update_mpcc(dc, pipe_ctx);
1763 }
1764
1765 if (pipe_ctx->update_flags.bits.scaler ||
1766 plane_state->update_flags.bits.scaling_change ||
1767 plane_state->update_flags.bits.position_change ||
1768 plane_state->update_flags.bits.per_pixel_alpha_change ||
1769 pipe_ctx->stream->update_flags.bits.scaling) {
1770 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->plane_state->per_pixel_alpha;
1771 ASSERT(pipe_ctx->plane_res.scl_data.lb_params.depth == LB_PIXEL_DEPTH_36BPP);
1772 /* scaler configuration */
1773 pipe_ctx->plane_res.dpp->funcs->dpp_set_scaler(
1774 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data);
1775 }
1776
1777 if (pipe_ctx->update_flags.bits.viewport ||
1778 (context == dc->current_state && plane_state->update_flags.bits.position_change) ||
1779 (context == dc->current_state && plane_state->update_flags.bits.scaling_change) ||
1780 (context == dc->current_state && pipe_ctx->stream->update_flags.bits.scaling)) {
1781
1782 hubp->funcs->mem_program_viewport(
1783 hubp,
1784 &pipe_ctx->plane_res.scl_data.viewport,
1785 &pipe_ctx->plane_res.scl_data.viewport_c);
1786 viewport_changed = true;
1787 }
1788
1789 if (hubp->funcs->hubp_program_mcache_id_and_split_coordinate)
1790 hubp->funcs->hubp_program_mcache_id_and_split_coordinate(hubp, &pipe_ctx->mcache_regs);
1791
1792 /* Any updates are handled in dc interface, just need to apply existing for plane enable */
1793 if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed ||
1794 pipe_ctx->update_flags.bits.scaler || viewport_changed == true) &&
1795 pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
1796 dc->hwss.set_cursor_attribute(pipe_ctx);
1797 dc->hwss.set_cursor_position(pipe_ctx);
1798
1799 if (dc->hwss.set_cursor_sdr_white_level)
1800 dc->hwss.set_cursor_sdr_white_level(pipe_ctx);
1801 }
1802
1803 /* Any updates are handled in dc interface, just need
1804 * to apply existing for plane enable / opp change */
1805 if (pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed
1806 || pipe_ctx->update_flags.bits.plane_changed
1807 || pipe_ctx->stream->update_flags.bits.gamut_remap
1808 || plane_state->update_flags.bits.gamut_remap_change
1809 || pipe_ctx->stream->update_flags.bits.out_csc) {
1810 /* dpp/cm gamut remap*/
1811 dc->hwss.program_gamut_remap(pipe_ctx);
1812
1813 /*call the dcn2 method which uses mpc csc*/
1814 dc->hwss.program_output_csc(dc,
1815 pipe_ctx,
1816 pipe_ctx->stream->output_color_space,
1817 pipe_ctx->stream->csc_color_matrix.matrix,
1818 hubp->opp_id);
1819 }
1820
1821 if (pipe_ctx->update_flags.bits.enable ||
1822 pipe_ctx->update_flags.bits.plane_changed ||
1823 pipe_ctx->update_flags.bits.opp_changed ||
1824 plane_state->update_flags.bits.pixel_format_change ||
1825 plane_state->update_flags.bits.horizontal_mirror_change ||
1826 plane_state->update_flags.bits.rotation_change ||
1827 plane_state->update_flags.bits.swizzle_change ||
1828 plane_state->update_flags.bits.dcc_change ||
1829 plane_state->update_flags.bits.bpp_change ||
1830 plane_state->update_flags.bits.scaling_change ||
1831 plane_state->update_flags.bits.plane_size_change) {
1832 struct plane_size size = plane_state->plane_size;
1833
1834 size.surface_size = pipe_ctx->plane_res.scl_data.viewport;
1835 hubp->funcs->hubp_program_surface_config(
1836 hubp,
1837 plane_state->format,
1838 &plane_state->tiling_info,
1839 &size,
1840 plane_state->rotation,
1841 &plane_state->dcc,
1842 plane_state->horizontal_mirror,
1843 0);
1844 hubp->power_gated = false;
1845 }
1846
1847 if (pipe_ctx->update_flags.bits.enable ||
1848 pipe_ctx->update_flags.bits.plane_changed ||
1849 plane_state->update_flags.bits.addr_update) {
1850 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER) &&
1851 pipe_mall_type == SUBVP_MAIN) {
1852 union block_sequence_params params;
1853
1854 params.subvp_save_surf_addr.dc_dmub_srv = dc->ctx->dmub_srv;
1855 params.subvp_save_surf_addr.addr = &pipe_ctx->plane_state->address;
1856 params.subvp_save_surf_addr.subvp_index = pipe_ctx->subvp_index;
1857 hwss_subvp_save_surf_addr(¶ms);
1858 }
1859 dc->hwss.update_plane_addr(dc, pipe_ctx);
1860 }
1861
1862 if (pipe_ctx->update_flags.bits.enable)
1863 hubp->funcs->set_blank(hubp, false);
1864 /* If the stream paired with this plane is phantom, the plane is also phantom */
1865 if (pipe_mall_type == SUBVP_PHANTOM && hubp->funcs->phantom_hubp_post_enable)
1866 hubp->funcs->phantom_hubp_post_enable(hubp);
1867 }
1868
dcn20_calculate_vready_offset_for_group(struct pipe_ctx * pipe)1869 static int dcn20_calculate_vready_offset_for_group(struct pipe_ctx *pipe)
1870 {
1871 struct pipe_ctx *other_pipe;
1872 int vready_offset = pipe->pipe_dlg_param.vready_offset;
1873
1874 /* Always use the largest vready_offset of all connected pipes */
1875 for (other_pipe = pipe->bottom_pipe; other_pipe != NULL; other_pipe = other_pipe->bottom_pipe) {
1876 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1877 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1878 }
1879 for (other_pipe = pipe->top_pipe; other_pipe != NULL; other_pipe = other_pipe->top_pipe) {
1880 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1881 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1882 }
1883 for (other_pipe = pipe->next_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->next_odm_pipe) {
1884 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1885 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1886 }
1887 for (other_pipe = pipe->prev_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->prev_odm_pipe) {
1888 if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
1889 vready_offset = other_pipe->pipe_dlg_param.vready_offset;
1890 }
1891
1892 return vready_offset;
1893 }
1894
dcn20_program_tg(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dce_hwseq * hws)1895 static void dcn20_program_tg(
1896 struct dc *dc,
1897 struct pipe_ctx *pipe_ctx,
1898 struct dc_state *context,
1899 struct dce_hwseq *hws)
1900 {
1901 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1902 pipe_ctx->stream_res.tg,
1903 dcn20_calculate_vready_offset_for_group(pipe_ctx),
1904 pipe_ctx->pipe_dlg_param.vstartup_start,
1905 pipe_ctx->pipe_dlg_param.vupdate_offset,
1906 pipe_ctx->pipe_dlg_param.vupdate_width,
1907 pipe_ctx->pipe_dlg_param.pstate_keepout);
1908
1909 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM)
1910 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
1911
1912 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
1913 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, true);
1914
1915 if (hws->funcs.setup_vupdate_interrupt)
1916 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1917 }
1918
dcn20_program_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)1919 static void dcn20_program_pipe(
1920 struct dc *dc,
1921 struct pipe_ctx *pipe_ctx,
1922 struct dc_state *context)
1923 {
1924 struct dce_hwseq *hws = dc->hwseq;
1925
1926 /* Only need to unblank on top pipe */
1927 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER)) {
1928 if (pipe_ctx->update_flags.bits.enable ||
1929 pipe_ctx->update_flags.bits.odm ||
1930 pipe_ctx->stream->update_flags.bits.abm_level)
1931 hws->funcs.blank_pixel_data(dc, pipe_ctx,
1932 !pipe_ctx->plane_state ||
1933 !pipe_ctx->plane_state->visible);
1934 }
1935
1936 /* Only update TG on top pipe */
1937 if (pipe_ctx->update_flags.bits.global_sync && !pipe_ctx->top_pipe
1938 && !pipe_ctx->prev_odm_pipe)
1939 dcn20_program_tg(dc, pipe_ctx, context, hws);
1940
1941 if (pipe_ctx->update_flags.bits.odm)
1942 hws->funcs.update_odm(dc, context, pipe_ctx);
1943
1944 if (pipe_ctx->update_flags.bits.enable) {
1945 if (hws->funcs.enable_plane)
1946 hws->funcs.enable_plane(dc, pipe_ctx, context);
1947 else
1948 dcn20_enable_plane(dc, pipe_ctx, context);
1949
1950 if (dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes)
1951 dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes(dc->res_pool->hubbub);
1952 }
1953
1954 if (pipe_ctx->update_flags.bits.det_size) {
1955 if (dc->res_pool->hubbub->funcs->program_det_size)
1956 dc->res_pool->hubbub->funcs->program_det_size(
1957 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->det_buffer_size_kb);
1958
1959 if (dc->res_pool->hubbub->funcs->program_det_segments)
1960 dc->res_pool->hubbub->funcs->program_det_segments(
1961 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->hubp_regs.det_size);
1962 }
1963
1964 if (pipe_ctx->plane_state && (pipe_ctx->update_flags.raw ||
1965 pipe_ctx->plane_state->update_flags.raw ||
1966 pipe_ctx->stream->update_flags.raw))
1967 dcn20_update_dchubp_dpp(dc, pipe_ctx, context);
1968
1969 if (pipe_ctx->plane_state && (pipe_ctx->update_flags.bits.enable ||
1970 pipe_ctx->plane_state->update_flags.bits.hdr_mult))
1971 hws->funcs.set_hdr_multiplier(pipe_ctx);
1972
1973 if (pipe_ctx->plane_state &&
1974 (pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
1975 pipe_ctx->plane_state->update_flags.bits.gamma_change ||
1976 pipe_ctx->plane_state->update_flags.bits.lut_3d ||
1977 pipe_ctx->update_flags.bits.enable))
1978 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
1979
1980 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
1981 * only do gamma programming for powering on, internal memcmp to avoid
1982 * updating on slave planes
1983 */
1984 if (pipe_ctx->update_flags.bits.enable ||
1985 pipe_ctx->update_flags.bits.plane_changed ||
1986 pipe_ctx->stream->update_flags.bits.out_tf ||
1987 (pipe_ctx->plane_state &&
1988 pipe_ctx->plane_state->update_flags.bits.output_tf_change))
1989 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
1990
1991 /* If the pipe has been enabled or has a different opp, we
1992 * should reprogram the fmt. This deals with cases where
1993 * interation between mpc and odm combine on different streams
1994 * causes a different pipe to be chosen to odm combine with.
1995 */
1996 if (pipe_ctx->update_flags.bits.enable
1997 || pipe_ctx->update_flags.bits.opp_changed) {
1998
1999 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
2000 pipe_ctx->stream_res.opp,
2001 COLOR_SPACE_YCBCR601,
2002 pipe_ctx->stream->timing.display_color_depth,
2003 pipe_ctx->stream->signal);
2004
2005 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
2006 pipe_ctx->stream_res.opp,
2007 &pipe_ctx->stream->bit_depth_params,
2008 &pipe_ctx->stream->clamping);
2009 }
2010
2011 /* Set ABM pipe after other pipe configurations done */
2012 if ((pipe_ctx->plane_state && pipe_ctx->plane_state->visible)) {
2013 if (pipe_ctx->stream_res.abm) {
2014 dc->hwss.set_pipe(pipe_ctx);
2015 pipe_ctx->stream_res.abm->funcs->set_abm_level(pipe_ctx->stream_res.abm,
2016 pipe_ctx->stream->abm_level);
2017 }
2018 }
2019
2020 if (pipe_ctx->update_flags.bits.test_pattern_changed) {
2021 struct output_pixel_processor *odm_opp = pipe_ctx->stream_res.opp;
2022 struct bit_depth_reduction_params params;
2023
2024 memset(¶ms, 0, sizeof(params));
2025 odm_opp->funcs->opp_program_bit_depth_reduction(odm_opp, ¶ms);
2026 dc->hwss.set_disp_pattern_generator(dc,
2027 pipe_ctx,
2028 pipe_ctx->stream_res.test_pattern_params.test_pattern,
2029 pipe_ctx->stream_res.test_pattern_params.color_space,
2030 pipe_ctx->stream_res.test_pattern_params.color_depth,
2031 NULL,
2032 pipe_ctx->stream_res.test_pattern_params.width,
2033 pipe_ctx->stream_res.test_pattern_params.height,
2034 pipe_ctx->stream_res.test_pattern_params.offset);
2035 }
2036 }
2037
dcn20_program_front_end_for_ctx(struct dc * dc,struct dc_state * context)2038 void dcn20_program_front_end_for_ctx(
2039 struct dc *dc,
2040 struct dc_state *context)
2041 {
2042 int i;
2043 unsigned int prev_hubp_count = 0;
2044 unsigned int hubp_count = 0;
2045 struct dce_hwseq *hws = dc->hwseq;
2046 struct pipe_ctx *pipe = NULL;
2047
2048 DC_LOGGER_INIT(dc->ctx->logger);
2049
2050 if (resource_is_pipe_topology_changed(dc->current_state, context))
2051 resource_log_pipe_topology_update(dc, context);
2052
2053 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2054 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2055 pipe = &context->res_ctx.pipe_ctx[i];
2056
2057 if (pipe->plane_state) {
2058 ASSERT(!pipe->plane_state->triplebuffer_flips);
2059 /*turn off triple buffer for full update*/
2060 dc->hwss.program_triplebuffer(
2061 dc, pipe, pipe->plane_state->triplebuffer_flips);
2062 }
2063 }
2064 }
2065
2066 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2067 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
2068 prev_hubp_count++;
2069 if (context->res_ctx.pipe_ctx[i].plane_state)
2070 hubp_count++;
2071 }
2072
2073 if (prev_hubp_count == 0 && hubp_count > 0) {
2074 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2075 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2076 dc->res_pool->hubbub, true, false);
2077 udelay(500);
2078 }
2079
2080 /* Set pipe update flags and lock pipes */
2081 for (i = 0; i < dc->res_pool->pipe_count; i++)
2082 dcn20_detect_pipe_changes(dc->current_state, context, &dc->current_state->res_ctx.pipe_ctx[i],
2083 &context->res_ctx.pipe_ctx[i]);
2084
2085 /* When disabling phantom pipes, turn on phantom OTG first (so we can get double
2086 * buffer updates properly)
2087 */
2088 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2089 struct dc_stream_state *stream = dc->current_state->res_ctx.pipe_ctx[i].stream;
2090
2091 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2092
2093 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable && stream &&
2094 dc_state_get_pipe_subvp_type(dc->current_state, pipe) == SUBVP_PHANTOM) {
2095 struct timing_generator *tg = dc->current_state->res_ctx.pipe_ctx[i].stream_res.tg;
2096
2097 if (tg->funcs->enable_crtc) {
2098 if (dc->hwseq->funcs.blank_pixel_data)
2099 dc->hwseq->funcs.blank_pixel_data(dc, pipe, true);
2100
2101 tg->funcs->enable_crtc(tg);
2102 }
2103 }
2104 }
2105 /* OTG blank before disabling all front ends */
2106 for (i = 0; i < dc->res_pool->pipe_count; i++)
2107 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2108 && !context->res_ctx.pipe_ctx[i].top_pipe
2109 && !context->res_ctx.pipe_ctx[i].prev_odm_pipe
2110 && context->res_ctx.pipe_ctx[i].stream)
2111 hws->funcs.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true);
2112
2113 /* Disconnect mpcc */
2114 for (i = 0; i < dc->res_pool->pipe_count; i++)
2115 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2116 || context->res_ctx.pipe_ctx[i].update_flags.bits.opp_changed) {
2117 struct hubbub *hubbub = dc->res_pool->hubbub;
2118
2119 /* Phantom pipe DET should be 0, but if a pipe in use is being transitioned to phantom
2120 * then we want to do the programming here (effectively it's being disabled). If we do
2121 * the programming later the DET won't be updated until the OTG for the phantom pipe is
2122 * turned on (i.e. in an MCLK switch) which can come in too late and cause issues with
2123 * DET allocation.
2124 */
2125 if ((context->res_ctx.pipe_ctx[i].update_flags.bits.disable ||
2126 (context->res_ctx.pipe_ctx[i].plane_state &&
2127 dc_state_get_pipe_subvp_type(context, &context->res_ctx.pipe_ctx[i])
2128 == SUBVP_PHANTOM))) {
2129 if (hubbub->funcs->program_det_size)
2130 hubbub->funcs->program_det_size(hubbub,
2131 dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2132 if (dc->res_pool->hubbub->funcs->program_det_segments)
2133 dc->res_pool->hubbub->funcs->program_det_segments(
2134 hubbub, dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2135 }
2136 hws->funcs.plane_atomic_disconnect(dc, dc->current_state,
2137 &dc->current_state->res_ctx.pipe_ctx[i]);
2138 DC_LOG_DC("Reset mpcc for pipe %d\n", dc->current_state->res_ctx.pipe_ctx[i].pipe_idx);
2139 }
2140
2141 /* update ODM for blanked OTG master pipes */
2142 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2143 pipe = &context->res_ctx.pipe_ctx[i];
2144 if (resource_is_pipe_type(pipe, OTG_MASTER) &&
2145 !resource_is_pipe_type(pipe, DPP_PIPE) &&
2146 pipe->update_flags.bits.odm &&
2147 hws->funcs.update_odm)
2148 hws->funcs.update_odm(dc, context, pipe);
2149 }
2150
2151 /*
2152 * Program all updated pipes, order matters for mpcc setup. Start with
2153 * top pipe and program all pipes that follow in order
2154 */
2155 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2156 pipe = &context->res_ctx.pipe_ctx[i];
2157
2158 if (pipe->plane_state && !pipe->top_pipe) {
2159 while (pipe) {
2160 if (hws->funcs.program_pipe)
2161 hws->funcs.program_pipe(dc, pipe, context);
2162 else {
2163 /* Don't program phantom pipes in the regular front end programming sequence.
2164 * There is an MPO transition case where a pipe being used by a video plane is
2165 * transitioned directly to be a phantom pipe when closing the MPO video.
2166 * However the phantom pipe will program a new HUBP_VTG_SEL (update takes place
2167 * right away) but the MPO still exists until the double buffered update of the
2168 * main pipe so we will get a frame of underflow if the phantom pipe is
2169 * programmed here.
2170 */
2171 if (pipe->stream &&
2172 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM)
2173 dcn20_program_pipe(dc, pipe, context);
2174 }
2175
2176 pipe = pipe->bottom_pipe;
2177 }
2178 }
2179
2180 /* Program secondary blending tree and writeback pipes */
2181 pipe = &context->res_ctx.pipe_ctx[i];
2182 if (!pipe->top_pipe && !pipe->prev_odm_pipe
2183 && pipe->stream && pipe->stream->num_wb_info > 0
2184 && (pipe->update_flags.raw || (pipe->plane_state && pipe->plane_state->update_flags.raw)
2185 || pipe->stream->update_flags.raw)
2186 && hws->funcs.program_all_writeback_pipes_in_tree)
2187 hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context);
2188
2189 /* Avoid underflow by check of pipe line read when adding 2nd plane. */
2190 if (hws->wa.wait_hubpret_read_start_during_mpo_transition &&
2191 !pipe->top_pipe &&
2192 pipe->stream &&
2193 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start &&
2194 dc->current_state->stream_status[0].plane_count == 1 &&
2195 context->stream_status[0].plane_count > 1) {
2196 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start(pipe->plane_res.hubp);
2197 }
2198 }
2199 }
2200
2201 /* post_unlock_reset_opp - the function wait for corresponding double
2202 * buffered pending status clear and reset opp head pipe's none double buffered
2203 * registers to their initial state.
2204 */
dcn20_post_unlock_reset_opp(struct dc * dc,struct pipe_ctx * opp_head)2205 void dcn20_post_unlock_reset_opp(struct dc *dc,
2206 struct pipe_ctx *opp_head)
2207 {
2208 struct display_stream_compressor *dsc = opp_head->stream_res.dsc;
2209 struct dccg *dccg = dc->res_pool->dccg;
2210
2211 /*
2212 * wait for all DPP pipes in current mpc blending tree completes double
2213 * buffered disconnection before resetting OPP
2214 */
2215 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, opp_head);
2216
2217 if (dsc) {
2218 bool is_dsc_ungated = false;
2219
2220 if (dc->hwseq->funcs.dsc_pg_status)
2221 is_dsc_ungated = dc->hwseq->funcs.dsc_pg_status(dc->hwseq, dsc->inst);
2222
2223 if (is_dsc_ungated) {
2224 /*
2225 * seamless update specific where we will postpone non
2226 * double buffered DSCCLK disable logic in post unlock
2227 * sequence after DSC is disconnected from OPP but not
2228 * yet power gated.
2229 */
2230 dsc->funcs->dsc_wait_disconnect_pending_clear(dsc);
2231 dsc->funcs->dsc_disable(dsc);
2232 if (dccg->funcs->set_ref_dscclk)
2233 dccg->funcs->set_ref_dscclk(dccg, dsc->inst);
2234 }
2235 }
2236 }
2237
dcn20_post_unlock_program_front_end(struct dc * dc,struct dc_state * context)2238 void dcn20_post_unlock_program_front_end(
2239 struct dc *dc,
2240 struct dc_state *context)
2241 {
2242 // Timeout for pipe enable
2243 unsigned int timeout_us = 100000;
2244 unsigned int polling_interval_us = 1;
2245 struct dce_hwseq *hwseq = dc->hwseq;
2246 int i;
2247
2248 for (i = 0; i < dc->res_pool->pipe_count; i++)
2249 if (resource_is_pipe_type(&dc->current_state->res_ctx.pipe_ctx[i], OPP_HEAD) &&
2250 !resource_is_pipe_type(&context->res_ctx.pipe_ctx[i], OPP_HEAD))
2251 dcn20_post_unlock_reset_opp(dc,
2252 &dc->current_state->res_ctx.pipe_ctx[i]);
2253
2254 for (i = 0; i < dc->res_pool->pipe_count; i++)
2255 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable)
2256 dc->hwss.disable_plane(dc, dc->current_state, &dc->current_state->res_ctx.pipe_ctx[i]);
2257
2258 /*
2259 * If we are enabling a pipe, we need to wait for pending clear as this is a critical
2260 * part of the enable operation otherwise, DM may request an immediate flip which
2261 * will cause HW to perform an "immediate enable" (as opposed to "vsync enable") which
2262 * is unsupported on DCN.
2263 */
2264 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2265 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2266 // Don't check flip pending on phantom pipes
2267 if (pipe->plane_state && !pipe->top_pipe && pipe->update_flags.bits.enable &&
2268 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2269 struct hubp *hubp = pipe->plane_res.hubp;
2270 int j = 0;
2271
2272 for (j = 0; j < timeout_us / polling_interval_us
2273 && hubp->funcs->hubp_is_flip_pending(hubp); j++)
2274 udelay(polling_interval_us);
2275 }
2276 }
2277
2278 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2279 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2280 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2281
2282 /* When going from a smaller ODM slice count to larger, we must ensure double
2283 * buffer update completes before we return to ensure we don't reduce DISPCLK
2284 * before we've transitioned to 2:1 or 4:1
2285 */
2286 if (resource_is_pipe_type(old_pipe, OTG_MASTER) && resource_is_pipe_type(pipe, OTG_MASTER) &&
2287 resource_get_odm_slice_count(old_pipe) < resource_get_odm_slice_count(pipe) &&
2288 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2289 int j = 0;
2290 struct timing_generator *tg = pipe->stream_res.tg;
2291
2292 if (tg->funcs->get_optc_double_buffer_pending) {
2293 for (j = 0; j < timeout_us / polling_interval_us
2294 && tg->funcs->get_optc_double_buffer_pending(tg); j++)
2295 udelay(polling_interval_us);
2296 }
2297 }
2298 }
2299
2300 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2301 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2302 dc->res_pool->hubbub, false, false);
2303
2304 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2305 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2306
2307 if (pipe->plane_state && !pipe->top_pipe) {
2308 /* Program phantom pipe here to prevent a frame of underflow in the MPO transition
2309 * case (if a pipe being used for a video plane transitions to a phantom pipe, it
2310 * can underflow due to HUBP_VTG_SEL programming if done in the regular front end
2311 * programming sequence).
2312 */
2313 while (pipe) {
2314 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
2315 /* When turning on the phantom pipe we want to run through the
2316 * entire enable sequence, so apply all the "enable" flags.
2317 */
2318 if (dc->hwss.apply_update_flags_for_phantom)
2319 dc->hwss.apply_update_flags_for_phantom(pipe);
2320 if (dc->hwss.update_phantom_vp_position)
2321 dc->hwss.update_phantom_vp_position(dc, context, pipe);
2322 dcn20_program_pipe(dc, pipe, context);
2323 }
2324 pipe = pipe->bottom_pipe;
2325 }
2326 }
2327 }
2328
2329 if (!hwseq)
2330 return;
2331
2332 /* P-State support transitions:
2333 * Natural -> FPO: P-State disabled in prepare, force disallow anytime is safe
2334 * FPO -> Natural: Unforce anytime after FW disable is safe (P-State will assert naturally)
2335 * Unsupported -> FPO: P-State enabled in optimize, force disallow anytime is safe
2336 * FPO -> Unsupported: P-State disabled in prepare, unforce disallow anytime is safe
2337 * FPO <-> SubVP: Force disallow is maintained on the FPO / SubVP pipes
2338 */
2339 if (hwseq->funcs.update_force_pstate)
2340 dc->hwseq->funcs.update_force_pstate(dc, context);
2341
2342 /* Only program the MALL registers after all the main and phantom pipes
2343 * are done programming.
2344 */
2345 if (hwseq->funcs.program_mall_pipe_config)
2346 hwseq->funcs.program_mall_pipe_config(dc, context);
2347
2348 /* WA to apply WM setting*/
2349 if (hwseq->wa.DEGVIDCN21)
2350 dc->res_pool->hubbub->funcs->apply_DEDCN21_147_wa(dc->res_pool->hubbub);
2351
2352 /* WA for stutter underflow during MPO transitions when adding 2nd plane */
2353 if (hwseq->wa.disallow_self_refresh_during_multi_plane_transition) {
2354
2355 if (dc->current_state->stream_status[0].plane_count == 1 &&
2356 context->stream_status[0].plane_count > 1) {
2357
2358 struct timing_generator *tg = dc->res_pool->timing_generators[0];
2359
2360 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub, false);
2361
2362 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied = true;
2363 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied_on_frame = tg->funcs->get_frame_count(tg);
2364 }
2365 }
2366 }
2367
dcn20_prepare_bandwidth(struct dc * dc,struct dc_state * context)2368 void dcn20_prepare_bandwidth(
2369 struct dc *dc,
2370 struct dc_state *context)
2371 {
2372 struct hubbub *hubbub = dc->res_pool->hubbub;
2373 unsigned int compbuf_size_kb = 0;
2374 unsigned int cache_wm_a = context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns;
2375 unsigned int i;
2376
2377 dc->clk_mgr->funcs->update_clocks(
2378 dc->clk_mgr,
2379 context,
2380 false);
2381
2382 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2383 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2384
2385 // At optimize don't restore the original watermark value
2386 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_NONE) {
2387 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2388 break;
2389 }
2390 }
2391
2392 /* program dchubbub watermarks:
2393 * For assigning wm_optimized_required, use |= operator since we don't want
2394 * to clear the value if the optimize has not happened yet
2395 */
2396 dc->wm_optimized_required |= hubbub->funcs->program_watermarks(hubbub,
2397 &context->bw_ctx.bw.dcn.watermarks,
2398 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
2399 false);
2400
2401 // Restore the real watermark so we can commit the value to DMCUB
2402 // DMCUB uses the "original" watermark value in SubVP MCLK switch
2403 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = cache_wm_a;
2404
2405 /* decrease compbuf size */
2406 if (hubbub->funcs->program_compbuf_size) {
2407 if (context->bw_ctx.dml.ip.min_comp_buffer_size_kbytes) {
2408 compbuf_size_kb = context->bw_ctx.dml.ip.min_comp_buffer_size_kbytes;
2409 dc->wm_optimized_required |= (compbuf_size_kb != dc->current_state->bw_ctx.dml.ip.min_comp_buffer_size_kbytes);
2410 } else {
2411 compbuf_size_kb = context->bw_ctx.bw.dcn.compbuf_size_kb;
2412 dc->wm_optimized_required |= (compbuf_size_kb != dc->current_state->bw_ctx.bw.dcn.compbuf_size_kb);
2413 }
2414
2415 hubbub->funcs->program_compbuf_size(hubbub, compbuf_size_kb, false);
2416 }
2417 }
2418
dcn20_optimize_bandwidth(struct dc * dc,struct dc_state * context)2419 void dcn20_optimize_bandwidth(
2420 struct dc *dc,
2421 struct dc_state *context)
2422 {
2423 struct hubbub *hubbub = dc->res_pool->hubbub;
2424 int i;
2425
2426 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2427 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2428
2429 // At optimize don't need to restore the original watermark value
2430 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_NONE) {
2431 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2432 break;
2433 }
2434 }
2435
2436 /* program dchubbub watermarks */
2437 hubbub->funcs->program_watermarks(hubbub,
2438 &context->bw_ctx.bw.dcn.watermarks,
2439 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
2440 true);
2441
2442 if (dc->clk_mgr->dc_mode_softmax_enabled)
2443 if (dc->clk_mgr->clks.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 &&
2444 context->bw_ctx.bw.dcn.clk.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000)
2445 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->dc_mode_softmax_memclk);
2446
2447 /* increase compbuf size */
2448 if (hubbub->funcs->program_compbuf_size)
2449 hubbub->funcs->program_compbuf_size(hubbub, context->bw_ctx.bw.dcn.compbuf_size_kb, true);
2450
2451 if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching) {
2452 dc_dmub_srv_p_state_delegate(dc,
2453 true, context);
2454 context->bw_ctx.bw.dcn.clk.p_state_change_support = true;
2455 dc->clk_mgr->clks.fw_based_mclk_switching = true;
2456 } else {
2457 dc->clk_mgr->clks.fw_based_mclk_switching = false;
2458 }
2459
2460 dc->clk_mgr->funcs->update_clocks(
2461 dc->clk_mgr,
2462 context,
2463 true);
2464 if (context->bw_ctx.bw.dcn.clk.zstate_support == DCN_ZSTATE_SUPPORT_ALLOW &&
2465 !dc->debug.disable_extblankadj) {
2466 for (i = 0; i < dc->res_pool->pipe_count; ++i) {
2467 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2468
2469 if (pipe_ctx->stream && pipe_ctx->plane_res.hubp->funcs->program_extended_blank
2470 && pipe_ctx->stream->adjust.v_total_min == pipe_ctx->stream->adjust.v_total_max
2471 && pipe_ctx->stream->adjust.v_total_max > pipe_ctx->stream->timing.v_total)
2472 pipe_ctx->plane_res.hubp->funcs->program_extended_blank(pipe_ctx->plane_res.hubp,
2473 pipe_ctx->dlg_regs.min_dst_y_next_start);
2474 }
2475 }
2476 }
2477
dcn20_update_bandwidth(struct dc * dc,struct dc_state * context)2478 bool dcn20_update_bandwidth(
2479 struct dc *dc,
2480 struct dc_state *context)
2481 {
2482 int i;
2483 struct dce_hwseq *hws = dc->hwseq;
2484
2485 /* recalculate DML parameters */
2486 if (dc->res_pool->funcs->validate_bandwidth(dc, context, DC_VALIDATE_MODE_AND_PROGRAMMING) != DC_OK)
2487 return false;
2488
2489 /* apply updated bandwidth parameters */
2490 dc->hwss.prepare_bandwidth(dc, context);
2491
2492 /* update hubp configs for all pipes */
2493 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2494 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2495
2496 if (pipe_ctx->plane_state == NULL)
2497 continue;
2498
2499 if (pipe_ctx->top_pipe == NULL) {
2500 bool blank = !is_pipe_tree_visible(pipe_ctx);
2501
2502 pipe_ctx->stream_res.tg->funcs->program_global_sync(
2503 pipe_ctx->stream_res.tg,
2504 dcn20_calculate_vready_offset_for_group(pipe_ctx),
2505 pipe_ctx->pipe_dlg_param.vstartup_start,
2506 pipe_ctx->pipe_dlg_param.vupdate_offset,
2507 pipe_ctx->pipe_dlg_param.vupdate_width,
2508 pipe_ctx->pipe_dlg_param.pstate_keepout);
2509
2510 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
2511 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, false);
2512
2513 if (pipe_ctx->prev_odm_pipe == NULL)
2514 hws->funcs.blank_pixel_data(dc, pipe_ctx, blank);
2515
2516 if (hws->funcs.setup_vupdate_interrupt)
2517 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
2518 }
2519
2520 pipe_ctx->plane_res.hubp->funcs->hubp_setup(
2521 pipe_ctx->plane_res.hubp,
2522 &pipe_ctx->dlg_regs,
2523 &pipe_ctx->ttu_regs,
2524 &pipe_ctx->rq_regs,
2525 &pipe_ctx->pipe_dlg_param);
2526 }
2527
2528 return true;
2529 }
2530
dcn20_enable_writeback(struct dc * dc,struct dc_writeback_info * wb_info,struct dc_state * context)2531 void dcn20_enable_writeback(
2532 struct dc *dc,
2533 struct dc_writeback_info *wb_info,
2534 struct dc_state *context)
2535 {
2536 struct dwbc *dwb;
2537 struct mcif_wb *mcif_wb;
2538 struct timing_generator *optc;
2539
2540 ASSERT(wb_info->dwb_pipe_inst < MAX_DWB_PIPES);
2541 ASSERT(wb_info->wb_enabled);
2542 dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst];
2543 mcif_wb = dc->res_pool->mcif_wb[wb_info->dwb_pipe_inst];
2544
2545 /* set the OPTC source mux */
2546 optc = dc->res_pool->timing_generators[dwb->otg_inst];
2547 optc->funcs->set_dwb_source(optc, wb_info->dwb_pipe_inst);
2548 /* set MCIF_WB buffer and arbitration configuration */
2549 mcif_wb->funcs->config_mcif_buf(mcif_wb, &wb_info->mcif_buf_params, wb_info->dwb_params.dest_height);
2550 mcif_wb->funcs->config_mcif_arb(mcif_wb, &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[wb_info->dwb_pipe_inst]);
2551 /* Enable MCIF_WB */
2552 mcif_wb->funcs->enable_mcif(mcif_wb);
2553 /* Enable DWB */
2554 dwb->funcs->enable(dwb, &wb_info->dwb_params);
2555 /* TODO: add sequence to enable/disable warmup */
2556 }
2557
dcn20_disable_writeback(struct dc * dc,unsigned int dwb_pipe_inst)2558 void dcn20_disable_writeback(
2559 struct dc *dc,
2560 unsigned int dwb_pipe_inst)
2561 {
2562 struct dwbc *dwb;
2563 struct mcif_wb *mcif_wb;
2564
2565 ASSERT(dwb_pipe_inst < MAX_DWB_PIPES);
2566 dwb = dc->res_pool->dwbc[dwb_pipe_inst];
2567 mcif_wb = dc->res_pool->mcif_wb[dwb_pipe_inst];
2568
2569 dwb->funcs->disable(dwb);
2570 mcif_wb->funcs->disable_mcif(mcif_wb);
2571 }
2572
dcn20_wait_for_blank_complete(struct output_pixel_processor * opp)2573 bool dcn20_wait_for_blank_complete(
2574 struct output_pixel_processor *opp)
2575 {
2576 int counter;
2577
2578 if (!opp)
2579 return false;
2580
2581 for (counter = 0; counter < 1000; counter++) {
2582 if (!opp->funcs->dpg_is_pending(opp))
2583 break;
2584
2585 udelay(100);
2586 }
2587
2588 if (counter == 1000) {
2589 dm_error("DC: failed to blank crtc!\n");
2590 return false;
2591 }
2592
2593 return opp->funcs->dpg_is_blanked(opp);
2594 }
2595
dcn20_dmdata_status_done(struct pipe_ctx * pipe_ctx)2596 bool dcn20_dmdata_status_done(struct pipe_ctx *pipe_ctx)
2597 {
2598 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2599
2600 if (!hubp)
2601 return false;
2602 return hubp->funcs->dmdata_status_done(hubp);
2603 }
2604
dcn20_disable_stream_gating(struct dc * dc,struct pipe_ctx * pipe_ctx)2605 void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
2606 {
2607 struct dce_hwseq *hws = dc->hwseq;
2608
2609 if (pipe_ctx->stream_res.dsc) {
2610 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2611
2612 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, true);
2613 while (odm_pipe) {
2614 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, true);
2615 odm_pipe = odm_pipe->next_odm_pipe;
2616 }
2617 }
2618 }
2619
dcn20_enable_stream_gating(struct dc * dc,struct pipe_ctx * pipe_ctx)2620 void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
2621 {
2622 struct dce_hwseq *hws = dc->hwseq;
2623
2624 if (pipe_ctx->stream_res.dsc) {
2625 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2626
2627 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, false);
2628 while (odm_pipe) {
2629 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, false);
2630 odm_pipe = odm_pipe->next_odm_pipe;
2631 }
2632 }
2633 }
2634
dcn20_set_dmdata_attributes(struct pipe_ctx * pipe_ctx)2635 void dcn20_set_dmdata_attributes(struct pipe_ctx *pipe_ctx)
2636 {
2637 struct dc_dmdata_attributes attr = { 0 };
2638 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2639
2640 attr.dmdata_mode = DMDATA_HW_MODE;
2641 attr.dmdata_size =
2642 dc_is_hdmi_signal(pipe_ctx->stream->signal) ? 32 : 36;
2643 attr.address.quad_part =
2644 pipe_ctx->stream->dmdata_address.quad_part;
2645 attr.dmdata_dl_delta = 0;
2646 attr.dmdata_qos_mode = 0;
2647 attr.dmdata_qos_level = 0;
2648 attr.dmdata_repeat = 1; /* always repeat */
2649 attr.dmdata_updated = 1;
2650 attr.dmdata_sw_data = NULL;
2651
2652 hubp->funcs->dmdata_set_attributes(hubp, &attr);
2653 }
2654
dcn20_init_vm_ctx(struct dce_hwseq * hws,struct dc * dc,struct dc_virtual_addr_space_config * va_config,int vmid)2655 void dcn20_init_vm_ctx(
2656 struct dce_hwseq *hws,
2657 struct dc *dc,
2658 struct dc_virtual_addr_space_config *va_config,
2659 int vmid)
2660 {
2661 struct dcn_hubbub_virt_addr_config config;
2662
2663 if (vmid == 0) {
2664 ASSERT(0); /* VMID cannot be 0 for vm context */
2665 return;
2666 }
2667
2668 config.page_table_start_addr = va_config->page_table_start_addr;
2669 config.page_table_end_addr = va_config->page_table_end_addr;
2670 config.page_table_block_size = va_config->page_table_block_size_in_bytes;
2671 config.page_table_depth = va_config->page_table_depth;
2672 config.page_table_base_addr = va_config->page_table_base_addr;
2673
2674 dc->res_pool->hubbub->funcs->init_vm_ctx(dc->res_pool->hubbub, &config, vmid);
2675 }
2676
dcn20_init_sys_ctx(struct dce_hwseq * hws,struct dc * dc,struct dc_phy_addr_space_config * pa_config)2677 int dcn20_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config)
2678 {
2679 struct dcn_hubbub_phys_addr_config config;
2680
2681 config.system_aperture.fb_top = pa_config->system_aperture.fb_top;
2682 config.system_aperture.fb_offset = pa_config->system_aperture.fb_offset;
2683 config.system_aperture.fb_base = pa_config->system_aperture.fb_base;
2684 config.system_aperture.agp_top = pa_config->system_aperture.agp_top;
2685 config.system_aperture.agp_bot = pa_config->system_aperture.agp_bot;
2686 config.system_aperture.agp_base = pa_config->system_aperture.agp_base;
2687 config.gart_config.page_table_start_addr = pa_config->gart_config.page_table_start_addr;
2688 config.gart_config.page_table_end_addr = pa_config->gart_config.page_table_end_addr;
2689 config.gart_config.page_table_base_addr = pa_config->gart_config.page_table_base_addr;
2690 config.page_table_default_page_addr = pa_config->page_table_default_page_addr;
2691
2692 return dc->res_pool->hubbub->funcs->init_dchub_sys_ctx(dc->res_pool->hubbub, &config);
2693 }
2694
patch_address_for_sbs_tb_stereo(struct pipe_ctx * pipe_ctx,PHYSICAL_ADDRESS_LOC * addr)2695 static bool patch_address_for_sbs_tb_stereo(
2696 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
2697 {
2698 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2699 bool sec_split = pipe_ctx->top_pipe &&
2700 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
2701 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2702 (pipe_ctx->stream->timing.timing_3d_format ==
2703 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2704 pipe_ctx->stream->timing.timing_3d_format ==
2705 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
2706 *addr = plane_state->address.grph_stereo.left_addr;
2707 plane_state->address.grph_stereo.left_addr =
2708 plane_state->address.grph_stereo.right_addr;
2709 return true;
2710 }
2711
2712 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
2713 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
2714 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
2715 plane_state->address.grph_stereo.right_addr =
2716 plane_state->address.grph_stereo.left_addr;
2717 plane_state->address.grph_stereo.right_meta_addr =
2718 plane_state->address.grph_stereo.left_meta_addr;
2719 }
2720 return false;
2721 }
2722
dcn20_update_plane_addr(const struct dc * dc,struct pipe_ctx * pipe_ctx)2723 void dcn20_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
2724 {
2725 bool addr_patched = false;
2726 PHYSICAL_ADDRESS_LOC addr;
2727 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2728
2729 if (plane_state == NULL)
2730 return;
2731
2732 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
2733
2734 // Call Helper to track VMID use
2735 vm_helper_mark_vmid_used(dc->vm_helper, plane_state->address.vmid, pipe_ctx->plane_res.hubp->inst);
2736
2737 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
2738 pipe_ctx->plane_res.hubp,
2739 &plane_state->address,
2740 plane_state->flip_immediate);
2741
2742 plane_state->status.requested_address = plane_state->address;
2743
2744 if (plane_state->flip_immediate)
2745 plane_state->status.current_address = plane_state->address;
2746
2747 if (addr_patched)
2748 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
2749 }
2750
dcn20_unblank_stream(struct pipe_ctx * pipe_ctx,struct dc_link_settings * link_settings)2751 void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx,
2752 struct dc_link_settings *link_settings)
2753 {
2754 struct encoder_unblank_param params = {0};
2755 struct dc_stream_state *stream = pipe_ctx->stream;
2756 struct dc_link *link = stream->link;
2757 struct dce_hwseq *hws = link->dc->hwseq;
2758 struct pipe_ctx *odm_pipe;
2759 bool is_two_pixels_per_container =
2760 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing);
2761
2762 params.opp_cnt = 1;
2763
2764 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
2765 params.opp_cnt++;
2766 }
2767 /* only 3 items below are used by unblank */
2768 params.timing = pipe_ctx->stream->timing;
2769
2770 params.link_settings.link_rate = link_settings->link_rate;
2771
2772 if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
2773 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
2774 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_unblank(
2775 pipe_ctx->stream_res.hpo_dp_stream_enc,
2776 pipe_ctx->stream_res.tg->inst);
2777 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
2778 if (is_two_pixels_per_container || params.opp_cnt > 1)
2779 params.timing.pix_clk_100hz /= 2;
2780 if (pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine)
2781 pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine(
2782 pipe_ctx->stream_res.stream_enc, params.opp_cnt > 1);
2783 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
2784 }
2785
2786 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
2787 hws->funcs.edp_backlight_control(link, true);
2788 }
2789 }
2790
dcn20_setup_vupdate_interrupt(struct dc * dc,struct pipe_ctx * pipe_ctx)2791 void dcn20_setup_vupdate_interrupt(struct dc *dc, struct pipe_ctx *pipe_ctx)
2792 {
2793 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2794 int start_line = dc->hwss.get_vupdate_offset_from_vsync(pipe_ctx);
2795
2796 if (start_line < 0)
2797 start_line = 0;
2798
2799 if (tg->funcs->setup_vertical_interrupt2)
2800 tg->funcs->setup_vertical_interrupt2(tg, start_line);
2801 }
2802
dcn20_reset_back_end_for_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)2803 void dcn20_reset_back_end_for_pipe(
2804 struct dc *dc,
2805 struct pipe_ctx *pipe_ctx,
2806 struct dc_state *context)
2807 {
2808 struct dc_link *link = pipe_ctx->stream->link;
2809 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
2810 struct dccg *dccg = dc->res_pool->dccg;
2811 struct dtbclk_dto_params dto_params = {0};
2812
2813 DC_LOGGER_INIT(dc->ctx->logger);
2814 if (pipe_ctx->stream_res.stream_enc == NULL) {
2815 pipe_ctx->stream = NULL;
2816 return;
2817 }
2818
2819 /* DPMS may already disable or */
2820 /* dpms_off status is incorrect due to fastboot
2821 * feature. When system resume from S4 with second
2822 * screen only, the dpms_off would be true but
2823 * VBIOS lit up eDP, so check link status too.
2824 */
2825 if (!pipe_ctx->stream->dpms_off || link->link_status.link_active)
2826 dc->link_srv->set_dpms_off(pipe_ctx);
2827 else if (pipe_ctx->stream_res.audio)
2828 dc->hwss.disable_audio_stream(pipe_ctx);
2829
2830 /* free acquired resources */
2831 if (pipe_ctx->stream_res.audio) {
2832 /*disable az_endpoint*/
2833 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2834
2835 /*free audio*/
2836 if (dc->caps.dynamic_audio == true) {
2837 /*we have to dynamic arbitrate the audio endpoints*/
2838 /*we free the resource, need reset is_audio_acquired*/
2839 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2840 pipe_ctx->stream_res.audio, false);
2841 pipe_ctx->stream_res.audio = NULL;
2842 }
2843 }
2844
2845 /* by upper caller loop, parent pipe: pipe0, will be reset last.
2846 * back end share by all pipes and will be disable only when disable
2847 * parent pipe.
2848 */
2849 if (pipe_ctx->top_pipe == NULL) {
2850
2851 dc->hwss.set_abm_immediate_disable(pipe_ctx);
2852
2853 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
2854
2855 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
2856 if (pipe_ctx->stream_res.tg->funcs->set_odm_bypass)
2857 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
2858 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
2859
2860 set_drr_and_clear_adjust_pending(pipe_ctx, pipe_ctx->stream, NULL);
2861 /* TODO - convert symclk_ref_cnts for otg to a bit map to solve
2862 * the case where the same symclk is shared across multiple otg
2863 * instances
2864 */
2865 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
2866 link->phy_state.symclk_ref_cnts.otg = 0;
2867 if (link->phy_state.symclk_state == SYMCLK_ON_TX_OFF) {
2868 link_hwss->disable_link_output(link,
2869 &pipe_ctx->link_res, pipe_ctx->stream->signal);
2870 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
2871 }
2872 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx) && dccg
2873 && dc->ctx->dce_version >= DCN_VERSION_3_5) {
2874 dto_params.otg_inst = pipe_ctx->stream_res.tg->inst;
2875 dto_params.timing = &pipe_ctx->stream->timing;
2876 if (dccg && dccg->funcs->set_dtbclk_dto)
2877 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
2878 }
2879 }
2880
2881 /*
2882 * In case of a dangling plane, setting this to NULL unconditionally
2883 * causes failures during reset hw ctx where, if stream is NULL,
2884 * it is expected that the pipe_ctx pointers to pipes and plane are NULL.
2885 */
2886 pipe_ctx->stream = NULL;
2887 pipe_ctx->top_pipe = NULL;
2888 pipe_ctx->bottom_pipe = NULL;
2889 pipe_ctx->next_odm_pipe = NULL;
2890 pipe_ctx->prev_odm_pipe = NULL;
2891 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
2892 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
2893 }
2894
dcn20_reset_hw_ctx_wrap(struct dc * dc,struct dc_state * context)2895 void dcn20_reset_hw_ctx_wrap(
2896 struct dc *dc,
2897 struct dc_state *context)
2898 {
2899 int i;
2900 struct dce_hwseq *hws = dc->hwseq;
2901
2902 /* Reset Back End*/
2903 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
2904 struct pipe_ctx *pipe_ctx_old =
2905 &dc->current_state->res_ctx.pipe_ctx[i];
2906 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2907
2908 if (!pipe_ctx_old->stream)
2909 continue;
2910
2911 if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe)
2912 continue;
2913
2914 if (!pipe_ctx->stream ||
2915 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2916 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2917
2918 dcn20_reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
2919 if (hws->funcs.enable_stream_gating)
2920 hws->funcs.enable_stream_gating(dc, pipe_ctx_old);
2921 if (old_clk)
2922 old_clk->funcs->cs_power_down(old_clk);
2923 }
2924 }
2925 }
2926
dcn20_update_mpcc(struct dc * dc,struct pipe_ctx * pipe_ctx)2927 void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
2928 {
2929 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2930 struct mpcc_blnd_cfg blnd_cfg = {0};
2931 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha;
2932 int mpcc_id;
2933 struct mpcc *new_mpcc;
2934 struct mpc *mpc = dc->res_pool->mpc;
2935 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
2936
2937 blnd_cfg.overlap_only = false;
2938 blnd_cfg.global_gain = 0xff;
2939
2940 if (per_pixel_alpha) {
2941 blnd_cfg.pre_multiplied_alpha = pipe_ctx->plane_state->pre_multiplied_alpha;
2942 if (pipe_ctx->plane_state->global_alpha) {
2943 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN;
2944 blnd_cfg.global_gain = pipe_ctx->plane_state->global_alpha_value;
2945 } else {
2946 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
2947 }
2948 } else {
2949 blnd_cfg.pre_multiplied_alpha = false;
2950 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
2951 }
2952
2953 if (pipe_ctx->plane_state->global_alpha)
2954 blnd_cfg.global_alpha = pipe_ctx->plane_state->global_alpha_value;
2955 else
2956 blnd_cfg.global_alpha = 0xff;
2957
2958 blnd_cfg.background_color_bpc = 4;
2959 blnd_cfg.bottom_gain_mode = 0;
2960 blnd_cfg.top_gain = 0x1f000;
2961 blnd_cfg.bottom_inside_gain = 0x1f000;
2962 blnd_cfg.bottom_outside_gain = 0x1f000;
2963
2964 if (pipe_ctx->plane_state->format
2965 == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA)
2966 blnd_cfg.pre_multiplied_alpha = false;
2967
2968 /*
2969 * TODO: remove hack
2970 * Note: currently there is a bug in init_hw such that
2971 * on resume from hibernate, BIOS sets up MPCC0, and
2972 * we do mpcc_remove but the mpcc cannot go to idle
2973 * after remove. This cause us to pick mpcc1 here,
2974 * which causes a pstate hang for yet unknown reason.
2975 */
2976 mpcc_id = hubp->inst;
2977
2978 /* If there is no full update, don't need to touch MPC tree*/
2979 if (!pipe_ctx->plane_state->update_flags.bits.full_update &&
2980 !pipe_ctx->update_flags.bits.mpcc) {
2981 mpc->funcs->update_blending(mpc, &blnd_cfg, mpcc_id);
2982 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, mpcc_id);
2983 return;
2984 }
2985
2986 /* check if this MPCC is already being used */
2987 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
2988 /* remove MPCC if being used */
2989 if (new_mpcc != NULL)
2990 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
2991 else
2992 if (dc->debug.sanity_checks)
2993 mpc->funcs->assert_mpcc_idle_before_connect(
2994 dc->res_pool->mpc, mpcc_id);
2995
2996 /* Call MPC to insert new plane */
2997 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
2998 mpc_tree_params,
2999 &blnd_cfg,
3000 NULL,
3001 NULL,
3002 hubp->inst,
3003 mpcc_id);
3004 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, mpcc_id);
3005
3006 ASSERT(new_mpcc != NULL);
3007 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
3008 hubp->mpcc_id = mpcc_id;
3009 }
3010
dcn20_enable_stream(struct pipe_ctx * pipe_ctx)3011 void dcn20_enable_stream(struct pipe_ctx *pipe_ctx)
3012 {
3013 enum dc_lane_count lane_count =
3014 pipe_ctx->stream->link->cur_link_settings.lane_count;
3015
3016 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
3017 struct dc_link *link = pipe_ctx->stream->link;
3018
3019 uint32_t active_total_with_borders;
3020 uint32_t early_control = 0;
3021 struct timing_generator *tg = pipe_ctx->stream_res.tg;
3022 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
3023 struct dc *dc = pipe_ctx->stream->ctx->dc;
3024 struct dtbclk_dto_params dto_params = {0};
3025 struct dccg *dccg = dc->res_pool->dccg;
3026 enum phyd32clk_clock_source phyd32clk;
3027 int dp_hpo_inst;
3028
3029 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
3030 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
3031
3032 if (!dc->config.unify_link_enc_assignment)
3033 link_enc = link_enc_cfg_get_link_enc(link);
3034
3035 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
3036 dto_params.otg_inst = tg->inst;
3037 dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10;
3038 dto_params.num_odm_segments = get_odm_segment_count(pipe_ctx);
3039 dto_params.timing = &pipe_ctx->stream->timing;
3040 dto_params.ref_dtbclk_khz = dc->clk_mgr->funcs->get_dtb_ref_clk_frequency(dc->clk_mgr);
3041 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
3042 dp_hpo_inst = pipe_ctx->stream_res.hpo_dp_stream_enc->inst;
3043 dccg->funcs->set_dpstreamclk(dccg, DTBCLK0, tg->inst, dp_hpo_inst);
3044
3045 phyd32clk = get_phyd32clk_src(link);
3046 if (link->cur_link_settings.link_rate == LINK_RATE_UNKNOWN) {
3047 dccg->funcs->disable_symclk32_se(dccg, dp_hpo_inst);
3048 } else {
3049 dccg->funcs->enable_symclk32_se(dccg, dp_hpo_inst, phyd32clk);
3050 }
3051 } else {
3052 if (dccg->funcs->enable_symclk_se)
3053 dccg->funcs->enable_symclk_se(dccg, stream_enc->stream_enc_inst,
3054 link_enc->transmitter - TRANSMITTER_UNIPHY_A);
3055 }
3056
3057 if (dc->res_pool->dccg->funcs->set_pixel_rate_div)
3058 dc->res_pool->dccg->funcs->set_pixel_rate_div(
3059 dc->res_pool->dccg,
3060 pipe_ctx->stream_res.tg->inst,
3061 pipe_ctx->pixel_rate_divider.div_factor1,
3062 pipe_ctx->pixel_rate_divider.div_factor2);
3063
3064 link_hwss->setup_stream_encoder(pipe_ctx);
3065
3066 if (pipe_ctx->plane_state && pipe_ctx->plane_state->flip_immediate != 1) {
3067 if (dc->hwss.program_dmdata_engine)
3068 dc->hwss.program_dmdata_engine(pipe_ctx);
3069 }
3070
3071 dc->hwss.update_info_frame(pipe_ctx);
3072
3073 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3074 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
3075
3076 /* enable early control to avoid corruption on DP monitor*/
3077 active_total_with_borders =
3078 timing->h_addressable
3079 + timing->h_border_left
3080 + timing->h_border_right;
3081
3082 if (lane_count != 0)
3083 early_control = active_total_with_borders % lane_count;
3084
3085 if (early_control == 0)
3086 early_control = lane_count;
3087
3088 tg->funcs->set_early_control(tg, early_control);
3089 }
3090
dcn20_program_dmdata_engine(struct pipe_ctx * pipe_ctx)3091 void dcn20_program_dmdata_engine(struct pipe_ctx *pipe_ctx)
3092 {
3093 struct dc_stream_state *stream = pipe_ctx->stream;
3094 struct hubp *hubp = pipe_ctx->plane_res.hubp;
3095 bool enable = false;
3096 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
3097 enum dynamic_metadata_mode mode = dc_is_dp_signal(stream->signal)
3098 ? dmdata_dp
3099 : dmdata_hdmi;
3100
3101 /* if using dynamic meta, don't set up generic infopackets */
3102 if (pipe_ctx->stream->dmdata_address.quad_part != 0) {
3103 pipe_ctx->stream_res.encoder_info_frame.hdrsmd.valid = false;
3104 enable = true;
3105 }
3106
3107 if (!hubp)
3108 return;
3109
3110 if (!stream_enc || !stream_enc->funcs->set_dynamic_metadata)
3111 return;
3112
3113 stream_enc->funcs->set_dynamic_metadata(stream_enc, enable,
3114 hubp->inst, mode);
3115 }
3116
dcn20_fpga_init_hw(struct dc * dc)3117 void dcn20_fpga_init_hw(struct dc *dc)
3118 {
3119 int i, j;
3120 struct dce_hwseq *hws = dc->hwseq;
3121 struct resource_pool *res_pool = dc->res_pool;
3122 struct dc_state *context = dc->current_state;
3123
3124 if (dc->clk_mgr && dc->clk_mgr->funcs->init_clocks)
3125 dc->clk_mgr->funcs->init_clocks(dc->clk_mgr);
3126
3127 // Initialize the dccg
3128 if (res_pool->dccg->funcs->dccg_init)
3129 res_pool->dccg->funcs->dccg_init(res_pool->dccg);
3130
3131 //Enable ability to power gate / don't force power on permanently
3132 hws->funcs.enable_power_gating_plane(hws, true);
3133
3134 // Specific to FPGA dccg and registers
3135 REG_WRITE(RBBMIF_TIMEOUT_DIS, 0xFFFFFFFF);
3136 REG_WRITE(RBBMIF_TIMEOUT_DIS_2, 0xFFFFFFFF);
3137
3138 hws->funcs.dccg_init(hws);
3139
3140 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, 2);
3141 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
3142 if (REG(REFCLK_CNTL))
3143 REG_WRITE(REFCLK_CNTL, 0);
3144 //
3145
3146
3147 /* Blank pixel data with OPP DPG */
3148 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3149 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3150
3151 if (tg->funcs->is_tg_enabled(tg))
3152 dcn20_init_blank(dc, tg);
3153 }
3154
3155 for (i = 0; i < res_pool->timing_generator_count; i++) {
3156 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3157
3158 if (tg->funcs->is_tg_enabled(tg))
3159 tg->funcs->lock(tg);
3160 }
3161
3162 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3163 struct dpp *dpp = res_pool->dpps[i];
3164
3165 dpp->funcs->dpp_reset(dpp);
3166 }
3167
3168 /* Reset all MPCC muxes */
3169 res_pool->mpc->funcs->mpc_init(res_pool->mpc);
3170
3171 /* initialize OPP mpc_tree parameter */
3172 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3173 res_pool->opps[i]->mpc_tree_params.opp_id = res_pool->opps[i]->inst;
3174 res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
3175 for (j = 0; j < MAX_PIPES; j++)
3176 res_pool->opps[i]->mpcc_disconnect_pending[j] = false;
3177 }
3178
3179 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3180 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3181 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3182 struct hubp *hubp = dc->res_pool->hubps[i];
3183 struct dpp *dpp = dc->res_pool->dpps[i];
3184
3185 pipe_ctx->stream_res.tg = tg;
3186 pipe_ctx->pipe_idx = i;
3187
3188 pipe_ctx->plane_res.hubp = hubp;
3189 pipe_ctx->plane_res.dpp = dpp;
3190 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
3191 hubp->mpcc_id = dpp->inst;
3192 hubp->opp_id = OPP_ID_INVALID;
3193 hubp->power_gated = false;
3194 pipe_ctx->stream_res.opp = NULL;
3195
3196 hubp->funcs->hubp_init(hubp);
3197
3198 //dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
3199 //dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
3200 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
3201 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
3202 /*to do*/
3203 hws->funcs.plane_atomic_disconnect(dc, context, pipe_ctx);
3204 }
3205
3206 /* initialize DWB pointer to MCIF_WB */
3207 for (i = 0; i < res_pool->res_cap->num_dwb; i++)
3208 res_pool->dwbc[i]->mcif = res_pool->mcif_wb[i];
3209
3210 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3211 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3212
3213 if (tg->funcs->is_tg_enabled(tg))
3214 tg->funcs->unlock(tg);
3215 }
3216
3217 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3218 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3219
3220 dc->hwss.disable_plane(dc, context, pipe_ctx);
3221
3222 pipe_ctx->stream_res.tg = NULL;
3223 pipe_ctx->plane_res.hubp = NULL;
3224 }
3225
3226 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3227 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3228
3229 tg->funcs->tg_init(tg);
3230 }
3231
3232 if (dc->res_pool->hubbub->funcs->init_crb)
3233 dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub);
3234 }
3235
dcn20_set_disp_pattern_generator(const struct dc * dc,struct pipe_ctx * pipe_ctx,enum controller_dp_test_pattern test_pattern,enum controller_dp_color_space color_space,enum dc_color_depth color_depth,const struct tg_color * solid_color,int width,int height,int offset)3236 void dcn20_set_disp_pattern_generator(const struct dc *dc,
3237 struct pipe_ctx *pipe_ctx,
3238 enum controller_dp_test_pattern test_pattern,
3239 enum controller_dp_color_space color_space,
3240 enum dc_color_depth color_depth,
3241 const struct tg_color *solid_color,
3242 int width, int height, int offset)
3243 {
3244 pipe_ctx->stream_res.opp->funcs->opp_set_disp_pattern_generator(pipe_ctx->stream_res.opp, test_pattern,
3245 color_space, color_depth, solid_color, width, height, offset);
3246 }
3247