1 /*
2 * Copyright 2020 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
26
27 #include "dm_services.h"
28 #include "dc.h"
29
30 #include "dcn30/dcn30_init.h"
31
32 #include "resource.h"
33 #include "include/irq_service_interface.h"
34 #include "dcn20/dcn20_resource.h"
35
36 #include "dcn30_resource.h"
37
38 #include "dcn10/dcn10_ipp.h"
39 #include "dcn30/dcn30_hubbub.h"
40 #include "dcn30/dcn30_mpc.h"
41 #include "dcn30/dcn30_hubp.h"
42 #include "irq/dcn30/irq_service_dcn30.h"
43 #include "dcn30/dcn30_dpp.h"
44 #include "dcn30/dcn30_optc.h"
45 #include "dcn20/dcn20_hwseq.h"
46 #include "dcn30/dcn30_hwseq.h"
47 #include "dce110/dce110_hwseq.h"
48 #include "dcn30/dcn30_opp.h"
49 #include "dcn20/dcn20_dsc.h"
50 #include "dcn30/dcn30_vpg.h"
51 #include "dcn30/dcn30_afmt.h"
52 #include "dcn30/dcn30_dio_stream_encoder.h"
53 #include "dcn30/dcn30_dio_link_encoder.h"
54 #include "dce/dce_clock_source.h"
55 #include "dce/dce_audio.h"
56 #include "dce/dce_hwseq.h"
57 #include "clk_mgr.h"
58 #include "dio/virtual/virtual_stream_encoder.h"
59 #include "dce110/dce110_resource.h"
60 #include "dml/display_mode_vba.h"
61 #include "dcn30/dcn30_dccg.h"
62 #include "dcn10/dcn10_resource.h"
63 #include "dio/dcn10/dcn10_dio.h"
64 #include "link_service.h"
65 #include "dce/dce_panel_cntl.h"
66
67 #include "dcn30/dcn30_dwb.h"
68 #include "dcn30/dcn30_mmhubbub.h"
69
70 #include "sienna_cichlid_ip_offset.h"
71 #include "dcn/dcn_3_0_0_offset.h"
72 #include "dcn/dcn_3_0_0_sh_mask.h"
73
74 #include "nbio/nbio_7_4_offset.h"
75
76 #include "dpcs/dpcs_3_0_0_offset.h"
77 #include "dpcs/dpcs_3_0_0_sh_mask.h"
78
79 #include "mmhub/mmhub_2_0_0_offset.h"
80 #include "mmhub/mmhub_2_0_0_sh_mask.h"
81
82 #include "reg_helper.h"
83 #include "dce/dmub_abm.h"
84 #include "dce/dmub_psr.h"
85 #include "dce/dce_aux.h"
86 #include "dce/dce_i2c.h"
87
88 #include "dml/dcn30/dcn30_fpu.h"
89 #include "dml/dcn30/display_mode_vba_30.h"
90 #include "vm_helper.h"
91 #include "dcn20/dcn20_vmid.h"
92 #include "amdgpu_socbb.h"
93 #include "dc_dmub_srv.h"
94
95 #define DC_LOGGER \
96 dc->ctx->logger
97 #define DC_LOGGER_INIT(logger)
98
99 enum dcn30_clk_src_array_id {
100 DCN30_CLK_SRC_PLL0,
101 DCN30_CLK_SRC_PLL1,
102 DCN30_CLK_SRC_PLL2,
103 DCN30_CLK_SRC_PLL3,
104 DCN30_CLK_SRC_PLL4,
105 DCN30_CLK_SRC_PLL5,
106 DCN30_CLK_SRC_TOTAL
107 };
108
109 /* begin *********************
110 * macros to expend register list macro defined in HW object header file
111 */
112
113 /* DCN */
114 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
115
116 #define BASE(seg) BASE_INNER(seg)
117
118 #define SR(reg_name)\
119 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
120 mm ## reg_name
121
122 #define SRI(reg_name, block, id)\
123 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
124 mm ## block ## id ## _ ## reg_name
125
126 #define SRI2(reg_name, block, id)\
127 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
128 mm ## reg_name
129
130 #define SRIR(var_name, reg_name, block, id)\
131 .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
132 mm ## block ## id ## _ ## reg_name
133
134 #define SRII(reg_name, block, id)\
135 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
136 mm ## block ## id ## _ ## reg_name
137
138 #define SRII_MPC_RMU(reg_name, block, id)\
139 .RMU##_##reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
140 mm ## block ## id ## _ ## reg_name
141
142 #define SRII_DWB(reg_name, temp_name, block, id)\
143 .reg_name[id] = BASE(mm ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
144 mm ## block ## id ## _ ## temp_name
145
146 #define SF_DWB2(reg_name, block, id, field_name, post_fix) \
147 .field_name = reg_name ## __ ## field_name ## post_fix
148
149 #define DCCG_SRII(reg_name, block, id)\
150 .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
151 mm ## block ## id ## _ ## reg_name
152
153 #define VUPDATE_SRII(reg_name, block, id)\
154 .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
155 mm ## reg_name ## _ ## block ## id
156
157 /* NBIO */
158 #define NBIO_BASE_INNER(seg) \
159 NBIO_BASE__INST0_SEG ## seg
160
161 #define NBIO_BASE(seg) \
162 NBIO_BASE_INNER(seg)
163
164 #define NBIO_SR(reg_name)\
165 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
166 mm ## reg_name
167
168 /* MMHUB */
169 #define MMHUB_BASE_INNER(seg) \
170 MMHUB_BASE__INST0_SEG ## seg
171
172 #define MMHUB_BASE(seg) \
173 MMHUB_BASE_INNER(seg)
174
175 #define MMHUB_SR(reg_name)\
176 .reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \
177 mmMM ## reg_name
178
179 /* CLOCK */
180 #define CLK_BASE_INNER(seg) \
181 CLK_BASE__INST0_SEG ## seg
182
183 #define CLK_BASE(seg) \
184 CLK_BASE_INNER(seg)
185
186 #define CLK_SRI(reg_name, block, inst)\
187 .reg_name = CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \
188 mm ## block ## _ ## inst ## _ ## reg_name
189
190
191 static const struct bios_registers bios_regs = {
192 NBIO_SR(BIOS_SCRATCH_3),
193 NBIO_SR(BIOS_SCRATCH_6)
194 };
195
196 #define clk_src_regs(index, pllid)\
197 [index] = {\
198 CS_COMMON_REG_LIST_DCN2_0(index, pllid),\
199 }
200
201 static const struct dce110_clk_src_regs clk_src_regs[] = {
202 clk_src_regs(0, A),
203 clk_src_regs(1, B),
204 clk_src_regs(2, C),
205 clk_src_regs(3, D),
206 clk_src_regs(4, E),
207 clk_src_regs(5, F)
208 };
209
210 static const struct dce110_clk_src_shift cs_shift = {
211 CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
212 };
213
214 static const struct dce110_clk_src_mask cs_mask = {
215 CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
216 };
217
218 #define abm_regs(id)\
219 [id] = {\
220 ABM_DCN30_REG_LIST(id)\
221 }
222
223 static const struct dce_abm_registers abm_regs[] = {
224 abm_regs(0),
225 abm_regs(1),
226 abm_regs(2),
227 abm_regs(3),
228 abm_regs(4),
229 abm_regs(5),
230 };
231
232 static const struct dce_abm_shift abm_shift = {
233 ABM_MASK_SH_LIST_DCN30(__SHIFT)
234 };
235
236 static const struct dce_abm_mask abm_mask = {
237 ABM_MASK_SH_LIST_DCN30(_MASK)
238 };
239
240
241
242 #define audio_regs(id)\
243 [id] = {\
244 AUD_COMMON_REG_LIST(id)\
245 }
246
247 static const struct dce_audio_registers audio_regs[] = {
248 audio_regs(0),
249 audio_regs(1),
250 audio_regs(2),
251 audio_regs(3),
252 audio_regs(4),
253 audio_regs(5),
254 audio_regs(6)
255 };
256
257 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
258 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
259 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
260 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
261
262 static const struct dce_audio_shift audio_shift = {
263 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
264 };
265
266 static const struct dce_audio_mask audio_mask = {
267 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
268 };
269
270 #define vpg_regs(id)\
271 [id] = {\
272 VPG_DCN3_REG_LIST(id)\
273 }
274
275 static const struct dcn30_vpg_registers vpg_regs[] = {
276 vpg_regs(0),
277 vpg_regs(1),
278 vpg_regs(2),
279 vpg_regs(3),
280 vpg_regs(4),
281 vpg_regs(5),
282 vpg_regs(6),
283 };
284
285 static const struct dcn30_vpg_shift vpg_shift = {
286 DCN3_VPG_MASK_SH_LIST(__SHIFT)
287 };
288
289 static const struct dcn30_vpg_mask vpg_mask = {
290 DCN3_VPG_MASK_SH_LIST(_MASK)
291 };
292
293 #define afmt_regs(id)\
294 [id] = {\
295 AFMT_DCN3_REG_LIST(id)\
296 }
297
298 static const struct dcn30_afmt_registers afmt_regs[] = {
299 afmt_regs(0),
300 afmt_regs(1),
301 afmt_regs(2),
302 afmt_regs(3),
303 afmt_regs(4),
304 afmt_regs(5),
305 afmt_regs(6),
306 };
307
308 static const struct dcn30_afmt_shift afmt_shift = {
309 DCN3_AFMT_MASK_SH_LIST(__SHIFT)
310 };
311
312 static const struct dcn30_afmt_mask afmt_mask = {
313 DCN3_AFMT_MASK_SH_LIST(_MASK)
314 };
315
316 #define stream_enc_regs(id)\
317 [id] = {\
318 SE_DCN3_REG_LIST(id)\
319 }
320
321 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
322 stream_enc_regs(0),
323 stream_enc_regs(1),
324 stream_enc_regs(2),
325 stream_enc_regs(3),
326 stream_enc_regs(4),
327 stream_enc_regs(5)
328 };
329
330 static const struct dcn10_stream_encoder_shift se_shift = {
331 SE_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
332 };
333
334 static const struct dcn10_stream_encoder_mask se_mask = {
335 SE_COMMON_MASK_SH_LIST_DCN30(_MASK)
336 };
337
338
339 #define aux_regs(id)\
340 [id] = {\
341 DCN2_AUX_REG_LIST(id)\
342 }
343
344 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
345 aux_regs(0),
346 aux_regs(1),
347 aux_regs(2),
348 aux_regs(3),
349 aux_regs(4),
350 aux_regs(5)
351 };
352
353 #define hpd_regs(id)\
354 [id] = {\
355 HPD_REG_LIST(id)\
356 }
357
358 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
359 hpd_regs(0),
360 hpd_regs(1),
361 hpd_regs(2),
362 hpd_regs(3),
363 hpd_regs(4),
364 hpd_regs(5)
365 };
366
367 #define link_regs(id, phyid)\
368 [id] = {\
369 LE_DCN3_REG_LIST(id), \
370 UNIPHY_DCN2_REG_LIST(phyid), \
371 DPCS_DCN2_REG_LIST(id), \
372 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
373 }
374
375 static const struct dce110_aux_registers_shift aux_shift = {
376 DCN_AUX_MASK_SH_LIST(__SHIFT)
377 };
378
379 static const struct dce110_aux_registers_mask aux_mask = {
380 DCN_AUX_MASK_SH_LIST(_MASK)
381 };
382
383 static const struct dcn10_link_enc_registers link_enc_regs[] = {
384 link_regs(0, A),
385 link_regs(1, B),
386 link_regs(2, C),
387 link_regs(3, D),
388 link_regs(4, E),
389 link_regs(5, F)
390 };
391
392 static const struct dcn10_link_enc_shift le_shift = {
393 LINK_ENCODER_MASK_SH_LIST_DCN30(__SHIFT),\
394 DPCS_DCN2_MASK_SH_LIST(__SHIFT)
395 };
396
397 static const struct dcn10_link_enc_mask le_mask = {
398 LINK_ENCODER_MASK_SH_LIST_DCN30(_MASK),\
399 DPCS_DCN2_MASK_SH_LIST(_MASK)
400 };
401
402
403 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
404 { DCN_PANEL_CNTL_REG_LIST() }
405 };
406
407 static const struct dce_panel_cntl_shift panel_cntl_shift = {
408 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
409 };
410
411 static const struct dce_panel_cntl_mask panel_cntl_mask = {
412 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
413 };
414
415 #define dpp_regs(id)\
416 [id] = {\
417 DPP_REG_LIST_DCN30(id),\
418 }
419
420 static const struct dcn3_dpp_registers dpp_regs[] = {
421 dpp_regs(0),
422 dpp_regs(1),
423 dpp_regs(2),
424 dpp_regs(3),
425 dpp_regs(4),
426 dpp_regs(5),
427 };
428
429 static const struct dcn3_dpp_shift tf_shift = {
430 DPP_REG_LIST_SH_MASK_DCN30(__SHIFT)
431 };
432
433 static const struct dcn3_dpp_mask tf_mask = {
434 DPP_REG_LIST_SH_MASK_DCN30(_MASK)
435 };
436
437 #define opp_regs(id)\
438 [id] = {\
439 OPP_REG_LIST_DCN30(id),\
440 }
441
442 static const struct dcn20_opp_registers opp_regs[] = {
443 opp_regs(0),
444 opp_regs(1),
445 opp_regs(2),
446 opp_regs(3),
447 opp_regs(4),
448 opp_regs(5)
449 };
450
451 static const struct dcn20_opp_shift opp_shift = {
452 OPP_MASK_SH_LIST_DCN20(__SHIFT)
453 };
454
455 static const struct dcn20_opp_mask opp_mask = {
456 OPP_MASK_SH_LIST_DCN20(_MASK)
457 };
458
459 #define aux_engine_regs(id)\
460 [id] = {\
461 AUX_COMMON_REG_LIST0(id), \
462 .AUXN_IMPCAL = 0, \
463 .AUXP_IMPCAL = 0, \
464 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
465 }
466
467 static const struct dce110_aux_registers aux_engine_regs[] = {
468 aux_engine_regs(0),
469 aux_engine_regs(1),
470 aux_engine_regs(2),
471 aux_engine_regs(3),
472 aux_engine_regs(4),
473 aux_engine_regs(5)
474 };
475
476 #define dwbc_regs_dcn3(id)\
477 [id] = {\
478 DWBC_COMMON_REG_LIST_DCN30(id),\
479 }
480
481 static const struct dcn30_dwbc_registers dwbc30_regs[] = {
482 dwbc_regs_dcn3(0),
483 };
484
485 static const struct dcn30_dwbc_shift dwbc30_shift = {
486 DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
487 };
488
489 static const struct dcn30_dwbc_mask dwbc30_mask = {
490 DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
491 };
492
493 #define mcif_wb_regs_dcn3(id)\
494 [id] = {\
495 MCIF_WB_COMMON_REG_LIST_DCN30(id),\
496 }
497
498 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = {
499 mcif_wb_regs_dcn3(0)
500 };
501
502 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
503 MCIF_WB_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
504 };
505
506 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
507 MCIF_WB_COMMON_MASK_SH_LIST_DCN30(_MASK)
508 };
509
510 #define dsc_regsDCN20(id)\
511 [id] = {\
512 DSC_REG_LIST_DCN20(id)\
513 }
514
515 static const struct dcn20_dsc_registers dsc_regs[] = {
516 dsc_regsDCN20(0),
517 dsc_regsDCN20(1),
518 dsc_regsDCN20(2),
519 dsc_regsDCN20(3),
520 dsc_regsDCN20(4),
521 dsc_regsDCN20(5)
522 };
523
524 static const struct dcn20_dsc_shift dsc_shift = {
525 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
526 };
527
528 static const struct dcn20_dsc_mask dsc_mask = {
529 DSC_REG_LIST_SH_MASK_DCN20(_MASK)
530 };
531
532 static const struct dcn30_mpc_registers mpc_regs = {
533 MPC_REG_LIST_DCN3_0(0),
534 MPC_REG_LIST_DCN3_0(1),
535 MPC_REG_LIST_DCN3_0(2),
536 MPC_REG_LIST_DCN3_0(3),
537 MPC_REG_LIST_DCN3_0(4),
538 MPC_REG_LIST_DCN3_0(5),
539 MPC_OUT_MUX_REG_LIST_DCN3_0(0),
540 MPC_OUT_MUX_REG_LIST_DCN3_0(1),
541 MPC_OUT_MUX_REG_LIST_DCN3_0(2),
542 MPC_OUT_MUX_REG_LIST_DCN3_0(3),
543 MPC_OUT_MUX_REG_LIST_DCN3_0(4),
544 MPC_OUT_MUX_REG_LIST_DCN3_0(5),
545 MPC_RMU_GLOBAL_REG_LIST_DCN3AG,
546 MPC_RMU_REG_LIST_DCN3AG(0),
547 MPC_RMU_REG_LIST_DCN3AG(1),
548 MPC_RMU_REG_LIST_DCN3AG(2),
549 MPC_DWB_MUX_REG_LIST_DCN3_0(0),
550 };
551
552 static const struct dcn30_mpc_shift mpc_shift = {
553 MPC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
554 };
555
556 static const struct dcn30_mpc_mask mpc_mask = {
557 MPC_COMMON_MASK_SH_LIST_DCN30(_MASK)
558 };
559
560 #define optc_regs(id)\
561 [id] = {OPTC_COMMON_REG_LIST_DCN3_0(id)}
562
563
564 static const struct dcn_optc_registers optc_regs[] = {
565 optc_regs(0),
566 optc_regs(1),
567 optc_regs(2),
568 optc_regs(3),
569 optc_regs(4),
570 optc_regs(5)
571 };
572
573 static const struct dcn_optc_shift optc_shift = {
574 OPTC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
575 };
576
577 static const struct dcn_optc_mask optc_mask = {
578 OPTC_COMMON_MASK_SH_LIST_DCN30(_MASK)
579 };
580
581 #define hubp_regs(id)\
582 [id] = {\
583 HUBP_REG_LIST_DCN30(id)\
584 }
585
586 static const struct dcn_hubp2_registers hubp_regs[] = {
587 hubp_regs(0),
588 hubp_regs(1),
589 hubp_regs(2),
590 hubp_regs(3),
591 hubp_regs(4),
592 hubp_regs(5)
593 };
594
595 static const struct dcn_hubp2_shift hubp_shift = {
596 HUBP_MASK_SH_LIST_DCN30(__SHIFT)
597 };
598
599 static const struct dcn_hubp2_mask hubp_mask = {
600 HUBP_MASK_SH_LIST_DCN30(_MASK)
601 };
602
603 static const struct dcn_hubbub_registers hubbub_reg = {
604 HUBBUB_REG_LIST_DCN30(0)
605 };
606
607 static const struct dcn_hubbub_shift hubbub_shift = {
608 HUBBUB_MASK_SH_LIST_DCN30(__SHIFT)
609 };
610
611 static const struct dcn_hubbub_mask hubbub_mask = {
612 HUBBUB_MASK_SH_LIST_DCN30(_MASK)
613 };
614
615 static const struct dccg_registers dccg_regs = {
616 DCCG_REG_LIST_DCN30()
617 };
618
619 static const struct dccg_shift dccg_shift = {
620 DCCG_MASK_SH_LIST_DCN3(__SHIFT)
621 };
622
623 static const struct dccg_mask dccg_mask = {
624 DCCG_MASK_SH_LIST_DCN3(_MASK)
625 };
626
627 static const struct dce_hwseq_registers hwseq_reg = {
628 HWSEQ_DCN30_REG_LIST()
629 };
630
631 static const struct dce_hwseq_shift hwseq_shift = {
632 HWSEQ_DCN30_MASK_SH_LIST(__SHIFT)
633 };
634
635 static const struct dce_hwseq_mask hwseq_mask = {
636 HWSEQ_DCN30_MASK_SH_LIST(_MASK)
637 };
638 #define vmid_regs(id)\
639 [id] = {\
640 DCN20_VMID_REG_LIST(id)\
641 }
642
643 static const struct dcn_vmid_registers vmid_regs[] = {
644 vmid_regs(0),
645 vmid_regs(1),
646 vmid_regs(2),
647 vmid_regs(3),
648 vmid_regs(4),
649 vmid_regs(5),
650 vmid_regs(6),
651 vmid_regs(7),
652 vmid_regs(8),
653 vmid_regs(9),
654 vmid_regs(10),
655 vmid_regs(11),
656 vmid_regs(12),
657 vmid_regs(13),
658 vmid_regs(14),
659 vmid_regs(15)
660 };
661
662 static const struct dcn20_vmid_shift vmid_shifts = {
663 DCN20_VMID_MASK_SH_LIST(__SHIFT)
664 };
665
666 static const struct dcn20_vmid_mask vmid_masks = {
667 DCN20_VMID_MASK_SH_LIST(_MASK)
668 };
669
670 static const struct resource_caps res_cap_dcn3 = {
671 .num_timing_generator = 6,
672 .num_opp = 6,
673 .num_video_plane = 6,
674 .num_audio = 6,
675 .num_stream_encoder = 6,
676 .num_pll = 6,
677 .num_dwb = 1,
678 .num_ddc = 6,
679 .num_vmid = 16,
680 .num_mpc_3dlut = 3,
681 .num_dsc = 6,
682 };
683
684 static const struct dc_plane_cap plane_cap = {
685 .type = DC_PLANE_TYPE_DCN_UNIVERSAL,
686 .per_pixel_alpha = true,
687
688 .pixel_format_support = {
689 .argb8888 = true,
690 .nv12 = true,
691 .fp16 = true,
692 .p010 = true,
693 .ayuv = false,
694 },
695
696 .max_upscale_factor = {
697 .argb8888 = 16000,
698 .nv12 = 16000,
699 .fp16 = 16000
700 },
701
702 /* 6:1 downscaling ratio: 1000/6 = 166.666 */
703 .max_downscale_factor = {
704 .argb8888 = 167,
705 .nv12 = 167,
706 .fp16 = 167
707 },
708 16,
709 16
710 };
711
712 static const struct dc_debug_options debug_defaults_drv = {
713 .disable_dmcu = true, //No DMCU on DCN30
714 .force_abm_enable = false,
715 .clock_trace = true,
716 .disable_pplib_clock_request = true,
717 .pipe_split_policy = MPC_SPLIT_DYNAMIC,
718 .force_single_disp_pipe_split = false,
719 .disable_dcc = DCC_ENABLE,
720 .vsr_support = true,
721 .performance_trace = false,
722 .max_downscale_src_width = 7680,/*upto 8K*/
723 .disable_pplib_wm_range = false,
724 .scl_reset_length10 = true,
725 .sanity_checks = false,
726 .underflow_assert_delay_us = 0xFFFFFFFF,
727 .dwb_fi_phase = -1, // -1 = disable,
728 .dmub_command_table = true,
729 .use_max_lb = true,
730 .exit_idle_opt_for_cursor_updates = true,
731 .using_dml2 = false,
732 };
733
734 static const struct dc_check_config config_defaults = {
735 .enable_legacy_fast_update = false,
736 };
737
738 static const struct dc_panel_config panel_config_defaults = {
739 .psr = {
740 .disable_psr = false,
741 .disallow_psrsu = false,
742 .disallow_replay = false,
743 },
744 };
745
dcn30_dpp_destroy(struct dpp ** dpp)746 static void dcn30_dpp_destroy(struct dpp **dpp)
747 {
748 kfree(TO_DCN20_DPP(*dpp));
749 *dpp = NULL;
750 }
751
dcn30_dpp_create(struct dc_context * ctx,uint32_t inst)752 static struct dpp *dcn30_dpp_create(
753 struct dc_context *ctx,
754 uint32_t inst)
755 {
756 struct dcn3_dpp *dpp =
757 kzalloc_obj(struct dcn3_dpp);
758
759 if (!dpp)
760 return NULL;
761
762 if (dpp3_construct(dpp, ctx, inst,
763 &dpp_regs[inst], &tf_shift, &tf_mask))
764 return &dpp->base;
765
766 BREAK_TO_DEBUGGER();
767 kfree(dpp);
768 return NULL;
769 }
770
dcn30_opp_create(struct dc_context * ctx,uint32_t inst)771 static struct output_pixel_processor *dcn30_opp_create(
772 struct dc_context *ctx, uint32_t inst)
773 {
774 struct dcn20_opp *opp =
775 kzalloc_obj(struct dcn20_opp);
776
777 if (!opp) {
778 BREAK_TO_DEBUGGER();
779 return NULL;
780 }
781
782 dcn20_opp_construct(opp, ctx, inst,
783 &opp_regs[inst], &opp_shift, &opp_mask);
784 return &opp->base;
785 }
786
dcn30_aux_engine_create(struct dc_context * ctx,uint32_t inst)787 static struct dce_aux *dcn30_aux_engine_create(
788 struct dc_context *ctx,
789 uint32_t inst)
790 {
791 struct aux_engine_dce110 *aux_engine =
792 kzalloc_obj(struct aux_engine_dce110);
793
794 if (!aux_engine)
795 return NULL;
796
797 dce110_aux_engine_construct(aux_engine, ctx, inst,
798 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
799 &aux_engine_regs[inst],
800 &aux_mask,
801 &aux_shift,
802 ctx->dc->caps.extended_aux_timeout_support);
803
804 return &aux_engine->base;
805 }
806
807 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST_DCN30(id) }
808
809 static const struct dce_i2c_registers i2c_hw_regs[] = {
810 i2c_inst_regs(1),
811 i2c_inst_regs(2),
812 i2c_inst_regs(3),
813 i2c_inst_regs(4),
814 i2c_inst_regs(5),
815 i2c_inst_regs(6),
816 };
817
818 static const struct dce_i2c_shift i2c_shifts = {
819 I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
820 };
821
822 static const struct dce_i2c_mask i2c_masks = {
823 I2C_COMMON_MASK_SH_LIST_DCN30(_MASK)
824 };
825
dcn30_i2c_hw_create(struct dc_context * ctx,uint32_t inst)826 static struct dce_i2c_hw *dcn30_i2c_hw_create(
827 struct dc_context *ctx,
828 uint32_t inst)
829 {
830 struct dce_i2c_hw *dce_i2c_hw =
831 kzalloc_obj(struct dce_i2c_hw);
832
833 if (!dce_i2c_hw)
834 return NULL;
835
836 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
837 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
838
839 return dce_i2c_hw;
840 }
841
dcn30_mpc_create(struct dc_context * ctx,int num_mpcc,int num_rmu)842 static struct mpc *dcn30_mpc_create(
843 struct dc_context *ctx,
844 int num_mpcc,
845 int num_rmu)
846 {
847 struct dcn30_mpc *mpc30 = kzalloc_obj(struct dcn30_mpc);
848
849 if (!mpc30)
850 return NULL;
851
852 dcn30_mpc_construct(mpc30, ctx,
853 &mpc_regs,
854 &mpc_shift,
855 &mpc_mask,
856 num_mpcc,
857 num_rmu);
858
859 return &mpc30->base;
860 }
861
dcn30_hubbub_create(struct dc_context * ctx)862 static struct hubbub *dcn30_hubbub_create(struct dc_context *ctx)
863 {
864 int i;
865
866 struct dcn20_hubbub *hubbub3 = kzalloc_obj(struct dcn20_hubbub);
867
868 if (!hubbub3)
869 return NULL;
870
871 hubbub3_construct(hubbub3, ctx,
872 &hubbub_reg,
873 &hubbub_shift,
874 &hubbub_mask);
875
876
877 for (i = 0; i < res_cap_dcn3.num_vmid; i++) {
878 struct dcn20_vmid *vmid = &hubbub3->vmid[i];
879
880 vmid->ctx = ctx;
881
882 vmid->regs = &vmid_regs[i];
883 vmid->shifts = &vmid_shifts;
884 vmid->masks = &vmid_masks;
885 }
886
887 return &hubbub3->base;
888 }
889
890 static const struct dcn_dio_registers dio_regs = {
891 DIO_REG_LIST_DCN10()
892 };
893
894 #define DIO_MASK_SH_LIST(mask_sh)\
895 HWS_SF(, DIO_MEM_PWR_CTRL, I2C_LIGHT_SLEEP_FORCE, mask_sh)
896
897 static const struct dcn_dio_shift dio_shift = {
898 DIO_MASK_SH_LIST(__SHIFT)
899 };
900
901 static const struct dcn_dio_mask dio_mask = {
902 DIO_MASK_SH_LIST(_MASK)
903 };
904
dcn30_dio_create(struct dc_context * ctx)905 static struct dio *dcn30_dio_create(struct dc_context *ctx)
906 {
907 struct dcn10_dio *dio10 = kzalloc_obj(struct dcn10_dio);
908
909 if (!dio10)
910 return NULL;
911
912 dcn10_dio_construct(dio10, ctx, &dio_regs, &dio_shift, &dio_mask);
913
914 return &dio10->base;
915 }
916
dcn30_timing_generator_create(struct dc_context * ctx,uint32_t instance)917 static struct timing_generator *dcn30_timing_generator_create(
918 struct dc_context *ctx,
919 uint32_t instance)
920 {
921 struct optc *tgn10 =
922 kzalloc_obj(struct optc);
923
924 if (!tgn10)
925 return NULL;
926
927 tgn10->base.inst = instance;
928 tgn10->base.ctx = ctx;
929
930 tgn10->tg_regs = &optc_regs[instance];
931 tgn10->tg_shift = &optc_shift;
932 tgn10->tg_mask = &optc_mask;
933
934 dcn30_timing_generator_init(tgn10);
935
936 return &tgn10->base;
937 }
938
939 static const struct encoder_feature_support link_enc_feature = {
940 .max_hdmi_deep_color = COLOR_DEPTH_121212,
941 .max_hdmi_pixel_clock = 600000,
942 .hdmi_ycbcr420_supported = true,
943 .dp_ycbcr420_supported = true,
944 .fec_supported = true,
945 .flags.bits.IS_HBR2_CAPABLE = true,
946 .flags.bits.IS_HBR3_CAPABLE = true,
947 .flags.bits.IS_TPS3_CAPABLE = true,
948 .flags.bits.IS_TPS4_CAPABLE = true
949 };
950
dcn30_link_encoder_create(struct dc_context * ctx,const struct encoder_init_data * enc_init_data)951 static struct link_encoder *dcn30_link_encoder_create(
952 struct dc_context *ctx,
953 const struct encoder_init_data *enc_init_data)
954 {
955 struct dcn20_link_encoder *enc20 =
956 kzalloc_obj(struct dcn20_link_encoder);
957
958 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
959 return NULL;
960
961 dcn30_link_encoder_construct(enc20,
962 enc_init_data,
963 &link_enc_feature,
964 &link_enc_regs[enc_init_data->transmitter],
965 &link_enc_aux_regs[enc_init_data->channel - 1],
966 &link_enc_hpd_regs[enc_init_data->hpd_source],
967 &le_shift,
968 &le_mask);
969
970 return &enc20->enc10.base;
971 }
972
dcn30_panel_cntl_create(const struct panel_cntl_init_data * init_data)973 static struct panel_cntl *dcn30_panel_cntl_create(const struct panel_cntl_init_data *init_data)
974 {
975 struct dce_panel_cntl *panel_cntl =
976 kzalloc_obj(struct dce_panel_cntl);
977
978 if (!panel_cntl)
979 return NULL;
980
981 dce_panel_cntl_construct(panel_cntl,
982 init_data,
983 &panel_cntl_regs[init_data->inst],
984 &panel_cntl_shift,
985 &panel_cntl_mask);
986
987 return &panel_cntl->base;
988 }
989
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)990 static void read_dce_straps(
991 struct dc_context *ctx,
992 struct resource_straps *straps)
993 {
994 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
995 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
996
997 }
998
dcn30_create_audio(struct dc_context * ctx,unsigned int inst)999 static struct audio *dcn30_create_audio(
1000 struct dc_context *ctx, unsigned int inst)
1001 {
1002 return dce_audio_create(ctx, inst,
1003 &audio_regs[inst], &audio_shift, &audio_mask);
1004 }
1005
dcn30_vpg_create(struct dc_context * ctx,uint32_t inst)1006 static struct vpg *dcn30_vpg_create(
1007 struct dc_context *ctx,
1008 uint32_t inst)
1009 {
1010 struct dcn30_vpg *vpg3 = kzalloc_obj(struct dcn30_vpg);
1011
1012 if (!vpg3)
1013 return NULL;
1014
1015 vpg3_construct(vpg3, ctx, inst,
1016 &vpg_regs[inst],
1017 &vpg_shift,
1018 &vpg_mask);
1019
1020 return &vpg3->base;
1021 }
1022
dcn30_afmt_create(struct dc_context * ctx,uint32_t inst)1023 static struct afmt *dcn30_afmt_create(
1024 struct dc_context *ctx,
1025 uint32_t inst)
1026 {
1027 struct dcn30_afmt *afmt3 = kzalloc_obj(struct dcn30_afmt);
1028
1029 if (!afmt3)
1030 return NULL;
1031
1032 afmt3_construct(afmt3, ctx, inst,
1033 &afmt_regs[inst],
1034 &afmt_shift,
1035 &afmt_mask);
1036
1037 return &afmt3->base;
1038 }
1039
dcn30_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1040 static struct stream_encoder *dcn30_stream_encoder_create(enum engine_id eng_id,
1041 struct dc_context *ctx)
1042 {
1043 struct dcn10_stream_encoder *enc1;
1044 struct vpg *vpg;
1045 struct afmt *afmt;
1046 int vpg_inst;
1047 int afmt_inst;
1048
1049 /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1050 if (eng_id <= ENGINE_ID_DIGF) {
1051 vpg_inst = eng_id;
1052 afmt_inst = eng_id;
1053 } else
1054 return NULL;
1055
1056 enc1 = kzalloc_obj(struct dcn10_stream_encoder);
1057 vpg = dcn30_vpg_create(ctx, vpg_inst);
1058 afmt = dcn30_afmt_create(ctx, afmt_inst);
1059
1060 if (!enc1 || !vpg || !afmt) {
1061 kfree(enc1);
1062 kfree(vpg);
1063 kfree(afmt);
1064 return NULL;
1065 }
1066
1067 dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1068 eng_id, vpg, afmt,
1069 &stream_enc_regs[eng_id],
1070 &se_shift, &se_mask);
1071
1072 return &enc1->base;
1073 }
1074
dcn30_hwseq_create(struct dc_context * ctx)1075 static struct dce_hwseq *dcn30_hwseq_create(struct dc_context *ctx)
1076 {
1077 struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq);
1078
1079 if (hws) {
1080 hws->ctx = ctx;
1081 hws->regs = &hwseq_reg;
1082 hws->shifts = &hwseq_shift;
1083 hws->masks = &hwseq_mask;
1084 }
1085 return hws;
1086 }
1087 static const struct resource_create_funcs res_create_funcs = {
1088 .read_dce_straps = read_dce_straps,
1089 .create_audio = dcn30_create_audio,
1090 .create_stream_encoder = dcn30_stream_encoder_create,
1091 .create_hwseq = dcn30_hwseq_create,
1092 };
1093
dcn30_resource_destruct(struct dcn30_resource_pool * pool)1094 static void dcn30_resource_destruct(struct dcn30_resource_pool *pool)
1095 {
1096 unsigned int i;
1097
1098 for (i = 0; i < pool->base.stream_enc_count; i++) {
1099 if (pool->base.stream_enc[i] != NULL) {
1100 if (pool->base.stream_enc[i]->vpg != NULL) {
1101 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1102 pool->base.stream_enc[i]->vpg = NULL;
1103 }
1104 if (pool->base.stream_enc[i]->afmt != NULL) {
1105 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1106 pool->base.stream_enc[i]->afmt = NULL;
1107 }
1108 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1109 pool->base.stream_enc[i] = NULL;
1110 }
1111 }
1112
1113 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1114 if (pool->base.dscs[i] != NULL)
1115 dcn20_dsc_destroy(&pool->base.dscs[i]);
1116 }
1117
1118 if (pool->base.mpc != NULL) {
1119 kfree(TO_DCN20_MPC(pool->base.mpc));
1120 pool->base.mpc = NULL;
1121 }
1122 if (pool->base.hubbub != NULL) {
1123 kfree(pool->base.hubbub);
1124 pool->base.hubbub = NULL;
1125 }
1126
1127 if (pool->base.dio != NULL) {
1128 kfree(TO_DCN10_DIO(pool->base.dio));
1129 pool->base.dio = NULL;
1130 }
1131
1132 for (i = 0; i < pool->base.pipe_count; i++) {
1133 if (pool->base.dpps[i] != NULL)
1134 dcn30_dpp_destroy(&pool->base.dpps[i]);
1135
1136 if (pool->base.ipps[i] != NULL)
1137 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1138
1139 if (pool->base.hubps[i] != NULL) {
1140 kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1141 pool->base.hubps[i] = NULL;
1142 }
1143
1144 if (pool->base.irqs != NULL) {
1145 dal_irq_service_destroy(&pool->base.irqs);
1146 }
1147 }
1148
1149 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1150 if (pool->base.engines[i] != NULL)
1151 dce110_engine_destroy(&pool->base.engines[i]);
1152 if (pool->base.hw_i2cs[i] != NULL) {
1153 kfree(pool->base.hw_i2cs[i]);
1154 pool->base.hw_i2cs[i] = NULL;
1155 }
1156 if (pool->base.sw_i2cs[i] != NULL) {
1157 kfree(pool->base.sw_i2cs[i]);
1158 pool->base.sw_i2cs[i] = NULL;
1159 }
1160 }
1161
1162 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1163 if (pool->base.opps[i] != NULL)
1164 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1165 }
1166
1167 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1168 if (pool->base.timing_generators[i] != NULL) {
1169 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1170 pool->base.timing_generators[i] = NULL;
1171 }
1172 }
1173
1174 for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1175 if (pool->base.dwbc[i] != NULL) {
1176 kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1177 pool->base.dwbc[i] = NULL;
1178 }
1179 if (pool->base.mcif_wb[i] != NULL) {
1180 kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1181 pool->base.mcif_wb[i] = NULL;
1182 }
1183 }
1184
1185 for (i = 0; i < pool->base.audio_count; i++) {
1186 if (pool->base.audios[i])
1187 dce_aud_destroy(&pool->base.audios[i]);
1188 }
1189
1190 for (i = 0; i < pool->base.clk_src_count; i++) {
1191 if (pool->base.clock_sources[i] != NULL) {
1192 dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1193 pool->base.clock_sources[i] = NULL;
1194 }
1195 }
1196
1197 for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1198 if (pool->base.mpc_lut[i] != NULL) {
1199 dc_3dlut_func_release(pool->base.mpc_lut[i]);
1200 pool->base.mpc_lut[i] = NULL;
1201 }
1202 if (pool->base.mpc_shaper[i] != NULL) {
1203 dc_transfer_func_release(pool->base.mpc_shaper[i]);
1204 pool->base.mpc_shaper[i] = NULL;
1205 }
1206 }
1207
1208 if (pool->base.dp_clock_source != NULL) {
1209 dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1210 pool->base.dp_clock_source = NULL;
1211 }
1212
1213 for (i = 0; i < pool->base.pipe_count; i++) {
1214 if (pool->base.multiple_abms[i] != NULL)
1215 dce_abm_destroy(&pool->base.multiple_abms[i]);
1216 }
1217
1218 if (pool->base.psr != NULL)
1219 dmub_psr_destroy(&pool->base.psr);
1220
1221 if (pool->base.dccg != NULL)
1222 dcn_dccg_destroy(&pool->base.dccg);
1223
1224 if (pool->base.oem_device != NULL) {
1225 struct dc *dc = pool->base.oem_device->ctx->dc;
1226
1227 dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1228 }
1229 }
1230
dcn30_hubp_create(struct dc_context * ctx,uint32_t inst)1231 static struct hubp *dcn30_hubp_create(
1232 struct dc_context *ctx,
1233 uint32_t inst)
1234 {
1235 struct dcn20_hubp *hubp2 =
1236 kzalloc_obj(struct dcn20_hubp);
1237
1238 if (!hubp2)
1239 return NULL;
1240
1241 if (hubp3_construct(hubp2, ctx, inst,
1242 &hubp_regs[inst], &hubp_shift, &hubp_mask))
1243 return &hubp2->base;
1244
1245 BREAK_TO_DEBUGGER();
1246 kfree(hubp2);
1247 return NULL;
1248 }
1249
dcn30_dwbc_create(struct dc_context * ctx,struct resource_pool * pool)1250 static bool dcn30_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1251 {
1252 int i;
1253 uint32_t pipe_count = pool->res_cap->num_dwb;
1254
1255 for (i = 0; i < pipe_count; i++) {
1256 struct dcn30_dwbc *dwbc30 = kzalloc_obj(struct dcn30_dwbc);
1257
1258 if (!dwbc30) {
1259 dm_error("DC: failed to create dwbc30!\n");
1260 return false;
1261 }
1262
1263 dcn30_dwbc_construct(dwbc30, ctx,
1264 &dwbc30_regs[i],
1265 &dwbc30_shift,
1266 &dwbc30_mask,
1267 i);
1268
1269 pool->dwbc[i] = &dwbc30->base;
1270 }
1271 return true;
1272 }
1273
dcn30_mmhubbub_create(struct dc_context * ctx,struct resource_pool * pool)1274 static bool dcn30_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1275 {
1276 int i;
1277 uint32_t pipe_count = pool->res_cap->num_dwb;
1278
1279 for (i = 0; i < pipe_count; i++) {
1280 struct dcn30_mmhubbub *mcif_wb30 = kzalloc_obj(struct dcn30_mmhubbub);
1281
1282 if (!mcif_wb30) {
1283 dm_error("DC: failed to create mcif_wb30!\n");
1284 return false;
1285 }
1286
1287 dcn30_mmhubbub_construct(mcif_wb30, ctx,
1288 &mcif_wb30_regs[i],
1289 &mcif_wb30_shift,
1290 &mcif_wb30_mask,
1291 i);
1292
1293 pool->mcif_wb[i] = &mcif_wb30->base;
1294 }
1295 return true;
1296 }
1297
dcn30_dsc_create(struct dc_context * ctx,uint32_t inst)1298 static struct display_stream_compressor *dcn30_dsc_create(
1299 struct dc_context *ctx, uint32_t inst)
1300 {
1301 struct dcn20_dsc *dsc =
1302 kzalloc_obj(struct dcn20_dsc);
1303
1304 if (!dsc) {
1305 BREAK_TO_DEBUGGER();
1306 return NULL;
1307 }
1308
1309 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1310 return &dsc->base;
1311 }
1312
dcn30_add_stream_to_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)1313 enum dc_status dcn30_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
1314 {
1315
1316 return dcn20_add_stream_to_ctx(dc, new_ctx, dc_stream);
1317 }
1318
dcn30_destroy_resource_pool(struct resource_pool ** pool)1319 static void dcn30_destroy_resource_pool(struct resource_pool **pool)
1320 {
1321 struct dcn30_resource_pool *dcn30_pool = TO_DCN30_RES_POOL(*pool);
1322
1323 dcn30_resource_destruct(dcn30_pool);
1324 kfree(dcn30_pool);
1325 *pool = NULL;
1326 }
1327
dcn30_clock_source_create(struct dc_context * ctx,struct dc_bios * bios,enum clock_source_id id,const struct dce110_clk_src_regs * regs,bool dp_clk_src)1328 static struct clock_source *dcn30_clock_source_create(
1329 struct dc_context *ctx,
1330 struct dc_bios *bios,
1331 enum clock_source_id id,
1332 const struct dce110_clk_src_regs *regs,
1333 bool dp_clk_src)
1334 {
1335 struct dce110_clk_src *clk_src =
1336 kzalloc_obj(struct dce110_clk_src);
1337
1338 if (!clk_src)
1339 return NULL;
1340
1341 if (dcn3_clk_src_construct(clk_src, ctx, bios, id,
1342 regs, &cs_shift, &cs_mask)) {
1343 clk_src->base.dp_clk_src = dp_clk_src;
1344 return &clk_src->base;
1345 }
1346
1347 kfree(clk_src);
1348 BREAK_TO_DEBUGGER();
1349 return NULL;
1350 }
1351
dcn30_populate_dml_pipes_from_context(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,enum dc_validate_mode validate_mode)1352 int dcn30_populate_dml_pipes_from_context(
1353 struct dc *dc, struct dc_state *context,
1354 display_e2e_pipe_params_st *pipes,
1355 enum dc_validate_mode validate_mode)
1356 {
1357 int i, pipe_cnt;
1358 struct resource_context *res_ctx = &context->res_ctx;
1359
1360 DC_FP_START();
1361 dcn20_populate_dml_pipes_from_context(dc, context, pipes, validate_mode);
1362 DC_FP_END();
1363
1364 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1365 if (!res_ctx->pipe_ctx[i].stream)
1366 continue;
1367
1368 pipes[pipe_cnt++].pipe.scale_ratio_depth.lb_depth =
1369 dm_lb_16;
1370 }
1371
1372 return pipe_cnt;
1373 }
1374
dcn30_populate_dml_writeback_from_context(struct dc * dc,struct resource_context * res_ctx,display_e2e_pipe_params_st * pipes)1375 void dcn30_populate_dml_writeback_from_context(
1376 struct dc *dc, struct resource_context *res_ctx, display_e2e_pipe_params_st *pipes)
1377 {
1378 DC_FP_START();
1379 dcn30_fpu_populate_dml_writeback_from_context(dc, res_ctx, pipes);
1380 DC_FP_END();
1381 }
1382
dcn30_calc_max_scaled_time(unsigned int time_per_pixel,enum mmhubbub_wbif_mode mode,unsigned int urgent_watermark)1383 unsigned int dcn30_calc_max_scaled_time(
1384 unsigned int time_per_pixel,
1385 enum mmhubbub_wbif_mode mode,
1386 unsigned int urgent_watermark)
1387 {
1388 unsigned int time_per_byte = 0;
1389 unsigned int total_free_entry = 0xb40;
1390 unsigned int buf_lh_capability;
1391 unsigned int max_scaled_time;
1392
1393 if (mode == PACKED_444) /* packed mode 32 bpp */
1394 time_per_byte = time_per_pixel/4;
1395 else if (mode == PACKED_444_FP16) /* packed mode 64 bpp */
1396 time_per_byte = time_per_pixel/8;
1397
1398 if (time_per_byte == 0)
1399 time_per_byte = 1;
1400
1401 buf_lh_capability = (total_free_entry*time_per_byte*32) >> 6; /* time_per_byte is in u6.6*/
1402 max_scaled_time = buf_lh_capability - urgent_watermark;
1403 return max_scaled_time;
1404 }
1405
dcn30_set_mcif_arb_params(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int pipe_cnt)1406 void dcn30_set_mcif_arb_params(
1407 struct dc *dc,
1408 struct dc_state *context,
1409 display_e2e_pipe_params_st *pipes,
1410 int pipe_cnt)
1411 {
1412 enum mmhubbub_wbif_mode wbif_mode;
1413 struct display_mode_lib *dml = &context->bw_ctx.dml;
1414 struct mcif_arb_params *wb_arb_params;
1415 int i, j, dwb_pipe;
1416
1417 /* Writeback MCIF_WB arbitration parameters */
1418 dwb_pipe = 0;
1419 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1420
1421 if (!context->res_ctx.pipe_ctx[i].stream)
1422 continue;
1423
1424 for (j = 0; j < MAX_DWB_PIPES; j++) {
1425 struct dc_writeback_info *writeback_info = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j];
1426
1427 if (writeback_info->wb_enabled == false)
1428 continue;
1429
1430 //wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params;
1431 wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe];
1432
1433 if (writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_ARGB ||
1434 writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_RGBA)
1435 wbif_mode = PACKED_444_FP16;
1436 else
1437 wbif_mode = PACKED_444;
1438
1439 DC_FP_START();
1440 dcn30_fpu_set_mcif_arb_params(wb_arb_params, dml, pipes, pipe_cnt, j);
1441 DC_FP_END();
1442 wb_arb_params->time_per_pixel = (1000000 << 6) / context->res_ctx.pipe_ctx[i].stream->phy_pix_clk; /* time_per_pixel should be in u6.6 format */
1443 wb_arb_params->slice_lines = 32;
1444 wb_arb_params->arbitration_slice = 2; /* irrelevant since there is no YUV output */
1445 wb_arb_params->max_scaled_time = dcn30_calc_max_scaled_time(wb_arb_params->time_per_pixel,
1446 wbif_mode,
1447 wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */
1448
1449 dwb_pipe++;
1450
1451 if (dwb_pipe >= MAX_DWB_PIPES)
1452 return;
1453 }
1454 }
1455 }
1456
1457 static struct dc_cap_funcs cap_funcs = {
1458 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1459 };
1460
dcn30_acquire_post_bldn_3dlut(struct resource_context * res_ctx,const struct resource_pool * pool,int mpcc_id,struct dc_3dlut ** lut,struct dc_transfer_func ** shaper)1461 bool dcn30_acquire_post_bldn_3dlut(
1462 struct resource_context *res_ctx,
1463 const struct resource_pool *pool,
1464 int mpcc_id,
1465 struct dc_3dlut **lut,
1466 struct dc_transfer_func **shaper)
1467 {
1468 int i;
1469 bool ret = false;
1470 union dc_3dlut_state *state;
1471
1472 ASSERT(*lut == NULL && *shaper == NULL);
1473 *lut = NULL;
1474 *shaper = NULL;
1475
1476 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1477 if (!res_ctx->is_mpc_3dlut_acquired[i]) {
1478 *lut = pool->mpc_lut[i];
1479 *shaper = pool->mpc_shaper[i];
1480 state = &pool->mpc_lut[i]->state;
1481 res_ctx->is_mpc_3dlut_acquired[i] = true;
1482 state->bits.rmu_idx_valid = 1;
1483 state->bits.rmu_mux_num = i;
1484 if (state->bits.rmu_mux_num == 0)
1485 state->bits.mpc_rmu0_mux = mpcc_id;
1486 else if (state->bits.rmu_mux_num == 1)
1487 state->bits.mpc_rmu1_mux = mpcc_id;
1488 else if (state->bits.rmu_mux_num == 2)
1489 state->bits.mpc_rmu2_mux = mpcc_id;
1490 ret = true;
1491 break;
1492 }
1493 }
1494 return ret;
1495 }
1496
dcn30_release_post_bldn_3dlut(struct resource_context * res_ctx,const struct resource_pool * pool,struct dc_3dlut ** lut,struct dc_transfer_func ** shaper)1497 bool dcn30_release_post_bldn_3dlut(
1498 struct resource_context *res_ctx,
1499 const struct resource_pool *pool,
1500 struct dc_3dlut **lut,
1501 struct dc_transfer_func **shaper)
1502 {
1503 int i;
1504 bool ret = false;
1505
1506 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1507 if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) {
1508 res_ctx->is_mpc_3dlut_acquired[i] = false;
1509 pool->mpc_lut[i]->state.raw = 0;
1510 *lut = NULL;
1511 *shaper = NULL;
1512 ret = true;
1513 break;
1514 }
1515 }
1516 return ret;
1517 }
1518
is_soc_bounding_box_valid(struct dc * dc)1519 static bool is_soc_bounding_box_valid(struct dc *dc)
1520 {
1521 uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev;
1522
1523 if (ASICREV_IS_SIENNA_CICHLID_P(hw_internal_rev))
1524 return true;
1525
1526 return false;
1527 }
1528
init_soc_bounding_box(struct dc * dc,struct dcn30_resource_pool * pool)1529 static bool init_soc_bounding_box(struct dc *dc,
1530 struct dcn30_resource_pool *pool)
1531 {
1532 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_0_soc;
1533 struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_0_ip;
1534
1535 DC_LOGGER_INIT(dc->ctx->logger);
1536
1537 if (!is_soc_bounding_box_valid(dc)) {
1538 DC_LOG_ERROR("%s: not valid soc bounding box\n", __func__);
1539 return false;
1540 }
1541
1542 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
1543 loaded_ip->max_num_dpp = pool->base.pipe_count;
1544 loaded_ip->clamp_min_dcfclk = dc->config.clamp_min_dcfclk;
1545 dcn20_patch_bounding_box(dc, loaded_bb);
1546 DC_FP_START();
1547 patch_dcn30_soc_bounding_box(dc, &dcn3_0_soc);
1548 DC_FP_END();
1549
1550 return true;
1551 }
1552
dcn30_split_stream_for_mpc_or_odm(const struct dc * dc,struct resource_context * res_ctx,struct pipe_ctx * pri_pipe,struct pipe_ctx * sec_pipe,bool odm)1553 static bool dcn30_split_stream_for_mpc_or_odm(
1554 const struct dc *dc,
1555 struct resource_context *res_ctx,
1556 struct pipe_ctx *pri_pipe,
1557 struct pipe_ctx *sec_pipe,
1558 bool odm)
1559 {
1560 int pipe_idx = sec_pipe->pipe_idx;
1561 const struct resource_pool *pool = dc->res_pool;
1562
1563 *sec_pipe = *pri_pipe;
1564
1565 sec_pipe->pipe_idx = pipe_idx;
1566 sec_pipe->plane_res.mi = pool->mis[pipe_idx];
1567 sec_pipe->plane_res.hubp = pool->hubps[pipe_idx];
1568 sec_pipe->plane_res.ipp = pool->ipps[pipe_idx];
1569 sec_pipe->plane_res.xfm = pool->transforms[pipe_idx];
1570 sec_pipe->plane_res.dpp = pool->dpps[pipe_idx];
1571 sec_pipe->plane_res.mpcc_inst = pool->dpps[pipe_idx]->inst;
1572 sec_pipe->stream_res.dsc = NULL;
1573 if (odm) {
1574 if (pri_pipe->next_odm_pipe) {
1575 ASSERT(pri_pipe->next_odm_pipe != sec_pipe);
1576 sec_pipe->next_odm_pipe = pri_pipe->next_odm_pipe;
1577 sec_pipe->next_odm_pipe->prev_odm_pipe = sec_pipe;
1578 }
1579 if (pri_pipe->top_pipe && pri_pipe->top_pipe->next_odm_pipe) {
1580 pri_pipe->top_pipe->next_odm_pipe->bottom_pipe = sec_pipe;
1581 sec_pipe->top_pipe = pri_pipe->top_pipe->next_odm_pipe;
1582 }
1583 if (pri_pipe->bottom_pipe && pri_pipe->bottom_pipe->next_odm_pipe) {
1584 pri_pipe->bottom_pipe->next_odm_pipe->top_pipe = sec_pipe;
1585 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe->next_odm_pipe;
1586 }
1587 pri_pipe->next_odm_pipe = sec_pipe;
1588 sec_pipe->prev_odm_pipe = pri_pipe;
1589
1590 if (!sec_pipe->top_pipe)
1591 sec_pipe->stream_res.opp = pool->opps[pipe_idx];
1592 else
1593 sec_pipe->stream_res.opp = sec_pipe->top_pipe->stream_res.opp;
1594 if (sec_pipe->stream->timing.flags.DSC == 1) {
1595 dcn20_acquire_dsc(dc, res_ctx, &sec_pipe->stream_res.dsc, pipe_idx);
1596 ASSERT(sec_pipe->stream_res.dsc);
1597 if (sec_pipe->stream_res.dsc == NULL)
1598 return false;
1599 }
1600 } else {
1601 if (pri_pipe->bottom_pipe) {
1602 ASSERT(pri_pipe->bottom_pipe != sec_pipe);
1603 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe;
1604 sec_pipe->bottom_pipe->top_pipe = sec_pipe;
1605 }
1606 pri_pipe->bottom_pipe = sec_pipe;
1607 sec_pipe->top_pipe = pri_pipe;
1608
1609 ASSERT(pri_pipe->plane_state);
1610 }
1611
1612 return true;
1613 }
1614
dcn30_find_split_pipe(struct dc * dc,struct dc_state * context,int old_index)1615 static struct pipe_ctx *dcn30_find_split_pipe(
1616 struct dc *dc,
1617 struct dc_state *context,
1618 int old_index)
1619 {
1620 struct pipe_ctx *pipe = NULL;
1621 int i;
1622
1623 if (old_index >= 0 && context->res_ctx.pipe_ctx[old_index].stream == NULL) {
1624 pipe = &context->res_ctx.pipe_ctx[old_index];
1625 pipe->pipe_idx = old_index;
1626 }
1627
1628 if (!pipe)
1629 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
1630 if (dc->current_state->res_ctx.pipe_ctx[i].top_pipe == NULL
1631 && dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe == NULL) {
1632 if (context->res_ctx.pipe_ctx[i].stream == NULL) {
1633 pipe = &context->res_ctx.pipe_ctx[i];
1634 pipe->pipe_idx = i;
1635 break;
1636 }
1637 }
1638 }
1639
1640 /*
1641 * May need to fix pipes getting tossed from 1 opp to another on flip
1642 * Add for debugging transient underflow during topology updates:
1643 * ASSERT(pipe);
1644 */
1645 if (!pipe)
1646 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
1647 if (context->res_ctx.pipe_ctx[i].stream == NULL) {
1648 pipe = &context->res_ctx.pipe_ctx[i];
1649 pipe->pipe_idx = i;
1650 break;
1651 }
1652 }
1653
1654 return pipe;
1655 }
1656
dcn30_internal_validate_bw(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int * pipe_cnt_out,int * vlevel_out,enum dc_validate_mode validate_mode,bool allow_self_refresh_only)1657 noinline bool dcn30_internal_validate_bw(
1658 struct dc *dc,
1659 struct dc_state *context,
1660 display_e2e_pipe_params_st *pipes,
1661 int *pipe_cnt_out,
1662 int *vlevel_out,
1663 enum dc_validate_mode validate_mode,
1664 bool allow_self_refresh_only)
1665 {
1666 bool out = false;
1667 bool repopulate_pipes = false;
1668 int split[MAX_PIPES] = { 0 };
1669 bool merge[MAX_PIPES] = { false };
1670 bool newly_split[MAX_PIPES] = { false };
1671 int pipe_cnt, i, pipe_idx, vlevel = 0;
1672 struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
1673
1674 ASSERT(pipes);
1675 if (!pipes)
1676 return false;
1677
1678 context->bw_ctx.dml.vba.maxMpcComb = 0;
1679 context->bw_ctx.dml.vba.VoltageLevel = 0;
1680 context->bw_ctx.dml.vba.DRAMClockChangeSupport[0][0] = dm_dram_clock_change_vactive;
1681 dc->res_pool->funcs->update_soc_for_wm_a(dc, context);
1682 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode);
1683
1684 if (!pipe_cnt) {
1685 out = true;
1686 goto validate_out;
1687 }
1688
1689 dml_log_pipe_params(&context->bw_ctx.dml, pipes, pipe_cnt);
1690
1691 if (validate_mode == DC_VALIDATE_MODE_AND_PROGRAMMING || !allow_self_refresh_only) {
1692 /*
1693 * DML favors voltage over p-state, but we're more interested in
1694 * supporting p-state over voltage. We can't support p-state in
1695 * prefetch mode > 0 so try capping the prefetch mode to start.
1696 */
1697 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1698 dm_allow_self_refresh_and_mclk_switch;
1699 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1700 /* This may adjust vlevel and maxMpcComb */
1701 if (vlevel < context->bw_ctx.dml.soc.num_states)
1702 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1703 }
1704 if (allow_self_refresh_only &&
1705 (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING || vlevel == context->bw_ctx.dml.soc.num_states ||
1706 vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported)) {
1707 /*
1708 * If mode is unsupported or there's still no p-state support
1709 * then fall back to favoring voltage.
1710 *
1711 * We don't actually support prefetch mode 2, so require that we
1712 * at least support prefetch mode 1.
1713 */
1714 context->bw_ctx.dml.validate_max_state = (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING);
1715 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1716 dm_allow_self_refresh;
1717
1718 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1719 if (vlevel < context->bw_ctx.dml.soc.num_states) {
1720 memset(split, 0, sizeof(split));
1721 memset(merge, 0, sizeof(merge));
1722 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1723 }
1724 context->bw_ctx.dml.validate_max_state = false;
1725 }
1726
1727 dml_log_mode_support_params(&context->bw_ctx.dml);
1728
1729 if (vlevel == context->bw_ctx.dml.soc.num_states)
1730 goto validate_fail;
1731
1732 if (!dc->config.enable_windowed_mpo_odm) {
1733 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1734 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1735 struct pipe_ctx *mpo_pipe = pipe->bottom_pipe;
1736
1737 if (!pipe->stream)
1738 continue;
1739
1740 /* We only support full screen mpo with ODM */
1741 if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled
1742 && pipe->plane_state && mpo_pipe
1743 && memcmp(&mpo_pipe->plane_state->clip_rect,
1744 &pipe->stream->src,
1745 sizeof(struct rect)) != 0) {
1746 ASSERT(mpo_pipe->plane_state != pipe->plane_state);
1747 goto validate_fail;
1748 }
1749 pipe_idx++;
1750 }
1751 }
1752
1753 /* merge pipes if necessary */
1754 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1755 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1756
1757 /*skip pipes that don't need merging*/
1758 if (!merge[i])
1759 continue;
1760
1761 /* if ODM merge we ignore mpc tree, mpo pipes will have their own flags */
1762 if (pipe->prev_odm_pipe) {
1763 /*split off odm pipe*/
1764 pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe;
1765 if (pipe->next_odm_pipe)
1766 pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe;
1767
1768 pipe->bottom_pipe = NULL;
1769 pipe->next_odm_pipe = NULL;
1770 pipe->plane_state = NULL;
1771 pipe->stream = NULL;
1772 pipe->top_pipe = NULL;
1773 pipe->prev_odm_pipe = NULL;
1774 if (pipe->stream_res.dsc)
1775 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc);
1776 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1777 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1778 repopulate_pipes = true;
1779 } else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
1780 struct pipe_ctx *top_pipe = pipe->top_pipe;
1781 struct pipe_ctx *bottom_pipe = pipe->bottom_pipe;
1782
1783 top_pipe->bottom_pipe = bottom_pipe;
1784 if (bottom_pipe)
1785 bottom_pipe->top_pipe = top_pipe;
1786
1787 pipe->top_pipe = NULL;
1788 pipe->bottom_pipe = NULL;
1789 pipe->plane_state = NULL;
1790 pipe->stream = NULL;
1791 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1792 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1793 repopulate_pipes = true;
1794 } else
1795 ASSERT(0); /* Should never try to merge master pipe */
1796
1797 }
1798
1799 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
1800 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1801 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1802 struct pipe_ctx *hsplit_pipe = NULL;
1803 bool odm;
1804 int old_index = -1;
1805
1806 if (!pipe->stream || newly_split[i])
1807 continue;
1808
1809 pipe_idx++;
1810 odm = vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled;
1811
1812 if (!pipe->plane_state && !odm)
1813 continue;
1814
1815 if (split[i]) {
1816 if (odm) {
1817 if (split[i] == 4 && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe)
1818 old_index = old_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1819 else if (old_pipe->next_odm_pipe)
1820 old_index = old_pipe->next_odm_pipe->pipe_idx;
1821 } else {
1822 if (split[i] == 4 && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1823 old_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1824 old_index = old_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1825 else if (old_pipe->bottom_pipe &&
1826 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1827 old_index = old_pipe->bottom_pipe->pipe_idx;
1828 }
1829 hsplit_pipe = dcn30_find_split_pipe(dc, context, old_index);
1830 ASSERT(hsplit_pipe);
1831 if (!hsplit_pipe)
1832 goto validate_fail;
1833
1834 if (!dcn30_split_stream_for_mpc_or_odm(
1835 dc, &context->res_ctx,
1836 pipe, hsplit_pipe, odm))
1837 goto validate_fail;
1838
1839 newly_split[hsplit_pipe->pipe_idx] = true;
1840 repopulate_pipes = true;
1841 }
1842 if (split[i] == 4) {
1843 struct pipe_ctx *pipe_4to1;
1844
1845 if (odm && old_pipe->next_odm_pipe)
1846 old_index = old_pipe->next_odm_pipe->pipe_idx;
1847 else if (!odm && old_pipe->bottom_pipe &&
1848 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1849 old_index = old_pipe->bottom_pipe->pipe_idx;
1850 else
1851 old_index = -1;
1852 pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index);
1853 ASSERT(pipe_4to1);
1854 if (!pipe_4to1)
1855 goto validate_fail;
1856 if (!dcn30_split_stream_for_mpc_or_odm(
1857 dc, &context->res_ctx,
1858 pipe, pipe_4to1, odm))
1859 goto validate_fail;
1860 newly_split[pipe_4to1->pipe_idx] = true;
1861
1862 if (odm && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe
1863 && old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe)
1864 old_index = old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1865 else if (!odm && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1866 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe &&
1867 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1868 old_index = old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1869 else
1870 old_index = -1;
1871 pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index);
1872 ASSERT(pipe_4to1);
1873 if (!pipe_4to1)
1874 goto validate_fail;
1875 if (!dcn30_split_stream_for_mpc_or_odm(
1876 dc, &context->res_ctx,
1877 hsplit_pipe, pipe_4to1, odm))
1878 goto validate_fail;
1879 newly_split[pipe_4to1->pipe_idx] = true;
1880 }
1881 if (odm)
1882 dcn20_build_mapped_resource(dc, context, pipe->stream);
1883 }
1884
1885 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1886 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1887
1888 if (pipe->plane_state) {
1889 if (!resource_build_scaling_params(pipe))
1890 goto validate_fail;
1891 }
1892 }
1893
1894 /* Actual dsc count per stream dsc validation*/
1895 if (!dcn20_validate_dsc(dc, context)) {
1896 vba->ValidationStatus[vba->soc.num_states] = DML_FAIL_DSC_VALIDATION_FAILURE;
1897 goto validate_fail;
1898 }
1899
1900 if (repopulate_pipes)
1901 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode);
1902 context->bw_ctx.dml.vba.VoltageLevel = vlevel;
1903 *vlevel_out = vlevel;
1904 *pipe_cnt_out = pipe_cnt;
1905
1906 out = true;
1907 goto validate_out;
1908
1909 validate_fail:
1910 out = false;
1911
1912 validate_out:
1913 return out;
1914 }
1915
get_refresh_rate(struct dc_state * context)1916 static int get_refresh_rate(struct dc_state *context)
1917 {
1918 int refresh_rate = 0;
1919 int h_v_total = 0;
1920 struct dc_crtc_timing *timing = NULL;
1921
1922 if (context == NULL || context->streams[0] == NULL)
1923 return 0;
1924
1925 /* check if refresh rate at least 120hz */
1926 timing = &context->streams[0]->timing;
1927
1928 h_v_total = timing->h_total * timing->v_total;
1929 if (h_v_total == 0)
1930 return 0;
1931
1932 refresh_rate = ((timing->pix_clk_100hz * 100) / (h_v_total)) + 1;
1933 return refresh_rate;
1934 }
1935
1936 #define MAX_STRETCHED_V_BLANK 500 // in micro-seconds
1937 /*
1938 * Scaling factor for v_blank stretch calculations considering timing in
1939 * micro-seconds and pixel clock in 100hz.
1940 * Note: the parenthesis are necessary to ensure the correct order of
1941 * operation where V_SCALE is used.
1942 */
1943 #define V_SCALE (10000 / MAX_STRETCHED_V_BLANK)
1944
get_frame_rate_at_max_stretch_100hz(struct dc_state * context)1945 static int get_frame_rate_at_max_stretch_100hz(struct dc_state *context)
1946 {
1947 struct dc_crtc_timing *timing = NULL;
1948 uint32_t sec_per_100_lines;
1949 uint32_t max_v_blank;
1950 uint32_t curr_v_blank;
1951 uint32_t v_stretch_max;
1952 uint32_t stretched_frame_pix_cnt;
1953 uint32_t scaled_stretched_frame_pix_cnt;
1954 uint32_t scaled_refresh_rate;
1955
1956 if (context == NULL || context->streams[0] == NULL)
1957 return 0;
1958
1959 /* check if refresh rate at least 120hz */
1960 timing = &context->streams[0]->timing;
1961 if (timing == NULL)
1962 return 0;
1963
1964 sec_per_100_lines = timing->pix_clk_100hz / timing->h_total + 1;
1965 max_v_blank = sec_per_100_lines / V_SCALE + 1;
1966 curr_v_blank = timing->v_total - timing->v_addressable;
1967 v_stretch_max = (max_v_blank > curr_v_blank) ? (max_v_blank - curr_v_blank) : (0);
1968 stretched_frame_pix_cnt = (v_stretch_max + timing->v_total) * timing->h_total;
1969 scaled_stretched_frame_pix_cnt = stretched_frame_pix_cnt / 10000;
1970 scaled_refresh_rate = (timing->pix_clk_100hz) / scaled_stretched_frame_pix_cnt + 1;
1971
1972 return scaled_refresh_rate;
1973 }
1974
is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(struct dc_state * context)1975 static bool is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(struct dc_state *context)
1976 {
1977 int refresh_rate_max_stretch_100hz;
1978 int min_refresh_100hz;
1979
1980 if (context == NULL || context->streams[0] == NULL)
1981 return false;
1982
1983 refresh_rate_max_stretch_100hz = get_frame_rate_at_max_stretch_100hz(context);
1984 min_refresh_100hz = context->streams[0]->timing.min_refresh_in_uhz / 10000;
1985
1986 if (refresh_rate_max_stretch_100hz < min_refresh_100hz)
1987 return false;
1988
1989 return true;
1990 }
1991
dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch(struct dc * dc,struct dc_state * context)1992 bool dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context)
1993 {
1994 int refresh_rate = 0;
1995 const int minimum_refreshrate_supported = 120;
1996 struct dc_stream_status *stream_status = NULL;
1997
1998 if (context == NULL || context->streams[0] == NULL)
1999 return false;
2000
2001 if (context->streams[0]->sink->edid_caps.panel_patch.disable_fams)
2002 return false;
2003
2004 if (dc->debug.disable_fams)
2005 return false;
2006
2007 if (!dc->caps.dmub_caps.mclk_sw)
2008 return false;
2009
2010 if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching_shut_down)
2011 return false;
2012
2013 /* more then 1 monitor connected */
2014 if (context->stream_count != 1)
2015 return false;
2016
2017 refresh_rate = get_refresh_rate(context);
2018 if (refresh_rate < minimum_refreshrate_supported)
2019 return false;
2020
2021 if (!is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(context))
2022 return false;
2023
2024 if (!context->streams[0]->allow_freesync)
2025 return false;
2026
2027 if (context->streams[0]->vrr_active_variable && (dc->debug.disable_fams_gaming == INGAME_FAMS_DISABLE))
2028 return false;
2029
2030 stream_status = dc_state_get_stream_status(context, context->streams[0]);
2031
2032 if (!stream_status)
2033 return false;
2034
2035 stream_status->fpo_in_use = true;
2036
2037 return true;
2038 }
2039
2040 /*
2041 * set up FPO watermarks, pstate, dram latency
2042 */
dcn30_setup_mclk_switch_using_fw_based_vblank_stretch(struct dc * dc,struct dc_state * context)2043 void dcn30_setup_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context)
2044 {
2045 ASSERT(dc != NULL && context != NULL);
2046 if (dc == NULL || context == NULL)
2047 return;
2048
2049 /* Set wm_a.pstate so high natural MCLK switches are impossible: 4 seconds */
2050 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2051 }
2052
dcn30_update_soc_for_wm_a(struct dc * dc,struct dc_state * context)2053 void dcn30_update_soc_for_wm_a(struct dc *dc, struct dc_state *context)
2054 {
2055 DC_FP_START();
2056 dcn30_fpu_update_soc_for_wm_a(dc, context);
2057 DC_FP_END();
2058 }
2059
dcn30_calculate_wm_and_dlg(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int pipe_cnt,int vlevel)2060 void dcn30_calculate_wm_and_dlg(
2061 struct dc *dc, struct dc_state *context,
2062 display_e2e_pipe_params_st *pipes,
2063 int pipe_cnt,
2064 int vlevel)
2065 {
2066 DC_FP_START();
2067 dcn30_fpu_calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
2068 DC_FP_END();
2069 }
2070
dcn30_validate_bandwidth(struct dc * dc,struct dc_state * context,enum dc_validate_mode validate_mode)2071 enum dc_status dcn30_validate_bandwidth(struct dc *dc,
2072 struct dc_state *context,
2073 enum dc_validate_mode validate_mode)
2074 {
2075 bool out = false;
2076
2077 BW_VAL_TRACE_SETUP();
2078
2079 int vlevel = 0;
2080 int pipe_cnt = 0;
2081 display_e2e_pipe_params_st *pipes = kzalloc_objs(display_e2e_pipe_params_st,
2082 dc->res_pool->pipe_count);
2083 DC_LOGGER_INIT(dc->ctx->logger);
2084
2085 BW_VAL_TRACE_COUNT();
2086
2087 if (!pipes)
2088 goto validate_fail;
2089
2090 DC_FP_START();
2091 out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, validate_mode, true);
2092 DC_FP_END();
2093
2094 if (pipe_cnt == 0)
2095 goto validate_out;
2096
2097 if (!out)
2098 goto validate_fail;
2099
2100 BW_VAL_TRACE_END_VOLTAGE_LEVEL();
2101
2102 if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING) {
2103 BW_VAL_TRACE_SKIP(fast);
2104 goto validate_out;
2105 }
2106
2107 DC_FP_START();
2108 if (dc->res_pool->funcs->calculate_wm_and_dlg)
2109 dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
2110 DC_FP_END();
2111
2112 BW_VAL_TRACE_END_WATERMARKS();
2113
2114 goto validate_out;
2115
2116 validate_fail:
2117 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n",
2118 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states]));
2119
2120 BW_VAL_TRACE_SKIP(fail);
2121 out = false;
2122
2123 validate_out:
2124 kfree(pipes);
2125
2126 BW_VAL_TRACE_FINISH();
2127
2128 return out ? DC_OK : DC_FAIL_BANDWIDTH_VALIDATE;
2129 }
2130
dcn30_update_bw_bounding_box(struct dc * dc,struct clk_bw_params * bw_params)2131 void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
2132 {
2133 unsigned int i, j;
2134 unsigned int num_states = 0;
2135
2136 unsigned int dcfclk_mhz[DC__VOLTAGE_STATES] = {0};
2137 unsigned int dram_speed_mts[DC__VOLTAGE_STATES] = {0};
2138 unsigned int optimal_uclk_for_dcfclk_sta_targets[DC__VOLTAGE_STATES] = {0};
2139 unsigned int optimal_dcfclk_for_uclk[DC__VOLTAGE_STATES] = {0};
2140
2141 unsigned int dcfclk_sta_targets[DC__VOLTAGE_STATES] = {694, 875, 1000, 1200};
2142 unsigned int num_dcfclk_sta_targets = 4;
2143 unsigned int num_uclk_states;
2144
2145 struct dc_bounding_box_max_clk dcn30_bb_max_clk;
2146
2147 memset(&dcn30_bb_max_clk, 0, sizeof(dcn30_bb_max_clk));
2148
2149 if (dc->ctx->dc_bios->vram_info.num_chans)
2150 dcn3_0_soc.num_chans = dc->ctx->dc_bios->vram_info.num_chans;
2151
2152 DC_FP_START();
2153 dcn30_fpu_update_dram_channel_width_bytes(dc);
2154 DC_FP_END();
2155
2156 if (bw_params->clk_table.entries[0].memclk_mhz) {
2157
2158 for (i = 0; i < MAX_NUM_DPM_LVL; i++) {
2159 if (bw_params->clk_table.entries[i].dcfclk_mhz > dcn30_bb_max_clk.max_dcfclk_mhz)
2160 dcn30_bb_max_clk.max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz;
2161 if (bw_params->clk_table.entries[i].dispclk_mhz > dcn30_bb_max_clk.max_dispclk_mhz)
2162 dcn30_bb_max_clk.max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz;
2163 if (bw_params->clk_table.entries[i].dppclk_mhz > dcn30_bb_max_clk.max_dppclk_mhz)
2164 dcn30_bb_max_clk.max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz;
2165 if (bw_params->clk_table.entries[i].phyclk_mhz > dcn30_bb_max_clk.max_phyclk_mhz)
2166 dcn30_bb_max_clk.max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz;
2167 }
2168
2169 DC_FP_START();
2170 dcn30_fpu_update_max_clk(&dcn30_bb_max_clk);
2171 DC_FP_END();
2172
2173 if (dcn30_bb_max_clk.max_dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) {
2174 // If max DCFCLK is greater than the max DCFCLK STA target, insert into the DCFCLK STA target array
2175 dcfclk_sta_targets[num_dcfclk_sta_targets] = dcn30_bb_max_clk.max_dcfclk_mhz;
2176 num_dcfclk_sta_targets++;
2177 } else if (dcn30_bb_max_clk.max_dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) {
2178 // If max DCFCLK is less than the max DCFCLK STA target, cap values and remove duplicates
2179 for (i = 0; i < num_dcfclk_sta_targets; i++) {
2180 if (dcfclk_sta_targets[i] > dcn30_bb_max_clk.max_dcfclk_mhz) {
2181 dcfclk_sta_targets[i] = dcn30_bb_max_clk.max_dcfclk_mhz;
2182 break;
2183 }
2184 }
2185 // Update size of array since we "removed" duplicates
2186 num_dcfclk_sta_targets = i + 1;
2187 }
2188
2189 num_uclk_states = bw_params->clk_table.num_entries;
2190
2191 // Calculate optimal dcfclk for each uclk
2192 for (i = 0; i < num_uclk_states; i++) {
2193 DC_FP_START();
2194 dcn30_fpu_get_optimal_dcfclk_fclk_for_uclk(bw_params->clk_table.entries[i].memclk_mhz * 16,
2195 &optimal_dcfclk_for_uclk[i], NULL);
2196 DC_FP_END();
2197 if (optimal_dcfclk_for_uclk[i] < bw_params->clk_table.entries[0].dcfclk_mhz) {
2198 optimal_dcfclk_for_uclk[i] = bw_params->clk_table.entries[0].dcfclk_mhz;
2199 }
2200 }
2201
2202 // Calculate optimal uclk for each dcfclk sta target
2203 for (i = 0; i < num_dcfclk_sta_targets; i++) {
2204 for (j = 0; j < num_uclk_states; j++) {
2205 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) {
2206 optimal_uclk_for_dcfclk_sta_targets[i] =
2207 bw_params->clk_table.entries[j].memclk_mhz * 16;
2208 break;
2209 } else {
2210 /* condition where (dcfclk_sta_targets[i] >= optimal_dcfclk_for_uclk[j]):
2211 * If it just so happens that the memory bandwidth is low enough such that
2212 * all the optimal DCFCLK for each UCLK is lower than the smallest DCFCLK STA
2213 * target, we need to populate the optimal UCLK for each DCFCLK STA target to
2214 * be the max UCLK.
2215 */
2216 if (j == num_uclk_states - 1) {
2217 optimal_uclk_for_dcfclk_sta_targets[i] =
2218 bw_params->clk_table.entries[j].memclk_mhz * 16;
2219 }
2220 }
2221 }
2222 }
2223
2224 i = 0;
2225 j = 0;
2226 // create the final dcfclk and uclk table
2227 while (i < num_dcfclk_sta_targets && j < num_uclk_states && num_states < DC__VOLTAGE_STATES) {
2228 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) {
2229 dcfclk_mhz[num_states] = dcfclk_sta_targets[i];
2230 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++];
2231 } else {
2232 if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) {
2233 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j];
2234 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16;
2235 } else {
2236 j = num_uclk_states;
2237 }
2238 }
2239 }
2240
2241 while (i < num_dcfclk_sta_targets && num_states < DC__VOLTAGE_STATES) {
2242 dcfclk_mhz[num_states] = dcfclk_sta_targets[i];
2243 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++];
2244 }
2245
2246 while (j < num_uclk_states && num_states < DC__VOLTAGE_STATES &&
2247 optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) {
2248 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j];
2249 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16;
2250 }
2251
2252 dcn3_0_soc.num_states = num_states;
2253 DC_FP_START();
2254 dcn30_fpu_update_bw_bounding_box(dc, bw_params, &dcn30_bb_max_clk, dcfclk_mhz, dram_speed_mts);
2255 DC_FP_END();
2256 }
2257 }
2258
dcn30_get_panel_config_defaults(struct dc_panel_config * panel_config)2259 static void dcn30_get_panel_config_defaults(struct dc_panel_config *panel_config)
2260 {
2261 *panel_config = panel_config_defaults;
2262 }
2263
2264 static const struct resource_funcs dcn30_res_pool_funcs = {
2265 .destroy = dcn30_destroy_resource_pool,
2266 .link_enc_create = dcn30_link_encoder_create,
2267 .panel_cntl_create = dcn30_panel_cntl_create,
2268 .validate_bandwidth = dcn30_validate_bandwidth,
2269 .calculate_wm_and_dlg = dcn30_calculate_wm_and_dlg,
2270 .update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
2271 .populate_dml_pipes = dcn30_populate_dml_pipes_from_context,
2272 .acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
2273 .release_pipe = dcn20_release_pipe,
2274 .add_stream_to_ctx = dcn30_add_stream_to_ctx,
2275 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
2276 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
2277 .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
2278 .set_mcif_arb_params = dcn30_set_mcif_arb_params,
2279 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
2280 .acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut,
2281 .release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut,
2282 .update_bw_bounding_box = dcn30_update_bw_bounding_box,
2283 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
2284 .get_panel_config_defaults = dcn30_get_panel_config_defaults,
2285 .get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe
2286 };
2287
2288 #define CTX ctx
2289
2290 #define REG(reg_name) \
2291 (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
2292
read_pipe_fuses(struct dc_context * ctx)2293 static uint32_t read_pipe_fuses(struct dc_context *ctx)
2294 {
2295 uint32_t value = REG_READ(CC_DC_PIPE_DIS);
2296 /* Support for max 6 pipes */
2297 value = value & 0x3f;
2298 return value;
2299 }
2300
dcn30_resource_construct(uint8_t num_virtual_links,struct dc * dc,struct dcn30_resource_pool * pool)2301 static bool dcn30_resource_construct(
2302 uint8_t num_virtual_links,
2303 struct dc *dc,
2304 struct dcn30_resource_pool *pool)
2305 {
2306 int i;
2307 struct dc_context *ctx = dc->ctx;
2308 struct irq_service_init_data init_data;
2309 struct ddc_service_init_data ddc_init_data = {0};
2310 uint32_t pipe_fuses = read_pipe_fuses(ctx);
2311 uint32_t num_pipes = 0;
2312
2313 if (!(pipe_fuses == 0 || pipe_fuses == 0x3e)) {
2314 BREAK_TO_DEBUGGER();
2315 dm_error("DC: Unexpected fuse recipe for navi2x !\n");
2316 /* fault to single pipe */
2317 pipe_fuses = 0x3e;
2318 }
2319
2320 DC_FP_START();
2321
2322 ctx->dc_bios->regs = &bios_regs;
2323
2324 pool->base.res_cap = &res_cap_dcn3;
2325
2326 pool->base.funcs = &dcn30_res_pool_funcs;
2327
2328 /*************************************************
2329 * Resource + asic cap harcoding *
2330 *************************************************/
2331 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
2332 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
2333 pool->base.mpcc_count = pool->base.res_cap->num_timing_generator;
2334 dc->caps.max_downscale_ratio = 600;
2335 dc->caps.i2c_speed_in_khz = 100;
2336 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/
2337 dc->caps.max_cursor_size = 256;
2338 dc->caps.min_horizontal_blanking_period = 80;
2339 dc->caps.dmdata_alloc_size = 2048;
2340 dc->caps.mall_size_per_mem_channel = 8;
2341 /* total size = mall per channel * num channels * 1024 * 1024 */
2342 dc->caps.mall_size_total = dc->caps.mall_size_per_mem_channel * dc->ctx->dc_bios->vram_info.num_chans * 1048576;
2343 dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
2344
2345 dc->caps.max_slave_planes = 2;
2346 dc->caps.max_slave_yuv_planes = 2;
2347 dc->caps.max_slave_rgb_planes = 2;
2348 dc->caps.post_blend_color_processing = true;
2349 dc->caps.force_dp_tps4_for_cp2520 = true;
2350 dc->caps.extended_aux_timeout_support = true;
2351 dc->caps.dmcub_support = true;
2352
2353 /* Color pipeline capabilities */
2354 dc->caps.color.dpp.dcn_arch = 1;
2355 dc->caps.color.dpp.input_lut_shared = 0;
2356 dc->caps.color.dpp.icsc = 1;
2357 dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
2358 dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2359 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2360 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
2361 dc->caps.color.dpp.dgam_rom_caps.pq = 1;
2362 dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
2363 dc->caps.color.dpp.post_csc = 1;
2364 dc->caps.color.dpp.gamma_corr = 1;
2365 dc->caps.color.dpp.dgam_rom_for_yuv = 0;
2366
2367 dc->caps.color.dpp.hw_3d_lut = 1;
2368 dc->caps.color.dpp.ogam_ram = 1;
2369 // no OGAM ROM on DCN3
2370 dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2371 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2372 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2373 dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2374 dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2375 dc->caps.color.dpp.ocsc = 0;
2376
2377 dc->caps.color.mpc.gamut_remap = 1;
2378 dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //3
2379 dc->caps.color.mpc.ogam_ram = 1;
2380 dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2381 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2382 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2383 dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2384 dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2385 dc->caps.color.mpc.ocsc = 1;
2386
2387 dc->caps.dp_hdmi21_pcon_support = true;
2388 dc->caps.max_v_total = (1 << 15) - 1;
2389 dc->caps.vtotal_limited_by_fp2 = true;
2390
2391 /* read VBIOS LTTPR caps */
2392 {
2393 if (ctx->dc_bios->funcs->get_lttpr_caps) {
2394 enum bp_result bp_query_result;
2395 uint8_t is_vbios_lttpr_enable = 0;
2396
2397 bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
2398 dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
2399 }
2400
2401 if (ctx->dc_bios->funcs->get_lttpr_interop) {
2402 enum bp_result bp_query_result;
2403 uint8_t is_vbios_interop_enabled = 0;
2404
2405 bp_query_result = ctx->dc_bios->funcs->get_lttpr_interop(ctx->dc_bios,
2406 &is_vbios_interop_enabled);
2407 dc->caps.vbios_lttpr_aware = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled;
2408 }
2409 }
2410 dc->check_config = config_defaults;
2411
2412 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
2413 dc->debug = debug_defaults_drv;
2414
2415 // Init the vm_helper
2416 if (dc->vm_helper)
2417 vm_helper_init(dc->vm_helper, 16);
2418
2419 /*************************************************
2420 * Create resources *
2421 *************************************************/
2422
2423 /* Clock Sources for Pixel Clock*/
2424 pool->base.clock_sources[DCN30_CLK_SRC_PLL0] =
2425 dcn30_clock_source_create(ctx, ctx->dc_bios,
2426 CLOCK_SOURCE_COMBO_PHY_PLL0,
2427 &clk_src_regs[0], false);
2428 pool->base.clock_sources[DCN30_CLK_SRC_PLL1] =
2429 dcn30_clock_source_create(ctx, ctx->dc_bios,
2430 CLOCK_SOURCE_COMBO_PHY_PLL1,
2431 &clk_src_regs[1], false);
2432 pool->base.clock_sources[DCN30_CLK_SRC_PLL2] =
2433 dcn30_clock_source_create(ctx, ctx->dc_bios,
2434 CLOCK_SOURCE_COMBO_PHY_PLL2,
2435 &clk_src_regs[2], false);
2436 pool->base.clock_sources[DCN30_CLK_SRC_PLL3] =
2437 dcn30_clock_source_create(ctx, ctx->dc_bios,
2438 CLOCK_SOURCE_COMBO_PHY_PLL3,
2439 &clk_src_regs[3], false);
2440 pool->base.clock_sources[DCN30_CLK_SRC_PLL4] =
2441 dcn30_clock_source_create(ctx, ctx->dc_bios,
2442 CLOCK_SOURCE_COMBO_PHY_PLL4,
2443 &clk_src_regs[4], false);
2444 pool->base.clock_sources[DCN30_CLK_SRC_PLL5] =
2445 dcn30_clock_source_create(ctx, ctx->dc_bios,
2446 CLOCK_SOURCE_COMBO_PHY_PLL5,
2447 &clk_src_regs[5], false);
2448
2449 pool->base.clk_src_count = DCN30_CLK_SRC_TOTAL;
2450
2451 /* todo: not reuse phy_pll registers */
2452 pool->base.dp_clock_source =
2453 dcn30_clock_source_create(ctx, ctx->dc_bios,
2454 CLOCK_SOURCE_ID_DP_DTO,
2455 &clk_src_regs[0], true);
2456
2457 for (i = 0; i < pool->base.clk_src_count; i++) {
2458 if (pool->base.clock_sources[i] == NULL) {
2459 dm_error("DC: failed to create clock sources!\n");
2460 BREAK_TO_DEBUGGER();
2461 goto create_fail;
2462 }
2463 }
2464
2465 /* DCCG */
2466 pool->base.dccg = dccg30_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
2467 if (pool->base.dccg == NULL) {
2468 dm_error("DC: failed to create dccg!\n");
2469 BREAK_TO_DEBUGGER();
2470 goto create_fail;
2471 }
2472
2473 /* PP Lib and SMU interfaces */
2474 init_soc_bounding_box(dc, pool);
2475
2476 num_pipes = dcn3_0_ip.max_num_dpp;
2477
2478 for (i = 0; i < dcn3_0_ip.max_num_dpp; i++)
2479 if (pipe_fuses & 1 << i)
2480 num_pipes--;
2481
2482 dcn3_0_ip.max_num_dpp = num_pipes;
2483 dcn3_0_ip.max_num_otg = num_pipes;
2484
2485 dml_init_instance(&dc->dml, &dcn3_0_soc, &dcn3_0_ip, DML_PROJECT_DCN30);
2486
2487 /* IRQ */
2488 init_data.ctx = dc->ctx;
2489 pool->base.irqs = dal_irq_service_dcn30_create(&init_data);
2490 if (!pool->base.irqs)
2491 goto create_fail;
2492
2493 /* HUBBUB */
2494 pool->base.hubbub = dcn30_hubbub_create(ctx);
2495 if (pool->base.hubbub == NULL) {
2496 BREAK_TO_DEBUGGER();
2497 dm_error("DC: failed to create hubbub!\n");
2498 goto create_fail;
2499 }
2500
2501 /* DIO */
2502 pool->base.dio = dcn30_dio_create(ctx);
2503 if (pool->base.dio == NULL) {
2504 BREAK_TO_DEBUGGER();
2505 dm_error("DC: failed to create dio!\n");
2506 goto create_fail;
2507 }
2508
2509 /* HUBPs, DPPs, OPPs and TGs */
2510 for (i = 0; i < pool->base.pipe_count; i++) {
2511 pool->base.hubps[i] = dcn30_hubp_create(ctx, i);
2512 if (pool->base.hubps[i] == NULL) {
2513 BREAK_TO_DEBUGGER();
2514 dm_error(
2515 "DC: failed to create hubps!\n");
2516 goto create_fail;
2517 }
2518
2519 pool->base.dpps[i] = dcn30_dpp_create(ctx, i);
2520 if (pool->base.dpps[i] == NULL) {
2521 BREAK_TO_DEBUGGER();
2522 dm_error(
2523 "DC: failed to create dpps!\n");
2524 goto create_fail;
2525 }
2526 }
2527
2528 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
2529 pool->base.opps[i] = dcn30_opp_create(ctx, i);
2530 if (pool->base.opps[i] == NULL) {
2531 BREAK_TO_DEBUGGER();
2532 dm_error(
2533 "DC: failed to create output pixel processor!\n");
2534 goto create_fail;
2535 }
2536 }
2537
2538 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2539 pool->base.timing_generators[i] = dcn30_timing_generator_create(
2540 ctx, i);
2541 if (pool->base.timing_generators[i] == NULL) {
2542 BREAK_TO_DEBUGGER();
2543 dm_error("DC: failed to create tg!\n");
2544 goto create_fail;
2545 }
2546 }
2547 pool->base.timing_generator_count = i;
2548 /* PSR */
2549 pool->base.psr = dmub_psr_create(ctx);
2550
2551 if (pool->base.psr == NULL) {
2552 dm_error("DC: failed to create PSR obj!\n");
2553 BREAK_TO_DEBUGGER();
2554 goto create_fail;
2555 }
2556
2557 /* ABM */
2558 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2559 pool->base.multiple_abms[i] = dmub_abm_create(ctx,
2560 &abm_regs[i],
2561 &abm_shift,
2562 &abm_mask);
2563 if (pool->base.multiple_abms[i] == NULL) {
2564 dm_error("DC: failed to create abm for pipe %d!\n", i);
2565 BREAK_TO_DEBUGGER();
2566 goto create_fail;
2567 }
2568 }
2569 /* MPC and DSC */
2570 pool->base.mpc = dcn30_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut);
2571 if (pool->base.mpc == NULL) {
2572 BREAK_TO_DEBUGGER();
2573 dm_error("DC: failed to create mpc!\n");
2574 goto create_fail;
2575 }
2576
2577 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2578 pool->base.dscs[i] = dcn30_dsc_create(ctx, i);
2579 if (pool->base.dscs[i] == NULL) {
2580 BREAK_TO_DEBUGGER();
2581 dm_error("DC: failed to create display stream compressor %d!\n", i);
2582 goto create_fail;
2583 }
2584 }
2585
2586 /* DWB and MMHUBBUB */
2587 if (!dcn30_dwbc_create(ctx, &pool->base)) {
2588 BREAK_TO_DEBUGGER();
2589 dm_error("DC: failed to create dwbc!\n");
2590 goto create_fail;
2591 }
2592
2593 if (!dcn30_mmhubbub_create(ctx, &pool->base)) {
2594 BREAK_TO_DEBUGGER();
2595 dm_error("DC: failed to create mcif_wb!\n");
2596 goto create_fail;
2597 }
2598
2599 /* AUX and I2C */
2600 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2601 pool->base.engines[i] = dcn30_aux_engine_create(ctx, i);
2602 if (pool->base.engines[i] == NULL) {
2603 BREAK_TO_DEBUGGER();
2604 dm_error(
2605 "DC:failed to create aux engine!!\n");
2606 goto create_fail;
2607 }
2608 pool->base.hw_i2cs[i] = dcn30_i2c_hw_create(ctx, i);
2609 if (pool->base.hw_i2cs[i] == NULL) {
2610 BREAK_TO_DEBUGGER();
2611 dm_error(
2612 "DC:failed to create hw i2c!!\n");
2613 goto create_fail;
2614 }
2615 pool->base.sw_i2cs[i] = NULL;
2616 }
2617
2618 /* Audio, Stream Encoders including HPO and virtual, MPC 3D LUTs */
2619 if (!resource_construct(num_virtual_links, dc, &pool->base,
2620 &res_create_funcs))
2621 goto create_fail;
2622
2623 /* HW Sequencer and Plane caps */
2624 dcn30_hw_sequencer_construct(dc);
2625
2626 dc->caps.max_planes = pool->base.pipe_count;
2627
2628 for (i = 0; i < dc->caps.max_planes; ++i)
2629 dc->caps.planes[i] = plane_cap;
2630
2631 dc->caps.max_odm_combine_factor = 4;
2632
2633 dc->cap_funcs = cap_funcs;
2634
2635 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2636 ddc_init_data.ctx = dc->ctx;
2637 ddc_init_data.link = NULL;
2638 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2639 ddc_init_data.id.enum_id = 0;
2640 ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2641 pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2642 } else {
2643 pool->base.oem_device = NULL;
2644 }
2645
2646 DC_FP_END();
2647
2648 return true;
2649
2650 create_fail:
2651
2652 DC_FP_END();
2653 dcn30_resource_destruct(pool);
2654
2655 return false;
2656 }
2657
dcn30_create_resource_pool(const struct dc_init_data * init_data,struct dc * dc)2658 struct resource_pool *dcn30_create_resource_pool(
2659 const struct dc_init_data *init_data,
2660 struct dc *dc)
2661 {
2662 struct dcn30_resource_pool *pool =
2663 kzalloc_obj(struct dcn30_resource_pool);
2664
2665 if (!pool)
2666 return NULL;
2667
2668 if (dcn30_resource_construct(init_data->num_virtual_links, dc, pool))
2669 return &pool->base;
2670
2671 BREAK_TO_DEBUGGER();
2672 kfree(pool);
2673 return NULL;
2674 }
2675