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"
46 #include "dce/dce_hwseq.h"
48 /* include DCE11 register header files */
49 #include "dce/dce_11_0_d.h"
50 #include "dce/dce_11_0_sh_mask.h"
52 struct dce110_hw_seq_reg_offsets
{
56 static const struct dce110_hw_seq_reg_offsets reg_offsets
[] = {
58 .crtc
= (mmCRTC0_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
61 .crtc
= (mmCRTC1_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
64 .crtc
= (mmCRTC2_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
67 .crtc
= (mmCRTCV_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
71 #define HW_REG_BLND(reg, id)\
72 (reg + reg_offsets[id].blnd)
74 #define HW_REG_CRTC(reg, id)\
75 (reg + reg_offsets[id].crtc)
77 #define MAX_WATERMARK 0xFFFF
78 #define SAFE_NBP_MARK 0x7FFF
80 /*******************************************************************************
82 ******************************************************************************/
83 /***************************PIPE_CONTROL***********************************/
84 static void dce110_init_pte(struct dc_context
*ctx
)
88 uint32_t chunk_int
= 0;
89 uint32_t chunk_mul
= 0;
91 addr
= mmUNP_DVMM_PTE_CONTROL
;
92 value
= dm_read_reg(ctx
, addr
);
104 DVMM_PTE_BUFFER_MODE0
);
110 DVMM_PTE_BUFFER_MODE1
);
112 dm_write_reg(ctx
, addr
, value
);
114 addr
= mmDVMM_PTE_REQ
;
115 value
= dm_read_reg(ctx
, addr
);
117 chunk_int
= get_reg_field_value(
120 HFLIP_PTEREQ_PER_CHUNK_INT
);
122 chunk_mul
= get_reg_field_value(
125 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
127 if (chunk_int
!= 0x4 || chunk_mul
!= 0x4) {
133 MAX_PTEREQ_TO_ISSUE
);
139 HFLIP_PTEREQ_PER_CHUNK_INT
);
145 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
147 dm_write_reg(ctx
, addr
, value
);
150 /**************************************************************************/
152 static void enable_display_pipe_clock_gating(
153 struct dc_context
*ctx
,
159 static bool dce110_enable_display_power_gating(
161 uint8_t controller_id
,
163 enum pipe_gating_control power_gating
)
165 enum bp_result bp_result
= BP_RESULT_OK
;
166 enum bp_pipe_control_action cntl
;
167 struct dc_context
*ctx
= dc
->ctx
;
168 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
170 if (IS_FPGA_MAXIMUS_DC(ctx
->dce_environment
))
173 if (power_gating
== PIPE_GATING_CONTROL_INIT
)
174 cntl
= ASIC_PIPE_INIT
;
175 else if (power_gating
== PIPE_GATING_CONTROL_ENABLE
)
176 cntl
= ASIC_PIPE_ENABLE
;
178 cntl
= ASIC_PIPE_DISABLE
;
180 if (controller_id
== underlay_idx
)
181 controller_id
= CONTROLLER_ID_UNDERLAY0
- 1;
183 if (power_gating
!= PIPE_GATING_CONTROL_INIT
|| controller_id
== 0){
185 bp_result
= dcb
->funcs
->enable_disp_power_gating(
186 dcb
, controller_id
+ 1, cntl
);
188 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
189 * by default when command table is called
191 * Bios parser accepts controller_id = 6 as indicative of
192 * underlay pipe in dce110. But we do not support more
195 if (controller_id
< CONTROLLER_ID_MAX
- 1)
197 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE
, controller_id
),
201 if (power_gating
!= PIPE_GATING_CONTROL_ENABLE
)
202 dce110_init_pte(ctx
);
204 if (bp_result
== BP_RESULT_OK
)
210 static void build_prescale_params(struct ipp_prescale_params
*prescale_params
,
211 const struct core_surface
*surface
)
213 prescale_params
->mode
= IPP_PRESCALE_MODE_FIXED_UNSIGNED
;
215 switch (surface
->public.format
) {
216 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888
:
217 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888
:
218 prescale_params
->scale
= 0x2020;
220 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010
:
221 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010
:
222 prescale_params
->scale
= 0x2008;
224 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616
:
225 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F
:
226 prescale_params
->scale
= 0x2000;
234 static bool dce110_set_input_transfer_func(
235 struct pipe_ctx
*pipe_ctx
,
236 const struct core_surface
*surface
)
238 struct input_pixel_processor
*ipp
= pipe_ctx
->ipp
;
239 const struct core_transfer_func
*tf
= NULL
;
240 struct ipp_prescale_params prescale_params
= { 0 };
246 if (surface
->public.in_transfer_func
)
247 tf
= DC_TRANSFER_FUNC_TO_CORE(surface
->public.in_transfer_func
);
249 build_prescale_params(&prescale_params
, surface
);
250 ipp
->funcs
->ipp_program_prescale(ipp
, &prescale_params
);
252 if (surface
->public.gamma_correction
)
253 ipp
->funcs
->ipp_program_input_lut(ipp
, surface
->public.gamma_correction
);
256 /* Default case if no input transfer function specified */
257 ipp
->funcs
->ipp_set_degamma(ipp
,
258 IPP_DEGAMMA_MODE_HW_sRGB
);
259 } else if (tf
->public.type
== TF_TYPE_PREDEFINED
) {
260 switch (tf
->public.tf
) {
261 case TRANSFER_FUNCTION_SRGB
:
262 ipp
->funcs
->ipp_set_degamma(ipp
,
263 IPP_DEGAMMA_MODE_HW_sRGB
);
265 case TRANSFER_FUNCTION_BT709
:
266 ipp
->funcs
->ipp_set_degamma(ipp
,
267 IPP_DEGAMMA_MODE_HW_xvYCC
);
269 case TRANSFER_FUNCTION_LINEAR
:
270 ipp
->funcs
->ipp_set_degamma(ipp
,
271 IPP_DEGAMMA_MODE_BYPASS
);
273 case TRANSFER_FUNCTION_PQ
:
281 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
288 static bool build_custom_float(
289 struct fixed31_32 value
,
290 const struct custom_float_format
*format
,
295 uint32_t exp_offset
= (1 << (format
->exponenta_bits
- 1)) - 1;
297 const struct fixed31_32 mantissa_constant_plus_max_fraction
=
298 dal_fixed31_32_from_fraction(
299 (1LL << (format
->mantissa_bits
+ 1)) - 1,
300 1LL << format
->mantissa_bits
);
302 struct fixed31_32 mantiss
;
304 if (dal_fixed31_32_eq(
306 dal_fixed31_32_zero
)) {
313 if (dal_fixed31_32_lt(
315 dal_fixed31_32_zero
)) {
316 *negative
= format
->sign
;
317 value
= dal_fixed31_32_neg(value
);
322 if (dal_fixed31_32_lt(
324 dal_fixed31_32_one
)) {
328 value
= dal_fixed31_32_shl(value
, 1);
330 } while (dal_fixed31_32_lt(
332 dal_fixed31_32_one
));
336 if (exp_offset
<= i
) {
342 *exponenta
= exp_offset
- i
;
343 } else if (dal_fixed31_32_le(
344 mantissa_constant_plus_max_fraction
,
349 value
= dal_fixed31_32_shr(value
, 1);
351 } while (dal_fixed31_32_lt(
352 mantissa_constant_plus_max_fraction
,
355 *exponenta
= exp_offset
+ i
- 1;
357 *exponenta
= exp_offset
;
360 mantiss
= dal_fixed31_32_sub(
364 if (dal_fixed31_32_lt(
366 dal_fixed31_32_zero
) ||
370 mantiss
= dal_fixed31_32_zero
;
372 mantiss
= dal_fixed31_32_shl(
374 format
->mantissa_bits
);
376 *mantissa
= dal_fixed31_32_floor(mantiss
);
381 static bool setup_custom_float(
382 const struct custom_float_format
*format
,
393 /* verification code:
394 * once calculation is ok we can remove it
397 const uint32_t mantissa_mask
=
398 (1 << (format
->mantissa_bits
+ 1)) - 1;
400 const uint32_t exponenta_mask
=
401 (1 << (format
->exponenta_bits
+ 1)) - 1;
403 if (mantissa
& ~mantissa_mask
) {
405 mantissa
= mantissa_mask
;
408 if (exponenta
& ~exponenta_mask
) {
410 exponenta
= exponenta_mask
;
413 /* end of verification code */
415 while (i
< format
->mantissa_bits
) {
416 uint32_t mask
= 1 << i
;
424 while (j
< format
->exponenta_bits
) {
425 uint32_t mask
= 1 << j
;
427 if (exponenta
& mask
)
433 if (negative
&& format
->sign
)
434 value
|= 1 << (i
+ j
);
441 static bool convert_to_custom_float_format(
442 struct fixed31_32 value
,
443 const struct custom_float_format
*format
,
450 return build_custom_float(
451 value
, format
, &negative
, &mantissa
, &exponenta
) &&
453 format
, negative
, mantissa
, exponenta
, result
);
456 static bool convert_to_custom_float(
457 struct pwl_result_data
*rgb_resulted
,
458 struct curve_points
*arr_points
,
459 uint32_t hw_points_num
)
461 struct custom_float_format fmt
;
463 struct pwl_result_data
*rgb
= rgb_resulted
;
467 fmt
.exponenta_bits
= 6;
468 fmt
.mantissa_bits
= 12;
471 if (!convert_to_custom_float_format(
474 &arr_points
[0].custom_float_x
)) {
479 if (!convert_to_custom_float_format(
480 arr_points
[0].offset
,
482 &arr_points
[0].custom_float_offset
)) {
487 if (!convert_to_custom_float_format(
490 &arr_points
[0].custom_float_slope
)) {
495 fmt
.mantissa_bits
= 10;
498 if (!convert_to_custom_float_format(
501 &arr_points
[1].custom_float_x
)) {
506 if (!convert_to_custom_float_format(
509 &arr_points
[1].custom_float_y
)) {
514 if (!convert_to_custom_float_format(
517 &arr_points
[2].custom_float_slope
)) {
522 fmt
.mantissa_bits
= 12;
525 while (i
!= hw_points_num
) {
526 if (!convert_to_custom_float_format(
534 if (!convert_to_custom_float_format(
542 if (!convert_to_custom_float_format(
550 if (!convert_to_custom_float_format(
553 &rgb
->delta_red_reg
)) {
558 if (!convert_to_custom_float_format(
561 &rgb
->delta_green_reg
)) {
566 if (!convert_to_custom_float_format(
569 &rgb
->delta_blue_reg
)) {
581 static bool dce110_translate_regamma_to_hw_format(const struct dc_transfer_func
582 *output_tf
, struct pwl_params
*regamma_params
)
584 if (output_tf
== NULL
|| regamma_params
== NULL
)
587 struct gamma_curve
*arr_curve_points
= regamma_params
->arr_curve_points
;
588 struct curve_points
*arr_points
= regamma_params
->arr_points
;
589 struct pwl_result_data
*rgb_resulted
= regamma_params
->rgb_resulted
;
590 struct fixed31_32 y_r
;
591 struct fixed31_32 y_g
;
592 struct fixed31_32 y_b
;
593 struct fixed31_32 y1_min
;
594 struct fixed31_32 y3_max
;
596 int32_t segment_start
, segment_end
;
597 uint32_t i
, j
, k
, seg_distr
[16], increment
, start_index
;
598 uint32_t hw_points
= 0;
600 memset(regamma_params
, 0, sizeof(struct pwl_params
));
602 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
604 * segments are from 2^-11 to 2^5
628 * segment is from 2^-10 to 2^0
651 for (k
= 0; k
< 16; k
++) {
652 if (seg_distr
[k
] != -1)
653 hw_points
+= (1 << seg_distr
[k
]);
657 for (k
= 0; k
< (segment_end
- segment_start
); k
++) {
658 increment
= 32 / (1 << seg_distr
[k
]);
659 start_index
= (segment_start
+ k
+ 25) * 32;
660 for (i
= start_index
; i
< start_index
+ 32; i
+= increment
) {
661 if (j
== hw_points
- 1)
663 rgb_resulted
[j
].red
= output_tf
->tf_pts
.red
[i
];
664 rgb_resulted
[j
].green
= output_tf
->tf_pts
.green
[i
];
665 rgb_resulted
[j
].blue
= output_tf
->tf_pts
.blue
[i
];
671 start_index
= (segment_end
+ 25) * 32;
672 rgb_resulted
[hw_points
- 1].red
=
673 output_tf
->tf_pts
.red
[start_index
];
674 rgb_resulted
[hw_points
- 1].green
=
675 output_tf
->tf_pts
.green
[start_index
];
676 rgb_resulted
[hw_points
- 1].blue
=
677 output_tf
->tf_pts
.blue
[start_index
];
679 arr_points
[0].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
680 dal_fixed31_32_from_int(segment_start
));
681 arr_points
[1].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
682 dal_fixed31_32_from_int(segment_end
));
683 arr_points
[2].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
684 dal_fixed31_32_from_int(segment_end
));
686 y_r
= rgb_resulted
[0].red
;
687 y_g
= rgb_resulted
[0].green
;
688 y_b
= rgb_resulted
[0].blue
;
690 y1_min
= dal_fixed31_32_min(y_r
, dal_fixed31_32_min(y_g
, y_b
));
692 arr_points
[0].y
= y1_min
;
693 arr_points
[0].slope
= dal_fixed31_32_div(
697 y_r
= rgb_resulted
[hw_points
- 1].red
;
698 y_g
= rgb_resulted
[hw_points
- 1].green
;
699 y_b
= rgb_resulted
[hw_points
- 1].blue
;
701 /* see comment above, m_arrPoints[1].y should be the Y value for the
702 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
704 y3_max
= dal_fixed31_32_max(y_r
, dal_fixed31_32_max(y_g
, y_b
));
706 arr_points
[1].y
= y3_max
;
707 arr_points
[2].y
= y3_max
;
709 arr_points
[1].slope
= dal_fixed31_32_zero
;
710 arr_points
[2].slope
= dal_fixed31_32_zero
;
712 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
713 /* for PQ, we want to have a straight line from last HW X point,
714 * and the slope to be such that we hit 1.0 at 10000 nits.
716 const struct fixed31_32 end_value
=
717 dal_fixed31_32_from_int(125);
719 arr_points
[1].slope
= dal_fixed31_32_div(
720 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
721 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
722 arr_points
[2].slope
= dal_fixed31_32_div(
723 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
724 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
727 regamma_params
->hw_points_num
= hw_points
;
730 for (k
= 0; k
< 16 && i
< 16; k
++) {
731 if (seg_distr
[k
] != -1) {
732 regamma_params
->arr_curve_points
[k
].segments_num
=
734 regamma_params
->arr_curve_points
[i
].offset
=
735 regamma_params
->arr_curve_points
[k
].
736 offset
+ (1 << seg_distr
[k
]);
741 if (seg_distr
[k
] != -1)
742 regamma_params
->arr_curve_points
[k
].segments_num
=
745 struct pwl_result_data
*rgb
= rgb_resulted
;
746 struct pwl_result_data
*rgb_plus_1
= rgb_resulted
+ 1;
750 while (i
!= hw_points
+ 1) {
751 if (dal_fixed31_32_lt(rgb_plus_1
->red
, rgb
->red
))
752 rgb_plus_1
->red
= rgb
->red
;
753 if (dal_fixed31_32_lt(rgb_plus_1
->green
, rgb
->green
))
754 rgb_plus_1
->green
= rgb
->green
;
755 if (dal_fixed31_32_lt(rgb_plus_1
->blue
, rgb
->blue
))
756 rgb_plus_1
->blue
= rgb
->blue
;
758 rgb
->delta_red
= dal_fixed31_32_sub(
761 rgb
->delta_green
= dal_fixed31_32_sub(
764 rgb
->delta_blue
= dal_fixed31_32_sub(
773 convert_to_custom_float(rgb_resulted
, arr_points
, hw_points
);
778 static bool dce110_set_output_transfer_func(
779 struct pipe_ctx
*pipe_ctx
,
780 const struct core_surface
*surface
, /* Surface - To be removed */
781 const struct core_stream
*stream
)
783 struct output_pixel_processor
*opp
= pipe_ctx
->opp
;
785 opp
->funcs
->opp_power_on_regamma_lut(opp
, true);
786 opp
->regamma_params
->hw_points_num
= GAMMA_HW_POINTS_NUM
;
788 if (stream
->public.out_transfer_func
&&
789 stream
->public.out_transfer_func
->type
==
790 TF_TYPE_PREDEFINED
&&
791 stream
->public.out_transfer_func
->tf
==
792 TRANSFER_FUNCTION_SRGB
) {
793 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_SRGB
);
794 } else if (dce110_translate_regamma_to_hw_format(
795 stream
->public.out_transfer_func
, opp
->regamma_params
)) {
796 opp
->funcs
->opp_program_regamma_pwl(opp
, opp
->regamma_params
);
797 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_USER
);
799 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_BYPASS
);
802 opp
->funcs
->opp_power_on_regamma_lut(opp
, false);
807 static enum dc_status
bios_parser_crtc_source_select(
808 struct pipe_ctx
*pipe_ctx
)
811 /* call VBIOS table to set CRTC source for the HW
813 * note: video bios clears all FMT setting here. */
814 struct bp_crtc_source_select crtc_source_select
= {0};
815 const struct core_sink
*sink
= pipe_ctx
->stream
->sink
;
817 crtc_source_select
.engine_id
= pipe_ctx
->stream_enc
->id
;
818 crtc_source_select
.controller_id
= pipe_ctx
->pipe_idx
+ 1;
819 /*TODO: Need to un-hardcode color depth, dp_audio and account for
820 * the case where signal and sink signal is different (translator
822 crtc_source_select
.signal
= pipe_ctx
->stream
->signal
;
823 crtc_source_select
.enable_dp_audio
= false;
824 crtc_source_select
.sink_signal
= pipe_ctx
->stream
->signal
;
825 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
827 dcb
= sink
->ctx
->dc_bios
;
829 if (BP_RESULT_OK
!= dcb
->funcs
->crtc_source_select(
831 &crtc_source_select
)) {
832 return DC_ERROR_UNEXPECTED
;
838 void dce110_update_info_frame(struct pipe_ctx
*pipe_ctx
)
840 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
841 pipe_ctx
->stream_enc
->funcs
->update_hdmi_info_packets(
842 pipe_ctx
->stream_enc
,
843 &pipe_ctx
->encoder_info_frame
);
844 else if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
845 pipe_ctx
->stream_enc
->funcs
->update_dp_info_packets(
846 pipe_ctx
->stream_enc
,
847 &pipe_ctx
->encoder_info_frame
);
850 void dce110_enable_stream(struct pipe_ctx
*pipe_ctx
)
852 enum dc_lane_count lane_count
=
853 pipe_ctx
->stream
->sink
->link
->public.cur_link_settings
.lane_count
;
855 struct dc_crtc_timing
*timing
= &pipe_ctx
->stream
->public.timing
;
856 struct core_link
*link
= pipe_ctx
->stream
->sink
->link
;
858 /* 1. update AVI info frame (HDMI, DP)
859 * we always need to update info frame
861 uint32_t active_total_with_borders
;
862 uint32_t early_control
= 0;
863 struct timing_generator
*tg
= pipe_ctx
->tg
;
865 /* TODOFPGA may change to hwss.update_info_frame */
866 dce110_update_info_frame(pipe_ctx
);
867 /* enable early control to avoid corruption on DP monitor*/
868 active_total_with_borders
=
869 timing
->h_addressable
870 + timing
->h_border_left
871 + timing
->h_border_right
;
874 early_control
= active_total_with_borders
% lane_count
;
876 if (early_control
== 0)
877 early_control
= lane_count
;
879 tg
->funcs
->set_early_control(tg
, early_control
);
881 /* enable audio only within mode set */
882 if (pipe_ctx
->audio
!= NULL
) {
883 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
884 pipe_ctx
->stream_enc
->funcs
->dp_audio_enable(pipe_ctx
->stream_enc
);
887 /* For MST, there are multiply stream go to only one link.
888 * connect DIG back_end to front_end while enable_stream and
889 * disconnect them during disable_stream
890 * BY this, it is logic clean to separate stream and link */
891 link
->link_enc
->funcs
->connect_dig_be_to_fe(link
->link_enc
,
892 pipe_ctx
->stream_enc
->id
, true);
896 void dce110_disable_stream(struct pipe_ctx
*pipe_ctx
)
898 struct core_stream
*stream
= pipe_ctx
->stream
;
899 struct core_link
*link
= stream
->sink
->link
;
901 if (pipe_ctx
->audio
) {
902 pipe_ctx
->audio
->funcs
->az_disable(pipe_ctx
->audio
);
904 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
905 pipe_ctx
->stream_enc
->funcs
->dp_audio_disable(
906 pipe_ctx
->stream_enc
);
908 pipe_ctx
->stream_enc
->funcs
->hdmi_audio_disable(
909 pipe_ctx
->stream_enc
);
911 pipe_ctx
->audio
= NULL
;
913 /* TODO: notify audio driver for if audio modes list changed
914 * add audio mode list change flag */
915 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
916 * stream->stream_engine_id);
920 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
921 pipe_ctx
->stream_enc
->funcs
->stop_hdmi_info_packets(
922 pipe_ctx
->stream_enc
);
924 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
925 pipe_ctx
->stream_enc
->funcs
->stop_dp_info_packets(
926 pipe_ctx
->stream_enc
);
928 pipe_ctx
->stream_enc
->funcs
->audio_mute_control(
929 pipe_ctx
->stream_enc
, true);
932 /* blank at encoder level */
933 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
934 pipe_ctx
->stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_enc
);
936 link
->link_enc
->funcs
->connect_dig_be_to_fe(
938 pipe_ctx
->stream_enc
->id
,
943 void dce110_unblank_stream(struct pipe_ctx
*pipe_ctx
,
944 struct dc_link_settings
*link_settings
)
946 struct encoder_unblank_param params
= { { 0 } };
948 /* only 3 items below are used by unblank */
949 params
.pixel_clk_khz
=
950 pipe_ctx
->stream
->public.timing
.pix_clk_khz
;
951 params
.link_settings
.link_rate
= link_settings
->link_rate
;
952 pipe_ctx
->stream_enc
->funcs
->dp_unblank(pipe_ctx
->stream_enc
, ¶ms
);
955 static enum audio_dto_source
translate_to_dto_source(enum controller_id crtc_id
)
958 case CONTROLLER_ID_D0
:
959 return DTO_SOURCE_ID0
;
960 case CONTROLLER_ID_D1
:
961 return DTO_SOURCE_ID1
;
962 case CONTROLLER_ID_D2
:
963 return DTO_SOURCE_ID2
;
964 case CONTROLLER_ID_D3
:
965 return DTO_SOURCE_ID3
;
966 case CONTROLLER_ID_D4
:
967 return DTO_SOURCE_ID4
;
968 case CONTROLLER_ID_D5
:
969 return DTO_SOURCE_ID5
;
971 return DTO_SOURCE_UNKNOWN
;
975 static void build_audio_output(
976 const struct pipe_ctx
*pipe_ctx
,
977 struct audio_output
*audio_output
)
979 const struct core_stream
*stream
= pipe_ctx
->stream
;
980 audio_output
->engine_id
= pipe_ctx
->stream_enc
->id
;
982 audio_output
->signal
= pipe_ctx
->stream
->signal
;
984 /* audio_crtc_info */
986 audio_output
->crtc_info
.h_total
=
987 stream
->public.timing
.h_total
;
990 * Audio packets are sent during actual CRTC blank physical signal, we
991 * need to specify actual active signal portion
993 audio_output
->crtc_info
.h_active
=
994 stream
->public.timing
.h_addressable
995 + stream
->public.timing
.h_border_left
996 + stream
->public.timing
.h_border_right
;
998 audio_output
->crtc_info
.v_active
=
999 stream
->public.timing
.v_addressable
1000 + stream
->public.timing
.v_border_top
1001 + stream
->public.timing
.v_border_bottom
;
1003 audio_output
->crtc_info
.pixel_repetition
= 1;
1005 audio_output
->crtc_info
.interlaced
=
1006 stream
->public.timing
.flags
.INTERLACE
;
1008 audio_output
->crtc_info
.refresh_rate
=
1009 (stream
->public.timing
.pix_clk_khz
*1000)/
1010 (stream
->public.timing
.h_total
*stream
->public.timing
.v_total
);
1012 audio_output
->crtc_info
.color_depth
=
1013 stream
->public.timing
.display_color_depth
;
1015 audio_output
->crtc_info
.requested_pixel_clock
=
1016 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1019 * TODO - Investigate why calculated pixel clk has to be
1020 * requested pixel clk
1022 audio_output
->crtc_info
.calculated_pixel_clock
=
1023 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1025 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT
||
1026 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
1027 audio_output
->pll_info
.dp_dto_source_clock_in_khz
=
1028 pipe_ctx
->dis_clk
->funcs
->get_dp_ref_clk_frequency(
1032 audio_output
->pll_info
.feed_back_divider
=
1033 pipe_ctx
->pll_settings
.feedback_divider
;
1035 audio_output
->pll_info
.dto_source
=
1036 translate_to_dto_source(
1037 pipe_ctx
->pipe_idx
+ 1);
1039 /* TODO hard code to enable for now. Need get from stream */
1040 audio_output
->pll_info
.ss_enabled
= true;
1042 audio_output
->pll_info
.ss_percentage
=
1043 pipe_ctx
->pll_settings
.ss_percentage
;
1046 static void get_surface_visual_confirm_color(const struct pipe_ctx
*pipe_ctx
,
1047 struct tg_color
*color
)
1049 uint32_t color_value
= MAX_TG_COLOR_VALUE
* (4 - pipe_ctx
->pipe_idx
) / 4;
1051 switch (pipe_ctx
->scl_data
.format
) {
1052 case PIXEL_FORMAT_ARGB8888
:
1053 /* set boarder color to red */
1054 color
->color_r_cr
= color_value
;
1057 case PIXEL_FORMAT_ARGB2101010
:
1058 /* set boarder color to blue */
1059 color
->color_b_cb
= color_value
;
1061 case PIXEL_FORMAT_420BPP12
:
1062 /* set boarder color to green */
1063 color
->color_g_y
= color_value
;
1065 case PIXEL_FORMAT_FP16
:
1066 /* set boarder color to white */
1067 color
->color_r_cr
= color_value
;
1068 color
->color_b_cb
= color_value
;
1069 color
->color_g_y
= color_value
;
1076 static void program_scaler(const struct core_dc
*dc
,
1077 const struct pipe_ctx
*pipe_ctx
)
1079 struct tg_color color
= {0};
1081 if (dc
->public.debug
.surface_visual_confirm
)
1082 get_surface_visual_confirm_color(pipe_ctx
, &color
);
1084 color_space_to_black_color(dc
,
1085 pipe_ctx
->stream
->public.output_color_space
,
1088 pipe_ctx
->xfm
->funcs
->transform_set_pixel_storage_depth(
1090 pipe_ctx
->scl_data
.lb_params
.depth
,
1091 &pipe_ctx
->stream
->bit_depth_params
);
1093 if (pipe_ctx
->tg
->funcs
->set_overscan_blank_color
)
1094 pipe_ctx
->tg
->funcs
->set_overscan_blank_color(
1098 pipe_ctx
->xfm
->funcs
->transform_set_scaler(pipe_ctx
->xfm
,
1099 &pipe_ctx
->scl_data
);
1102 static enum dc_status
dce110_prog_pixclk_crtc_otg(
1103 struct pipe_ctx
*pipe_ctx
,
1104 struct validate_context
*context
,
1107 struct core_stream
*stream
= pipe_ctx
->stream
;
1108 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_context
->res_ctx
.
1109 pipe_ctx
[pipe_ctx
->pipe_idx
];
1110 struct tg_color black_color
= {0};
1112 if (!pipe_ctx_old
->stream
) {
1114 /* program blank color */
1115 color_space_to_black_color(dc
,
1116 stream
->public.output_color_space
, &black_color
);
1117 pipe_ctx
->tg
->funcs
->set_blank_color(
1122 * Must blank CRTC after disabling power gating and before any
1123 * programming, otherwise CRTC will be hung in bad state
1125 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, true);
1127 if (false == pipe_ctx
->clock_source
->funcs
->program_pix_clk(
1128 pipe_ctx
->clock_source
,
1129 &pipe_ctx
->pix_clk_params
,
1130 &pipe_ctx
->pll_settings
)) {
1131 BREAK_TO_DEBUGGER();
1132 return DC_ERROR_UNEXPECTED
;
1135 pipe_ctx
->tg
->funcs
->program_timing(
1137 &stream
->public.timing
,
1141 if (!pipe_ctx_old
->stream
) {
1142 if (false == pipe_ctx
->tg
->funcs
->enable_crtc(
1144 BREAK_TO_DEBUGGER();
1145 return DC_ERROR_UNEXPECTED
;
1152 static enum dc_status
apply_single_controller_ctx_to_hw(
1153 struct pipe_ctx
*pipe_ctx
,
1154 struct validate_context
*context
,
1157 struct core_stream
*stream
= pipe_ctx
->stream
;
1158 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_context
->res_ctx
.
1159 pipe_ctx
[pipe_ctx
->pipe_idx
];
1162 dc
->hwss
.prog_pixclk_crtc_otg(pipe_ctx
, context
, dc
);
1164 pipe_ctx
->opp
->funcs
->opp_set_dyn_expansion(
1166 COLOR_SPACE_YCBCR601
,
1167 stream
->public.timing
.display_color_depth
,
1168 pipe_ctx
->stream
->signal
);
1170 pipe_ctx
->opp
->funcs
->opp_program_fmt(
1172 &stream
->bit_depth_params
,
1175 /* FPGA does not program backend */
1176 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
))
1179 /* TODO: move to stream encoder */
1180 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1181 if (DC_OK
!= bios_parser_crtc_source_select(pipe_ctx
)) {
1182 BREAK_TO_DEBUGGER();
1183 return DC_ERROR_UNEXPECTED
;
1186 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1187 stream
->sink
->link
->link_enc
->funcs
->setup(
1188 stream
->sink
->link
->link_enc
,
1189 pipe_ctx
->stream
->signal
);
1191 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1192 pipe_ctx
->stream_enc
->funcs
->dp_set_stream_attribute(
1193 pipe_ctx
->stream_enc
,
1194 &stream
->public.timing
,
1195 stream
->public.output_color_space
);
1197 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1198 pipe_ctx
->stream_enc
->funcs
->hdmi_set_stream_attribute(
1199 pipe_ctx
->stream_enc
,
1200 &stream
->public.timing
,
1201 stream
->phy_pix_clk
,
1202 pipe_ctx
->audio
!= NULL
);
1204 if (dc_is_dvi_signal(pipe_ctx
->stream
->signal
))
1205 pipe_ctx
->stream_enc
->funcs
->dvi_set_stream_attribute(
1206 pipe_ctx
->stream_enc
,
1207 &stream
->public.timing
,
1208 (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
) ?
1211 if (!pipe_ctx_old
->stream
) {
1212 core_link_enable_stream(pipe_ctx
);
1214 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1215 dce110_unblank_stream(pipe_ctx
,
1216 &stream
->sink
->link
->public.cur_link_settings
);
1219 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1220 /* program_scaler and allocate_mem_input are not new asic */
1221 if (!pipe_ctx_old
|| memcmp(&pipe_ctx_old
->scl_data
,
1222 &pipe_ctx
->scl_data
,
1223 sizeof(struct scaler_data
)) != 0)
1224 program_scaler(dc
, pipe_ctx
);
1226 /* mst support - use total stream count */
1227 pipe_ctx
->mi
->funcs
->allocate_mem_input(
1229 stream
->public.timing
.h_total
,
1230 stream
->public.timing
.v_total
,
1231 stream
->public.timing
.pix_clk_khz
,
1232 context
->stream_count
);
1237 /******************************************************************************/
1239 static void power_down_encoders(struct core_dc
*dc
)
1243 for (i
= 0; i
< dc
->link_count
; i
++) {
1244 dc
->links
[i
]->link_enc
->funcs
->disable_output(
1245 dc
->links
[i
]->link_enc
, SIGNAL_TYPE_NONE
);
1249 static void power_down_controllers(struct core_dc
*dc
)
1253 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1254 dc
->res_pool
->timing_generators
[i
]->funcs
->disable_crtc(
1255 dc
->res_pool
->timing_generators
[i
]);
1259 static void power_down_clock_sources(struct core_dc
*dc
)
1263 if (dc
->res_pool
->dp_clock_source
->funcs
->cs_power_down(
1264 dc
->res_pool
->dp_clock_source
) == false)
1265 dm_error("Failed to power down pll! (dp clk src)\n");
1267 for (i
= 0; i
< dc
->res_pool
->clk_src_count
; i
++) {
1268 if (dc
->res_pool
->clock_sources
[i
]->funcs
->cs_power_down(
1269 dc
->res_pool
->clock_sources
[i
]) == false)
1270 dm_error("Failed to power down pll! (clk src index=%d)\n", i
);
1274 static void power_down_all_hw_blocks(struct core_dc
*dc
)
1276 power_down_encoders(dc
);
1278 power_down_controllers(dc
);
1280 power_down_clock_sources(dc
);
1283 static void disable_vga_and_power_gate_all_controllers(
1287 struct timing_generator
*tg
;
1288 struct dc_context
*ctx
= dc
->ctx
;
1290 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1291 tg
= dc
->res_pool
->timing_generators
[i
];
1293 tg
->funcs
->disable_vga(tg
);
1295 /* Enable CLOCK gating for each pipe BEFORE controller
1297 enable_display_pipe_clock_gating(ctx
,
1300 dc
->hwss
.power_down_front_end(
1301 dc
, &dc
->current_context
->res_ctx
.pipe_ctx
[i
]);
1306 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1307 * 1. Power down all DC HW blocks
1308 * 2. Disable VGA engine on all controllers
1309 * 3. Enable power gating for controller
1310 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1312 void dce110_enable_accelerated_mode(struct core_dc
*dc
)
1314 power_down_all_hw_blocks(dc
);
1316 disable_vga_and_power_gate_all_controllers(dc
);
1317 bios_set_scratch_acc_mode_change(dc
->ctx
->dc_bios
);
1320 static uint32_t compute_pstate_blackout_duration(
1321 struct bw_fixed blackout_duration
,
1322 const struct core_stream
*stream
)
1324 uint32_t total_dest_line_time_ns
;
1325 uint32_t pstate_blackout_duration_ns
;
1327 pstate_blackout_duration_ns
= 1000 * blackout_duration
.value
>> 24;
1329 total_dest_line_time_ns
= 1000000UL *
1330 stream
->public.timing
.h_total
/
1331 stream
->public.timing
.pix_clk_khz
+
1332 pstate_blackout_duration_ns
;
1334 return total_dest_line_time_ns
;
1337 /* get the index of the pipe_ctx if there were no gaps in the pipe_ctx array*/
1338 int get_bw_result_idx(
1339 struct resource_context
*res_ctx
,
1342 int i
, collapsed_idx
;
1344 if (res_ctx
->pipe_ctx
[pipe_idx
].top_pipe
)
1348 for (i
= 0; i
< pipe_idx
; i
++) {
1349 if (res_ctx
->pipe_ctx
[i
].stream
)
1353 return collapsed_idx
;
1356 static bool is_watermark_set_a_greater(
1357 const struct bw_watermarks
*set_a
,
1358 const struct bw_watermarks
*set_b
)
1360 if (set_a
->a_mark
> set_b
->a_mark
1361 || set_a
->b_mark
> set_b
->b_mark
1362 || set_a
->c_mark
> set_b
->c_mark
1363 || set_a
->d_mark
> set_b
->d_mark
)
1368 static bool did_watermarks_increase(
1369 struct pipe_ctx
*pipe_ctx
,
1370 struct validate_context
*context
,
1371 struct validate_context
*old_context
)
1373 int collapsed_pipe_idx
= get_bw_result_idx(&context
->res_ctx
,
1374 pipe_ctx
->pipe_idx
);
1375 int old_collapsed_pipe_idx
= get_bw_result_idx(&old_context
->res_ctx
,
1376 pipe_ctx
->pipe_idx
);
1377 struct pipe_ctx
*old_pipe_ctx
= &old_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
1379 if (!old_pipe_ctx
->stream
)
1382 if (is_watermark_set_a_greater(
1383 &context
->bw_results
.nbp_state_change_wm_ns
[collapsed_pipe_idx
],
1384 &old_context
->bw_results
.nbp_state_change_wm_ns
[old_collapsed_pipe_idx
]))
1386 if (is_watermark_set_a_greater(
1387 &context
->bw_results
.stutter_exit_wm_ns
[collapsed_pipe_idx
],
1388 &old_context
->bw_results
.stutter_exit_wm_ns
[old_collapsed_pipe_idx
]))
1390 if (is_watermark_set_a_greater(
1391 &context
->bw_results
.urgent_wm_ns
[collapsed_pipe_idx
],
1392 &old_context
->bw_results
.urgent_wm_ns
[old_collapsed_pipe_idx
]))
1398 static void program_wm_for_pipe(struct core_dc
*dc
,
1399 struct pipe_ctx
*pipe_ctx
,
1400 struct validate_context
*context
)
1402 int total_dest_line_time_ns
= compute_pstate_blackout_duration(
1403 dc
->bw_vbios
.blackout_duration
,
1405 int bw_result_idx
= get_bw_result_idx(&context
->res_ctx
,
1406 pipe_ctx
->pipe_idx
);
1408 pipe_ctx
->mi
->funcs
->mem_input_program_display_marks(
1410 context
->bw_results
.nbp_state_change_wm_ns
[bw_result_idx
],
1411 context
->bw_results
.stutter_exit_wm_ns
[bw_result_idx
],
1412 context
->bw_results
.urgent_wm_ns
[bw_result_idx
],
1413 total_dest_line_time_ns
);
1415 if (pipe_ctx
->top_pipe
)
1416 pipe_ctx
->mi
->funcs
->mem_input_program_chroma_display_marks(
1418 context
->bw_results
.nbp_state_change_wm_ns
[bw_result_idx
+ 1],
1419 context
->bw_results
.stutter_exit_wm_ns
[bw_result_idx
+ 1],
1420 context
->bw_results
.urgent_wm_ns
[bw_result_idx
+ 1],
1421 total_dest_line_time_ns
);
1424 void dce110_set_displaymarks(
1425 const struct core_dc
*dc
,
1426 struct validate_context
*context
)
1428 uint8_t i
, num_pipes
;
1429 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
1431 for (i
= 0, num_pipes
= 0; i
< MAX_PIPES
; i
++) {
1432 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1433 uint32_t total_dest_line_time_ns
;
1435 if (pipe_ctx
->stream
== NULL
)
1438 total_dest_line_time_ns
= compute_pstate_blackout_duration(
1439 dc
->bw_vbios
.blackout_duration
, pipe_ctx
->stream
);
1440 pipe_ctx
->mi
->funcs
->mem_input_program_display_marks(
1442 context
->bw_results
.nbp_state_change_wm_ns
[num_pipes
],
1443 context
->bw_results
.stutter_exit_wm_ns
[num_pipes
],
1444 context
->bw_results
.urgent_wm_ns
[num_pipes
],
1445 total_dest_line_time_ns
);
1446 if (i
== underlay_idx
) {
1448 pipe_ctx
->mi
->funcs
->mem_input_program_chroma_display_marks(
1450 context
->bw_results
.nbp_state_change_wm_ns
[num_pipes
],
1451 context
->bw_results
.stutter_exit_wm_ns
[num_pipes
],
1452 context
->bw_results
.urgent_wm_ns
[num_pipes
],
1453 total_dest_line_time_ns
);
1459 static void set_safe_displaymarks(struct resource_context
*res_ctx
)
1462 int underlay_idx
= res_ctx
->pool
->underlay_pipe_index
;
1463 struct bw_watermarks max_marks
= {
1464 MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
};
1465 struct bw_watermarks nbp_marks
= {
1466 SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
};
1468 for (i
= 0; i
< MAX_PIPES
; i
++) {
1469 if (res_ctx
->pipe_ctx
[i
].stream
== NULL
)
1472 res_ctx
->pipe_ctx
[i
].mi
->funcs
->mem_input_program_display_marks(
1473 res_ctx
->pipe_ctx
[i
].mi
,
1478 if (i
== underlay_idx
)
1479 res_ctx
->pipe_ctx
[i
].mi
->funcs
->mem_input_program_chroma_display_marks(
1480 res_ctx
->pipe_ctx
[i
].mi
,
1488 static void switch_dp_clock_sources(
1489 const struct core_dc
*dc
,
1490 struct resource_context
*res_ctx
)
1493 for (i
= 0; i
< MAX_PIPES
; i
++) {
1494 struct pipe_ctx
*pipe_ctx
= &res_ctx
->pipe_ctx
[i
];
1496 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1499 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
)) {
1500 struct clock_source
*clk_src
=
1501 resource_find_used_clk_src_for_sharing(
1505 clk_src
!= pipe_ctx
->clock_source
) {
1506 resource_unreference_clock_source(
1507 res_ctx
, &pipe_ctx
->clock_source
);
1508 pipe_ctx
->clock_source
= clk_src
;
1509 resource_reference_clock_source(res_ctx
, clk_src
);
1511 dce_crtc_switch_to_clk_src(dc
->hwseq
, clk_src
, i
);
1517 /*******************************************************************************
1519 ******************************************************************************/
1521 static void reset_single_pipe_hw_ctx(
1522 const struct core_dc
*dc
,
1523 struct pipe_ctx
*pipe_ctx
,
1524 struct validate_context
*context
)
1526 core_link_disable_stream(pipe_ctx
);
1527 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, true);
1528 if (!hwss_wait_for_blank_complete(pipe_ctx
->tg
)) {
1529 dm_error("DC: failed to blank crtc!\n");
1530 BREAK_TO_DEBUGGER();
1532 pipe_ctx
->tg
->funcs
->disable_crtc(pipe_ctx
->tg
);
1533 pipe_ctx
->mi
->funcs
->free_mem_input(
1534 pipe_ctx
->mi
, context
->stream_count
);
1535 resource_unreference_clock_source(
1536 &context
->res_ctx
, &pipe_ctx
->clock_source
);
1538 dc
->hwss
.power_down_front_end((struct core_dc
*)dc
, pipe_ctx
);
1540 pipe_ctx
->stream
= NULL
;
1543 static void set_drr(struct pipe_ctx
**pipe_ctx
,
1544 int num_pipes
, int vmin
, int vmax
)
1547 struct drr_params params
= {0};
1549 params
.vertical_total_max
= vmax
;
1550 params
.vertical_total_min
= vmin
;
1552 /* TODO: If multiple pipes are to be supported, you need
1556 for (i
= 0; i
< num_pipes
; i
++) {
1557 pipe_ctx
[i
]->tg
->funcs
->set_drr(pipe_ctx
[i
]->tg
, ¶ms
);
1561 static void set_static_screen_control(struct pipe_ctx
**pipe_ctx
,
1562 int num_pipes
, int value
)
1566 for (i
= 0; i
< num_pipes
; i
++)
1567 pipe_ctx
[i
]->tg
->funcs
->
1568 set_static_screen_control(pipe_ctx
[i
]->tg
, value
);
1571 /* unit: in_khz before mode set, get pixel clock from context. ASIC register
1572 * may not be programmed yet.
1573 * TODO: after mode set, pre_mode_set = false,
1574 * may read PLL register to get pixel clock
1576 static uint32_t get_max_pixel_clock_for_all_paths(
1578 struct validate_context
*context
,
1581 uint32_t max_pix_clk
= 0;
1584 if (!pre_mode_set
) {
1585 /* TODO: read ASIC register to get pixel clock */
1589 for (i
= 0; i
< MAX_PIPES
; i
++) {
1590 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1592 if (pipe_ctx
->stream
== NULL
)
1595 /* do not check under lay */
1596 if (pipe_ctx
->top_pipe
)
1599 if (pipe_ctx
->pix_clk_params
.requested_pix_clk
> max_pix_clk
)
1601 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1604 if (max_pix_clk
== 0)
1611 * Find clock state based on clock requested. if clock value is 0, simply
1612 * set clock state as requested without finding clock state by clock value
1614 static void apply_min_clocks(
1616 struct validate_context
*context
,
1617 enum dm_pp_clocks_state
*clocks_state
,
1620 struct state_dependent_clocks req_clocks
= {0};
1621 struct pipe_ctx
*pipe_ctx
;
1624 for (i
= 0; i
< MAX_PIPES
; i
++) {
1625 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1626 if (pipe_ctx
->dis_clk
!= NULL
)
1630 if (!pre_mode_set
) {
1631 /* set clock_state without verification */
1632 if (pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state
) {
1633 pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state(
1634 pipe_ctx
->dis_clk
, *clocks_state
);
1641 /* get the required state based on state dependent clocks:
1642 * display clock and pixel clock
1644 req_clocks
.display_clk_khz
= context
->bw_results
.dispclk_khz
;
1646 req_clocks
.pixel_clk_khz
= get_max_pixel_clock_for_all_paths(
1649 if (pipe_ctx
->dis_clk
->funcs
->get_required_clocks_state
) {
1650 *clocks_state
= pipe_ctx
->dis_clk
->funcs
->get_required_clocks_state(
1651 pipe_ctx
->dis_clk
, &req_clocks
);
1652 pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state(
1653 pipe_ctx
->dis_clk
, *clocks_state
);
1658 static enum dc_status
apply_ctx_to_hw_fpga(
1660 struct validate_context
*context
)
1662 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1665 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1666 struct pipe_ctx
*pipe_ctx_old
=
1667 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1668 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1670 if (pipe_ctx
->stream
== NULL
)
1673 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1676 status
= apply_single_controller_ctx_to_hw(
1681 if (status
!= DC_OK
)
1688 static void reset_hw_ctx_wrap(
1690 struct validate_context
*context
)
1694 /* Reset old context */
1695 /* look up the targets that have been removed since last commit */
1696 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1697 struct pipe_ctx
*pipe_ctx_old
=
1698 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1699 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1701 /* Note: We need to disable output if clock sources change,
1702 * since bios does optimization and doesn't apply if changing
1703 * PHY when not already disabled.
1706 /* Skip underlay pipe since it will be handled in commit surface*/
1707 if (!pipe_ctx_old
->stream
|| pipe_ctx_old
->top_pipe
)
1710 if (!pipe_ctx
->stream
||
1711 pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
1712 reset_single_pipe_hw_ctx(
1713 dc
, pipe_ctx_old
, dc
->current_context
);
1717 /*TODO: const validate_context*/
1718 enum dc_status
dce110_apply_ctx_to_hw(
1720 struct validate_context
*context
)
1722 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
1723 enum dc_status status
;
1725 bool programmed_audio_dto
= false;
1726 enum dm_pp_clocks_state clocks_state
= DM_PP_CLOCKS_STATE_INVALID
;
1728 /* Reset old context */
1729 /* look up the targets that have been removed since last commit */
1730 dc
->hwss
.reset_hw_ctx_wrap(dc
, context
);
1732 /* Skip applying if no targets */
1733 if (context
->stream_count
<= 0)
1736 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1737 apply_ctx_to_hw_fpga(dc
, context
);
1741 /* Apply new context */
1742 dcb
->funcs
->set_scratch_critical_state(dcb
, true);
1744 /* below is for real asic only */
1745 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1746 struct pipe_ctx
*pipe_ctx_old
=
1747 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1748 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1750 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1753 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
) {
1754 if (pipe_ctx_old
->clock_source
!= pipe_ctx
->clock_source
)
1755 dce_crtc_switch_to_clk_src(dc
->hwseq
,
1756 pipe_ctx
->clock_source
, i
);
1760 dc
->hwss
.enable_display_power_gating(
1761 dc
, i
, dc
->ctx
->dc_bios
,
1762 PIPE_GATING_CONTROL_DISABLE
);
1765 set_safe_displaymarks(&context
->res_ctx
);
1766 /*TODO: when pplib works*/
1767 apply_min_clocks(dc
, context
, &clocks_state
, true);
1769 if (context
->bw_results
.dispclk_khz
1770 > dc
->current_context
->bw_results
.dispclk_khz
)
1771 context
->res_ctx
.pool
->display_clock
->funcs
->set_clock(
1772 context
->res_ctx
.pool
->display_clock
,
1773 context
->bw_results
.dispclk_khz
* 115 / 100);
1775 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1776 struct pipe_ctx
*pipe_ctx_old
=
1777 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1778 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1780 if (pipe_ctx
->stream
== NULL
)
1783 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1786 if (pipe_ctx
->top_pipe
)
1789 if (context
->res_ctx
.pipe_ctx
[i
].audio
!= NULL
) {
1790 /* Setup audio rate clock source */
1792 * Audio lag happened on DP monitor when unplug a HDMI monitor
1795 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
1796 * is set to either dto0 or dto1, audio should work fine.
1797 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
1798 * set to dto0 will cause audio lag.
1801 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
1802 * find first available pipe with audio, setup audio wall DTO per topology
1803 * instead of per pipe.
1805 struct audio_output audio_output
;
1807 build_audio_output(pipe_ctx
, &audio_output
);
1809 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1810 pipe_ctx
->stream_enc
->funcs
->dp_audio_setup(
1811 pipe_ctx
->stream_enc
,
1812 pipe_ctx
->audio
->inst
,
1813 &pipe_ctx
->stream
->public.audio_info
);
1815 pipe_ctx
->stream_enc
->funcs
->hdmi_audio_setup(
1816 pipe_ctx
->stream_enc
,
1817 pipe_ctx
->audio
->inst
,
1818 &pipe_ctx
->stream
->public.audio_info
,
1819 &audio_output
.crtc_info
);
1821 pipe_ctx
->audio
->funcs
->az_configure(
1823 pipe_ctx
->stream
->signal
,
1824 &audio_output
.crtc_info
,
1825 &pipe_ctx
->stream
->public.audio_info
);
1827 if (!programmed_audio_dto
) {
1828 pipe_ctx
->audio
->funcs
->wall_dto_setup(
1830 pipe_ctx
->stream
->signal
,
1831 &audio_output
.crtc_info
,
1832 &audio_output
.pll_info
);
1833 programmed_audio_dto
= true;
1837 status
= apply_single_controller_ctx_to_hw(
1842 if (DC_OK
!= status
)
1846 dc
->hwss
.set_displaymarks(dc
, context
);
1849 apply_min_clocks(dc
, context
, &clocks_state
, false);
1851 dcb
->funcs
->set_scratch_critical_state(dcb
, false);
1853 switch_dp_clock_sources(dc
, &context
->res_ctx
);
1858 /*******************************************************************************
1859 * Front End programming
1860 ******************************************************************************/
1861 static void set_default_colors(struct pipe_ctx
*pipe_ctx
)
1863 struct default_adjustment default_adjust
= { 0 };
1865 default_adjust
.force_hw_default
= false;
1866 if (pipe_ctx
->surface
== NULL
)
1867 default_adjust
.in_color_space
= COLOR_SPACE_SRGB
;
1869 default_adjust
.in_color_space
=
1870 pipe_ctx
->surface
->public.color_space
;
1871 if (pipe_ctx
->stream
== NULL
)
1872 default_adjust
.out_color_space
= COLOR_SPACE_SRGB
;
1874 default_adjust
.out_color_space
=
1875 pipe_ctx
->stream
->public.output_color_space
;
1876 default_adjust
.csc_adjust_type
= GRAPHICS_CSC_ADJUST_TYPE_SW
;
1877 default_adjust
.surface_pixel_format
= pipe_ctx
->scl_data
.format
;
1879 /* display color depth */
1880 default_adjust
.color_depth
=
1881 pipe_ctx
->stream
->public.timing
.display_color_depth
;
1883 /* Lb color depth */
1884 default_adjust
.lb_color_depth
= pipe_ctx
->scl_data
.lb_params
.depth
;
1886 pipe_ctx
->opp
->funcs
->opp_set_csc_default(
1887 pipe_ctx
->opp
, &default_adjust
);
1891 /*******************************************************************************
1892 * In order to turn on/off specific surface we will program
1895 * In case that we have two surfaces and they have a different visibility
1896 * we can't turn off the CRTC since it will turn off the entire display
1898 * |----------------------------------------------- |
1899 * |bottom pipe|curr pipe | | |
1900 * |Surface |Surface | Blender | CRCT |
1901 * |visibility |visibility | Configuration| |
1902 * |------------------------------------------------|
1903 * | off | off | CURRENT_PIPE | blank |
1904 * | off | on | CURRENT_PIPE | unblank |
1905 * | on | off | OTHER_PIPE | unblank |
1906 * | on | on | BLENDING | unblank |
1907 * -------------------------------------------------|
1909 ******************************************************************************/
1910 static void program_surface_visibility(const struct core_dc
*dc
,
1911 struct pipe_ctx
*pipe_ctx
)
1913 enum blnd_mode blender_mode
= BLND_MODE_CURRENT_PIPE
;
1914 bool blank_target
= false;
1916 if (pipe_ctx
->bottom_pipe
) {
1918 /* For now we are supporting only two pipes */
1919 ASSERT(pipe_ctx
->bottom_pipe
->bottom_pipe
== NULL
);
1921 if (pipe_ctx
->bottom_pipe
->surface
->public.visible
) {
1922 if (pipe_ctx
->surface
->public.visible
)
1923 blender_mode
= BLND_MODE_BLENDING
;
1925 blender_mode
= BLND_MODE_OTHER_PIPE
;
1927 } else if (!pipe_ctx
->surface
->public.visible
)
1928 blank_target
= true;
1930 } else if (!pipe_ctx
->surface
->public.visible
)
1931 blank_target
= true;
1933 dce_set_blender_mode(dc
->hwseq
, pipe_ctx
->pipe_idx
, blender_mode
);
1934 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, blank_target
);
1939 * TODO REMOVE, USE UPDATE INSTEAD
1941 static void set_plane_config(
1942 const struct core_dc
*dc
,
1943 struct pipe_ctx
*pipe_ctx
,
1944 struct resource_context
*res_ctx
)
1946 struct mem_input
*mi
= pipe_ctx
->mi
;
1947 struct core_surface
*surface
= pipe_ctx
->surface
;
1948 struct xfm_grph_csc_adjustment adjust
;
1949 struct out_csc_color_matrix tbl_entry
;
1952 memset(&adjust
, 0, sizeof(adjust
));
1953 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
1954 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
1956 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
1958 set_default_colors(pipe_ctx
);
1959 if (pipe_ctx
->stream
->public.csc_color_matrix
.enable_adjustment
1961 tbl_entry
.color_space
=
1962 pipe_ctx
->stream
->public.output_color_space
;
1964 for (i
= 0; i
< 12; i
++)
1965 tbl_entry
.regval
[i
] =
1966 pipe_ctx
->stream
->public.csc_color_matrix
.matrix
[i
];
1968 pipe_ctx
->opp
->funcs
->opp_set_csc_adjustment
1969 (pipe_ctx
->opp
, &tbl_entry
);
1972 if (pipe_ctx
->stream
->public.gamut_remap_matrix
.enable_remap
== true) {
1973 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
1974 adjust
.temperature_matrix
[0] =
1976 public.gamut_remap_matrix
.matrix
[0];
1977 adjust
.temperature_matrix
[1] =
1979 public.gamut_remap_matrix
.matrix
[1];
1980 adjust
.temperature_matrix
[2] =
1982 public.gamut_remap_matrix
.matrix
[2];
1983 adjust
.temperature_matrix
[3] =
1985 public.gamut_remap_matrix
.matrix
[4];
1986 adjust
.temperature_matrix
[4] =
1988 public.gamut_remap_matrix
.matrix
[5];
1989 adjust
.temperature_matrix
[5] =
1991 public.gamut_remap_matrix
.matrix
[6];
1992 adjust
.temperature_matrix
[6] =
1994 public.gamut_remap_matrix
.matrix
[8];
1995 adjust
.temperature_matrix
[7] =
1997 public.gamut_remap_matrix
.matrix
[9];
1998 adjust
.temperature_matrix
[8] =
2000 public.gamut_remap_matrix
.matrix
[10];
2003 pipe_ctx
->xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->xfm
, &adjust
);
2005 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2006 program_scaler(dc
, pipe_ctx
);
2008 program_surface_visibility(dc
, pipe_ctx
);
2010 mi
->funcs
->mem_input_program_surface_config(
2012 surface
->public.format
,
2013 &surface
->public.tiling_info
,
2014 &surface
->public.plane_size
,
2015 surface
->public.rotation
,
2018 pipe_ctx
->surface
->public.visible
);
2020 if (dc
->public.config
.gpu_vm_support
)
2021 mi
->funcs
->mem_input_program_pte_vm(
2023 surface
->public.format
,
2024 &surface
->public.tiling_info
,
2025 surface
->public.rotation
);
2028 static void update_plane_addr(const struct core_dc
*dc
,
2029 struct pipe_ctx
*pipe_ctx
)
2031 struct core_surface
*surface
= pipe_ctx
->surface
;
2033 if (surface
== NULL
)
2036 pipe_ctx
->mi
->funcs
->mem_input_program_surface_flip_and_addr(
2038 &surface
->public.address
,
2039 surface
->public.flip_immediate
);
2041 surface
->status
.requested_address
= surface
->public.address
;
2044 void dce110_update_pending_status(struct pipe_ctx
*pipe_ctx
)
2046 struct core_surface
*surface
= pipe_ctx
->surface
;
2048 if (surface
== NULL
)
2051 surface
->status
.is_flip_pending
=
2052 pipe_ctx
->mi
->funcs
->mem_input_is_flip_pending(
2055 if (surface
->status
.is_flip_pending
&& !surface
->public.visible
)
2056 pipe_ctx
->mi
->current_address
= pipe_ctx
->mi
->request_address
;
2058 surface
->status
.current_address
= pipe_ctx
->mi
->current_address
;
2061 void dce110_power_down(struct core_dc
*dc
)
2063 power_down_all_hw_blocks(dc
);
2064 disable_vga_and_power_gate_all_controllers(dc
);
2067 static bool wait_for_reset_trigger_to_occur(
2068 struct dc_context
*dc_ctx
,
2069 struct timing_generator
*tg
)
2073 /* To avoid endless loop we wait at most
2074 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2075 const uint32_t frames_to_wait_on_triggered_reset
= 10;
2078 for (i
= 0; i
< frames_to_wait_on_triggered_reset
; i
++) {
2080 if (!tg
->funcs
->is_counter_moving(tg
)) {
2081 DC_ERROR("TG counter is not moving!\n");
2085 if (tg
->funcs
->did_triggered_reset_occur(tg
)) {
2087 /* usually occurs at i=1 */
2088 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2093 /* Wait for one frame. */
2094 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VACTIVE
);
2095 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VBLANK
);
2099 DC_ERROR("GSL: Timeout on reset trigger!\n");
2104 /* Enable timing synchronization for a group of Timing Generators. */
2105 static void dce110_enable_timing_synchronization(
2109 struct pipe_ctx
*grouped_pipes
[])
2111 struct dc_context
*dc_ctx
= dc
->ctx
;
2112 struct dcp_gsl_params gsl_params
= { 0 };
2115 DC_SYNC_INFO("GSL: Setting-up...\n");
2117 /* Designate a single TG in the group as a master.
2118 * Since HW doesn't care which one, we always assign
2119 * the 1st one in the group. */
2120 gsl_params
.gsl_group
= 0;
2121 gsl_params
.gsl_master
= grouped_pipes
[0]->tg
->inst
;
2123 for (i
= 0; i
< group_size
; i
++)
2124 grouped_pipes
[i
]->tg
->funcs
->setup_global_swap_lock(
2125 grouped_pipes
[i
]->tg
, &gsl_params
);
2127 /* Reset slave controllers on master VSync */
2128 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2130 for (i
= 1 /* skip the master */; i
< group_size
; i
++)
2131 grouped_pipes
[i
]->tg
->funcs
->enable_reset_trigger(
2132 grouped_pipes
[i
]->tg
, gsl_params
.gsl_group
);
2136 for (i
= 1 /* skip the master */; i
< group_size
; i
++) {
2137 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2138 wait_for_reset_trigger_to_occur(dc_ctx
, grouped_pipes
[i
]->tg
);
2139 /* Regardless of success of the wait above, remove the reset or
2140 * the driver will start timing out on Display requests. */
2141 DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
2142 grouped_pipes
[i
]->tg
->funcs
->disable_reset_trigger(grouped_pipes
[i
]->tg
);
2146 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2147 * is that the sync'ed displays will not drift out of sync over time*/
2148 DC_SYNC_INFO("GSL: Restoring register states.\n");
2149 for (i
= 0; i
< group_size
; i
++)
2150 grouped_pipes
[i
]->tg
->funcs
->tear_down_global_swap_lock(grouped_pipes
[i
]->tg
);
2152 DC_SYNC_INFO("GSL: Set-up complete.\n");
2155 static void init_hw(struct core_dc
*dc
)
2159 struct transform
*xfm
;
2161 bp
= dc
->ctx
->dc_bios
;
2162 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2163 xfm
= dc
->res_pool
->transforms
[i
];
2164 xfm
->funcs
->transform_reset(xfm
);
2166 dc
->hwss
.enable_display_power_gating(
2168 PIPE_GATING_CONTROL_INIT
);
2169 dc
->hwss
.enable_display_power_gating(
2171 PIPE_GATING_CONTROL_DISABLE
);
2172 dc
->hwss
.enable_display_pipe_clock_gating(
2177 dce_clock_gating_power_up(dc
->hwseq
, false);;
2178 /***************************************/
2180 for (i
= 0; i
< dc
->link_count
; i
++) {
2181 /****************************************/
2182 /* Power up AND update implementation according to the
2183 * required signal (which may be different from the
2184 * default signal on connector). */
2185 struct core_link
*link
= dc
->links
[i
];
2186 link
->link_enc
->funcs
->hw_init(link
->link_enc
);
2189 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2190 struct timing_generator
*tg
= dc
->res_pool
->timing_generators
[i
];
2192 tg
->funcs
->disable_vga(tg
);
2194 /* Blank controller using driver code instead of
2196 tg
->funcs
->set_blank(tg
, true);
2197 hwss_wait_for_blank_complete(tg
);
2200 for (i
= 0; i
< dc
->res_pool
->audio_count
; i
++) {
2201 struct audio
*audio
= dc
->res_pool
->audios
[i
];
2202 audio
->funcs
->hw_init(audio
);
2206 /* TODO: move this to apply_ctx_tohw some how?*/
2207 static void dce110_power_on_pipe_if_needed(
2209 struct pipe_ctx
*pipe_ctx
,
2210 struct validate_context
*context
)
2212 struct pipe_ctx
*old_pipe_ctx
= &dc
->current_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2213 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
2214 struct tg_color black_color
= {0};
2216 if (!old_pipe_ctx
->stream
&& pipe_ctx
->stream
) {
2217 dc
->hwss
.enable_display_power_gating(
2220 dcb
, PIPE_GATING_CONTROL_DISABLE
);
2223 * This is for powering on underlay, so crtc does not
2224 * need to be enabled
2227 pipe_ctx
->tg
->funcs
->program_timing(pipe_ctx
->tg
,
2228 &pipe_ctx
->stream
->public.timing
,
2231 pipe_ctx
->tg
->funcs
->enable_advanced_request(
2234 &pipe_ctx
->stream
->public.timing
);
2236 pipe_ctx
->mi
->funcs
->allocate_mem_input(pipe_ctx
->mi
,
2237 pipe_ctx
->stream
->public.timing
.h_total
,
2238 pipe_ctx
->stream
->public.timing
.v_total
,
2239 pipe_ctx
->stream
->public.timing
.pix_clk_khz
,
2240 context
->stream_count
);
2242 /* TODO unhardcode*/
2243 color_space_to_black_color(dc
,
2244 COLOR_SPACE_YCBCR601
, &black_color
);
2245 pipe_ctx
->tg
->funcs
->set_blank_color(
2251 static void dce110_increase_watermarks_for_pipe(
2253 struct pipe_ctx
*pipe_ctx
,
2254 struct validate_context
*context
)
2256 if (did_watermarks_increase(pipe_ctx
, context
, dc
->current_context
))
2257 program_wm_for_pipe(dc
, pipe_ctx
, context
);
2260 static void dce110_set_bandwidth(struct core_dc
*dc
)
2264 for (i
= 0; i
< dc
->current_context
->res_ctx
.pool
->pipe_count
; i
++) {
2265 struct pipe_ctx
*pipe_ctx
= &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
2267 if (!pipe_ctx
->stream
)
2270 program_wm_for_pipe(dc
, pipe_ctx
, dc
->current_context
);
2273 dc
->current_context
->res_ctx
.pool
->display_clock
->funcs
->set_clock(
2274 dc
->current_context
->res_ctx
.pool
->display_clock
,
2275 dc
->current_context
->bw_results
.dispclk_khz
* 115 / 100);
2278 static void dce110_program_front_end_for_pipe(
2279 struct core_dc
*dc
, struct pipe_ctx
*pipe_ctx
)
2281 struct mem_input
*mi
= pipe_ctx
->mi
;
2282 struct pipe_ctx
*old_pipe
= NULL
;
2283 struct core_surface
*surface
= pipe_ctx
->surface
;
2284 struct xfm_grph_csc_adjustment adjust
;
2285 struct out_csc_color_matrix tbl_entry
;
2288 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2290 if (dc
->current_context
)
2291 old_pipe
= &dc
->current_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2293 memset(&adjust
, 0, sizeof(adjust
));
2294 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2296 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2298 set_default_colors(pipe_ctx
);
2299 if (pipe_ctx
->stream
->public.csc_color_matrix
.enable_adjustment
2301 tbl_entry
.color_space
=
2302 pipe_ctx
->stream
->public.output_color_space
;
2304 for (i
= 0; i
< 12; i
++)
2305 tbl_entry
.regval
[i
] =
2306 pipe_ctx
->stream
->public.csc_color_matrix
.matrix
[i
];
2308 pipe_ctx
->opp
->funcs
->opp_set_csc_adjustment
2309 (pipe_ctx
->opp
, &tbl_entry
);
2312 if (pipe_ctx
->stream
->public.gamut_remap_matrix
.enable_remap
== true) {
2313 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2314 adjust
.temperature_matrix
[0] =
2316 public.gamut_remap_matrix
.matrix
[0];
2317 adjust
.temperature_matrix
[1] =
2319 public.gamut_remap_matrix
.matrix
[1];
2320 adjust
.temperature_matrix
[2] =
2322 public.gamut_remap_matrix
.matrix
[2];
2323 adjust
.temperature_matrix
[3] =
2325 public.gamut_remap_matrix
.matrix
[4];
2326 adjust
.temperature_matrix
[4] =
2328 public.gamut_remap_matrix
.matrix
[5];
2329 adjust
.temperature_matrix
[5] =
2331 public.gamut_remap_matrix
.matrix
[6];
2332 adjust
.temperature_matrix
[6] =
2334 public.gamut_remap_matrix
.matrix
[8];
2335 adjust
.temperature_matrix
[7] =
2337 public.gamut_remap_matrix
.matrix
[9];
2338 adjust
.temperature_matrix
[8] =
2340 public.gamut_remap_matrix
.matrix
[10];
2343 pipe_ctx
->xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->xfm
, &adjust
);
2345 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2346 if (old_pipe
&& memcmp(&old_pipe
->scl_data
,
2347 &pipe_ctx
->scl_data
,
2348 sizeof(struct scaler_data
)) != 0)
2349 program_scaler(dc
, pipe_ctx
);
2351 mi
->funcs
->mem_input_program_surface_config(
2353 surface
->public.format
,
2354 &surface
->public.tiling_info
,
2355 &surface
->public.plane_size
,
2356 surface
->public.rotation
,
2359 pipe_ctx
->surface
->public.visible
);
2361 if (dc
->public.config
.gpu_vm_support
)
2362 mi
->funcs
->mem_input_program_pte_vm(
2364 surface
->public.format
,
2365 &surface
->public.tiling_info
,
2366 surface
->public.rotation
);
2368 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2369 "Pipe:%d 0x%x: addr hi:0x%x, "
2372 " %d; dst: %d, %d, %d, %d;"
2373 "clip: %d, %d, %d, %d\n",
2376 pipe_ctx
->surface
->public.address
.grph
.addr
.high_part
,
2377 pipe_ctx
->surface
->public.address
.grph
.addr
.low_part
,
2378 pipe_ctx
->surface
->public.src_rect
.x
,
2379 pipe_ctx
->surface
->public.src_rect
.y
,
2380 pipe_ctx
->surface
->public.src_rect
.width
,
2381 pipe_ctx
->surface
->public.src_rect
.height
,
2382 pipe_ctx
->surface
->public.dst_rect
.x
,
2383 pipe_ctx
->surface
->public.dst_rect
.y
,
2384 pipe_ctx
->surface
->public.dst_rect
.width
,
2385 pipe_ctx
->surface
->public.dst_rect
.height
,
2386 pipe_ctx
->surface
->public.clip_rect
.x
,
2387 pipe_ctx
->surface
->public.clip_rect
.y
,
2388 pipe_ctx
->surface
->public.clip_rect
.width
,
2389 pipe_ctx
->surface
->public.clip_rect
.height
);
2391 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2392 "Pipe %d: width, height, x, y\n"
2393 "viewport:%d, %d, %d, %d\n"
2394 "recout: %d, %d, %d, %d\n",
2396 pipe_ctx
->scl_data
.viewport
.width
,
2397 pipe_ctx
->scl_data
.viewport
.height
,
2398 pipe_ctx
->scl_data
.viewport
.x
,
2399 pipe_ctx
->scl_data
.viewport
.y
,
2400 pipe_ctx
->scl_data
.recout
.width
,
2401 pipe_ctx
->scl_data
.recout
.height
,
2402 pipe_ctx
->scl_data
.recout
.x
,
2403 pipe_ctx
->scl_data
.recout
.y
);
2406 static void dce110_prepare_pipe_for_context(
2408 struct pipe_ctx
*pipe_ctx
,
2409 struct validate_context
*context
)
2411 dce110_power_on_pipe_if_needed(dc
, pipe_ctx
, context
);
2412 dc
->hwss
.increase_watermarks_for_pipe(dc
, pipe_ctx
, context
);
2415 static void dce110_apply_ctx_for_surface(
2417 struct core_surface
*surface
,
2418 struct validate_context
*context
)
2422 /* TODO remove when removing the surface reset workaroud*/
2426 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
2427 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2429 if (pipe_ctx
->surface
!= surface
)
2432 dce110_program_front_end_for_pipe(dc
, pipe_ctx
);
2433 program_surface_visibility(dc
, pipe_ctx
);
2438 static void dce110_power_down_fe(struct core_dc
*dc
, struct pipe_ctx
*pipe
)
2442 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++)
2443 if (&dc
->current_context
->res_ctx
.pipe_ctx
[i
] == pipe
)
2446 if (i
== dc
->res_pool
->pipe_count
)
2449 dc
->hwss
.enable_display_power_gating(
2450 dc
, i
, dc
->ctx
->dc_bios
, PIPE_GATING_CONTROL_ENABLE
);
2452 pipe
->xfm
->funcs
->transform_reset(pipe
->xfm
);
2453 memset(&pipe
->scl_data
, 0, sizeof(struct scaler_data
));
2456 static const struct hw_sequencer_funcs dce110_funcs
= {
2458 .apply_ctx_to_hw
= dce110_apply_ctx_to_hw
,
2459 .prepare_pipe_for_context
= dce110_prepare_pipe_for_context
,
2460 .apply_ctx_for_surface
= dce110_apply_ctx_for_surface
,
2461 .set_plane_config
= set_plane_config
,
2462 .update_plane_addr
= update_plane_addr
,
2463 .update_pending_status
= dce110_update_pending_status
,
2464 .set_input_transfer_func
= dce110_set_input_transfer_func
,
2465 .set_output_transfer_func
= dce110_set_output_transfer_func
,
2466 .power_down
= dce110_power_down
,
2467 .enable_accelerated_mode
= dce110_enable_accelerated_mode
,
2468 .enable_timing_synchronization
= dce110_enable_timing_synchronization
,
2469 .update_info_frame
= dce110_update_info_frame
,
2470 .enable_stream
= dce110_enable_stream
,
2471 .disable_stream
= dce110_disable_stream
,
2472 .unblank_stream
= dce110_unblank_stream
,
2473 .enable_display_pipe_clock_gating
= enable_display_pipe_clock_gating
,
2474 .enable_display_power_gating
= dce110_enable_display_power_gating
,
2475 .power_down_front_end
= dce110_power_down_fe
,
2476 .pipe_control_lock
= dce_pipe_control_lock
,
2477 .set_displaymarks
= dce110_set_displaymarks
,
2478 .increase_watermarks_for_pipe
= dce110_increase_watermarks_for_pipe
,
2479 .set_bandwidth
= dce110_set_bandwidth
,
2481 .set_static_screen_control
= set_static_screen_control
,
2482 .reset_hw_ctx_wrap
= reset_hw_ctx_wrap
,
2483 .prog_pixclk_crtc_otg
= dce110_prog_pixclk_crtc_otg
,
2486 bool dce110_hw_sequencer_construct(struct core_dc
*dc
)
2488 dc
->hwss
= dce110_funcs
;