1 // SPDX-License-Identifier: MIT
2 //
3 // Copyright 2024 Advanced Micro Devices, Inc.
4
5 #include "dm_services.h"
6 #include "basics/dc_common.h"
7 #include "dm_helpers.h"
8 #include "core_types.h"
9 #include "resource.h"
10 #include "dccg.h"
11 #include "dce/dce_hwseq.h"
12 #include "reg_helper.h"
13 #include "abm.h"
14 #include "hubp.h"
15 #include "dchubbub.h"
16 #include "timing_generator.h"
17 #include "opp.h"
18 #include "ipp.h"
19 #include "mpc.h"
20 #include "mcif_wb.h"
21 #include "dc_dmub_srv.h"
22 #include "link_hwss.h"
23 #include "dpcd_defs.h"
24 #include "clk_mgr.h"
25 #include "dsc.h"
26 #include "link.h"
27
28 #include "dce/dmub_hw_lock_mgr.h"
29 #include "dcn10/dcn10_cm_common.h"
30 #include "dcn20/dcn20_optc.h"
31 #include "dcn30/dcn30_cm_common.h"
32 #include "dcn32/dcn32_hwseq.h"
33 #include "dcn401_hwseq.h"
34 #include "dcn401/dcn401_resource.h"
35 #include "dc_state_priv.h"
36 #include "link_enc_cfg.h"
37
38 #define DC_LOGGER_INIT(logger)
39
40 #define CTX \
41 hws->ctx
42 #define REG(reg)\
43 hws->regs->reg
44 #define DC_LOGGER \
45 dc->ctx->logger
46
47
48 #undef FN
49 #define FN(reg_name, field_name) \
50 hws->shifts->field_name, hws->masks->field_name
51
dcn401_initialize_min_clocks(struct dc * dc)52 static void dcn401_initialize_min_clocks(struct dc *dc)
53 {
54 struct dc_clocks *clocks = &dc->current_state->bw_ctx.bw.dcn.clk;
55
56 clocks->dcfclk_deep_sleep_khz = DCN3_2_DCFCLK_DS_INIT_KHZ;
57 clocks->dcfclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dcfclk_mhz * 1000;
58 clocks->socclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].socclk_mhz * 1000;
59 clocks->dramclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].memclk_mhz * 1000;
60 clocks->dppclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dppclk_mhz * 1000;
61 if (dc->debug.disable_boot_optimizations) {
62 clocks->dispclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dispclk_mhz * 1000;
63 } else {
64 /* Even though DPG_EN = 1 for the connected display, it still requires the
65 * correct timing so we cannot set DISPCLK to min freq or it could cause
66 * audio corruption. Read current DISPCLK from DENTIST and request the same
67 * freq to ensure that the timing is valid and unchanged.
68 */
69 clocks->dispclk_khz = dc->clk_mgr->funcs->get_dispclk_from_dentist(dc->clk_mgr);
70 }
71 clocks->ref_dtbclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dtbclk_mhz * 1000;
72 clocks->fclk_p_state_change_support = true;
73 clocks->p_state_change_support = true;
74
75 dc->clk_mgr->funcs->update_clocks(
76 dc->clk_mgr,
77 dc->current_state,
78 true);
79 }
80
dcn401_program_gamut_remap(struct pipe_ctx * pipe_ctx)81 void dcn401_program_gamut_remap(struct pipe_ctx *pipe_ctx)
82 {
83 unsigned int i = 0;
84 struct mpc_grph_gamut_adjustment mpc_adjust;
85 unsigned int mpcc_id = pipe_ctx->plane_res.mpcc_inst;
86 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
87
88 //For now assert if location is not pre-blend
89 if (pipe_ctx->plane_state)
90 ASSERT(pipe_ctx->plane_state->mcm_location == MPCC_MOVABLE_CM_LOCATION_BEFORE);
91
92 // program MPCC_MCM_FIRST_GAMUT_REMAP
93 memset(&mpc_adjust, 0, sizeof(mpc_adjust));
94 mpc_adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
95 mpc_adjust.mpcc_gamut_remap_block_id = MPCC_MCM_FIRST_GAMUT_REMAP;
96
97 if (pipe_ctx->plane_state &&
98 pipe_ctx->plane_state->gamut_remap_matrix.enable_remap == true) {
99 mpc_adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
100 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
101 mpc_adjust.temperature_matrix[i] =
102 pipe_ctx->plane_state->gamut_remap_matrix.matrix[i];
103 }
104
105 mpc->funcs->set_gamut_remap(mpc, mpcc_id, &mpc_adjust);
106
107 // program MPCC_MCM_SECOND_GAMUT_REMAP for Bypass / Disable for now
108 mpc_adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
109 mpc_adjust.mpcc_gamut_remap_block_id = MPCC_MCM_SECOND_GAMUT_REMAP;
110
111 mpc->funcs->set_gamut_remap(mpc, mpcc_id, &mpc_adjust);
112
113 // program MPCC_OGAM_GAMUT_REMAP same as is currently used on DCN3x
114 memset(&mpc_adjust, 0, sizeof(mpc_adjust));
115 mpc_adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
116 mpc_adjust.mpcc_gamut_remap_block_id = MPCC_OGAM_GAMUT_REMAP;
117
118 if (pipe_ctx->top_pipe == NULL) {
119 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
120 mpc_adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
121 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
122 mpc_adjust.temperature_matrix[i] =
123 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
124 }
125 }
126
127 mpc->funcs->set_gamut_remap(mpc, mpcc_id, &mpc_adjust);
128 }
129
dcn401_init_hw(struct dc * dc)130 void dcn401_init_hw(struct dc *dc)
131 {
132 struct abm **abms = dc->res_pool->multiple_abms;
133 struct dce_hwseq *hws = dc->hwseq;
134 struct dc_bios *dcb = dc->ctx->dc_bios;
135 struct resource_pool *res_pool = dc->res_pool;
136 int i;
137 int edp_num;
138 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
139 uint32_t user_level = MAX_BACKLIGHT_LEVEL;
140 int current_dchub_ref_freq = 0;
141
142 if (dc->clk_mgr && dc->clk_mgr->funcs && dc->clk_mgr->funcs->init_clocks) {
143 dc->clk_mgr->funcs->init_clocks(dc->clk_mgr);
144
145 // mark dcmode limits present if any clock has distinct AC and DC values from SMU
146 dc->caps.dcmode_power_limits_present =
147 (dc->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_dcfclk_levels && dc->clk_mgr->bw_params->dc_mode_limit.dcfclk_mhz) ||
148 (dc->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_dispclk_levels && dc->clk_mgr->bw_params->dc_mode_limit.dispclk_mhz) ||
149 (dc->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_dtbclk_levels && dc->clk_mgr->bw_params->dc_mode_limit.dtbclk_mhz) ||
150 (dc->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_fclk_levels && dc->clk_mgr->bw_params->dc_mode_limit.fclk_mhz) ||
151 (dc->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_memclk_levels && dc->clk_mgr->bw_params->dc_mode_limit.memclk_mhz) ||
152 (dc->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_socclk_levels && dc->clk_mgr->bw_params->dc_mode_limit.socclk_mhz);
153 }
154
155 // Initialize the dccg
156 if (res_pool->dccg->funcs->dccg_init)
157 res_pool->dccg->funcs->dccg_init(res_pool->dccg);
158
159 // Disable DMUB Initialization until IPS state programming is finalized
160 //if (!dcb->funcs->is_accelerated_mode(dcb)) {
161 // hws->funcs.bios_golden_init(dc);
162 //}
163
164 // Set default OPTC memory power states
165 if (dc->debug.enable_mem_low_power.bits.optc) {
166 // Shutdown when unassigned and light sleep in VBLANK
167 REG_SET_2(ODM_MEM_PWR_CTRL3, 0, ODM_MEM_UNASSIGNED_PWR_MODE, 3, ODM_MEM_VBLANK_PWR_MODE, 1);
168 }
169
170 if (dc->debug.enable_mem_low_power.bits.vga) {
171 // Power down VGA memory
172 REG_UPDATE(MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, 1);
173 }
174
175 if (dc->ctx->dc_bios->fw_info_valid) {
176 res_pool->ref_clocks.xtalin_clock_inKhz =
177 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency;
178
179 if (res_pool->hubbub) {
180 (res_pool->dccg->funcs->get_dccg_ref_freq)(res_pool->dccg,
181 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency,
182 &res_pool->ref_clocks.dccg_ref_clock_inKhz);
183
184 current_dchub_ref_freq = res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000;
185
186 (res_pool->hubbub->funcs->get_dchub_ref_freq)(res_pool->hubbub,
187 res_pool->ref_clocks.dccg_ref_clock_inKhz,
188 &res_pool->ref_clocks.dchub_ref_clock_inKhz);
189 } else {
190 // Not all ASICs have DCCG sw component
191 res_pool->ref_clocks.dccg_ref_clock_inKhz =
192 res_pool->ref_clocks.xtalin_clock_inKhz;
193 res_pool->ref_clocks.dchub_ref_clock_inKhz =
194 res_pool->ref_clocks.xtalin_clock_inKhz;
195 }
196 } else
197 ASSERT_CRITICAL(false);
198
199 for (i = 0; i < dc->link_count; i++) {
200 /* Power up AND update implementation according to the
201 * required signal (which may be different from the
202 * default signal on connector).
203 */
204 struct dc_link *link = dc->links[i];
205
206 link->link_enc->funcs->hw_init(link->link_enc);
207
208 /* Check for enabled DIG to identify enabled display */
209 if (link->link_enc->funcs->is_dig_enabled &&
210 link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
211 link->link_status.link_active = true;
212 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
213 if (link->link_enc->funcs->fec_is_active &&
214 link->link_enc->funcs->fec_is_active(link->link_enc))
215 link->fec_state = dc_link_fec_enabled;
216 }
217 }
218
219 /* enable_power_gating_plane before dsc_pg_control because
220 * FORCEON = 1 with hw default value on bootup, resume from s3
221 */
222 if (hws->funcs.enable_power_gating_plane)
223 hws->funcs.enable_power_gating_plane(dc->hwseq, true);
224
225 /* we want to turn off all dp displays before doing detection */
226 dc->link_srv->blank_all_dp_displays(dc);
227
228 /* If taking control over from VBIOS, we may want to optimize our first
229 * mode set, so we need to skip powering down pipes until we know which
230 * pipes we want to use.
231 * Otherwise, if taking control is not possible, we need to power
232 * everything down.
233 */
234 if (dcb->funcs->is_accelerated_mode(dcb) || !dc->config.seamless_boot_edp_requested) {
235 /* Disable boot optimizations means power down everything including PHY, DIG,
236 * and OTG (i.e. the boot is not optimized because we do a full power down).
237 */
238 if (dc->hwss.enable_accelerated_mode && dc->debug.disable_boot_optimizations)
239 dc->hwss.enable_accelerated_mode(dc, dc->current_state);
240 else
241 hws->funcs.init_pipes(dc, dc->current_state);
242
243 if (dc->res_pool->hubbub->funcs->allow_self_refresh_control)
244 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub,
245 !dc->res_pool->hubbub->ctx->dc->debug.disable_stutter);
246
247 dcn401_initialize_min_clocks(dc);
248
249 /* On HW init, allow idle optimizations after pipes have been turned off.
250 *
251 * In certain D3 cases (i.e. BOCO / BOMACO) it's possible that hardware state
252 * is reset (i.e. not in idle at the time hw init is called), but software state
253 * still has idle_optimizations = true, so we must disable idle optimizations first
254 * (i.e. set false), then re-enable (set true).
255 */
256 dc_allow_idle_optimizations(dc, false);
257 dc_allow_idle_optimizations(dc, true);
258 }
259
260 /* In headless boot cases, DIG may be turned
261 * on which causes HW/SW discrepancies.
262 * To avoid this, power down hardware on boot
263 * if DIG is turned on and seamless boot not enabled
264 */
265 if (!dc->config.seamless_boot_edp_requested) {
266 struct dc_link *edp_links[MAX_NUM_EDP];
267 struct dc_link *edp_link;
268
269 dc_get_edp_links(dc, edp_links, &edp_num);
270 if (edp_num) {
271 for (i = 0; i < edp_num; i++) {
272 edp_link = edp_links[i];
273 if (edp_link->link_enc->funcs->is_dig_enabled &&
274 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
275 dc->hwss.edp_backlight_control &&
276 hws->funcs.power_down &&
277 dc->hwss.edp_power_control) {
278 dc->hwss.edp_backlight_control(edp_link, false);
279 hws->funcs.power_down(dc);
280 dc->hwss.edp_power_control(edp_link, false);
281 }
282 }
283 } else {
284 for (i = 0; i < dc->link_count; i++) {
285 struct dc_link *link = dc->links[i];
286
287 if (link->link_enc->funcs->is_dig_enabled &&
288 link->link_enc->funcs->is_dig_enabled(link->link_enc) &&
289 hws->funcs.power_down) {
290 hws->funcs.power_down(dc);
291 break;
292 }
293
294 }
295 }
296 }
297
298 for (i = 0; i < res_pool->audio_count; i++) {
299 struct audio *audio = res_pool->audios[i];
300
301 audio->funcs->hw_init(audio);
302 }
303
304 for (i = 0; i < dc->link_count; i++) {
305 struct dc_link *link = dc->links[i];
306
307 if (link->panel_cntl) {
308 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
309 user_level = link->panel_cntl->stored_backlight_registers.USER_LEVEL;
310 }
311 }
312
313 for (i = 0; i < dc->res_pool->pipe_count; i++) {
314 if (abms[i] != NULL && abms[i]->funcs != NULL)
315 abms[i]->funcs->abm_init(abms[i], backlight, user_level);
316 }
317
318 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
319 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
320
321 if (!dc->debug.disable_clock_gate) {
322 /* enable all DCN clock gating */
323 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
324
325 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
326
327 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
328 }
329
330 dcn401_setup_hpo_hw_control(hws, true);
331
332 if (!dcb->funcs->is_accelerated_mode(dcb) && dc->res_pool->hubbub->funcs->init_watermarks)
333 dc->res_pool->hubbub->funcs->init_watermarks(dc->res_pool->hubbub);
334
335 if (dc->clk_mgr && dc->clk_mgr->funcs && dc->clk_mgr->funcs->notify_wm_ranges)
336 dc->clk_mgr->funcs->notify_wm_ranges(dc->clk_mgr);
337
338 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
339 dc->res_pool->hubbub->funcs->force_pstate_change_control(
340 dc->res_pool->hubbub, false, false);
341
342 if (dc->res_pool->hubbub->funcs->init_crb)
343 dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub);
344
345 if (dc->res_pool->hubbub->funcs->set_request_limit && dc->config.sdpif_request_limit_words_per_umc > 0)
346 dc->res_pool->hubbub->funcs->set_request_limit(dc->res_pool->hubbub, dc->ctx->dc_bios->vram_info.num_chans, dc->config.sdpif_request_limit_words_per_umc);
347
348 // Get DMCUB capabilities
349 if (dc->ctx->dmub_srv) {
350 dc_dmub_srv_query_caps_cmd(dc->ctx->dmub_srv);
351 dc->caps.dmub_caps.psr = dc->ctx->dmub_srv->dmub->feature_caps.psr;
352 dc->caps.dmub_caps.mclk_sw = dc->ctx->dmub_srv->dmub->feature_caps.fw_assisted_mclk_switch_ver > 0;
353 dc->caps.dmub_caps.fams_ver = dc->ctx->dmub_srv->dmub->feature_caps.fw_assisted_mclk_switch_ver;
354 dc->debug.fams2_config.bits.enable &=
355 dc->caps.dmub_caps.fams_ver == dc->debug.fams_version.ver; // sw & fw fams versions must match for support
356 if ((!dc->debug.fams2_config.bits.enable && dc->res_pool->funcs->update_bw_bounding_box)
357 || res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000 != current_dchub_ref_freq) {
358 /* update bounding box if FAMS2 disabled, or if dchub clk has changed */
359 if (dc->clk_mgr)
360 dc->res_pool->funcs->update_bw_bounding_box(dc,
361 dc->clk_mgr->bw_params);
362 }
363 }
364 }
365
dcn401_get_mcm_lut_xable_from_pipe_ctx(struct dc * dc,struct pipe_ctx * pipe_ctx,enum MCM_LUT_XABLE * shaper_xable,enum MCM_LUT_XABLE * lut3d_xable,enum MCM_LUT_XABLE * lut1d_xable)366 static void dcn401_get_mcm_lut_xable_from_pipe_ctx(struct dc *dc, struct pipe_ctx *pipe_ctx,
367 enum MCM_LUT_XABLE *shaper_xable,
368 enum MCM_LUT_XABLE *lut3d_xable,
369 enum MCM_LUT_XABLE *lut1d_xable)
370 {
371 enum dc_cm2_shaper_3dlut_setting shaper_3dlut_setting = DC_CM2_SHAPER_3DLUT_SETTING_BYPASS_ALL;
372 bool lut1d_enable = false;
373 struct mpc *mpc = dc->res_pool->mpc;
374 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
375
376 if (!pipe_ctx->plane_state)
377 return;
378 shaper_3dlut_setting = pipe_ctx->plane_state->mcm_shaper_3dlut_setting;
379 lut1d_enable = pipe_ctx->plane_state->mcm_lut1d_enable;
380 mpc->funcs->set_movable_cm_location(mpc, MPCC_MOVABLE_CM_LOCATION_BEFORE, mpcc_id);
381 pipe_ctx->plane_state->mcm_location = MPCC_MOVABLE_CM_LOCATION_BEFORE;
382
383 *lut1d_xable = lut1d_enable ? MCM_LUT_ENABLE : MCM_LUT_DISABLE;
384
385 switch (shaper_3dlut_setting) {
386 case DC_CM2_SHAPER_3DLUT_SETTING_BYPASS_ALL:
387 *lut3d_xable = *shaper_xable = MCM_LUT_DISABLE;
388 break;
389 case DC_CM2_SHAPER_3DLUT_SETTING_ENABLE_SHAPER:
390 *lut3d_xable = MCM_LUT_DISABLE;
391 *shaper_xable = MCM_LUT_ENABLE;
392 break;
393 case DC_CM2_SHAPER_3DLUT_SETTING_ENABLE_SHAPER_3DLUT:
394 *lut3d_xable = *shaper_xable = MCM_LUT_ENABLE;
395 break;
396 }
397 }
398
dcn401_populate_mcm_luts(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_cm2_func_luts mcm_luts,bool lut_bank_a)399 void dcn401_populate_mcm_luts(struct dc *dc,
400 struct pipe_ctx *pipe_ctx,
401 struct dc_cm2_func_luts mcm_luts,
402 bool lut_bank_a)
403 {
404 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
405 struct hubp *hubp = pipe_ctx->plane_res.hubp;
406 int mpcc_id = hubp->inst;
407 struct mpc *mpc = dc->res_pool->mpc;
408 union mcm_lut_params m_lut_params;
409 enum dc_cm2_transfer_func_source lut3d_src = mcm_luts.lut3d_data.lut3d_src;
410 enum hubp_3dlut_fl_format format;
411 enum hubp_3dlut_fl_mode mode;
412 enum hubp_3dlut_fl_width width;
413 enum hubp_3dlut_fl_addressing_mode addr_mode;
414 enum hubp_3dlut_fl_crossbar_bit_slice crossbar_bit_slice_y_g;
415 enum hubp_3dlut_fl_crossbar_bit_slice crossbar_bit_slice_cb_b;
416 enum hubp_3dlut_fl_crossbar_bit_slice crossbar_bit_slice_cr_r;
417 enum MCM_LUT_XABLE shaper_xable = MCM_LUT_DISABLE;
418 enum MCM_LUT_XABLE lut3d_xable = MCM_LUT_DISABLE;
419 enum MCM_LUT_XABLE lut1d_xable = MCM_LUT_DISABLE;
420 bool is_17x17x17 = true;
421 bool rval;
422
423 dcn401_get_mcm_lut_xable_from_pipe_ctx(dc, pipe_ctx, &shaper_xable, &lut3d_xable, &lut1d_xable);
424
425 /* 1D LUT */
426 if (mcm_luts.lut1d_func) {
427 memset(&m_lut_params, 0, sizeof(m_lut_params));
428 if (mcm_luts.lut1d_func->type == TF_TYPE_HWPWL)
429 m_lut_params.pwl = &mcm_luts.lut1d_func->pwl;
430 else if (mcm_luts.lut1d_func->type == TF_TYPE_DISTRIBUTED_POINTS) {
431 rval = cm3_helper_translate_curve_to_hw_format(
432 mcm_luts.lut1d_func,
433 &dpp_base->regamma_params, false);
434 m_lut_params.pwl = rval ? &dpp_base->regamma_params : NULL;
435 }
436 if (m_lut_params.pwl) {
437 if (mpc->funcs->populate_lut)
438 mpc->funcs->populate_lut(mpc, MCM_LUT_1DLUT, m_lut_params, lut_bank_a, mpcc_id);
439 }
440 if (mpc->funcs->program_lut_mode)
441 mpc->funcs->program_lut_mode(mpc, MCM_LUT_1DLUT, lut1d_xable && m_lut_params.pwl, lut_bank_a, mpcc_id);
442 }
443
444 /* Shaper */
445 if (mcm_luts.shaper) {
446 memset(&m_lut_params, 0, sizeof(m_lut_params));
447 if (mcm_luts.shaper->type == TF_TYPE_HWPWL)
448 m_lut_params.pwl = &mcm_luts.shaper->pwl;
449 else if (mcm_luts.shaper->type == TF_TYPE_DISTRIBUTED_POINTS) {
450 ASSERT(false);
451 rval = cm3_helper_translate_curve_to_hw_format(
452 mcm_luts.shaper,
453 &dpp_base->regamma_params, true);
454 m_lut_params.pwl = rval ? &dpp_base->regamma_params : NULL;
455 }
456 if (m_lut_params.pwl) {
457 if (mpc->funcs->populate_lut)
458 mpc->funcs->populate_lut(mpc, MCM_LUT_SHAPER, m_lut_params, lut_bank_a, mpcc_id);
459 }
460 if (mpc->funcs->program_lut_mode)
461 mpc->funcs->program_lut_mode(mpc, MCM_LUT_SHAPER, shaper_xable, lut_bank_a, mpcc_id);
462 }
463
464 /* 3DLUT */
465 switch (lut3d_src) {
466 case DC_CM2_TRANSFER_FUNC_SOURCE_SYSMEM:
467 memset(&m_lut_params, 0, sizeof(m_lut_params));
468 if (hubp->funcs->hubp_enable_3dlut_fl)
469 hubp->funcs->hubp_enable_3dlut_fl(hubp, false);
470 if (mcm_luts.lut3d_data.lut3d_func && mcm_luts.lut3d_data.lut3d_func->state.bits.initialized) {
471 m_lut_params.lut3d = &mcm_luts.lut3d_data.lut3d_func->lut_3d;
472 if (mpc->funcs->populate_lut)
473 mpc->funcs->populate_lut(mpc, MCM_LUT_3DLUT, m_lut_params, lut_bank_a, mpcc_id);
474 if (mpc->funcs->program_lut_mode)
475 mpc->funcs->program_lut_mode(mpc, MCM_LUT_3DLUT, lut3d_xable, lut_bank_a,
476 mpcc_id);
477 }
478 break;
479 case DC_CM2_TRANSFER_FUNC_SOURCE_VIDMEM:
480
481 if (mpc->funcs->program_lut_read_write_control)
482 mpc->funcs->program_lut_read_write_control(mpc, MCM_LUT_3DLUT, lut_bank_a, mpcc_id);
483 if (mpc->funcs->program_lut_mode)
484 mpc->funcs->program_lut_mode(mpc, MCM_LUT_3DLUT, lut3d_xable, lut_bank_a, mpcc_id);
485 if (mpc->funcs->program_3dlut_size)
486 mpc->funcs->program_3dlut_size(mpc, is_17x17x17, mpcc_id);
487 if (hubp->funcs->hubp_program_3dlut_fl_addr)
488 hubp->funcs->hubp_program_3dlut_fl_addr(hubp, mcm_luts.lut3d_data.gpu_mem_params.addr);
489 switch (mcm_luts.lut3d_data.gpu_mem_params.layout) {
490 case DC_CM2_GPU_MEM_LAYOUT_3D_SWIZZLE_LINEAR_RGB:
491 mode = hubp_3dlut_fl_mode_native_1;
492 addr_mode = hubp_3dlut_fl_addressing_mode_sw_linear;
493 break;
494 case DC_CM2_GPU_MEM_LAYOUT_3D_SWIZZLE_LINEAR_BGR:
495 mode = hubp_3dlut_fl_mode_native_2;
496 addr_mode = hubp_3dlut_fl_addressing_mode_sw_linear;
497 break;
498 case DC_CM2_GPU_MEM_LAYOUT_1D_PACKED_LINEAR:
499 mode = hubp_3dlut_fl_mode_transform;
500 addr_mode = hubp_3dlut_fl_addressing_mode_simple_linear;
501 break;
502 default:
503 mode = hubp_3dlut_fl_mode_disable;
504 addr_mode = hubp_3dlut_fl_addressing_mode_sw_linear;
505 break;
506 }
507 if (hubp->funcs->hubp_program_3dlut_fl_mode)
508 hubp->funcs->hubp_program_3dlut_fl_mode(hubp, mode);
509
510 if (hubp->funcs->hubp_program_3dlut_fl_addressing_mode)
511 hubp->funcs->hubp_program_3dlut_fl_addressing_mode(hubp, addr_mode);
512
513 switch (mcm_luts.lut3d_data.gpu_mem_params.format_params.format) {
514 case DC_CM2_GPU_MEM_FORMAT_16161616_UNORM_12MSB:
515 default:
516 format = hubp_3dlut_fl_format_unorm_12msb_bitslice;
517 break;
518 case DC_CM2_GPU_MEM_FORMAT_16161616_UNORM_12LSB:
519 format = hubp_3dlut_fl_format_unorm_12lsb_bitslice;
520 break;
521 case DC_CM2_GPU_MEM_FORMAT_16161616_FLOAT_FP1_5_10:
522 format = hubp_3dlut_fl_format_float_fp1_5_10;
523 break;
524 }
525 if (hubp->funcs->hubp_program_3dlut_fl_format)
526 hubp->funcs->hubp_program_3dlut_fl_format(hubp, format);
527 if (hubp->funcs->hubp_update_3dlut_fl_bias_scale)
528 hubp->funcs->hubp_update_3dlut_fl_bias_scale(hubp,
529 mcm_luts.lut3d_data.gpu_mem_params.format_params.float_params.bias,
530 mcm_luts.lut3d_data.gpu_mem_params.format_params.float_params.scale);
531
532 switch (mcm_luts.lut3d_data.gpu_mem_params.component_order) {
533 case DC_CM2_GPU_MEM_PIXEL_COMPONENT_ORDER_RGBA:
534 default:
535 crossbar_bit_slice_cr_r = hubp_3dlut_fl_crossbar_bit_slice_0_15;
536 crossbar_bit_slice_y_g = hubp_3dlut_fl_crossbar_bit_slice_16_31;
537 crossbar_bit_slice_cb_b = hubp_3dlut_fl_crossbar_bit_slice_32_47;
538 break;
539 }
540
541 if (hubp->funcs->hubp_program_3dlut_fl_crossbar)
542 hubp->funcs->hubp_program_3dlut_fl_crossbar(hubp,
543 crossbar_bit_slice_y_g,
544 crossbar_bit_slice_cb_b,
545 crossbar_bit_slice_cr_r);
546
547 switch (mcm_luts.lut3d_data.gpu_mem_params.size) {
548 case DC_CM2_GPU_MEM_SIZE_171717:
549 default:
550 width = hubp_3dlut_fl_width_17;
551 break;
552 case DC_CM2_GPU_MEM_SIZE_TRANSFORMED:
553 width = hubp_3dlut_fl_width_transformed;
554 break;
555 }
556 if (hubp->funcs->hubp_program_3dlut_fl_width)
557 hubp->funcs->hubp_program_3dlut_fl_width(hubp, width);
558 if (mpc->funcs->update_3dlut_fast_load_select)
559 mpc->funcs->update_3dlut_fast_load_select(mpc, mpcc_id, hubp->inst);
560
561 if (hubp->funcs->hubp_enable_3dlut_fl)
562 hubp->funcs->hubp_enable_3dlut_fl(hubp, true);
563 else {
564 if (mpc->funcs->program_lut_mode) {
565 mpc->funcs->program_lut_mode(mpc, MCM_LUT_SHAPER, MCM_LUT_DISABLE, lut_bank_a, mpcc_id);
566 mpc->funcs->program_lut_mode(mpc, MCM_LUT_3DLUT, MCM_LUT_DISABLE, lut_bank_a, mpcc_id);
567 mpc->funcs->program_lut_mode(mpc, MCM_LUT_1DLUT, MCM_LUT_DISABLE, lut_bank_a, mpcc_id);
568 }
569 }
570 break;
571
572 }
573 }
574
dcn401_trigger_3dlut_dma_load(struct dc * dc,struct pipe_ctx * pipe_ctx)575 void dcn401_trigger_3dlut_dma_load(struct dc *dc, struct pipe_ctx *pipe_ctx)
576 {
577 struct hubp *hubp = pipe_ctx->plane_res.hubp;
578
579 if (hubp->funcs->hubp_enable_3dlut_fl) {
580 hubp->funcs->hubp_enable_3dlut_fl(hubp, true);
581 }
582 }
583
dcn401_set_mcm_luts(struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)584 bool dcn401_set_mcm_luts(struct pipe_ctx *pipe_ctx,
585 const struct dc_plane_state *plane_state)
586 {
587 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
588 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
589 struct dc *dc = pipe_ctx->stream_res.opp->ctx->dc;
590 struct mpc *mpc = dc->res_pool->mpc;
591 bool result;
592 const struct pwl_params *lut_params = NULL;
593 bool rval;
594
595 if (plane_state->mcm_luts.lut3d_data.lut3d_src == DC_CM2_TRANSFER_FUNC_SOURCE_VIDMEM) {
596 dcn401_populate_mcm_luts(dc, pipe_ctx, plane_state->mcm_luts, plane_state->lut_bank_a);
597 return true;
598 }
599
600 mpc->funcs->set_movable_cm_location(mpc, MPCC_MOVABLE_CM_LOCATION_BEFORE, mpcc_id);
601 pipe_ctx->plane_state->mcm_location = MPCC_MOVABLE_CM_LOCATION_BEFORE;
602 // 1D LUT
603 if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
604 lut_params = &plane_state->blend_tf.pwl;
605 else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
606 rval = cm3_helper_translate_curve_to_hw_format(&plane_state->blend_tf,
607 &dpp_base->regamma_params, false);
608 lut_params = rval ? &dpp_base->regamma_params : NULL;
609 }
610 result = mpc->funcs->program_1dlut(mpc, lut_params, mpcc_id);
611 lut_params = NULL;
612
613 // Shaper
614 if (plane_state->in_shaper_func.type == TF_TYPE_HWPWL)
615 lut_params = &plane_state->in_shaper_func.pwl;
616 else if (plane_state->in_shaper_func.type == TF_TYPE_DISTRIBUTED_POINTS) {
617 // TODO: dpp_base replace
618 rval = cm3_helper_translate_curve_to_hw_format(&plane_state->in_shaper_func,
619 &dpp_base->shaper_params, true);
620 lut_params = rval ? &dpp_base->shaper_params : NULL;
621 }
622 result &= mpc->funcs->program_shaper(mpc, lut_params, mpcc_id);
623
624 // 3D
625 if (mpc->funcs->program_3dlut) {
626 if (plane_state->lut3d_func.state.bits.initialized == 1)
627 result &= mpc->funcs->program_3dlut(mpc, &plane_state->lut3d_func.lut_3d, mpcc_id);
628 else
629 result &= mpc->funcs->program_3dlut(mpc, NULL, mpcc_id);
630 }
631
632 return result;
633 }
634
dcn401_set_output_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_stream_state * stream)635 bool dcn401_set_output_transfer_func(struct dc *dc,
636 struct pipe_ctx *pipe_ctx,
637 const struct dc_stream_state *stream)
638 {
639 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
640 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
641 const struct pwl_params *params = NULL;
642 bool ret = false;
643
644 /* program OGAM or 3DLUT only for the top pipe*/
645 if (resource_is_pipe_type(pipe_ctx, OPP_HEAD)) {
646 /*program shaper and 3dlut in MPC*/
647 ret = dcn32_set_mpc_shaper_3dlut(pipe_ctx, stream);
648 if (ret == false && mpc->funcs->set_output_gamma) {
649 if (stream->out_transfer_func.type == TF_TYPE_HWPWL)
650 params = &stream->out_transfer_func.pwl;
651 else if (pipe_ctx->stream->out_transfer_func.type ==
652 TF_TYPE_DISTRIBUTED_POINTS &&
653 cm3_helper_translate_curve_to_hw_format(
654 &stream->out_transfer_func,
655 &mpc->blender_params, false))
656 params = &mpc->blender_params;
657 /* there are no ROM LUTs in OUTGAM */
658 if (stream->out_transfer_func.type == TF_TYPE_PREDEFINED)
659 BREAK_TO_DEBUGGER();
660 }
661 }
662
663 if (mpc->funcs->set_output_gamma)
664 mpc->funcs->set_output_gamma(mpc, mpcc_id, params);
665
666 return ret;
667 }
668
dcn401_calculate_dccg_tmds_div_value(struct pipe_ctx * pipe_ctx,unsigned int * tmds_div)669 void dcn401_calculate_dccg_tmds_div_value(struct pipe_ctx *pipe_ctx,
670 unsigned int *tmds_div)
671 {
672 struct dc_stream_state *stream = pipe_ctx->stream;
673
674 if (dc_is_tmds_signal(stream->signal) || dc_is_virtual_signal(stream->signal)) {
675 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
676 *tmds_div = PIXEL_RATE_DIV_BY_2;
677 else
678 *tmds_div = PIXEL_RATE_DIV_BY_4;
679 } else {
680 *tmds_div = PIXEL_RATE_DIV_BY_1;
681 }
682
683 if (*tmds_div == PIXEL_RATE_DIV_NA)
684 ASSERT(false);
685
686 }
687
enable_stream_timing_calc(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc,unsigned int * tmds_div,int * opp_inst,int * opp_cnt,struct pipe_ctx * opp_heads[MAX_PIPES],bool * manual_mode,struct drr_params * params,unsigned int * event_triggers)688 static void enable_stream_timing_calc(
689 struct pipe_ctx *pipe_ctx,
690 struct dc_state *context,
691 struct dc *dc,
692 unsigned int *tmds_div,
693 int *opp_inst,
694 int *opp_cnt,
695 struct pipe_ctx *opp_heads[MAX_PIPES],
696 bool *manual_mode,
697 struct drr_params *params,
698 unsigned int *event_triggers)
699 {
700 struct dc_stream_state *stream = pipe_ctx->stream;
701 int i;
702
703 if (dc_is_tmds_signal(stream->signal) || dc_is_virtual_signal(stream->signal))
704 dcn401_calculate_dccg_tmds_div_value(pipe_ctx, tmds_div);
705
706 *opp_cnt = resource_get_opp_heads_for_otg_master(pipe_ctx, &context->res_ctx, opp_heads);
707 for (i = 0; i < *opp_cnt; i++)
708 opp_inst[i] = opp_heads[i]->stream_res.opp->inst;
709
710 if (dc_is_tmds_signal(stream->signal)) {
711 stream->link->phy_state.symclk_ref_cnts.otg = 1;
712 if (stream->link->phy_state.symclk_state == SYMCLK_OFF_TX_OFF)
713 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
714 else
715 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
716 }
717
718 params->vertical_total_min = stream->adjust.v_total_min;
719 params->vertical_total_max = stream->adjust.v_total_max;
720 params->vertical_total_mid = stream->adjust.v_total_mid;
721 params->vertical_total_mid_frame_num = stream->adjust.v_total_mid_frame_num;
722
723 // DRR should set trigger event to monitor surface update event
724 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
725 *event_triggers = 0x80;
726 }
727
dcn401_enable_stream_timing(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc)728 enum dc_status dcn401_enable_stream_timing(
729 struct pipe_ctx *pipe_ctx,
730 struct dc_state *context,
731 struct dc *dc)
732 {
733 struct dce_hwseq *hws = dc->hwseq;
734 struct dc_stream_state *stream = pipe_ctx->stream;
735 struct drr_params params = {0};
736 unsigned int event_triggers = 0;
737 int opp_cnt = 1;
738 int opp_inst[MAX_PIPES] = {0};
739 struct pipe_ctx *opp_heads[MAX_PIPES] = {0};
740 struct dc_crtc_timing patched_crtc_timing = stream->timing;
741 bool manual_mode = false;
742 unsigned int tmds_div = PIXEL_RATE_DIV_NA;
743 unsigned int unused_div = PIXEL_RATE_DIV_NA;
744 int odm_slice_width;
745 int last_odm_slice_width;
746 int i;
747
748 if (!resource_is_pipe_type(pipe_ctx, OTG_MASTER))
749 return DC_OK;
750
751 enable_stream_timing_calc(pipe_ctx, context, dc, &tmds_div, opp_inst,
752 &opp_cnt, opp_heads, &manual_mode, ¶ms, &event_triggers);
753
754 if (dc->res_pool->dccg->funcs->set_pixel_rate_div) {
755 dc->res_pool->dccg->funcs->set_pixel_rate_div(
756 dc->res_pool->dccg, pipe_ctx->stream_res.tg->inst,
757 tmds_div, unused_div);
758 }
759
760 /* TODO check if timing_changed, disable stream if timing changed */
761
762 if (opp_cnt > 1) {
763 odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, false);
764 last_odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, true);
765 pipe_ctx->stream_res.tg->funcs->set_odm_combine(
766 pipe_ctx->stream_res.tg,
767 opp_inst, opp_cnt,
768 odm_slice_width, last_odm_slice_width);
769 }
770
771 /* set DTBCLK_P */
772 if (dc->res_pool->dccg->funcs->set_dtbclk_p_src) {
773 if (dc_is_dp_signal(stream->signal) || dc_is_virtual_signal(stream->signal)) {
774 dc->res_pool->dccg->funcs->set_dtbclk_p_src(dc->res_pool->dccg, DPREFCLK, pipe_ctx->stream_res.tg->inst);
775 }
776 }
777
778 /* HW program guide assume display already disable
779 * by unplug sequence. OTG assume stop.
780 */
781 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, true);
782
783 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
784 pipe_ctx->clock_source,
785 &pipe_ctx->stream_res.pix_clk_params,
786 dc->link_srv->dp_get_encoding_format(&pipe_ctx->link_config.dp_link_settings),
787 &pipe_ctx->pll_settings)) {
788 BREAK_TO_DEBUGGER();
789 return DC_ERROR_UNEXPECTED;
790 }
791
792 if (dc->hwseq->funcs.PLAT_58856_wa && (!dc_is_dp_signal(stream->signal)))
793 dc->hwseq->funcs.PLAT_58856_wa(context, pipe_ctx);
794
795 /* if we are borrowing from hblank, h_addressable needs to be adjusted */
796 if (dc->debug.enable_hblank_borrow)
797 patched_crtc_timing.h_addressable = patched_crtc_timing.h_addressable + pipe_ctx->hblank_borrow;
798
799 pipe_ctx->stream_res.tg->funcs->program_timing(
800 pipe_ctx->stream_res.tg,
801 &patched_crtc_timing,
802 (unsigned int)pipe_ctx->global_sync.dcn4x.vready_offset_pixels,
803 (unsigned int)pipe_ctx->global_sync.dcn4x.vstartup_lines,
804 (unsigned int)pipe_ctx->global_sync.dcn4x.vupdate_offset_pixels,
805 (unsigned int)pipe_ctx->global_sync.dcn4x.vupdate_vupdate_width_pixels,
806 (unsigned int)pipe_ctx->global_sync.dcn4x.pstate_keepout_start_lines,
807 pipe_ctx->stream->signal,
808 true);
809
810 for (i = 0; i < opp_cnt; i++) {
811 opp_heads[i]->stream_res.opp->funcs->opp_pipe_clock_control(
812 opp_heads[i]->stream_res.opp,
813 true);
814 opp_heads[i]->stream_res.opp->funcs->opp_program_left_edge_extra_pixel(
815 opp_heads[i]->stream_res.opp,
816 stream->timing.pixel_encoding,
817 resource_is_pipe_type(opp_heads[i], OTG_MASTER));
818 }
819
820 pipe_ctx->stream_res.opp->funcs->opp_pipe_clock_control(
821 pipe_ctx->stream_res.opp,
822 true);
823
824 hws->funcs.blank_pixel_data(dc, pipe_ctx, true);
825
826 /* VTG is within DCHUB command block. DCFCLK is always on */
827 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
828 BREAK_TO_DEBUGGER();
829 return DC_ERROR_UNEXPECTED;
830 }
831
832 hws->funcs.wait_for_blank_complete(pipe_ctx->stream_res.opp);
833
834 if (pipe_ctx->stream_res.tg->funcs->set_drr)
835 pipe_ctx->stream_res.tg->funcs->set_drr(
836 pipe_ctx->stream_res.tg, ¶ms);
837
838 /* Event triggers and num frames initialized for DRR, but can be
839 * later updated for PSR use. Note DRR trigger events are generated
840 * regardless of whether num frames met.
841 */
842 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
843 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
844 pipe_ctx->stream_res.tg, event_triggers, 2);
845
846 /* TODO program crtc source select for non-virtual signal*/
847 /* TODO program FMT */
848 /* TODO setup link_enc */
849 /* TODO set stream attributes */
850 /* TODO program audio */
851 /* TODO enable stream if timing changed */
852 /* TODO unblank stream if DP */
853
854 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) == SUBVP_PHANTOM) {
855 if (pipe_ctx->stream_res.tg->funcs->phantom_crtc_post_enable)
856 pipe_ctx->stream_res.tg->funcs->phantom_crtc_post_enable(pipe_ctx->stream_res.tg);
857 }
858
859 return DC_OK;
860 }
861
get_phyd32clk_src(struct dc_link * link)862 static enum phyd32clk_clock_source get_phyd32clk_src(struct dc_link *link)
863 {
864 switch (link->link_enc->transmitter) {
865 case TRANSMITTER_UNIPHY_A:
866 return PHYD32CLKA;
867 case TRANSMITTER_UNIPHY_B:
868 return PHYD32CLKB;
869 case TRANSMITTER_UNIPHY_C:
870 return PHYD32CLKC;
871 case TRANSMITTER_UNIPHY_D:
872 return PHYD32CLKD;
873 case TRANSMITTER_UNIPHY_E:
874 return PHYD32CLKE;
875 default:
876 return PHYD32CLKA;
877 }
878 }
879
dcn401_enable_stream_calc(struct pipe_ctx * pipe_ctx,int * dp_hpo_inst,enum phyd32clk_clock_source * phyd32clk,unsigned int * tmds_div,uint32_t * early_control)880 static void dcn401_enable_stream_calc(
881 struct pipe_ctx *pipe_ctx,
882 int *dp_hpo_inst,
883 enum phyd32clk_clock_source *phyd32clk,
884 unsigned int *tmds_div,
885 uint32_t *early_control)
886 {
887
888 struct dc *dc = pipe_ctx->stream->ctx->dc;
889 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
890 enum dc_lane_count lane_count =
891 pipe_ctx->stream->link->cur_link_settings.lane_count;
892 uint32_t active_total_with_borders;
893
894 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx))
895 *dp_hpo_inst = pipe_ctx->stream_res.hpo_dp_stream_enc->inst;
896
897 *phyd32clk = get_phyd32clk_src(pipe_ctx->stream->link);
898
899 if (dc_is_tmds_signal(pipe_ctx->stream->signal))
900 dcn401_calculate_dccg_tmds_div_value(pipe_ctx, tmds_div);
901 else
902 *tmds_div = PIXEL_RATE_DIV_BY_1;
903
904 /* enable early control to avoid corruption on DP monitor*/
905 active_total_with_borders =
906 timing->h_addressable
907 + timing->h_border_left
908 + timing->h_border_right;
909
910 if (lane_count != 0)
911 *early_control = active_total_with_borders % lane_count;
912
913 if (*early_control == 0)
914 *early_control = lane_count;
915
916 }
917
dcn401_enable_stream(struct pipe_ctx * pipe_ctx)918 void dcn401_enable_stream(struct pipe_ctx *pipe_ctx)
919 {
920 uint32_t early_control = 0;
921 struct timing_generator *tg = pipe_ctx->stream_res.tg;
922 struct dc_link *link = pipe_ctx->stream->link;
923 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
924 struct dc *dc = pipe_ctx->stream->ctx->dc;
925 struct dccg *dccg = dc->res_pool->dccg;
926 enum phyd32clk_clock_source phyd32clk;
927 int dp_hpo_inst = 0;
928 unsigned int tmds_div = PIXEL_RATE_DIV_NA;
929 unsigned int unused_div = PIXEL_RATE_DIV_NA;
930 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
931 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
932
933 dcn401_enable_stream_calc(pipe_ctx, &dp_hpo_inst, &phyd32clk,
934 &tmds_div, &early_control);
935
936 if (dc_is_dp_signal(pipe_ctx->stream->signal) || dc_is_virtual_signal(pipe_ctx->stream->signal)) {
937 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
938 dccg->funcs->set_dpstreamclk(dccg, DPREFCLK, tg->inst, dp_hpo_inst);
939
940 dccg->funcs->enable_symclk32_se(dccg, dp_hpo_inst, phyd32clk);
941 } else {
942 dccg->funcs->enable_symclk_se(dccg, stream_enc->stream_enc_inst,
943 link_enc->transmitter - TRANSMITTER_UNIPHY_A);
944 }
945 }
946
947 if (dc->res_pool->dccg->funcs->set_pixel_rate_div) {
948 dc->res_pool->dccg->funcs->set_pixel_rate_div(
949 dc->res_pool->dccg,
950 pipe_ctx->stream_res.tg->inst,
951 tmds_div,
952 unused_div);
953 }
954
955 link_hwss->setup_stream_encoder(pipe_ctx);
956
957 if (pipe_ctx->plane_state && pipe_ctx->plane_state->flip_immediate != 1) {
958 if (dc->hwss.program_dmdata_engine)
959 dc->hwss.program_dmdata_engine(pipe_ctx);
960 }
961
962 dc->hwss.update_info_frame(pipe_ctx);
963
964 if (dc_is_dp_signal(pipe_ctx->stream->signal))
965 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
966
967 tg->funcs->set_early_control(tg, early_control);
968 }
969
dcn401_setup_hpo_hw_control(const struct dce_hwseq * hws,bool enable)970 void dcn401_setup_hpo_hw_control(const struct dce_hwseq *hws, bool enable)
971 {
972 REG_UPDATE(HPO_TOP_HW_CONTROL, HPO_IO_EN, enable);
973 }
974
dcn401_can_pipe_disable_cursor(struct pipe_ctx * pipe_ctx)975 static bool dcn401_can_pipe_disable_cursor(struct pipe_ctx *pipe_ctx)
976 {
977 struct pipe_ctx *test_pipe, *split_pipe;
978 const struct scaler_data *scl_data = &pipe_ctx->plane_res.scl_data;
979 struct rect r1 = scl_data->recout, r2, r2_half;
980 int r1_r = r1.x + r1.width, r1_b = r1.y + r1.height, r2_r, r2_b;
981 int cur_layer = pipe_ctx->plane_state->layer_index;
982
983 /**
984 * Disable the cursor if there's another pipe above this with a
985 * plane that contains this pipe's viewport to prevent double cursor
986 * and incorrect scaling artifacts.
987 */
988 for (test_pipe = pipe_ctx->top_pipe; test_pipe;
989 test_pipe = test_pipe->top_pipe) {
990 // Skip invisible layer and pipe-split plane on same layer
991 if (!test_pipe->plane_state ||
992 !test_pipe->plane_state->visible ||
993 test_pipe->plane_state->layer_index == cur_layer)
994 continue;
995
996 r2 = test_pipe->plane_res.scl_data.recout;
997 r2_r = r2.x + r2.width;
998 r2_b = r2.y + r2.height;
999
1000 /**
1001 * There is another half plane on same layer because of
1002 * pipe-split, merge together per same height.
1003 */
1004 for (split_pipe = pipe_ctx->top_pipe; split_pipe;
1005 split_pipe = split_pipe->top_pipe)
1006 if (split_pipe->plane_state->layer_index == test_pipe->plane_state->layer_index) {
1007 r2_half = split_pipe->plane_res.scl_data.recout;
1008 r2.x = (r2_half.x < r2.x) ? r2_half.x : r2.x;
1009 r2.width = r2.width + r2_half.width;
1010 r2_r = r2.x + r2.width;
1011 break;
1012 }
1013
1014 if (r1.x >= r2.x && r1.y >= r2.y && r1_r <= r2_r && r1_b <= r2_b)
1015 return true;
1016 }
1017
1018 return false;
1019 }
1020
adjust_hotspot_between_slices_for_2x_magnify(uint32_t cursor_width,struct dc_cursor_position * pos_cpy)1021 void adjust_hotspot_between_slices_for_2x_magnify(uint32_t cursor_width, struct dc_cursor_position *pos_cpy)
1022 {
1023 if (cursor_width <= 128) {
1024 pos_cpy->x_hotspot /= 2;
1025 pos_cpy->x_hotspot += 1;
1026 } else {
1027 pos_cpy->x_hotspot /= 2;
1028 pos_cpy->x_hotspot += 2;
1029 }
1030 }
1031
disable_link_output_symclk_on_tx_off(struct dc_link * link,enum dp_link_encoding link_encoding)1032 static void disable_link_output_symclk_on_tx_off(struct dc_link *link, enum dp_link_encoding link_encoding)
1033 {
1034 struct dc *dc = link->ctx->dc;
1035 struct pipe_ctx *pipe_ctx = NULL;
1036 uint8_t i;
1037
1038 for (i = 0; i < MAX_PIPES; i++) {
1039 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
1040 if (pipe_ctx->stream && pipe_ctx->stream->link == link && pipe_ctx->top_pipe == NULL) {
1041 pipe_ctx->clock_source->funcs->program_pix_clk(
1042 pipe_ctx->clock_source,
1043 &pipe_ctx->stream_res.pix_clk_params,
1044 link_encoding,
1045 &pipe_ctx->pll_settings);
1046 break;
1047 }
1048 }
1049 }
1050
dcn401_disable_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)1051 void dcn401_disable_link_output(struct dc_link *link,
1052 const struct link_resource *link_res,
1053 enum signal_type signal)
1054 {
1055 struct dc *dc = link->ctx->dc;
1056 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
1057 struct dmcu *dmcu = dc->res_pool->dmcu;
1058
1059 if (signal == SIGNAL_TYPE_EDP &&
1060 link->dc->hwss.edp_backlight_control &&
1061 !link->skip_implict_edp_power_control)
1062 link->dc->hwss.edp_backlight_control(link, false);
1063 else if (dmcu != NULL && dmcu->funcs->lock_phy)
1064 dmcu->funcs->lock_phy(dmcu);
1065
1066 if (dc_is_tmds_signal(signal) && link->phy_state.symclk_ref_cnts.otg > 0) {
1067 disable_link_output_symclk_on_tx_off(link, DP_UNKNOWN_ENCODING);
1068 link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
1069 } else {
1070 link_hwss->disable_link_output(link, link_res, signal);
1071 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
1072 }
1073
1074 if (signal == SIGNAL_TYPE_EDP &&
1075 link->dc->hwss.edp_backlight_control &&
1076 !link->skip_implict_edp_power_control)
1077 link->dc->hwss.edp_power_control(link, false);
1078 else if (dmcu != NULL && dmcu->funcs->lock_phy)
1079 dmcu->funcs->unlock_phy(dmcu);
1080
1081 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
1082 }
1083
dcn401_set_cursor_position(struct pipe_ctx * pipe_ctx)1084 void dcn401_set_cursor_position(struct pipe_ctx *pipe_ctx)
1085 {
1086 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
1087 struct hubp *hubp = pipe_ctx->plane_res.hubp;
1088 struct dpp *dpp = pipe_ctx->plane_res.dpp;
1089 struct dc_cursor_mi_param param = {
1090 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
1091 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.dchub_ref_clock_inKhz,
1092 .viewport = pipe_ctx->plane_res.scl_data.viewport,
1093 .recout = pipe_ctx->plane_res.scl_data.recout,
1094 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
1095 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
1096 .rotation = pipe_ctx->plane_state->rotation,
1097 .mirror = pipe_ctx->plane_state->horizontal_mirror,
1098 .stream = pipe_ctx->stream
1099 };
1100 struct rect odm_slice_src = { 0 };
1101 bool odm_combine_on = (pipe_ctx->next_odm_pipe != NULL) ||
1102 (pipe_ctx->prev_odm_pipe != NULL);
1103 int prev_odm_width = 0;
1104 struct pipe_ctx *prev_odm_pipe = NULL;
1105 bool mpc_combine_on = false;
1106 int bottom_pipe_x_pos = 0;
1107
1108 int x_pos = pos_cpy.x;
1109 int y_pos = pos_cpy.y;
1110 int recout_x_pos = 0;
1111 int recout_y_pos = 0;
1112
1113 if ((pipe_ctx->top_pipe != NULL) || (pipe_ctx->bottom_pipe != NULL)) {
1114 if ((pipe_ctx->plane_state->src_rect.width != pipe_ctx->plane_res.scl_data.viewport.width) ||
1115 (pipe_ctx->plane_state->src_rect.height != pipe_ctx->plane_res.scl_data.viewport.height)) {
1116 mpc_combine_on = true;
1117 }
1118 }
1119
1120 /* DCN4 moved cursor composition after Scaler, so in HW it is in
1121 * recout space and for HW Cursor position programming need to
1122 * translate to recout space.
1123 *
1124 * Cursor X and Y position programmed into HW can't be negative,
1125 * in fact it is X, Y coordinate shifted for the HW Cursor Hot spot
1126 * position that goes into HW X and Y coordinates while HW Hot spot
1127 * X and Y coordinates are length relative to the cursor top left
1128 * corner, hotspot must be smaller than the cursor size.
1129 *
1130 * DMs/DC interface for Cursor position is in stream->src space, and
1131 * DMs supposed to transform Cursor coordinates to stream->src space,
1132 * then here we need to translate Cursor coordinates to stream->dst
1133 * space, as now in HW, Cursor coordinates are in per pipe recout
1134 * space, and for the given pipe valid coordinates are only in range
1135 * from 0,0 - recout width, recout height space.
1136 * If certain pipe combining is in place, need to further adjust per
1137 * pipe to make sure each pipe enabling cursor on its part of the
1138 * screen.
1139 */
1140 x_pos = pipe_ctx->stream->dst.x + x_pos * pipe_ctx->stream->dst.width /
1141 pipe_ctx->stream->src.width;
1142 y_pos = pipe_ctx->stream->dst.y + y_pos * pipe_ctx->stream->dst.height /
1143 pipe_ctx->stream->src.height;
1144
1145 /* If the cursor's source viewport is clipped then we need to
1146 * translate the cursor to appear in the correct position on
1147 * the screen.
1148 *
1149 * This translation isn't affected by scaling so it needs to be
1150 * done *after* we adjust the position for the scale factor.
1151 *
1152 * This is only done by opt-in for now since there are still
1153 * some usecases like tiled display that might enable the
1154 * cursor on both streams while expecting dc to clip it.
1155 */
1156 if (pos_cpy.translate_by_source) {
1157 x_pos += pipe_ctx->plane_state->src_rect.x;
1158 y_pos += pipe_ctx->plane_state->src_rect.y;
1159 }
1160
1161 /* Adjust for ODM Combine
1162 * next/prev_odm_offset is to account for scaled modes that have underscan
1163 */
1164 if (odm_combine_on) {
1165 prev_odm_pipe = pipe_ctx->prev_odm_pipe;
1166
1167 while (prev_odm_pipe != NULL) {
1168 odm_slice_src = resource_get_odm_slice_src_rect(prev_odm_pipe);
1169 prev_odm_width += odm_slice_src.width;
1170 prev_odm_pipe = prev_odm_pipe->prev_odm_pipe;
1171 }
1172
1173 x_pos -= (prev_odm_width);
1174 }
1175
1176 /* If the position is negative then we need to add to the hotspot
1177 * to fix cursor size between ODM slices
1178 */
1179
1180 if (x_pos < 0) {
1181 pos_cpy.x_hotspot -= x_pos;
1182 if (hubp->curs_attr.attribute_flags.bits.ENABLE_MAGNIFICATION)
1183 adjust_hotspot_between_slices_for_2x_magnify(hubp->curs_attr.width, &pos_cpy);
1184 x_pos = 0;
1185 }
1186
1187 if (y_pos < 0) {
1188 pos_cpy.y_hotspot -= y_pos;
1189 y_pos = 0;
1190 }
1191
1192 /* If the position on bottom MPC pipe is negative then we need to add to the hotspot and
1193 * adjust x_pos on bottom pipe to make cursor visible when crossing between MPC slices.
1194 */
1195 if (mpc_combine_on &&
1196 pipe_ctx->top_pipe &&
1197 (pipe_ctx == pipe_ctx->top_pipe->bottom_pipe)) {
1198
1199 bottom_pipe_x_pos = x_pos - pipe_ctx->plane_res.scl_data.recout.x;
1200 if (bottom_pipe_x_pos < 0) {
1201 x_pos = pipe_ctx->plane_res.scl_data.recout.x;
1202 pos_cpy.x_hotspot -= bottom_pipe_x_pos;
1203 if (hubp->curs_attr.attribute_flags.bits.ENABLE_MAGNIFICATION)
1204 adjust_hotspot_between_slices_for_2x_magnify(hubp->curs_attr.width, &pos_cpy);
1205 }
1206 }
1207
1208 pos_cpy.x = (uint32_t)x_pos;
1209 pos_cpy.y = (uint32_t)y_pos;
1210
1211 if (pos_cpy.enable && dcn401_can_pipe_disable_cursor(pipe_ctx))
1212 pos_cpy.enable = false;
1213
1214 x_pos = pos_cpy.x - param.recout.x;
1215 y_pos = pos_cpy.y - param.recout.y;
1216
1217 recout_x_pos = x_pos - pos_cpy.x_hotspot;
1218 recout_y_pos = y_pos - pos_cpy.y_hotspot;
1219
1220 if (recout_x_pos >= (int)param.recout.width)
1221 pos_cpy.enable = false; /* not visible beyond right edge*/
1222
1223 if (recout_y_pos >= (int)param.recout.height)
1224 pos_cpy.enable = false; /* not visible beyond bottom edge*/
1225
1226 if (recout_x_pos + (int)hubp->curs_attr.width <= 0)
1227 pos_cpy.enable = false; /* not visible beyond left edge*/
1228
1229 if (recout_y_pos + (int)hubp->curs_attr.height <= 0)
1230 pos_cpy.enable = false; /* not visible beyond top edge*/
1231
1232 hubp->funcs->set_cursor_position(hubp, &pos_cpy, ¶m);
1233 dpp->funcs->set_cursor_position(dpp, &pos_cpy, ¶m, hubp->curs_attr.width, hubp->curs_attr.height);
1234 }
1235
dcn401_check_no_memory_request_for_cab(struct dc * dc)1236 static bool dcn401_check_no_memory_request_for_cab(struct dc *dc)
1237 {
1238 int i;
1239
1240 /* First, check no-memory-request case */
1241 for (i = 0; i < dc->current_state->stream_count; i++) {
1242 if ((dc->current_state->stream_status[i].plane_count) &&
1243 (dc->current_state->streams[i]->link->psr_settings.psr_version == DC_PSR_VERSION_UNSUPPORTED))
1244 /* Fail eligibility on a visible stream */
1245 return false;
1246 }
1247
1248 return true;
1249 }
1250
dcn401_calculate_cab_allocation(struct dc * dc,struct dc_state * ctx)1251 static uint32_t dcn401_calculate_cab_allocation(struct dc *dc, struct dc_state *ctx)
1252 {
1253 int i;
1254 uint8_t num_ways = 0;
1255 uint32_t mall_ss_size_bytes = 0;
1256
1257 mall_ss_size_bytes = ctx->bw_ctx.bw.dcn.mall_ss_size_bytes;
1258 // TODO add additional logic for PSR active stream exclusion optimization
1259 // mall_ss_psr_active_size_bytes = ctx->bw_ctx.bw.dcn.mall_ss_psr_active_size_bytes;
1260
1261 // Include cursor size for CAB allocation
1262 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1263 struct pipe_ctx *pipe = &ctx->res_ctx.pipe_ctx[i];
1264
1265 if (!pipe->stream || !pipe->plane_state)
1266 continue;
1267
1268 mall_ss_size_bytes += dcn32_helper_calculate_mall_bytes_for_cursor(dc, pipe, false);
1269 }
1270
1271 // Convert number of cache lines required to number of ways
1272 if (dc->debug.force_mall_ss_num_ways > 0)
1273 num_ways = dc->debug.force_mall_ss_num_ways;
1274 else if (dc->res_pool->funcs->calculate_mall_ways_from_bytes)
1275 num_ways = dc->res_pool->funcs->calculate_mall_ways_from_bytes(dc, mall_ss_size_bytes);
1276 else
1277 num_ways = 0;
1278
1279 return num_ways;
1280 }
1281
dcn401_apply_idle_power_optimizations(struct dc * dc,bool enable)1282 bool dcn401_apply_idle_power_optimizations(struct dc *dc, bool enable)
1283 {
1284 union dmub_rb_cmd cmd;
1285 uint8_t ways, i;
1286 int j;
1287 bool mall_ss_unsupported = false;
1288 struct dc_plane_state *plane = NULL;
1289
1290 if (!dc->ctx->dmub_srv || !dc->current_state)
1291 return false;
1292
1293 for (i = 0; i < dc->current_state->stream_count; i++) {
1294 /* MALL SS messaging is not supported with PSR at this time */
1295 if (dc->current_state->streams[i] != NULL &&
1296 dc->current_state->streams[i]->link->psr_settings.psr_version != DC_PSR_VERSION_UNSUPPORTED) {
1297 DC_LOG_MALL("MALL SS not supported with PSR at this time\n");
1298 return false;
1299 }
1300 }
1301
1302 memset(&cmd, 0, sizeof(cmd));
1303 cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
1304 cmd.cab.header.payload_bytes = sizeof(cmd.cab) - sizeof(cmd.cab.header);
1305
1306 if (enable) {
1307 if (dcn401_check_no_memory_request_for_cab(dc)) {
1308 /* 1. Check no memory request case for CAB.
1309 * If no memory request case, send CAB_ACTION NO_DCN_REQ DMUB message
1310 */
1311 DC_LOG_MALL("sending CAB action NO_DCN_REQ\n");
1312 cmd.cab.header.sub_type = DMUB_CMD__CAB_NO_DCN_REQ;
1313 } else {
1314 /* 2. Check if all surfaces can fit in CAB.
1315 * If surfaces can fit into CAB, send CAB_ACTION_ALLOW DMUB message
1316 * and configure HUBP's to fetch from MALL
1317 */
1318 ways = dcn401_calculate_cab_allocation(dc, dc->current_state);
1319
1320 /* MALL not supported with Stereo3D or TMZ surface. If any plane is using stereo,
1321 * or TMZ surface, don't try to enter MALL.
1322 */
1323 for (i = 0; i < dc->current_state->stream_count; i++) {
1324 for (j = 0; j < dc->current_state->stream_status[i].plane_count; j++) {
1325 plane = dc->current_state->stream_status[i].plane_states[j];
1326
1327 if (plane->address.type == PLN_ADDR_TYPE_GRPH_STEREO ||
1328 plane->address.tmz_surface) {
1329 mall_ss_unsupported = true;
1330 break;
1331 }
1332 }
1333 if (mall_ss_unsupported)
1334 break;
1335 }
1336 if (ways <= dc->caps.cache_num_ways && !mall_ss_unsupported) {
1337 cmd.cab.header.sub_type = DMUB_CMD__CAB_DCN_SS_FIT_IN_CAB;
1338 cmd.cab.cab_alloc_ways = ways;
1339 DC_LOG_MALL("cab allocation: %d ways. CAB action: DCN_SS_FIT_IN_CAB\n", ways);
1340 } else {
1341 cmd.cab.header.sub_type = DMUB_CMD__CAB_DCN_SS_NOT_FIT_IN_CAB;
1342 DC_LOG_MALL("frame does not fit in CAB: %d ways required. CAB action: DCN_SS_NOT_FIT_IN_CAB\n", ways);
1343 }
1344 }
1345 } else {
1346 /* Disable CAB */
1347 cmd.cab.header.sub_type = DMUB_CMD__CAB_NO_IDLE_OPTIMIZATION;
1348 DC_LOG_MALL("idle optimization disabled\n");
1349 }
1350
1351 dm_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT);
1352
1353 return true;
1354 }
1355
dcn401_wait_for_dcc_meta_propagation(const struct dc * dc,const struct pipe_ctx * top_pipe)1356 void dcn401_wait_for_dcc_meta_propagation(const struct dc *dc,
1357 const struct pipe_ctx *top_pipe)
1358 {
1359 bool is_wait_needed = false;
1360 const struct pipe_ctx *pipe_ctx = top_pipe;
1361
1362 /* check if any surfaces are updating address while using flip immediate and dcc */
1363 while (pipe_ctx != NULL) {
1364 if (pipe_ctx->plane_state &&
1365 pipe_ctx->plane_state->dcc.enable &&
1366 pipe_ctx->plane_state->flip_immediate &&
1367 pipe_ctx->plane_state->update_flags.bits.addr_update) {
1368 is_wait_needed = true;
1369 break;
1370 }
1371
1372 /* check next pipe */
1373 pipe_ctx = pipe_ctx->bottom_pipe;
1374 }
1375
1376 if (is_wait_needed && dc->debug.dcc_meta_propagation_delay_us > 0) {
1377 udelay(dc->debug.dcc_meta_propagation_delay_us);
1378 }
1379 }
1380
dcn401_prepare_bandwidth(struct dc * dc,struct dc_state * context)1381 void dcn401_prepare_bandwidth(struct dc *dc,
1382 struct dc_state *context)
1383 {
1384 struct hubbub *hubbub = dc->res_pool->hubbub;
1385 bool p_state_change_support = context->bw_ctx.bw.dcn.clk.p_state_change_support;
1386 unsigned int compbuf_size = 0;
1387
1388 /* Any transition into P-State support should disable MCLK switching first to avoid hangs */
1389 if (p_state_change_support) {
1390 dc->optimized_required = true;
1391 context->bw_ctx.bw.dcn.clk.p_state_change_support = false;
1392 }
1393
1394 if (dc->clk_mgr->dc_mode_softmax_enabled)
1395 if (dc->clk_mgr->clks.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 &&
1396 context->bw_ctx.bw.dcn.clk.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000)
1397 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->clk_table.entries[dc->clk_mgr->bw_params->clk_table.num_entries - 1].memclk_mhz);
1398
1399 /* Increase clocks */
1400 dc->clk_mgr->funcs->update_clocks(
1401 dc->clk_mgr,
1402 context,
1403 false);
1404
1405 /* program dchubbub watermarks:
1406 * For assigning wm_optimized_required, use |= operator since we don't want
1407 * to clear the value if the optimize has not happened yet
1408 */
1409 dc->wm_optimized_required |= hubbub->funcs->program_watermarks(hubbub,
1410 &context->bw_ctx.bw.dcn.watermarks,
1411 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
1412 false);
1413 /* update timeout thresholds */
1414 if (hubbub->funcs->program_arbiter) {
1415 dc->wm_optimized_required |= hubbub->funcs->program_arbiter(hubbub, &context->bw_ctx.bw.dcn.arb_regs, false);
1416 }
1417
1418 /* decrease compbuf size */
1419 if (hubbub->funcs->program_compbuf_segments) {
1420 compbuf_size = context->bw_ctx.bw.dcn.arb_regs.compbuf_size;
1421 dc->wm_optimized_required |= (compbuf_size != dc->current_state->bw_ctx.bw.dcn.arb_regs.compbuf_size);
1422
1423 hubbub->funcs->program_compbuf_segments(hubbub, compbuf_size, false);
1424 }
1425
1426 if (dc->debug.fams2_config.bits.enable) {
1427 dcn401_fams2_global_control_lock(dc, context, true);
1428 dcn401_fams2_update_config(dc, context, false);
1429 dcn401_fams2_global_control_lock(dc, context, false);
1430 }
1431
1432 if (p_state_change_support != context->bw_ctx.bw.dcn.clk.p_state_change_support) {
1433 /* After disabling P-State, restore the original value to ensure we get the correct P-State
1434 * on the next optimize. */
1435 context->bw_ctx.bw.dcn.clk.p_state_change_support = p_state_change_support;
1436 }
1437 }
1438
dcn401_optimize_bandwidth(struct dc * dc,struct dc_state * context)1439 void dcn401_optimize_bandwidth(
1440 struct dc *dc,
1441 struct dc_state *context)
1442 {
1443 int i;
1444 struct hubbub *hubbub = dc->res_pool->hubbub;
1445
1446 /* enable fams2 if needed */
1447 if (dc->debug.fams2_config.bits.enable) {
1448 dcn401_fams2_global_control_lock(dc, context, true);
1449 dcn401_fams2_update_config(dc, context, true);
1450 dcn401_fams2_global_control_lock(dc, context, false);
1451 }
1452
1453 /* program dchubbub watermarks */
1454 hubbub->funcs->program_watermarks(hubbub,
1455 &context->bw_ctx.bw.dcn.watermarks,
1456 dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000,
1457 true);
1458 /* update timeout thresholds */
1459 if (hubbub->funcs->program_arbiter) {
1460 hubbub->funcs->program_arbiter(hubbub, &context->bw_ctx.bw.dcn.arb_regs, true);
1461 }
1462
1463 if (dc->clk_mgr->dc_mode_softmax_enabled)
1464 if (dc->clk_mgr->clks.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 &&
1465 context->bw_ctx.bw.dcn.clk.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000)
1466 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->dc_mode_softmax_memclk);
1467
1468 /* increase compbuf size */
1469 if (hubbub->funcs->program_compbuf_segments)
1470 hubbub->funcs->program_compbuf_segments(hubbub, context->bw_ctx.bw.dcn.arb_regs.compbuf_size, true);
1471
1472 dc->clk_mgr->funcs->update_clocks(
1473 dc->clk_mgr,
1474 context,
1475 true);
1476 if (context->bw_ctx.bw.dcn.clk.zstate_support == DCN_ZSTATE_SUPPORT_ALLOW) {
1477 for (i = 0; i < dc->res_pool->pipe_count; ++i) {
1478 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1479
1480 if (pipe_ctx->stream && pipe_ctx->plane_res.hubp->funcs->program_extended_blank
1481 && pipe_ctx->stream->adjust.v_total_min == pipe_ctx->stream->adjust.v_total_max
1482 && pipe_ctx->stream->adjust.v_total_max > pipe_ctx->stream->timing.v_total)
1483 pipe_ctx->plane_res.hubp->funcs->program_extended_blank(pipe_ctx->plane_res.hubp,
1484 pipe_ctx->dlg_regs.min_dst_y_next_start);
1485 }
1486 }
1487 }
1488
dcn401_fams2_global_control_lock(struct dc * dc,struct dc_state * context,bool lock)1489 void dcn401_fams2_global_control_lock(struct dc *dc,
1490 struct dc_state *context,
1491 bool lock)
1492 {
1493 /* use always for now */
1494 union dmub_inbox0_cmd_lock_hw hw_lock_cmd = { 0 };
1495
1496 if (!dc->ctx || !dc->ctx->dmub_srv || !dc->debug.fams2_config.bits.enable)
1497 return;
1498
1499 hw_lock_cmd.bits.command_code = DMUB_INBOX0_CMD__HW_LOCK;
1500 hw_lock_cmd.bits.hw_lock_client = HW_LOCK_CLIENT_DRIVER;
1501 hw_lock_cmd.bits.lock = lock;
1502 hw_lock_cmd.bits.should_release = !lock;
1503 dmub_hw_lock_mgr_inbox0_cmd(dc->ctx->dmub_srv, hw_lock_cmd);
1504 }
1505
dcn401_fams2_global_control_lock_fast(union block_sequence_params * params)1506 void dcn401_fams2_global_control_lock_fast(union block_sequence_params *params)
1507 {
1508 struct dc *dc = params->fams2_global_control_lock_fast_params.dc;
1509 bool lock = params->fams2_global_control_lock_fast_params.lock;
1510
1511 if (params->fams2_global_control_lock_fast_params.is_required) {
1512 union dmub_inbox0_cmd_lock_hw hw_lock_cmd = { 0 };
1513
1514 hw_lock_cmd.bits.command_code = DMUB_INBOX0_CMD__HW_LOCK;
1515 hw_lock_cmd.bits.hw_lock_client = HW_LOCK_CLIENT_DRIVER;
1516 hw_lock_cmd.bits.lock = lock;
1517 hw_lock_cmd.bits.should_release = !lock;
1518 dmub_hw_lock_mgr_inbox0_cmd(dc->ctx->dmub_srv, hw_lock_cmd);
1519 }
1520 }
1521
dcn401_fams2_update_config(struct dc * dc,struct dc_state * context,bool enable)1522 void dcn401_fams2_update_config(struct dc *dc, struct dc_state *context, bool enable)
1523 {
1524 bool fams2_required;
1525
1526 if (!dc->ctx || !dc->ctx->dmub_srv || !dc->debug.fams2_config.bits.enable)
1527 return;
1528
1529 fams2_required = context->bw_ctx.bw.dcn.fams2_global_config.features.bits.enable;
1530
1531 dc_dmub_srv_fams2_update_config(dc, context, enable && fams2_required);
1532 }
1533
update_dsc_for_odm_change(struct dc * dc,struct dc_state * context,struct pipe_ctx * otg_master)1534 static void update_dsc_for_odm_change(struct dc *dc, struct dc_state *context,
1535 struct pipe_ctx *otg_master)
1536 {
1537 int i;
1538 struct pipe_ctx *old_pipe;
1539 struct pipe_ctx *new_pipe;
1540 struct pipe_ctx *old_opp_heads[MAX_PIPES];
1541 struct pipe_ctx *old_otg_master;
1542 int old_opp_head_count = 0;
1543
1544 old_otg_master = &dc->current_state->res_ctx.pipe_ctx[otg_master->pipe_idx];
1545
1546 if (resource_is_pipe_type(old_otg_master, OTG_MASTER)) {
1547 old_opp_head_count = resource_get_opp_heads_for_otg_master(old_otg_master,
1548 &dc->current_state->res_ctx,
1549 old_opp_heads);
1550 } else {
1551 // DC cannot assume that the current state and the new state
1552 // share the same OTG pipe since this is not true when called
1553 // in the context of a commit stream not checked. Hence, set
1554 // old_otg_master to NULL to skip the DSC configuration.
1555 old_otg_master = NULL;
1556 }
1557
1558
1559 if (otg_master->stream_res.dsc)
1560 dcn32_update_dsc_on_stream(otg_master,
1561 otg_master->stream->timing.flags.DSC);
1562 if (old_otg_master && old_otg_master->stream_res.dsc) {
1563 for (i = 0; i < old_opp_head_count; i++) {
1564 old_pipe = old_opp_heads[i];
1565 new_pipe = &context->res_ctx.pipe_ctx[old_pipe->pipe_idx];
1566 if (old_pipe->stream_res.dsc && !new_pipe->stream_res.dsc)
1567 old_pipe->stream_res.dsc->funcs->dsc_disconnect(
1568 old_pipe->stream_res.dsc);
1569 }
1570 }
1571 }
1572
dcn401_update_odm(struct dc * dc,struct dc_state * context,struct pipe_ctx * otg_master)1573 void dcn401_update_odm(struct dc *dc, struct dc_state *context,
1574 struct pipe_ctx *otg_master)
1575 {
1576 struct pipe_ctx *opp_heads[MAX_PIPES];
1577 int opp_inst[MAX_PIPES] = {0};
1578 int opp_head_count;
1579 int odm_slice_width = resource_get_odm_slice_dst_width(otg_master, false);
1580 int last_odm_slice_width = resource_get_odm_slice_dst_width(otg_master, true);
1581 int i;
1582
1583 opp_head_count = resource_get_opp_heads_for_otg_master(
1584 otg_master, &context->res_ctx, opp_heads);
1585
1586 for (i = 0; i < opp_head_count; i++)
1587 opp_inst[i] = opp_heads[i]->stream_res.opp->inst;
1588 if (opp_head_count > 1)
1589 otg_master->stream_res.tg->funcs->set_odm_combine(
1590 otg_master->stream_res.tg,
1591 opp_inst, opp_head_count,
1592 odm_slice_width, last_odm_slice_width);
1593 else
1594 otg_master->stream_res.tg->funcs->set_odm_bypass(
1595 otg_master->stream_res.tg,
1596 &otg_master->stream->timing);
1597
1598 for (i = 0; i < opp_head_count; i++) {
1599 opp_heads[i]->stream_res.opp->funcs->opp_pipe_clock_control(
1600 opp_heads[i]->stream_res.opp,
1601 true);
1602 opp_heads[i]->stream_res.opp->funcs->opp_program_left_edge_extra_pixel(
1603 opp_heads[i]->stream_res.opp,
1604 opp_heads[i]->stream->timing.pixel_encoding,
1605 resource_is_pipe_type(opp_heads[i], OTG_MASTER));
1606 }
1607
1608 update_dsc_for_odm_change(dc, context, otg_master);
1609
1610 if (!resource_is_pipe_type(otg_master, DPP_PIPE))
1611 /*
1612 * blank pattern is generated by OPP, reprogram blank pattern
1613 * due to OPP count change
1614 */
1615 dc->hwseq->funcs.blank_pixel_data(dc, otg_master, true);
1616 }
1617
dcn401_unblank_stream(struct pipe_ctx * pipe_ctx,struct dc_link_settings * link_settings)1618 void dcn401_unblank_stream(struct pipe_ctx *pipe_ctx,
1619 struct dc_link_settings *link_settings)
1620 {
1621 struct encoder_unblank_param params = {0};
1622 struct dc_stream_state *stream = pipe_ctx->stream;
1623 struct dc_link *link = stream->link;
1624 struct dce_hwseq *hws = link->dc->hwseq;
1625
1626 /* calculate parameters for unblank */
1627 params.opp_cnt = resource_get_odm_slice_count(pipe_ctx);
1628
1629 params.timing = pipe_ctx->stream->timing;
1630 params.link_settings.link_rate = link_settings->link_rate;
1631 params.pix_per_cycle = pipe_ctx->stream_res.pix_clk_params.dio_se_pix_per_cycle;
1632
1633 if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1634 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_unblank(
1635 pipe_ctx->stream_res.hpo_dp_stream_enc,
1636 pipe_ctx->stream_res.tg->inst);
1637 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1638 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
1639 }
1640
1641 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP)
1642 hws->funcs.edp_backlight_control(link, true);
1643 }
1644
dcn401_hardware_release(struct dc * dc)1645 void dcn401_hardware_release(struct dc *dc)
1646 {
1647 dc_dmub_srv_fams2_update_config(dc, dc->current_state, false);
1648
1649 /* If pstate unsupported, or still supported
1650 * by firmware, force it supported by dcn
1651 */
1652 if (dc->current_state) {
1653 if ((!dc->clk_mgr->clks.p_state_change_support ||
1654 dc->current_state->bw_ctx.bw.dcn.fams2_global_config.features.bits.enable) &&
1655 dc->res_pool->hubbub->funcs->force_pstate_change_control)
1656 dc->res_pool->hubbub->funcs->force_pstate_change_control(
1657 dc->res_pool->hubbub, true, true);
1658
1659 dc->current_state->bw_ctx.bw.dcn.clk.p_state_change_support = true;
1660 dc->clk_mgr->funcs->update_clocks(dc->clk_mgr, dc->current_state, true);
1661 }
1662 }
1663
dcn401_wait_for_det_buffer_update_under_otg_master(struct dc * dc,struct dc_state * context,struct pipe_ctx * otg_master)1664 void dcn401_wait_for_det_buffer_update_under_otg_master(struct dc *dc, struct dc_state *context, struct pipe_ctx *otg_master)
1665 {
1666 struct pipe_ctx *opp_heads[MAX_PIPES];
1667 struct pipe_ctx *dpp_pipes[MAX_PIPES];
1668 struct hubbub *hubbub = dc->res_pool->hubbub;
1669 int dpp_count = 0;
1670
1671 if (!otg_master->stream)
1672 return;
1673
1674 int slice_count = resource_get_opp_heads_for_otg_master(otg_master,
1675 &context->res_ctx, opp_heads);
1676
1677 for (int slice_idx = 0; slice_idx < slice_count; slice_idx++) {
1678 if (opp_heads[slice_idx]->plane_state) {
1679 dpp_count = resource_get_dpp_pipes_for_opp_head(
1680 opp_heads[slice_idx],
1681 &context->res_ctx,
1682 dpp_pipes);
1683 for (int dpp_idx = 0; dpp_idx < dpp_count; dpp_idx++) {
1684 struct pipe_ctx *dpp_pipe = dpp_pipes[dpp_idx];
1685 if (dpp_pipe && hubbub &&
1686 dpp_pipe->plane_res.hubp &&
1687 hubbub->funcs->wait_for_det_update)
1688 hubbub->funcs->wait_for_det_update(hubbub, dpp_pipe->plane_res.hubp->inst);
1689 }
1690 } else {
1691 if (hubbub && opp_heads[slice_idx]->plane_res.hubp && hubbub->funcs->wait_for_det_update)
1692 hubbub->funcs->wait_for_det_update(hubbub, opp_heads[slice_idx]->plane_res.hubp->inst);
1693 }
1694 }
1695 }
1696
dcn401_interdependent_update_lock(struct dc * dc,struct dc_state * context,bool lock)1697 void dcn401_interdependent_update_lock(struct dc *dc,
1698 struct dc_state *context, bool lock)
1699 {
1700 unsigned int i = 0;
1701 struct pipe_ctx *pipe = NULL;
1702 struct timing_generator *tg = NULL;
1703
1704 if (lock) {
1705 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1706 pipe = &context->res_ctx.pipe_ctx[i];
1707 tg = pipe->stream_res.tg;
1708
1709 if (!resource_is_pipe_type(pipe, OTG_MASTER) ||
1710 !tg->funcs->is_tg_enabled(tg) ||
1711 dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM)
1712 continue;
1713 dc->hwss.pipe_control_lock(dc, pipe, true);
1714 }
1715 } else {
1716 /* Need to free DET being used first and have pipe update, then unlock the remaining pipes*/
1717 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1718 pipe = &context->res_ctx.pipe_ctx[i];
1719 tg = pipe->stream_res.tg;
1720
1721 if (!resource_is_pipe_type(pipe, OTG_MASTER) ||
1722 !tg->funcs->is_tg_enabled(tg) ||
1723 dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
1724 continue;
1725 }
1726
1727 if (dc->scratch.pipes_to_unlock_first[i]) {
1728 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1729 dc->hwss.pipe_control_lock(dc, pipe, false);
1730 /* Assumes pipe of the same index in current_state is also an OTG_MASTER pipe*/
1731 dcn401_wait_for_det_buffer_update_under_otg_master(dc, dc->current_state, old_pipe);
1732 }
1733 }
1734
1735 /* Unlocking the rest of the pipes */
1736 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1737 if (dc->scratch.pipes_to_unlock_first[i])
1738 continue;
1739
1740 pipe = &context->res_ctx.pipe_ctx[i];
1741 tg = pipe->stream_res.tg;
1742 if (!resource_is_pipe_type(pipe, OTG_MASTER) ||
1743 !tg->funcs->is_tg_enabled(tg) ||
1744 dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
1745 continue;
1746 }
1747
1748 dc->hwss.pipe_control_lock(dc, pipe, false);
1749 }
1750 }
1751 }
1752
dcn401_perform_3dlut_wa_unlock(struct pipe_ctx * pipe_ctx)1753 void dcn401_perform_3dlut_wa_unlock(struct pipe_ctx *pipe_ctx)
1754 {
1755 /* If 3DLUT FL is enabled and 3DLUT is in use, follow the workaround sequence for pipe unlock to make sure that
1756 * HUBP will properly fetch 3DLUT contents after unlock.
1757 *
1758 * This is meant to work around a known HW issue where VREADY will cancel the pending 3DLUT_ENABLE signal regardless
1759 * of whether OTG lock is currently being held or not.
1760 */
1761 struct pipe_ctx *wa_pipes[MAX_PIPES] = { NULL };
1762 struct pipe_ctx *odm_pipe, *mpc_pipe;
1763 int i, wa_pipe_ct = 0;
1764
1765 for (odm_pipe = pipe_ctx; odm_pipe != NULL; odm_pipe = odm_pipe->next_odm_pipe) {
1766 for (mpc_pipe = odm_pipe; mpc_pipe != NULL; mpc_pipe = mpc_pipe->bottom_pipe) {
1767 if (mpc_pipe->plane_state && mpc_pipe->plane_state->mcm_luts.lut3d_data.lut3d_src
1768 == DC_CM2_TRANSFER_FUNC_SOURCE_VIDMEM
1769 && mpc_pipe->plane_state->mcm_shaper_3dlut_setting
1770 == DC_CM2_SHAPER_3DLUT_SETTING_ENABLE_SHAPER_3DLUT) {
1771 wa_pipes[wa_pipe_ct++] = mpc_pipe;
1772 }
1773 }
1774 }
1775
1776 if (wa_pipe_ct > 0) {
1777 if (pipe_ctx->stream_res.tg->funcs->set_vupdate_keepout)
1778 pipe_ctx->stream_res.tg->funcs->set_vupdate_keepout(pipe_ctx->stream_res.tg, true);
1779
1780 for (i = 0; i < wa_pipe_ct; ++i) {
1781 if (wa_pipes[i]->plane_res.hubp->funcs->hubp_enable_3dlut_fl)
1782 wa_pipes[i]->plane_res.hubp->funcs->hubp_enable_3dlut_fl(wa_pipes[i]->plane_res.hubp, true);
1783 }
1784
1785 pipe_ctx->stream_res.tg->funcs->unlock(pipe_ctx->stream_res.tg);
1786 if (pipe_ctx->stream_res.tg->funcs->wait_update_lock_status)
1787 pipe_ctx->stream_res.tg->funcs->wait_update_lock_status(pipe_ctx->stream_res.tg, false);
1788
1789 for (i = 0; i < wa_pipe_ct; ++i) {
1790 if (wa_pipes[i]->plane_res.hubp->funcs->hubp_enable_3dlut_fl)
1791 wa_pipes[i]->plane_res.hubp->funcs->hubp_enable_3dlut_fl(wa_pipes[i]->plane_res.hubp, true);
1792 }
1793
1794 if (pipe_ctx->stream_res.tg->funcs->set_vupdate_keepout)
1795 pipe_ctx->stream_res.tg->funcs->set_vupdate_keepout(pipe_ctx->stream_res.tg, false);
1796 } else {
1797 pipe_ctx->stream_res.tg->funcs->unlock(pipe_ctx->stream_res.tg);
1798 }
1799 }
1800
dcn401_program_outstanding_updates(struct dc * dc,struct dc_state * context)1801 void dcn401_program_outstanding_updates(struct dc *dc,
1802 struct dc_state *context)
1803 {
1804 struct hubbub *hubbub = dc->res_pool->hubbub;
1805
1806 /* update compbuf if required */
1807 if (hubbub->funcs->program_compbuf_segments)
1808 hubbub->funcs->program_compbuf_segments(hubbub, context->bw_ctx.bw.dcn.arb_regs.compbuf_size, true);
1809 }
1810
dcn401_reset_back_end_for_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)1811 void dcn401_reset_back_end_for_pipe(
1812 struct dc *dc,
1813 struct pipe_ctx *pipe_ctx,
1814 struct dc_state *context)
1815 {
1816 struct dc_link *link = pipe_ctx->stream->link;
1817 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1818
1819 DC_LOGGER_INIT(dc->ctx->logger);
1820 if (pipe_ctx->stream_res.stream_enc == NULL) {
1821 pipe_ctx->stream = NULL;
1822 return;
1823 }
1824
1825 /* DPMS may already disable or */
1826 /* dpms_off status is incorrect due to fastboot
1827 * feature. When system resume from S4 with second
1828 * screen only, the dpms_off would be true but
1829 * VBIOS lit up eDP, so check link status too.
1830 */
1831 if (!pipe_ctx->stream->dpms_off || link->link_status.link_active)
1832 dc->link_srv->set_dpms_off(pipe_ctx);
1833 else if (pipe_ctx->stream_res.audio)
1834 dc->hwss.disable_audio_stream(pipe_ctx);
1835
1836 /* free acquired resources */
1837 if (pipe_ctx->stream_res.audio) {
1838 /*disable az_endpoint*/
1839 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
1840
1841 /*free audio*/
1842 if (dc->caps.dynamic_audio == true) {
1843 /*we have to dynamic arbitrate the audio endpoints*/
1844 /*we free the resource, need reset is_audio_acquired*/
1845 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
1846 pipe_ctx->stream_res.audio, false);
1847 pipe_ctx->stream_res.audio = NULL;
1848 }
1849 }
1850
1851 /* by upper caller loop, parent pipe: pipe0, will be reset last.
1852 * back end share by all pipes and will be disable only when disable
1853 * parent pipe.
1854 */
1855 if (pipe_ctx->top_pipe == NULL) {
1856
1857 dc->hwss.set_abm_immediate_disable(pipe_ctx);
1858
1859 pipe_ctx->stream_res.tg->funcs->disable_crtc(pipe_ctx->stream_res.tg);
1860
1861 pipe_ctx->stream_res.tg->funcs->enable_optc_clock(pipe_ctx->stream_res.tg, false);
1862 if (pipe_ctx->stream_res.tg->funcs->set_odm_bypass)
1863 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
1864 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
1865
1866 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1867 pipe_ctx->stream_res.tg->funcs->set_drr(
1868 pipe_ctx->stream_res.tg, NULL);
1869 /* TODO - convert symclk_ref_cnts for otg to a bit map to solve
1870 * the case where the same symclk is shared across multiple otg
1871 * instances
1872 */
1873 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
1874 link->phy_state.symclk_ref_cnts.otg = 0;
1875 if (link->phy_state.symclk_state == SYMCLK_ON_TX_OFF) {
1876 link_hwss->disable_link_output(link,
1877 &pipe_ctx->link_res, pipe_ctx->stream->signal);
1878 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
1879 }
1880
1881 /* reset DTBCLK_P */
1882 if (dc->res_pool->dccg->funcs->set_dtbclk_p_src)
1883 dc->res_pool->dccg->funcs->set_dtbclk_p_src(dc->res_pool->dccg, REFCLK, pipe_ctx->stream_res.tg->inst);
1884 }
1885
1886 /*
1887 * In case of a dangling plane, setting this to NULL unconditionally
1888 * causes failures during reset hw ctx where, if stream is NULL,
1889 * it is expected that the pipe_ctx pointers to pipes and plane are NULL.
1890 */
1891 pipe_ctx->stream = NULL;
1892 pipe_ctx->top_pipe = NULL;
1893 pipe_ctx->bottom_pipe = NULL;
1894 pipe_ctx->next_odm_pipe = NULL;
1895 pipe_ctx->prev_odm_pipe = NULL;
1896 DC_LOG_DEBUG("Reset back end for pipe %d, tg:%d\n",
1897 pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
1898 }
1899
dcn401_reset_hw_ctx_wrap(struct dc * dc,struct dc_state * context)1900 void dcn401_reset_hw_ctx_wrap(
1901 struct dc *dc,
1902 struct dc_state *context)
1903 {
1904 int i;
1905 struct dce_hwseq *hws = dc->hwseq;
1906
1907 /* Reset Back End*/
1908 for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
1909 struct pipe_ctx *pipe_ctx_old =
1910 &dc->current_state->res_ctx.pipe_ctx[i];
1911 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1912
1913 if (!pipe_ctx_old->stream)
1914 continue;
1915
1916 if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe)
1917 continue;
1918
1919 if (!pipe_ctx->stream ||
1920 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
1921 struct clock_source *old_clk = pipe_ctx_old->clock_source;
1922
1923 if (hws->funcs.reset_back_end_for_pipe)
1924 hws->funcs.reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
1925 if (hws->funcs.enable_stream_gating)
1926 hws->funcs.enable_stream_gating(dc, pipe_ctx_old);
1927 if (old_clk)
1928 old_clk->funcs->cs_power_down(old_clk);
1929 }
1930 }
1931 }
1932
dcn401_calculate_vready_offset_for_group(struct pipe_ctx * pipe)1933 static unsigned int dcn401_calculate_vready_offset_for_group(struct pipe_ctx *pipe)
1934 {
1935 struct pipe_ctx *other_pipe;
1936 unsigned int vready_offset = pipe->global_sync.dcn4x.vready_offset_pixels;
1937
1938 /* Always use the largest vready_offset of all connected pipes */
1939 for (other_pipe = pipe->bottom_pipe; other_pipe != NULL; other_pipe = other_pipe->bottom_pipe) {
1940 if (other_pipe->global_sync.dcn4x.vready_offset_pixels > vready_offset)
1941 vready_offset = other_pipe->global_sync.dcn4x.vready_offset_pixels;
1942 }
1943 for (other_pipe = pipe->top_pipe; other_pipe != NULL; other_pipe = other_pipe->top_pipe) {
1944 if (other_pipe->global_sync.dcn4x.vready_offset_pixels > vready_offset)
1945 vready_offset = other_pipe->global_sync.dcn4x.vready_offset_pixels;
1946 }
1947 for (other_pipe = pipe->next_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->next_odm_pipe) {
1948 if (other_pipe->global_sync.dcn4x.vready_offset_pixels > vready_offset)
1949 vready_offset = other_pipe->global_sync.dcn4x.vready_offset_pixels;
1950 }
1951 for (other_pipe = pipe->prev_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->prev_odm_pipe) {
1952 if (other_pipe->global_sync.dcn4x.vready_offset_pixels > vready_offset)
1953 vready_offset = other_pipe->global_sync.dcn4x.vready_offset_pixels;
1954 }
1955
1956 return vready_offset;
1957 }
1958
dcn401_program_tg(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dce_hwseq * hws)1959 static void dcn401_program_tg(
1960 struct dc *dc,
1961 struct pipe_ctx *pipe_ctx,
1962 struct dc_state *context,
1963 struct dce_hwseq *hws)
1964 {
1965 pipe_ctx->stream_res.tg->funcs->program_global_sync(
1966 pipe_ctx->stream_res.tg,
1967 dcn401_calculate_vready_offset_for_group(pipe_ctx),
1968 (unsigned int)pipe_ctx->global_sync.dcn4x.vstartup_lines,
1969 (unsigned int)pipe_ctx->global_sync.dcn4x.vupdate_offset_pixels,
1970 (unsigned int)pipe_ctx->global_sync.dcn4x.vupdate_vupdate_width_pixels,
1971 (unsigned int)pipe_ctx->global_sync.dcn4x.pstate_keepout_start_lines);
1972
1973 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM)
1974 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
1975
1976 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
1977 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, true);
1978
1979 if (hws->funcs.setup_vupdate_interrupt)
1980 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1981 }
1982
dcn401_program_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx,struct dc_state * context)1983 static void dcn401_program_pipe(
1984 struct dc *dc,
1985 struct pipe_ctx *pipe_ctx,
1986 struct dc_state *context)
1987 {
1988 struct dce_hwseq *hws = dc->hwseq;
1989
1990 /* Only need to unblank on top pipe */
1991 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER)) {
1992 if (pipe_ctx->update_flags.bits.enable ||
1993 pipe_ctx->update_flags.bits.odm ||
1994 pipe_ctx->stream->update_flags.bits.abm_level)
1995 hws->funcs.blank_pixel_data(dc, pipe_ctx,
1996 !pipe_ctx->plane_state ||
1997 !pipe_ctx->plane_state->visible);
1998 }
1999
2000 /* Only update TG on top pipe */
2001 if (pipe_ctx->update_flags.bits.global_sync && !pipe_ctx->top_pipe
2002 && !pipe_ctx->prev_odm_pipe)
2003 dcn401_program_tg(dc, pipe_ctx, context, hws);
2004
2005 if (pipe_ctx->update_flags.bits.odm)
2006 hws->funcs.update_odm(dc, context, pipe_ctx);
2007
2008 if (pipe_ctx->update_flags.bits.enable) {
2009 if (hws->funcs.enable_plane)
2010 hws->funcs.enable_plane(dc, pipe_ctx, context);
2011 else
2012 dc->hwss.enable_plane(dc, pipe_ctx, context);
2013
2014 if (dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes)
2015 dc->res_pool->hubbub->funcs->force_wm_propagate_to_pipes(dc->res_pool->hubbub);
2016 }
2017
2018 if (pipe_ctx->update_flags.bits.det_size) {
2019 if (dc->res_pool->hubbub->funcs->program_det_size)
2020 dc->res_pool->hubbub->funcs->program_det_size(
2021 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->det_buffer_size_kb);
2022 if (dc->res_pool->hubbub->funcs->program_det_segments)
2023 dc->res_pool->hubbub->funcs->program_det_segments(
2024 dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->hubp_regs.det_size);
2025 }
2026
2027 if (pipe_ctx->update_flags.raw ||
2028 (pipe_ctx->plane_state && pipe_ctx->plane_state->update_flags.raw) ||
2029 pipe_ctx->stream->update_flags.raw)
2030 dc->hwss.update_dchubp_dpp(dc, pipe_ctx, context);
2031
2032 if (pipe_ctx->plane_state && (pipe_ctx->update_flags.bits.enable ||
2033 pipe_ctx->plane_state->update_flags.bits.hdr_mult))
2034 hws->funcs.set_hdr_multiplier(pipe_ctx);
2035
2036 if (hws->funcs.populate_mcm_luts) {
2037 if (pipe_ctx->plane_state) {
2038 hws->funcs.populate_mcm_luts(dc, pipe_ctx, pipe_ctx->plane_state->mcm_luts,
2039 pipe_ctx->plane_state->lut_bank_a);
2040 pipe_ctx->plane_state->lut_bank_a = !pipe_ctx->plane_state->lut_bank_a;
2041 }
2042 }
2043
2044 if (pipe_ctx->plane_state &&
2045 (pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2046 pipe_ctx->plane_state->update_flags.bits.gamma_change ||
2047 pipe_ctx->plane_state->update_flags.bits.lut_3d ||
2048 pipe_ctx->update_flags.bits.enable))
2049 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
2050
2051 /* dcn10_translate_regamma_to_hw_format takes 750us to finish
2052 * only do gamma programming for powering on, internal memcmp to avoid
2053 * updating on slave planes
2054 */
2055 if (pipe_ctx->update_flags.bits.enable ||
2056 pipe_ctx->update_flags.bits.plane_changed ||
2057 pipe_ctx->stream->update_flags.bits.out_tf ||
2058 (pipe_ctx->plane_state &&
2059 pipe_ctx->plane_state->update_flags.bits.output_tf_change))
2060 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
2061
2062 /* If the pipe has been enabled or has a different opp, we
2063 * should reprogram the fmt. This deals with cases where
2064 * interation between mpc and odm combine on different streams
2065 * causes a different pipe to be chosen to odm combine with.
2066 */
2067 if (pipe_ctx->update_flags.bits.enable
2068 || pipe_ctx->update_flags.bits.opp_changed) {
2069
2070 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
2071 pipe_ctx->stream_res.opp,
2072 COLOR_SPACE_YCBCR601,
2073 pipe_ctx->stream->timing.display_color_depth,
2074 pipe_ctx->stream->signal);
2075
2076 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
2077 pipe_ctx->stream_res.opp,
2078 &pipe_ctx->stream->bit_depth_params,
2079 &pipe_ctx->stream->clamping);
2080 }
2081
2082 /* Set ABM pipe after other pipe configurations done */
2083 if ((pipe_ctx->plane_state && pipe_ctx->plane_state->visible)) {
2084 if (pipe_ctx->stream_res.abm) {
2085 dc->hwss.set_pipe(pipe_ctx);
2086 pipe_ctx->stream_res.abm->funcs->set_abm_level(pipe_ctx->stream_res.abm,
2087 pipe_ctx->stream->abm_level);
2088 }
2089 }
2090
2091 if (pipe_ctx->update_flags.bits.test_pattern_changed) {
2092 struct output_pixel_processor *odm_opp = pipe_ctx->stream_res.opp;
2093 struct bit_depth_reduction_params params;
2094
2095 memset(¶ms, 0, sizeof(params));
2096 odm_opp->funcs->opp_program_bit_depth_reduction(odm_opp, ¶ms);
2097 dc->hwss.set_disp_pattern_generator(dc,
2098 pipe_ctx,
2099 pipe_ctx->stream_res.test_pattern_params.test_pattern,
2100 pipe_ctx->stream_res.test_pattern_params.color_space,
2101 pipe_ctx->stream_res.test_pattern_params.color_depth,
2102 NULL,
2103 pipe_ctx->stream_res.test_pattern_params.width,
2104 pipe_ctx->stream_res.test_pattern_params.height,
2105 pipe_ctx->stream_res.test_pattern_params.offset);
2106 }
2107 }
2108
dcn401_program_front_end_for_ctx(struct dc * dc,struct dc_state * context)2109 void dcn401_program_front_end_for_ctx(
2110 struct dc *dc,
2111 struct dc_state *context)
2112 {
2113 int i;
2114 unsigned int prev_hubp_count = 0;
2115 unsigned int hubp_count = 0;
2116 struct dce_hwseq *hws = dc->hwseq;
2117 struct pipe_ctx *pipe = NULL;
2118
2119 DC_LOGGER_INIT(dc->ctx->logger);
2120
2121 if (resource_is_pipe_topology_changed(dc->current_state, context))
2122 resource_log_pipe_topology_update(dc, context);
2123
2124 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2125 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2126 pipe = &context->res_ctx.pipe_ctx[i];
2127
2128 if (!pipe->top_pipe && !pipe->prev_odm_pipe && pipe->plane_state) {
2129 if (pipe->plane_state->triplebuffer_flips)
2130 BREAK_TO_DEBUGGER();
2131
2132 /*turn off triple buffer for full update*/
2133 dc->hwss.program_triplebuffer(
2134 dc, pipe, pipe->plane_state->triplebuffer_flips);
2135 }
2136 }
2137 }
2138
2139 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2140 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
2141 prev_hubp_count++;
2142 if (context->res_ctx.pipe_ctx[i].plane_state)
2143 hubp_count++;
2144 }
2145
2146 if (prev_hubp_count == 0 && hubp_count > 0) {
2147 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2148 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2149 dc->res_pool->hubbub, true, false);
2150 udelay(500);
2151 }
2152
2153 /* Set pipe update flags and lock pipes */
2154 for (i = 0; i < dc->res_pool->pipe_count; i++)
2155 dc->hwss.detect_pipe_changes(dc->current_state, context, &dc->current_state->res_ctx.pipe_ctx[i],
2156 &context->res_ctx.pipe_ctx[i]);
2157
2158 /* When disabling phantom pipes, turn on phantom OTG first (so we can get double
2159 * buffer updates properly)
2160 */
2161 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2162 struct dc_stream_state *stream = dc->current_state->res_ctx.pipe_ctx[i].stream;
2163
2164 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2165
2166 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable && stream &&
2167 dc_state_get_pipe_subvp_type(dc->current_state, pipe) == SUBVP_PHANTOM) {
2168 struct timing_generator *tg = dc->current_state->res_ctx.pipe_ctx[i].stream_res.tg;
2169
2170 if (tg->funcs->enable_crtc) {
2171 if (dc->hwseq->funcs.blank_pixel_data)
2172 dc->hwseq->funcs.blank_pixel_data(dc, pipe, true);
2173
2174 tg->funcs->enable_crtc(tg);
2175 }
2176 }
2177 }
2178 /* OTG blank before disabling all front ends */
2179 for (i = 0; i < dc->res_pool->pipe_count; i++)
2180 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2181 && !context->res_ctx.pipe_ctx[i].top_pipe
2182 && !context->res_ctx.pipe_ctx[i].prev_odm_pipe
2183 && context->res_ctx.pipe_ctx[i].stream)
2184 hws->funcs.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true);
2185
2186
2187 /* Disconnect mpcc */
2188 for (i = 0; i < dc->res_pool->pipe_count; i++)
2189 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
2190 || context->res_ctx.pipe_ctx[i].update_flags.bits.opp_changed) {
2191 struct hubbub *hubbub = dc->res_pool->hubbub;
2192
2193 /* Phantom pipe DET should be 0, but if a pipe in use is being transitioned to phantom
2194 * then we want to do the programming here (effectively it's being disabled). If we do
2195 * the programming later the DET won't be updated until the OTG for the phantom pipe is
2196 * turned on (i.e. in an MCLK switch) which can come in too late and cause issues with
2197 * DET allocation.
2198 */
2199 if ((context->res_ctx.pipe_ctx[i].update_flags.bits.disable ||
2200 (context->res_ctx.pipe_ctx[i].plane_state &&
2201 dc_state_get_pipe_subvp_type(context, &context->res_ctx.pipe_ctx[i]) ==
2202 SUBVP_PHANTOM))) {
2203 if (hubbub->funcs->program_det_size)
2204 hubbub->funcs->program_det_size(hubbub,
2205 dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2206 if (dc->res_pool->hubbub->funcs->program_det_segments)
2207 dc->res_pool->hubbub->funcs->program_det_segments(
2208 hubbub, dc->current_state->res_ctx.pipe_ctx[i].plane_res.hubp->inst, 0);
2209 }
2210 hws->funcs.plane_atomic_disconnect(dc, dc->current_state,
2211 &dc->current_state->res_ctx.pipe_ctx[i]);
2212 DC_LOG_DC("Reset mpcc for pipe %d\n", dc->current_state->res_ctx.pipe_ctx[i].pipe_idx);
2213 }
2214
2215 /* update ODM for blanked OTG master pipes */
2216 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2217 pipe = &context->res_ctx.pipe_ctx[i];
2218 if (resource_is_pipe_type(pipe, OTG_MASTER) &&
2219 !resource_is_pipe_type(pipe, DPP_PIPE) &&
2220 pipe->update_flags.bits.odm &&
2221 hws->funcs.update_odm)
2222 hws->funcs.update_odm(dc, context, pipe);
2223 }
2224
2225 /*
2226 * Program all updated pipes, order matters for mpcc setup. Start with
2227 * top pipe and program all pipes that follow in order
2228 */
2229 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2230 pipe = &context->res_ctx.pipe_ctx[i];
2231
2232 if (pipe->plane_state && !pipe->top_pipe) {
2233 while (pipe) {
2234 if (hws->funcs.program_pipe)
2235 hws->funcs.program_pipe(dc, pipe, context);
2236 else {
2237 /* Don't program phantom pipes in the regular front end programming sequence.
2238 * There is an MPO transition case where a pipe being used by a video plane is
2239 * transitioned directly to be a phantom pipe when closing the MPO video.
2240 * However the phantom pipe will program a new HUBP_VTG_SEL (update takes place
2241 * right away) but the MPO still exists until the double buffered update of the
2242 * main pipe so we will get a frame of underflow if the phantom pipe is
2243 * programmed here.
2244 */
2245 if (pipe->stream &&
2246 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM)
2247 dcn401_program_pipe(dc, pipe, context);
2248 }
2249
2250 pipe = pipe->bottom_pipe;
2251 }
2252 }
2253
2254 /* Program secondary blending tree and writeback pipes */
2255 pipe = &context->res_ctx.pipe_ctx[i];
2256 if (!pipe->top_pipe && !pipe->prev_odm_pipe
2257 && pipe->stream && pipe->stream->num_wb_info > 0
2258 && (pipe->update_flags.raw || (pipe->plane_state && pipe->plane_state->update_flags.raw)
2259 || pipe->stream->update_flags.raw)
2260 && hws->funcs.program_all_writeback_pipes_in_tree)
2261 hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context);
2262
2263 /* Avoid underflow by check of pipe line read when adding 2nd plane. */
2264 if (hws->wa.wait_hubpret_read_start_during_mpo_transition &&
2265 !pipe->top_pipe &&
2266 pipe->stream &&
2267 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start &&
2268 dc->current_state->stream_status[0].plane_count == 1 &&
2269 context->stream_status[0].plane_count > 1) {
2270 pipe->plane_res.hubp->funcs->hubp_wait_pipe_read_start(pipe->plane_res.hubp);
2271 }
2272 }
2273 }
2274
dcn401_post_unlock_program_front_end(struct dc * dc,struct dc_state * context)2275 void dcn401_post_unlock_program_front_end(
2276 struct dc *dc,
2277 struct dc_state *context)
2278 {
2279 // Timeout for pipe enable
2280 unsigned int timeout_us = 100000;
2281 unsigned int polling_interval_us = 1;
2282 struct dce_hwseq *hwseq = dc->hwseq;
2283 int i;
2284
2285 DC_LOGGER_INIT(dc->ctx->logger);
2286
2287 for (i = 0; i < dc->res_pool->pipe_count; i++)
2288 if (resource_is_pipe_type(&dc->current_state->res_ctx.pipe_ctx[i], OPP_HEAD) &&
2289 !resource_is_pipe_type(&context->res_ctx.pipe_ctx[i], OPP_HEAD))
2290 dc->hwss.post_unlock_reset_opp(dc,
2291 &dc->current_state->res_ctx.pipe_ctx[i]);
2292
2293 for (i = 0; i < dc->res_pool->pipe_count; i++)
2294 if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable)
2295 dc->hwss.disable_plane(dc, dc->current_state, &dc->current_state->res_ctx.pipe_ctx[i]);
2296
2297 /*
2298 * If we are enabling a pipe, we need to wait for pending clear as this is a critical
2299 * part of the enable operation otherwise, DM may request an immediate flip which
2300 * will cause HW to perform an "immediate enable" (as opposed to "vsync enable") which
2301 * is unsupported on DCN.
2302 */
2303 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2304 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2305 // Don't check flip pending on phantom pipes
2306 if (pipe->plane_state && !pipe->top_pipe && pipe->update_flags.bits.enable &&
2307 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2308 struct hubp *hubp = pipe->plane_res.hubp;
2309 int j = 0;
2310
2311 for (j = 0; j < timeout_us / polling_interval_us
2312 && hubp->funcs->hubp_is_flip_pending(hubp); j++)
2313 udelay(polling_interval_us);
2314 }
2315 }
2316
2317 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2318 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2319 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2320
2321 /* When going from a smaller ODM slice count to larger, we must ensure double
2322 * buffer update completes before we return to ensure we don't reduce DISPCLK
2323 * before we've transitioned to 2:1 or 4:1
2324 */
2325 if (resource_is_pipe_type(old_pipe, OTG_MASTER) && resource_is_pipe_type(pipe, OTG_MASTER) &&
2326 resource_get_odm_slice_count(old_pipe) < resource_get_odm_slice_count(pipe) &&
2327 dc_state_get_pipe_subvp_type(context, pipe) != SUBVP_PHANTOM) {
2328 int j = 0;
2329 struct timing_generator *tg = pipe->stream_res.tg;
2330
2331 if (tg->funcs->get_optc_double_buffer_pending) {
2332 for (j = 0; j < timeout_us / polling_interval_us
2333 && tg->funcs->get_optc_double_buffer_pending(tg); j++)
2334 udelay(polling_interval_us);
2335 }
2336 }
2337 }
2338
2339 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
2340 dc->res_pool->hubbub->funcs->force_pstate_change_control(
2341 dc->res_pool->hubbub, false, false);
2342
2343
2344 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2345 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2346
2347 if (pipe->plane_state && !pipe->top_pipe) {
2348 /* Program phantom pipe here to prevent a frame of underflow in the MPO transition
2349 * case (if a pipe being used for a video plane transitions to a phantom pipe, it
2350 * can underflow due to HUBP_VTG_SEL programming if done in the regular front end
2351 * programming sequence).
2352 */
2353 while (pipe) {
2354 if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
2355 /* When turning on the phantom pipe we want to run through the
2356 * entire enable sequence, so apply all the "enable" flags.
2357 */
2358 if (dc->hwss.apply_update_flags_for_phantom)
2359 dc->hwss.apply_update_flags_for_phantom(pipe);
2360 if (dc->hwss.update_phantom_vp_position)
2361 dc->hwss.update_phantom_vp_position(dc, context, pipe);
2362 dcn401_program_pipe(dc, pipe, context);
2363 }
2364 pipe = pipe->bottom_pipe;
2365 }
2366 }
2367 }
2368
2369 if (!hwseq)
2370 return;
2371
2372 /* P-State support transitions:
2373 * Natural -> FPO: P-State disabled in prepare, force disallow anytime is safe
2374 * FPO -> Natural: Unforce anytime after FW disable is safe (P-State will assert naturally)
2375 * Unsupported -> FPO: P-State enabled in optimize, force disallow anytime is safe
2376 * FPO -> Unsupported: P-State disabled in prepare, unforce disallow anytime is safe
2377 * FPO <-> SubVP: Force disallow is maintained on the FPO / SubVP pipes
2378 */
2379 if (hwseq->funcs.update_force_pstate)
2380 dc->hwseq->funcs.update_force_pstate(dc, context);
2381
2382 /* Only program the MALL registers after all the main and phantom pipes
2383 * are done programming.
2384 */
2385 if (hwseq->funcs.program_mall_pipe_config)
2386 hwseq->funcs.program_mall_pipe_config(dc, context);
2387
2388 /* WA to apply WM setting*/
2389 if (hwseq->wa.DEGVIDCN21)
2390 dc->res_pool->hubbub->funcs->apply_DEDCN21_147_wa(dc->res_pool->hubbub);
2391
2392
2393 /* WA for stutter underflow during MPO transitions when adding 2nd plane */
2394 if (hwseq->wa.disallow_self_refresh_during_multi_plane_transition) {
2395
2396 if (dc->current_state->stream_status[0].plane_count == 1 &&
2397 context->stream_status[0].plane_count > 1) {
2398
2399 struct timing_generator *tg = dc->res_pool->timing_generators[0];
2400
2401 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub, false);
2402
2403 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied = true;
2404 hwseq->wa_state.disallow_self_refresh_during_multi_plane_transition_applied_on_frame =
2405 tg->funcs->get_frame_count(tg);
2406 }
2407 }
2408 }
2409
dcn401_update_bandwidth(struct dc * dc,struct dc_state * context)2410 bool dcn401_update_bandwidth(
2411 struct dc *dc,
2412 struct dc_state *context)
2413 {
2414 int i;
2415 struct dce_hwseq *hws = dc->hwseq;
2416
2417 /* recalculate DML parameters */
2418 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false))
2419 return false;
2420
2421 /* apply updated bandwidth parameters */
2422 dc->hwss.prepare_bandwidth(dc, context);
2423
2424 /* update hubp configs for all pipes */
2425 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2426 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2427
2428 if (pipe_ctx->plane_state == NULL)
2429 continue;
2430
2431 if (pipe_ctx->top_pipe == NULL) {
2432 bool blank = !is_pipe_tree_visible(pipe_ctx);
2433
2434 pipe_ctx->stream_res.tg->funcs->program_global_sync(
2435 pipe_ctx->stream_res.tg,
2436 dcn401_calculate_vready_offset_for_group(pipe_ctx),
2437 (unsigned int)pipe_ctx->global_sync.dcn4x.vstartup_lines,
2438 (unsigned int)pipe_ctx->global_sync.dcn4x.vupdate_offset_pixels,
2439 (unsigned int)pipe_ctx->global_sync.dcn4x.vupdate_vupdate_width_pixels,
2440 (unsigned int)pipe_ctx->global_sync.dcn4x.pstate_keepout_start_lines);
2441
2442 pipe_ctx->stream_res.tg->funcs->set_vtg_params(
2443 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing, false);
2444
2445 if (pipe_ctx->prev_odm_pipe == NULL)
2446 hws->funcs.blank_pixel_data(dc, pipe_ctx, blank);
2447
2448 if (hws->funcs.setup_vupdate_interrupt)
2449 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
2450 }
2451
2452 if (pipe_ctx->plane_res.hubp->funcs->hubp_setup2)
2453 pipe_ctx->plane_res.hubp->funcs->hubp_setup2(
2454 pipe_ctx->plane_res.hubp,
2455 &pipe_ctx->hubp_regs,
2456 &pipe_ctx->global_sync,
2457 &pipe_ctx->stream->timing);
2458 }
2459
2460 return true;
2461 }
2462
dcn401_detect_pipe_changes(struct dc_state * old_state,struct dc_state * new_state,struct pipe_ctx * old_pipe,struct pipe_ctx * new_pipe)2463 void dcn401_detect_pipe_changes(struct dc_state *old_state,
2464 struct dc_state *new_state,
2465 struct pipe_ctx *old_pipe,
2466 struct pipe_ctx *new_pipe)
2467 {
2468 bool old_is_phantom = dc_state_get_pipe_subvp_type(old_state, old_pipe) == SUBVP_PHANTOM;
2469 bool new_is_phantom = dc_state_get_pipe_subvp_type(new_state, new_pipe) == SUBVP_PHANTOM;
2470
2471 unsigned int old_pipe_vready_offset_pixels = old_pipe->global_sync.dcn4x.vready_offset_pixels;
2472 unsigned int new_pipe_vready_offset_pixels = new_pipe->global_sync.dcn4x.vready_offset_pixels;
2473 unsigned int old_pipe_vstartup_lines = old_pipe->global_sync.dcn4x.vstartup_lines;
2474 unsigned int new_pipe_vstartup_lines = new_pipe->global_sync.dcn4x.vstartup_lines;
2475 unsigned int old_pipe_vupdate_offset_pixels = old_pipe->global_sync.dcn4x.vupdate_offset_pixels;
2476 unsigned int new_pipe_vupdate_offset_pixels = new_pipe->global_sync.dcn4x.vupdate_offset_pixels;
2477 unsigned int old_pipe_vupdate_width_pixels = old_pipe->global_sync.dcn4x.vupdate_vupdate_width_pixels;
2478 unsigned int new_pipe_vupdate_width_pixels = new_pipe->global_sync.dcn4x.vupdate_vupdate_width_pixels;
2479
2480 new_pipe->update_flags.raw = 0;
2481
2482 /* If non-phantom pipe is being transitioned to a phantom pipe,
2483 * set disable and return immediately. This is because the pipe
2484 * that was previously in use must be fully disabled before we
2485 * can "enable" it as a phantom pipe (since the OTG will certainly
2486 * be different). The post_unlock sequence will set the correct
2487 * update flags to enable the phantom pipe.
2488 */
2489 if (old_pipe->plane_state && !old_is_phantom &&
2490 new_pipe->plane_state && new_is_phantom) {
2491 new_pipe->update_flags.bits.disable = 1;
2492 return;
2493 }
2494
2495 if (resource_is_pipe_type(new_pipe, OTG_MASTER) &&
2496 resource_is_odm_topology_changed(new_pipe, old_pipe))
2497 /* Detect odm changes */
2498 new_pipe->update_flags.bits.odm = 1;
2499
2500 /* Exit on unchanged, unused pipe */
2501 if (!old_pipe->plane_state && !new_pipe->plane_state)
2502 return;
2503 /* Detect pipe enable/disable */
2504 if (!old_pipe->plane_state && new_pipe->plane_state) {
2505 new_pipe->update_flags.bits.enable = 1;
2506 new_pipe->update_flags.bits.mpcc = 1;
2507 new_pipe->update_flags.bits.dppclk = 1;
2508 new_pipe->update_flags.bits.hubp_interdependent = 1;
2509 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
2510 new_pipe->update_flags.bits.unbounded_req = 1;
2511 new_pipe->update_flags.bits.gamut_remap = 1;
2512 new_pipe->update_flags.bits.scaler = 1;
2513 new_pipe->update_flags.bits.viewport = 1;
2514 new_pipe->update_flags.bits.det_size = 1;
2515 if (new_pipe->stream->test_pattern.type != DP_TEST_PATTERN_VIDEO_MODE &&
2516 new_pipe->stream_res.test_pattern_params.width != 0 &&
2517 new_pipe->stream_res.test_pattern_params.height != 0)
2518 new_pipe->update_flags.bits.test_pattern_changed = 1;
2519 if (!new_pipe->top_pipe && !new_pipe->prev_odm_pipe) {
2520 new_pipe->update_flags.bits.odm = 1;
2521 new_pipe->update_flags.bits.global_sync = 1;
2522 }
2523 return;
2524 }
2525
2526 /* For SubVP we need to unconditionally enable because any phantom pipes are
2527 * always removed then newly added for every full updates whenever SubVP is in use.
2528 * The remove-add sequence of the phantom pipe always results in the pipe
2529 * being blanked in enable_stream_timing (DPG).
2530 */
2531 if (new_pipe->stream && dc_state_get_pipe_subvp_type(new_state, new_pipe) == SUBVP_PHANTOM)
2532 new_pipe->update_flags.bits.enable = 1;
2533
2534 /* Phantom pipes are effectively disabled, if the pipe was previously phantom
2535 * we have to enable
2536 */
2537 if (old_pipe->plane_state && old_is_phantom &&
2538 new_pipe->plane_state && !new_is_phantom)
2539 new_pipe->update_flags.bits.enable = 1;
2540
2541 if (old_pipe->plane_state && !new_pipe->plane_state) {
2542 new_pipe->update_flags.bits.disable = 1;
2543 return;
2544 }
2545
2546 /* Detect plane change */
2547 if (old_pipe->plane_state != new_pipe->plane_state)
2548 new_pipe->update_flags.bits.plane_changed = true;
2549
2550 /* Detect top pipe only changes */
2551 if (resource_is_pipe_type(new_pipe, OTG_MASTER)) {
2552 /* Detect global sync changes */
2553 if ((old_pipe_vready_offset_pixels != new_pipe_vready_offset_pixels)
2554 || (old_pipe_vstartup_lines != new_pipe_vstartup_lines)
2555 || (old_pipe_vupdate_offset_pixels != new_pipe_vupdate_offset_pixels)
2556 || (old_pipe_vupdate_width_pixels != new_pipe_vupdate_width_pixels))
2557 new_pipe->update_flags.bits.global_sync = 1;
2558 }
2559
2560 if (old_pipe->det_buffer_size_kb != new_pipe->det_buffer_size_kb)
2561 new_pipe->update_flags.bits.det_size = 1;
2562
2563 /*
2564 * Detect opp / tg change, only set on change, not on enable
2565 * Assume mpcc inst = pipe index, if not this code needs to be updated
2566 * since mpcc is what is affected by these. In fact all of our sequence
2567 * makes this assumption at the moment with how hubp reset is matched to
2568 * same index mpcc reset.
2569 */
2570 if (old_pipe->stream_res.opp != new_pipe->stream_res.opp)
2571 new_pipe->update_flags.bits.opp_changed = 1;
2572 if (old_pipe->stream_res.tg != new_pipe->stream_res.tg)
2573 new_pipe->update_flags.bits.tg_changed = 1;
2574
2575 /*
2576 * Detect mpcc blending changes, only dpp inst and opp matter here,
2577 * mpccs getting removed/inserted update connected ones during their own
2578 * programming
2579 */
2580 if (old_pipe->plane_res.dpp != new_pipe->plane_res.dpp
2581 || old_pipe->stream_res.opp != new_pipe->stream_res.opp)
2582 new_pipe->update_flags.bits.mpcc = 1;
2583
2584 /* Detect dppclk change */
2585 if (old_pipe->plane_res.bw.dppclk_khz != new_pipe->plane_res.bw.dppclk_khz)
2586 new_pipe->update_flags.bits.dppclk = 1;
2587
2588 /* Check for scl update */
2589 if (memcmp(&old_pipe->plane_res.scl_data, &new_pipe->plane_res.scl_data, sizeof(struct scaler_data)))
2590 new_pipe->update_flags.bits.scaler = 1;
2591 /* Check for vp update */
2592 if (memcmp(&old_pipe->plane_res.scl_data.viewport, &new_pipe->plane_res.scl_data.viewport, sizeof(struct rect))
2593 || memcmp(&old_pipe->plane_res.scl_data.viewport_c,
2594 &new_pipe->plane_res.scl_data.viewport_c, sizeof(struct rect)))
2595 new_pipe->update_flags.bits.viewport = 1;
2596
2597 /* Detect dlg/ttu/rq updates */
2598 {
2599 struct dml2_display_dlg_regs old_dlg_regs = old_pipe->hubp_regs.dlg_regs;
2600 struct dml2_display_ttu_regs old_ttu_regs = old_pipe->hubp_regs.ttu_regs;
2601 struct dml2_display_rq_regs old_rq_regs = old_pipe->hubp_regs.rq_regs;
2602 struct dml2_display_dlg_regs *new_dlg_regs = &new_pipe->hubp_regs.dlg_regs;
2603 struct dml2_display_ttu_regs *new_ttu_regs = &new_pipe->hubp_regs.ttu_regs;
2604 struct dml2_display_rq_regs *new_rq_regs = &new_pipe->hubp_regs.rq_regs;
2605
2606 /* Detect pipe interdependent updates */
2607 if ((old_dlg_regs.dst_y_prefetch != new_dlg_regs->dst_y_prefetch)
2608 || (old_dlg_regs.vratio_prefetch != new_dlg_regs->vratio_prefetch)
2609 || (old_dlg_regs.vratio_prefetch_c != new_dlg_regs->vratio_prefetch_c)
2610 || (old_dlg_regs.dst_y_per_vm_vblank != new_dlg_regs->dst_y_per_vm_vblank)
2611 || (old_dlg_regs.dst_y_per_row_vblank != new_dlg_regs->dst_y_per_row_vblank)
2612 || (old_dlg_regs.dst_y_per_vm_flip != new_dlg_regs->dst_y_per_vm_flip)
2613 || (old_dlg_regs.dst_y_per_row_flip != new_dlg_regs->dst_y_per_row_flip)
2614 || (old_dlg_regs.refcyc_per_meta_chunk_vblank_l != new_dlg_regs->refcyc_per_meta_chunk_vblank_l)
2615 || (old_dlg_regs.refcyc_per_meta_chunk_vblank_c != new_dlg_regs->refcyc_per_meta_chunk_vblank_c)
2616 || (old_dlg_regs.refcyc_per_meta_chunk_flip_l != new_dlg_regs->refcyc_per_meta_chunk_flip_l)
2617 || (old_dlg_regs.refcyc_per_line_delivery_pre_l != new_dlg_regs->refcyc_per_line_delivery_pre_l)
2618 || (old_dlg_regs.refcyc_per_line_delivery_pre_c != new_dlg_regs->refcyc_per_line_delivery_pre_c)
2619 || (old_ttu_regs.refcyc_per_req_delivery_pre_l != new_ttu_regs->refcyc_per_req_delivery_pre_l)
2620 || (old_ttu_regs.refcyc_per_req_delivery_pre_c != new_ttu_regs->refcyc_per_req_delivery_pre_c)
2621 || (old_ttu_regs.refcyc_per_req_delivery_pre_cur0 !=
2622 new_ttu_regs->refcyc_per_req_delivery_pre_cur0)
2623 || (old_ttu_regs.min_ttu_vblank != new_ttu_regs->min_ttu_vblank)
2624 || (old_ttu_regs.qos_level_flip != new_ttu_regs->qos_level_flip)) {
2625 old_dlg_regs.dst_y_prefetch = new_dlg_regs->dst_y_prefetch;
2626 old_dlg_regs.vratio_prefetch = new_dlg_regs->vratio_prefetch;
2627 old_dlg_regs.vratio_prefetch_c = new_dlg_regs->vratio_prefetch_c;
2628 old_dlg_regs.dst_y_per_vm_vblank = new_dlg_regs->dst_y_per_vm_vblank;
2629 old_dlg_regs.dst_y_per_row_vblank = new_dlg_regs->dst_y_per_row_vblank;
2630 old_dlg_regs.dst_y_per_vm_flip = new_dlg_regs->dst_y_per_vm_flip;
2631 old_dlg_regs.dst_y_per_row_flip = new_dlg_regs->dst_y_per_row_flip;
2632 old_dlg_regs.refcyc_per_meta_chunk_vblank_l = new_dlg_regs->refcyc_per_meta_chunk_vblank_l;
2633 old_dlg_regs.refcyc_per_meta_chunk_vblank_c = new_dlg_regs->refcyc_per_meta_chunk_vblank_c;
2634 old_dlg_regs.refcyc_per_meta_chunk_flip_l = new_dlg_regs->refcyc_per_meta_chunk_flip_l;
2635 old_dlg_regs.refcyc_per_line_delivery_pre_l = new_dlg_regs->refcyc_per_line_delivery_pre_l;
2636 old_dlg_regs.refcyc_per_line_delivery_pre_c = new_dlg_regs->refcyc_per_line_delivery_pre_c;
2637 old_ttu_regs.refcyc_per_req_delivery_pre_l = new_ttu_regs->refcyc_per_req_delivery_pre_l;
2638 old_ttu_regs.refcyc_per_req_delivery_pre_c = new_ttu_regs->refcyc_per_req_delivery_pre_c;
2639 old_ttu_regs.refcyc_per_req_delivery_pre_cur0 = new_ttu_regs->refcyc_per_req_delivery_pre_cur0;
2640 old_ttu_regs.min_ttu_vblank = new_ttu_regs->min_ttu_vblank;
2641 old_ttu_regs.qos_level_flip = new_ttu_regs->qos_level_flip;
2642 new_pipe->update_flags.bits.hubp_interdependent = 1;
2643 }
2644 /* Detect any other updates to ttu/rq/dlg */
2645 if (memcmp(&old_dlg_regs, new_dlg_regs, sizeof(old_dlg_regs)) ||
2646 memcmp(&old_ttu_regs, new_ttu_regs, sizeof(old_ttu_regs)) ||
2647 memcmp(&old_rq_regs, new_rq_regs, sizeof(old_rq_regs)))
2648 new_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
2649 }
2650
2651 if (old_pipe->unbounded_req != new_pipe->unbounded_req)
2652 new_pipe->update_flags.bits.unbounded_req = 1;
2653
2654 if (memcmp(&old_pipe->stream_res.test_pattern_params,
2655 &new_pipe->stream_res.test_pattern_params, sizeof(struct test_pattern_params))) {
2656 new_pipe->update_flags.bits.test_pattern_changed = 1;
2657 }
2658 }
2659