1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "dm_services.h"
30 #include "dcn32_init.h"
33 #include "include/irq_service_interface.h"
34 #include "dcn32_resource.h"
36 #include "dcn20/dcn20_resource.h"
37 #include "dcn30/dcn30_resource.h"
39 #include "dcn10/dcn10_ipp.h"
40 #include "dcn30/dcn30_hubbub.h"
41 #include "dcn31/dcn31_hubbub.h"
42 #include "dcn32/dcn32_hubbub.h"
43 #include "dcn32/dcn32_mpc.h"
44 #include "dcn32_hubp.h"
45 #include "irq/dcn32/irq_service_dcn32.h"
46 #include "dcn32/dcn32_dpp.h"
47 #include "dcn32/dcn32_optc.h"
48 #include "dcn20/dcn20_hwseq.h"
49 #include "dcn30/dcn30_hwseq.h"
50 #include "dce110/dce110_hw_sequencer.h"
51 #include "dcn30/dcn30_opp.h"
52 #include "dcn20/dcn20_dsc.h"
53 #include "dcn30/dcn30_vpg.h"
54 #include "dcn30/dcn30_afmt.h"
55 #include "dcn30/dcn30_dio_stream_encoder.h"
56 #include "dcn32/dcn32_dio_stream_encoder.h"
57 #include "dcn31/dcn31_hpo_dp_stream_encoder.h"
58 #include "dcn31/dcn31_hpo_dp_link_encoder.h"
59 #include "dcn32/dcn32_hpo_dp_link_encoder.h"
60 #include "dc_link_dp.h"
61 #include "dcn31/dcn31_apg.h"
62 #include "dcn31/dcn31_dio_link_encoder.h"
63 #include "dcn32/dcn32_dio_link_encoder.h"
64 #include "dce/dce_clock_source.h"
65 #include "dce/dce_audio.h"
66 #include "dce/dce_hwseq.h"
68 #include "virtual/virtual_stream_encoder.h"
69 #include "dml/display_mode_vba.h"
70 #include "dcn32/dcn32_dccg.h"
71 #include "dcn10/dcn10_resource.h"
72 #include "dc_link_ddc.h"
73 #include "dcn31/dcn31_panel_cntl.h"
75 #include "dcn30/dcn30_dwb.h"
76 #include "dcn32/dcn32_mmhubbub.h"
78 #include "dcn/dcn_3_2_0_offset.h"
79 #include "dcn/dcn_3_2_0_sh_mask.h"
80 #include "nbio/nbio_4_3_0_offset.h"
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"
88 #include "dml/dcn30/display_mode_vba_30.h"
89 #include "vm_helper.h"
90 #include "dcn20/dcn20_vmid.h"
91 #include "dml/dcn32/dcn32_fpu.h"
93 #define DCN_BASE__INST0_SEG1 0x000000C0
94 #define DCN_BASE__INST0_SEG2 0x000034C0
95 #define DCN_BASE__INST0_SEG3 0x00009000
96 #define NBIO_BASE__INST0_SEG1 0x00000014
98 #define MAX_INSTANCE 6
101 struct IP_BASE_INSTANCE {
102 unsigned int segment[MAX_SEGMENT];
106 struct IP_BASE_INSTANCE instance[MAX_INSTANCE];
109 static const struct IP_BASE DCN_BASE = { { { { 0x00000012, 0x000000C0, 0x000034C0, 0x00009000, 0x02403C00, 0 } },
110 { { 0, 0, 0, 0, 0, 0 } },
111 { { 0, 0, 0, 0, 0, 0 } },
112 { { 0, 0, 0, 0, 0, 0 } },
113 { { 0, 0, 0, 0, 0, 0 } },
114 { { 0, 0, 0, 0, 0, 0 } } } };
116 #define DC_LOGGER_INIT(logger)
118 enum dcn32_clk_src_array_id {
127 /* begin *********************
128 * macros to expend register list macro defined in HW object header file
132 /* TODO awful hack. fixup dcn20_dwb.h */
134 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
136 #define BASE(seg) BASE_INNER(seg)
138 #define SR(reg_name)\
139 .reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
142 #define SRI(reg_name, block, id)\
143 .reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
144 reg ## block ## id ## _ ## reg_name
146 #define SRI2(reg_name, block, id)\
147 .reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
150 #define SRIR(var_name, reg_name, block, id)\
151 .var_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
152 reg ## block ## id ## _ ## reg_name
154 #define SRII(reg_name, block, id)\
155 .reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
156 reg ## block ## id ## _ ## reg_name
158 #define SRII_MPC_RMU(reg_name, block, id)\
159 .RMU##_##reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
160 reg ## block ## id ## _ ## reg_name
162 #define SRII_DWB(reg_name, temp_name, block, id)\
163 .reg_name[id] = BASE(reg ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
164 reg ## block ## id ## _ ## temp_name
166 #define DCCG_SRII(reg_name, block, id)\
167 .block ## _ ## reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
168 reg ## block ## id ## _ ## reg_name
170 #define VUPDATE_SRII(reg_name, block, id)\
171 .reg_name[id] = BASE(reg ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
172 reg ## reg_name ## _ ## block ## id
175 #define NBIO_BASE_INNER(seg) \
176 NBIO_BASE__INST0_SEG ## seg
178 #define NBIO_BASE(seg) \
181 #define NBIO_SR(reg_name)\
182 .reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
183 regBIF_BX0_ ## reg_name
187 #define REG(reg_name) \
188 (DCN_BASE.instance[0].segment[reg ## reg_name ## _BASE_IDX] + reg ## reg_name)
190 static const struct bios_registers bios_regs = {
191 NBIO_SR(BIOS_SCRATCH_3),
192 NBIO_SR(BIOS_SCRATCH_6)
195 #define clk_src_regs(index, pllid)\
197 CS_COMMON_REG_LIST_DCN3_0(index, pllid),\
200 static const struct dce110_clk_src_regs clk_src_regs[] = {
208 static const struct dce110_clk_src_shift cs_shift = {
209 CS_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
212 static const struct dce110_clk_src_mask cs_mask = {
213 CS_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
216 #define abm_regs(id)\
218 ABM_DCN32_REG_LIST(id)\
221 static const struct dce_abm_registers abm_regs[] = {
228 static const struct dce_abm_shift abm_shift = {
229 ABM_MASK_SH_LIST_DCN32(__SHIFT)
232 static const struct dce_abm_mask abm_mask = {
233 ABM_MASK_SH_LIST_DCN32(_MASK)
236 #define audio_regs(id)\
238 AUD_COMMON_REG_LIST(id)\
241 static const struct dce_audio_registers audio_regs[] = {
249 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
250 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
251 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
252 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
254 static const struct dce_audio_shift audio_shift = {
255 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
258 static const struct dce_audio_mask audio_mask = {
259 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
262 #define vpg_regs(id)\
264 VPG_DCN3_REG_LIST(id)\
267 static const struct dcn30_vpg_registers vpg_regs[] = {
280 static const struct dcn30_vpg_shift vpg_shift = {
281 DCN3_VPG_MASK_SH_LIST(__SHIFT)
284 static const struct dcn30_vpg_mask vpg_mask = {
285 DCN3_VPG_MASK_SH_LIST(_MASK)
288 #define afmt_regs(id)\
290 AFMT_DCN3_REG_LIST(id)\
293 static const struct dcn30_afmt_registers afmt_regs[] = {
302 static const struct dcn30_afmt_shift afmt_shift = {
303 DCN3_AFMT_MASK_SH_LIST(__SHIFT)
306 static const struct dcn30_afmt_mask afmt_mask = {
307 DCN3_AFMT_MASK_SH_LIST(_MASK)
310 #define apg_regs(id)\
312 APG_DCN31_REG_LIST(id)\
315 static const struct dcn31_apg_registers apg_regs[] = {
322 static const struct dcn31_apg_shift apg_shift = {
323 DCN31_APG_MASK_SH_LIST(__SHIFT)
326 static const struct dcn31_apg_mask apg_mask = {
327 DCN31_APG_MASK_SH_LIST(_MASK)
330 #define stream_enc_regs(id)\
332 SE_DCN32_REG_LIST(id)\
335 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
343 static const struct dcn10_stream_encoder_shift se_shift = {
344 SE_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
347 static const struct dcn10_stream_encoder_mask se_mask = {
348 SE_COMMON_MASK_SH_LIST_DCN32(_MASK)
352 #define aux_regs(id)\
354 DCN2_AUX_REG_LIST(id)\
357 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
365 #define hpd_regs(id)\
370 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
378 #define link_regs(id, phyid)\
380 LE_DCN31_REG_LIST(id), \
381 UNIPHY_DCN2_REG_LIST(phyid), \
382 /*DPCS_DCN31_REG_LIST(id),*/ \
385 static const struct dcn10_link_enc_registers link_enc_regs[] = {
393 static const struct dcn10_link_enc_shift le_shift = {
394 LINK_ENCODER_MASK_SH_LIST_DCN31(__SHIFT), \
395 //DPCS_DCN31_MASK_SH_LIST(__SHIFT)
398 static const struct dcn10_link_enc_mask le_mask = {
399 LINK_ENCODER_MASK_SH_LIST_DCN31(_MASK), \
401 //DPCS_DCN31_MASK_SH_LIST(_MASK)
404 #define hpo_dp_stream_encoder_reg_list(id)\
406 DCN3_1_HPO_DP_STREAM_ENC_REG_LIST(id)\
409 static const struct dcn31_hpo_dp_stream_encoder_registers hpo_dp_stream_enc_regs[] = {
410 hpo_dp_stream_encoder_reg_list(0),
411 hpo_dp_stream_encoder_reg_list(1),
412 hpo_dp_stream_encoder_reg_list(2),
413 hpo_dp_stream_encoder_reg_list(3),
416 static const struct dcn31_hpo_dp_stream_encoder_shift hpo_dp_se_shift = {
417 DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(__SHIFT)
420 static const struct dcn31_hpo_dp_stream_encoder_mask hpo_dp_se_mask = {
421 DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(_MASK)
425 #define hpo_dp_link_encoder_reg_list(id)\
427 DCN3_1_HPO_DP_LINK_ENC_REG_LIST(id),\
428 /*DCN3_1_RDPCSTX_REG_LIST(0),*/\
429 /*DCN3_1_RDPCSTX_REG_LIST(1),*/\
430 /*DCN3_1_RDPCSTX_REG_LIST(2),*/\
431 /*DCN3_1_RDPCSTX_REG_LIST(3),*/\
432 /*DCN3_1_RDPCSTX_REG_LIST(4)*/\
435 static const struct dcn31_hpo_dp_link_encoder_registers hpo_dp_link_enc_regs[] = {
436 hpo_dp_link_encoder_reg_list(0),
437 hpo_dp_link_encoder_reg_list(1),
440 static const struct dcn31_hpo_dp_link_encoder_shift hpo_dp_le_shift = {
441 DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(__SHIFT)
444 static const struct dcn31_hpo_dp_link_encoder_mask hpo_dp_le_mask = {
445 DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(_MASK)
448 #define dpp_regs(id)\
450 DPP_REG_LIST_DCN30_COMMON(id),\
453 static const struct dcn3_dpp_registers dpp_regs[] = {
460 static const struct dcn3_dpp_shift tf_shift = {
461 DPP_REG_LIST_SH_MASK_DCN30_COMMON(__SHIFT)
464 static const struct dcn3_dpp_mask tf_mask = {
465 DPP_REG_LIST_SH_MASK_DCN30_COMMON(_MASK)
469 #define opp_regs(id)\
471 OPP_REG_LIST_DCN30(id),\
474 static const struct dcn20_opp_registers opp_regs[] = {
481 static const struct dcn20_opp_shift opp_shift = {
482 OPP_MASK_SH_LIST_DCN20(__SHIFT)
485 static const struct dcn20_opp_mask opp_mask = {
486 OPP_MASK_SH_LIST_DCN20(_MASK)
489 #define aux_engine_regs(id)\
491 AUX_COMMON_REG_LIST0(id), \
494 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
497 static const struct dce110_aux_registers aux_engine_regs[] = {
505 static const struct dce110_aux_registers_shift aux_shift = {
506 DCN_AUX_MASK_SH_LIST(__SHIFT)
509 static const struct dce110_aux_registers_mask aux_mask = {
510 DCN_AUX_MASK_SH_LIST(_MASK)
514 #define dwbc_regs_dcn3(id)\
516 DWBC_COMMON_REG_LIST_DCN30(id),\
519 static const struct dcn30_dwbc_registers dwbc30_regs[] = {
523 static const struct dcn30_dwbc_shift dwbc30_shift = {
524 DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
527 static const struct dcn30_dwbc_mask dwbc30_mask = {
528 DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
531 #define mcif_wb_regs_dcn3(id)\
533 MCIF_WB_COMMON_REG_LIST_DCN32(id),\
536 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = {
540 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
541 MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
544 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
545 MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK)
548 #define dsc_regsDCN20(id)\
550 DSC_REG_LIST_DCN20(id)\
553 static const struct dcn20_dsc_registers dsc_regs[] = {
560 static const struct dcn20_dsc_shift dsc_shift = {
561 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
564 static const struct dcn20_dsc_mask dsc_mask = {
565 DSC_REG_LIST_SH_MASK_DCN20(_MASK)
568 static const struct dcn30_mpc_registers mpc_regs = {
569 MPC_REG_LIST_DCN3_2(0),
570 MPC_REG_LIST_DCN3_2(1),
571 MPC_REG_LIST_DCN3_2(2),
572 MPC_REG_LIST_DCN3_2(3),
573 MPC_OUT_MUX_REG_LIST_DCN3_0(0),
574 MPC_OUT_MUX_REG_LIST_DCN3_0(1),
575 MPC_OUT_MUX_REG_LIST_DCN3_0(2),
576 MPC_OUT_MUX_REG_LIST_DCN3_0(3),
577 MPC_DWB_MUX_REG_LIST_DCN3_0(0),
580 static const struct dcn30_mpc_shift mpc_shift = {
581 MPC_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
584 static const struct dcn30_mpc_mask mpc_mask = {
585 MPC_COMMON_MASK_SH_LIST_DCN32(_MASK)
588 #define optc_regs(id)\
589 [id] = {OPTC_COMMON_REG_LIST_DCN3_2(id)}
592 //static struct dcn_optc_registers optc_regs[] = {
594 static const struct dcn_optc_registers optc_regs[] = {
602 static const struct dcn_optc_shift optc_shift = {
603 OPTC_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
606 static const struct dcn_optc_mask optc_mask = {
607 OPTC_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
610 #define hubp_regs(id)\
612 HUBP_REG_LIST_DCN32(id)\
615 static const struct dcn_hubp2_registers hubp_regs[] = {
623 static const struct dcn_hubp2_shift hubp_shift = {
624 HUBP_MASK_SH_LIST_DCN32(__SHIFT)
627 static const struct dcn_hubp2_mask hubp_mask = {
628 HUBP_MASK_SH_LIST_DCN32(_MASK)
630 static const struct dcn_hubbub_registers hubbub_reg = {
631 HUBBUB_REG_LIST_DCN32(0)
634 static const struct dcn_hubbub_shift hubbub_shift = {
635 HUBBUB_MASK_SH_LIST_DCN32(__SHIFT)
638 static const struct dcn_hubbub_mask hubbub_mask = {
639 HUBBUB_MASK_SH_LIST_DCN32(_MASK)
642 static const struct dccg_registers dccg_regs = {
643 DCCG_REG_LIST_DCN32()
646 static const struct dccg_shift dccg_shift = {
647 DCCG_MASK_SH_LIST_DCN32(__SHIFT)
650 static const struct dccg_mask dccg_mask = {
651 DCCG_MASK_SH_LIST_DCN32(_MASK)
655 #define SRII2(reg_name_pre, reg_name_post, id)\
656 .reg_name_pre ## _ ## reg_name_post[id] = BASE(reg ## reg_name_pre \
657 ## id ## _ ## reg_name_post ## _BASE_IDX) + \
658 reg ## reg_name_pre ## id ## _ ## reg_name_post
661 #define HWSEQ_DCN32_REG_LIST()\
662 SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \
663 SR(DIO_MEM_PWR_CTRL), \
664 SR(ODM_MEM_PWR_CTRL3), \
665 SR(MMHUBBUB_MEM_PWR_CNTL), \
666 SR(DCCG_GATE_DISABLE_CNTL), \
667 SR(DCCG_GATE_DISABLE_CNTL2), \
669 SR(DC_MEM_GLOBAL_PWR_REQ_CNTL), \
670 SRII(PIXEL_RATE_CNTL, OTG, 0), \
671 SRII(PIXEL_RATE_CNTL, OTG, 1),\
672 SRII(PIXEL_RATE_CNTL, OTG, 2),\
673 SRII(PIXEL_RATE_CNTL, OTG, 3),\
674 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 0),\
675 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 1),\
676 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 2),\
677 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 3),\
678 SR(MICROSECOND_TIME_BASE_DIV), \
679 SR(MILLISECOND_TIME_BASE_DIV), \
680 SR(DISPCLK_FREQ_CHANGE_CNTL), \
681 SR(RBBMIF_TIMEOUT_DIS), \
682 SR(RBBMIF_TIMEOUT_DIS_2), \
683 SR(DCHUBBUB_CRC_CTRL), \
684 SR(DPP_TOP0_DPP_CRC_CTRL), \
685 SR(DPP_TOP0_DPP_CRC_VAL_B_A), \
686 SR(DPP_TOP0_DPP_CRC_VAL_R_G), \
688 SR(MPC_CRC_RESULT_GB), \
689 SR(MPC_CRC_RESULT_C), \
690 SR(MPC_CRC_RESULT_AR), \
691 SR(DOMAIN0_PG_CONFIG), \
692 SR(DOMAIN1_PG_CONFIG), \
693 SR(DOMAIN2_PG_CONFIG), \
694 SR(DOMAIN3_PG_CONFIG), \
695 SR(DOMAIN16_PG_CONFIG), \
696 SR(DOMAIN17_PG_CONFIG), \
697 SR(DOMAIN18_PG_CONFIG), \
698 SR(DOMAIN19_PG_CONFIG), \
699 SR(DOMAIN0_PG_STATUS), \
700 SR(DOMAIN1_PG_STATUS), \
701 SR(DOMAIN2_PG_STATUS), \
702 SR(DOMAIN3_PG_STATUS), \
703 SR(DOMAIN16_PG_STATUS), \
704 SR(DOMAIN17_PG_STATUS), \
705 SR(DOMAIN18_PG_STATUS), \
706 SR(DOMAIN19_PG_STATUS), \
713 SR(DC_IP_REQUEST_CNTL), \
714 SR(AZALIA_AUDIO_DTO), \
715 SR(AZALIA_CONTROLLER_CLOCK_GATING)
717 static const struct dce_hwseq_registers hwseq_reg = {
718 HWSEQ_DCN32_REG_LIST()
721 #define HWSEQ_DCN32_MASK_SH_LIST(mask_sh)\
722 HWSEQ_DCN_MASK_SH_LIST(mask_sh), \
723 HWS_SF(, DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, mask_sh), \
724 HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
725 HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
726 HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
727 HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
728 HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
729 HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
730 HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
731 HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
732 HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
733 HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
734 HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
735 HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
736 HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
737 HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
738 HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
739 HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
740 HWS_SF(, DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
741 HWS_SF(, DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
742 HWS_SF(, DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
743 HWS_SF(, DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
744 HWS_SF(, DOMAIN16_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
745 HWS_SF(, DOMAIN17_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
746 HWS_SF(, DOMAIN18_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
747 HWS_SF(, DOMAIN19_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
748 HWS_SF(, DC_IP_REQUEST_CNTL, IP_REQUEST_EN, mask_sh), \
749 HWS_SF(, AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, mask_sh), \
750 HWS_SF(, HPO_TOP_CLOCK_CONTROL, HPO_HDMISTREAMCLK_G_GATE_DIS, mask_sh), \
751 HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_UNASSIGNED_PWR_MODE, mask_sh), \
752 HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_VBLANK_PWR_MODE, mask_sh), \
753 HWS_SF(, MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, mask_sh)
755 static const struct dce_hwseq_shift hwseq_shift = {
756 HWSEQ_DCN32_MASK_SH_LIST(__SHIFT)
759 static const struct dce_hwseq_mask hwseq_mask = {
760 HWSEQ_DCN32_MASK_SH_LIST(_MASK)
762 #define vmid_regs(id)\
764 DCN20_VMID_REG_LIST(id)\
767 static const struct dcn_vmid_registers vmid_regs[] = {
786 static const struct dcn20_vmid_shift vmid_shifts = {
787 DCN20_VMID_MASK_SH_LIST(__SHIFT)
790 static const struct dcn20_vmid_mask vmid_masks = {
791 DCN20_VMID_MASK_SH_LIST(_MASK)
794 static const struct resource_caps res_cap_dcn32 = {
795 .num_timing_generator = 4,
797 .num_video_plane = 4,
799 .num_stream_encoder = 5,
800 .num_hpo_dp_stream_encoder = 4,
801 .num_hpo_dp_link_encoder = 2,
810 static const struct dc_plane_cap plane_cap = {
811 .type = DC_PLANE_TYPE_DCN_UNIVERSAL,
812 .blends_with_above = true,
813 .blends_with_below = true,
814 .per_pixel_alpha = true,
816 .pixel_format_support = {
824 .max_upscale_factor = {
830 // 6:1 downscaling ratio: 1000/6 = 166.666
831 .max_downscale_factor = {
840 static const struct dc_debug_options debug_defaults_drv = {
841 .disable_dmcu = true,
842 .force_abm_enable = false,
843 .timing_trace = false,
845 .disable_pplib_clock_request = false,
846 .pipe_split_policy = MPC_SPLIT_AVOID, // Due to CRB, no need to MPC split anymore
847 .force_single_disp_pipe_split = false,
848 .disable_dcc = DCC_ENABLE,
850 .performance_trace = false,
851 .max_downscale_src_width = 7680,/*upto 8K*/
852 .disable_pplib_wm_range = false,
853 .scl_reset_length10 = true,
854 .sanity_checks = false,
855 .underflow_assert_delay_us = 0xFFFFFFFF,
856 .dwb_fi_phase = -1, // -1 = disable,
857 .dmub_command_table = true,
858 .enable_mem_low_power = {
862 .dmcu = false, // This is previously known to cause hang on S3 cycles if enabled
870 .force_disable_subvp = false,
871 .exit_idle_opt_for_cursor_updates = true,
872 .enable_single_display_2to1_odm_policy = true,
873 .enable_dp_dig_pixel_rate_div_policy = 1,
876 static const struct dc_debug_options debug_defaults_diags = {
877 .disable_dmcu = true,
878 .force_abm_enable = false,
879 .timing_trace = true,
881 .disable_dpp_power_gate = true,
882 .disable_hubp_power_gate = true,
883 .disable_dsc_power_gate = true,
884 .disable_clock_gate = true,
885 .disable_pplib_clock_request = true,
886 .disable_pplib_wm_range = true,
887 .disable_stutter = false,
888 .scl_reset_length10 = true,
889 .dwb_fi_phase = -1, // -1 = disable
890 .dmub_command_table = true,
891 .enable_tri_buf = true,
893 .force_disable_subvp = true
896 static struct dce_aux *dcn32_aux_engine_create(
897 struct dc_context *ctx,
900 struct aux_engine_dce110 *aux_engine =
901 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
906 dce110_aux_engine_construct(aux_engine, ctx, inst,
907 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
908 &aux_engine_regs[inst],
911 ctx->dc->caps.extended_aux_timeout_support);
913 return &aux_engine->base;
915 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST_DCN30(id) }
917 static const struct dce_i2c_registers i2c_hw_regs[] = {
925 static const struct dce_i2c_shift i2c_shifts = {
926 I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
929 static const struct dce_i2c_mask i2c_masks = {
930 I2C_COMMON_MASK_SH_LIST_DCN30(_MASK)
933 static struct dce_i2c_hw *dcn32_i2c_hw_create(
934 struct dc_context *ctx,
937 struct dce_i2c_hw *dce_i2c_hw =
938 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
943 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
944 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
949 static struct clock_source *dcn32_clock_source_create(
950 struct dc_context *ctx,
951 struct dc_bios *bios,
952 enum clock_source_id id,
953 const struct dce110_clk_src_regs *regs,
956 struct dce110_clk_src *clk_src =
957 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
962 if (dcn31_clk_src_construct(clk_src, ctx, bios, id,
963 regs, &cs_shift, &cs_mask)) {
964 clk_src->base.dp_clk_src = dp_clk_src;
965 return &clk_src->base;
972 static struct hubbub *dcn32_hubbub_create(struct dc_context *ctx)
976 struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub),
982 hubbub32_construct(hubbub2, ctx,
986 ctx->dc->dml.ip.det_buffer_size_kbytes,
987 ctx->dc->dml.ip.pixel_chunk_size_kbytes,
988 ctx->dc->dml.ip.config_return_buffer_size_in_kbytes);
991 for (i = 0; i < res_cap_dcn32.num_vmid; i++) {
992 struct dcn20_vmid *vmid = &hubbub2->vmid[i];
996 vmid->regs = &vmid_regs[i];
997 vmid->shifts = &vmid_shifts;
998 vmid->masks = &vmid_masks;
1001 return &hubbub2->base;
1004 static struct hubp *dcn32_hubp_create(
1005 struct dc_context *ctx,
1008 struct dcn20_hubp *hubp2 =
1009 kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
1014 if (hubp32_construct(hubp2, ctx, inst,
1015 &hubp_regs[inst], &hubp_shift, &hubp_mask))
1016 return &hubp2->base;
1018 BREAK_TO_DEBUGGER();
1023 static void dcn32_dpp_destroy(struct dpp **dpp)
1025 kfree(TO_DCN30_DPP(*dpp));
1029 static struct dpp *dcn32_dpp_create(
1030 struct dc_context *ctx,
1033 struct dcn3_dpp *dpp3 =
1034 kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL);
1039 if (dpp32_construct(dpp3, ctx, inst,
1040 &dpp_regs[inst], &tf_shift, &tf_mask))
1043 BREAK_TO_DEBUGGER();
1048 static struct mpc *dcn32_mpc_create(
1049 struct dc_context *ctx,
1053 struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc),
1059 dcn32_mpc_construct(mpc30, ctx,
1066 return &mpc30->base;
1069 static struct output_pixel_processor *dcn32_opp_create(
1070 struct dc_context *ctx, uint32_t inst)
1072 struct dcn20_opp *opp2 =
1073 kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
1076 BREAK_TO_DEBUGGER();
1080 dcn20_opp_construct(opp2, ctx, inst,
1081 &opp_regs[inst], &opp_shift, &opp_mask);
1086 static struct timing_generator *dcn32_timing_generator_create(
1087 struct dc_context *ctx,
1090 struct optc *tgn10 =
1091 kzalloc(sizeof(struct optc), GFP_KERNEL);
1096 tgn10->base.inst = instance;
1097 tgn10->base.ctx = ctx;
1099 tgn10->tg_regs = &optc_regs[instance];
1100 tgn10->tg_shift = &optc_shift;
1101 tgn10->tg_mask = &optc_mask;
1103 dcn32_timing_generator_init(tgn10);
1105 return &tgn10->base;
1108 static const struct encoder_feature_support link_enc_feature = {
1109 .max_hdmi_deep_color = COLOR_DEPTH_121212,
1110 .max_hdmi_pixel_clock = 600000,
1111 .hdmi_ycbcr420_supported = true,
1112 .dp_ycbcr420_supported = true,
1113 .fec_supported = true,
1114 .flags.bits.IS_HBR2_CAPABLE = true,
1115 .flags.bits.IS_HBR3_CAPABLE = true,
1116 .flags.bits.IS_TPS3_CAPABLE = true,
1117 .flags.bits.IS_TPS4_CAPABLE = true
1120 static struct link_encoder *dcn32_link_encoder_create(
1121 struct dc_context *ctx,
1122 const struct encoder_init_data *enc_init_data)
1124 struct dcn20_link_encoder *enc20 =
1125 kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1130 dcn32_link_encoder_construct(enc20,
1133 &link_enc_regs[enc_init_data->transmitter],
1134 &link_enc_aux_regs[enc_init_data->channel - 1],
1135 &link_enc_hpd_regs[enc_init_data->hpd_source],
1139 return &enc20->enc10.base;
1142 struct panel_cntl *dcn32_panel_cntl_create(const struct panel_cntl_init_data *init_data)
1144 struct dcn31_panel_cntl *panel_cntl =
1145 kzalloc(sizeof(struct dcn31_panel_cntl), GFP_KERNEL);
1150 dcn31_panel_cntl_construct(panel_cntl, init_data);
1152 return &panel_cntl->base;
1155 static void read_dce_straps(
1156 struct dc_context *ctx,
1157 struct resource_straps *straps)
1159 generic_reg_get(ctx, regDC_PINSTRAPS + BASE(regDC_PINSTRAPS_BASE_IDX),
1160 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
1164 static struct audio *dcn32_create_audio(
1165 struct dc_context *ctx, unsigned int inst)
1167 return dce_audio_create(ctx, inst,
1168 &audio_regs[inst], &audio_shift, &audio_mask);
1171 static struct vpg *dcn32_vpg_create(
1172 struct dc_context *ctx,
1175 struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL);
1180 vpg3_construct(vpg3, ctx, inst,
1188 static struct afmt *dcn32_afmt_create(
1189 struct dc_context *ctx,
1192 struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
1197 afmt3_construct(afmt3, ctx, inst,
1202 return &afmt3->base;
1205 static struct apg *dcn31_apg_create(
1206 struct dc_context *ctx,
1209 struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1214 apg31_construct(apg31, ctx, inst,
1219 return &apg31->base;
1222 static struct stream_encoder *dcn32_stream_encoder_create(
1223 enum engine_id eng_id,
1224 struct dc_context *ctx)
1226 struct dcn10_stream_encoder *enc1;
1232 /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1233 if (eng_id <= ENGINE_ID_DIGF) {
1239 enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1240 vpg = dcn32_vpg_create(ctx, vpg_inst);
1241 afmt = dcn32_afmt_create(ctx, afmt_inst);
1243 if (!enc1 || !vpg || !afmt) {
1250 dcn32_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1252 &stream_enc_regs[eng_id],
1253 &se_shift, &se_mask);
1258 static struct hpo_dp_stream_encoder *dcn32_hpo_dp_stream_encoder_create(
1259 enum engine_id eng_id,
1260 struct dc_context *ctx)
1262 struct dcn31_hpo_dp_stream_encoder *hpo_dp_enc31;
1265 uint32_t hpo_dp_inst;
1269 ASSERT((eng_id >= ENGINE_ID_HPO_DP_0) && (eng_id <= ENGINE_ID_HPO_DP_3));
1270 hpo_dp_inst = eng_id - ENGINE_ID_HPO_DP_0;
1272 /* Mapping of VPG register blocks to HPO DP block instance:
1273 * VPG[6] -> HPO_DP[0]
1274 * VPG[7] -> HPO_DP[1]
1275 * VPG[8] -> HPO_DP[2]
1276 * VPG[9] -> HPO_DP[3]
1278 vpg_inst = hpo_dp_inst + 6;
1280 /* Mapping of APG register blocks to HPO DP block instance:
1281 * APG[0] -> HPO_DP[0]
1282 * APG[1] -> HPO_DP[1]
1283 * APG[2] -> HPO_DP[2]
1284 * APG[3] -> HPO_DP[3]
1286 apg_inst = hpo_dp_inst;
1288 /* allocate HPO stream encoder and create VPG sub-block */
1289 hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1290 vpg = dcn32_vpg_create(ctx, vpg_inst);
1291 apg = dcn31_apg_create(ctx, apg_inst);
1293 if (!hpo_dp_enc31 || !vpg || !apg) {
1294 kfree(hpo_dp_enc31);
1300 dcn31_hpo_dp_stream_encoder_construct(hpo_dp_enc31, ctx, ctx->dc_bios,
1301 hpo_dp_inst, eng_id, vpg, apg,
1302 &hpo_dp_stream_enc_regs[hpo_dp_inst],
1303 &hpo_dp_se_shift, &hpo_dp_se_mask);
1305 return &hpo_dp_enc31->base;
1308 static struct hpo_dp_link_encoder *dcn32_hpo_dp_link_encoder_create(
1310 struct dc_context *ctx)
1312 struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1314 /* allocate HPO link encoder */
1315 hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1317 hpo_dp_link_encoder32_construct(hpo_dp_enc31, ctx, inst,
1318 &hpo_dp_link_enc_regs[inst],
1319 &hpo_dp_le_shift, &hpo_dp_le_mask);
1321 return &hpo_dp_enc31->base;
1324 static struct dce_hwseq *dcn32_hwseq_create(
1325 struct dc_context *ctx)
1327 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1331 hws->regs = &hwseq_reg;
1332 hws->shifts = &hwseq_shift;
1333 hws->masks = &hwseq_mask;
1337 static const struct resource_create_funcs res_create_funcs = {
1338 .read_dce_straps = read_dce_straps,
1339 .create_audio = dcn32_create_audio,
1340 .create_stream_encoder = dcn32_stream_encoder_create,
1341 .create_hpo_dp_stream_encoder = dcn32_hpo_dp_stream_encoder_create,
1342 .create_hpo_dp_link_encoder = dcn32_hpo_dp_link_encoder_create,
1343 .create_hwseq = dcn32_hwseq_create,
1346 static const struct resource_create_funcs res_create_maximus_funcs = {
1347 .read_dce_straps = NULL,
1348 .create_audio = NULL,
1349 .create_stream_encoder = NULL,
1350 .create_hpo_dp_stream_encoder = dcn32_hpo_dp_stream_encoder_create,
1351 .create_hpo_dp_link_encoder = dcn32_hpo_dp_link_encoder_create,
1352 .create_hwseq = dcn32_hwseq_create,
1355 static void dcn32_resource_destruct(struct dcn32_resource_pool *pool)
1359 for (i = 0; i < pool->base.stream_enc_count; i++) {
1360 if (pool->base.stream_enc[i] != NULL) {
1361 if (pool->base.stream_enc[i]->vpg != NULL) {
1362 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1363 pool->base.stream_enc[i]->vpg = NULL;
1365 if (pool->base.stream_enc[i]->afmt != NULL) {
1366 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1367 pool->base.stream_enc[i]->afmt = NULL;
1369 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1370 pool->base.stream_enc[i] = NULL;
1374 for (i = 0; i < pool->base.hpo_dp_stream_enc_count; i++) {
1375 if (pool->base.hpo_dp_stream_enc[i] != NULL) {
1376 if (pool->base.hpo_dp_stream_enc[i]->vpg != NULL) {
1377 kfree(DCN30_VPG_FROM_VPG(pool->base.hpo_dp_stream_enc[i]->vpg));
1378 pool->base.hpo_dp_stream_enc[i]->vpg = NULL;
1380 if (pool->base.hpo_dp_stream_enc[i]->apg != NULL) {
1381 kfree(DCN31_APG_FROM_APG(pool->base.hpo_dp_stream_enc[i]->apg));
1382 pool->base.hpo_dp_stream_enc[i]->apg = NULL;
1384 kfree(DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(pool->base.hpo_dp_stream_enc[i]));
1385 pool->base.hpo_dp_stream_enc[i] = NULL;
1389 for (i = 0; i < pool->base.hpo_dp_link_enc_count; i++) {
1390 if (pool->base.hpo_dp_link_enc[i] != NULL) {
1391 kfree(DCN3_1_HPO_DP_LINK_ENC_FROM_HPO_LINK_ENC(pool->base.hpo_dp_link_enc[i]));
1392 pool->base.hpo_dp_link_enc[i] = NULL;
1396 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1397 if (pool->base.dscs[i] != NULL)
1398 dcn20_dsc_destroy(&pool->base.dscs[i]);
1401 if (pool->base.mpc != NULL) {
1402 kfree(TO_DCN20_MPC(pool->base.mpc));
1403 pool->base.mpc = NULL;
1405 if (pool->base.hubbub != NULL) {
1406 kfree(TO_DCN20_HUBBUB(pool->base.hubbub));
1407 pool->base.hubbub = NULL;
1409 for (i = 0; i < pool->base.pipe_count; i++) {
1410 if (pool->base.dpps[i] != NULL)
1411 dcn32_dpp_destroy(&pool->base.dpps[i]);
1413 if (pool->base.ipps[i] != NULL)
1414 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1416 if (pool->base.hubps[i] != NULL) {
1417 kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1418 pool->base.hubps[i] = NULL;
1421 if (pool->base.irqs != NULL) {
1422 dal_irq_service_destroy(&pool->base.irqs);
1426 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1427 if (pool->base.engines[i] != NULL)
1428 dce110_engine_destroy(&pool->base.engines[i]);
1429 if (pool->base.hw_i2cs[i] != NULL) {
1430 kfree(pool->base.hw_i2cs[i]);
1431 pool->base.hw_i2cs[i] = NULL;
1433 if (pool->base.sw_i2cs[i] != NULL) {
1434 kfree(pool->base.sw_i2cs[i]);
1435 pool->base.sw_i2cs[i] = NULL;
1439 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1440 if (pool->base.opps[i] != NULL)
1441 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1444 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1445 if (pool->base.timing_generators[i] != NULL) {
1446 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1447 pool->base.timing_generators[i] = NULL;
1451 for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1452 if (pool->base.dwbc[i] != NULL) {
1453 kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1454 pool->base.dwbc[i] = NULL;
1456 if (pool->base.mcif_wb[i] != NULL) {
1457 kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1458 pool->base.mcif_wb[i] = NULL;
1462 for (i = 0; i < pool->base.audio_count; i++) {
1463 if (pool->base.audios[i])
1464 dce_aud_destroy(&pool->base.audios[i]);
1467 for (i = 0; i < pool->base.clk_src_count; i++) {
1468 if (pool->base.clock_sources[i] != NULL) {
1469 dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1470 pool->base.clock_sources[i] = NULL;
1474 for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1475 if (pool->base.mpc_lut[i] != NULL) {
1476 dc_3dlut_func_release(pool->base.mpc_lut[i]);
1477 pool->base.mpc_lut[i] = NULL;
1479 if (pool->base.mpc_shaper[i] != NULL) {
1480 dc_transfer_func_release(pool->base.mpc_shaper[i]);
1481 pool->base.mpc_shaper[i] = NULL;
1485 if (pool->base.dp_clock_source != NULL) {
1486 dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1487 pool->base.dp_clock_source = NULL;
1490 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1491 if (pool->base.multiple_abms[i] != NULL)
1492 dce_abm_destroy(&pool->base.multiple_abms[i]);
1495 if (pool->base.psr != NULL)
1496 dmub_psr_destroy(&pool->base.psr);
1498 if (pool->base.dccg != NULL)
1499 dcn_dccg_destroy(&pool->base.dccg);
1501 if (pool->base.oem_device != NULL)
1502 dal_ddc_service_destroy(&pool->base.oem_device);
1506 static bool dcn32_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1509 uint32_t dwb_count = pool->res_cap->num_dwb;
1511 for (i = 0; i < dwb_count; i++) {
1512 struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc),
1516 dm_error("DC: failed to create dwbc30!\n");
1520 dcn30_dwbc_construct(dwbc30, ctx,
1526 pool->dwbc[i] = &dwbc30->base;
1531 static bool dcn32_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1534 uint32_t dwb_count = pool->res_cap->num_dwb;
1536 for (i = 0; i < dwb_count; i++) {
1537 struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1541 dm_error("DC: failed to create mcif_wb30!\n");
1545 dcn32_mmhubbub_construct(mcif_wb30, ctx,
1551 pool->mcif_wb[i] = &mcif_wb30->base;
1556 static struct display_stream_compressor *dcn32_dsc_create(
1557 struct dc_context *ctx, uint32_t inst)
1559 struct dcn20_dsc *dsc =
1560 kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1563 BREAK_TO_DEBUGGER();
1567 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1569 dsc->max_image_width = 6016;
1574 static void dcn32_destroy_resource_pool(struct resource_pool **pool)
1576 struct dcn32_resource_pool *dcn32_pool = TO_DCN32_RES_POOL(*pool);
1578 dcn32_resource_destruct(dcn32_pool);
1583 bool dcn32_acquire_post_bldn_3dlut(
1584 struct resource_context *res_ctx,
1585 const struct resource_pool *pool,
1587 struct dc_3dlut **lut,
1588 struct dc_transfer_func **shaper)
1591 union dc_3dlut_state *state;
1593 ASSERT(*lut == NULL && *shaper == NULL);
1597 if (!res_ctx->is_mpc_3dlut_acquired[mpcc_id]) {
1598 *lut = pool->mpc_lut[mpcc_id];
1599 *shaper = pool->mpc_shaper[mpcc_id];
1600 state = &pool->mpc_lut[mpcc_id]->state;
1601 res_ctx->is_mpc_3dlut_acquired[mpcc_id] = true;
1607 bool dcn32_release_post_bldn_3dlut(
1608 struct resource_context *res_ctx,
1609 const struct resource_pool *pool,
1610 struct dc_3dlut **lut,
1611 struct dc_transfer_func **shaper)
1616 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1617 if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) {
1618 res_ctx->is_mpc_3dlut_acquired[i] = false;
1619 pool->mpc_lut[i]->state.raw = 0;
1629 static void dcn32_enable_phantom_plane(struct dc *dc,
1630 struct dc_state *context,
1631 struct dc_stream_state *phantom_stream,
1632 unsigned int dc_pipe_idx)
1634 struct dc_plane_state *phantom_plane = NULL;
1635 struct dc_plane_state *prev_phantom_plane = NULL;
1636 struct pipe_ctx *curr_pipe = &context->res_ctx.pipe_ctx[dc_pipe_idx];
1639 if (curr_pipe->top_pipe && curr_pipe->top_pipe->plane_state == curr_pipe->plane_state)
1640 phantom_plane = prev_phantom_plane;
1642 phantom_plane = dc_create_plane_state(dc);
1644 memcpy(&phantom_plane->address, &curr_pipe->plane_state->address, sizeof(phantom_plane->address));
1645 memcpy(&phantom_plane->scaling_quality, &curr_pipe->plane_state->scaling_quality,
1646 sizeof(phantom_plane->scaling_quality));
1647 memcpy(&phantom_plane->src_rect, &curr_pipe->plane_state->src_rect, sizeof(phantom_plane->src_rect));
1648 memcpy(&phantom_plane->dst_rect, &curr_pipe->plane_state->dst_rect, sizeof(phantom_plane->dst_rect));
1649 memcpy(&phantom_plane->clip_rect, &curr_pipe->plane_state->clip_rect, sizeof(phantom_plane->clip_rect));
1650 memcpy(&phantom_plane->plane_size, &curr_pipe->plane_state->plane_size,
1651 sizeof(phantom_plane->plane_size));
1652 memcpy(&phantom_plane->tiling_info, &curr_pipe->plane_state->tiling_info,
1653 sizeof(phantom_plane->tiling_info));
1654 memcpy(&phantom_plane->dcc, &curr_pipe->plane_state->dcc, sizeof(phantom_plane->dcc));
1655 phantom_plane->format = curr_pipe->plane_state->format;
1656 phantom_plane->rotation = curr_pipe->plane_state->rotation;
1657 phantom_plane->visible = curr_pipe->plane_state->visible;
1659 /* Shadow pipe has small viewport. */
1660 phantom_plane->clip_rect.y = 0;
1661 phantom_plane->clip_rect.height = phantom_stream->timing.v_addressable;
1663 dc_add_plane_to_context(dc, phantom_stream, phantom_plane, context);
1665 curr_pipe = curr_pipe->bottom_pipe;
1666 prev_phantom_plane = phantom_plane;
1670 static struct dc_stream_state *dcn32_enable_phantom_stream(struct dc *dc,
1671 struct dc_state *context,
1672 display_e2e_pipe_params_st *pipes,
1673 unsigned int pipe_cnt,
1674 unsigned int dc_pipe_idx)
1676 struct dc_stream_state *phantom_stream = NULL;
1677 struct pipe_ctx *ref_pipe = &context->res_ctx.pipe_ctx[dc_pipe_idx];
1679 phantom_stream = dc_create_stream_for_sink(ref_pipe->stream->sink);
1680 phantom_stream->signal = SIGNAL_TYPE_VIRTUAL;
1681 phantom_stream->dpms_off = true;
1682 phantom_stream->mall_stream_config.type = SUBVP_PHANTOM;
1683 phantom_stream->mall_stream_config.paired_stream = ref_pipe->stream;
1684 ref_pipe->stream->mall_stream_config.type = SUBVP_MAIN;
1685 ref_pipe->stream->mall_stream_config.paired_stream = phantom_stream;
1687 /* stream has limited viewport and small timing */
1688 memcpy(&phantom_stream->timing, &ref_pipe->stream->timing, sizeof(phantom_stream->timing));
1689 memcpy(&phantom_stream->src, &ref_pipe->stream->src, sizeof(phantom_stream->src));
1690 memcpy(&phantom_stream->dst, &ref_pipe->stream->dst, sizeof(phantom_stream->dst));
1692 dcn32_set_phantom_stream_timing(dc, context, ref_pipe, phantom_stream, pipes, pipe_cnt, dc_pipe_idx);
1695 dc_add_stream_to_ctx(dc, context, phantom_stream);
1696 return phantom_stream;
1699 // return true if removed piped from ctx, false otherwise
1700 bool dcn32_remove_phantom_pipes(struct dc *dc, struct dc_state *context)
1703 bool removed_pipe = false;
1705 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1706 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1707 // build scaling params for phantom pipes
1708 if (pipe->plane_state && pipe->stream && pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
1709 dc_rem_all_planes_for_stream(dc, pipe->stream, context);
1710 dc_remove_stream_from_ctx(dc, context, pipe->stream);
1711 removed_pipe = true;
1714 // Clear all phantom stream info
1716 pipe->stream->mall_stream_config.type = SUBVP_NONE;
1717 pipe->stream->mall_stream_config.paired_stream = NULL;
1720 return removed_pipe;
1723 /* TODO: Input to this function should indicate which pipe indexes (or streams)
1724 * require a phantom pipe / stream
1726 void dcn32_add_phantom_pipes(struct dc *dc, struct dc_state *context,
1727 display_e2e_pipe_params_st *pipes,
1728 unsigned int pipe_cnt,
1731 struct dc_stream_state *phantom_stream = NULL;
1734 // The index of the DC pipe passed into this function is guarenteed to
1735 // be a valid candidate for SubVP (i.e. has a plane, stream, doesn't
1736 // already have phantom pipe assigned, etc.) by previous checks.
1737 phantom_stream = dcn32_enable_phantom_stream(dc, context, pipes, pipe_cnt, index);
1738 dcn32_enable_phantom_plane(dc, context, phantom_stream, index);
1740 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1741 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1743 // Build scaling params for phantom pipes which were newly added.
1744 // We determine which phantom pipes were added by comparing with
1745 // the phantom stream.
1746 if (pipe->plane_state && pipe->stream && pipe->stream == phantom_stream &&
1747 pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
1748 pipe->stream->use_dynamic_meta = false;
1749 pipe->plane_state->flip_immediate = false;
1750 if (!resource_build_scaling_params(pipe)) {
1751 // Log / remove phantom pipes since failed to build scaling params
1757 bool dcn32_validate_bandwidth(struct dc *dc,
1758 struct dc_state *context,
1763 BW_VAL_TRACE_SETUP();
1767 display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
1768 DC_LOGGER_INIT(dc->ctx->logger);
1770 BW_VAL_TRACE_COUNT();
1773 out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate);
1782 BW_VAL_TRACE_END_VOLTAGE_LEVEL();
1784 if (fast_validate) {
1785 BW_VAL_TRACE_SKIP(fast);
1789 dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
1791 BW_VAL_TRACE_END_WATERMARKS();
1796 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n",
1797 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states]));
1799 BW_VAL_TRACE_SKIP(fail);
1805 BW_VAL_TRACE_FINISH();
1811 static bool is_dual_plane(enum surface_pixel_format format)
1813 return format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN || format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA;
1816 int dcn32_populate_dml_pipes_from_context(
1817 struct dc *dc, struct dc_state *context,
1818 display_e2e_pipe_params_st *pipes,
1822 struct resource_context *res_ctx = &context->res_ctx;
1823 struct pipe_ctx *pipe;
1824 bool subvp_in_use = false, is_pipe_split_expected[MAX_PIPES];
1825 int plane_count = 0;
1826 struct dc_crtc_timing *timing;
1828 dcn20_populate_dml_pipes_from_context(dc, context, pipes, fast_validate);
1830 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1832 if (!res_ctx->pipe_ctx[i].stream)
1834 pipe = &res_ctx->pipe_ctx[i];
1835 timing = &pipe->stream->timing;
1837 pipes[pipe_cnt].pipe.src.gpuvm = true;
1838 pipes[pipe_cnt].pipe.src.dcc_fraction_of_zs_req_luma = 0;
1839 pipes[pipe_cnt].pipe.src.dcc_fraction_of_zs_req_chroma = 0;
1840 pipes[pipe_cnt].pipe.dest.vfront_porch = timing->v_front_porch;
1841 pipes[pipe_cnt].pipe.src.gpuvm_min_page_size_kbytes = 256; // according to spreadsheet
1842 pipes[pipe_cnt].pipe.src.unbounded_req_mode = false;
1843 pipes[pipe_cnt].pipe.scale_ratio_depth.lb_depth = dm_lb_19;
1845 switch (pipe->stream->mall_stream_config.type) {
1847 pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_sub_viewport;
1848 subvp_in_use = true;
1851 pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_phantom_pipe;
1852 pipes[pipe_cnt].pipe.src.use_mall_for_static_screen = dm_use_mall_static_screen_disable;
1853 // Disallow unbounded req for SubVP according to DCHUB programming guide
1854 pipes[pipe_cnt].pipe.src.unbounded_req_mode = false;
1857 pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_disable;
1858 pipes[pipe_cnt].pipe.src.use_mall_for_static_screen = dm_use_mall_static_screen_disable;
1864 pipes[pipe_cnt].dout.dsc_input_bpc = 0;
1865 if (pipes[pipe_cnt].dout.dsc_enable) {
1866 switch (timing->display_color_depth) {
1867 case COLOR_DEPTH_888:
1868 pipes[pipe_cnt].dout.dsc_input_bpc = 8;
1870 case COLOR_DEPTH_101010:
1871 pipes[pipe_cnt].dout.dsc_input_bpc = 10;
1873 case COLOR_DEPTH_121212:
1874 pipes[pipe_cnt].dout.dsc_input_bpc = 12;
1882 /* Calculate the number of planes we have so we can determine
1883 * whether to apply ODM 2to1 policy or not
1885 if (pipe->stream && !pipe->prev_odm_pipe &&
1886 (!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state))
1890 is_pipe_split_expected[i] = dcn32_predict_pipe_split(context, pipes[i].pipe, i);
1896 /* Determine whether we will apply ODM 2to1 policy
1897 * Applies to single display and where the number of planes is less than 3
1898 * For 3 plane case ( 2 MPO planes ), we will not set the policy for the MPO pipes
1900 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1901 if (!res_ctx->pipe_ctx[i].stream)
1903 pipe = &res_ctx->pipe_ctx[i];
1904 timing = &pipe->stream->timing;
1906 pipes[pipe_cnt].pipe.dest.odm_combine_policy = dm_odm_combine_policy_dal;
1907 res_ctx->pipe_ctx[i].stream->odm_2to1_policy_applied = false;
1908 if (context->stream_count == 1 && timing->dsc_cfg.num_slices_h != 1) {
1909 if (dc->debug.enable_single_display_2to1_odm_policy) {
1910 if (!((plane_count > 2) && pipe->top_pipe))
1911 pipes[pipe_cnt].pipe.dest.odm_combine_policy = dm_odm_combine_policy_2to1;
1913 res_ctx->pipe_ctx[i].stream->odm_2to1_policy_applied = true;
1918 /* For DET allocation, we don't want to use DML policy (not optimal for utilizing all
1919 * the DET available for each pipe). Use the DET override input to maintain our driver
1922 if (pipe_cnt == 1 && !is_pipe_split_expected[0]) {
1923 pipes[0].pipe.src.det_size_override = DCN3_2_MAX_DET_SIZE;
1924 if (pipe->plane_state && !dc->debug.disable_z9_mpc) {
1925 if (!is_dual_plane(pipe->plane_state->format)) {
1926 pipes[0].pipe.src.det_size_override = DCN3_2_DEFAULT_DET_SIZE;
1927 pipes[0].pipe.src.unbounded_req_mode = true;
1928 if (pipe->plane_state->src_rect.width >= 5120 &&
1929 pipe->plane_state->src_rect.height >= 2880)
1930 pipes[0].pipe.src.det_size_override = 320; // 5K or higher
1934 dcn32_determine_det_override(context, pipes, is_pipe_split_expected, dc->res_pool->pipe_count);
1936 // In general cases we want to keep the dram clock change requirement
1937 // (prefer configs that support MCLK switch). Only override to false
1940 context->bw_ctx.dml.soc.dram_clock_change_requirement_final = false;
1942 context->bw_ctx.dml.soc.dram_clock_change_requirement_final = true;
1947 static struct dc_cap_funcs cap_funcs = {
1948 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1951 void dcn32_calculate_wm_and_dlg(struct dc *dc, struct dc_state *context,
1952 display_e2e_pipe_params_st *pipes,
1957 dcn32_calculate_wm_and_dlg_fpu(dc, context, pipes, pipe_cnt, vlevel);
1961 static void dcn32_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
1964 dcn32_update_bw_bounding_box_fpu(dc, bw_params);
1968 static struct resource_funcs dcn32_res_pool_funcs = {
1969 .destroy = dcn32_destroy_resource_pool,
1970 .link_enc_create = dcn32_link_encoder_create,
1971 .link_enc_create_minimal = NULL,
1972 .panel_cntl_create = dcn32_panel_cntl_create,
1973 .validate_bandwidth = dcn32_validate_bandwidth,
1974 .calculate_wm_and_dlg = dcn32_calculate_wm_and_dlg,
1975 .populate_dml_pipes = dcn32_populate_dml_pipes_from_context,
1976 .acquire_idle_pipe_for_head_pipe_in_layer = dcn32_acquire_idle_pipe_for_head_pipe_in_layer,
1977 .add_stream_to_ctx = dcn30_add_stream_to_ctx,
1978 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1979 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1980 .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
1981 .set_mcif_arb_params = dcn30_set_mcif_arb_params,
1982 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1983 .acquire_post_bldn_3dlut = dcn32_acquire_post_bldn_3dlut,
1984 .release_post_bldn_3dlut = dcn32_release_post_bldn_3dlut,
1985 .update_bw_bounding_box = dcn32_update_bw_bounding_box,
1986 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
1987 .update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
1988 .add_phantom_pipes = dcn32_add_phantom_pipes,
1989 .remove_phantom_pipes = dcn32_remove_phantom_pipes,
1993 static bool dcn32_resource_construct(
1994 uint8_t num_virtual_links,
1996 struct dcn32_resource_pool *pool)
1999 struct dc_context *ctx = dc->ctx;
2000 struct irq_service_init_data init_data;
2001 struct ddc_service_init_data ddc_init_data = {0};
2002 uint32_t pipe_fuses = 0;
2003 uint32_t num_pipes = 4;
2007 ctx->dc_bios->regs = &bios_regs;
2009 pool->base.res_cap = &res_cap_dcn32;
2010 /* max number of pipes for ASIC before checking for pipe fuses */
2011 num_pipes = pool->base.res_cap->num_timing_generator;
2012 pipe_fuses = REG_READ(CC_DC_PIPE_DIS);
2014 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++)
2015 if (pipe_fuses & 1 << i)
2019 ASSERT(0); //Unexpected - Pipe 0 should always be fully functional!
2021 if (pipe_fuses & CC_DC_PIPE_DIS__DC_FULL_DIS_MASK)
2022 ASSERT(0); //Entire DCN is harvested!
2024 /* within dml lib, initial value is hard coded, if ASIC pipe is fused, the
2025 * value will be changed, update max_num_dpp and max_num_otg for dml.
2027 dcn3_2_ip.max_num_dpp = num_pipes;
2028 dcn3_2_ip.max_num_otg = num_pipes;
2030 pool->base.funcs = &dcn32_res_pool_funcs;
2032 /*************************************************
2033 * Resource + asic cap harcoding *
2034 *************************************************/
2035 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
2036 pool->base.timing_generator_count = num_pipes;
2037 pool->base.pipe_count = num_pipes;
2038 pool->base.mpcc_count = num_pipes;
2039 dc->caps.max_downscale_ratio = 600;
2040 dc->caps.i2c_speed_in_khz = 100;
2041 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a applied by default*/
2042 dc->caps.max_cursor_size = 256;
2043 dc->caps.min_horizontal_blanking_period = 80;
2044 dc->caps.dmdata_alloc_size = 2048;
2045 dc->caps.mall_size_per_mem_channel = 0;
2046 dc->caps.mall_size_total = 0;
2047 dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
2049 dc->caps.cache_line_size = 64;
2050 dc->caps.cache_num_ways = 16;
2051 dc->caps.max_cab_allocation_bytes = 67108864; // 64MB = 1024 * 1024 * 64
2052 dc->caps.subvp_fw_processing_delay_us = 15;
2053 dc->caps.subvp_prefetch_end_to_mall_start_us = 15;
2054 dc->caps.subvp_swath_height_margin_lines = 16;
2055 dc->caps.subvp_pstate_allow_width_us = 20;
2056 dc->caps.subvp_vertical_int_margin_us = 30;
2058 dc->caps.max_slave_planes = 2;
2059 dc->caps.max_slave_yuv_planes = 2;
2060 dc->caps.max_slave_rgb_planes = 2;
2061 dc->caps.post_blend_color_processing = true;
2062 dc->caps.force_dp_tps4_for_cp2520 = true;
2063 dc->caps.dp_hpo = true;
2064 dc->caps.dp_hdmi21_pcon_support = true;
2065 dc->caps.edp_dsc_support = true;
2066 dc->caps.extended_aux_timeout_support = true;
2067 dc->caps.dmcub_support = true;
2069 /* Color pipeline capabilities */
2070 dc->caps.color.dpp.dcn_arch = 1;
2071 dc->caps.color.dpp.input_lut_shared = 0;
2072 dc->caps.color.dpp.icsc = 1;
2073 dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
2074 dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2075 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2076 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
2077 dc->caps.color.dpp.dgam_rom_caps.pq = 1;
2078 dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
2079 dc->caps.color.dpp.post_csc = 1;
2080 dc->caps.color.dpp.gamma_corr = 1;
2081 dc->caps.color.dpp.dgam_rom_for_yuv = 0;
2083 dc->caps.color.dpp.hw_3d_lut = 1;
2084 dc->caps.color.dpp.ogam_ram = 0; // no OGAM in DPP since DCN1
2085 // no OGAM ROM on DCN2 and later ASICs
2086 dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2087 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2088 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2089 dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2090 dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2091 dc->caps.color.dpp.ocsc = 0;
2093 dc->caps.color.mpc.gamut_remap = 1;
2094 dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //4, configurable to be before or after BLND in MPCC
2095 dc->caps.color.mpc.ogam_ram = 1;
2096 dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2097 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2098 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2099 dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2100 dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2101 dc->caps.color.mpc.ocsc = 1;
2103 /* Use pipe context based otg sync logic */
2104 dc->config.use_pipe_ctx_sync_logic = true;
2106 /* read VBIOS LTTPR caps */
2108 if (ctx->dc_bios->funcs->get_lttpr_caps) {
2109 enum bp_result bp_query_result;
2110 uint8_t is_vbios_lttpr_enable = 0;
2112 bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
2113 dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
2116 /* interop bit is implicit */
2118 dc->caps.vbios_lttpr_aware = true;
2122 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
2123 dc->debug = debug_defaults_drv;
2124 else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) {
2125 dc->debug = debug_defaults_diags;
2127 dc->debug = debug_defaults_diags;
2128 // Init the vm_helper
2130 vm_helper_init(dc->vm_helper, 16);
2132 /*************************************************
2133 * Create resources *
2134 *************************************************/
2136 /* Clock Sources for Pixel Clock*/
2137 pool->base.clock_sources[DCN32_CLK_SRC_PLL0] =
2138 dcn32_clock_source_create(ctx, ctx->dc_bios,
2139 CLOCK_SOURCE_COMBO_PHY_PLL0,
2140 &clk_src_regs[0], false);
2141 pool->base.clock_sources[DCN32_CLK_SRC_PLL1] =
2142 dcn32_clock_source_create(ctx, ctx->dc_bios,
2143 CLOCK_SOURCE_COMBO_PHY_PLL1,
2144 &clk_src_regs[1], false);
2145 pool->base.clock_sources[DCN32_CLK_SRC_PLL2] =
2146 dcn32_clock_source_create(ctx, ctx->dc_bios,
2147 CLOCK_SOURCE_COMBO_PHY_PLL2,
2148 &clk_src_regs[2], false);
2149 pool->base.clock_sources[DCN32_CLK_SRC_PLL3] =
2150 dcn32_clock_source_create(ctx, ctx->dc_bios,
2151 CLOCK_SOURCE_COMBO_PHY_PLL3,
2152 &clk_src_regs[3], false);
2153 pool->base.clock_sources[DCN32_CLK_SRC_PLL4] =
2154 dcn32_clock_source_create(ctx, ctx->dc_bios,
2155 CLOCK_SOURCE_COMBO_PHY_PLL4,
2156 &clk_src_regs[4], false);
2158 pool->base.clk_src_count = DCN32_CLK_SRC_TOTAL;
2160 /* todo: not reuse phy_pll registers */
2161 pool->base.dp_clock_source =
2162 dcn32_clock_source_create(ctx, ctx->dc_bios,
2163 CLOCK_SOURCE_ID_DP_DTO,
2164 &clk_src_regs[0], true);
2166 for (i = 0; i < pool->base.clk_src_count; i++) {
2167 if (pool->base.clock_sources[i] == NULL) {
2168 dm_error("DC: failed to create clock sources!\n");
2169 BREAK_TO_DEBUGGER();
2175 pool->base.dccg = dccg32_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
2176 if (pool->base.dccg == NULL) {
2177 dm_error("DC: failed to create dccg!\n");
2178 BREAK_TO_DEBUGGER();
2183 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
2184 dml_init_instance(&dc->dml, &dcn3_2_soc, &dcn3_2_ip, DML_PROJECT_DCN32);
2187 init_data.ctx = dc->ctx;
2188 pool->base.irqs = dal_irq_service_dcn32_create(&init_data);
2189 if (!pool->base.irqs)
2193 pool->base.hubbub = dcn32_hubbub_create(ctx);
2194 if (pool->base.hubbub == NULL) {
2195 BREAK_TO_DEBUGGER();
2196 dm_error("DC: failed to create hubbub!\n");
2200 /* HUBPs, DPPs, OPPs, TGs, ABMs */
2201 for (i = 0, j = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2203 /* if pipe is disabled, skip instance of HW pipe,
2204 * i.e, skip ASIC register instance
2206 if (pipe_fuses & 1 << i)
2210 pool->base.hubps[j] = dcn32_hubp_create(ctx, i);
2211 if (pool->base.hubps[j] == NULL) {
2212 BREAK_TO_DEBUGGER();
2214 "DC: failed to create hubps!\n");
2219 pool->base.dpps[j] = dcn32_dpp_create(ctx, i);
2220 if (pool->base.dpps[j] == NULL) {
2221 BREAK_TO_DEBUGGER();
2223 "DC: failed to create dpps!\n");
2228 pool->base.opps[j] = dcn32_opp_create(ctx, i);
2229 if (pool->base.opps[j] == NULL) {
2230 BREAK_TO_DEBUGGER();
2232 "DC: failed to create output pixel processor!\n");
2237 pool->base.timing_generators[j] = dcn32_timing_generator_create(
2239 if (pool->base.timing_generators[j] == NULL) {
2240 BREAK_TO_DEBUGGER();
2241 dm_error("DC: failed to create tg!\n");
2246 pool->base.multiple_abms[j] = dmub_abm_create(ctx,
2250 if (pool->base.multiple_abms[j] == NULL) {
2251 dm_error("DC: failed to create abm for pipe %d!\n", i);
2252 BREAK_TO_DEBUGGER();
2256 /* index for resource pool arrays for next valid pipe */
2261 pool->base.psr = dmub_psr_create(ctx);
2262 if (pool->base.psr == NULL) {
2263 dm_error("DC: failed to create psr obj!\n");
2264 BREAK_TO_DEBUGGER();
2269 pool->base.mpc = dcn32_mpc_create(ctx, pool->base.res_cap->num_timing_generator, pool->base.res_cap->num_mpc_3dlut);
2270 if (pool->base.mpc == NULL) {
2271 BREAK_TO_DEBUGGER();
2272 dm_error("DC: failed to create mpc!\n");
2277 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2278 pool->base.dscs[i] = dcn32_dsc_create(ctx, i);
2279 if (pool->base.dscs[i] == NULL) {
2280 BREAK_TO_DEBUGGER();
2281 dm_error("DC: failed to create display stream compressor %d!\n", i);
2287 if (!dcn32_dwbc_create(ctx, &pool->base)) {
2288 BREAK_TO_DEBUGGER();
2289 dm_error("DC: failed to create dwbc!\n");
2294 if (!dcn32_mmhubbub_create(ctx, &pool->base)) {
2295 BREAK_TO_DEBUGGER();
2296 dm_error("DC: failed to create mcif_wb!\n");
2301 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2302 pool->base.engines[i] = dcn32_aux_engine_create(ctx, i);
2303 if (pool->base.engines[i] == NULL) {
2304 BREAK_TO_DEBUGGER();
2306 "DC:failed to create aux engine!!\n");
2309 pool->base.hw_i2cs[i] = dcn32_i2c_hw_create(ctx, i);
2310 if (pool->base.hw_i2cs[i] == NULL) {
2311 BREAK_TO_DEBUGGER();
2313 "DC:failed to create hw i2c!!\n");
2316 pool->base.sw_i2cs[i] = NULL;
2319 /* Audio, HWSeq, Stream Encoders including HPO and virtual, MPC 3D LUTs */
2320 if (!resource_construct(num_virtual_links, dc, &pool->base,
2321 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
2322 &res_create_funcs : &res_create_maximus_funcs)))
2325 /* HW Sequencer init functions and Plane caps */
2326 dcn32_hw_sequencer_init_functions(dc);
2328 dc->caps.max_planes = pool->base.pipe_count;
2330 for (i = 0; i < dc->caps.max_planes; ++i)
2331 dc->caps.planes[i] = plane_cap;
2333 dc->cap_funcs = cap_funcs;
2335 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2336 ddc_init_data.ctx = dc->ctx;
2337 ddc_init_data.link = NULL;
2338 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2339 ddc_init_data.id.enum_id = 0;
2340 ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2341 pool->base.oem_device = dal_ddc_service_create(&ddc_init_data);
2343 pool->base.oem_device = NULL;
2354 dcn32_resource_destruct(pool);
2359 struct resource_pool *dcn32_create_resource_pool(
2360 const struct dc_init_data *init_data,
2363 struct dcn32_resource_pool *pool =
2364 kzalloc(sizeof(struct dcn32_resource_pool), GFP_KERNEL);
2369 if (dcn32_resource_construct(init_data->num_virtual_links, dc, pool))
2372 BREAK_TO_DEBUGGER();
2377 static struct pipe_ctx *find_idle_secondary_pipe_check_mpo(
2378 struct resource_context *res_ctx,
2379 const struct resource_pool *pool,
2380 const struct pipe_ctx *primary_pipe)
2383 struct pipe_ctx *secondary_pipe = NULL;
2384 struct pipe_ctx *next_odm_mpo_pipe = NULL;
2385 int primary_index, preferred_pipe_idx;
2386 struct pipe_ctx *old_primary_pipe = NULL;
2389 * Modified from find_idle_secondary_pipe
2390 * With windowed MPO and ODM, we want to avoid the case where we want a
2391 * free pipe for the left side but the free pipe is being used on the
2393 * Add check on current_state if the primary_pipe is the left side,
2394 * to check the right side ( primary_pipe->next_odm_pipe ) to see if
2395 * it is using a pipe for MPO ( primary_pipe->next_odm_pipe->bottom_pipe )
2396 * - If so, then don't use this pipe
2397 * EXCEPTION - 3 plane ( 2 MPO plane ) case
2398 * - in this case, the primary pipe has already gotten a free pipe for the
2399 * MPO window in the left
2400 * - when it tries to get a free pipe for the MPO window on the right,
2401 * it will see that it is already assigned to the right side
2402 * ( primary_pipe->next_odm_pipe ). But in this case, we want this
2403 * free pipe, since it will be for the right side. So add an
2404 * additional condition, that skipping the free pipe on the right only
2405 * applies if the primary pipe has no bottom pipe currently assigned
2408 primary_index = primary_pipe->pipe_idx;
2409 old_primary_pipe = &primary_pipe->stream->ctx->dc->current_state->res_ctx.pipe_ctx[primary_index];
2410 if ((old_primary_pipe->next_odm_pipe) && (old_primary_pipe->next_odm_pipe->bottom_pipe)
2411 && (!primary_pipe->bottom_pipe))
2412 next_odm_mpo_pipe = old_primary_pipe->next_odm_pipe->bottom_pipe;
2414 preferred_pipe_idx = (pool->pipe_count - 1) - primary_pipe->pipe_idx;
2415 if ((res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) &&
2416 !(next_odm_mpo_pipe && next_odm_mpo_pipe->pipe_idx == preferred_pipe_idx)) {
2417 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
2418 secondary_pipe->pipe_idx = preferred_pipe_idx;
2423 * search backwards for the second pipe to keep pipe
2424 * assignment more consistent
2426 if (!secondary_pipe)
2427 for (i = pool->pipe_count - 1; i >= 0; i--) {
2428 if ((res_ctx->pipe_ctx[i].stream == NULL) &&
2429 !(next_odm_mpo_pipe && next_odm_mpo_pipe->pipe_idx == i)) {
2430 secondary_pipe = &res_ctx->pipe_ctx[i];
2431 secondary_pipe->pipe_idx = i;
2436 return secondary_pipe;
2439 struct pipe_ctx *dcn32_acquire_idle_pipe_for_head_pipe_in_layer(
2440 struct dc_state *state,
2441 const struct resource_pool *pool,
2442 struct dc_stream_state *stream,
2443 struct pipe_ctx *head_pipe)
2445 struct resource_context *res_ctx = &state->res_ctx;
2446 struct pipe_ctx *idle_pipe, *pipe;
2447 struct resource_context *old_ctx = &stream->ctx->dc->current_state->res_ctx;
2454 * Modified from dcn20_acquire_idle_pipe_for_layer
2455 * Check if head_pipe in old_context already has bottom_pipe allocated.
2456 * - If so, check if that pipe is available in the current context.
2457 * -- If so, reuse pipe from old_context
2459 head_index = head_pipe->pipe_idx;
2460 pipe = &old_ctx->pipe_ctx[head_index];
2461 if (pipe->bottom_pipe && res_ctx->pipe_ctx[pipe->bottom_pipe->pipe_idx].stream == NULL) {
2462 idle_pipe = &res_ctx->pipe_ctx[pipe->bottom_pipe->pipe_idx];
2463 idle_pipe->pipe_idx = pipe->bottom_pipe->pipe_idx;
2465 idle_pipe = find_idle_secondary_pipe_check_mpo(res_ctx, pool, head_pipe);
2470 idle_pipe->stream = head_pipe->stream;
2471 idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
2472 idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
2474 idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
2475 idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
2476 idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
2477 idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;