2 * Copyright 2015 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.
25 #include "dm_services.h"
27 #include "dc_bios_types.h"
28 #include "core_types.h"
29 #include "core_status.h"
31 #include "hw_sequencer.h"
32 #include "dm_helpers.h"
33 #include "dce110_hw_sequencer.h"
34 #include "dce110_timing_generator.h"
36 #include "bios/bios_parser_helper.h"
37 #include "timing_generator.h"
38 #include "mem_input.h"
41 #include "transform.h"
42 #include "stream_encoder.h"
43 #include "link_encoder.h"
44 #include "clock_source.h"
47 #include "dce/dce_hwseq.h"
49 /* include DCE11 register header files */
50 #include "dce/dce_11_0_d.h"
51 #include "dce/dce_11_0_sh_mask.h"
52 #include "custom_float.h"
54 struct dce110_hw_seq_reg_offsets
{
58 static const struct dce110_hw_seq_reg_offsets reg_offsets
[] = {
60 .crtc
= (mmCRTC0_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
63 .crtc
= (mmCRTC1_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
66 .crtc
= (mmCRTC2_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
69 .crtc
= (mmCRTCV_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
73 #define HW_REG_BLND(reg, id)\
74 (reg + reg_offsets[id].blnd)
76 #define HW_REG_CRTC(reg, id)\
77 (reg + reg_offsets[id].crtc)
79 #define MAX_WATERMARK 0xFFFF
80 #define SAFE_NBP_MARK 0x7FFF
82 /*******************************************************************************
84 ******************************************************************************/
85 /***************************PIPE_CONTROL***********************************/
86 static void dce110_init_pte(struct dc_context
*ctx
)
90 uint32_t chunk_int
= 0;
91 uint32_t chunk_mul
= 0;
93 addr
= mmUNP_DVMM_PTE_CONTROL
;
94 value
= dm_read_reg(ctx
, addr
);
100 DVMM_USE_SINGLE_PTE
);
106 DVMM_PTE_BUFFER_MODE0
);
112 DVMM_PTE_BUFFER_MODE1
);
114 dm_write_reg(ctx
, addr
, value
);
116 addr
= mmDVMM_PTE_REQ
;
117 value
= dm_read_reg(ctx
, addr
);
119 chunk_int
= get_reg_field_value(
122 HFLIP_PTEREQ_PER_CHUNK_INT
);
124 chunk_mul
= get_reg_field_value(
127 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
129 if (chunk_int
!= 0x4 || chunk_mul
!= 0x4) {
135 MAX_PTEREQ_TO_ISSUE
);
141 HFLIP_PTEREQ_PER_CHUNK_INT
);
147 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
149 dm_write_reg(ctx
, addr
, value
);
152 /**************************************************************************/
154 static void enable_display_pipe_clock_gating(
155 struct dc_context
*ctx
,
161 static bool dce110_enable_display_power_gating(
163 uint8_t controller_id
,
165 enum pipe_gating_control power_gating
)
167 enum bp_result bp_result
= BP_RESULT_OK
;
168 enum bp_pipe_control_action cntl
;
169 struct dc_context
*ctx
= dc
->ctx
;
170 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
172 if (IS_FPGA_MAXIMUS_DC(ctx
->dce_environment
))
175 if (power_gating
== PIPE_GATING_CONTROL_INIT
)
176 cntl
= ASIC_PIPE_INIT
;
177 else if (power_gating
== PIPE_GATING_CONTROL_ENABLE
)
178 cntl
= ASIC_PIPE_ENABLE
;
180 cntl
= ASIC_PIPE_DISABLE
;
182 if (controller_id
== underlay_idx
)
183 controller_id
= CONTROLLER_ID_UNDERLAY0
- 1;
185 if (power_gating
!= PIPE_GATING_CONTROL_INIT
|| controller_id
== 0){
187 bp_result
= dcb
->funcs
->enable_disp_power_gating(
188 dcb
, controller_id
+ 1, cntl
);
190 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
191 * by default when command table is called
193 * Bios parser accepts controller_id = 6 as indicative of
194 * underlay pipe in dce110. But we do not support more
197 if (controller_id
< CONTROLLER_ID_MAX
- 1)
199 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE
, controller_id
),
203 if (power_gating
!= PIPE_GATING_CONTROL_ENABLE
)
204 dce110_init_pte(ctx
);
206 if (bp_result
== BP_RESULT_OK
)
212 static void build_prescale_params(struct ipp_prescale_params
*prescale_params
,
213 const struct core_surface
*surface
)
215 prescale_params
->mode
= IPP_PRESCALE_MODE_FIXED_UNSIGNED
;
217 switch (surface
->public.format
) {
218 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888
:
219 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888
:
220 prescale_params
->scale
= 0x2020;
222 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010
:
223 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010
:
224 prescale_params
->scale
= 0x2008;
226 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616
:
227 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F
:
228 prescale_params
->scale
= 0x2000;
237 /* Only use LUT for 8 bit formats */
238 static bool use_lut(const struct core_surface
*surface
)
240 switch (surface
->public.format
) {
241 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888
:
242 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888
:
249 static bool dce110_set_input_transfer_func(
250 struct pipe_ctx
*pipe_ctx
,
251 const struct core_surface
*surface
)
253 struct input_pixel_processor
*ipp
= pipe_ctx
->ipp
;
254 const struct core_transfer_func
*tf
= NULL
;
255 struct ipp_prescale_params prescale_params
= { 0 };
261 if (surface
->public.in_transfer_func
)
262 tf
= DC_TRANSFER_FUNC_TO_CORE(surface
->public.in_transfer_func
);
264 build_prescale_params(&prescale_params
, surface
);
265 ipp
->funcs
->ipp_program_prescale(ipp
, &prescale_params
);
267 if (surface
->public.gamma_correction
&& use_lut(surface
))
268 ipp
->funcs
->ipp_program_input_lut(ipp
, surface
->public.gamma_correction
);
271 /* Default case if no input transfer function specified */
272 ipp
->funcs
->ipp_set_degamma(ipp
,
273 IPP_DEGAMMA_MODE_HW_sRGB
);
274 } else if (tf
->public.type
== TF_TYPE_PREDEFINED
) {
275 switch (tf
->public.tf
) {
276 case TRANSFER_FUNCTION_SRGB
:
277 ipp
->funcs
->ipp_set_degamma(ipp
,
278 IPP_DEGAMMA_MODE_HW_sRGB
);
280 case TRANSFER_FUNCTION_BT709
:
281 ipp
->funcs
->ipp_set_degamma(ipp
,
282 IPP_DEGAMMA_MODE_HW_xvYCC
);
284 case TRANSFER_FUNCTION_LINEAR
:
285 ipp
->funcs
->ipp_set_degamma(ipp
,
286 IPP_DEGAMMA_MODE_BYPASS
);
288 case TRANSFER_FUNCTION_PQ
:
295 } else if (tf
->public.type
== TF_TYPE_BYPASS
) {
296 ipp
->funcs
->ipp_set_degamma(ipp
, IPP_DEGAMMA_MODE_BYPASS
);
298 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
305 static bool convert_to_custom_float(
306 struct pwl_result_data
*rgb_resulted
,
307 struct curve_points
*arr_points
,
308 uint32_t hw_points_num
)
310 struct custom_float_format fmt
;
312 struct pwl_result_data
*rgb
= rgb_resulted
;
316 fmt
.exponenta_bits
= 6;
317 fmt
.mantissa_bits
= 12;
320 if (!convert_to_custom_float_format(
323 &arr_points
[0].custom_float_x
)) {
328 if (!convert_to_custom_float_format(
329 arr_points
[0].offset
,
331 &arr_points
[0].custom_float_offset
)) {
336 if (!convert_to_custom_float_format(
339 &arr_points
[0].custom_float_slope
)) {
344 fmt
.mantissa_bits
= 10;
347 if (!convert_to_custom_float_format(
350 &arr_points
[1].custom_float_x
)) {
355 if (!convert_to_custom_float_format(
358 &arr_points
[1].custom_float_y
)) {
363 if (!convert_to_custom_float_format(
366 &arr_points
[2].custom_float_slope
)) {
371 fmt
.mantissa_bits
= 12;
374 while (i
!= hw_points_num
) {
375 if (!convert_to_custom_float_format(
383 if (!convert_to_custom_float_format(
391 if (!convert_to_custom_float_format(
399 if (!convert_to_custom_float_format(
402 &rgb
->delta_red_reg
)) {
407 if (!convert_to_custom_float_format(
410 &rgb
->delta_green_reg
)) {
415 if (!convert_to_custom_float_format(
418 &rgb
->delta_blue_reg
)) {
430 static bool dce110_translate_regamma_to_hw_format(const struct dc_transfer_func
431 *output_tf
, struct pwl_params
*regamma_params
)
433 struct curve_points
*arr_points
;
434 struct pwl_result_data
*rgb_resulted
;
435 struct pwl_result_data
*rgb
;
436 struct pwl_result_data
*rgb_plus_1
;
437 struct fixed31_32 y_r
;
438 struct fixed31_32 y_g
;
439 struct fixed31_32 y_b
;
440 struct fixed31_32 y1_min
;
441 struct fixed31_32 y3_max
;
443 int32_t segment_start
, segment_end
;
444 uint32_t i
, j
, k
, seg_distr
[16], increment
, start_index
, hw_points
;
446 if (output_tf
== NULL
|| regamma_params
== NULL
||
447 output_tf
->type
== TF_TYPE_BYPASS
)
450 arr_points
= regamma_params
->arr_points
;
451 rgb_resulted
= regamma_params
->rgb_resulted
;
454 memset(regamma_params
, 0, sizeof(struct pwl_params
));
456 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
458 * segments are from 2^-11 to 2^5
482 * segment is from 2^-10 to 2^0
505 for (k
= 0; k
< 16; k
++) {
506 if (seg_distr
[k
] != -1)
507 hw_points
+= (1 << seg_distr
[k
]);
511 for (k
= 0; k
< (segment_end
- segment_start
); k
++) {
512 increment
= 32 / (1 << seg_distr
[k
]);
513 start_index
= (segment_start
+ k
+ 25) * 32;
514 for (i
= start_index
; i
< start_index
+ 32; i
+= increment
) {
515 if (j
== hw_points
- 1)
517 rgb_resulted
[j
].red
= output_tf
->tf_pts
.red
[i
];
518 rgb_resulted
[j
].green
= output_tf
->tf_pts
.green
[i
];
519 rgb_resulted
[j
].blue
= output_tf
->tf_pts
.blue
[i
];
525 start_index
= (segment_end
+ 25) * 32;
526 rgb_resulted
[hw_points
- 1].red
=
527 output_tf
->tf_pts
.red
[start_index
];
528 rgb_resulted
[hw_points
- 1].green
=
529 output_tf
->tf_pts
.green
[start_index
];
530 rgb_resulted
[hw_points
- 1].blue
=
531 output_tf
->tf_pts
.blue
[start_index
];
533 arr_points
[0].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
534 dal_fixed31_32_from_int(segment_start
));
535 arr_points
[1].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
536 dal_fixed31_32_from_int(segment_end
));
537 arr_points
[2].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
538 dal_fixed31_32_from_int(segment_end
));
540 y_r
= rgb_resulted
[0].red
;
541 y_g
= rgb_resulted
[0].green
;
542 y_b
= rgb_resulted
[0].blue
;
544 y1_min
= dal_fixed31_32_min(y_r
, dal_fixed31_32_min(y_g
, y_b
));
546 arr_points
[0].y
= y1_min
;
547 arr_points
[0].slope
= dal_fixed31_32_div(
551 y_r
= rgb_resulted
[hw_points
- 1].red
;
552 y_g
= rgb_resulted
[hw_points
- 1].green
;
553 y_b
= rgb_resulted
[hw_points
- 1].blue
;
555 /* see comment above, m_arrPoints[1].y should be the Y value for the
556 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
558 y3_max
= dal_fixed31_32_max(y_r
, dal_fixed31_32_max(y_g
, y_b
));
560 arr_points
[1].y
= y3_max
;
561 arr_points
[2].y
= y3_max
;
563 arr_points
[1].slope
= dal_fixed31_32_zero
;
564 arr_points
[2].slope
= dal_fixed31_32_zero
;
566 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
567 /* for PQ, we want to have a straight line from last HW X point,
568 * and the slope to be such that we hit 1.0 at 10000 nits.
570 const struct fixed31_32 end_value
=
571 dal_fixed31_32_from_int(125);
573 arr_points
[1].slope
= dal_fixed31_32_div(
574 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
575 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
576 arr_points
[2].slope
= dal_fixed31_32_div(
577 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
578 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
581 regamma_params
->hw_points_num
= hw_points
;
584 for (k
= 0; k
< 16 && i
< 16; k
++) {
585 if (seg_distr
[k
] != -1) {
586 regamma_params
->arr_curve_points
[k
].segments_num
=
588 regamma_params
->arr_curve_points
[i
].offset
=
589 regamma_params
->arr_curve_points
[k
].
590 offset
+ (1 << seg_distr
[k
]);
595 if (seg_distr
[k
] != -1)
596 regamma_params
->arr_curve_points
[k
].segments_num
=
600 rgb_plus_1
= rgb_resulted
+ 1;
604 while (i
!= hw_points
+ 1) {
605 if (dal_fixed31_32_lt(rgb_plus_1
->red
, rgb
->red
))
606 rgb_plus_1
->red
= rgb
->red
;
607 if (dal_fixed31_32_lt(rgb_plus_1
->green
, rgb
->green
))
608 rgb_plus_1
->green
= rgb
->green
;
609 if (dal_fixed31_32_lt(rgb_plus_1
->blue
, rgb
->blue
))
610 rgb_plus_1
->blue
= rgb
->blue
;
612 rgb
->delta_red
= dal_fixed31_32_sub(
615 rgb
->delta_green
= dal_fixed31_32_sub(
618 rgb
->delta_blue
= dal_fixed31_32_sub(
627 convert_to_custom_float(rgb_resulted
, arr_points
, hw_points
);
632 static bool dce110_set_output_transfer_func(
633 struct pipe_ctx
*pipe_ctx
,
634 const struct core_stream
*stream
)
636 struct output_pixel_processor
*opp
= pipe_ctx
->opp
;
638 opp
->funcs
->opp_power_on_regamma_lut(opp
, true);
639 opp
->regamma_params
.hw_points_num
= GAMMA_HW_POINTS_NUM
;
641 if (stream
->public.out_transfer_func
&&
642 stream
->public.out_transfer_func
->type
==
643 TF_TYPE_PREDEFINED
&&
644 stream
->public.out_transfer_func
->tf
==
645 TRANSFER_FUNCTION_SRGB
) {
646 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_SRGB
);
647 } else if (dce110_translate_regamma_to_hw_format(
648 stream
->public.out_transfer_func
, &opp
->regamma_params
)) {
649 opp
->funcs
->opp_program_regamma_pwl(opp
, &opp
->regamma_params
);
650 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_USER
);
652 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_BYPASS
);
655 opp
->funcs
->opp_power_on_regamma_lut(opp
, false);
660 static enum dc_status
bios_parser_crtc_source_select(
661 struct pipe_ctx
*pipe_ctx
)
664 /* call VBIOS table to set CRTC source for the HW
666 * note: video bios clears all FMT setting here. */
667 struct bp_crtc_source_select crtc_source_select
= {0};
668 const struct core_sink
*sink
= pipe_ctx
->stream
->sink
;
670 crtc_source_select
.engine_id
= pipe_ctx
->stream_enc
->id
;
671 crtc_source_select
.controller_id
= pipe_ctx
->pipe_idx
+ 1;
672 /*TODO: Need to un-hardcode color depth, dp_audio and account for
673 * the case where signal and sink signal is different (translator
675 crtc_source_select
.signal
= pipe_ctx
->stream
->signal
;
676 crtc_source_select
.enable_dp_audio
= false;
677 crtc_source_select
.sink_signal
= pipe_ctx
->stream
->signal
;
678 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
680 dcb
= sink
->ctx
->dc_bios
;
682 if (BP_RESULT_OK
!= dcb
->funcs
->crtc_source_select(
684 &crtc_source_select
)) {
685 return DC_ERROR_UNEXPECTED
;
691 void dce110_update_info_frame(struct pipe_ctx
*pipe_ctx
)
693 ASSERT(pipe_ctx
->stream
);
695 if (pipe_ctx
->stream_enc
== NULL
)
696 return; /* this is not root pipe */
698 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
699 pipe_ctx
->stream_enc
->funcs
->update_hdmi_info_packets(
700 pipe_ctx
->stream_enc
,
701 &pipe_ctx
->encoder_info_frame
);
702 else if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
703 pipe_ctx
->stream_enc
->funcs
->update_dp_info_packets(
704 pipe_ctx
->stream_enc
,
705 &pipe_ctx
->encoder_info_frame
);
708 void dce110_enable_stream(struct pipe_ctx
*pipe_ctx
)
710 enum dc_lane_count lane_count
=
711 pipe_ctx
->stream
->sink
->link
->public.cur_link_settings
.lane_count
;
713 struct dc_crtc_timing
*timing
= &pipe_ctx
->stream
->public.timing
;
714 struct core_link
*link
= pipe_ctx
->stream
->sink
->link
;
716 /* 1. update AVI info frame (HDMI, DP)
717 * we always need to update info frame
719 uint32_t active_total_with_borders
;
720 uint32_t early_control
= 0;
721 struct timing_generator
*tg
= pipe_ctx
->tg
;
723 /* TODOFPGA may change to hwss.update_info_frame */
724 dce110_update_info_frame(pipe_ctx
);
725 /* enable early control to avoid corruption on DP monitor*/
726 active_total_with_borders
=
727 timing
->h_addressable
728 + timing
->h_border_left
729 + timing
->h_border_right
;
732 early_control
= active_total_with_borders
% lane_count
;
734 if (early_control
== 0)
735 early_control
= lane_count
;
737 tg
->funcs
->set_early_control(tg
, early_control
);
739 /* enable audio only within mode set */
740 if (pipe_ctx
->audio
!= NULL
) {
741 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
742 pipe_ctx
->stream_enc
->funcs
->dp_audio_enable(pipe_ctx
->stream_enc
);
745 /* For MST, there are multiply stream go to only one link.
746 * connect DIG back_end to front_end while enable_stream and
747 * disconnect them during disable_stream
748 * BY this, it is logic clean to separate stream and link */
749 link
->link_enc
->funcs
->connect_dig_be_to_fe(link
->link_enc
,
750 pipe_ctx
->stream_enc
->id
, true);
754 void dce110_disable_stream(struct pipe_ctx
*pipe_ctx
)
756 struct core_stream
*stream
= pipe_ctx
->stream
;
757 struct core_link
*link
= stream
->sink
->link
;
759 if (pipe_ctx
->audio
) {
760 pipe_ctx
->audio
->funcs
->az_disable(pipe_ctx
->audio
);
762 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
763 pipe_ctx
->stream_enc
->funcs
->dp_audio_disable(
764 pipe_ctx
->stream_enc
);
766 pipe_ctx
->stream_enc
->funcs
->hdmi_audio_disable(
767 pipe_ctx
->stream_enc
);
769 pipe_ctx
->audio
= NULL
;
771 /* TODO: notify audio driver for if audio modes list changed
772 * add audio mode list change flag */
773 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
774 * stream->stream_engine_id);
778 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
779 pipe_ctx
->stream_enc
->funcs
->stop_hdmi_info_packets(
780 pipe_ctx
->stream_enc
);
782 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
783 pipe_ctx
->stream_enc
->funcs
->stop_dp_info_packets(
784 pipe_ctx
->stream_enc
);
786 pipe_ctx
->stream_enc
->funcs
->audio_mute_control(
787 pipe_ctx
->stream_enc
, true);
790 /* blank at encoder level */
791 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
792 pipe_ctx
->stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_enc
);
794 link
->link_enc
->funcs
->connect_dig_be_to_fe(
796 pipe_ctx
->stream_enc
->id
,
801 void dce110_unblank_stream(struct pipe_ctx
*pipe_ctx
,
802 struct dc_link_settings
*link_settings
)
804 struct encoder_unblank_param params
= { { 0 } };
806 /* only 3 items below are used by unblank */
807 params
.pixel_clk_khz
=
808 pipe_ctx
->stream
->public.timing
.pix_clk_khz
;
809 params
.link_settings
.link_rate
= link_settings
->link_rate
;
810 pipe_ctx
->stream_enc
->funcs
->dp_unblank(pipe_ctx
->stream_enc
, ¶ms
);
813 static enum audio_dto_source
translate_to_dto_source(enum controller_id crtc_id
)
816 case CONTROLLER_ID_D0
:
817 return DTO_SOURCE_ID0
;
818 case CONTROLLER_ID_D1
:
819 return DTO_SOURCE_ID1
;
820 case CONTROLLER_ID_D2
:
821 return DTO_SOURCE_ID2
;
822 case CONTROLLER_ID_D3
:
823 return DTO_SOURCE_ID3
;
824 case CONTROLLER_ID_D4
:
825 return DTO_SOURCE_ID4
;
826 case CONTROLLER_ID_D5
:
827 return DTO_SOURCE_ID5
;
829 return DTO_SOURCE_UNKNOWN
;
833 static void build_audio_output(
834 const struct pipe_ctx
*pipe_ctx
,
835 struct audio_output
*audio_output
)
837 const struct core_stream
*stream
= pipe_ctx
->stream
;
838 audio_output
->engine_id
= pipe_ctx
->stream_enc
->id
;
840 audio_output
->signal
= pipe_ctx
->stream
->signal
;
842 /* audio_crtc_info */
844 audio_output
->crtc_info
.h_total
=
845 stream
->public.timing
.h_total
;
848 * Audio packets are sent during actual CRTC blank physical signal, we
849 * need to specify actual active signal portion
851 audio_output
->crtc_info
.h_active
=
852 stream
->public.timing
.h_addressable
853 + stream
->public.timing
.h_border_left
854 + stream
->public.timing
.h_border_right
;
856 audio_output
->crtc_info
.v_active
=
857 stream
->public.timing
.v_addressable
858 + stream
->public.timing
.v_border_top
859 + stream
->public.timing
.v_border_bottom
;
861 audio_output
->crtc_info
.pixel_repetition
= 1;
863 audio_output
->crtc_info
.interlaced
=
864 stream
->public.timing
.flags
.INTERLACE
;
866 audio_output
->crtc_info
.refresh_rate
=
867 (stream
->public.timing
.pix_clk_khz
*1000)/
868 (stream
->public.timing
.h_total
*stream
->public.timing
.v_total
);
870 audio_output
->crtc_info
.color_depth
=
871 stream
->public.timing
.display_color_depth
;
873 audio_output
->crtc_info
.requested_pixel_clock
=
874 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
876 audio_output
->crtc_info
.calculated_pixel_clock
=
877 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
879 /*for HDMI, audio ACR is with deep color ratio factor*/
880 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
) &&
881 audio_output
->crtc_info
.requested_pixel_clock
==
882 stream
->public.timing
.pix_clk_khz
) {
883 if (pipe_ctx
->pix_clk_params
.pixel_encoding
== PIXEL_ENCODING_YCBCR420
) {
884 audio_output
->crtc_info
.requested_pixel_clock
=
885 audio_output
->crtc_info
.requested_pixel_clock
/2;
886 audio_output
->crtc_info
.calculated_pixel_clock
=
887 pipe_ctx
->pix_clk_params
.requested_pix_clk
/2;
892 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT
||
893 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
894 audio_output
->pll_info
.dp_dto_source_clock_in_khz
=
895 pipe_ctx
->dis_clk
->funcs
->get_dp_ref_clk_frequency(
899 audio_output
->pll_info
.feed_back_divider
=
900 pipe_ctx
->pll_settings
.feedback_divider
;
902 audio_output
->pll_info
.dto_source
=
903 translate_to_dto_source(
904 pipe_ctx
->pipe_idx
+ 1);
906 /* TODO hard code to enable for now. Need get from stream */
907 audio_output
->pll_info
.ss_enabled
= true;
909 audio_output
->pll_info
.ss_percentage
=
910 pipe_ctx
->pll_settings
.ss_percentage
;
913 static void get_surface_visual_confirm_color(const struct pipe_ctx
*pipe_ctx
,
914 struct tg_color
*color
)
916 uint32_t color_value
= MAX_TG_COLOR_VALUE
* (4 - pipe_ctx
->pipe_idx
) / 4;
918 switch (pipe_ctx
->scl_data
.format
) {
919 case PIXEL_FORMAT_ARGB8888
:
920 /* set boarder color to red */
921 color
->color_r_cr
= color_value
;
924 case PIXEL_FORMAT_ARGB2101010
:
925 /* set boarder color to blue */
926 color
->color_b_cb
= color_value
;
928 case PIXEL_FORMAT_420BPP12
:
929 case PIXEL_FORMAT_420BPP15
:
930 /* set boarder color to green */
931 color
->color_g_y
= color_value
;
933 case PIXEL_FORMAT_FP16
:
934 /* set boarder color to white */
935 color
->color_r_cr
= color_value
;
936 color
->color_b_cb
= color_value
;
937 color
->color_g_y
= color_value
;
944 static void program_scaler(const struct core_dc
*dc
,
945 const struct pipe_ctx
*pipe_ctx
)
947 struct tg_color color
= {0};
949 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
951 if (pipe_ctx
->xfm
->funcs
->transform_set_pixel_storage_depth
== NULL
)
955 if (dc
->public.debug
.surface_visual_confirm
)
956 get_surface_visual_confirm_color(pipe_ctx
, &color
);
958 color_space_to_black_color(dc
,
959 pipe_ctx
->stream
->public.output_color_space
,
962 pipe_ctx
->xfm
->funcs
->transform_set_pixel_storage_depth(
964 pipe_ctx
->scl_data
.lb_params
.depth
,
965 &pipe_ctx
->stream
->bit_depth_params
);
967 if (pipe_ctx
->tg
->funcs
->set_overscan_blank_color
)
968 pipe_ctx
->tg
->funcs
->set_overscan_blank_color(
972 pipe_ctx
->xfm
->funcs
->transform_set_scaler(pipe_ctx
->xfm
,
973 &pipe_ctx
->scl_data
);
976 static enum dc_status
dce110_prog_pixclk_crtc_otg(
977 struct pipe_ctx
*pipe_ctx
,
978 struct validate_context
*context
,
981 struct core_stream
*stream
= pipe_ctx
->stream
;
982 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_context
->res_ctx
.
983 pipe_ctx
[pipe_ctx
->pipe_idx
];
984 struct tg_color black_color
= {0};
986 if (!pipe_ctx_old
->stream
) {
988 /* program blank color */
989 color_space_to_black_color(dc
,
990 stream
->public.output_color_space
, &black_color
);
991 pipe_ctx
->tg
->funcs
->set_blank_color(
996 * Must blank CRTC after disabling power gating and before any
997 * programming, otherwise CRTC will be hung in bad state
999 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, true);
1001 if (false == pipe_ctx
->clock_source
->funcs
->program_pix_clk(
1002 pipe_ctx
->clock_source
,
1003 &pipe_ctx
->pix_clk_params
,
1004 &pipe_ctx
->pll_settings
)) {
1005 BREAK_TO_DEBUGGER();
1006 return DC_ERROR_UNEXPECTED
;
1009 pipe_ctx
->tg
->funcs
->program_timing(
1011 &stream
->public.timing
,
1014 pipe_ctx
->tg
->funcs
->set_static_screen_control(
1019 if (!pipe_ctx_old
->stream
) {
1020 if (false == pipe_ctx
->tg
->funcs
->enable_crtc(
1022 BREAK_TO_DEBUGGER();
1023 return DC_ERROR_UNEXPECTED
;
1032 static enum dc_status
apply_single_controller_ctx_to_hw(
1033 struct pipe_ctx
*pipe_ctx
,
1034 struct validate_context
*context
,
1037 struct core_stream
*stream
= pipe_ctx
->stream
;
1038 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_context
->res_ctx
.
1039 pipe_ctx
[pipe_ctx
->pipe_idx
];
1042 dc
->hwss
.prog_pixclk_crtc_otg(pipe_ctx
, context
, dc
);
1044 pipe_ctx
->opp
->funcs
->opp_set_dyn_expansion(
1046 COLOR_SPACE_YCBCR601
,
1047 stream
->public.timing
.display_color_depth
,
1048 pipe_ctx
->stream
->signal
);
1050 /* FPGA does not program backend */
1051 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1052 pipe_ctx
->opp
->funcs
->opp_program_fmt(
1054 &stream
->bit_depth_params
,
1058 /* TODO: move to stream encoder */
1059 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1060 if (DC_OK
!= bios_parser_crtc_source_select(pipe_ctx
)) {
1061 BREAK_TO_DEBUGGER();
1062 return DC_ERROR_UNEXPECTED
;
1065 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1066 stream
->sink
->link
->link_enc
->funcs
->setup(
1067 stream
->sink
->link
->link_enc
,
1068 pipe_ctx
->stream
->signal
);
1070 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1071 pipe_ctx
->stream_enc
->funcs
->setup_stereo_sync(
1072 pipe_ctx
->stream_enc
,
1074 stream
->public.timing
.timing_3d_format
!= TIMING_3D_FORMAT_NONE
);
1077 /*vbios crtc_source_selection and encoder_setup will override fmt_C*/
1078 pipe_ctx
->opp
->funcs
->opp_program_fmt(
1080 &stream
->bit_depth_params
,
1083 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1084 pipe_ctx
->stream_enc
->funcs
->dp_set_stream_attribute(
1085 pipe_ctx
->stream_enc
,
1086 &stream
->public.timing
,
1087 stream
->public.output_color_space
);
1089 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1090 pipe_ctx
->stream_enc
->funcs
->hdmi_set_stream_attribute(
1091 pipe_ctx
->stream_enc
,
1092 &stream
->public.timing
,
1093 stream
->phy_pix_clk
,
1094 pipe_ctx
->audio
!= NULL
);
1096 if (dc_is_dvi_signal(pipe_ctx
->stream
->signal
))
1097 pipe_ctx
->stream_enc
->funcs
->dvi_set_stream_attribute(
1098 pipe_ctx
->stream_enc
,
1099 &stream
->public.timing
,
1100 (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
) ?
1103 if (!pipe_ctx_old
->stream
) {
1104 core_link_enable_stream(pipe_ctx
);
1106 resource_build_info_frame(pipe_ctx
);
1107 dce110_update_info_frame(pipe_ctx
);
1108 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1109 dce110_unblank_stream(pipe_ctx
,
1110 &stream
->sink
->link
->public.cur_link_settings
);
1113 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1114 /* program_scaler and allocate_mem_input are not new asic */
1115 if (!pipe_ctx_old
|| memcmp(&pipe_ctx_old
->scl_data
,
1116 &pipe_ctx
->scl_data
,
1117 sizeof(struct scaler_data
)) != 0)
1118 program_scaler(dc
, pipe_ctx
);
1120 /* mst support - use total stream count */
1121 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1122 if (pipe_ctx
->mi
->funcs
->allocate_mem_input
!= NULL
)
1124 pipe_ctx
->mi
->funcs
->allocate_mem_input(
1126 stream
->public.timing
.h_total
,
1127 stream
->public.timing
.v_total
,
1128 stream
->public.timing
.pix_clk_khz
,
1129 context
->stream_count
);
1131 pipe_ctx
->stream
->sink
->link
->psr_enabled
= false;
1136 /******************************************************************************/
1138 static void power_down_encoders(struct core_dc
*dc
)
1142 for (i
= 0; i
< dc
->link_count
; i
++) {
1143 dc
->links
[i
]->link_enc
->funcs
->disable_output(
1144 dc
->links
[i
]->link_enc
, SIGNAL_TYPE_NONE
);
1148 static void power_down_controllers(struct core_dc
*dc
)
1152 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1153 dc
->res_pool
->timing_generators
[i
]->funcs
->disable_crtc(
1154 dc
->res_pool
->timing_generators
[i
]);
1158 static void power_down_clock_sources(struct core_dc
*dc
)
1162 if (dc
->res_pool
->dp_clock_source
->funcs
->cs_power_down(
1163 dc
->res_pool
->dp_clock_source
) == false)
1164 dm_error("Failed to power down pll! (dp clk src)\n");
1166 for (i
= 0; i
< dc
->res_pool
->clk_src_count
; i
++) {
1167 if (dc
->res_pool
->clock_sources
[i
]->funcs
->cs_power_down(
1168 dc
->res_pool
->clock_sources
[i
]) == false)
1169 dm_error("Failed to power down pll! (clk src index=%d)\n", i
);
1173 static void power_down_all_hw_blocks(struct core_dc
*dc
)
1175 power_down_encoders(dc
);
1177 power_down_controllers(dc
);
1179 power_down_clock_sources(dc
);
1182 static void disable_vga_and_power_gate_all_controllers(
1186 struct timing_generator
*tg
;
1187 struct dc_context
*ctx
= dc
->ctx
;
1189 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1190 tg
= dc
->res_pool
->timing_generators
[i
];
1192 tg
->funcs
->disable_vga(tg
);
1194 /* Enable CLOCK gating for each pipe BEFORE controller
1196 enable_display_pipe_clock_gating(ctx
,
1199 dc
->hwss
.power_down_front_end(
1200 dc
, &dc
->current_context
->res_ctx
.pipe_ctx
[i
]);
1205 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1206 * 1. Power down all DC HW blocks
1207 * 2. Disable VGA engine on all controllers
1208 * 3. Enable power gating for controller
1209 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1211 void dce110_enable_accelerated_mode(struct core_dc
*dc
)
1213 power_down_all_hw_blocks(dc
);
1215 disable_vga_and_power_gate_all_controllers(dc
);
1216 bios_set_scratch_acc_mode_change(dc
->ctx
->dc_bios
);
1219 static uint32_t compute_pstate_blackout_duration(
1220 struct bw_fixed blackout_duration
,
1221 const struct core_stream
*stream
)
1223 uint32_t total_dest_line_time_ns
;
1224 uint32_t pstate_blackout_duration_ns
;
1226 pstate_blackout_duration_ns
= 1000 * blackout_duration
.value
>> 24;
1228 total_dest_line_time_ns
= 1000000UL *
1229 stream
->public.timing
.h_total
/
1230 stream
->public.timing
.pix_clk_khz
+
1231 pstate_blackout_duration_ns
;
1233 return total_dest_line_time_ns
;
1236 void dce110_set_displaymarks(
1237 const struct core_dc
*dc
,
1238 struct validate_context
*context
)
1240 uint8_t i
, num_pipes
;
1241 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
1243 for (i
= 0, num_pipes
= 0; i
< MAX_PIPES
; i
++) {
1244 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1245 uint32_t total_dest_line_time_ns
;
1247 if (pipe_ctx
->stream
== NULL
)
1250 total_dest_line_time_ns
= compute_pstate_blackout_duration(
1251 dc
->bw_vbios
.blackout_duration
, pipe_ctx
->stream
);
1252 pipe_ctx
->mi
->funcs
->mem_input_program_display_marks(
1254 context
->bw
.dce
.nbp_state_change_wm_ns
[num_pipes
],
1255 context
->bw
.dce
.stutter_exit_wm_ns
[num_pipes
],
1256 context
->bw
.dce
.urgent_wm_ns
[num_pipes
],
1257 total_dest_line_time_ns
);
1258 if (i
== underlay_idx
) {
1260 pipe_ctx
->mi
->funcs
->mem_input_program_chroma_display_marks(
1262 context
->bw
.dce
.nbp_state_change_wm_ns
[num_pipes
],
1263 context
->bw
.dce
.stutter_exit_wm_ns
[num_pipes
],
1264 context
->bw
.dce
.urgent_wm_ns
[num_pipes
],
1265 total_dest_line_time_ns
);
1271 static void set_safe_displaymarks(
1272 struct resource_context
*res_ctx
,
1273 const struct resource_pool
*pool
)
1276 int underlay_idx
= pool
->underlay_pipe_index
;
1277 struct dce_watermarks max_marks
= {
1278 MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
};
1279 struct dce_watermarks nbp_marks
= {
1280 SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
};
1282 for (i
= 0; i
< MAX_PIPES
; i
++) {
1283 if (res_ctx
->pipe_ctx
[i
].stream
== NULL
)
1286 res_ctx
->pipe_ctx
[i
].mi
->funcs
->mem_input_program_display_marks(
1287 res_ctx
->pipe_ctx
[i
].mi
,
1292 if (i
== underlay_idx
)
1293 res_ctx
->pipe_ctx
[i
].mi
->funcs
->mem_input_program_chroma_display_marks(
1294 res_ctx
->pipe_ctx
[i
].mi
,
1302 static void switch_dp_clock_sources(
1303 const struct core_dc
*dc
,
1304 struct resource_context
*res_ctx
)
1307 for (i
= 0; i
< MAX_PIPES
; i
++) {
1308 struct pipe_ctx
*pipe_ctx
= &res_ctx
->pipe_ctx
[i
];
1310 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1313 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
)) {
1314 struct clock_source
*clk_src
=
1315 resource_find_used_clk_src_for_sharing(
1319 clk_src
!= pipe_ctx
->clock_source
) {
1320 resource_unreference_clock_source(
1321 res_ctx
, dc
->res_pool
,
1322 &pipe_ctx
->clock_source
);
1323 pipe_ctx
->clock_source
= clk_src
;
1324 resource_reference_clock_source(
1325 res_ctx
, dc
->res_pool
, clk_src
);
1327 dce_crtc_switch_to_clk_src(dc
->hwseq
, clk_src
, i
);
1333 /*******************************************************************************
1335 ******************************************************************************/
1337 static void reset_single_pipe_hw_ctx(
1338 const struct core_dc
*dc
,
1339 struct pipe_ctx
*pipe_ctx
,
1340 struct validate_context
*context
)
1342 core_link_disable_stream(pipe_ctx
);
1343 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, true);
1344 if (!hwss_wait_for_blank_complete(pipe_ctx
->tg
)) {
1345 dm_error("DC: failed to blank crtc!\n");
1346 BREAK_TO_DEBUGGER();
1348 pipe_ctx
->tg
->funcs
->disable_crtc(pipe_ctx
->tg
);
1349 pipe_ctx
->mi
->funcs
->free_mem_input(
1350 pipe_ctx
->mi
, context
->stream_count
);
1351 resource_unreference_clock_source(&context
->res_ctx
, dc
->res_pool
,
1352 &pipe_ctx
->clock_source
);
1354 dc
->hwss
.power_down_front_end((struct core_dc
*)dc
, pipe_ctx
);
1356 pipe_ctx
->stream
= NULL
;
1359 static void set_drr(struct pipe_ctx
**pipe_ctx
,
1360 int num_pipes
, int vmin
, int vmax
)
1363 struct drr_params params
= {0};
1365 params
.vertical_total_max
= vmax
;
1366 params
.vertical_total_min
= vmin
;
1368 /* TODO: If multiple pipes are to be supported, you need
1372 for (i
= 0; i
< num_pipes
; i
++) {
1373 pipe_ctx
[i
]->tg
->funcs
->set_drr(pipe_ctx
[i
]->tg
, ¶ms
);
1377 static void get_position(struct pipe_ctx
**pipe_ctx
,
1379 struct crtc_position
*position
)
1383 /* TODO: handle pipes > 1
1385 for (i
= 0; i
< num_pipes
; i
++)
1386 pipe_ctx
[i
]->tg
->funcs
->get_position(pipe_ctx
[i
]->tg
, position
);
1389 static void set_static_screen_control(struct pipe_ctx
**pipe_ctx
,
1390 int num_pipes
, const struct dc_static_screen_events
*events
)
1393 unsigned int value
= 0;
1395 if (events
->overlay_update
)
1397 if (events
->surface_update
)
1399 if (events
->cursor_update
)
1402 for (i
= 0; i
< num_pipes
; i
++)
1403 pipe_ctx
[i
]->tg
->funcs
->
1404 set_static_screen_control(pipe_ctx
[i
]->tg
, value
);
1407 /* unit: in_khz before mode set, get pixel clock from context. ASIC register
1408 * may not be programmed yet.
1409 * TODO: after mode set, pre_mode_set = false,
1410 * may read PLL register to get pixel clock
1412 static uint32_t get_max_pixel_clock_for_all_paths(
1414 struct validate_context
*context
,
1417 uint32_t max_pix_clk
= 0;
1420 if (!pre_mode_set
) {
1421 /* TODO: read ASIC register to get pixel clock */
1425 for (i
= 0; i
< MAX_PIPES
; i
++) {
1426 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1428 if (pipe_ctx
->stream
== NULL
)
1431 /* do not check under lay */
1432 if (pipe_ctx
->top_pipe
)
1435 if (pipe_ctx
->pix_clk_params
.requested_pix_clk
> max_pix_clk
)
1437 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1440 if (max_pix_clk
== 0)
1446 /* Find clock state based on clock requested. if clock value is 0, simply
1447 * set clock state as requested without finding clock state by clock value
1448 *TODO: when dce120_hw_sequencer.c is created, override apply_min_clock.
1450 * TODOFPGA remove TODO after implement dal_display_clock_get_cur_clocks_value
1451 * etc support for dcn1.0
1453 static void apply_min_clocks(
1455 struct validate_context
*context
,
1456 enum dm_pp_clocks_state
*clocks_state
,
1459 struct state_dependent_clocks req_clocks
= {0};
1460 struct pipe_ctx
*pipe_ctx
;
1463 for (i
= 0; i
< MAX_PIPES
; i
++) {
1464 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1465 if (pipe_ctx
->dis_clk
!= NULL
)
1469 if (!pre_mode_set
) {
1470 /* set clock_state without verification */
1471 if (pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state
) {
1472 pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state(
1473 pipe_ctx
->dis_clk
, *clocks_state
);
1477 /* TODO: This is incorrect. Figure out how to fix. */
1478 pipe_ctx
->dis_clk
->funcs
->apply_clock_voltage_request(
1480 DM_PP_CLOCK_TYPE_DISPLAY_CLK
,
1481 pipe_ctx
->dis_clk
->cur_clocks_value
.dispclk_in_khz
,
1485 pipe_ctx
->dis_clk
->funcs
->apply_clock_voltage_request(
1487 DM_PP_CLOCK_TYPE_PIXELCLK
,
1488 pipe_ctx
->dis_clk
->cur_clocks_value
.max_pixelclk_in_khz
,
1492 pipe_ctx
->dis_clk
->funcs
->apply_clock_voltage_request(
1494 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1495 pipe_ctx
->dis_clk
->cur_clocks_value
.max_non_dp_phyclk_in_khz
,
1501 /* get the required state based on state dependent clocks:
1502 * display clock and pixel clock
1504 req_clocks
.display_clk_khz
= context
->bw
.dce
.dispclk_khz
;
1506 req_clocks
.pixel_clk_khz
= get_max_pixel_clock_for_all_paths(
1509 if (pipe_ctx
->dis_clk
->funcs
->get_required_clocks_state
) {
1510 *clocks_state
= pipe_ctx
->dis_clk
->funcs
->get_required_clocks_state(
1511 pipe_ctx
->dis_clk
, &req_clocks
);
1512 pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state(
1513 pipe_ctx
->dis_clk
, *clocks_state
);
1515 pipe_ctx
->dis_clk
->funcs
->apply_clock_voltage_request(
1517 DM_PP_CLOCK_TYPE_DISPLAY_CLK
,
1518 req_clocks
.display_clk_khz
,
1522 pipe_ctx
->dis_clk
->funcs
->apply_clock_voltage_request(
1524 DM_PP_CLOCK_TYPE_PIXELCLK
,
1525 req_clocks
.pixel_clk_khz
,
1529 pipe_ctx
->dis_clk
->funcs
->apply_clock_voltage_request(
1531 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1532 req_clocks
.pixel_clk_khz
,
1538 static enum dc_status
apply_ctx_to_hw_fpga(
1540 struct validate_context
*context
)
1542 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1545 for (i
= 0; i
< MAX_PIPES
; i
++) {
1546 struct pipe_ctx
*pipe_ctx_old
=
1547 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1548 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1550 if (pipe_ctx
->stream
== NULL
)
1553 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1556 status
= apply_single_controller_ctx_to_hw(
1561 if (status
!= DC_OK
)
1568 static void reset_hw_ctx_wrap(
1570 struct validate_context
*context
)
1574 /* Reset old context */
1575 /* look up the targets that have been removed since last commit */
1576 for (i
= 0; i
< MAX_PIPES
; i
++) {
1577 struct pipe_ctx
*pipe_ctx_old
=
1578 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1579 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1581 /* Note: We need to disable output if clock sources change,
1582 * since bios does optimization and doesn't apply if changing
1583 * PHY when not already disabled.
1586 /* Skip underlay pipe since it will be handled in commit surface*/
1587 if (!pipe_ctx_old
->stream
|| pipe_ctx_old
->top_pipe
)
1590 if (!pipe_ctx
->stream
||
1591 pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
1592 reset_single_pipe_hw_ctx(
1593 dc
, pipe_ctx_old
, dc
->current_context
);
1598 enum dc_status
dce110_apply_ctx_to_hw(
1600 struct validate_context
*context
)
1602 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
1603 enum dc_status status
;
1605 enum dm_pp_clocks_state clocks_state
= DM_PP_CLOCKS_STATE_INVALID
;
1607 /* Reset old context */
1608 /* look up the targets that have been removed since last commit */
1609 dc
->hwss
.reset_hw_ctx_wrap(dc
, context
);
1611 /* Skip applying if no targets */
1612 if (context
->stream_count
<= 0)
1615 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1616 apply_ctx_to_hw_fpga(dc
, context
);
1620 /* Apply new context */
1621 dcb
->funcs
->set_scratch_critical_state(dcb
, true);
1623 /* below is for real asic only */
1624 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1625 struct pipe_ctx
*pipe_ctx_old
=
1626 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1627 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1629 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1632 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
) {
1633 if (pipe_ctx_old
->clock_source
!= pipe_ctx
->clock_source
)
1634 dce_crtc_switch_to_clk_src(dc
->hwseq
,
1635 pipe_ctx
->clock_source
, i
);
1639 dc
->hwss
.enable_display_power_gating(
1640 dc
, i
, dc
->ctx
->dc_bios
,
1641 PIPE_GATING_CONTROL_DISABLE
);
1644 set_safe_displaymarks(&context
->res_ctx
, dc
->res_pool
);
1645 /*TODO: when pplib works*/
1646 apply_min_clocks(dc
, context
, &clocks_state
, true);
1648 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1649 if (resource_parse_asic_id(dc
->ctx
->asic_id
) == DCN_VERSION_1_0
) {
1650 if (context
->bw
.dcn
.calc_clk
.fclk_khz
1651 > dc
->current_context
->bw
.dcn
.cur_clk
.fclk_khz
) {
1652 struct dm_pp_clock_for_voltage_req clock
;
1654 clock
.clk_type
= DM_PP_CLOCK_TYPE_FCLK
;
1655 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.fclk_khz
;
1656 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1657 dc
->current_context
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1658 context
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1660 if (context
->bw
.dcn
.calc_clk
.dcfclk_khz
1661 > dc
->current_context
->bw
.dcn
.cur_clk
.dcfclk_khz
) {
1662 struct dm_pp_clock_for_voltage_req clock
;
1664 clock
.clk_type
= DM_PP_CLOCK_TYPE_DCFCLK
;
1665 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.dcfclk_khz
;
1666 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1667 dc
->current_context
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1668 context
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1670 if (context
->bw
.dcn
.calc_clk
.dispclk_khz
1671 > dc
->current_context
->bw
.dcn
.cur_clk
.dispclk_khz
) {
1672 dc
->res_pool
->display_clock
->funcs
->set_clock(
1673 dc
->res_pool
->display_clock
,
1674 context
->bw
.dcn
.calc_clk
.dispclk_khz
);
1675 dc
->current_context
->bw
.dcn
.cur_clk
.dispclk_khz
=
1676 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
1677 context
->bw
.dcn
.cur_clk
.dispclk_khz
=
1678 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
1682 if (context
->bw
.dce
.dispclk_khz
1683 > dc
->current_context
->bw
.dce
.dispclk_khz
) {
1684 dc
->res_pool
->display_clock
->funcs
->set_clock(
1685 dc
->res_pool
->display_clock
,
1686 context
->bw
.dce
.dispclk_khz
* 115 / 100);
1688 /* program audio wall clock. use HDMI as clock source if HDMI
1689 * audio active. Otherwise, use DP as clock source
1690 * first, loop to find any HDMI audio, if not, loop find DP audio
1692 /* Setup audio rate clock source */
1694 * Audio lag happened on DP monitor when unplug a HDMI monitor
1697 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
1698 * is set to either dto0 or dto1, audio should work fine.
1699 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
1700 * set to dto0 will cause audio lag.
1703 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
1704 * find first available pipe with audio, setup audio wall DTO per topology
1705 * instead of per pipe.
1707 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1708 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1710 if (pipe_ctx
->stream
== NULL
)
1713 if (pipe_ctx
->top_pipe
)
1716 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_HDMI_TYPE_A
)
1719 if (pipe_ctx
->audio
!= NULL
) {
1720 struct audio_output audio_output
;
1722 build_audio_output(pipe_ctx
, &audio_output
);
1724 pipe_ctx
->audio
->funcs
->wall_dto_setup(
1726 pipe_ctx
->stream
->signal
,
1727 &audio_output
.crtc_info
,
1728 &audio_output
.pll_info
);
1733 /* no HDMI audio is found, try DP audio */
1734 if (i
== dc
->res_pool
->pipe_count
) {
1735 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1736 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1738 if (pipe_ctx
->stream
== NULL
)
1741 if (pipe_ctx
->top_pipe
)
1744 if (!dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1747 if (pipe_ctx
->audio
!= NULL
) {
1748 struct audio_output audio_output
;
1750 build_audio_output(pipe_ctx
, &audio_output
);
1752 pipe_ctx
->audio
->funcs
->wall_dto_setup(
1754 pipe_ctx
->stream
->signal
,
1755 &audio_output
.crtc_info
,
1756 &audio_output
.pll_info
);
1762 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1763 struct pipe_ctx
*pipe_ctx_old
=
1764 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1765 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1767 if (pipe_ctx
->stream
== NULL
)
1770 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1773 if (pipe_ctx
->stream
&& pipe_ctx_old
->stream
1774 && !pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
1777 if (pipe_ctx
->top_pipe
)
1780 if (context
->res_ctx
.pipe_ctx
[i
].audio
!= NULL
) {
1782 struct audio_output audio_output
;
1784 build_audio_output(pipe_ctx
, &audio_output
);
1786 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1787 pipe_ctx
->stream_enc
->funcs
->dp_audio_setup(
1788 pipe_ctx
->stream_enc
,
1789 pipe_ctx
->audio
->inst
,
1790 &pipe_ctx
->stream
->public.audio_info
);
1792 pipe_ctx
->stream_enc
->funcs
->hdmi_audio_setup(
1793 pipe_ctx
->stream_enc
,
1794 pipe_ctx
->audio
->inst
,
1795 &pipe_ctx
->stream
->public.audio_info
,
1796 &audio_output
.crtc_info
);
1798 pipe_ctx
->audio
->funcs
->az_configure(
1800 pipe_ctx
->stream
->signal
,
1801 &audio_output
.crtc_info
,
1802 &pipe_ctx
->stream
->public.audio_info
);
1805 status
= apply_single_controller_ctx_to_hw(
1810 if (dc
->hwss
.power_on_front_end
)
1811 dc
->hwss
.power_on_front_end(dc
, pipe_ctx
, context
);
1813 if (DC_OK
!= status
)
1817 dc
->hwss
.set_bandwidth(dc
, context
, true);
1820 apply_min_clocks(dc
, context
, &clocks_state
, false);
1822 dcb
->funcs
->set_scratch_critical_state(dcb
, false);
1824 switch_dp_clock_sources(dc
, &context
->res_ctx
);
1830 /*******************************************************************************
1831 * Front End programming
1832 ******************************************************************************/
1833 static void set_default_colors(struct pipe_ctx
*pipe_ctx
)
1835 struct default_adjustment default_adjust
= { 0 };
1837 default_adjust
.force_hw_default
= false;
1838 if (pipe_ctx
->surface
== NULL
)
1839 default_adjust
.in_color_space
= COLOR_SPACE_SRGB
;
1841 default_adjust
.in_color_space
=
1842 pipe_ctx
->surface
->public.color_space
;
1843 if (pipe_ctx
->stream
== NULL
)
1844 default_adjust
.out_color_space
= COLOR_SPACE_SRGB
;
1846 default_adjust
.out_color_space
=
1847 pipe_ctx
->stream
->public.output_color_space
;
1848 default_adjust
.csc_adjust_type
= GRAPHICS_CSC_ADJUST_TYPE_SW
;
1849 default_adjust
.surface_pixel_format
= pipe_ctx
->scl_data
.format
;
1851 /* display color depth */
1852 default_adjust
.color_depth
=
1853 pipe_ctx
->stream
->public.timing
.display_color_depth
;
1855 /* Lb color depth */
1856 default_adjust
.lb_color_depth
= pipe_ctx
->scl_data
.lb_params
.depth
;
1858 pipe_ctx
->opp
->funcs
->opp_set_csc_default(
1859 pipe_ctx
->opp
, &default_adjust
);
1863 /*******************************************************************************
1864 * In order to turn on/off specific surface we will program
1867 * In case that we have two surfaces and they have a different visibility
1868 * we can't turn off the CRTC since it will turn off the entire display
1870 * |----------------------------------------------- |
1871 * |bottom pipe|curr pipe | | |
1872 * |Surface |Surface | Blender | CRCT |
1873 * |visibility |visibility | Configuration| |
1874 * |------------------------------------------------|
1875 * | off | off | CURRENT_PIPE | blank |
1876 * | off | on | CURRENT_PIPE | unblank |
1877 * | on | off | OTHER_PIPE | unblank |
1878 * | on | on | BLENDING | unblank |
1879 * -------------------------------------------------|
1881 ******************************************************************************/
1882 static void program_surface_visibility(const struct core_dc
*dc
,
1883 struct pipe_ctx
*pipe_ctx
)
1885 enum blnd_mode blender_mode
= BLND_MODE_CURRENT_PIPE
;
1886 bool blank_target
= false;
1888 if (pipe_ctx
->bottom_pipe
) {
1890 /* For now we are supporting only two pipes */
1891 ASSERT(pipe_ctx
->bottom_pipe
->bottom_pipe
== NULL
);
1893 if (pipe_ctx
->bottom_pipe
->surface
->public.visible
) {
1894 if (pipe_ctx
->surface
->public.visible
)
1895 blender_mode
= BLND_MODE_BLENDING
;
1897 blender_mode
= BLND_MODE_OTHER_PIPE
;
1899 } else if (!pipe_ctx
->surface
->public.visible
)
1900 blank_target
= true;
1902 } else if (!pipe_ctx
->surface
->public.visible
)
1903 blank_target
= true;
1905 dce_set_blender_mode(dc
->hwseq
, pipe_ctx
->pipe_idx
, blender_mode
);
1906 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, blank_target
);
1911 * TODO REMOVE, USE UPDATE INSTEAD
1913 static void set_plane_config(
1914 const struct core_dc
*dc
,
1915 struct pipe_ctx
*pipe_ctx
,
1916 struct resource_context
*res_ctx
)
1918 struct mem_input
*mi
= pipe_ctx
->mi
;
1919 struct core_surface
*surface
= pipe_ctx
->surface
;
1920 struct xfm_grph_csc_adjustment adjust
;
1921 struct out_csc_color_matrix tbl_entry
;
1924 memset(&adjust
, 0, sizeof(adjust
));
1925 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
1926 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
1928 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
1930 set_default_colors(pipe_ctx
);
1931 if (pipe_ctx
->stream
->public.csc_color_matrix
.enable_adjustment
1933 tbl_entry
.color_space
=
1934 pipe_ctx
->stream
->public.output_color_space
;
1936 for (i
= 0; i
< 12; i
++)
1937 tbl_entry
.regval
[i
] =
1938 pipe_ctx
->stream
->public.csc_color_matrix
.matrix
[i
];
1940 pipe_ctx
->opp
->funcs
->opp_set_csc_adjustment
1941 (pipe_ctx
->opp
, &tbl_entry
);
1944 if (pipe_ctx
->stream
->public.gamut_remap_matrix
.enable_remap
== true) {
1945 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
1946 adjust
.temperature_matrix
[0] =
1948 public.gamut_remap_matrix
.matrix
[0];
1949 adjust
.temperature_matrix
[1] =
1951 public.gamut_remap_matrix
.matrix
[1];
1952 adjust
.temperature_matrix
[2] =
1954 public.gamut_remap_matrix
.matrix
[2];
1955 adjust
.temperature_matrix
[3] =
1957 public.gamut_remap_matrix
.matrix
[4];
1958 adjust
.temperature_matrix
[4] =
1960 public.gamut_remap_matrix
.matrix
[5];
1961 adjust
.temperature_matrix
[5] =
1963 public.gamut_remap_matrix
.matrix
[6];
1964 adjust
.temperature_matrix
[6] =
1966 public.gamut_remap_matrix
.matrix
[8];
1967 adjust
.temperature_matrix
[7] =
1969 public.gamut_remap_matrix
.matrix
[9];
1970 adjust
.temperature_matrix
[8] =
1972 public.gamut_remap_matrix
.matrix
[10];
1975 pipe_ctx
->xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->xfm
, &adjust
);
1977 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1978 program_scaler(dc
, pipe_ctx
);
1980 program_surface_visibility(dc
, pipe_ctx
);
1982 mi
->funcs
->mem_input_program_surface_config(
1984 surface
->public.format
,
1985 &surface
->public.tiling_info
,
1986 &surface
->public.plane_size
,
1987 surface
->public.rotation
,
1990 pipe_ctx
->surface
->public.visible
);
1992 if (dc
->public.config
.gpu_vm_support
)
1993 mi
->funcs
->mem_input_program_pte_vm(
1995 surface
->public.format
,
1996 &surface
->public.tiling_info
,
1997 surface
->public.rotation
);
2000 static void update_plane_addr(const struct core_dc
*dc
,
2001 struct pipe_ctx
*pipe_ctx
)
2003 struct core_surface
*surface
= pipe_ctx
->surface
;
2005 if (surface
== NULL
)
2008 pipe_ctx
->mi
->funcs
->mem_input_program_surface_flip_and_addr(
2010 &surface
->public.address
,
2011 surface
->public.flip_immediate
);
2013 surface
->status
.requested_address
= surface
->public.address
;
2016 void dce110_update_pending_status(struct pipe_ctx
*pipe_ctx
)
2018 struct core_surface
*surface
= pipe_ctx
->surface
;
2020 if (surface
== NULL
)
2023 surface
->status
.is_flip_pending
=
2024 pipe_ctx
->mi
->funcs
->mem_input_is_flip_pending(
2027 if (surface
->status
.is_flip_pending
&& !surface
->public.visible
)
2028 pipe_ctx
->mi
->current_address
= pipe_ctx
->mi
->request_address
;
2030 surface
->status
.current_address
= pipe_ctx
->mi
->current_address
;
2033 void dce110_power_down(struct core_dc
*dc
)
2035 power_down_all_hw_blocks(dc
);
2036 disable_vga_and_power_gate_all_controllers(dc
);
2039 static bool wait_for_reset_trigger_to_occur(
2040 struct dc_context
*dc_ctx
,
2041 struct timing_generator
*tg
)
2045 /* To avoid endless loop we wait at most
2046 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2047 const uint32_t frames_to_wait_on_triggered_reset
= 10;
2050 for (i
= 0; i
< frames_to_wait_on_triggered_reset
; i
++) {
2052 if (!tg
->funcs
->is_counter_moving(tg
)) {
2053 DC_ERROR("TG counter is not moving!\n");
2057 if (tg
->funcs
->did_triggered_reset_occur(tg
)) {
2059 /* usually occurs at i=1 */
2060 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2065 /* Wait for one frame. */
2066 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VACTIVE
);
2067 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VBLANK
);
2071 DC_ERROR("GSL: Timeout on reset trigger!\n");
2076 /* Enable timing synchronization for a group of Timing Generators. */
2077 static void dce110_enable_timing_synchronization(
2081 struct pipe_ctx
*grouped_pipes
[])
2083 struct dc_context
*dc_ctx
= dc
->ctx
;
2084 struct dcp_gsl_params gsl_params
= { 0 };
2087 DC_SYNC_INFO("GSL: Setting-up...\n");
2089 /* Designate a single TG in the group as a master.
2090 * Since HW doesn't care which one, we always assign
2091 * the 1st one in the group. */
2092 gsl_params
.gsl_group
= 0;
2093 gsl_params
.gsl_master
= grouped_pipes
[0]->tg
->inst
;
2095 for (i
= 0; i
< group_size
; i
++)
2096 grouped_pipes
[i
]->tg
->funcs
->setup_global_swap_lock(
2097 grouped_pipes
[i
]->tg
, &gsl_params
);
2099 /* Reset slave controllers on master VSync */
2100 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2102 for (i
= 1 /* skip the master */; i
< group_size
; i
++)
2103 grouped_pipes
[i
]->tg
->funcs
->enable_reset_trigger(
2104 grouped_pipes
[i
]->tg
, gsl_params
.gsl_group
);
2108 for (i
= 1 /* skip the master */; i
< group_size
; i
++) {
2109 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2110 wait_for_reset_trigger_to_occur(dc_ctx
, grouped_pipes
[i
]->tg
);
2111 /* Regardless of success of the wait above, remove the reset or
2112 * the driver will start timing out on Display requests. */
2113 DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
2114 grouped_pipes
[i
]->tg
->funcs
->disable_reset_trigger(grouped_pipes
[i
]->tg
);
2118 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2119 * is that the sync'ed displays will not drift out of sync over time*/
2120 DC_SYNC_INFO("GSL: Restoring register states.\n");
2121 for (i
= 0; i
< group_size
; i
++)
2122 grouped_pipes
[i
]->tg
->funcs
->tear_down_global_swap_lock(grouped_pipes
[i
]->tg
);
2124 DC_SYNC_INFO("GSL: Set-up complete.\n");
2127 static void init_hw(struct core_dc
*dc
)
2131 struct transform
*xfm
;
2134 bp
= dc
->ctx
->dc_bios
;
2135 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2136 xfm
= dc
->res_pool
->transforms
[i
];
2137 xfm
->funcs
->transform_reset(xfm
);
2139 dc
->hwss
.enable_display_power_gating(
2141 PIPE_GATING_CONTROL_INIT
);
2142 dc
->hwss
.enable_display_power_gating(
2144 PIPE_GATING_CONTROL_DISABLE
);
2145 dc
->hwss
.enable_display_pipe_clock_gating(
2150 dce_clock_gating_power_up(dc
->hwseq
, false);
2151 /***************************************/
2153 for (i
= 0; i
< dc
->link_count
; i
++) {
2154 /****************************************/
2155 /* Power up AND update implementation according to the
2156 * required signal (which may be different from the
2157 * default signal on connector). */
2158 struct core_link
*link
= dc
->links
[i
];
2159 link
->link_enc
->funcs
->hw_init(link
->link_enc
);
2162 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2163 struct timing_generator
*tg
= dc
->res_pool
->timing_generators
[i
];
2165 tg
->funcs
->disable_vga(tg
);
2167 /* Blank controller using driver code instead of
2169 tg
->funcs
->set_blank(tg
, true);
2170 hwss_wait_for_blank_complete(tg
);
2173 for (i
= 0; i
< dc
->res_pool
->audio_count
; i
++) {
2174 struct audio
*audio
= dc
->res_pool
->audios
[i
];
2175 audio
->funcs
->hw_init(audio
);
2178 abm
= dc
->res_pool
->abm
;
2180 abm
->funcs
->init_backlight(abm
);
2181 abm
->funcs
->abm_init(abm
);
2185 void dce110_fill_display_configs(
2186 const struct validate_context
*context
,
2187 struct dm_pp_display_configuration
*pp_display_cfg
)
2192 for (j
= 0; j
< context
->stream_count
; j
++) {
2195 const struct core_stream
*stream
= context
->streams
[j
];
2196 struct dm_pp_single_disp_config
*cfg
=
2197 &pp_display_cfg
->disp_configs
[num_cfgs
];
2198 const struct pipe_ctx
*pipe_ctx
= NULL
;
2200 for (k
= 0; k
< MAX_PIPES
; k
++)
2201 if (stream
== context
->res_ctx
.pipe_ctx
[k
].stream
) {
2202 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[k
];
2206 ASSERT(pipe_ctx
!= NULL
);
2209 cfg
->signal
= pipe_ctx
->stream
->signal
;
2210 cfg
->pipe_idx
= pipe_ctx
->pipe_idx
;
2211 cfg
->src_height
= stream
->public.src
.height
;
2212 cfg
->src_width
= stream
->public.src
.width
;
2213 cfg
->ddi_channel_mapping
=
2214 stream
->sink
->link
->ddi_channel_mapping
.raw
;
2216 stream
->sink
->link
->link_enc
->transmitter
;
2217 cfg
->link_settings
.lane_count
=
2218 stream
->sink
->link
->public.cur_link_settings
.lane_count
;
2219 cfg
->link_settings
.link_rate
=
2220 stream
->sink
->link
->public.cur_link_settings
.link_rate
;
2221 cfg
->link_settings
.link_spread
=
2222 stream
->sink
->link
->public.cur_link_settings
.link_spread
;
2223 cfg
->sym_clock
= stream
->phy_pix_clk
;
2224 /* Round v_refresh*/
2225 cfg
->v_refresh
= stream
->public.timing
.pix_clk_khz
* 1000;
2226 cfg
->v_refresh
/= stream
->public.timing
.h_total
;
2227 cfg
->v_refresh
= (cfg
->v_refresh
+ stream
->public.timing
.v_total
/ 2)
2228 / stream
->public.timing
.v_total
;
2231 pp_display_cfg
->display_count
= num_cfgs
;
2234 uint32_t dce110_get_min_vblank_time_us(const struct validate_context
*context
)
2237 uint32_t min_vertical_blank_time
= -1;
2239 for (j
= 0; j
< context
->stream_count
; j
++) {
2240 const struct dc_stream
*stream
= &context
->streams
[j
]->public;
2241 uint32_t vertical_blank_in_pixels
= 0;
2242 uint32_t vertical_blank_time
= 0;
2244 vertical_blank_in_pixels
= stream
->timing
.h_total
*
2245 (stream
->timing
.v_total
2246 - stream
->timing
.v_addressable
);
2248 vertical_blank_time
= vertical_blank_in_pixels
2249 * 1000 / stream
->timing
.pix_clk_khz
;
2251 if (min_vertical_blank_time
> vertical_blank_time
)
2252 min_vertical_blank_time
= vertical_blank_time
;
2255 return min_vertical_blank_time
;
2258 static int determine_sclk_from_bounding_box(
2259 const struct core_dc
*dc
,
2265 * Some asics do not give us sclk levels, so we just report the actual
2268 if (dc
->sclk_lvls
.num_levels
== 0)
2269 return required_sclk
;
2271 for (i
= 0; i
< dc
->sclk_lvls
.num_levels
; i
++) {
2272 if (dc
->sclk_lvls
.clocks_in_khz
[i
] >= required_sclk
)
2273 return dc
->sclk_lvls
.clocks_in_khz
[i
];
2276 * even maximum level could not satisfy requirement, this
2277 * is unexpected at this stage, should have been caught at
2281 return dc
->sclk_lvls
.clocks_in_khz
[dc
->sclk_lvls
.num_levels
- 1];
2284 static void pplib_apply_display_requirements(
2286 struct validate_context
*context
)
2288 struct dm_pp_display_configuration
*pp_display_cfg
= &context
->pp_display_cfg
;
2290 pp_display_cfg
->all_displays_in_sync
=
2291 context
->bw
.dce
.all_displays_in_sync
;
2292 pp_display_cfg
->nb_pstate_switch_disable
=
2293 context
->bw
.dce
.nbp_state_change_enable
== false;
2294 pp_display_cfg
->cpu_cc6_disable
=
2295 context
->bw
.dce
.cpuc_state_change_enable
== false;
2296 pp_display_cfg
->cpu_pstate_disable
=
2297 context
->bw
.dce
.cpup_state_change_enable
== false;
2298 pp_display_cfg
->cpu_pstate_separation_time
=
2299 context
->bw
.dce
.blackout_recovery_time_us
;
2301 pp_display_cfg
->min_memory_clock_khz
= context
->bw
.dce
.yclk_khz
2302 / MEMORY_TYPE_MULTIPLIER
;
2304 pp_display_cfg
->min_engine_clock_khz
= determine_sclk_from_bounding_box(
2306 context
->bw
.dce
.sclk_khz
);
2308 pp_display_cfg
->min_engine_clock_deep_sleep_khz
2309 = context
->bw
.dce
.sclk_deep_sleep_khz
;
2311 pp_display_cfg
->avail_mclk_switch_time_us
=
2312 dce110_get_min_vblank_time_us(context
);
2314 pp_display_cfg
->avail_mclk_switch_time_in_disp_active_us
= 0;
2316 pp_display_cfg
->disp_clk_khz
= context
->bw
.dce
.dispclk_khz
;
2318 dce110_fill_display_configs(context
, pp_display_cfg
);
2320 /* TODO: is this still applicable?*/
2321 if (pp_display_cfg
->display_count
== 1) {
2322 const struct dc_crtc_timing
*timing
=
2323 &context
->streams
[0]->public.timing
;
2325 pp_display_cfg
->crtc_index
=
2326 pp_display_cfg
->disp_configs
[0].pipe_idx
;
2327 pp_display_cfg
->line_time_in_us
= timing
->h_total
* 1000
2328 / timing
->pix_clk_khz
;
2331 if (memcmp(&dc
->prev_display_config
, pp_display_cfg
, sizeof(
2332 struct dm_pp_display_configuration
)) != 0)
2333 dm_pp_apply_display_requirements(dc
->ctx
, pp_display_cfg
);
2335 dc
->prev_display_config
= *pp_display_cfg
;
2338 static void dce110_set_bandwidth(
2340 struct validate_context
*context
,
2341 bool decrease_allowed
)
2343 dce110_set_displaymarks(dc
, context
);
2345 if (decrease_allowed
|| context
->bw
.dce
.dispclk_khz
> dc
->current_context
->bw
.dce
.dispclk_khz
) {
2346 dc
->res_pool
->display_clock
->funcs
->set_clock(
2347 dc
->res_pool
->display_clock
,
2348 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2349 dc
->current_context
->bw
.dce
.dispclk_khz
= context
->bw
.dce
.dispclk_khz
;
2352 pplib_apply_display_requirements(dc
, context
);
2355 static void dce110_program_front_end_for_pipe(
2356 struct core_dc
*dc
, struct pipe_ctx
*pipe_ctx
)
2358 struct mem_input
*mi
= pipe_ctx
->mi
;
2359 struct pipe_ctx
*old_pipe
= NULL
;
2360 struct core_surface
*surface
= pipe_ctx
->surface
;
2361 struct xfm_grph_csc_adjustment adjust
;
2362 struct out_csc_color_matrix tbl_entry
;
2365 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2367 if (dc
->current_context
)
2368 old_pipe
= &dc
->current_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2370 memset(&adjust
, 0, sizeof(adjust
));
2371 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2373 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2375 set_default_colors(pipe_ctx
);
2376 if (pipe_ctx
->stream
->public.csc_color_matrix
.enable_adjustment
2378 tbl_entry
.color_space
=
2379 pipe_ctx
->stream
->public.output_color_space
;
2381 for (i
= 0; i
< 12; i
++)
2382 tbl_entry
.regval
[i
] =
2383 pipe_ctx
->stream
->public.csc_color_matrix
.matrix
[i
];
2385 pipe_ctx
->opp
->funcs
->opp_set_csc_adjustment
2386 (pipe_ctx
->opp
, &tbl_entry
);
2389 if (pipe_ctx
->stream
->public.gamut_remap_matrix
.enable_remap
== true) {
2390 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2391 adjust
.temperature_matrix
[0] =
2393 public.gamut_remap_matrix
.matrix
[0];
2394 adjust
.temperature_matrix
[1] =
2396 public.gamut_remap_matrix
.matrix
[1];
2397 adjust
.temperature_matrix
[2] =
2399 public.gamut_remap_matrix
.matrix
[2];
2400 adjust
.temperature_matrix
[3] =
2402 public.gamut_remap_matrix
.matrix
[4];
2403 adjust
.temperature_matrix
[4] =
2405 public.gamut_remap_matrix
.matrix
[5];
2406 adjust
.temperature_matrix
[5] =
2408 public.gamut_remap_matrix
.matrix
[6];
2409 adjust
.temperature_matrix
[6] =
2411 public.gamut_remap_matrix
.matrix
[8];
2412 adjust
.temperature_matrix
[7] =
2414 public.gamut_remap_matrix
.matrix
[9];
2415 adjust
.temperature_matrix
[8] =
2417 public.gamut_remap_matrix
.matrix
[10];
2420 pipe_ctx
->xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->xfm
, &adjust
);
2422 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2423 if (old_pipe
&& memcmp(&old_pipe
->scl_data
,
2424 &pipe_ctx
->scl_data
,
2425 sizeof(struct scaler_data
)) != 0)
2426 program_scaler(dc
, pipe_ctx
);
2428 mi
->funcs
->mem_input_program_surface_config(
2430 surface
->public.format
,
2431 &surface
->public.tiling_info
,
2432 &surface
->public.plane_size
,
2433 surface
->public.rotation
,
2436 pipe_ctx
->surface
->public.visible
);
2438 if (dc
->public.config
.gpu_vm_support
)
2439 mi
->funcs
->mem_input_program_pte_vm(
2441 surface
->public.format
,
2442 &surface
->public.tiling_info
,
2443 surface
->public.rotation
);
2445 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2446 "Pipe:%d 0x%x: addr hi:0x%x, "
2449 " %d; dst: %d, %d, %d, %d;"
2450 "clip: %d, %d, %d, %d\n",
2453 pipe_ctx
->surface
->public.address
.grph
.addr
.high_part
,
2454 pipe_ctx
->surface
->public.address
.grph
.addr
.low_part
,
2455 pipe_ctx
->surface
->public.src_rect
.x
,
2456 pipe_ctx
->surface
->public.src_rect
.y
,
2457 pipe_ctx
->surface
->public.src_rect
.width
,
2458 pipe_ctx
->surface
->public.src_rect
.height
,
2459 pipe_ctx
->surface
->public.dst_rect
.x
,
2460 pipe_ctx
->surface
->public.dst_rect
.y
,
2461 pipe_ctx
->surface
->public.dst_rect
.width
,
2462 pipe_ctx
->surface
->public.dst_rect
.height
,
2463 pipe_ctx
->surface
->public.clip_rect
.x
,
2464 pipe_ctx
->surface
->public.clip_rect
.y
,
2465 pipe_ctx
->surface
->public.clip_rect
.width
,
2466 pipe_ctx
->surface
->public.clip_rect
.height
);
2468 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2469 "Pipe %d: width, height, x, y\n"
2470 "viewport:%d, %d, %d, %d\n"
2471 "recout: %d, %d, %d, %d\n",
2473 pipe_ctx
->scl_data
.viewport
.width
,
2474 pipe_ctx
->scl_data
.viewport
.height
,
2475 pipe_ctx
->scl_data
.viewport
.x
,
2476 pipe_ctx
->scl_data
.viewport
.y
,
2477 pipe_ctx
->scl_data
.recout
.width
,
2478 pipe_ctx
->scl_data
.recout
.height
,
2479 pipe_ctx
->scl_data
.recout
.x
,
2480 pipe_ctx
->scl_data
.recout
.y
);
2483 static void dce110_apply_ctx_for_surface(
2485 struct core_surface
*surface
,
2486 struct validate_context
*context
)
2490 /* TODO remove when removing the surface reset workaroud*/
2494 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2495 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2497 if (pipe_ctx
->surface
!= surface
)
2500 dce110_program_front_end_for_pipe(dc
, pipe_ctx
);
2501 program_surface_visibility(dc
, pipe_ctx
);
2506 static void dce110_power_down_fe(struct core_dc
*dc
, struct pipe_ctx
*pipe
)
2510 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++)
2511 if (&dc
->current_context
->res_ctx
.pipe_ctx
[i
] == pipe
)
2514 if (i
== dc
->res_pool
->pipe_count
)
2517 dc
->hwss
.enable_display_power_gating(
2518 dc
, i
, dc
->ctx
->dc_bios
, PIPE_GATING_CONTROL_ENABLE
);
2520 pipe
->xfm
->funcs
->transform_reset(pipe
->xfm
);
2521 memset(&pipe
->scl_data
, 0, sizeof(struct scaler_data
));
2524 static const struct hw_sequencer_funcs dce110_funcs
= {
2526 .apply_ctx_to_hw
= dce110_apply_ctx_to_hw
,
2527 .apply_ctx_for_surface
= dce110_apply_ctx_for_surface
,
2528 .set_plane_config
= set_plane_config
,
2529 .update_plane_addr
= update_plane_addr
,
2530 .update_pending_status
= dce110_update_pending_status
,
2531 .set_input_transfer_func
= dce110_set_input_transfer_func
,
2532 .set_output_transfer_func
= dce110_set_output_transfer_func
,
2533 .power_down
= dce110_power_down
,
2534 .enable_accelerated_mode
= dce110_enable_accelerated_mode
,
2535 .enable_timing_synchronization
= dce110_enable_timing_synchronization
,
2536 .update_info_frame
= dce110_update_info_frame
,
2537 .enable_stream
= dce110_enable_stream
,
2538 .disable_stream
= dce110_disable_stream
,
2539 .unblank_stream
= dce110_unblank_stream
,
2540 .enable_display_pipe_clock_gating
= enable_display_pipe_clock_gating
,
2541 .enable_display_power_gating
= dce110_enable_display_power_gating
,
2542 .power_down_front_end
= dce110_power_down_fe
,
2543 .pipe_control_lock
= dce_pipe_control_lock
,
2544 .set_bandwidth
= dce110_set_bandwidth
,
2546 .get_position
= get_position
,
2547 .set_static_screen_control
= set_static_screen_control
,
2548 .reset_hw_ctx_wrap
= reset_hw_ctx_wrap
,
2549 .prog_pixclk_crtc_otg
= dce110_prog_pixclk_crtc_otg
,
2552 bool dce110_hw_sequencer_construct(struct core_dc
*dc
)
2554 dc
->hwss
= dce110_funcs
;