2 * Copyright 2016 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "dm_services.h"
28 #include "dm_helpers.h"
29 #include "core_types.h"
32 #include "dce/dce_hwseq.h"
33 #include "dcn30/dcn30_cm_common.h"
34 #include "reg_helper.h"
38 #include "timing_generator.h"
43 #include "dc_dmub_srv.h"
44 #include "link_hwss.h"
45 #include "dpcd_defs.h"
46 #include "dcn32_hwseq.h"
49 #include "dcn20/dcn20_optc.h"
50 #include "dc_link_dp.h"
52 #define DC_LOGGER_INIT(logger)
63 #define FN(reg_name, field_name) \
64 hws->shifts->field_name, hws->masks->field_name
66 void dcn32_dsc_pg_control(
67 struct dce_hwseq *hws,
68 unsigned int dsc_inst,
71 uint32_t power_gate = power_on ? 0 : 1;
72 uint32_t pwr_status = power_on ? 0 : 2;
73 uint32_t org_ip_request_cntl = 0;
75 if (hws->ctx->dc->debug.disable_dsc_power_gate)
78 REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
79 if (org_ip_request_cntl == 0)
80 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
84 REG_UPDATE(DOMAIN16_PG_CONFIG,
85 DOMAIN_POWER_GATE, power_gate);
87 REG_WAIT(DOMAIN16_PG_STATUS,
88 DOMAIN_PGFSM_PWR_STATUS, pwr_status,
92 REG_UPDATE(DOMAIN17_PG_CONFIG,
93 DOMAIN_POWER_GATE, power_gate);
95 REG_WAIT(DOMAIN17_PG_STATUS,
96 DOMAIN_PGFSM_PWR_STATUS, pwr_status,
100 REG_UPDATE(DOMAIN18_PG_CONFIG,
101 DOMAIN_POWER_GATE, power_gate);
103 REG_WAIT(DOMAIN18_PG_STATUS,
104 DOMAIN_PGFSM_PWR_STATUS, pwr_status,
108 REG_UPDATE(DOMAIN19_PG_CONFIG,
109 DOMAIN_POWER_GATE, power_gate);
111 REG_WAIT(DOMAIN19_PG_STATUS,
112 DOMAIN_PGFSM_PWR_STATUS, pwr_status,
120 if (org_ip_request_cntl == 0)
121 REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
125 void dcn32_enable_power_gating_plane(
126 struct dce_hwseq *hws,
129 bool force_on = true; /* disable power gating */
135 REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
136 REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
137 REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
138 REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
141 REG_UPDATE(DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
142 REG_UPDATE(DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
143 REG_UPDATE(DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
144 REG_UPDATE(DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
147 void dcn32_hubp_pg_control(struct dce_hwseq *hws, unsigned int hubp_inst, bool power_on)
149 uint32_t power_gate = power_on ? 0 : 1;
150 uint32_t pwr_status = power_on ? 0 : 2;
152 if (hws->ctx->dc->debug.disable_hubp_power_gate)
155 if (REG(DOMAIN0_PG_CONFIG) == 0)
160 REG_SET(DOMAIN0_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
161 REG_WAIT(DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
164 REG_SET(DOMAIN1_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
165 REG_WAIT(DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
168 REG_SET(DOMAIN2_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
169 REG_WAIT(DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
172 REG_SET(DOMAIN3_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
173 REG_WAIT(DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
181 static bool dcn32_check_no_memory_request_for_cab(struct dc *dc)
185 /* First, check no-memory-request case */
186 for (i = 0; i < dc->current_state->stream_count; i++) {
187 if (dc->current_state->stream_status[i].plane_count)
188 /* Fail eligibility on a visible stream */
192 if (i == dc->current_state->stream_count)
198 /* This function takes in the start address and surface size to be cached in CAB
199 * and calculates the total number of cache lines required to store the surface.
200 * The number of cache lines used for each surface is calculated independently of
201 * one another. For example, if there is a primary surface(1), meta surface(2), and
202 * cursor(3), this function should be called 3 times to calculate the number of cache
203 * lines used for each of those surfaces.
205 static uint32_t dcn32_cache_lines_for_surface(struct dc *dc, uint32_t surface_size, uint64_t start_address)
207 uint32_t lines_used = 1;
208 uint32_t num_cached_bytes = 0;
209 uint32_t remaining_size = 0;
210 uint32_t cache_line_size = dc->caps.cache_line_size;
212 /* 1. Calculate surface size minus the number of bytes stored
213 * in the first cache line (all bytes in first cache line might
214 * not be fully used).
216 num_cached_bytes = cache_line_size - (start_address % cache_line_size);
217 remaining_size = surface_size - num_cached_bytes;
219 /* 2. Calculate number of cache lines that will be fully used with
220 * the remaining number of bytes to be stored.
222 lines_used += (remaining_size / cache_line_size);
224 /* 3. Check if we need an extra line due to the remaining size not being
225 * a multiple of CACHE_LINE_SIZE.
227 if (remaining_size % cache_line_size > 0)
233 /* This function loops through every surface that needs to be cached in CAB for SS,
234 * and calculates the total number of ways required to store all surfaces (primary,
237 static uint32_t dcn32_calculate_cab_allocation(struct dc *dc, struct dc_state *ctx)
240 struct dc_stream_state *stream = NULL;
241 struct dc_plane_state *plane = NULL;
242 uint32_t surface_size = 0;
243 uint32_t cursor_size = 0;
244 uint32_t cache_lines_used = 0;
245 uint32_t total_lines = 0;
246 uint32_t lines_per_way = 0;
247 uint32_t num_ways = 0;
249 for (i = 0; i < ctx->stream_count; i++) {
250 stream = ctx->streams[i];
252 // Don't include PSR surface in the total surface size for CAB allocation
253 if (stream->link->psr_settings.psr_version != DC_PSR_VERSION_UNSUPPORTED)
256 if (ctx->stream_status[i].plane_count == 0)
259 // For each stream, loop through each plane to calculate the number of cache
260 // lines required to store the surface in CAB
261 for (j = 0; j < ctx->stream_status[i].plane_count; j++) {
262 plane = ctx->stream_status[i].plane_states[j];
264 // Calculate total surface size
265 surface_size = plane->plane_size.surface_pitch *
266 plane->plane_size.surface_size.height *
267 (plane->format >= SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616 ? 8 : 4);
269 // Convert surface size + starting address to number of cache lines required
270 // (alignment accounted for)
271 cache_lines_used += dcn32_cache_lines_for_surface(dc, surface_size,
272 plane->address.grph.addr.quad_part);
274 if (plane->address.grph.meta_addr.quad_part) {
276 cache_lines_used += dcn32_cache_lines_for_surface(dc, surface_size,
277 plane->address.grph.meta_addr.quad_part);
281 // Include cursor size for CAB allocation
282 if (stream->cursor_position.enable && plane->address.grph.cursor_cache_addr.quad_part) {
283 cursor_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size;
284 switch (stream->cursor_attributes.color_format) {
285 case CURSOR_MODE_MONO:
288 case CURSOR_MODE_COLOR_1BIT_AND:
289 case CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA:
290 case CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA:
294 case CURSOR_MODE_COLOR_64BIT_FP_PRE_MULTIPLIED:
295 case CURSOR_MODE_COLOR_64BIT_FP_UN_PRE_MULTIPLIED:
299 cache_lines_used += dcn32_cache_lines_for_surface(dc, surface_size,
300 plane->address.grph.cursor_cache_addr.quad_part);
304 // Convert number of cache lines required to number of ways
305 total_lines = dc->caps.max_cab_allocation_bytes / dc->caps.cache_line_size;
306 lines_per_way = total_lines / dc->caps.cache_num_ways;
307 num_ways = cache_lines_used / lines_per_way;
309 if (cache_lines_used % lines_per_way > 0)
315 bool dcn32_apply_idle_power_optimizations(struct dc *dc, bool enable)
317 union dmub_rb_cmd cmd;
320 if (!dc->ctx->dmub_srv)
324 if (dc->current_state) {
326 /* 1. Check no memory request case for CAB.
327 * If no memory request case, send CAB_ACTION NO_DF_REQ DMUB message
329 if (dcn32_check_no_memory_request_for_cab(dc)) {
330 /* Enable no-memory-requests case */
331 memset(&cmd, 0, sizeof(cmd));
332 cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
333 cmd.cab.header.sub_type = DMUB_CMD__CAB_NO_DCN_REQ;
334 cmd.cab.header.payload_bytes = sizeof(cmd.cab) - sizeof(cmd.cab.header);
336 dc_dmub_srv_cmd_queue(dc->ctx->dmub_srv, &cmd);
337 dc_dmub_srv_cmd_execute(dc->ctx->dmub_srv);
342 /* 2. Check if all surfaces can fit in CAB.
343 * If surfaces can fit into CAB, send CAB_ACTION_ALLOW DMUB message
344 * and configure HUBP's to fetch from MALL
346 ways = dcn32_calculate_cab_allocation(dc, dc->current_state);
347 if (ways <= dc->caps.cache_num_ways) {
348 memset(&cmd, 0, sizeof(cmd));
349 cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
350 cmd.cab.header.sub_type = DMUB_CMD__CAB_DCN_SS_FIT_IN_CAB;
351 cmd.cab.header.payload_bytes = sizeof(cmd.cab) - sizeof(cmd.cab.header);
352 cmd.cab.cab_alloc_ways = ways;
354 dc_dmub_srv_cmd_queue(dc->ctx->dmub_srv, &cmd);
355 dc_dmub_srv_cmd_execute(dc->ctx->dmub_srv);
365 memset(&cmd, 0, sizeof(cmd));
366 cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
367 cmd.cab.header.sub_type = DMUB_CMD__CAB_NO_IDLE_OPTIMIZATION;
368 cmd.cab.header.payload_bytes =
369 sizeof(cmd.cab) - sizeof(cmd.cab.header);
371 dc_dmub_srv_cmd_queue(dc->ctx->dmub_srv, &cmd);
372 dc_dmub_srv_cmd_execute(dc->ctx->dmub_srv);
373 dc_dmub_srv_wait_idle(dc->ctx->dmub_srv);
378 /* Send DMCUB message with SubVP pipe info
379 * - For each pipe in context, populate payload with required SubVP information
380 * if the pipe is using SubVP for MCLK switch
381 * - This function must be called while the DMUB HW lock is acquired by driver
383 void dcn32_commit_subvp_config(struct dc *dc, struct dc_state *context)
387 bool enable_subvp = false;
389 if (!dc->ctx || !dc->ctx->dmub_srv)
392 for (i = 0; i < dc->res_pool->pipe_count; i++) {
393 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
395 if (pipe_ctx->stream && pipe_ctx->stream->mall_stream_config.paired_stream &&
396 pipe_ctx->stream->mall_stream_config.type == SUBVP_MAIN) {
397 // There is at least 1 SubVP pipe, so enable SubVP
402 dc_dmub_setup_subvp_dmub_command(dc, context, enable_subvp);
406 static bool dcn32_set_mpc_shaper_3dlut(
407 struct pipe_ctx *pipe_ctx, const struct dc_stream_state *stream)
409 struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
410 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
411 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
414 const struct pwl_params *shaper_lut = NULL;
415 //get the shaper lut params
416 if (stream->func_shaper) {
417 if (stream->func_shaper->type == TF_TYPE_HWPWL)
418 shaper_lut = &stream->func_shaper->pwl;
419 else if (stream->func_shaper->type == TF_TYPE_DISTRIBUTED_POINTS) {
420 cm_helper_translate_curve_to_hw_format(
422 &dpp_base->shaper_params, true);
423 shaper_lut = &dpp_base->shaper_params;
427 if (stream->lut3d_func &&
428 stream->lut3d_func->state.bits.initialized == 1) {
430 result = mpc->funcs->program_3dlut(mpc,
431 &stream->lut3d_func->lut_3d,
434 result = mpc->funcs->program_shaper(mpc,
441 bool dcn32_set_output_transfer_func(struct dc *dc,
442 struct pipe_ctx *pipe_ctx,
443 const struct dc_stream_state *stream)
445 int mpcc_id = pipe_ctx->plane_res.hubp->inst;
446 struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
447 struct pwl_params *params = NULL;
450 /* program OGAM or 3DLUT only for the top pipe*/
451 if (pipe_ctx->top_pipe == NULL) {
452 /*program shaper and 3dlut in MPC*/
453 ret = dcn32_set_mpc_shaper_3dlut(pipe_ctx, stream);
454 if (ret == false && mpc->funcs->set_output_gamma && stream->out_transfer_func) {
455 if (stream->out_transfer_func->type == TF_TYPE_HWPWL)
456 params = &stream->out_transfer_func->pwl;
457 else if (pipe_ctx->stream->out_transfer_func->type ==
458 TF_TYPE_DISTRIBUTED_POINTS &&
459 cm3_helper_translate_curve_to_hw_format(
460 stream->out_transfer_func,
461 &mpc->blender_params, false))
462 params = &mpc->blender_params;
463 /* there are no ROM LUTs in OUTGAM */
464 if (stream->out_transfer_func->type == TF_TYPE_PREDEFINED)
469 mpc->funcs->set_output_gamma(mpc, mpcc_id, params);
473 /* Program P-State force value according to if pipe is using SubVP or not:
474 * 1. Reset P-State force on all pipes first
475 * 2. For each main pipe, force P-State disallow (P-State allow moderated by DMUB)
477 void dcn32_subvp_update_force_pstate(struct dc *dc, struct dc_state *context)
481 /* Unforce p-state for each pipe
483 for (i = 0; i < dc->res_pool->pipe_count; i++) {
484 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
485 struct hubp *hubp = pipe->plane_res.hubp;
487 if (hubp && hubp->funcs->hubp_update_force_pstate_disallow)
488 hubp->funcs->hubp_update_force_pstate_disallow(hubp, false);
489 if (pipe->stream && pipe->stream->mall_stream_config.type == SUBVP_MAIN)
496 /* Loop through each pipe -- for each subvp main pipe force p-state allow equal to false.
498 for (i = 0; i < dc->res_pool->pipe_count; i++) {
499 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
501 if (pipe->stream && pipe->plane_state && pipe->stream->mall_stream_config.type == SUBVP_MAIN) {
502 struct hubp *hubp = pipe->plane_res.hubp;
504 if (hubp && hubp->funcs->hubp_update_force_pstate_disallow)
505 hubp->funcs->hubp_update_force_pstate_disallow(hubp, true);
510 /* Update MALL_SEL register based on if pipe / plane
511 * is a phantom pipe, main pipe, and if using MALL
514 void dcn32_update_mall_sel(struct dc *dc, struct dc_state *context)
517 unsigned int num_ways = dcn32_calculate_cab_allocation(dc, context);
519 for (i = 0; i < dc->res_pool->pipe_count; i++) {
520 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
521 struct hubp *hubp = pipe->plane_res.hubp;
523 if (pipe->stream && pipe->plane_state && hubp && hubp->funcs->hubp_update_mall_sel) {
524 if (pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
525 hubp->funcs->hubp_update_mall_sel(hubp, 1);
527 hubp->funcs->hubp_update_mall_sel(hubp,
528 num_ways <= dc->caps.cache_num_ways &&
529 pipe->stream->link->psr_settings.psr_version == DC_PSR_VERSION_UNSUPPORTED ? 2 : 0);
535 /* Program the sub-viewport pipe configuration after the main / phantom pipes
536 * have been programmed in hardware.
537 * 1. Update force P-State for all the main pipes (disallow P-state)
538 * 2. Update MALL_SEL register
539 * 3. Program FORCE_ONE_ROW_FOR_FRAME for main subvp pipes
541 void dcn32_program_mall_pipe_config(struct dc *dc, struct dc_state *context)
544 struct dce_hwseq *hws = dc->hwseq;
545 // Update force P-state for each pipe accordingly
546 if (hws && hws->funcs.subvp_update_force_pstate)
547 hws->funcs.subvp_update_force_pstate(dc, context);
549 // Update MALL_SEL register for each pipe
550 if (hws && hws->funcs.update_mall_sel)
551 hws->funcs.update_mall_sel(dc, context);
553 // Program FORCE_ONE_ROW_FOR_FRAME and CURSOR_REQ_MODE for main subvp pipes
554 for (i = 0; i < dc->res_pool->pipe_count; i++) {
555 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
556 struct hubp *hubp = pipe->plane_res.hubp;
558 if (pipe->stream && hubp && hubp->funcs->hubp_prepare_subvp_buffering) {
559 /* TODO - remove setting CURSOR_REQ_MODE to 0 for legacy cases
560 * - need to investigate single pipe MPO + SubVP case to
561 * see if CURSOR_REQ_MODE will be back to 1 for SubVP
562 * when it should be 0 for MPO
564 if (pipe->stream->mall_stream_config.type == SUBVP_MAIN) {
565 hubp->funcs->hubp_prepare_subvp_buffering(hubp, true);
571 void dcn32_init_hw(struct dc *dc)
573 struct abm **abms = dc->res_pool->multiple_abms;
574 struct dce_hwseq *hws = dc->hwseq;
575 struct dc_bios *dcb = dc->ctx->dc_bios;
576 struct resource_pool *res_pool = dc->res_pool;
579 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
581 dc->debug.disable_idle_power_optimizations = true;
582 if (dc->clk_mgr && dc->clk_mgr->funcs->init_clocks)
583 dc->clk_mgr->funcs->init_clocks(dc->clk_mgr);
585 // Initialize the dccg
586 if (res_pool->dccg->funcs->dccg_init)
587 res_pool->dccg->funcs->dccg_init(res_pool->dccg);
589 if (!dcb->funcs->is_accelerated_mode(dcb)) {
590 hws->funcs.bios_golden_init(dc);
591 hws->funcs.disable_vga(dc->hwseq);
594 // Set default OPTC memory power states
595 if (dc->debug.enable_mem_low_power.bits.optc) {
596 // Shutdown when unassigned and light sleep in VBLANK
597 REG_SET_2(ODM_MEM_PWR_CTRL3, 0, ODM_MEM_UNASSIGNED_PWR_MODE, 3, ODM_MEM_VBLANK_PWR_MODE, 1);
600 if (dc->debug.enable_mem_low_power.bits.vga) {
601 // Power down VGA memory
602 REG_UPDATE(MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, 1);
605 if (dc->ctx->dc_bios->fw_info_valid) {
606 res_pool->ref_clocks.xtalin_clock_inKhz =
607 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency;
609 if (res_pool->dccg && res_pool->hubbub) {
610 (res_pool->dccg->funcs->get_dccg_ref_freq)(res_pool->dccg,
611 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency,
612 &res_pool->ref_clocks.dccg_ref_clock_inKhz);
614 (res_pool->hubbub->funcs->get_dchub_ref_freq)(res_pool->hubbub,
615 res_pool->ref_clocks.dccg_ref_clock_inKhz,
616 &res_pool->ref_clocks.dchub_ref_clock_inKhz);
618 // Not all ASICs have DCCG sw component
619 res_pool->ref_clocks.dccg_ref_clock_inKhz =
620 res_pool->ref_clocks.xtalin_clock_inKhz;
621 res_pool->ref_clocks.dchub_ref_clock_inKhz =
622 res_pool->ref_clocks.xtalin_clock_inKhz;
625 ASSERT_CRITICAL(false);
627 for (i = 0; i < dc->link_count; i++) {
628 /* Power up AND update implementation according to the
629 * required signal (which may be different from the
630 * default signal on connector).
632 struct dc_link *link = dc->links[i];
634 link->link_enc->funcs->hw_init(link->link_enc);
636 /* Check for enabled DIG to identify enabled display */
637 if (link->link_enc->funcs->is_dig_enabled &&
638 link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
639 link->link_status.link_active = true;
640 if (link->link_enc->funcs->fec_is_active &&
641 link->link_enc->funcs->fec_is_active(link->link_enc))
642 link->fec_state = dc_link_fec_enabled;
646 /* Power gate DSCs */
647 for (i = 0; i < res_pool->res_cap->num_dsc; i++)
648 if (hws->funcs.dsc_pg_control != NULL)
649 hws->funcs.dsc_pg_control(hws, res_pool->dscs[i]->inst, false);
651 /* we want to turn off all dp displays before doing detection */
652 dc_link_blank_all_dp_displays(dc);
654 /* If taking control over from VBIOS, we may want to optimize our first
655 * mode set, so we need to skip powering down pipes until we know which
656 * pipes we want to use.
657 * Otherwise, if taking control is not possible, we need to power
660 if (dcb->funcs->is_accelerated_mode(dcb) || !dc->config.seamless_boot_edp_requested) {
661 hws->funcs.init_pipes(dc, dc->current_state);
662 if (dc->res_pool->hubbub->funcs->allow_self_refresh_control)
663 dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub,
664 !dc->res_pool->hubbub->ctx->dc->debug.disable_stutter);
667 /* In headless boot cases, DIG may be turned
668 * on which causes HW/SW discrepancies.
669 * To avoid this, power down hardware on boot
670 * if DIG is turned on and seamless boot not enabled
672 if (!dc->config.seamless_boot_edp_requested) {
673 struct dc_link *edp_links[MAX_NUM_EDP];
674 struct dc_link *edp_link;
676 get_edp_links(dc, edp_links, &edp_num);
678 for (i = 0; i < edp_num; i++) {
679 edp_link = edp_links[i];
680 if (edp_link->link_enc->funcs->is_dig_enabled &&
681 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
682 dc->hwss.edp_backlight_control &&
683 dc->hwss.power_down &&
684 dc->hwss.edp_power_control) {
685 dc->hwss.edp_backlight_control(edp_link, false);
686 dc->hwss.power_down(dc);
687 dc->hwss.edp_power_control(edp_link, false);
691 for (i = 0; i < dc->link_count; i++) {
692 struct dc_link *link = dc->links[i];
694 if (link->link_enc->funcs->is_dig_enabled &&
695 link->link_enc->funcs->is_dig_enabled(link->link_enc) &&
696 dc->hwss.power_down) {
697 dc->hwss.power_down(dc);
705 for (i = 0; i < res_pool->audio_count; i++) {
706 struct audio *audio = res_pool->audios[i];
708 audio->funcs->hw_init(audio);
711 for (i = 0; i < dc->link_count; i++) {
712 struct dc_link *link = dc->links[i];
714 if (link->panel_cntl)
715 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
718 for (i = 0; i < dc->res_pool->pipe_count; i++) {
719 if (abms[i] != NULL && abms[i]->funcs != NULL)
720 abms[i]->funcs->abm_init(abms[i], backlight);
723 /* power AFMT HDMI memory TODO: may move to dis/en output save power*/
724 REG_WRITE(DIO_MEM_PWR_CTRL, 0);
726 if (!dc->debug.disable_clock_gate) {
727 /* enable all DCN clock gating */
728 REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
730 REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
732 REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
734 if (hws->funcs.enable_power_gating_plane)
735 hws->funcs.enable_power_gating_plane(dc->hwseq, true);
737 if (!dcb->funcs->is_accelerated_mode(dcb) && dc->res_pool->hubbub->funcs->init_watermarks)
738 dc->res_pool->hubbub->funcs->init_watermarks(dc->res_pool->hubbub);
740 if (dc->clk_mgr->funcs->notify_wm_ranges)
741 dc->clk_mgr->funcs->notify_wm_ranges(dc->clk_mgr);
743 if (dc->clk_mgr->funcs->set_hard_max_memclk)
744 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
746 if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
747 dc->res_pool->hubbub->funcs->force_pstate_change_control(
748 dc->res_pool->hubbub, false, false);
750 if (dc->res_pool->hubbub->funcs->init_crb)
751 dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub);
753 // Get DMCUB capabilities
754 if (dc->ctx->dmub_srv) {
755 dc_dmub_srv_query_caps_cmd(dc->ctx->dmub_srv->dmub);
756 dc->caps.dmub_caps.psr = dc->ctx->dmub_srv->dmub->feature_caps.psr;
760 static int calc_mpc_flow_ctrl_cnt(const struct dc_stream_state *stream,
763 bool hblank_halved = optc2_is_two_pixels_per_containter(&stream->timing);
767 hblank_halved = true;
769 flow_ctrl_cnt = stream->timing.h_total - stream->timing.h_addressable -
770 stream->timing.h_border_left -
771 stream->timing.h_border_right;
776 /* ODM combine 4:1 case */
780 return flow_ctrl_cnt;
783 static void update_dsc_on_stream(struct pipe_ctx *pipe_ctx, bool enable)
785 struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
786 struct dc_stream_state *stream = pipe_ctx->stream;
787 struct pipe_ctx *odm_pipe;
791 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
795 struct dsc_config dsc_cfg;
796 struct dsc_optc_config dsc_optc_cfg;
797 enum optc_dsc_mode optc_dsc_mode;
799 /* Enable DSC hw block */
800 dsc_cfg.pic_width = (stream->timing.h_addressable + stream->timing.h_border_left + stream->timing.h_border_right) / opp_cnt;
801 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top + stream->timing.v_border_bottom;
802 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
803 dsc_cfg.color_depth = stream->timing.display_color_depth;
804 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
805 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
806 ASSERT(dsc_cfg.dc_dsc_cfg.num_slices_h % opp_cnt == 0);
807 dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt;
809 dsc->funcs->dsc_set_config(dsc, &dsc_cfg, &dsc_optc_cfg);
810 dsc->funcs->dsc_enable(dsc, pipe_ctx->stream_res.opp->inst);
811 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
812 struct display_stream_compressor *odm_dsc = odm_pipe->stream_res.dsc;
815 odm_dsc->funcs->dsc_set_config(odm_dsc, &dsc_cfg, &dsc_optc_cfg);
816 odm_dsc->funcs->dsc_enable(odm_dsc, odm_pipe->stream_res.opp->inst);
818 dsc_cfg.dc_dsc_cfg.num_slices_h *= opp_cnt;
819 dsc_cfg.pic_width *= opp_cnt;
821 optc_dsc_mode = dsc_optc_cfg.is_pixel_format_444 ? OPTC_DSC_ENABLED_444 : OPTC_DSC_ENABLED_NATIVE_SUBSAMPLED;
823 /* Enable DSC in OPTC */
824 DC_LOG_DSC("Setting optc DSC config for tg instance %d:", pipe_ctx->stream_res.tg->inst);
825 pipe_ctx->stream_res.tg->funcs->set_dsc_config(pipe_ctx->stream_res.tg,
827 dsc_optc_cfg.bytes_per_pixel,
828 dsc_optc_cfg.slice_width);
830 /* disable DSC in OPTC */
831 pipe_ctx->stream_res.tg->funcs->set_dsc_config(
832 pipe_ctx->stream_res.tg,
833 OPTC_DSC_DISABLED, 0, 0);
835 /* disable DSC block */
836 dsc->funcs->dsc_disable(pipe_ctx->stream_res.dsc);
837 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
838 ASSERT(odm_pipe->stream_res.dsc);
839 odm_pipe->stream_res.dsc->funcs->dsc_disable(odm_pipe->stream_res.dsc);
845 * Given any pipe_ctx, return the total ODM combine factor, and optionally return
846 * the OPPids which are used
848 static unsigned int get_odm_config(struct pipe_ctx *pipe_ctx, unsigned int *opp_instances)
850 unsigned int opp_count = 1;
851 struct pipe_ctx *odm_pipe;
853 /* First get to the top pipe */
854 for (odm_pipe = pipe_ctx; odm_pipe->prev_odm_pipe; odm_pipe = odm_pipe->prev_odm_pipe)
857 /* First pipe is always used */
859 opp_instances[0] = odm_pipe->stream_res.opp->inst;
861 /* Find and count odm pipes, if any */
862 for (odm_pipe = odm_pipe->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
864 opp_instances[opp_count] = odm_pipe->stream_res.opp->inst;
871 void dcn32_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
873 struct pipe_ctx *odm_pipe;
875 int opp_inst[MAX_PIPES] = {0};
876 bool rate_control_2x_pclk = (pipe_ctx->stream->timing.flags.INTERLACE || optc2_is_two_pixels_per_containter(&pipe_ctx->stream->timing));
877 struct mpc_dwb_flow_control flow_control;
878 struct mpc *mpc = dc->res_pool->mpc;
881 opp_cnt = get_odm_config(pipe_ctx, opp_inst);
884 pipe_ctx->stream_res.tg->funcs->set_odm_combine(
885 pipe_ctx->stream_res.tg,
887 &pipe_ctx->stream->timing);
889 pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
890 pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
892 rate_control_2x_pclk = rate_control_2x_pclk || opp_cnt > 1;
893 flow_control.flow_ctrl_mode = 0;
894 flow_control.flow_ctrl_cnt0 = 0x80;
895 flow_control.flow_ctrl_cnt1 = calc_mpc_flow_ctrl_cnt(pipe_ctx->stream, opp_cnt);
896 if (mpc->funcs->set_out_rate_control) {
897 for (i = 0; i < opp_cnt; ++i) {
898 mpc->funcs->set_out_rate_control(
901 rate_control_2x_pclk,
906 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
907 odm_pipe->stream_res.opp->funcs->opp_pipe_clock_control(
908 odm_pipe->stream_res.opp,
912 // Don't program pixel clock after link is already enabled
913 /* if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
914 pipe_ctx->clock_source,
915 &pipe_ctx->stream_res.pix_clk_params,
916 &pipe_ctx->pll_settings)) {
920 if (pipe_ctx->stream_res.dsc)
921 update_dsc_on_stream(pipe_ctx, pipe_ctx->stream->timing.flags.DSC);
924 unsigned int dcn32_calculate_dccg_k1_k2_values(struct pipe_ctx *pipe_ctx, unsigned int *k1_div, unsigned int *k2_div)
926 struct dc_stream_state *stream = pipe_ctx->stream;
927 unsigned int odm_combine_factor = 0;
929 odm_combine_factor = get_odm_config(pipe_ctx, NULL);
931 if (is_dp_128b_132b_signal(pipe_ctx)) {
932 *k2_div = PIXEL_RATE_DIV_BY_1;
933 } else if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal) || dc_is_dvi_signal(pipe_ctx->stream->signal)) {
934 *k1_div = PIXEL_RATE_DIV_BY_1;
935 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
936 *k2_div = PIXEL_RATE_DIV_BY_2;
938 *k2_div = PIXEL_RATE_DIV_BY_4;
939 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
940 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
941 *k1_div = PIXEL_RATE_DIV_BY_1;
942 *k2_div = PIXEL_RATE_DIV_BY_2;
943 } else if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) {
944 *k1_div = PIXEL_RATE_DIV_BY_2;
945 *k2_div = PIXEL_RATE_DIV_BY_2;
947 if (odm_combine_factor == 1)
948 *k2_div = PIXEL_RATE_DIV_BY_4;
949 else if (odm_combine_factor == 2)
950 *k2_div = PIXEL_RATE_DIV_BY_2;
954 if ((*k1_div == PIXEL_RATE_DIV_NA) && (*k2_div == PIXEL_RATE_DIV_NA))
957 return odm_combine_factor;