@@ -624,6 +624,40 @@ static struct msm_display_topology dpu_encoder_get_topology(
624624 return topology ;
625625}
626626
627+ static void dpu_encoder_assign_crtc_resources (struct dpu_kms * dpu_kms ,
628+ struct drm_encoder * drm_enc ,
629+ struct dpu_global_state * global_state ,
630+ struct drm_crtc_state * crtc_state )
631+ {
632+ struct dpu_crtc_state * cstate ;
633+ struct dpu_hw_blk * hw_ctl [MAX_CHANNELS_PER_ENC ];
634+ struct dpu_hw_blk * hw_lm [MAX_CHANNELS_PER_ENC ];
635+ struct dpu_hw_blk * hw_dspp [MAX_CHANNELS_PER_ENC ];
636+ int num_lm , num_ctl , num_dspp , i ;
637+
638+ cstate = to_dpu_crtc_state (crtc_state );
639+
640+ memset (cstate -> mixers , 0 , sizeof (cstate -> mixers ));
641+
642+ num_ctl = dpu_rm_get_assigned_resources (& dpu_kms -> rm , global_state ,
643+ drm_enc -> base .id , DPU_HW_BLK_CTL , hw_ctl , ARRAY_SIZE (hw_ctl ));
644+ num_lm = dpu_rm_get_assigned_resources (& dpu_kms -> rm , global_state ,
645+ drm_enc -> base .id , DPU_HW_BLK_LM , hw_lm , ARRAY_SIZE (hw_lm ));
646+ num_dspp = dpu_rm_get_assigned_resources (& dpu_kms -> rm , global_state ,
647+ drm_enc -> base .id , DPU_HW_BLK_DSPP , hw_dspp ,
648+ ARRAY_SIZE (hw_dspp ));
649+
650+ for (i = 0 ; i < num_lm ; i ++ ) {
651+ int ctl_idx = (i < num_ctl ) ? i : (num_ctl - 1 );
652+
653+ cstate -> mixers [i ].hw_lm = to_dpu_hw_mixer (hw_lm [i ]);
654+ cstate -> mixers [i ].lm_ctl = to_dpu_hw_ctl (hw_ctl [ctl_idx ]);
655+ cstate -> mixers [i ].hw_dspp = i < num_dspp ? to_dpu_hw_dspp (hw_dspp [i ]) : NULL ;
656+ }
657+
658+ cstate -> num_mixers = num_lm ;
659+ }
660+
627661static int dpu_encoder_virt_atomic_check (
628662 struct drm_encoder * drm_enc ,
629663 struct drm_crtc_state * crtc_state ,
@@ -692,6 +726,9 @@ static int dpu_encoder_virt_atomic_check(
692726 if (!crtc_state -> active_changed || crtc_state -> enable )
693727 ret = dpu_rm_reserve (& dpu_kms -> rm , global_state ,
694728 drm_enc , crtc_state , topology );
729+ if (!ret )
730+ dpu_encoder_assign_crtc_resources (dpu_kms , drm_enc ,
731+ global_state , crtc_state );
695732 }
696733
697734 trace_dpu_enc_atomic_check_flags (DRMID (drm_enc ), adj_mode -> flags );
@@ -1093,14 +1130,11 @@ static void dpu_encoder_virt_atomic_mode_set(struct drm_encoder *drm_enc,
10931130 struct dpu_encoder_virt * dpu_enc ;
10941131 struct msm_drm_private * priv ;
10951132 struct dpu_kms * dpu_kms ;
1096- struct dpu_crtc_state * cstate ;
10971133 struct dpu_global_state * global_state ;
10981134 struct dpu_hw_blk * hw_pp [MAX_CHANNELS_PER_ENC ];
10991135 struct dpu_hw_blk * hw_ctl [MAX_CHANNELS_PER_ENC ];
1100- struct dpu_hw_blk * hw_lm [MAX_CHANNELS_PER_ENC ];
1101- struct dpu_hw_blk * hw_dspp [MAX_CHANNELS_PER_ENC ] = { NULL };
11021136 struct dpu_hw_blk * hw_dsc [MAX_CHANNELS_PER_ENC ];
1103- int num_lm , num_ctl , num_pp , num_dsc ;
1137+ int num_ctl , num_pp , num_dsc ;
11041138 unsigned int dsc_mask = 0 ;
11051139 int i ;
11061140
@@ -1129,11 +1163,6 @@ static void dpu_encoder_virt_atomic_mode_set(struct drm_encoder *drm_enc,
11291163 ARRAY_SIZE (hw_pp ));
11301164 num_ctl = dpu_rm_get_assigned_resources (& dpu_kms -> rm , global_state ,
11311165 drm_enc -> base .id , DPU_HW_BLK_CTL , hw_ctl , ARRAY_SIZE (hw_ctl ));
1132- num_lm = dpu_rm_get_assigned_resources (& dpu_kms -> rm , global_state ,
1133- drm_enc -> base .id , DPU_HW_BLK_LM , hw_lm , ARRAY_SIZE (hw_lm ));
1134- dpu_rm_get_assigned_resources (& dpu_kms -> rm , global_state ,
1135- drm_enc -> base .id , DPU_HW_BLK_DSPP , hw_dspp ,
1136- ARRAY_SIZE (hw_dspp ));
11371166
11381167 for (i = 0 ; i < MAX_CHANNELS_PER_ENC ; i ++ )
11391168 dpu_enc -> hw_pp [i ] = i < num_pp ? to_dpu_hw_pingpong (hw_pp [i ])
@@ -1159,36 +1188,23 @@ static void dpu_encoder_virt_atomic_mode_set(struct drm_encoder *drm_enc,
11591188 dpu_enc -> cur_master -> hw_cdm = hw_cdm ? to_dpu_hw_cdm (hw_cdm ) : NULL ;
11601189 }
11611190
1162- cstate = to_dpu_crtc_state (crtc_state );
1163-
1164- for (i = 0 ; i < num_lm ; i ++ ) {
1165- int ctl_idx = (i < num_ctl ) ? i : (num_ctl - 1 );
1166-
1167- cstate -> mixers [i ].hw_lm = to_dpu_hw_mixer (hw_lm [i ]);
1168- cstate -> mixers [i ].lm_ctl = to_dpu_hw_ctl (hw_ctl [ctl_idx ]);
1169- cstate -> mixers [i ].hw_dspp = to_dpu_hw_dspp (hw_dspp [i ]);
1170- }
1171-
1172- cstate -> num_mixers = num_lm ;
1173-
11741191 for (i = 0 ; i < dpu_enc -> num_phys_encs ; i ++ ) {
11751192 struct dpu_encoder_phys * phys = dpu_enc -> phys_encs [i ];
11761193
1177- if (!dpu_enc -> hw_pp [i ]) {
1194+ phys -> hw_pp = dpu_enc -> hw_pp [i ];
1195+ if (!phys -> hw_pp ) {
11781196 DPU_ERROR_ENC (dpu_enc ,
11791197 "no pp block assigned at idx: %d\n" , i );
11801198 return ;
11811199 }
11821200
1183- if (!hw_ctl [i ]) {
1201+ phys -> hw_ctl = i < num_ctl ? to_dpu_hw_ctl (hw_ctl [i ]) : NULL ;
1202+ if (!phys -> hw_ctl ) {
11841203 DPU_ERROR_ENC (dpu_enc ,
11851204 "no ctl block assigned at idx: %d\n" , i );
11861205 return ;
11871206 }
11881207
1189- phys -> hw_pp = dpu_enc -> hw_pp [i ];
1190- phys -> hw_ctl = to_dpu_hw_ctl (hw_ctl [i ]);
1191-
11921208 phys -> cached_mode = crtc_state -> adjusted_mode ;
11931209 if (phys -> ops .atomic_mode_set )
11941210 phys -> ops .atomic_mode_set (phys , crtc_state , conn_state );
0 commit comments