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_service.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 udelay(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 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
1988
1989 /* If the pipe has been enabled or has a different opp, we
1990 * should reprogram the fmt. This deals with cases where
1991 * interation between mpc and odm combine on different streams
1992 * causes a different pipe to be chosen to odm combine with.
1993 */
1994 if (pipe_ctx->update_flags.bits.enable
1995 || pipe_ctx->update_flags.bits.opp_changed) {
1996
1997 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1998 pipe_ctx->stream_res.opp,
1999 COLOR_SPACE_YCBCR601,
2000 pipe_ctx->stream->timing.display_color_depth,
2001 pipe_ctx->stream->signal);
2002
2003 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
2004 pipe_ctx->stream_res.opp,
2005 &pipe_ctx->stream->bit_depth_params,
2006 &pipe_ctx->stream->clamping);
2007 }
2008
2009 /* Set ABM pipe after other pipe configurations done */
2010 if ((pipe_ctx->plane_state && pipe_ctx->plane_state->visible)) {
2011 if (pipe_ctx->stream_res.abm) {
2012 dc->hwss.set_pipe(pipe_ctx);
2013 pipe_ctx->stream_res.abm->funcs->set_abm_level(pipe_ctx->stream_res.abm,
2014 pipe_ctx->stream->abm_level);
2015 }
2016 }
2017
2018 if (pipe_ctx->update_flags.bits.test_pattern_changed) {
2019 struct output_pixel_processor *odm_opp = pipe_ctx->stream_res.opp;
2020 struct bit_depth_reduction_params params;
2021
2022 memset(¶ms, 0, sizeof(params));
2023 odm_opp->funcs->opp_program_bit_depth_reduction(odm_opp, ¶ms);
2024 dc->hwss.set_disp_pattern_generator(dc,
2025 pipe_ctx,
2026 pipe_ctx->stream_res.test_pattern_params.test_pattern,
2027 pipe_ctx->stream_res.test_pattern_params.color_space,
2028 pipe_ctx->stream_res.test_pattern_params.color_depth,
2029 NULL,
2030 pipe_ctx->stream_res.test_pattern_params.width,
2031 pipe_ctx->stream_res.test_pattern_params.height,
2032 pipe_ctx->stream_res.test_pattern_params.offset);
2033 }
2034 }
2035
dcn20_program_front_end_for_ctx(struct dc * dc,struct dc_state * context)2036 void dcn20_program_front_end_for_ctx(
2037 struct dc *dc,
2038 struct dc_state *context)
2039 {
2040 int i;
2041 unsigned int prev_hubp_count = 0;
2042 unsigned int hubp_count = 0;
2043 struct dce_hwseq *hws = dc->hwseq;
2044 struct pipe_ctx *pipe = NULL;
2045
2046 DC_LOGGER_INIT(dc->ctx->logger);
2047
2048 if (resource_is_pipe_topology_changed(dc->current_state, context))
2049 resource_log_pipe_topology_update(dc, context);
2050
2051 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2052 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2053 pipe = &context->res_ctx.pipe_ctx[i];
2054
2055 if (pipe->plane_state) {
2056 ASSERT(!pipe->plane_state->triplebuffer_flips);
2057 /*turn off triple buffer for full update*/
2058 dc->hwss.program_triplebuffer(
2059 dc, pipe, pipe->plane_state->triplebuffer_flips);
2060 }
2061 }
2062 }
2063
2064 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2065 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
2066 prev_hubp_count++;
2067 if (context->res_ctx.pipe_ctx[i].plane_state)
2068 hubp_count++;
2069 }
2070
2071 if (prev_hubp_count == 0 && hubp_count > 0) {
2072 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2073 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2074 dc->res_pool->hubbub, true, false);
2075 udelay(500);
2076 }
2077
2078 /* Set pipe update flags and lock pipes */
2079 for (i = 0; i < dc->res_pool->pipe_count; i++)
2080 dcn20_detect_pipe_changes(dc->current_state, context, &dc->current_state->res_ctx.pipe_ctx[i],
2081 &context->res_ctx.pipe_ctx[i]);
2082
2083 /* When disabling phantom pipes, turn on phantom OTG first (so we can get double
2084 * buffer updates properly)
2085 */
2086 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2087 struct dc_stream_state *stream = dc->current_state->res_ctx.pipe_ctx[i].stream;
2088
2089 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2090
2091 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable && stream &&
2092 dc_state_get_pipe_subvp_type(dc->current_state, pipe) == SUBVP_PHANTOM) {
2093 struct timing_generator *tg = dc->current_state->res_ctx.pipe_ctx[i].stream_res.tg;
2094
2095 if (tg->funcs->enable_crtc) {
2096 if (dc->hwseq->funcs.blank_pixel_data)
2097 dc->hwseq->funcs.blank_pixel_data(dc, pipe, true);
2098
2099 tg->funcs->enable_crtc(tg);
2100 }
2101 }
2102 }
2103 /* OTG blank before disabling all front ends */
2104 for (i = 0; i < dc->res_pool->pipe_count; i++)
2105 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2106 && !context->res_ctx.pipe_ctx[i].top_pipe
2107 && !context->res_ctx.pipe_ctx[i].prev_odm_pipe
2108 && context->res_ctx.pipe_ctx[i].stream)
2109 hws->funcs.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true);
2110
2111 /* Disconnect mpcc */
2112 for (i = 0; i < dc->res_pool->pipe_count; i++)
2113 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2114 || context->res_ctx.pipe_ctx[i].update_flags.bits.opp_changed) {
2115 struct hubbub *hubbub = dc->res_pool->hubbub;
2116
2117 /* Phantom pipe DET should be 0, but if a pipe in use is being transitioned to phantom
2118 * then we want to do the programming here (effectively it's being disabled). If we do
2119 * the programming later the DET won't be updated until the OTG for the phantom pipe is
2120 * turned on (i.e. in an MCLK switch) which can come in too late and cause issues with
2121 * DET allocation.
2122 */
2123 if ((context->res_ctx.pipe_ctx[i].update_flags.bits.disable ||
2124 (context->res_ctx.pipe_ctx[i].plane_state &&
2125 dc_state_get_pipe_subvp_type(context, &context->res_ctx.pipe_ctx[i])
2126 == SUBVP_PHANTOM))) {
2127 if (hubbub->funcs->program_det_size)
2128 hubbub->funcs->program_det_size(hubbub,
2129 dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2130 if (dc->res_pool->hubbub->funcs->program_det_segments)
2131 dc->res_pool->hubbub->funcs->program_det_segments(
2132 hubbub, dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2133 }
2134 hws->funcs.plane_atomic_disconnect(dc, dc->current_state,
2135 &dc->current_state->res_ctx.pipe_ctx[i]);
2136 DC_LOG_DC("Reset mpcc for pipe %d\n", dc->current_state->res_ctx.pipe_ctx[i].pipe_idx);
2137 }
2138
2139 /* update ODM for blanked OTG master pipes */
2140 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2141 pipe = &context->res_ctx.pipe_ctx[i];
2142 if (resource_is_pipe_type(pipe, OTG_MASTER) &&
2143 !resource_is_pipe_type(pipe, DPP_PIPE) &&
2144 pipe->update_flags.bits.odm &&
2145 hws->funcs.update_odm)
2146 hws->funcs.update_odm(dc, context, pipe);
2147 }
2148
2149 /*
2150 * Program all updated pipes, order matters for mpcc setup. Start with
2151 * top pipe and program all pipes that follow in order
2152 */
2153 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2154 pipe = &context->res_ctx.pipe_ctx[i];
2155
2156 if (pipe->plane_state && !pipe->top_pipe) {
2157 while (pipe) {
2158 if (hws->funcs.program_pipe)
2159 hws->funcs.program_pipe(dc, pipe, context);
2160 else {
2161 /* Don't program phantom pipes in the regular front end programming sequence.
2162 * There is an MPO transition case where a pipe being used by a video plane is
2163 * transitioned directly to be a phantom pipe when closing the MPO video.
2164 * However the phantom pipe will program a new HUBP_VTG_SEL (update takes place
2165 * right away) but the MPO still exists until the double buffered update of the
2166 * main pipe so we will get a frame of underflow if the phantom pipe is
2167 * programmed here.
2168 */
2169 if (pipe->stream &&
2170 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM)
2171 dcn20_program_pipe(dc, pipe, context);
2172 }
2173
2174 pipe = pipe->bottom_pipe;
2175 }
2176 }
2177
2178 /* Program secondary blending tree and writeback pipes */
2179 pipe = &context->res_ctx.pipe_ctx[i];
2180 if (!pipe->top_pipe && !pipe->prev_odm_pipe
2181 && pipe->stream && pipe->stream->num_wb_info > 0
2182 && (pipe->update_flags.raw || (pipe->plane_state && pipe->plane_state->update_flags.raw)
2183 || pipe->stream->update_flags.raw)
2184 && hws->funcs.program_all_writeback_pipes_in_tree)
2185 hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context);
2186
2187 /* Avoid underflow by check of pipe line read when adding 2nd plane. */
2188 if (hws->wa.wait_hubpret_read_start_during_mpo_transition &&
2189 !pipe->top_pipe &&
2190 pipe->stream &&
2191 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start &&
2192 dc->current_state->stream_status[0].plane_count == 1 &&
2193 context->stream_status[0].plane_count > 1) {
2194 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start(pipe->plane_res.hubp);
2195 }
2196 }
2197 }
2198
2199 /* post_unlock_reset_opp - the function wait for corresponding double
2200 * buffered pending status clear and reset opp head pipe's none double buffered
2201 * registers to their initial state.
2202 */
dcn20_post_unlock_reset_opp(struct dc * dc,struct pipe_ctx * opp_head)2203 void dcn20_post_unlock_reset_opp(struct dc *dc,
2204 struct pipe_ctx *opp_head)
2205 {
2206 struct display_stream_compressor *dsc = opp_head->stream_res.dsc;
2207 struct dccg *dccg = dc->res_pool->dccg;
2208
2209 /*
2210 * wait for all DPP pipes in current mpc blending tree completes double
2211 * buffered disconnection before resetting OPP
2212 */
2213 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, opp_head);
2214
2215 if (dsc) {
2216 bool is_dsc_ungated = false;
2217
2218 if (dc->hwseq->funcs.dsc_pg_status)
2219 is_dsc_ungated = dc->hwseq->funcs.dsc_pg_status(dc->hwseq, dsc->inst);
2220
2221 if (is_dsc_ungated) {
2222 /*
2223 * seamless update specific where we will postpone non
2224 * double buffered DSCCLK disable logic in post unlock
2225 * sequence after DSC is disconnected from OPP but not
2226 * yet power gated.
2227 */
2228 dsc->funcs->dsc_wait_disconnect_pending_clear(dsc);
2229 dsc->funcs->dsc_disable(dsc);
2230 if (dccg->funcs->set_ref_dscclk)
2231 dccg->funcs->set_ref_dscclk(dccg, dsc->inst);
2232 }
2233 }
2234 }
2235
dcn20_post_unlock_program_front_end(struct dc * dc,struct dc_state * context)2236 void dcn20_post_unlock_program_front_end(
2237 struct dc *dc,
2238 struct dc_state *context)
2239 {
2240 // Timeout for pipe enable
2241 unsigned int timeout_us = 100000;
2242 unsigned int polling_interval_us = 1;
2243 struct dce_hwseq *hwseq = dc->hwseq;
2244 int i;
2245
2246 for (i = 0; i < dc->res_pool->pipe_count; i++)
2247 if (resource_is_pipe_type(&dc->current_state->res_ctx.pipe_ctx[i], OPP_HEAD) &&
2248 !resource_is_pipe_type(&context->res_ctx.pipe_ctx[i], OPP_HEAD))
2249 dcn20_post_unlock_reset_opp(dc,
2250 &dc->current_state->res_ctx.pipe_ctx[i]);
2251
2252 for (i = 0; i < dc->res_pool->pipe_count; i++)
2253 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable)
2254 dc->hwss.disable_plane(dc, dc->current_state, &dc->current_state->res_ctx.pipe_ctx[i]);
2255
2256 /*
2257 * If we are enabling a pipe, we need to wait for pending clear as this is a critical
2258 * part of the enable operation otherwise, DM may request an immediate flip which
2259 * will cause HW to perform an "immediate enable" (as opposed to "vsync enable") which
2260 * is unsupported on DCN.
2261 */
2262 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2263 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2264 // Don't check flip pending on phantom pipes
2265 if (pipe->plane_state && !pipe->top_pipe && pipe->update_flags.bits.enable &&
2266 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2267 struct hubp *hubp = pipe->plane_res.hubp;
2268 int j = 0;
2269
2270 for (j = 0; j < timeout_us / polling_interval_us
2271 && hubp->funcs->hubp_is_flip_pending(hubp); j++)
2272 udelay(polling_interval_us);
2273 }
2274 }
2275
2276 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2277 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2278 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2279
2280 /* When going from a smaller ODM slice count to larger, we must ensure double
2281 * buffer update completes before we return to ensure we don't reduce DISPCLK
2282 * before we've transitioned to 2:1 or 4:1
2283 */
2284 if (resource_is_pipe_type(old_pipe, OTG_MASTER) && resource_is_pipe_type(pipe, OTG_MASTER) &&
2285 resource_get_odm_slice_count(old_pipe) < resource_get_odm_slice_count(pipe) &&
2286 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2287 int j = 0;
2288 struct timing_generator *tg = pipe->stream_res.tg;
2289
2290 if (tg->funcs->get_optc_double_buffer_pending) {
2291 for (j = 0; j < timeout_us / polling_interval_us
2292 && tg->funcs->get_optc_double_buffer_pending(tg); j++)
2293 udelay(polling_interval_us);
2294 }
2295 }
2296 }
2297
2298 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2299 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2300 dc->res_pool->hubbub, false, false);
2301
2302 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2303 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2304
2305 if (pipe->plane_state && !pipe->top_pipe) {
2306 /* Program phantom pipe here to prevent a frame of underflow in the MPO transition
2307 * case (if a pipe being used for a video plane transitions to a phantom pipe, it
2308 * can underflow due to HUBP_VTG_SEL programming if done in the regular front end
2309 * programming sequence).
2310 */
2311 while (pipe) {
2312 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
2313 /* When turning on the phantom pipe we want to run through the
2314 * entire enable sequence, so apply all the "enable" flags.
2315 */
2316 if (dc->hwss.apply_update_flags_for_phantom)
2317 dc->hwss.apply_update_flags_for_phantom(pipe);
2318 if (dc->hwss.update_phantom_vp_position)
2319 dc->hwss.update_phantom_vp_position(dc, context, pipe);
2320 dcn20_program_pipe(dc, pipe, context);
2321 }
2322 pipe = pipe->bottom_pipe;
2323 }
2324 }
2325 }
2326
2327 if (!hwseq)
2328 return;
2329
2330 /* P-State support transitions:
2331 * Natural -> FPO: P-State disabled in prepare, force disallow anytime is safe
2332 * FPO -> Natural: Unforce anytime after FW disable is safe (P-State will assert naturally)
2333 * Unsupported -> FPO: P-State enabled in optimize, force disallow anytime is safe
2334 * FPO -> Unsupported: P-State disabled in prepare, unforce disallow anytime is safe
2335 * FPO <-> SubVP: Force disallow is maintained on the FPO / SubVP pipes
2336 */
2337 if (hwseq->funcs.update_force_pstate)
2338 dc->hwseq->funcs.update_force_pstate(dc, context);
2339
2340 /* Only program the MALL registers after all the main and phantom pipes
2341 * are done programming.
2342 */
2343 if (hwseq->funcs.program_mall_pipe_config)
2344 hwseq->funcs.program_mall_pipe_config(dc, context);
2345
2346 /* WA to apply WM setting*/
2347 if (hwseq->wa.DEGVIDCN21)
2348 dc->res_pool->hubbub->funcs->apply_DEDCN21_147_wa(dc->res_pool->hubbub);
2349
2350 /* WA for stutter underflow during MPO transitions when adding 2nd plane */
2351 if (hwseq->wa.disallow_self_refresh_during_multi_plane_transition) {
2352
2353 if (dc->current_state->stream_status[0].plane_count == 1 &&
2354 context->stream_status[0].plane_count > 1) {
2355
2356 struct timing_generator *tg = dc->res_pool->timing_generators[0];
2357
2358 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub, false);
2359
2360 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied = true;
2361 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied_on_frame = tg->funcs->get_frame_count(tg);
2362 }
2363 }
2364 }
2365
dcn20_prepare_bandwidth(struct dc * dc,struct dc_state * context)2366 void dcn20_prepare_bandwidth(
2367 struct dc *dc,
2368 struct dc_state *context)
2369 {
2370 struct hubbub *hubbub = dc->res_pool->hubbub;
2371 unsigned int compbuf_size_kb = 0;
2372 unsigned int cache_wm_a = context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns;
2373 unsigned int i;
2374
2375 dc->clk_mgr->funcs->update_clocks(
2376 dc->clk_mgr,
2377 context,
2378 false);
2379
2380 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2381 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2382
2383 // At optimize don't restore the original watermark value
2384 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_NONE) {
2385 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2386 break;
2387 }
2388 }
2389
2390 /* program dchubbub watermarks:
2391 * For assigning optimized_required, use |= operator since we don't want
2392 * to clear the value if the optimize has not happened yet
2393 */
2394 dc->optimized_required |= hubbub->funcs->program_watermarks(hubbub,
2395 &context->bw_ctx.bw.dcn.watermarks,
2396 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
2397 false);
2398
2399 // Restore the real watermark so we can commit the value to DMCUB
2400 // DMCUB uses the "original" watermark value in SubVP MCLK switch
2401 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = cache_wm_a;
2402
2403 /* decrease compbuf size */
2404 if (hubbub->funcs->program_compbuf_size) {
2405 if (context->bw_ctx.dml.ip.min_comp_buffer_size_kbytes) {
2406 compbuf_size_kb = context->bw_ctx.dml.ip.min_comp_buffer_size_kbytes;
2407 dc->optimized_required |= (compbuf_size_kb != dc->current_state->bw_ctx.dml.ip.min_comp_buffer_size_kbytes);
2408 } else {
2409 compbuf_size_kb = context->bw_ctx.bw.dcn.compbuf_size_kb;
2410 dc->optimized_required |= (compbuf_size_kb != dc->current_state->bw_ctx.bw.dcn.compbuf_size_kb);
2411 }
2412
2413 hubbub->funcs->program_compbuf_size(hubbub, compbuf_size_kb, false);
2414 }
2415 }
2416
dcn20_optimize_bandwidth(struct dc * dc,struct dc_state * context)2417 void dcn20_optimize_bandwidth(
2418 struct dc *dc,
2419 struct dc_state *context)
2420 {
2421 struct hubbub *hubbub = dc->res_pool->hubbub;
2422 int i;
2423
2424 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2425 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2426
2427 // At optimize don't need to restore the original watermark value
2428 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_NONE) {
2429 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2430 break;
2431 }
2432 }
2433
2434 /* program dchubbub watermarks */
2435 hubbub->funcs->program_watermarks(hubbub,
2436 &context->bw_ctx.bw.dcn.watermarks,
2437 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
2438 true);
2439
2440 if (dc->clk_mgr->dc_mode_softmax_enabled)
2441 if (dc->clk_mgr->clks.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 &&
2442 context->bw_ctx.bw.dcn.clk.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000)
2443 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->dc_mode_softmax_memclk);
2444
2445 /* increase compbuf size */
2446 if (hubbub->funcs->program_compbuf_size)
2447 hubbub->funcs->program_compbuf_size(hubbub, context->bw_ctx.bw.dcn.compbuf_size_kb, true);
2448
2449 if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching) {
2450 dc_dmub_srv_p_state_delegate(dc,
2451 true, context);
2452 context->bw_ctx.bw.dcn.clk.p_state_change_support = true;
2453 dc->clk_mgr->clks.fw_based_mclk_switching = true;
2454 } else {
2455 dc->clk_mgr->clks.fw_based_mclk_switching = false;
2456 }
2457
2458 dc->clk_mgr->funcs->update_clocks(
2459 dc->clk_mgr,
2460 context,
2461 true);
2462 if (context->bw_ctx.bw.dcn.clk.zstate_support == DCN_ZSTATE_SUPPORT_ALLOW &&
2463 !dc->debug.disable_extblankadj) {
2464 for (i = 0; i < dc->res_pool->pipe_count; ++i) {
2465 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2466
2467 if (pipe_ctx->stream && pipe_ctx->plane_res.hubp->funcs->program_extended_blank
2468 && pipe_ctx->stream->adjust.v_total_min == pipe_ctx->stream->adjust.v_total_max
2469 && pipe_ctx->stream->adjust.v_total_max > pipe_ctx->stream->timing.v_total)
2470 pipe_ctx->plane_res.hubp->funcs->program_extended_blank(pipe_ctx->plane_res.hubp,
2471 pipe_ctx->dlg_regs.min_dst_y_next_start);
2472 }
2473 }
2474 }
2475
dcn20_update_bandwidth(struct dc * dc,struct dc_state * context)2476 bool dcn20_update_bandwidth(
2477 struct dc *dc,
2478 struct dc_state *context)
2479 {
2480 int i;
2481 struct dce_hwseq *hws = dc->hwseq;
2482
2483 /* recalculate DML parameters */
2484 if (dc->res_pool->funcs->validate_bandwidth(dc, context, DC_VALIDATE_MODE_AND_PROGRAMMING) != DC_OK)
2485 return false;
2486
2487 /* apply updated bandwidth parameters */
2488 dc->hwss.prepare_bandwidth(dc, context);
2489
2490 /* update hubp configs for all pipes */
2491 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2492 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2493
2494 if (pipe_ctx->plane_state == NULL)
2495 continue;
2496
2497 if (pipe_ctx->top_pipe == NULL) {
2498 bool blank = !is_pipe_tree_visible(pipe_ctx);
2499
2500 pipe_ctx->stream_res.tg->funcs->program_global_sync(
2501 pipe_ctx->stream_res.tg,
2502 dcn20_calculate_vready_offset_for_group(pipe_ctx),
2503 pipe_ctx->pipe_dlg_param.vstartup_start,
2504 pipe_ctx->pipe_dlg_param.vupdate_offset,
2505 pipe_ctx->pipe_dlg_param.vupdate_width,
2506 pipe_ctx->pipe_dlg_param.pstate_keepout);
2507
2508 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
2509 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, false);
2510
2511 if (pipe_ctx->prev_odm_pipe == NULL)
2512 hws->funcs.blank_pixel_data(dc, pipe_ctx, blank);
2513
2514 if (hws->funcs.setup_vupdate_interrupt)
2515 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
2516 }
2517
2518 pipe_ctx->plane_res.hubp->funcs->hubp_setup(
2519 pipe_ctx->plane_res.hubp,
2520 &pipe_ctx->dlg_regs,
2521 &pipe_ctx->ttu_regs,
2522 &pipe_ctx->rq_regs,
2523 &pipe_ctx->pipe_dlg_param);
2524 }
2525
2526 return true;
2527 }
2528
dcn20_enable_writeback(struct dc * dc,struct dc_writeback_info * wb_info,struct dc_state * context)2529 void dcn20_enable_writeback(
2530 struct dc *dc,
2531 struct dc_writeback_info *wb_info,
2532 struct dc_state *context)
2533 {
2534 struct dwbc *dwb;
2535 struct mcif_wb *mcif_wb;
2536 struct timing_generator *optc;
2537
2538 ASSERT(wb_info->dwb_pipe_inst < MAX_DWB_PIPES);
2539 ASSERT(wb_info->wb_enabled);
2540 dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst];
2541 mcif_wb = dc->res_pool->mcif_wb[wb_info->dwb_pipe_inst];
2542
2543 /* set the OPTC source mux */
2544 optc = dc->res_pool->timing_generators[dwb->otg_inst];
2545 optc->funcs->set_dwb_source(optc, wb_info->dwb_pipe_inst);
2546 /* set MCIF_WB buffer and arbitration configuration */
2547 mcif_wb->funcs->config_mcif_buf(mcif_wb, &wb_info->mcif_buf_params, wb_info->dwb_params.dest_height);
2548 mcif_wb->funcs->config_mcif_arb(mcif_wb, &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[wb_info->dwb_pipe_inst]);
2549 /* Enable MCIF_WB */
2550 mcif_wb->funcs->enable_mcif(mcif_wb);
2551 /* Enable DWB */
2552 dwb->funcs->enable(dwb, &wb_info->dwb_params);
2553 /* TODO: add sequence to enable/disable warmup */
2554 }
2555
dcn20_disable_writeback(struct dc * dc,unsigned int dwb_pipe_inst)2556 void dcn20_disable_writeback(
2557 struct dc *dc,
2558 unsigned int dwb_pipe_inst)
2559 {
2560 struct dwbc *dwb;
2561 struct mcif_wb *mcif_wb;
2562
2563 ASSERT(dwb_pipe_inst < MAX_DWB_PIPES);
2564 dwb = dc->res_pool->dwbc[dwb_pipe_inst];
2565 mcif_wb = dc->res_pool->mcif_wb[dwb_pipe_inst];
2566
2567 dwb->funcs->disable(dwb);
2568 mcif_wb->funcs->disable_mcif(mcif_wb);
2569 }
2570
dcn20_wait_for_blank_complete(struct output_pixel_processor * opp)2571 bool dcn20_wait_for_blank_complete(
2572 struct output_pixel_processor *opp)
2573 {
2574 int counter;
2575
2576 if (!opp)
2577 return false;
2578
2579 for (counter = 0; counter < 1000; counter++) {
2580 if (!opp->funcs->dpg_is_pending(opp))
2581 break;
2582
2583 udelay(100);
2584 }
2585
2586 if (counter == 1000) {
2587 dm_error("DC: failed to blank crtc!\n");
2588 return false;
2589 }
2590
2591 return opp->funcs->dpg_is_blanked(opp);
2592 }
2593
dcn20_dmdata_status_done(struct pipe_ctx * pipe_ctx)2594 bool dcn20_dmdata_status_done(struct pipe_ctx *pipe_ctx)
2595 {
2596 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2597
2598 if (!hubp)
2599 return false;
2600 return hubp->funcs->dmdata_status_done(hubp);
2601 }
2602
dcn20_disable_stream_gating(struct dc * dc,struct pipe_ctx * pipe_ctx)2603 void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
2604 {
2605 struct dce_hwseq *hws = dc->hwseq;
2606
2607 if (pipe_ctx->stream_res.dsc) {
2608 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2609
2610 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, true);
2611 while (odm_pipe) {
2612 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, true);
2613 odm_pipe = odm_pipe->next_odm_pipe;
2614 }
2615 }
2616 }
2617
dcn20_enable_stream_gating(struct dc * dc,struct pipe_ctx * pipe_ctx)2618 void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
2619 {
2620 struct dce_hwseq *hws = dc->hwseq;
2621
2622 if (pipe_ctx->stream_res.dsc) {
2623 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2624
2625 hws->funcs.dsc_pg_control(hws, pipe_ctx->stream_res.dsc->inst, false);
2626 while (odm_pipe) {
2627 hws->funcs.dsc_pg_control(hws, odm_pipe->stream_res.dsc->inst, false);
2628 odm_pipe = odm_pipe->next_odm_pipe;
2629 }
2630 }
2631 }
2632
dcn20_set_dmdata_attributes(struct pipe_ctx * pipe_ctx)2633 void dcn20_set_dmdata_attributes(struct pipe_ctx *pipe_ctx)
2634 {
2635 struct dc_dmdata_attributes attr = { 0 };
2636 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2637
2638 attr.dmdata_mode = DMDATA_HW_MODE;
2639 attr.dmdata_size =
2640 dc_is_hdmi_signal(pipe_ctx->stream->signal) ? 32 : 36;
2641 attr.address.quad_part =
2642 pipe_ctx->stream->dmdata_address.quad_part;
2643 attr.dmdata_dl_delta = 0;
2644 attr.dmdata_qos_mode = 0;
2645 attr.dmdata_qos_level = 0;
2646 attr.dmdata_repeat = 1; /* always repeat */
2647 attr.dmdata_updated = 1;
2648 attr.dmdata_sw_data = NULL;
2649
2650 hubp->funcs->dmdata_set_attributes(hubp, &attr);
2651 }
2652
dcn20_init_vm_ctx(struct dce_hwseq * hws,struct dc * dc,struct dc_virtual_addr_space_config * va_config,int vmid)2653 void dcn20_init_vm_ctx(
2654 struct dce_hwseq *hws,
2655 struct dc *dc,
2656 struct dc_virtual_addr_space_config *va_config,
2657 int vmid)
2658 {
2659 struct dcn_hubbub_virt_addr_config config;
2660
2661 if (vmid == 0) {
2662 ASSERT(0); /* VMID cannot be 0 for vm context */
2663 return;
2664 }
2665
2666 config.page_table_start_addr = va_config->page_table_start_addr;
2667 config.page_table_end_addr = va_config->page_table_end_addr;
2668 config.page_table_block_size = va_config->page_table_block_size_in_bytes;
2669 config.page_table_depth = va_config->page_table_depth;
2670 config.page_table_base_addr = va_config->page_table_base_addr;
2671
2672 dc->res_pool->hubbub->funcs->init_vm_ctx(dc->res_pool->hubbub, &config, vmid);
2673 }
2674
dcn20_init_sys_ctx(struct dce_hwseq * hws,struct dc * dc,struct dc_phy_addr_space_config * pa_config)2675 int dcn20_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config)
2676 {
2677 struct dcn_hubbub_phys_addr_config config;
2678
2679 config.system_aperture.fb_top = pa_config->system_aperture.fb_top;
2680 config.system_aperture.fb_offset = pa_config->system_aperture.fb_offset;
2681 config.system_aperture.fb_base = pa_config->system_aperture.fb_base;
2682 config.system_aperture.agp_top = pa_config->system_aperture.agp_top;
2683 config.system_aperture.agp_bot = pa_config->system_aperture.agp_bot;
2684 config.system_aperture.agp_base = pa_config->system_aperture.agp_base;
2685 config.gart_config.page_table_start_addr = pa_config->gart_config.page_table_start_addr;
2686 config.gart_config.page_table_end_addr = pa_config->gart_config.page_table_end_addr;
2687 config.gart_config.page_table_base_addr = pa_config->gart_config.page_table_base_addr;
2688 config.page_table_default_page_addr = pa_config->page_table_default_page_addr;
2689
2690 return dc->res_pool->hubbub->funcs->init_dchub_sys_ctx(dc->res_pool->hubbub, &config);
2691 }
2692
patch_address_for_sbs_tb_stereo(struct pipe_ctx * pipe_ctx,PHYSICAL_ADDRESS_LOC * addr)2693 static bool patch_address_for_sbs_tb_stereo(
2694 struct pipe_ctx *pipe_ctx, PHYSICAL_ADDRESS_LOC *addr)
2695 {
2696 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2697 bool sec_split = pipe_ctx->top_pipe &&
2698 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state;
2699 if (sec_split && plane_state->address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2700 (pipe_ctx->stream->timing.timing_3d_format ==
2701 TIMING_3D_FORMAT_SIDE_BY_SIDE ||
2702 pipe_ctx->stream->timing.timing_3d_format ==
2703 TIMING_3D_FORMAT_TOP_AND_BOTTOM)) {
2704 *addr = plane_state->address.grph_stereo.left_addr;
2705 plane_state->address.grph_stereo.left_addr =
2706 plane_state->address.grph_stereo.right_addr;
2707 return true;
2708 }
2709
2710 if (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_NONE &&
2711 plane_state->address.type != PLN_ADDR_TYPE_GRPH_STEREO) {
2712 plane_state->address.type = PLN_ADDR_TYPE_GRPH_STEREO;
2713 plane_state->address.grph_stereo.right_addr =
2714 plane_state->address.grph_stereo.left_addr;
2715 plane_state->address.grph_stereo.right_meta_addr =
2716 plane_state->address.grph_stereo.left_meta_addr;
2717 }
2718 return false;
2719 }
2720
dcn20_update_plane_addr(const struct dc * dc,struct pipe_ctx * pipe_ctx)2721 void dcn20_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
2722 {
2723 bool addr_patched = false;
2724 PHYSICAL_ADDRESS_LOC addr;
2725 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2726
2727 if (plane_state == NULL)
2728 return;
2729
2730 addr_patched = patch_address_for_sbs_tb_stereo(pipe_ctx, &addr);
2731
2732 // Call Helper to track VMID use
2733 vm_helper_mark_vmid_used(dc->vm_helper, plane_state->address.vmid, pipe_ctx->plane_res.hubp->inst);
2734
2735 pipe_ctx->plane_res.hubp->funcs->hubp_program_surface_flip_and_addr(
2736 pipe_ctx->plane_res.hubp,
2737 &plane_state->address,
2738 plane_state->flip_immediate);
2739
2740 plane_state->status.requested_address = plane_state->address;
2741
2742 if (plane_state->flip_immediate)
2743 plane_state->status.current_address = plane_state->address;
2744
2745 if (addr_patched)
2746 pipe_ctx->plane_state->address.grph_stereo.left_addr = addr;
2747 }
2748
dcn20_unblank_stream(struct pipe_ctx * pipe_ctx,struct dc_link_settings * link_settings)2749 void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx,
2750 struct dc_link_settings *link_settings)
2751 {
2752 struct encoder_unblank_param params = {0};
2753 struct dc_stream_state *stream = pipe_ctx->stream;
2754 struct dc_link *link = stream->link;
2755 struct dce_hwseq *hws = link->dc->hwseq;
2756 struct pipe_ctx *odm_pipe;
2757 bool is_two_pixels_per_container =
2758 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing);
2759
2760 params.opp_cnt = 1;
2761
2762 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
2763 params.opp_cnt++;
2764 }
2765 /* only 3 items below are used by unblank */
2766 params.timing = pipe_ctx->stream->timing;
2767
2768 params.link_settings.link_rate = link_settings->link_rate;
2769
2770 if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
2771 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
2772 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_unblank(
2773 pipe_ctx->stream_res.hpo_dp_stream_enc,
2774 pipe_ctx->stream_res.tg->inst);
2775 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
2776 if (is_two_pixels_per_container || params.opp_cnt > 1)
2777 params.timing.pix_clk_100hz /= 2;
2778 if (pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine)
2779 pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine(
2780 pipe_ctx->stream_res.stream_enc, params.opp_cnt > 1);
2781 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
2782 }
2783
2784 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
2785 hws->funcs.edp_backlight_control(link, true);
2786 }
2787 }
2788
dcn20_setup_vupdate_interrupt(struct dc * dc,struct pipe_ctx * pipe_ctx)2789 void dcn20_setup_vupdate_interrupt(struct dc *dc, struct pipe_ctx *pipe_ctx)
2790 {
2791 struct timing_generator *tg = pipe_ctx->stream_res.tg;
2792 int start_line = dc->hwss.get_vupdate_offset_from_vsync(pipe_ctx);
2793
2794 if (start_line < 0)
2795 start_line = 0;
2796
2797 if (tg->funcs->setup_vertical_interrupt2)
2798 tg->funcs->setup_vertical_interrupt2(tg, start_line);
2799 }
2800
dcn20_reset_back_end_for_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)2801 void dcn20_reset_back_end_for_pipe(
2802 struct dc *dc,
2803 struct pipe_ctx *pipe_ctx,
2804 struct dc_state *context)
2805 {
2806 struct dc_link *link = pipe_ctx->stream->link;
2807 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
2808 struct dccg *dccg = dc->res_pool->dccg;
2809 struct dtbclk_dto_params dto_params = {0};
2810
2811 DC_LOGGER_INIT(dc->ctx->logger);
2812 if (pipe_ctx->stream_res.stream_enc == NULL) {
2813 pipe_ctx->stream = NULL;
2814 return;
2815 }
2816
2817 /* DPMS may already disable or */
2818 /* dpms_off status is incorrect due to fastboot
2819 * feature. When system resume from S4 with second
2820 * screen only, the dpms_off would be true but
2821 * VBIOS lit up eDP, so check link status too.
2822 */
2823 if (!pipe_ctx->stream->dpms_off || link->link_status.link_active)
2824 dc->link_srv->set_dpms_off(pipe_ctx);
2825 else if (pipe_ctx->stream_res.audio)
2826 dc->hwss.disable_audio_stream(pipe_ctx);
2827
2828 /* free acquired resources */
2829 if (pipe_ctx->stream_res.audio) {
2830 /*disable az_endpoint*/
2831 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2832
2833 /*free audio*/
2834 if (dc->caps.dynamic_audio == true) {
2835 /*we have to dynamic arbitrate the audio endpoints*/
2836 /*we free the resource, need reset is_audio_acquired*/
2837 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2838 pipe_ctx->stream_res.audio, false);
2839 pipe_ctx->stream_res.audio = NULL;
2840 }
2841 }
2842
2843 /* by upper caller loop, parent pipe: pipe0, will be reset last.
2844 * back end share by all pipes and will be disable only when disable
2845 * parent pipe.
2846 */
2847 if (pipe_ctx->top_pipe == NULL) {
2848
2849 dc->hwss.set_abm_immediate_disable(pipe_ctx);
2850
2851 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
2852
2853 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
2854 if (pipe_ctx->stream_res.tg->funcs->set_odm_bypass)
2855 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
2856 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
2857
2858 set_drr_and_clear_adjust_pending(pipe_ctx, pipe_ctx->stream, NULL);
2859 /* TODO - convert symclk_ref_cnts for otg to a bit map to solve
2860 * the case where the same symclk is shared across multiple otg
2861 * instances
2862 */
2863 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
2864 link->phy_state.symclk_ref_cnts.otg = 0;
2865 if (link->phy_state.symclk_state == SYMCLK_ON_TX_OFF) {
2866 link_hwss->disable_link_output(link,
2867 &pipe_ctx->link_res, pipe_ctx->stream->signal);
2868 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
2869 }
2870 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx) && dccg
2871 && dc->ctx->dce_version >= DCN_VERSION_3_5) {
2872 dto_params.otg_inst = pipe_ctx->stream_res.tg->inst;
2873 dto_params.timing = &pipe_ctx->stream->timing;
2874 if (dccg && dccg->funcs->set_dtbclk_dto)
2875 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
2876 }
2877 }
2878
2879 /*
2880 * In case of a dangling plane, setting this to NULL unconditionally
2881 * causes failures during reset hw ctx where, if stream is NULL,
2882 * it is expected that the pipe_ctx pointers to pipes and plane are NULL.
2883 */
2884 pipe_ctx->stream = NULL;
2885 pipe_ctx->top_pipe = NULL;
2886 pipe_ctx->bottom_pipe = NULL;
2887 pipe_ctx->next_odm_pipe = NULL;
2888 pipe_ctx->prev_odm_pipe = NULL;
2889 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
2890 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
2891 }
2892
dcn20_reset_hw_ctx_wrap(struct dc * dc,struct dc_state * context)2893 void dcn20_reset_hw_ctx_wrap(
2894 struct dc *dc,
2895 struct dc_state *context)
2896 {
2897 int i;
2898 struct dce_hwseq *hws = dc->hwseq;
2899
2900 /* Reset Back End*/
2901 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
2902 struct pipe_ctx *pipe_ctx_old =
2903 &dc->current_state->res_ctx.pipe_ctx[i];
2904 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2905
2906 if (!pipe_ctx_old->stream)
2907 continue;
2908
2909 if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe)
2910 continue;
2911
2912 if (!pipe_ctx->stream ||
2913 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2914 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2915
2916 dcn20_reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
2917 if (hws->funcs.enable_stream_gating)
2918 hws->funcs.enable_stream_gating(dc, pipe_ctx_old);
2919 if (old_clk)
2920 old_clk->funcs->cs_power_down(old_clk);
2921 }
2922 }
2923 }
2924
dcn20_update_mpcc(struct dc * dc,struct pipe_ctx * pipe_ctx)2925 void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
2926 {
2927 struct hubp *hubp = pipe_ctx->plane_res.hubp;
2928 struct mpcc_blnd_cfg blnd_cfg = {0};
2929 bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha;
2930 int mpcc_id;
2931 struct mpcc *new_mpcc;
2932 struct mpc *mpc = dc->res_pool->mpc;
2933 struct mpc_tree *mpc_tree_params = &(pipe_ctx->stream_res.opp->mpc_tree_params);
2934
2935 blnd_cfg.overlap_only = false;
2936 blnd_cfg.global_gain = 0xff;
2937
2938 if (per_pixel_alpha) {
2939 blnd_cfg.pre_multiplied_alpha = pipe_ctx->plane_state->pre_multiplied_alpha;
2940 if (pipe_ctx->plane_state->global_alpha) {
2941 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN;
2942 blnd_cfg.global_gain = pipe_ctx->plane_state->global_alpha_value;
2943 } else {
2944 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA;
2945 }
2946 } else {
2947 blnd_cfg.pre_multiplied_alpha = false;
2948 blnd_cfg.alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA;
2949 }
2950
2951 if (pipe_ctx->plane_state->global_alpha)
2952 blnd_cfg.global_alpha = pipe_ctx->plane_state->global_alpha_value;
2953 else
2954 blnd_cfg.global_alpha = 0xff;
2955
2956 blnd_cfg.background_color_bpc = 4;
2957 blnd_cfg.bottom_gain_mode = 0;
2958 blnd_cfg.top_gain = 0x1f000;
2959 blnd_cfg.bottom_inside_gain = 0x1f000;
2960 blnd_cfg.bottom_outside_gain = 0x1f000;
2961
2962 if (pipe_ctx->plane_state->format
2963 == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA)
2964 blnd_cfg.pre_multiplied_alpha = false;
2965
2966 /*
2967 * TODO: remove hack
2968 * Note: currently there is a bug in init_hw such that
2969 * on resume from hibernate, BIOS sets up MPCC0, and
2970 * we do mpcc_remove but the mpcc cannot go to idle
2971 * after remove. This cause us to pick mpcc1 here,
2972 * which causes a pstate hang for yet unknown reason.
2973 */
2974 mpcc_id = hubp->inst;
2975
2976 /* If there is no full update, don't need to touch MPC tree*/
2977 if (!pipe_ctx->plane_state->update_flags.bits.full_update &&
2978 !pipe_ctx->update_flags.bits.mpcc) {
2979 mpc->funcs->update_blending(mpc, &blnd_cfg, mpcc_id);
2980 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, mpcc_id);
2981 return;
2982 }
2983
2984 /* check if this MPCC is already being used */
2985 new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
2986 /* remove MPCC if being used */
2987 if (new_mpcc != NULL)
2988 mpc->funcs->remove_mpcc(mpc, mpc_tree_params, new_mpcc);
2989 else
2990 if (dc->debug.sanity_checks)
2991 mpc->funcs->assert_mpcc_idle_before_connect(
2992 dc->res_pool->mpc, mpcc_id);
2993
2994 /* Call MPC to insert new plane */
2995 new_mpcc = mpc->funcs->insert_plane(dc->res_pool->mpc,
2996 mpc_tree_params,
2997 &blnd_cfg,
2998 NULL,
2999 NULL,
3000 hubp->inst,
3001 mpcc_id);
3002 dc->hwss.update_visual_confirm_color(dc, pipe_ctx, mpcc_id);
3003
3004 ASSERT(new_mpcc != NULL);
3005 hubp->opp_id = pipe_ctx->stream_res.opp->inst;
3006 hubp->mpcc_id = mpcc_id;
3007 }
3008
dcn20_enable_stream(struct pipe_ctx * pipe_ctx)3009 void dcn20_enable_stream(struct pipe_ctx *pipe_ctx)
3010 {
3011 enum dc_lane_count lane_count =
3012 pipe_ctx->stream->link->cur_link_settings.lane_count;
3013
3014 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
3015 struct dc_link *link = pipe_ctx->stream->link;
3016
3017 uint32_t active_total_with_borders;
3018 uint32_t early_control = 0;
3019 struct timing_generator *tg = pipe_ctx->stream_res.tg;
3020 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
3021 struct dc *dc = pipe_ctx->stream->ctx->dc;
3022 struct dtbclk_dto_params dto_params = {0};
3023 struct dccg *dccg = dc->res_pool->dccg;
3024 enum phyd32clk_clock_source phyd32clk;
3025 int dp_hpo_inst;
3026
3027 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
3028 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
3029
3030 if (!dc->config.unify_link_enc_assignment)
3031 link_enc = link_enc_cfg_get_link_enc(link);
3032
3033 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
3034 dto_params.otg_inst = tg->inst;
3035 dto_params.pixclk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10;
3036 dto_params.num_odm_segments = get_odm_segment_count(pipe_ctx);
3037 dto_params.timing = &pipe_ctx->stream->timing;
3038 dto_params.ref_dtbclk_khz = dc->clk_mgr->funcs->get_dtb_ref_clk_frequency(dc->clk_mgr);
3039 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
3040 dp_hpo_inst = pipe_ctx->stream_res.hpo_dp_stream_enc->inst;
3041 dccg->funcs->set_dpstreamclk(dccg, DTBCLK0, tg->inst, dp_hpo_inst);
3042
3043 phyd32clk = get_phyd32clk_src(link);
3044 if (link->cur_link_settings.link_rate == LINK_RATE_UNKNOWN) {
3045 dccg->funcs->disable_symclk32_se(dccg, dp_hpo_inst);
3046 } else {
3047 dccg->funcs->enable_symclk32_se(dccg, dp_hpo_inst, phyd32clk);
3048 }
3049 } else {
3050 if (dccg->funcs->enable_symclk_se)
3051 dccg->funcs->enable_symclk_se(dccg, stream_enc->stream_enc_inst,
3052 link_enc->transmitter - TRANSMITTER_UNIPHY_A);
3053 }
3054
3055 link_hwss->setup_stream_attribute(pipe_ctx);
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 if (hws->funcs.enable_power_gating_plane)
3133 hws->funcs.enable_power_gating_plane(hws, true);
3134
3135 // Specific to FPGA dccg and registers
3136 REG_WRITE(RBBMIF_TIMEOUT_DIS, 0xFFFFFFFF);
3137 REG_WRITE(RBBMIF_TIMEOUT_DIS_2, 0xFFFFFFFF);
3138
3139 hws->funcs.dccg_init(hws);
3140
3141 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, 2);
3142 REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
3143 if (REG(REFCLK_CNTL))
3144 REG_WRITE(REFCLK_CNTL, 0);
3145 //
3146
3147
3148 /* Blank pixel data with OPP DPG */
3149 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3150 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3151
3152 if (tg->funcs->is_tg_enabled(tg))
3153 dcn20_init_blank(dc, tg);
3154 }
3155
3156 for (i = 0; i < res_pool->timing_generator_count; i++) {
3157 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3158
3159 if (tg->funcs->is_tg_enabled(tg))
3160 tg->funcs->lock(tg);
3161 }
3162
3163 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3164 struct dpp *dpp = res_pool->dpps[i];
3165
3166 dpp->funcs->dpp_reset(dpp);
3167 }
3168
3169 /* Reset all MPCC muxes */
3170 res_pool->mpc->funcs->mpc_init(res_pool->mpc);
3171
3172 /* initialize OPP mpc_tree parameter */
3173 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3174 res_pool->opps[i]->mpc_tree_params.opp_id = res_pool->opps[i]->inst;
3175 res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
3176 for (j = 0; j < MAX_PIPES; j++)
3177 res_pool->opps[i]->mpcc_disconnect_pending[j] = false;
3178 }
3179
3180 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3181 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3182 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3183 struct hubp *hubp = dc->res_pool->hubps[i];
3184 struct dpp *dpp = dc->res_pool->dpps[i];
3185
3186 pipe_ctx->stream_res.tg = tg;
3187 pipe_ctx->pipe_idx = i;
3188
3189 pipe_ctx->plane_res.hubp = hubp;
3190 pipe_ctx->plane_res.dpp = dpp;
3191 pipe_ctx->plane_res.mpcc_inst = dpp->inst;
3192 hubp->mpcc_id = dpp->inst;
3193 hubp->opp_id = OPP_ID_INVALID;
3194 hubp->power_gated = false;
3195 pipe_ctx->stream_res.opp = NULL;
3196
3197 hubp->funcs->hubp_init(hubp);
3198
3199 //dc->res_pool->opps[i]->mpc_tree_params.opp_id = dc->res_pool->opps[i]->inst;
3200 //dc->res_pool->opps[i]->mpc_tree_params.opp_list = NULL;
3201 dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
3202 pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
3203 /*to do*/
3204 hws->funcs.plane_atomic_disconnect(dc, context, pipe_ctx);
3205 }
3206
3207 /* initialize DWB pointer to MCIF_WB */
3208 for (i = 0; i < res_pool->res_cap->num_dwb; i++)
3209 res_pool->dwbc[i]->mcif = res_pool->mcif_wb[i];
3210
3211 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3212 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3213
3214 if (tg->funcs->is_tg_enabled(tg))
3215 tg->funcs->unlock(tg);
3216 }
3217
3218 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3219 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3220
3221 dc->hwss.disable_plane(dc, context, pipe_ctx);
3222
3223 pipe_ctx->stream_res.tg = NULL;
3224 pipe_ctx->plane_res.hubp = NULL;
3225 }
3226
3227 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
3228 struct timing_generator *tg = dc->res_pool->timing_generators[i];
3229
3230 tg->funcs->tg_init(tg);
3231 }
3232
3233 if (dc->res_pool->hubbub->funcs->init_crb)
3234 dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub);
3235 }
3236
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)3237 void dcn20_set_disp_pattern_generator(const struct dc *dc,
3238 struct pipe_ctx *pipe_ctx,
3239 enum controller_dp_test_pattern test_pattern,
3240 enum controller_dp_color_space color_space,
3241 enum dc_color_depth color_depth,
3242 const struct tg_color *solid_color,
3243 int width, int height, int offset)
3244 {
3245 pipe_ctx->stream_res.opp->funcs->opp_set_disp_pattern_generator(pipe_ctx->stream_res.opp, test_pattern,
3246 color_space, color_depth, solid_color, width, height, offset);
3247 }
3248