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