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 (void)ctx;
956 struct dcn20_link_encoder *enc20 =
957 kzalloc_obj(struct dcn20_link_encoder);
958
959 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
960 return NULL;
961
962 dcn30_link_encoder_construct(enc20,
963 enc_init_data,
964 &link_enc_feature,
965 &link_enc_regs[enc_init_data->transmitter],
966 &link_enc_aux_regs[enc_init_data->channel - 1],
967 &link_enc_hpd_regs[enc_init_data->hpd_source],
968 &le_shift,
969 &le_mask);
970
971 return &enc20->enc10.base;
972 }
973
dcn30_panel_cntl_create(const struct panel_cntl_init_data * init_data)974 static struct panel_cntl *dcn30_panel_cntl_create(const struct panel_cntl_init_data *init_data)
975 {
976 struct dce_panel_cntl *panel_cntl =
977 kzalloc_obj(struct dce_panel_cntl);
978
979 if (!panel_cntl)
980 return NULL;
981
982 dce_panel_cntl_construct(panel_cntl,
983 init_data,
984 &panel_cntl_regs[init_data->inst],
985 &panel_cntl_shift,
986 &panel_cntl_mask);
987
988 return &panel_cntl->base;
989 }
990
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)991 static void read_dce_straps(
992 struct dc_context *ctx,
993 struct resource_straps *straps)
994 {
995 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
996 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
997
998 }
999
dcn30_create_audio(struct dc_context * ctx,unsigned int inst)1000 static struct audio *dcn30_create_audio(
1001 struct dc_context *ctx, unsigned int inst)
1002 {
1003 return dce_audio_create(ctx, inst,
1004 &audio_regs[inst], &audio_shift, &audio_mask);
1005 }
1006
dcn30_vpg_create(struct dc_context * ctx,uint32_t inst)1007 static struct vpg *dcn30_vpg_create(
1008 struct dc_context *ctx,
1009 uint32_t inst)
1010 {
1011 struct dcn30_vpg *vpg3 = kzalloc_obj(struct dcn30_vpg);
1012
1013 if (!vpg3)
1014 return NULL;
1015
1016 vpg3_construct(vpg3, ctx, inst,
1017 &vpg_regs[inst],
1018 &vpg_shift,
1019 &vpg_mask);
1020
1021 return &vpg3->base;
1022 }
1023
dcn30_afmt_create(struct dc_context * ctx,uint32_t inst)1024 static struct afmt *dcn30_afmt_create(
1025 struct dc_context *ctx,
1026 uint32_t inst)
1027 {
1028 struct dcn30_afmt *afmt3 = kzalloc_obj(struct dcn30_afmt);
1029
1030 if (!afmt3)
1031 return NULL;
1032
1033 afmt3_construct(afmt3, ctx, inst,
1034 &afmt_regs[inst],
1035 &afmt_shift,
1036 &afmt_mask);
1037
1038 return &afmt3->base;
1039 }
1040
dcn30_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1041 static struct stream_encoder *dcn30_stream_encoder_create(enum engine_id eng_id,
1042 struct dc_context *ctx)
1043 {
1044 struct dcn10_stream_encoder *enc1;
1045 struct vpg *vpg;
1046 struct afmt *afmt;
1047 int vpg_inst;
1048 int afmt_inst;
1049
1050 /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1051 if (eng_id <= ENGINE_ID_DIGF) {
1052 vpg_inst = eng_id;
1053 afmt_inst = eng_id;
1054 } else
1055 return NULL;
1056
1057 enc1 = kzalloc_obj(struct dcn10_stream_encoder);
1058 vpg = dcn30_vpg_create(ctx, vpg_inst);
1059 afmt = dcn30_afmt_create(ctx, afmt_inst);
1060
1061 if (!enc1 || !vpg || !afmt) {
1062 kfree(enc1);
1063 kfree(vpg);
1064 kfree(afmt);
1065 return NULL;
1066 }
1067
1068 dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1069 eng_id, vpg, afmt,
1070 &stream_enc_regs[eng_id],
1071 &se_shift, &se_mask);
1072
1073 return &enc1->base;
1074 }
1075
dcn30_hwseq_create(struct dc_context * ctx)1076 static struct dce_hwseq *dcn30_hwseq_create(struct dc_context *ctx)
1077 {
1078 struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq);
1079
1080 if (hws) {
1081 hws->ctx = ctx;
1082 hws->regs = &hwseq_reg;
1083 hws->shifts = &hwseq_shift;
1084 hws->masks = &hwseq_mask;
1085 }
1086 return hws;
1087 }
1088 static const struct resource_create_funcs res_create_funcs = {
1089 .read_dce_straps = read_dce_straps,
1090 .create_audio = dcn30_create_audio,
1091 .create_stream_encoder = dcn30_stream_encoder_create,
1092 .create_hwseq = dcn30_hwseq_create,
1093 };
1094
dcn30_resource_destruct(struct dcn30_resource_pool * pool)1095 static void dcn30_resource_destruct(struct dcn30_resource_pool *pool)
1096 {
1097 unsigned int i;
1098
1099 for (i = 0; i < pool->base.stream_enc_count; i++) {
1100 if (pool->base.stream_enc[i] != NULL) {
1101 if (pool->base.stream_enc[i]->vpg != NULL) {
1102 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1103 pool->base.stream_enc[i]->vpg = NULL;
1104 }
1105 if (pool->base.stream_enc[i]->afmt != NULL) {
1106 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1107 pool->base.stream_enc[i]->afmt = NULL;
1108 }
1109 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1110 pool->base.stream_enc[i] = NULL;
1111 }
1112 }
1113
1114 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1115 if (pool->base.dscs[i] != NULL)
1116 dcn20_dsc_destroy(&pool->base.dscs[i]);
1117 }
1118
1119 if (pool->base.mpc != NULL) {
1120 kfree(TO_DCN20_MPC(pool->base.mpc));
1121 pool->base.mpc = NULL;
1122 }
1123 if (pool->base.hubbub != NULL) {
1124 kfree(pool->base.hubbub);
1125 pool->base.hubbub = NULL;
1126 }
1127
1128 if (pool->base.dio != NULL) {
1129 kfree(TO_DCN10_DIO(pool->base.dio));
1130 pool->base.dio = NULL;
1131 }
1132
1133 for (i = 0; i < pool->base.pipe_count; i++) {
1134 if (pool->base.dpps[i] != NULL)
1135 dcn30_dpp_destroy(&pool->base.dpps[i]);
1136
1137 if (pool->base.ipps[i] != NULL)
1138 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1139
1140 if (pool->base.hubps[i] != NULL) {
1141 kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1142 pool->base.hubps[i] = NULL;
1143 }
1144
1145 if (pool->base.irqs != NULL) {
1146 dal_irq_service_destroy(&pool->base.irqs);
1147 }
1148 }
1149
1150 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1151 if (pool->base.engines[i] != NULL)
1152 dce110_engine_destroy(&pool->base.engines[i]);
1153 if (pool->base.hw_i2cs[i] != NULL) {
1154 kfree(pool->base.hw_i2cs[i]);
1155 pool->base.hw_i2cs[i] = NULL;
1156 }
1157 if (pool->base.sw_i2cs[i] != NULL) {
1158 kfree(pool->base.sw_i2cs[i]);
1159 pool->base.sw_i2cs[i] = NULL;
1160 }
1161 }
1162
1163 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1164 if (pool->base.opps[i] != NULL)
1165 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1166 }
1167
1168 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1169 if (pool->base.timing_generators[i] != NULL) {
1170 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1171 pool->base.timing_generators[i] = NULL;
1172 }
1173 }
1174
1175 for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1176 if (pool->base.dwbc[i] != NULL) {
1177 kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1178 pool->base.dwbc[i] = NULL;
1179 }
1180 if (pool->base.mcif_wb[i] != NULL) {
1181 kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1182 pool->base.mcif_wb[i] = NULL;
1183 }
1184 }
1185
1186 for (i = 0; i < pool->base.audio_count; i++) {
1187 if (pool->base.audios[i])
1188 dce_aud_destroy(&pool->base.audios[i]);
1189 }
1190
1191 for (i = 0; i < pool->base.clk_src_count; i++) {
1192 if (pool->base.clock_sources[i] != NULL) {
1193 dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1194 pool->base.clock_sources[i] = NULL;
1195 }
1196 }
1197
1198 for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1199 if (pool->base.mpc_lut[i] != NULL) {
1200 dc_3dlut_func_release(pool->base.mpc_lut[i]);
1201 pool->base.mpc_lut[i] = NULL;
1202 }
1203 if (pool->base.mpc_shaper[i] != NULL) {
1204 dc_transfer_func_release(pool->base.mpc_shaper[i]);
1205 pool->base.mpc_shaper[i] = NULL;
1206 }
1207 }
1208
1209 if (pool->base.dp_clock_source != NULL) {
1210 dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1211 pool->base.dp_clock_source = NULL;
1212 }
1213
1214 for (i = 0; i < pool->base.pipe_count; i++) {
1215 if (pool->base.multiple_abms[i] != NULL)
1216 dce_abm_destroy(&pool->base.multiple_abms[i]);
1217 }
1218
1219 if (pool->base.psr != NULL)
1220 dmub_psr_destroy(&pool->base.psr);
1221
1222 if (pool->base.dccg != NULL)
1223 dcn_dccg_destroy(&pool->base.dccg);
1224
1225 if (pool->base.oem_device != NULL) {
1226 struct dc *dc = pool->base.oem_device->ctx->dc;
1227
1228 dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1229 }
1230 }
1231
dcn30_hubp_create(struct dc_context * ctx,uint32_t inst)1232 static struct hubp *dcn30_hubp_create(
1233 struct dc_context *ctx,
1234 uint32_t inst)
1235 {
1236 struct dcn20_hubp *hubp2 =
1237 kzalloc_obj(struct dcn20_hubp);
1238
1239 if (!hubp2)
1240 return NULL;
1241
1242 if (hubp3_construct(hubp2, ctx, inst,
1243 &hubp_regs[inst], &hubp_shift, &hubp_mask))
1244 return &hubp2->base;
1245
1246 BREAK_TO_DEBUGGER();
1247 kfree(hubp2);
1248 return NULL;
1249 }
1250
dcn30_dwbc_create(struct dc_context * ctx,struct resource_pool * pool)1251 static bool dcn30_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1252 {
1253 int i;
1254 uint32_t pipe_count = pool->res_cap->num_dwb;
1255
1256 for (i = 0; i < pipe_count; i++) {
1257 struct dcn30_dwbc *dwbc30 = kzalloc_obj(struct dcn30_dwbc);
1258
1259 if (!dwbc30) {
1260 dm_error("DC: failed to create dwbc30!\n");
1261 return false;
1262 }
1263
1264 dcn30_dwbc_construct(dwbc30, ctx,
1265 &dwbc30_regs[i],
1266 &dwbc30_shift,
1267 &dwbc30_mask,
1268 i);
1269
1270 pool->dwbc[i] = &dwbc30->base;
1271 }
1272 return true;
1273 }
1274
dcn30_mmhubbub_create(struct dc_context * ctx,struct resource_pool * pool)1275 static bool dcn30_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1276 {
1277 int i;
1278 uint32_t pipe_count = pool->res_cap->num_dwb;
1279
1280 for (i = 0; i < pipe_count; i++) {
1281 struct dcn30_mmhubbub *mcif_wb30 = kzalloc_obj(struct dcn30_mmhubbub);
1282
1283 if (!mcif_wb30) {
1284 dm_error("DC: failed to create mcif_wb30!\n");
1285 return false;
1286 }
1287
1288 dcn30_mmhubbub_construct(mcif_wb30, ctx,
1289 &mcif_wb30_regs[i],
1290 &mcif_wb30_shift,
1291 &mcif_wb30_mask,
1292 i);
1293
1294 pool->mcif_wb[i] = &mcif_wb30->base;
1295 }
1296 return true;
1297 }
1298
dcn30_dsc_create(struct dc_context * ctx,uint32_t inst)1299 static struct display_stream_compressor *dcn30_dsc_create(
1300 struct dc_context *ctx, uint32_t inst)
1301 {
1302 struct dcn20_dsc *dsc =
1303 kzalloc_obj(struct dcn20_dsc);
1304
1305 if (!dsc) {
1306 BREAK_TO_DEBUGGER();
1307 return NULL;
1308 }
1309
1310 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1311 return &dsc->base;
1312 }
1313
dcn30_add_stream_to_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)1314 enum dc_status dcn30_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
1315 {
1316
1317 return dcn20_add_stream_to_ctx(dc, new_ctx, dc_stream);
1318 }
1319
dcn30_destroy_resource_pool(struct resource_pool ** pool)1320 static void dcn30_destroy_resource_pool(struct resource_pool **pool)
1321 {
1322 struct dcn30_resource_pool *dcn30_pool = TO_DCN30_RES_POOL(*pool);
1323
1324 dcn30_resource_destruct(dcn30_pool);
1325 kfree(dcn30_pool);
1326 *pool = NULL;
1327 }
1328
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)1329 static struct clock_source *dcn30_clock_source_create(
1330 struct dc_context *ctx,
1331 struct dc_bios *bios,
1332 enum clock_source_id id,
1333 const struct dce110_clk_src_regs *regs,
1334 bool dp_clk_src)
1335 {
1336 struct dce110_clk_src *clk_src =
1337 kzalloc_obj(struct dce110_clk_src);
1338
1339 if (!clk_src)
1340 return NULL;
1341
1342 if (dcn3_clk_src_construct(clk_src, ctx, bios, id,
1343 regs, &cs_shift, &cs_mask)) {
1344 clk_src->base.dp_clk_src = dp_clk_src;
1345 return &clk_src->base;
1346 }
1347
1348 kfree(clk_src);
1349 BREAK_TO_DEBUGGER();
1350 return NULL;
1351 }
1352
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)1353 int dcn30_populate_dml_pipes_from_context(
1354 struct dc *dc, struct dc_state *context,
1355 display_e2e_pipe_params_st *pipes,
1356 enum dc_validate_mode validate_mode)
1357 {
1358 int i, pipe_cnt;
1359 struct resource_context *res_ctx = &context->res_ctx;
1360
1361 DC_FP_START();
1362 dcn20_populate_dml_pipes_from_context(dc, context, pipes, validate_mode);
1363 DC_FP_END();
1364
1365 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1366 if (!res_ctx->pipe_ctx[i].stream)
1367 continue;
1368
1369 pipes[pipe_cnt++].pipe.scale_ratio_depth.lb_depth =
1370 dm_lb_16;
1371 }
1372
1373 return pipe_cnt;
1374 }
1375
dcn30_populate_dml_writeback_from_context(struct dc * dc,struct resource_context * res_ctx,display_e2e_pipe_params_st * pipes)1376 void dcn30_populate_dml_writeback_from_context(
1377 struct dc *dc, struct resource_context *res_ctx, display_e2e_pipe_params_st *pipes)
1378 {
1379 DC_FP_START();
1380 dcn30_fpu_populate_dml_writeback_from_context(dc, res_ctx, pipes);
1381 DC_FP_END();
1382 }
1383
dcn30_calc_max_scaled_time(unsigned int time_per_pixel,enum mmhubbub_wbif_mode mode,unsigned int urgent_watermark)1384 unsigned int dcn30_calc_max_scaled_time(
1385 unsigned int time_per_pixel,
1386 enum mmhubbub_wbif_mode mode,
1387 unsigned int urgent_watermark)
1388 {
1389 unsigned int time_per_byte = 0;
1390 unsigned int total_free_entry = 0xb40;
1391 unsigned int buf_lh_capability;
1392 unsigned int max_scaled_time;
1393
1394 if (mode == PACKED_444) /* packed mode 32 bpp */
1395 time_per_byte = time_per_pixel/4;
1396 else if (mode == PACKED_444_FP16) /* packed mode 64 bpp */
1397 time_per_byte = time_per_pixel/8;
1398
1399 if (time_per_byte == 0)
1400 time_per_byte = 1;
1401
1402 buf_lh_capability = (total_free_entry*time_per_byte*32) >> 6; /* time_per_byte is in u6.6*/
1403 max_scaled_time = buf_lh_capability - urgent_watermark;
1404 return max_scaled_time;
1405 }
1406
dcn30_set_mcif_arb_params(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int pipe_cnt)1407 void dcn30_set_mcif_arb_params(
1408 struct dc *dc,
1409 struct dc_state *context,
1410 display_e2e_pipe_params_st *pipes,
1411 int pipe_cnt)
1412 {
1413 enum mmhubbub_wbif_mode wbif_mode;
1414 struct display_mode_lib *dml = &context->bw_ctx.dml;
1415 struct mcif_arb_params *wb_arb_params;
1416 int i, j, dwb_pipe;
1417
1418 /* Writeback MCIF_WB arbitration parameters */
1419 dwb_pipe = 0;
1420 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1421
1422 if (!context->res_ctx.pipe_ctx[i].stream)
1423 continue;
1424
1425 for (j = 0; j < MAX_DWB_PIPES; j++) {
1426 struct dc_writeback_info *writeback_info = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j];
1427
1428 if (writeback_info->wb_enabled == false)
1429 continue;
1430
1431 //wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params;
1432 wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe];
1433
1434 if (writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_ARGB ||
1435 writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_RGBA)
1436 wbif_mode = PACKED_444_FP16;
1437 else
1438 wbif_mode = PACKED_444;
1439
1440 DC_FP_START();
1441 dcn30_fpu_set_mcif_arb_params(wb_arb_params, dml, pipes, pipe_cnt, j);
1442 DC_FP_END();
1443 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 */
1444 wb_arb_params->slice_lines = 32;
1445 wb_arb_params->arbitration_slice = 2; /* irrelevant since there is no YUV output */
1446 wb_arb_params->max_scaled_time = dcn30_calc_max_scaled_time(wb_arb_params->time_per_pixel,
1447 wbif_mode,
1448 wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */
1449
1450 dwb_pipe++;
1451
1452 if (dwb_pipe >= MAX_DWB_PIPES)
1453 return;
1454 }
1455 }
1456 }
1457
1458 static struct dc_cap_funcs cap_funcs = {
1459 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1460 };
1461
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)1462 bool dcn30_acquire_post_bldn_3dlut(
1463 struct resource_context *res_ctx,
1464 const struct resource_pool *pool,
1465 int mpcc_id,
1466 struct dc_3dlut **lut,
1467 struct dc_transfer_func **shaper)
1468 {
1469 int i;
1470 bool ret = false;
1471 union dc_3dlut_state *state;
1472
1473 ASSERT(*lut == NULL && *shaper == NULL);
1474 *lut = NULL;
1475 *shaper = NULL;
1476
1477 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1478 if (!res_ctx->is_mpc_3dlut_acquired[i]) {
1479 *lut = pool->mpc_lut[i];
1480 *shaper = pool->mpc_shaper[i];
1481 state = &pool->mpc_lut[i]->state;
1482 res_ctx->is_mpc_3dlut_acquired[i] = true;
1483 state->bits.rmu_idx_valid = 1;
1484 state->bits.rmu_mux_num = i;
1485 if (state->bits.rmu_mux_num == 0)
1486 state->bits.mpc_rmu0_mux = mpcc_id;
1487 else if (state->bits.rmu_mux_num == 1)
1488 state->bits.mpc_rmu1_mux = mpcc_id;
1489 else if (state->bits.rmu_mux_num == 2)
1490 state->bits.mpc_rmu2_mux = mpcc_id;
1491 ret = true;
1492 break;
1493 }
1494 }
1495 return ret;
1496 }
1497
dcn30_release_post_bldn_3dlut(struct resource_context * res_ctx,const struct resource_pool * pool,struct dc_3dlut ** lut,struct dc_transfer_func ** shaper)1498 bool dcn30_release_post_bldn_3dlut(
1499 struct resource_context *res_ctx,
1500 const struct resource_pool *pool,
1501 struct dc_3dlut **lut,
1502 struct dc_transfer_func **shaper)
1503 {
1504 int i;
1505 bool ret = false;
1506
1507 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1508 if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) {
1509 res_ctx->is_mpc_3dlut_acquired[i] = false;
1510 pool->mpc_lut[i]->state.raw = 0;
1511 *lut = NULL;
1512 *shaper = NULL;
1513 ret = true;
1514 break;
1515 }
1516 }
1517 return ret;
1518 }
1519
is_soc_bounding_box_valid(struct dc * dc)1520 static bool is_soc_bounding_box_valid(struct dc *dc)
1521 {
1522 uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev;
1523
1524 if (ASICREV_IS_SIENNA_CICHLID_P(hw_internal_rev))
1525 return true;
1526
1527 return false;
1528 }
1529
init_soc_bounding_box(struct dc * dc,struct dcn30_resource_pool * pool)1530 static bool init_soc_bounding_box(struct dc *dc,
1531 struct dcn30_resource_pool *pool)
1532 {
1533 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_0_soc;
1534 struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_0_ip;
1535
1536 DC_LOGGER_INIT(dc->ctx->logger);
1537
1538 if (!is_soc_bounding_box_valid(dc)) {
1539 DC_LOG_ERROR("%s: not valid soc bounding box\n", __func__);
1540 return false;
1541 }
1542
1543 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
1544 loaded_ip->max_num_dpp = pool->base.pipe_count;
1545 loaded_ip->clamp_min_dcfclk = dc->config.clamp_min_dcfclk;
1546 dcn20_patch_bounding_box(dc, loaded_bb);
1547 DC_FP_START();
1548 patch_dcn30_soc_bounding_box(dc, &dcn3_0_soc);
1549 DC_FP_END();
1550
1551 return true;
1552 }
1553
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)1554 static bool dcn30_split_stream_for_mpc_or_odm(
1555 const struct dc *dc,
1556 struct resource_context *res_ctx,
1557 struct pipe_ctx *pri_pipe,
1558 struct pipe_ctx *sec_pipe,
1559 bool odm)
1560 {
1561 int pipe_idx = sec_pipe->pipe_idx;
1562 const struct resource_pool *pool = dc->res_pool;
1563
1564 *sec_pipe = *pri_pipe;
1565
1566 sec_pipe->pipe_idx = pipe_idx;
1567 sec_pipe->plane_res.mi = pool->mis[pipe_idx];
1568 sec_pipe->plane_res.hubp = pool->hubps[pipe_idx];
1569 sec_pipe->plane_res.ipp = pool->ipps[pipe_idx];
1570 sec_pipe->plane_res.xfm = pool->transforms[pipe_idx];
1571 sec_pipe->plane_res.dpp = pool->dpps[pipe_idx];
1572 sec_pipe->plane_res.mpcc_inst = pool->dpps[pipe_idx]->inst;
1573 sec_pipe->stream_res.dsc = NULL;
1574 if (odm) {
1575 if (pri_pipe->next_odm_pipe) {
1576 ASSERT(pri_pipe->next_odm_pipe != sec_pipe);
1577 sec_pipe->next_odm_pipe = pri_pipe->next_odm_pipe;
1578 sec_pipe->next_odm_pipe->prev_odm_pipe = sec_pipe;
1579 }
1580 if (pri_pipe->top_pipe && pri_pipe->top_pipe->next_odm_pipe) {
1581 pri_pipe->top_pipe->next_odm_pipe->bottom_pipe = sec_pipe;
1582 sec_pipe->top_pipe = pri_pipe->top_pipe->next_odm_pipe;
1583 }
1584 if (pri_pipe->bottom_pipe && pri_pipe->bottom_pipe->next_odm_pipe) {
1585 pri_pipe->bottom_pipe->next_odm_pipe->top_pipe = sec_pipe;
1586 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe->next_odm_pipe;
1587 }
1588 pri_pipe->next_odm_pipe = sec_pipe;
1589 sec_pipe->prev_odm_pipe = pri_pipe;
1590
1591 if (!sec_pipe->top_pipe)
1592 sec_pipe->stream_res.opp = pool->opps[pipe_idx];
1593 else
1594 sec_pipe->stream_res.opp = sec_pipe->top_pipe->stream_res.opp;
1595 if (sec_pipe->stream->timing.flags.DSC == 1) {
1596 dcn20_acquire_dsc(dc, res_ctx, &sec_pipe->stream_res.dsc, pipe_idx);
1597 ASSERT(sec_pipe->stream_res.dsc);
1598 if (sec_pipe->stream_res.dsc == NULL)
1599 return false;
1600 }
1601 } else {
1602 if (pri_pipe->bottom_pipe) {
1603 ASSERT(pri_pipe->bottom_pipe != sec_pipe);
1604 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe;
1605 sec_pipe->bottom_pipe->top_pipe = sec_pipe;
1606 }
1607 pri_pipe->bottom_pipe = sec_pipe;
1608 sec_pipe->top_pipe = pri_pipe;
1609
1610 ASSERT(pri_pipe->plane_state);
1611 }
1612
1613 return true;
1614 }
1615
dcn30_find_split_pipe(struct dc * dc,struct dc_state * context,int old_index)1616 static struct pipe_ctx *dcn30_find_split_pipe(
1617 struct dc *dc,
1618 struct dc_state *context,
1619 int old_index)
1620 {
1621 struct pipe_ctx *pipe = NULL;
1622 int i;
1623
1624 if (old_index >= 0 && context->res_ctx.pipe_ctx[old_index].stream == NULL) {
1625 pipe = &context->res_ctx.pipe_ctx[old_index];
1626 pipe->pipe_idx = old_index;
1627 }
1628
1629 if (!pipe)
1630 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
1631 if (dc->current_state->res_ctx.pipe_ctx[i].top_pipe == NULL
1632 && dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe == NULL) {
1633 if (context->res_ctx.pipe_ctx[i].stream == NULL) {
1634 pipe = &context->res_ctx.pipe_ctx[i];
1635 pipe->pipe_idx = i;
1636 break;
1637 }
1638 }
1639 }
1640
1641 /*
1642 * May need to fix pipes getting tossed from 1 opp to another on flip
1643 * Add for debugging transient underflow during topology updates:
1644 * ASSERT(pipe);
1645 */
1646 if (!pipe)
1647 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
1648 if (context->res_ctx.pipe_ctx[i].stream == NULL) {
1649 pipe = &context->res_ctx.pipe_ctx[i];
1650 pipe->pipe_idx = i;
1651 break;
1652 }
1653 }
1654
1655 return pipe;
1656 }
1657
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)1658 noinline bool dcn30_internal_validate_bw(
1659 struct dc *dc,
1660 struct dc_state *context,
1661 display_e2e_pipe_params_st *pipes,
1662 int *pipe_cnt_out,
1663 int *vlevel_out,
1664 enum dc_validate_mode validate_mode,
1665 bool allow_self_refresh_only)
1666 {
1667 bool out = false;
1668 bool repopulate_pipes = false;
1669 int split[MAX_PIPES] = { 0 };
1670 bool merge[MAX_PIPES] = { false };
1671 bool newly_split[MAX_PIPES] = { false };
1672 int pipe_cnt, i, pipe_idx, vlevel = 0;
1673 struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
1674
1675 ASSERT(pipes);
1676 if (!pipes)
1677 return false;
1678
1679 dcn20_merge_pipes_for_validate(dc, context);
1680
1681 context->bw_ctx.dml.vba.maxMpcComb = 0;
1682 context->bw_ctx.dml.vba.VoltageLevel = 0;
1683 context->bw_ctx.dml.vba.DRAMClockChangeSupport[0][0] = dm_dram_clock_change_vactive;
1684 dc->res_pool->funcs->update_soc_for_wm_a(dc, context);
1685 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode);
1686
1687 if (!pipe_cnt) {
1688 out = true;
1689 goto validate_out;
1690 }
1691
1692 dml_log_pipe_params(&context->bw_ctx.dml, pipes, pipe_cnt);
1693
1694 if (validate_mode == DC_VALIDATE_MODE_AND_PROGRAMMING || !allow_self_refresh_only) {
1695 /*
1696 * DML favors voltage over p-state, but we're more interested in
1697 * supporting p-state over voltage. We can't support p-state in
1698 * prefetch mode > 0 so try capping the prefetch mode to start.
1699 */
1700 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1701 dm_allow_self_refresh_and_mclk_switch;
1702 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1703 /* This may adjust vlevel and maxMpcComb */
1704 if (vlevel < context->bw_ctx.dml.soc.num_states)
1705 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1706 }
1707 if (allow_self_refresh_only &&
1708 (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING || vlevel == context->bw_ctx.dml.soc.num_states ||
1709 vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported)) {
1710 /*
1711 * If mode is unsupported or there's still no p-state support
1712 * then fall back to favoring voltage.
1713 *
1714 * We don't actually support prefetch mode 2, so require that we
1715 * at least support prefetch mode 1.
1716 */
1717 context->bw_ctx.dml.validate_max_state = (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING);
1718 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1719 dm_allow_self_refresh;
1720
1721 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1722 if (vlevel < context->bw_ctx.dml.soc.num_states) {
1723 memset(split, 0, sizeof(split));
1724 memset(merge, 0, sizeof(merge));
1725 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1726 }
1727 context->bw_ctx.dml.validate_max_state = false;
1728 }
1729
1730 dml_log_mode_support_params(&context->bw_ctx.dml);
1731
1732 if (vlevel == context->bw_ctx.dml.soc.num_states)
1733 goto validate_fail;
1734
1735 if (!dc->config.enable_windowed_mpo_odm) {
1736 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1737 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1738 struct pipe_ctx *mpo_pipe = pipe->bottom_pipe;
1739
1740 if (!pipe->stream)
1741 continue;
1742
1743 /* We only support full screen mpo with ODM */
1744 if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled
1745 && pipe->plane_state && mpo_pipe
1746 && memcmp(&mpo_pipe->plane_state->clip_rect,
1747 &pipe->stream->src,
1748 sizeof(struct rect)) != 0) {
1749 ASSERT(mpo_pipe->plane_state != pipe->plane_state);
1750 goto validate_fail;
1751 }
1752 pipe_idx++;
1753 }
1754 }
1755
1756 /* merge pipes if necessary */
1757 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1758 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1759
1760 /*skip pipes that don't need merging*/
1761 if (!merge[i])
1762 continue;
1763
1764 /* if ODM merge we ignore mpc tree, mpo pipes will have their own flags */
1765 if (pipe->prev_odm_pipe) {
1766 /*split off odm pipe*/
1767 pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe;
1768 if (pipe->next_odm_pipe)
1769 pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe;
1770
1771 pipe->bottom_pipe = NULL;
1772 pipe->next_odm_pipe = NULL;
1773 pipe->plane_state = NULL;
1774 pipe->stream = NULL;
1775 pipe->top_pipe = NULL;
1776 pipe->prev_odm_pipe = NULL;
1777 if (pipe->stream_res.dsc)
1778 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc);
1779 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1780 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1781 repopulate_pipes = true;
1782 } else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
1783 struct pipe_ctx *top_pipe = pipe->top_pipe;
1784 struct pipe_ctx *bottom_pipe = pipe->bottom_pipe;
1785
1786 top_pipe->bottom_pipe = bottom_pipe;
1787 if (bottom_pipe)
1788 bottom_pipe->top_pipe = top_pipe;
1789
1790 pipe->top_pipe = NULL;
1791 pipe->bottom_pipe = NULL;
1792 pipe->plane_state = NULL;
1793 pipe->stream = NULL;
1794 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1795 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1796 repopulate_pipes = true;
1797 } else
1798 ASSERT(0); /* Should never try to merge master pipe */
1799
1800 }
1801
1802 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
1803 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1804 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1805 struct pipe_ctx *hsplit_pipe = NULL;
1806 bool odm;
1807 int old_index = -1;
1808
1809 if (!pipe->stream || newly_split[i])
1810 continue;
1811
1812 pipe_idx++;
1813 odm = vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled;
1814
1815 if (!pipe->plane_state && !odm)
1816 continue;
1817
1818 if (split[i]) {
1819 if (odm) {
1820 if (split[i] == 4 && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe)
1821 old_index = old_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1822 else if (old_pipe->next_odm_pipe)
1823 old_index = old_pipe->next_odm_pipe->pipe_idx;
1824 } else {
1825 if (split[i] == 4 && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1826 old_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1827 old_index = old_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1828 else if (old_pipe->bottom_pipe &&
1829 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1830 old_index = old_pipe->bottom_pipe->pipe_idx;
1831 }
1832 hsplit_pipe = dcn30_find_split_pipe(dc, context, old_index);
1833 ASSERT(hsplit_pipe);
1834 if (!hsplit_pipe)
1835 goto validate_fail;
1836
1837 if (!dcn30_split_stream_for_mpc_or_odm(
1838 dc, &context->res_ctx,
1839 pipe, hsplit_pipe, odm))
1840 goto validate_fail;
1841
1842 newly_split[hsplit_pipe->pipe_idx] = true;
1843 repopulate_pipes = true;
1844 }
1845 if (split[i] == 4) {
1846 struct pipe_ctx *pipe_4to1;
1847
1848 if (odm && old_pipe->next_odm_pipe)
1849 old_index = old_pipe->next_odm_pipe->pipe_idx;
1850 else if (!odm && old_pipe->bottom_pipe &&
1851 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1852 old_index = old_pipe->bottom_pipe->pipe_idx;
1853 else
1854 old_index = -1;
1855 pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index);
1856 ASSERT(pipe_4to1);
1857 if (!pipe_4to1)
1858 goto validate_fail;
1859 if (!dcn30_split_stream_for_mpc_or_odm(
1860 dc, &context->res_ctx,
1861 pipe, pipe_4to1, odm))
1862 goto validate_fail;
1863 newly_split[pipe_4to1->pipe_idx] = true;
1864
1865 if (odm && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe
1866 && old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe)
1867 old_index = old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1868 else if (!odm && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1869 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe &&
1870 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1871 old_index = old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1872 else
1873 old_index = -1;
1874 pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index);
1875 ASSERT(pipe_4to1);
1876 if (!pipe_4to1)
1877 goto validate_fail;
1878 if (!dcn30_split_stream_for_mpc_or_odm(
1879 dc, &context->res_ctx,
1880 hsplit_pipe, pipe_4to1, odm))
1881 goto validate_fail;
1882 newly_split[pipe_4to1->pipe_idx] = true;
1883 }
1884 if (odm)
1885 dcn20_build_mapped_resource(dc, context, pipe->stream);
1886 }
1887
1888 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1889 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1890
1891 if (pipe->plane_state) {
1892 if (!resource_build_scaling_params(pipe))
1893 goto validate_fail;
1894 }
1895 }
1896
1897 /* Actual dsc count per stream dsc validation*/
1898 if (!dcn20_validate_dsc(dc, context)) {
1899 vba->ValidationStatus[vba->soc.num_states] = DML_FAIL_DSC_VALIDATION_FAILURE;
1900 goto validate_fail;
1901 }
1902
1903 if (repopulate_pipes)
1904 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode);
1905 context->bw_ctx.dml.vba.VoltageLevel = vlevel;
1906 *vlevel_out = vlevel;
1907 *pipe_cnt_out = pipe_cnt;
1908
1909 out = true;
1910 goto validate_out;
1911
1912 validate_fail:
1913 out = false;
1914
1915 validate_out:
1916 return out;
1917 }
1918
get_refresh_rate(struct dc_state * context)1919 static int get_refresh_rate(struct dc_state *context)
1920 {
1921 int refresh_rate = 0;
1922 int h_v_total = 0;
1923 struct dc_crtc_timing *timing = NULL;
1924
1925 if (context == NULL || context->streams[0] == NULL)
1926 return 0;
1927
1928 /* check if refresh rate at least 120hz */
1929 timing = &context->streams[0]->timing;
1930
1931 h_v_total = timing->h_total * timing->v_total;
1932 if (h_v_total == 0)
1933 return 0;
1934
1935 refresh_rate = ((timing->pix_clk_100hz * 100) / (h_v_total)) + 1;
1936 return refresh_rate;
1937 }
1938
1939 #define MAX_STRETCHED_V_BLANK 500 // in micro-seconds
1940 /*
1941 * Scaling factor for v_blank stretch calculations considering timing in
1942 * micro-seconds and pixel clock in 100hz.
1943 * Note: the parenthesis are necessary to ensure the correct order of
1944 * operation where V_SCALE is used.
1945 */
1946 #define V_SCALE (10000 / MAX_STRETCHED_V_BLANK)
1947
get_frame_rate_at_max_stretch_100hz(struct dc_state * context)1948 static int get_frame_rate_at_max_stretch_100hz(struct dc_state *context)
1949 {
1950 struct dc_crtc_timing *timing = NULL;
1951 uint32_t sec_per_100_lines;
1952 uint32_t max_v_blank;
1953 uint32_t curr_v_blank;
1954 uint32_t v_stretch_max;
1955 uint32_t stretched_frame_pix_cnt;
1956 uint32_t scaled_stretched_frame_pix_cnt;
1957 uint32_t scaled_refresh_rate;
1958
1959 if (context == NULL || context->streams[0] == NULL)
1960 return 0;
1961
1962 /* check if refresh rate at least 120hz */
1963 timing = &context->streams[0]->timing;
1964 if (timing == NULL)
1965 return 0;
1966
1967 sec_per_100_lines = timing->pix_clk_100hz / timing->h_total + 1;
1968 max_v_blank = sec_per_100_lines / V_SCALE + 1;
1969 curr_v_blank = timing->v_total - timing->v_addressable;
1970 v_stretch_max = (max_v_blank > curr_v_blank) ? (max_v_blank - curr_v_blank) : (0);
1971 stretched_frame_pix_cnt = (v_stretch_max + timing->v_total) * timing->h_total;
1972 scaled_stretched_frame_pix_cnt = stretched_frame_pix_cnt / 10000;
1973 scaled_refresh_rate = (timing->pix_clk_100hz) / scaled_stretched_frame_pix_cnt + 1;
1974
1975 return scaled_refresh_rate;
1976 }
1977
is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(struct dc_state * context)1978 static bool is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(struct dc_state *context)
1979 {
1980 int refresh_rate_max_stretch_100hz;
1981 int min_refresh_100hz;
1982
1983 if (context == NULL || context->streams[0] == NULL)
1984 return false;
1985
1986 refresh_rate_max_stretch_100hz = get_frame_rate_at_max_stretch_100hz(context);
1987 min_refresh_100hz = context->streams[0]->timing.min_refresh_in_uhz / 10000;
1988
1989 if (refresh_rate_max_stretch_100hz < min_refresh_100hz)
1990 return false;
1991
1992 return true;
1993 }
1994
dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch(struct dc * dc,struct dc_state * context)1995 bool dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context)
1996 {
1997 int refresh_rate = 0;
1998 const int minimum_refreshrate_supported = 120;
1999 struct dc_stream_status *stream_status = NULL;
2000
2001 if (context == NULL || context->streams[0] == NULL)
2002 return false;
2003
2004 if (context->streams[0]->sink->edid_caps.panel_patch.disable_fams)
2005 return false;
2006
2007 if (dc->debug.disable_fams)
2008 return false;
2009
2010 if (!dc->caps.dmub_caps.mclk_sw)
2011 return false;
2012
2013 if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching_shut_down)
2014 return false;
2015
2016 /* more then 1 monitor connected */
2017 if (context->stream_count != 1)
2018 return false;
2019
2020 refresh_rate = get_refresh_rate(context);
2021 if (refresh_rate < minimum_refreshrate_supported)
2022 return false;
2023
2024 if (!is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(context))
2025 return false;
2026
2027 if (!context->streams[0]->allow_freesync)
2028 return false;
2029
2030 if (context->streams[0]->vrr_active_variable && (dc->debug.disable_fams_gaming == INGAME_FAMS_DISABLE))
2031 return false;
2032
2033 stream_status = dc_state_get_stream_status(context, context->streams[0]);
2034
2035 if (!stream_status)
2036 return false;
2037
2038 stream_status->fpo_in_use = true;
2039
2040 return true;
2041 }
2042
2043 /*
2044 * set up FPO watermarks, pstate, dram latency
2045 */
dcn30_setup_mclk_switch_using_fw_based_vblank_stretch(struct dc * dc,struct dc_state * context)2046 void dcn30_setup_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context)
2047 {
2048 ASSERT(dc != NULL && context != NULL);
2049 if (dc == NULL || context == NULL)
2050 return;
2051
2052 /* Set wm_a.pstate so high natural MCLK switches are impossible: 4 seconds */
2053 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2054 }
2055
dcn30_update_soc_for_wm_a(struct dc * dc,struct dc_state * context)2056 void dcn30_update_soc_for_wm_a(struct dc *dc, struct dc_state *context)
2057 {
2058 DC_FP_START();
2059 dcn30_fpu_update_soc_for_wm_a(dc, context);
2060 DC_FP_END();
2061 }
2062
dcn30_calculate_wm_and_dlg(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int pipe_cnt,int vlevel)2063 void dcn30_calculate_wm_and_dlg(
2064 struct dc *dc, struct dc_state *context,
2065 display_e2e_pipe_params_st *pipes,
2066 int pipe_cnt,
2067 int vlevel)
2068 {
2069 DC_FP_START();
2070 dcn30_fpu_calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
2071 DC_FP_END();
2072 }
2073
dcn30_validate_bandwidth(struct dc * dc,struct dc_state * context,enum dc_validate_mode validate_mode)2074 enum dc_status dcn30_validate_bandwidth(struct dc *dc,
2075 struct dc_state *context,
2076 enum dc_validate_mode validate_mode)
2077 {
2078 bool out = false;
2079
2080 BW_VAL_TRACE_SETUP();
2081
2082 int vlevel = 0;
2083 int pipe_cnt = 0;
2084 display_e2e_pipe_params_st *pipes = kzalloc_objs(display_e2e_pipe_params_st,
2085 dc->res_pool->pipe_count);
2086 DC_LOGGER_INIT(dc->ctx->logger);
2087
2088 BW_VAL_TRACE_COUNT();
2089
2090 if (!pipes)
2091 goto validate_fail;
2092
2093 DC_FP_START();
2094 out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, validate_mode, true);
2095 DC_FP_END();
2096
2097 if (pipe_cnt == 0)
2098 goto validate_out;
2099
2100 if (!out)
2101 goto validate_fail;
2102
2103 BW_VAL_TRACE_END_VOLTAGE_LEVEL();
2104
2105 if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING) {
2106 BW_VAL_TRACE_SKIP(fast);
2107 goto validate_out;
2108 }
2109
2110 DC_FP_START();
2111 if (dc->res_pool->funcs->calculate_wm_and_dlg)
2112 dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
2113 DC_FP_END();
2114
2115 BW_VAL_TRACE_END_WATERMARKS();
2116
2117 goto validate_out;
2118
2119 validate_fail:
2120 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n",
2121 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states]));
2122
2123 BW_VAL_TRACE_SKIP(fail);
2124 out = false;
2125
2126 validate_out:
2127 kfree(pipes);
2128
2129 BW_VAL_TRACE_FINISH();
2130
2131 return out ? DC_OK : DC_FAIL_BANDWIDTH_VALIDATE;
2132 }
2133
dcn30_update_bw_bounding_box(struct dc * dc,struct clk_bw_params * bw_params)2134 void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
2135 {
2136 unsigned int i, j;
2137 unsigned int num_states = 0;
2138
2139 unsigned int dcfclk_mhz[DC__VOLTAGE_STATES] = {0};
2140 unsigned int dram_speed_mts[DC__VOLTAGE_STATES] = {0};
2141 unsigned int optimal_uclk_for_dcfclk_sta_targets[DC__VOLTAGE_STATES] = {0};
2142 unsigned int optimal_dcfclk_for_uclk[DC__VOLTAGE_STATES] = {0};
2143
2144 unsigned int dcfclk_sta_targets[DC__VOLTAGE_STATES] = {694, 875, 1000, 1200};
2145 unsigned int num_dcfclk_sta_targets = 4;
2146 unsigned int num_uclk_states;
2147
2148 struct dc_bounding_box_max_clk dcn30_bb_max_clk;
2149
2150 memset(&dcn30_bb_max_clk, 0, sizeof(dcn30_bb_max_clk));
2151
2152 if (dc->ctx->dc_bios->vram_info.num_chans)
2153 dcn3_0_soc.num_chans = dc->ctx->dc_bios->vram_info.num_chans;
2154
2155 DC_FP_START();
2156 dcn30_fpu_update_dram_channel_width_bytes(dc);
2157 DC_FP_END();
2158
2159 if (bw_params->clk_table.entries[0].memclk_mhz) {
2160
2161 for (i = 0; i < MAX_NUM_DPM_LVL; i++) {
2162 if (bw_params->clk_table.entries[i].dcfclk_mhz > dcn30_bb_max_clk.max_dcfclk_mhz)
2163 dcn30_bb_max_clk.max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz;
2164 if (bw_params->clk_table.entries[i].dispclk_mhz > dcn30_bb_max_clk.max_dispclk_mhz)
2165 dcn30_bb_max_clk.max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz;
2166 if (bw_params->clk_table.entries[i].dppclk_mhz > dcn30_bb_max_clk.max_dppclk_mhz)
2167 dcn30_bb_max_clk.max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz;
2168 if (bw_params->clk_table.entries[i].phyclk_mhz > dcn30_bb_max_clk.max_phyclk_mhz)
2169 dcn30_bb_max_clk.max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz;
2170 }
2171
2172 DC_FP_START();
2173 dcn30_fpu_update_max_clk(&dcn30_bb_max_clk);
2174 DC_FP_END();
2175
2176 if (dcn30_bb_max_clk.max_dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) {
2177 // If max DCFCLK is greater than the max DCFCLK STA target, insert into the DCFCLK STA target array
2178 dcfclk_sta_targets[num_dcfclk_sta_targets] = dcn30_bb_max_clk.max_dcfclk_mhz;
2179 num_dcfclk_sta_targets++;
2180 } else if (dcn30_bb_max_clk.max_dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) {
2181 // If max DCFCLK is less than the max DCFCLK STA target, cap values and remove duplicates
2182 for (i = 0; i < num_dcfclk_sta_targets; i++) {
2183 if (dcfclk_sta_targets[i] > dcn30_bb_max_clk.max_dcfclk_mhz) {
2184 dcfclk_sta_targets[i] = dcn30_bb_max_clk.max_dcfclk_mhz;
2185 break;
2186 }
2187 }
2188 // Update size of array since we "removed" duplicates
2189 num_dcfclk_sta_targets = i + 1;
2190 }
2191
2192 num_uclk_states = bw_params->clk_table.num_entries;
2193
2194 // Calculate optimal dcfclk for each uclk
2195 for (i = 0; i < num_uclk_states; i++) {
2196 DC_FP_START();
2197 dcn30_fpu_get_optimal_dcfclk_fclk_for_uclk(bw_params->clk_table.entries[i].memclk_mhz * 16,
2198 &optimal_dcfclk_for_uclk[i], NULL);
2199 DC_FP_END();
2200 if (optimal_dcfclk_for_uclk[i] < bw_params->clk_table.entries[0].dcfclk_mhz) {
2201 optimal_dcfclk_for_uclk[i] = bw_params->clk_table.entries[0].dcfclk_mhz;
2202 }
2203 }
2204
2205 // Calculate optimal uclk for each dcfclk sta target
2206 for (i = 0; i < num_dcfclk_sta_targets; i++) {
2207 for (j = 0; j < num_uclk_states; j++) {
2208 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) {
2209 optimal_uclk_for_dcfclk_sta_targets[i] =
2210 bw_params->clk_table.entries[j].memclk_mhz * 16;
2211 break;
2212 } else {
2213 /* condition where (dcfclk_sta_targets[i] >= optimal_dcfclk_for_uclk[j]):
2214 * If it just so happens that the memory bandwidth is low enough such that
2215 * all the optimal DCFCLK for each UCLK is lower than the smallest DCFCLK STA
2216 * target, we need to populate the optimal UCLK for each DCFCLK STA target to
2217 * be the max UCLK.
2218 */
2219 if (j == num_uclk_states - 1) {
2220 optimal_uclk_for_dcfclk_sta_targets[i] =
2221 bw_params->clk_table.entries[j].memclk_mhz * 16;
2222 }
2223 }
2224 }
2225 }
2226
2227 i = 0;
2228 j = 0;
2229 // create the final dcfclk and uclk table
2230 while (i < num_dcfclk_sta_targets && j < num_uclk_states && num_states < DC__VOLTAGE_STATES) {
2231 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) {
2232 dcfclk_mhz[num_states] = dcfclk_sta_targets[i];
2233 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++];
2234 } else {
2235 if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) {
2236 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j];
2237 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16;
2238 } else {
2239 j = num_uclk_states;
2240 }
2241 }
2242 }
2243
2244 while (i < num_dcfclk_sta_targets && num_states < DC__VOLTAGE_STATES) {
2245 dcfclk_mhz[num_states] = dcfclk_sta_targets[i];
2246 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++];
2247 }
2248
2249 while (j < num_uclk_states && num_states < DC__VOLTAGE_STATES &&
2250 optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) {
2251 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j];
2252 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16;
2253 }
2254
2255 dcn3_0_soc.num_states = num_states;
2256 DC_FP_START();
2257 dcn30_fpu_update_bw_bounding_box(dc, bw_params, &dcn30_bb_max_clk, dcfclk_mhz, dram_speed_mts);
2258 DC_FP_END();
2259 }
2260 }
2261
dcn30_get_panel_config_defaults(struct dc_panel_config * panel_config)2262 static void dcn30_get_panel_config_defaults(struct dc_panel_config *panel_config)
2263 {
2264 *panel_config = panel_config_defaults;
2265 }
2266
2267 static const struct resource_funcs dcn30_res_pool_funcs = {
2268 .destroy = dcn30_destroy_resource_pool,
2269 .link_enc_create = dcn30_link_encoder_create,
2270 .panel_cntl_create = dcn30_panel_cntl_create,
2271 .validate_bandwidth = dcn30_validate_bandwidth,
2272 .calculate_wm_and_dlg = dcn30_calculate_wm_and_dlg,
2273 .update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
2274 .populate_dml_pipes = dcn30_populate_dml_pipes_from_context,
2275 .acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
2276 .release_pipe = dcn20_release_pipe,
2277 .add_stream_to_ctx = dcn30_add_stream_to_ctx,
2278 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
2279 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
2280 .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
2281 .set_mcif_arb_params = dcn30_set_mcif_arb_params,
2282 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
2283 .acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut,
2284 .release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut,
2285 .update_bw_bounding_box = dcn30_update_bw_bounding_box,
2286 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
2287 .get_panel_config_defaults = dcn30_get_panel_config_defaults,
2288 .get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe,
2289 .get_default_tiling_info = dcn10_get_default_tiling_info
2290 };
2291
2292 #define CTX ctx
2293
2294 #define REG(reg_name) \
2295 (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
2296
read_pipe_fuses(struct dc_context * ctx)2297 static uint32_t read_pipe_fuses(struct dc_context *ctx)
2298 {
2299 uint32_t value = REG_READ(CC_DC_PIPE_DIS);
2300 /* Support for max 6 pipes */
2301 value = value & 0x3f;
2302 return value;
2303 }
2304
dcn30_resource_construct(uint8_t num_virtual_links,struct dc * dc,struct dcn30_resource_pool * pool)2305 static bool dcn30_resource_construct(
2306 uint8_t num_virtual_links,
2307 struct dc *dc,
2308 struct dcn30_resource_pool *pool)
2309 {
2310 int i;
2311 struct dc_context *ctx = dc->ctx;
2312 struct irq_service_init_data init_data;
2313 struct ddc_service_init_data ddc_init_data = {0};
2314 uint32_t pipe_fuses = read_pipe_fuses(ctx);
2315 uint32_t num_pipes = 0;
2316
2317 if (!(pipe_fuses == 0 || pipe_fuses == 0x3e)) {
2318 BREAK_TO_DEBUGGER();
2319 dm_error("DC: Unexpected fuse recipe for navi2x !\n");
2320 /* fault to single pipe */
2321 pipe_fuses = 0x3e;
2322 }
2323
2324 DC_FP_START();
2325
2326 ctx->dc_bios->regs = &bios_regs;
2327
2328 pool->base.res_cap = &res_cap_dcn3;
2329
2330 pool->base.funcs = &dcn30_res_pool_funcs;
2331
2332 /*************************************************
2333 * Resource + asic cap harcoding *
2334 *************************************************/
2335 pool->base.underlay_pipe_index = (unsigned int)NO_UNDERLAY_PIPE;
2336 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
2337 pool->base.mpcc_count = pool->base.res_cap->num_timing_generator;
2338 dc->caps.max_downscale_ratio = 600;
2339 dc->caps.i2c_speed_in_khz = 100;
2340 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/
2341 dc->caps.max_cursor_size = 256;
2342 dc->caps.min_horizontal_blanking_period = 80;
2343 dc->caps.dmdata_alloc_size = 2048;
2344 dc->caps.mall_size_per_mem_channel = 8;
2345 /* total size = mall per channel * num channels * 1024 * 1024 */
2346 dc->caps.mall_size_total = dc->caps.mall_size_per_mem_channel * dc->ctx->dc_bios->vram_info.num_chans * 1048576;
2347 dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
2348
2349 dc->caps.max_slave_planes = 2;
2350 dc->caps.max_slave_yuv_planes = 2;
2351 dc->caps.max_slave_rgb_planes = 2;
2352 dc->caps.post_blend_color_processing = true;
2353 dc->caps.force_dp_tps4_for_cp2520 = true;
2354 dc->caps.extended_aux_timeout_support = true;
2355 dc->caps.dmcub_support = true;
2356
2357 /* Color pipeline capabilities */
2358 dc->caps.color.dpp.dcn_arch = 1;
2359 dc->caps.color.dpp.input_lut_shared = 0;
2360 dc->caps.color.dpp.icsc = 1;
2361 dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
2362 dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2363 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2364 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
2365 dc->caps.color.dpp.dgam_rom_caps.pq = 1;
2366 dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
2367 dc->caps.color.dpp.post_csc = 1;
2368 dc->caps.color.dpp.gamma_corr = 1;
2369 dc->caps.color.dpp.dgam_rom_for_yuv = 0;
2370
2371 dc->caps.color.dpp.hw_3d_lut = 1;
2372 dc->caps.color.dpp.ogam_ram = 1;
2373 // no OGAM ROM on DCN3
2374 dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2375 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2376 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2377 dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2378 dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2379 dc->caps.color.dpp.ocsc = 0;
2380
2381 dc->caps.color.mpc.gamut_remap = 1;
2382 dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //3
2383 dc->caps.color.mpc.ogam_ram = 1;
2384 dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2385 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2386 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2387 dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2388 dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2389 dc->caps.color.mpc.ocsc = 1;
2390
2391 dc->caps.dp_hdmi21_pcon_support = true;
2392 dc->caps.max_v_total = (1 << 15) - 1;
2393 dc->caps.vtotal_limited_by_fp2 = true;
2394
2395 /* read VBIOS LTTPR caps */
2396 {
2397 if (ctx->dc_bios->funcs->get_lttpr_caps) {
2398 enum bp_result bp_query_result;
2399 uint8_t is_vbios_lttpr_enable = 0;
2400
2401 bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
2402 dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
2403 }
2404
2405 if (ctx->dc_bios->funcs->get_lttpr_interop) {
2406 enum bp_result bp_query_result;
2407 uint8_t is_vbios_interop_enabled = 0;
2408
2409 bp_query_result = ctx->dc_bios->funcs->get_lttpr_interop(ctx->dc_bios,
2410 &is_vbios_interop_enabled);
2411 dc->caps.vbios_lttpr_aware = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled;
2412 }
2413 }
2414 dc->check_config = config_defaults;
2415
2416 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
2417 dc->debug = debug_defaults_drv;
2418
2419 // Init the vm_helper
2420 if (dc->vm_helper)
2421 vm_helper_init(dc->vm_helper, 16);
2422
2423 /*************************************************
2424 * Create resources *
2425 *************************************************/
2426
2427 /* Clock Sources for Pixel Clock*/
2428 pool->base.clock_sources[DCN30_CLK_SRC_PLL0] =
2429 dcn30_clock_source_create(ctx, ctx->dc_bios,
2430 CLOCK_SOURCE_COMBO_PHY_PLL0,
2431 &clk_src_regs[0], false);
2432 pool->base.clock_sources[DCN30_CLK_SRC_PLL1] =
2433 dcn30_clock_source_create(ctx, ctx->dc_bios,
2434 CLOCK_SOURCE_COMBO_PHY_PLL1,
2435 &clk_src_regs[1], false);
2436 pool->base.clock_sources[DCN30_CLK_SRC_PLL2] =
2437 dcn30_clock_source_create(ctx, ctx->dc_bios,
2438 CLOCK_SOURCE_COMBO_PHY_PLL2,
2439 &clk_src_regs[2], false);
2440 pool->base.clock_sources[DCN30_CLK_SRC_PLL3] =
2441 dcn30_clock_source_create(ctx, ctx->dc_bios,
2442 CLOCK_SOURCE_COMBO_PHY_PLL3,
2443 &clk_src_regs[3], false);
2444 pool->base.clock_sources[DCN30_CLK_SRC_PLL4] =
2445 dcn30_clock_source_create(ctx, ctx->dc_bios,
2446 CLOCK_SOURCE_COMBO_PHY_PLL4,
2447 &clk_src_regs[4], false);
2448 pool->base.clock_sources[DCN30_CLK_SRC_PLL5] =
2449 dcn30_clock_source_create(ctx, ctx->dc_bios,
2450 CLOCK_SOURCE_COMBO_PHY_PLL5,
2451 &clk_src_regs[5], false);
2452
2453 pool->base.clk_src_count = DCN30_CLK_SRC_TOTAL;
2454
2455 /* todo: not reuse phy_pll registers */
2456 pool->base.dp_clock_source =
2457 dcn30_clock_source_create(ctx, ctx->dc_bios,
2458 CLOCK_SOURCE_ID_DP_DTO,
2459 &clk_src_regs[0], true);
2460
2461 for (i = 0; i < pool->base.clk_src_count; i++) {
2462 if (pool->base.clock_sources[i] == NULL) {
2463 dm_error("DC: failed to create clock sources!\n");
2464 BREAK_TO_DEBUGGER();
2465 goto create_fail;
2466 }
2467 }
2468
2469 /* DCCG */
2470 pool->base.dccg = dccg30_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
2471 if (pool->base.dccg == NULL) {
2472 dm_error("DC: failed to create dccg!\n");
2473 BREAK_TO_DEBUGGER();
2474 goto create_fail;
2475 }
2476
2477 /* PP Lib and SMU interfaces */
2478 init_soc_bounding_box(dc, pool);
2479
2480 num_pipes = dcn3_0_ip.max_num_dpp;
2481
2482 for (i = 0; i < dcn3_0_ip.max_num_dpp; i++)
2483 if (pipe_fuses & 1 << i)
2484 num_pipes--;
2485
2486 dcn3_0_ip.max_num_dpp = num_pipes;
2487 dcn3_0_ip.max_num_otg = num_pipes;
2488
2489 dml_init_instance(&dc->dml, &dcn3_0_soc, &dcn3_0_ip, DML_PROJECT_DCN30);
2490
2491 /* IRQ */
2492 init_data.ctx = dc->ctx;
2493 pool->base.irqs = dal_irq_service_dcn30_create(&init_data);
2494 if (!pool->base.irqs)
2495 goto create_fail;
2496
2497 /* HUBBUB */
2498 pool->base.hubbub = dcn30_hubbub_create(ctx);
2499 if (pool->base.hubbub == NULL) {
2500 BREAK_TO_DEBUGGER();
2501 dm_error("DC: failed to create hubbub!\n");
2502 goto create_fail;
2503 }
2504
2505 /* DIO */
2506 pool->base.dio = dcn30_dio_create(ctx);
2507 if (pool->base.dio == NULL) {
2508 BREAK_TO_DEBUGGER();
2509 dm_error("DC: failed to create dio!\n");
2510 goto create_fail;
2511 }
2512
2513 /* HUBPs, DPPs, OPPs and TGs */
2514 for (i = 0; i < pool->base.pipe_count; i++) {
2515 pool->base.hubps[i] = dcn30_hubp_create(ctx, i);
2516 if (pool->base.hubps[i] == NULL) {
2517 BREAK_TO_DEBUGGER();
2518 dm_error(
2519 "DC: failed to create hubps!\n");
2520 goto create_fail;
2521 }
2522
2523 pool->base.dpps[i] = dcn30_dpp_create(ctx, i);
2524 if (pool->base.dpps[i] == NULL) {
2525 BREAK_TO_DEBUGGER();
2526 dm_error(
2527 "DC: failed to create dpps!\n");
2528 goto create_fail;
2529 }
2530 }
2531
2532 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
2533 pool->base.opps[i] = dcn30_opp_create(ctx, i);
2534 if (pool->base.opps[i] == NULL) {
2535 BREAK_TO_DEBUGGER();
2536 dm_error(
2537 "DC: failed to create output pixel processor!\n");
2538 goto create_fail;
2539 }
2540 }
2541
2542 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2543 pool->base.timing_generators[i] = dcn30_timing_generator_create(
2544 ctx, i);
2545 if (pool->base.timing_generators[i] == NULL) {
2546 BREAK_TO_DEBUGGER();
2547 dm_error("DC: failed to create tg!\n");
2548 goto create_fail;
2549 }
2550 }
2551 pool->base.timing_generator_count = i;
2552 /* PSR */
2553 pool->base.psr = dmub_psr_create(ctx);
2554
2555 if (pool->base.psr == NULL) {
2556 dm_error("DC: failed to create PSR obj!\n");
2557 BREAK_TO_DEBUGGER();
2558 goto create_fail;
2559 }
2560
2561 /* ABM */
2562 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2563 pool->base.multiple_abms[i] = dmub_abm_create(ctx,
2564 &abm_regs[i],
2565 &abm_shift,
2566 &abm_mask);
2567 if (pool->base.multiple_abms[i] == NULL) {
2568 dm_error("DC: failed to create abm for pipe %d!\n", i);
2569 BREAK_TO_DEBUGGER();
2570 goto create_fail;
2571 }
2572 }
2573 /* MPC and DSC */
2574 pool->base.mpc = dcn30_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut);
2575 if (pool->base.mpc == NULL) {
2576 BREAK_TO_DEBUGGER();
2577 dm_error("DC: failed to create mpc!\n");
2578 goto create_fail;
2579 }
2580
2581 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2582 pool->base.dscs[i] = dcn30_dsc_create(ctx, i);
2583 if (pool->base.dscs[i] == NULL) {
2584 BREAK_TO_DEBUGGER();
2585 dm_error("DC: failed to create display stream compressor %d!\n", i);
2586 goto create_fail;
2587 }
2588 }
2589
2590 /* DWB and MMHUBBUB */
2591 if (!dcn30_dwbc_create(ctx, &pool->base)) {
2592 BREAK_TO_DEBUGGER();
2593 dm_error("DC: failed to create dwbc!\n");
2594 goto create_fail;
2595 }
2596
2597 if (!dcn30_mmhubbub_create(ctx, &pool->base)) {
2598 BREAK_TO_DEBUGGER();
2599 dm_error("DC: failed to create mcif_wb!\n");
2600 goto create_fail;
2601 }
2602
2603 /* AUX and I2C */
2604 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2605 pool->base.engines[i] = dcn30_aux_engine_create(ctx, i);
2606 if (pool->base.engines[i] == NULL) {
2607 BREAK_TO_DEBUGGER();
2608 dm_error(
2609 "DC:failed to create aux engine!!\n");
2610 goto create_fail;
2611 }
2612 pool->base.hw_i2cs[i] = dcn30_i2c_hw_create(ctx, i);
2613 if (pool->base.hw_i2cs[i] == NULL) {
2614 BREAK_TO_DEBUGGER();
2615 dm_error(
2616 "DC:failed to create hw i2c!!\n");
2617 goto create_fail;
2618 }
2619 pool->base.sw_i2cs[i] = NULL;
2620 }
2621
2622 /* Audio, Stream Encoders including HPO and virtual, MPC 3D LUTs */
2623 if (!resource_construct(num_virtual_links, dc, &pool->base,
2624 &res_create_funcs))
2625 goto create_fail;
2626
2627 /* HW Sequencer and Plane caps */
2628 dcn30_hw_sequencer_construct(dc);
2629
2630 dc->caps.max_planes = pool->base.pipe_count;
2631
2632 for (i = 0; i < dc->caps.max_planes; ++i)
2633 dc->caps.planes[i] = plane_cap;
2634
2635 dc->caps.max_odm_combine_factor = 4;
2636
2637 dc->cap_funcs = cap_funcs;
2638
2639 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2640 ddc_init_data.ctx = dc->ctx;
2641 ddc_init_data.link = NULL;
2642 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2643 ddc_init_data.id.enum_id = 0;
2644 ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2645 pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2646 } else {
2647 pool->base.oem_device = NULL;
2648 }
2649
2650 DC_FP_END();
2651
2652 return true;
2653
2654 create_fail:
2655
2656 DC_FP_END();
2657 dcn30_resource_destruct(pool);
2658
2659 return false;
2660 }
2661
dcn30_create_resource_pool(const struct dc_init_data * init_data,struct dc * dc)2662 struct resource_pool *dcn30_create_resource_pool(
2663 const struct dc_init_data *init_data,
2664 struct dc *dc)
2665 {
2666 struct dcn30_resource_pool *pool =
2667 kzalloc_obj(struct dcn30_resource_pool);
2668
2669 if (!pool)
2670 return NULL;
2671
2672 if (dcn30_resource_construct(init_data->num_virtual_links, dc, pool))
2673 return &pool->base;
2674
2675 BREAK_TO_DEBUGGER();
2676 kfree(pool);
2677 return NULL;
2678 }
2679