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"
53 struct dce110_hw_seq_reg_offsets
{
57 static const struct dce110_hw_seq_reg_offsets reg_offsets
[] = {
59 .crtc
= (mmCRTC0_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
62 .crtc
= (mmCRTC1_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
65 .crtc
= (mmCRTC2_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
68 .crtc
= (mmCRTCV_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
72 #define HW_REG_BLND(reg, id)\
73 (reg + reg_offsets[id].blnd)
75 #define HW_REG_CRTC(reg, id)\
76 (reg + reg_offsets[id].crtc)
78 #define MAX_WATERMARK 0xFFFF
79 #define SAFE_NBP_MARK 0x7FFF
81 /*******************************************************************************
83 ******************************************************************************/
84 /***************************PIPE_CONTROL***********************************/
85 static void dce110_init_pte(struct dc_context
*ctx
)
89 uint32_t chunk_int
= 0;
90 uint32_t chunk_mul
= 0;
92 addr
= mmUNP_DVMM_PTE_CONTROL
;
93 value
= dm_read_reg(ctx
, addr
);
105 DVMM_PTE_BUFFER_MODE0
);
111 DVMM_PTE_BUFFER_MODE1
);
113 dm_write_reg(ctx
, addr
, value
);
115 addr
= mmDVMM_PTE_REQ
;
116 value
= dm_read_reg(ctx
, addr
);
118 chunk_int
= get_reg_field_value(
121 HFLIP_PTEREQ_PER_CHUNK_INT
);
123 chunk_mul
= get_reg_field_value(
126 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
128 if (chunk_int
!= 0x4 || chunk_mul
!= 0x4) {
134 MAX_PTEREQ_TO_ISSUE
);
140 HFLIP_PTEREQ_PER_CHUNK_INT
);
146 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
148 dm_write_reg(ctx
, addr
, value
);
151 /**************************************************************************/
153 static void enable_display_pipe_clock_gating(
154 struct dc_context
*ctx
,
160 static bool dce110_enable_display_power_gating(
162 uint8_t controller_id
,
164 enum pipe_gating_control power_gating
)
166 enum bp_result bp_result
= BP_RESULT_OK
;
167 enum bp_pipe_control_action cntl
;
168 struct dc_context
*ctx
= dc
->ctx
;
169 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
171 if (IS_FPGA_MAXIMUS_DC(ctx
->dce_environment
))
174 if (power_gating
== PIPE_GATING_CONTROL_INIT
)
175 cntl
= ASIC_PIPE_INIT
;
176 else if (power_gating
== PIPE_GATING_CONTROL_ENABLE
)
177 cntl
= ASIC_PIPE_ENABLE
;
179 cntl
= ASIC_PIPE_DISABLE
;
181 if (controller_id
== underlay_idx
)
182 controller_id
= CONTROLLER_ID_UNDERLAY0
- 1;
184 if (power_gating
!= PIPE_GATING_CONTROL_INIT
|| controller_id
== 0){
186 bp_result
= dcb
->funcs
->enable_disp_power_gating(
187 dcb
, controller_id
+ 1, cntl
);
189 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
190 * by default when command table is called
192 * Bios parser accepts controller_id = 6 as indicative of
193 * underlay pipe in dce110. But we do not support more
196 if (controller_id
< CONTROLLER_ID_MAX
- 1)
198 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE
, controller_id
),
202 if (power_gating
!= PIPE_GATING_CONTROL_ENABLE
)
203 dce110_init_pte(ctx
);
205 if (bp_result
== BP_RESULT_OK
)
211 static void build_prescale_params(struct ipp_prescale_params
*prescale_params
,
212 const struct core_surface
*surface
)
214 prescale_params
->mode
= IPP_PRESCALE_MODE_FIXED_UNSIGNED
;
216 switch (surface
->public.format
) {
217 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888
:
218 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888
:
219 prescale_params
->scale
= 0x2020;
221 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010
:
222 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010
:
223 prescale_params
->scale
= 0x2008;
225 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616
:
226 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F
:
227 prescale_params
->scale
= 0x2000;
235 static bool dce110_set_input_transfer_func(
236 struct pipe_ctx
*pipe_ctx
,
237 const struct core_surface
*surface
)
239 struct input_pixel_processor
*ipp
= pipe_ctx
->ipp
;
240 const struct core_transfer_func
*tf
= NULL
;
241 struct ipp_prescale_params prescale_params
= { 0 };
247 if (surface
->public.in_transfer_func
)
248 tf
= DC_TRANSFER_FUNC_TO_CORE(surface
->public.in_transfer_func
);
250 build_prescale_params(&prescale_params
, surface
);
251 ipp
->funcs
->ipp_program_prescale(ipp
, &prescale_params
);
253 if (surface
->public.gamma_correction
)
254 ipp
->funcs
->ipp_program_input_lut(ipp
, surface
->public.gamma_correction
);
257 /* Default case if no input transfer function specified */
258 ipp
->funcs
->ipp_set_degamma(ipp
,
259 IPP_DEGAMMA_MODE_HW_sRGB
);
260 } else if (tf
->public.type
== TF_TYPE_PREDEFINED
) {
261 switch (tf
->public.tf
) {
262 case TRANSFER_FUNCTION_SRGB
:
263 ipp
->funcs
->ipp_set_degamma(ipp
,
264 IPP_DEGAMMA_MODE_HW_sRGB
);
266 case TRANSFER_FUNCTION_BT709
:
267 ipp
->funcs
->ipp_set_degamma(ipp
,
268 IPP_DEGAMMA_MODE_HW_xvYCC
);
270 case TRANSFER_FUNCTION_LINEAR
:
271 ipp
->funcs
->ipp_set_degamma(ipp
,
272 IPP_DEGAMMA_MODE_BYPASS
);
274 case TRANSFER_FUNCTION_PQ
:
282 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
289 static bool build_custom_float(
290 struct fixed31_32 value
,
291 const struct custom_float_format
*format
,
296 uint32_t exp_offset
= (1 << (format
->exponenta_bits
- 1)) - 1;
298 const struct fixed31_32 mantissa_constant_plus_max_fraction
=
299 dal_fixed31_32_from_fraction(
300 (1LL << (format
->mantissa_bits
+ 1)) - 1,
301 1LL << format
->mantissa_bits
);
303 struct fixed31_32 mantiss
;
305 if (dal_fixed31_32_eq(
307 dal_fixed31_32_zero
)) {
314 if (dal_fixed31_32_lt(
316 dal_fixed31_32_zero
)) {
317 *negative
= format
->sign
;
318 value
= dal_fixed31_32_neg(value
);
323 if (dal_fixed31_32_lt(
325 dal_fixed31_32_one
)) {
329 value
= dal_fixed31_32_shl(value
, 1);
331 } while (dal_fixed31_32_lt(
333 dal_fixed31_32_one
));
337 if (exp_offset
<= i
) {
343 *exponenta
= exp_offset
- i
;
344 } else if (dal_fixed31_32_le(
345 mantissa_constant_plus_max_fraction
,
350 value
= dal_fixed31_32_shr(value
, 1);
352 } while (dal_fixed31_32_lt(
353 mantissa_constant_plus_max_fraction
,
356 *exponenta
= exp_offset
+ i
- 1;
358 *exponenta
= exp_offset
;
361 mantiss
= dal_fixed31_32_sub(
365 if (dal_fixed31_32_lt(
367 dal_fixed31_32_zero
) ||
371 mantiss
= dal_fixed31_32_zero
;
373 mantiss
= dal_fixed31_32_shl(
375 format
->mantissa_bits
);
377 *mantissa
= dal_fixed31_32_floor(mantiss
);
382 static bool setup_custom_float(
383 const struct custom_float_format
*format
,
394 /* verification code:
395 * once calculation is ok we can remove it
398 const uint32_t mantissa_mask
=
399 (1 << (format
->mantissa_bits
+ 1)) - 1;
401 const uint32_t exponenta_mask
=
402 (1 << (format
->exponenta_bits
+ 1)) - 1;
404 if (mantissa
& ~mantissa_mask
) {
406 mantissa
= mantissa_mask
;
409 if (exponenta
& ~exponenta_mask
) {
411 exponenta
= exponenta_mask
;
414 /* end of verification code */
416 while (i
< format
->mantissa_bits
) {
417 uint32_t mask
= 1 << i
;
425 while (j
< format
->exponenta_bits
) {
426 uint32_t mask
= 1 << j
;
428 if (exponenta
& mask
)
434 if (negative
&& format
->sign
)
435 value
|= 1 << (i
+ j
);
442 static bool convert_to_custom_float_format(
443 struct fixed31_32 value
,
444 const struct custom_float_format
*format
,
451 return build_custom_float(
452 value
, format
, &negative
, &mantissa
, &exponenta
) &&
454 format
, negative
, mantissa
, exponenta
, result
);
457 static bool convert_to_custom_float(
458 struct pwl_result_data
*rgb_resulted
,
459 struct curve_points
*arr_points
,
460 uint32_t hw_points_num
)
462 struct custom_float_format fmt
;
464 struct pwl_result_data
*rgb
= rgb_resulted
;
468 fmt
.exponenta_bits
= 6;
469 fmt
.mantissa_bits
= 12;
472 if (!convert_to_custom_float_format(
475 &arr_points
[0].custom_float_x
)) {
480 if (!convert_to_custom_float_format(
481 arr_points
[0].offset
,
483 &arr_points
[0].custom_float_offset
)) {
488 if (!convert_to_custom_float_format(
491 &arr_points
[0].custom_float_slope
)) {
496 fmt
.mantissa_bits
= 10;
499 if (!convert_to_custom_float_format(
502 &arr_points
[1].custom_float_x
)) {
507 if (!convert_to_custom_float_format(
510 &arr_points
[1].custom_float_y
)) {
515 if (!convert_to_custom_float_format(
518 &arr_points
[2].custom_float_slope
)) {
523 fmt
.mantissa_bits
= 12;
526 while (i
!= hw_points_num
) {
527 if (!convert_to_custom_float_format(
535 if (!convert_to_custom_float_format(
543 if (!convert_to_custom_float_format(
551 if (!convert_to_custom_float_format(
554 &rgb
->delta_red_reg
)) {
559 if (!convert_to_custom_float_format(
562 &rgb
->delta_green_reg
)) {
567 if (!convert_to_custom_float_format(
570 &rgb
->delta_blue_reg
)) {
582 bool dce110_translate_regamma_to_hw_format(const struct dc_transfer_func
583 *output_tf
, struct pwl_params
*regamma_params
)
585 struct curve_points
*arr_points
;
586 struct pwl_result_data
*rgb_resulted
;
587 struct pwl_result_data
*rgb
;
588 struct pwl_result_data
*rgb_plus_1
;
589 struct fixed31_32 y_r
;
590 struct fixed31_32 y_g
;
591 struct fixed31_32 y_b
;
592 struct fixed31_32 y1_min
;
593 struct fixed31_32 y3_max
;
595 int32_t segment_start
, segment_end
;
596 uint32_t i
, j
, k
, seg_distr
[16], increment
, start_index
, hw_points
;
598 if (output_tf
== NULL
|| regamma_params
== NULL
)
601 arr_points
= regamma_params
->arr_points
;
602 rgb_resulted
= regamma_params
->rgb_resulted
;
605 memset(regamma_params
, 0, sizeof(struct pwl_params
));
607 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
609 * segments are from 2^-11 to 2^5
633 * segment is from 2^-10 to 2^0
656 for (k
= 0; k
< 16; k
++) {
657 if (seg_distr
[k
] != -1)
658 hw_points
+= (1 << seg_distr
[k
]);
662 for (k
= 0; k
< (segment_end
- segment_start
); k
++) {
663 increment
= 32 / (1 << seg_distr
[k
]);
664 start_index
= (segment_start
+ k
+ 25) * 32;
665 for (i
= start_index
; i
< start_index
+ 32; i
+= increment
) {
666 if (j
== hw_points
- 1)
668 rgb_resulted
[j
].red
= output_tf
->tf_pts
.red
[i
];
669 rgb_resulted
[j
].green
= output_tf
->tf_pts
.green
[i
];
670 rgb_resulted
[j
].blue
= output_tf
->tf_pts
.blue
[i
];
676 start_index
= (segment_end
+ 25) * 32;
677 rgb_resulted
[hw_points
- 1].red
=
678 output_tf
->tf_pts
.red
[start_index
];
679 rgb_resulted
[hw_points
- 1].green
=
680 output_tf
->tf_pts
.green
[start_index
];
681 rgb_resulted
[hw_points
- 1].blue
=
682 output_tf
->tf_pts
.blue
[start_index
];
684 arr_points
[0].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
685 dal_fixed31_32_from_int(segment_start
));
686 arr_points
[1].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
687 dal_fixed31_32_from_int(segment_end
));
688 arr_points
[2].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
689 dal_fixed31_32_from_int(segment_end
));
691 y_r
= rgb_resulted
[0].red
;
692 y_g
= rgb_resulted
[0].green
;
693 y_b
= rgb_resulted
[0].blue
;
695 y1_min
= dal_fixed31_32_min(y_r
, dal_fixed31_32_min(y_g
, y_b
));
697 arr_points
[0].y
= y1_min
;
698 arr_points
[0].slope
= dal_fixed31_32_div(
702 y_r
= rgb_resulted
[hw_points
- 1].red
;
703 y_g
= rgb_resulted
[hw_points
- 1].green
;
704 y_b
= rgb_resulted
[hw_points
- 1].blue
;
706 /* see comment above, m_arrPoints[1].y should be the Y value for the
707 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
709 y3_max
= dal_fixed31_32_max(y_r
, dal_fixed31_32_max(y_g
, y_b
));
711 arr_points
[1].y
= y3_max
;
712 arr_points
[2].y
= y3_max
;
714 arr_points
[1].slope
= dal_fixed31_32_zero
;
715 arr_points
[2].slope
= dal_fixed31_32_zero
;
717 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
718 /* for PQ, we want to have a straight line from last HW X point,
719 * and the slope to be such that we hit 1.0 at 10000 nits.
721 const struct fixed31_32 end_value
=
722 dal_fixed31_32_from_int(125);
724 arr_points
[1].slope
= dal_fixed31_32_div(
725 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
726 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
727 arr_points
[2].slope
= dal_fixed31_32_div(
728 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
729 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
732 regamma_params
->hw_points_num
= hw_points
;
735 for (k
= 0; k
< 16 && i
< 16; k
++) {
736 if (seg_distr
[k
] != -1) {
737 regamma_params
->arr_curve_points
[k
].segments_num
=
739 regamma_params
->arr_curve_points
[i
].offset
=
740 regamma_params
->arr_curve_points
[k
].
741 offset
+ (1 << seg_distr
[k
]);
746 if (seg_distr
[k
] != -1)
747 regamma_params
->arr_curve_points
[k
].segments_num
=
751 rgb_plus_1
= rgb_resulted
+ 1;
755 while (i
!= hw_points
+ 1) {
756 if (dal_fixed31_32_lt(rgb_plus_1
->red
, rgb
->red
))
757 rgb_plus_1
->red
= rgb
->red
;
758 if (dal_fixed31_32_lt(rgb_plus_1
->green
, rgb
->green
))
759 rgb_plus_1
->green
= rgb
->green
;
760 if (dal_fixed31_32_lt(rgb_plus_1
->blue
, rgb
->blue
))
761 rgb_plus_1
->blue
= rgb
->blue
;
763 rgb
->delta_red
= dal_fixed31_32_sub(
766 rgb
->delta_green
= dal_fixed31_32_sub(
769 rgb
->delta_blue
= dal_fixed31_32_sub(
778 convert_to_custom_float(rgb_resulted
, arr_points
, hw_points
);
783 static bool dce110_set_output_transfer_func(
784 struct pipe_ctx
*pipe_ctx
,
785 const struct core_surface
*surface
, /* Surface - To be removed */
786 const struct core_stream
*stream
)
788 struct output_pixel_processor
*opp
= pipe_ctx
->opp
;
790 opp
->funcs
->opp_power_on_regamma_lut(opp
, true);
791 opp
->regamma_params
->hw_points_num
= GAMMA_HW_POINTS_NUM
;
793 if (stream
->public.out_transfer_func
&&
794 stream
->public.out_transfer_func
->type
==
795 TF_TYPE_PREDEFINED
&&
796 stream
->public.out_transfer_func
->tf
==
797 TRANSFER_FUNCTION_SRGB
) {
798 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_SRGB
);
799 } else if (dce110_translate_regamma_to_hw_format(
800 stream
->public.out_transfer_func
, opp
->regamma_params
)) {
801 opp
->funcs
->opp_program_regamma_pwl(opp
, opp
->regamma_params
);
802 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_USER
);
804 opp
->funcs
->opp_set_regamma_mode(opp
, OPP_REGAMMA_BYPASS
);
807 opp
->funcs
->opp_power_on_regamma_lut(opp
, false);
812 static enum dc_status
bios_parser_crtc_source_select(
813 struct pipe_ctx
*pipe_ctx
)
816 /* call VBIOS table to set CRTC source for the HW
818 * note: video bios clears all FMT setting here. */
819 struct bp_crtc_source_select crtc_source_select
= {0};
820 const struct core_sink
*sink
= pipe_ctx
->stream
->sink
;
822 crtc_source_select
.engine_id
= pipe_ctx
->stream_enc
->id
;
823 crtc_source_select
.controller_id
= pipe_ctx
->pipe_idx
+ 1;
824 /*TODO: Need to un-hardcode color depth, dp_audio and account for
825 * the case where signal and sink signal is different (translator
827 crtc_source_select
.signal
= pipe_ctx
->stream
->signal
;
828 crtc_source_select
.enable_dp_audio
= false;
829 crtc_source_select
.sink_signal
= pipe_ctx
->stream
->signal
;
830 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
832 dcb
= sink
->ctx
->dc_bios
;
834 if (BP_RESULT_OK
!= dcb
->funcs
->crtc_source_select(
836 &crtc_source_select
)) {
837 return DC_ERROR_UNEXPECTED
;
843 void dce110_update_info_frame(struct pipe_ctx
*pipe_ctx
)
845 ASSERT(pipe_ctx
->stream
);
847 if (pipe_ctx
->stream_enc
== NULL
)
848 return; /* this is not root pipe */
850 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
851 pipe_ctx
->stream_enc
->funcs
->update_hdmi_info_packets(
852 pipe_ctx
->stream_enc
,
853 &pipe_ctx
->encoder_info_frame
);
854 else if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
855 pipe_ctx
->stream_enc
->funcs
->update_dp_info_packets(
856 pipe_ctx
->stream_enc
,
857 &pipe_ctx
->encoder_info_frame
);
860 void dce110_enable_stream(struct pipe_ctx
*pipe_ctx
)
862 enum dc_lane_count lane_count
=
863 pipe_ctx
->stream
->sink
->link
->public.cur_link_settings
.lane_count
;
865 struct dc_crtc_timing
*timing
= &pipe_ctx
->stream
->public.timing
;
866 struct core_link
*link
= pipe_ctx
->stream
->sink
->link
;
868 /* 1. update AVI info frame (HDMI, DP)
869 * we always need to update info frame
871 uint32_t active_total_with_borders
;
872 uint32_t early_control
= 0;
873 struct timing_generator
*tg
= pipe_ctx
->tg
;
875 /* TODOFPGA may change to hwss.update_info_frame */
876 dce110_update_info_frame(pipe_ctx
);
877 /* enable early control to avoid corruption on DP monitor*/
878 active_total_with_borders
=
879 timing
->h_addressable
880 + timing
->h_border_left
881 + timing
->h_border_right
;
884 early_control
= active_total_with_borders
% lane_count
;
886 if (early_control
== 0)
887 early_control
= lane_count
;
889 tg
->funcs
->set_early_control(tg
, early_control
);
891 /* enable audio only within mode set */
892 if (pipe_ctx
->audio
!= NULL
) {
893 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
894 pipe_ctx
->stream_enc
->funcs
->dp_audio_enable(pipe_ctx
->stream_enc
);
897 /* For MST, there are multiply stream go to only one link.
898 * connect DIG back_end to front_end while enable_stream and
899 * disconnect them during disable_stream
900 * BY this, it is logic clean to separate stream and link */
901 link
->link_enc
->funcs
->connect_dig_be_to_fe(link
->link_enc
,
902 pipe_ctx
->stream_enc
->id
, true);
906 void dce110_disable_stream(struct pipe_ctx
*pipe_ctx
)
908 struct core_stream
*stream
= pipe_ctx
->stream
;
909 struct core_link
*link
= stream
->sink
->link
;
911 if (pipe_ctx
->audio
) {
912 pipe_ctx
->audio
->funcs
->az_disable(pipe_ctx
->audio
);
914 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
915 pipe_ctx
->stream_enc
->funcs
->dp_audio_disable(
916 pipe_ctx
->stream_enc
);
918 pipe_ctx
->stream_enc
->funcs
->hdmi_audio_disable(
919 pipe_ctx
->stream_enc
);
921 pipe_ctx
->audio
= NULL
;
923 /* TODO: notify audio driver for if audio modes list changed
924 * add audio mode list change flag */
925 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
926 * stream->stream_engine_id);
930 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
931 pipe_ctx
->stream_enc
->funcs
->stop_hdmi_info_packets(
932 pipe_ctx
->stream_enc
);
934 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
935 pipe_ctx
->stream_enc
->funcs
->stop_dp_info_packets(
936 pipe_ctx
->stream_enc
);
938 pipe_ctx
->stream_enc
->funcs
->audio_mute_control(
939 pipe_ctx
->stream_enc
, true);
942 /* blank at encoder level */
943 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
944 pipe_ctx
->stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_enc
);
946 link
->link_enc
->funcs
->connect_dig_be_to_fe(
948 pipe_ctx
->stream_enc
->id
,
953 void dce110_unblank_stream(struct pipe_ctx
*pipe_ctx
,
954 struct dc_link_settings
*link_settings
)
956 struct encoder_unblank_param params
= { { 0 } };
958 /* only 3 items below are used by unblank */
959 params
.pixel_clk_khz
=
960 pipe_ctx
->stream
->public.timing
.pix_clk_khz
;
961 params
.link_settings
.link_rate
= link_settings
->link_rate
;
962 pipe_ctx
->stream_enc
->funcs
->dp_unblank(pipe_ctx
->stream_enc
, ¶ms
);
965 static enum audio_dto_source
translate_to_dto_source(enum controller_id crtc_id
)
968 case CONTROLLER_ID_D0
:
969 return DTO_SOURCE_ID0
;
970 case CONTROLLER_ID_D1
:
971 return DTO_SOURCE_ID1
;
972 case CONTROLLER_ID_D2
:
973 return DTO_SOURCE_ID2
;
974 case CONTROLLER_ID_D3
:
975 return DTO_SOURCE_ID3
;
976 case CONTROLLER_ID_D4
:
977 return DTO_SOURCE_ID4
;
978 case CONTROLLER_ID_D5
:
979 return DTO_SOURCE_ID5
;
981 return DTO_SOURCE_UNKNOWN
;
985 static void build_audio_output(
986 const struct pipe_ctx
*pipe_ctx
,
987 struct audio_output
*audio_output
)
989 const struct core_stream
*stream
= pipe_ctx
->stream
;
990 audio_output
->engine_id
= pipe_ctx
->stream_enc
->id
;
992 audio_output
->signal
= pipe_ctx
->stream
->signal
;
994 /* audio_crtc_info */
996 audio_output
->crtc_info
.h_total
=
997 stream
->public.timing
.h_total
;
1000 * Audio packets are sent during actual CRTC blank physical signal, we
1001 * need to specify actual active signal portion
1003 audio_output
->crtc_info
.h_active
=
1004 stream
->public.timing
.h_addressable
1005 + stream
->public.timing
.h_border_left
1006 + stream
->public.timing
.h_border_right
;
1008 audio_output
->crtc_info
.v_active
=
1009 stream
->public.timing
.v_addressable
1010 + stream
->public.timing
.v_border_top
1011 + stream
->public.timing
.v_border_bottom
;
1013 audio_output
->crtc_info
.pixel_repetition
= 1;
1015 audio_output
->crtc_info
.interlaced
=
1016 stream
->public.timing
.flags
.INTERLACE
;
1018 audio_output
->crtc_info
.refresh_rate
=
1019 (stream
->public.timing
.pix_clk_khz
*1000)/
1020 (stream
->public.timing
.h_total
*stream
->public.timing
.v_total
);
1022 audio_output
->crtc_info
.color_depth
=
1023 stream
->public.timing
.display_color_depth
;
1025 audio_output
->crtc_info
.requested_pixel_clock
=
1026 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1029 * TODO - Investigate why calculated pixel clk has to be
1030 * requested pixel clk
1032 audio_output
->crtc_info
.calculated_pixel_clock
=
1033 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1035 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT
||
1036 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
1037 audio_output
->pll_info
.dp_dto_source_clock_in_khz
=
1038 pipe_ctx
->dis_clk
->funcs
->get_dp_ref_clk_frequency(
1042 audio_output
->pll_info
.feed_back_divider
=
1043 pipe_ctx
->pll_settings
.feedback_divider
;
1045 audio_output
->pll_info
.dto_source
=
1046 translate_to_dto_source(
1047 pipe_ctx
->pipe_idx
+ 1);
1049 /* TODO hard code to enable for now. Need get from stream */
1050 audio_output
->pll_info
.ss_enabled
= true;
1052 audio_output
->pll_info
.ss_percentage
=
1053 pipe_ctx
->pll_settings
.ss_percentage
;
1056 static void get_surface_visual_confirm_color(const struct pipe_ctx
*pipe_ctx
,
1057 struct tg_color
*color
)
1059 uint32_t color_value
= MAX_TG_COLOR_VALUE
* (4 - pipe_ctx
->pipe_idx
) / 4;
1061 switch (pipe_ctx
->scl_data
.format
) {
1062 case PIXEL_FORMAT_ARGB8888
:
1063 /* set boarder color to red */
1064 color
->color_r_cr
= color_value
;
1067 case PIXEL_FORMAT_ARGB2101010
:
1068 /* set boarder color to blue */
1069 color
->color_b_cb
= color_value
;
1071 case PIXEL_FORMAT_420BPP12
:
1072 /* set boarder color to green */
1073 color
->color_g_y
= color_value
;
1075 case PIXEL_FORMAT_FP16
:
1076 /* set boarder color to white */
1077 color
->color_r_cr
= color_value
;
1078 color
->color_b_cb
= color_value
;
1079 color
->color_g_y
= color_value
;
1086 static void program_scaler(const struct core_dc
*dc
,
1087 const struct pipe_ctx
*pipe_ctx
)
1089 struct tg_color color
= {0};
1091 if (dc
->public.debug
.surface_visual_confirm
)
1092 get_surface_visual_confirm_color(pipe_ctx
, &color
);
1094 color_space_to_black_color(dc
,
1095 pipe_ctx
->stream
->public.output_color_space
,
1098 pipe_ctx
->xfm
->funcs
->transform_set_pixel_storage_depth(
1100 pipe_ctx
->scl_data
.lb_params
.depth
,
1101 &pipe_ctx
->stream
->bit_depth_params
);
1103 if (pipe_ctx
->tg
->funcs
->set_overscan_blank_color
)
1104 pipe_ctx
->tg
->funcs
->set_overscan_blank_color(
1108 pipe_ctx
->xfm
->funcs
->transform_set_scaler(pipe_ctx
->xfm
,
1109 &pipe_ctx
->scl_data
);
1112 static enum dc_status
dce110_prog_pixclk_crtc_otg(
1113 struct pipe_ctx
*pipe_ctx
,
1114 struct validate_context
*context
,
1117 struct core_stream
*stream
= pipe_ctx
->stream
;
1118 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_context
->res_ctx
.
1119 pipe_ctx
[pipe_ctx
->pipe_idx
];
1120 struct tg_color black_color
= {0};
1122 if (!pipe_ctx_old
->stream
) {
1124 /* program blank color */
1125 color_space_to_black_color(dc
,
1126 stream
->public.output_color_space
, &black_color
);
1127 pipe_ctx
->tg
->funcs
->set_blank_color(
1132 * Must blank CRTC after disabling power gating and before any
1133 * programming, otherwise CRTC will be hung in bad state
1135 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, true);
1137 if (false == pipe_ctx
->clock_source
->funcs
->program_pix_clk(
1138 pipe_ctx
->clock_source
,
1139 &pipe_ctx
->pix_clk_params
,
1140 &pipe_ctx
->pll_settings
)) {
1141 BREAK_TO_DEBUGGER();
1142 return DC_ERROR_UNEXPECTED
;
1145 pipe_ctx
->tg
->funcs
->program_timing(
1147 &stream
->public.timing
,
1151 if (!pipe_ctx_old
->stream
) {
1152 if (false == pipe_ctx
->tg
->funcs
->enable_crtc(
1154 BREAK_TO_DEBUGGER();
1155 return DC_ERROR_UNEXPECTED
;
1162 static enum dc_status
apply_single_controller_ctx_to_hw(
1163 struct pipe_ctx
*pipe_ctx
,
1164 struct validate_context
*context
,
1167 struct core_stream
*stream
= pipe_ctx
->stream
;
1168 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_context
->res_ctx
.
1169 pipe_ctx
[pipe_ctx
->pipe_idx
];
1172 dc
->hwss
.prog_pixclk_crtc_otg(pipe_ctx
, context
, dc
);
1174 pipe_ctx
->opp
->funcs
->opp_set_dyn_expansion(
1176 COLOR_SPACE_YCBCR601
,
1177 stream
->public.timing
.display_color_depth
,
1178 pipe_ctx
->stream
->signal
);
1180 pipe_ctx
->opp
->funcs
->opp_program_fmt(
1182 &stream
->bit_depth_params
,
1185 /* FPGA does not program backend */
1186 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
))
1189 /* TODO: move to stream encoder */
1190 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1191 if (DC_OK
!= bios_parser_crtc_source_select(pipe_ctx
)) {
1192 BREAK_TO_DEBUGGER();
1193 return DC_ERROR_UNEXPECTED
;
1196 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1197 stream
->sink
->link
->link_enc
->funcs
->setup(
1198 stream
->sink
->link
->link_enc
,
1199 pipe_ctx
->stream
->signal
);
1201 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1202 pipe_ctx
->stream_enc
->funcs
->dp_set_stream_attribute(
1203 pipe_ctx
->stream_enc
,
1204 &stream
->public.timing
,
1205 stream
->public.output_color_space
);
1207 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1208 pipe_ctx
->stream_enc
->funcs
->hdmi_set_stream_attribute(
1209 pipe_ctx
->stream_enc
,
1210 &stream
->public.timing
,
1211 stream
->phy_pix_clk
,
1212 pipe_ctx
->audio
!= NULL
);
1214 if (dc_is_dvi_signal(pipe_ctx
->stream
->signal
))
1215 pipe_ctx
->stream_enc
->funcs
->dvi_set_stream_attribute(
1216 pipe_ctx
->stream_enc
,
1217 &stream
->public.timing
,
1218 (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
) ?
1221 if (!pipe_ctx_old
->stream
) {
1222 core_link_enable_stream(pipe_ctx
);
1224 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1225 dce110_unblank_stream(pipe_ctx
,
1226 &stream
->sink
->link
->public.cur_link_settings
);
1229 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1230 /* program_scaler and allocate_mem_input are not new asic */
1231 if (!pipe_ctx_old
|| memcmp(&pipe_ctx_old
->scl_data
,
1232 &pipe_ctx
->scl_data
,
1233 sizeof(struct scaler_data
)) != 0)
1234 program_scaler(dc
, pipe_ctx
);
1236 /* mst support - use total stream count */
1237 pipe_ctx
->mi
->funcs
->allocate_mem_input(
1239 stream
->public.timing
.h_total
,
1240 stream
->public.timing
.v_total
,
1241 stream
->public.timing
.pix_clk_khz
,
1242 context
->stream_count
);
1247 /******************************************************************************/
1249 static void power_down_encoders(struct core_dc
*dc
)
1253 for (i
= 0; i
< dc
->link_count
; i
++) {
1254 dc
->links
[i
]->link_enc
->funcs
->disable_output(
1255 dc
->links
[i
]->link_enc
, SIGNAL_TYPE_NONE
);
1259 static void power_down_controllers(struct core_dc
*dc
)
1263 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1264 dc
->res_pool
->timing_generators
[i
]->funcs
->disable_crtc(
1265 dc
->res_pool
->timing_generators
[i
]);
1269 static void power_down_clock_sources(struct core_dc
*dc
)
1273 if (dc
->res_pool
->dp_clock_source
->funcs
->cs_power_down(
1274 dc
->res_pool
->dp_clock_source
) == false)
1275 dm_error("Failed to power down pll! (dp clk src)\n");
1277 for (i
= 0; i
< dc
->res_pool
->clk_src_count
; i
++) {
1278 if (dc
->res_pool
->clock_sources
[i
]->funcs
->cs_power_down(
1279 dc
->res_pool
->clock_sources
[i
]) == false)
1280 dm_error("Failed to power down pll! (clk src index=%d)\n", i
);
1284 static void power_down_all_hw_blocks(struct core_dc
*dc
)
1286 power_down_encoders(dc
);
1288 power_down_controllers(dc
);
1290 power_down_clock_sources(dc
);
1293 static void disable_vga_and_power_gate_all_controllers(
1297 struct timing_generator
*tg
;
1298 struct dc_context
*ctx
= dc
->ctx
;
1300 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1301 tg
= dc
->res_pool
->timing_generators
[i
];
1303 tg
->funcs
->disable_vga(tg
);
1305 /* Enable CLOCK gating for each pipe BEFORE controller
1307 enable_display_pipe_clock_gating(ctx
,
1310 dc
->hwss
.power_down_front_end(
1311 dc
, &dc
->current_context
->res_ctx
.pipe_ctx
[i
]);
1316 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1317 * 1. Power down all DC HW blocks
1318 * 2. Disable VGA engine on all controllers
1319 * 3. Enable power gating for controller
1320 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1322 void dce110_enable_accelerated_mode(struct core_dc
*dc
)
1324 power_down_all_hw_blocks(dc
);
1326 disable_vga_and_power_gate_all_controllers(dc
);
1327 bios_set_scratch_acc_mode_change(dc
->ctx
->dc_bios
);
1330 static uint32_t compute_pstate_blackout_duration(
1331 struct bw_fixed blackout_duration
,
1332 const struct core_stream
*stream
)
1334 uint32_t total_dest_line_time_ns
;
1335 uint32_t pstate_blackout_duration_ns
;
1337 pstate_blackout_duration_ns
= 1000 * blackout_duration
.value
>> 24;
1339 total_dest_line_time_ns
= 1000000UL *
1340 stream
->public.timing
.h_total
/
1341 stream
->public.timing
.pix_clk_khz
+
1342 pstate_blackout_duration_ns
;
1344 return total_dest_line_time_ns
;
1347 /* get the index of the pipe_ctx if there were no gaps in the pipe_ctx array*/
1348 int get_bw_result_idx(
1349 struct resource_context
*res_ctx
,
1352 int i
, collapsed_idx
;
1354 if (res_ctx
->pipe_ctx
[pipe_idx
].top_pipe
)
1358 for (i
= 0; i
< pipe_idx
; i
++) {
1359 if (res_ctx
->pipe_ctx
[i
].stream
)
1363 return collapsed_idx
;
1366 static bool is_watermark_set_a_greater(
1367 const struct bw_watermarks
*set_a
,
1368 const struct bw_watermarks
*set_b
)
1370 if (set_a
->a_mark
> set_b
->a_mark
1371 || set_a
->b_mark
> set_b
->b_mark
1372 || set_a
->c_mark
> set_b
->c_mark
1373 || set_a
->d_mark
> set_b
->d_mark
)
1378 static bool did_watermarks_increase(
1379 struct pipe_ctx
*pipe_ctx
,
1380 struct validate_context
*context
,
1381 struct validate_context
*old_context
)
1383 int collapsed_pipe_idx
= get_bw_result_idx(&context
->res_ctx
,
1384 pipe_ctx
->pipe_idx
);
1385 int old_collapsed_pipe_idx
= get_bw_result_idx(&old_context
->res_ctx
,
1386 pipe_ctx
->pipe_idx
);
1387 struct pipe_ctx
*old_pipe_ctx
= &old_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
1389 if (!old_pipe_ctx
->stream
)
1392 if (is_watermark_set_a_greater(
1393 &context
->bw_results
.nbp_state_change_wm_ns
[collapsed_pipe_idx
],
1394 &old_context
->bw_results
.nbp_state_change_wm_ns
[old_collapsed_pipe_idx
]))
1396 if (is_watermark_set_a_greater(
1397 &context
->bw_results
.stutter_exit_wm_ns
[collapsed_pipe_idx
],
1398 &old_context
->bw_results
.stutter_exit_wm_ns
[old_collapsed_pipe_idx
]))
1400 if (is_watermark_set_a_greater(
1401 &context
->bw_results
.urgent_wm_ns
[collapsed_pipe_idx
],
1402 &old_context
->bw_results
.urgent_wm_ns
[old_collapsed_pipe_idx
]))
1408 static void program_wm_for_pipe(struct core_dc
*dc
,
1409 struct pipe_ctx
*pipe_ctx
,
1410 struct validate_context
*context
)
1412 int total_dest_line_time_ns
= compute_pstate_blackout_duration(
1413 dc
->bw_vbios
.blackout_duration
,
1415 int bw_result_idx
= get_bw_result_idx(&context
->res_ctx
,
1416 pipe_ctx
->pipe_idx
);
1418 pipe_ctx
->mi
->funcs
->mem_input_program_display_marks(
1420 context
->bw_results
.nbp_state_change_wm_ns
[bw_result_idx
],
1421 context
->bw_results
.stutter_exit_wm_ns
[bw_result_idx
],
1422 context
->bw_results
.urgent_wm_ns
[bw_result_idx
],
1423 total_dest_line_time_ns
);
1425 if (pipe_ctx
->top_pipe
)
1426 pipe_ctx
->mi
->funcs
->mem_input_program_chroma_display_marks(
1428 context
->bw_results
.nbp_state_change_wm_ns
[bw_result_idx
+ 1],
1429 context
->bw_results
.stutter_exit_wm_ns
[bw_result_idx
+ 1],
1430 context
->bw_results
.urgent_wm_ns
[bw_result_idx
+ 1],
1431 total_dest_line_time_ns
);
1434 void dce110_set_displaymarks(
1435 const struct core_dc
*dc
,
1436 struct validate_context
*context
)
1438 uint8_t i
, num_pipes
;
1439 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
1441 for (i
= 0, num_pipes
= 0; i
< MAX_PIPES
; i
++) {
1442 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1443 uint32_t total_dest_line_time_ns
;
1445 if (pipe_ctx
->stream
== NULL
)
1448 total_dest_line_time_ns
= compute_pstate_blackout_duration(
1449 dc
->bw_vbios
.blackout_duration
, pipe_ctx
->stream
);
1450 pipe_ctx
->mi
->funcs
->mem_input_program_display_marks(
1452 context
->bw_results
.nbp_state_change_wm_ns
[num_pipes
],
1453 context
->bw_results
.stutter_exit_wm_ns
[num_pipes
],
1454 context
->bw_results
.urgent_wm_ns
[num_pipes
],
1455 total_dest_line_time_ns
);
1456 if (i
== underlay_idx
) {
1458 pipe_ctx
->mi
->funcs
->mem_input_program_chroma_display_marks(
1460 context
->bw_results
.nbp_state_change_wm_ns
[num_pipes
],
1461 context
->bw_results
.stutter_exit_wm_ns
[num_pipes
],
1462 context
->bw_results
.urgent_wm_ns
[num_pipes
],
1463 total_dest_line_time_ns
);
1469 static void set_safe_displaymarks(struct resource_context
*res_ctx
)
1472 int underlay_idx
= res_ctx
->pool
->underlay_pipe_index
;
1473 struct bw_watermarks max_marks
= {
1474 MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
};
1475 struct bw_watermarks nbp_marks
= {
1476 SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
};
1478 for (i
= 0; i
< MAX_PIPES
; i
++) {
1479 if (res_ctx
->pipe_ctx
[i
].stream
== NULL
)
1482 res_ctx
->pipe_ctx
[i
].mi
->funcs
->mem_input_program_display_marks(
1483 res_ctx
->pipe_ctx
[i
].mi
,
1488 if (i
== underlay_idx
)
1489 res_ctx
->pipe_ctx
[i
].mi
->funcs
->mem_input_program_chroma_display_marks(
1490 res_ctx
->pipe_ctx
[i
].mi
,
1498 static void switch_dp_clock_sources(
1499 const struct core_dc
*dc
,
1500 struct resource_context
*res_ctx
)
1503 for (i
= 0; i
< MAX_PIPES
; i
++) {
1504 struct pipe_ctx
*pipe_ctx
= &res_ctx
->pipe_ctx
[i
];
1506 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1509 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
)) {
1510 struct clock_source
*clk_src
=
1511 resource_find_used_clk_src_for_sharing(
1515 clk_src
!= pipe_ctx
->clock_source
) {
1516 resource_unreference_clock_source(
1517 res_ctx
, &pipe_ctx
->clock_source
);
1518 pipe_ctx
->clock_source
= clk_src
;
1519 resource_reference_clock_source(res_ctx
, clk_src
);
1521 dce_crtc_switch_to_clk_src(dc
->hwseq
, clk_src
, i
);
1527 /*******************************************************************************
1529 ******************************************************************************/
1531 static void reset_single_pipe_hw_ctx(
1532 const struct core_dc
*dc
,
1533 struct pipe_ctx
*pipe_ctx
,
1534 struct validate_context
*context
)
1536 core_link_disable_stream(pipe_ctx
);
1537 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, true);
1538 if (!hwss_wait_for_blank_complete(pipe_ctx
->tg
)) {
1539 dm_error("DC: failed to blank crtc!\n");
1540 BREAK_TO_DEBUGGER();
1542 pipe_ctx
->tg
->funcs
->disable_crtc(pipe_ctx
->tg
);
1543 pipe_ctx
->mi
->funcs
->free_mem_input(
1544 pipe_ctx
->mi
, context
->stream_count
);
1545 resource_unreference_clock_source(
1546 &context
->res_ctx
, &pipe_ctx
->clock_source
);
1548 dc
->hwss
.power_down_front_end((struct core_dc
*)dc
, pipe_ctx
);
1550 pipe_ctx
->stream
= NULL
;
1553 static void set_drr(struct pipe_ctx
**pipe_ctx
,
1554 int num_pipes
, int vmin
, int vmax
)
1557 struct drr_params params
= {0};
1559 params
.vertical_total_max
= vmax
;
1560 params
.vertical_total_min
= vmin
;
1562 /* TODO: If multiple pipes are to be supported, you need
1566 for (i
= 0; i
< num_pipes
; i
++) {
1567 pipe_ctx
[i
]->tg
->funcs
->set_drr(pipe_ctx
[i
]->tg
, ¶ms
);
1571 static void set_static_screen_control(struct pipe_ctx
**pipe_ctx
,
1572 int num_pipes
, int value
)
1576 for (i
= 0; i
< num_pipes
; i
++)
1577 pipe_ctx
[i
]->tg
->funcs
->
1578 set_static_screen_control(pipe_ctx
[i
]->tg
, value
);
1581 /* unit: in_khz before mode set, get pixel clock from context. ASIC register
1582 * may not be programmed yet.
1583 * TODO: after mode set, pre_mode_set = false,
1584 * may read PLL register to get pixel clock
1586 static uint32_t get_max_pixel_clock_for_all_paths(
1588 struct validate_context
*context
,
1591 uint32_t max_pix_clk
= 0;
1594 if (!pre_mode_set
) {
1595 /* TODO: read ASIC register to get pixel clock */
1599 for (i
= 0; i
< MAX_PIPES
; i
++) {
1600 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1602 if (pipe_ctx
->stream
== NULL
)
1605 /* do not check under lay */
1606 if (pipe_ctx
->top_pipe
)
1609 if (pipe_ctx
->pix_clk_params
.requested_pix_clk
> max_pix_clk
)
1611 pipe_ctx
->pix_clk_params
.requested_pix_clk
;
1614 if (max_pix_clk
== 0)
1621 * Find clock state based on clock requested. if clock value is 0, simply
1622 * set clock state as requested without finding clock state by clock value
1624 static void apply_min_clocks(
1626 struct validate_context
*context
,
1627 enum dm_pp_clocks_state
*clocks_state
,
1630 struct state_dependent_clocks req_clocks
= {0};
1631 struct pipe_ctx
*pipe_ctx
;
1634 for (i
= 0; i
< MAX_PIPES
; i
++) {
1635 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1636 if (pipe_ctx
->dis_clk
!= NULL
)
1640 if (!pre_mode_set
) {
1641 /* set clock_state without verification */
1642 if (pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state
) {
1643 pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state(
1644 pipe_ctx
->dis_clk
, *clocks_state
);
1651 /* get the required state based on state dependent clocks:
1652 * display clock and pixel clock
1654 req_clocks
.display_clk_khz
= context
->bw_results
.dispclk_khz
;
1656 req_clocks
.pixel_clk_khz
= get_max_pixel_clock_for_all_paths(
1659 if (pipe_ctx
->dis_clk
->funcs
->get_required_clocks_state
) {
1660 *clocks_state
= pipe_ctx
->dis_clk
->funcs
->get_required_clocks_state(
1661 pipe_ctx
->dis_clk
, &req_clocks
);
1662 pipe_ctx
->dis_clk
->funcs
->set_min_clocks_state(
1663 pipe_ctx
->dis_clk
, *clocks_state
);
1668 static enum dc_status
apply_ctx_to_hw_fpga(
1670 struct validate_context
*context
)
1672 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1675 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1676 struct pipe_ctx
*pipe_ctx_old
=
1677 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1678 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1680 if (pipe_ctx
->stream
== NULL
)
1683 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1686 status
= apply_single_controller_ctx_to_hw(
1691 if (status
!= DC_OK
)
1698 static void reset_hw_ctx_wrap(
1700 struct validate_context
*context
)
1704 /* Reset old context */
1705 /* look up the targets that have been removed since last commit */
1706 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1707 struct pipe_ctx
*pipe_ctx_old
=
1708 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1709 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1711 /* Note: We need to disable output if clock sources change,
1712 * since bios does optimization and doesn't apply if changing
1713 * PHY when not already disabled.
1716 /* Skip underlay pipe since it will be handled in commit surface*/
1717 if (!pipe_ctx_old
->stream
|| pipe_ctx_old
->top_pipe
)
1720 if (!pipe_ctx
->stream
||
1721 pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
1722 reset_single_pipe_hw_ctx(
1723 dc
, pipe_ctx_old
, dc
->current_context
);
1727 /*TODO: const validate_context*/
1728 enum dc_status
dce110_apply_ctx_to_hw(
1730 struct validate_context
*context
)
1732 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
1733 enum dc_status status
;
1735 bool programmed_audio_dto
= false;
1736 enum dm_pp_clocks_state clocks_state
= DM_PP_CLOCKS_STATE_INVALID
;
1738 /* Reset old context */
1739 /* look up the targets that have been removed since last commit */
1740 dc
->hwss
.reset_hw_ctx_wrap(dc
, context
);
1742 /* Skip applying if no targets */
1743 if (context
->stream_count
<= 0)
1746 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1747 apply_ctx_to_hw_fpga(dc
, context
);
1751 /* Apply new context */
1752 dcb
->funcs
->set_scratch_critical_state(dcb
, true);
1754 /* below is for real asic only */
1755 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1756 struct pipe_ctx
*pipe_ctx_old
=
1757 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1758 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1760 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1763 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
) {
1764 if (pipe_ctx_old
->clock_source
!= pipe_ctx
->clock_source
)
1765 dce_crtc_switch_to_clk_src(dc
->hwseq
,
1766 pipe_ctx
->clock_source
, i
);
1770 dc
->hwss
.enable_display_power_gating(
1771 dc
, i
, dc
->ctx
->dc_bios
,
1772 PIPE_GATING_CONTROL_DISABLE
);
1775 set_safe_displaymarks(&context
->res_ctx
);
1776 /*TODO: when pplib works*/
1777 apply_min_clocks(dc
, context
, &clocks_state
, true);
1779 if (context
->bw_results
.dispclk_khz
1780 > dc
->current_context
->bw_results
.dispclk_khz
)
1781 context
->res_ctx
.pool
->display_clock
->funcs
->set_clock(
1782 context
->res_ctx
.pool
->display_clock
,
1783 context
->bw_results
.dispclk_khz
* 115 / 100);
1785 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
1786 struct pipe_ctx
*pipe_ctx_old
=
1787 &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
1788 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1790 if (pipe_ctx
->stream
== NULL
)
1793 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1796 if (pipe_ctx
->top_pipe
)
1799 if (context
->res_ctx
.pipe_ctx
[i
].audio
!= NULL
) {
1800 /* Setup audio rate clock source */
1802 * Audio lag happened on DP monitor when unplug a HDMI monitor
1805 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
1806 * is set to either dto0 or dto1, audio should work fine.
1807 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
1808 * set to dto0 will cause audio lag.
1811 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
1812 * find first available pipe with audio, setup audio wall DTO per topology
1813 * instead of per pipe.
1815 struct audio_output audio_output
;
1817 build_audio_output(pipe_ctx
, &audio_output
);
1819 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1820 pipe_ctx
->stream_enc
->funcs
->dp_audio_setup(
1821 pipe_ctx
->stream_enc
,
1822 pipe_ctx
->audio
->inst
,
1823 &pipe_ctx
->stream
->public.audio_info
);
1825 pipe_ctx
->stream_enc
->funcs
->hdmi_audio_setup(
1826 pipe_ctx
->stream_enc
,
1827 pipe_ctx
->audio
->inst
,
1828 &pipe_ctx
->stream
->public.audio_info
,
1829 &audio_output
.crtc_info
);
1831 pipe_ctx
->audio
->funcs
->az_configure(
1833 pipe_ctx
->stream
->signal
,
1834 &audio_output
.crtc_info
,
1835 &pipe_ctx
->stream
->public.audio_info
);
1837 if (!programmed_audio_dto
) {
1838 pipe_ctx
->audio
->funcs
->wall_dto_setup(
1840 pipe_ctx
->stream
->signal
,
1841 &audio_output
.crtc_info
,
1842 &audio_output
.pll_info
);
1843 programmed_audio_dto
= true;
1847 status
= apply_single_controller_ctx_to_hw(
1852 if (DC_OK
!= status
)
1856 dc
->hwss
.set_displaymarks(dc
, context
);
1859 apply_min_clocks(dc
, context
, &clocks_state
, false);
1861 dcb
->funcs
->set_scratch_critical_state(dcb
, false);
1863 switch_dp_clock_sources(dc
, &context
->res_ctx
);
1868 /*******************************************************************************
1869 * Front End programming
1870 ******************************************************************************/
1871 static void set_default_colors(struct pipe_ctx
*pipe_ctx
)
1873 struct default_adjustment default_adjust
= { 0 };
1875 default_adjust
.force_hw_default
= false;
1876 if (pipe_ctx
->surface
== NULL
)
1877 default_adjust
.in_color_space
= COLOR_SPACE_SRGB
;
1879 default_adjust
.in_color_space
=
1880 pipe_ctx
->surface
->public.color_space
;
1881 if (pipe_ctx
->stream
== NULL
)
1882 default_adjust
.out_color_space
= COLOR_SPACE_SRGB
;
1884 default_adjust
.out_color_space
=
1885 pipe_ctx
->stream
->public.output_color_space
;
1886 default_adjust
.csc_adjust_type
= GRAPHICS_CSC_ADJUST_TYPE_SW
;
1887 default_adjust
.surface_pixel_format
= pipe_ctx
->scl_data
.format
;
1889 /* display color depth */
1890 default_adjust
.color_depth
=
1891 pipe_ctx
->stream
->public.timing
.display_color_depth
;
1893 /* Lb color depth */
1894 default_adjust
.lb_color_depth
= pipe_ctx
->scl_data
.lb_params
.depth
;
1896 pipe_ctx
->opp
->funcs
->opp_set_csc_default(
1897 pipe_ctx
->opp
, &default_adjust
);
1901 /*******************************************************************************
1902 * In order to turn on/off specific surface we will program
1905 * In case that we have two surfaces and they have a different visibility
1906 * we can't turn off the CRTC since it will turn off the entire display
1908 * |----------------------------------------------- |
1909 * |bottom pipe|curr pipe | | |
1910 * |Surface |Surface | Blender | CRCT |
1911 * |visibility |visibility | Configuration| |
1912 * |------------------------------------------------|
1913 * | off | off | CURRENT_PIPE | blank |
1914 * | off | on | CURRENT_PIPE | unblank |
1915 * | on | off | OTHER_PIPE | unblank |
1916 * | on | on | BLENDING | unblank |
1917 * -------------------------------------------------|
1919 ******************************************************************************/
1920 static void program_surface_visibility(const struct core_dc
*dc
,
1921 struct pipe_ctx
*pipe_ctx
)
1923 enum blnd_mode blender_mode
= BLND_MODE_CURRENT_PIPE
;
1924 bool blank_target
= false;
1926 if (pipe_ctx
->bottom_pipe
) {
1928 /* For now we are supporting only two pipes */
1929 ASSERT(pipe_ctx
->bottom_pipe
->bottom_pipe
== NULL
);
1931 if (pipe_ctx
->bottom_pipe
->surface
->public.visible
) {
1932 if (pipe_ctx
->surface
->public.visible
)
1933 blender_mode
= BLND_MODE_BLENDING
;
1935 blender_mode
= BLND_MODE_OTHER_PIPE
;
1937 } else if (!pipe_ctx
->surface
->public.visible
)
1938 blank_target
= true;
1940 } else if (!pipe_ctx
->surface
->public.visible
)
1941 blank_target
= true;
1943 dce_set_blender_mode(dc
->hwseq
, pipe_ctx
->pipe_idx
, blender_mode
);
1944 pipe_ctx
->tg
->funcs
->set_blank(pipe_ctx
->tg
, blank_target
);
1949 * TODO REMOVE, USE UPDATE INSTEAD
1951 static void set_plane_config(
1952 const struct core_dc
*dc
,
1953 struct pipe_ctx
*pipe_ctx
,
1954 struct resource_context
*res_ctx
)
1956 struct mem_input
*mi
= pipe_ctx
->mi
;
1957 struct core_surface
*surface
= pipe_ctx
->surface
;
1958 struct xfm_grph_csc_adjustment adjust
;
1959 struct out_csc_color_matrix tbl_entry
;
1962 memset(&adjust
, 0, sizeof(adjust
));
1963 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
1964 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
1966 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
1968 set_default_colors(pipe_ctx
);
1969 if (pipe_ctx
->stream
->public.csc_color_matrix
.enable_adjustment
1971 tbl_entry
.color_space
=
1972 pipe_ctx
->stream
->public.output_color_space
;
1974 for (i
= 0; i
< 12; i
++)
1975 tbl_entry
.regval
[i
] =
1976 pipe_ctx
->stream
->public.csc_color_matrix
.matrix
[i
];
1978 pipe_ctx
->opp
->funcs
->opp_set_csc_adjustment
1979 (pipe_ctx
->opp
, &tbl_entry
);
1982 if (pipe_ctx
->stream
->public.gamut_remap_matrix
.enable_remap
== true) {
1983 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
1984 adjust
.temperature_matrix
[0] =
1986 public.gamut_remap_matrix
.matrix
[0];
1987 adjust
.temperature_matrix
[1] =
1989 public.gamut_remap_matrix
.matrix
[1];
1990 adjust
.temperature_matrix
[2] =
1992 public.gamut_remap_matrix
.matrix
[2];
1993 adjust
.temperature_matrix
[3] =
1995 public.gamut_remap_matrix
.matrix
[4];
1996 adjust
.temperature_matrix
[4] =
1998 public.gamut_remap_matrix
.matrix
[5];
1999 adjust
.temperature_matrix
[5] =
2001 public.gamut_remap_matrix
.matrix
[6];
2002 adjust
.temperature_matrix
[6] =
2004 public.gamut_remap_matrix
.matrix
[8];
2005 adjust
.temperature_matrix
[7] =
2007 public.gamut_remap_matrix
.matrix
[9];
2008 adjust
.temperature_matrix
[8] =
2010 public.gamut_remap_matrix
.matrix
[10];
2013 pipe_ctx
->xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->xfm
, &adjust
);
2015 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2016 program_scaler(dc
, pipe_ctx
);
2018 program_surface_visibility(dc
, pipe_ctx
);
2020 mi
->funcs
->mem_input_program_surface_config(
2022 surface
->public.format
,
2023 &surface
->public.tiling_info
,
2024 &surface
->public.plane_size
,
2025 surface
->public.rotation
,
2028 pipe_ctx
->surface
->public.visible
);
2030 if (dc
->public.config
.gpu_vm_support
)
2031 mi
->funcs
->mem_input_program_pte_vm(
2033 surface
->public.format
,
2034 &surface
->public.tiling_info
,
2035 surface
->public.rotation
);
2038 static void update_plane_addr(const struct core_dc
*dc
,
2039 struct pipe_ctx
*pipe_ctx
)
2041 struct core_surface
*surface
= pipe_ctx
->surface
;
2043 if (surface
== NULL
)
2046 pipe_ctx
->mi
->funcs
->mem_input_program_surface_flip_and_addr(
2048 &surface
->public.address
,
2049 surface
->public.flip_immediate
);
2051 surface
->status
.requested_address
= surface
->public.address
;
2054 void dce110_update_pending_status(struct pipe_ctx
*pipe_ctx
)
2056 struct core_surface
*surface
= pipe_ctx
->surface
;
2058 if (surface
== NULL
)
2061 surface
->status
.is_flip_pending
=
2062 pipe_ctx
->mi
->funcs
->mem_input_is_flip_pending(
2065 if (surface
->status
.is_flip_pending
&& !surface
->public.visible
)
2066 pipe_ctx
->mi
->current_address
= pipe_ctx
->mi
->request_address
;
2068 surface
->status
.current_address
= pipe_ctx
->mi
->current_address
;
2071 void dce110_power_down(struct core_dc
*dc
)
2073 power_down_all_hw_blocks(dc
);
2074 disable_vga_and_power_gate_all_controllers(dc
);
2077 static bool wait_for_reset_trigger_to_occur(
2078 struct dc_context
*dc_ctx
,
2079 struct timing_generator
*tg
)
2083 /* To avoid endless loop we wait at most
2084 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2085 const uint32_t frames_to_wait_on_triggered_reset
= 10;
2088 for (i
= 0; i
< frames_to_wait_on_triggered_reset
; i
++) {
2090 if (!tg
->funcs
->is_counter_moving(tg
)) {
2091 DC_ERROR("TG counter is not moving!\n");
2095 if (tg
->funcs
->did_triggered_reset_occur(tg
)) {
2097 /* usually occurs at i=1 */
2098 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2103 /* Wait for one frame. */
2104 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VACTIVE
);
2105 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VBLANK
);
2109 DC_ERROR("GSL: Timeout on reset trigger!\n");
2114 /* Enable timing synchronization for a group of Timing Generators. */
2115 static void dce110_enable_timing_synchronization(
2119 struct pipe_ctx
*grouped_pipes
[])
2121 struct dc_context
*dc_ctx
= dc
->ctx
;
2122 struct dcp_gsl_params gsl_params
= { 0 };
2125 DC_SYNC_INFO("GSL: Setting-up...\n");
2127 /* Designate a single TG in the group as a master.
2128 * Since HW doesn't care which one, we always assign
2129 * the 1st one in the group. */
2130 gsl_params
.gsl_group
= 0;
2131 gsl_params
.gsl_master
= grouped_pipes
[0]->tg
->inst
;
2133 for (i
= 0; i
< group_size
; i
++)
2134 grouped_pipes
[i
]->tg
->funcs
->setup_global_swap_lock(
2135 grouped_pipes
[i
]->tg
, &gsl_params
);
2137 /* Reset slave controllers on master VSync */
2138 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2140 for (i
= 1 /* skip the master */; i
< group_size
; i
++)
2141 grouped_pipes
[i
]->tg
->funcs
->enable_reset_trigger(
2142 grouped_pipes
[i
]->tg
, gsl_params
.gsl_group
);
2146 for (i
= 1 /* skip the master */; i
< group_size
; i
++) {
2147 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2148 wait_for_reset_trigger_to_occur(dc_ctx
, grouped_pipes
[i
]->tg
);
2149 /* Regardless of success of the wait above, remove the reset or
2150 * the driver will start timing out on Display requests. */
2151 DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
2152 grouped_pipes
[i
]->tg
->funcs
->disable_reset_trigger(grouped_pipes
[i
]->tg
);
2156 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2157 * is that the sync'ed displays will not drift out of sync over time*/
2158 DC_SYNC_INFO("GSL: Restoring register states.\n");
2159 for (i
= 0; i
< group_size
; i
++)
2160 grouped_pipes
[i
]->tg
->funcs
->tear_down_global_swap_lock(grouped_pipes
[i
]->tg
);
2162 DC_SYNC_INFO("GSL: Set-up complete.\n");
2165 static void init_hw(struct core_dc
*dc
)
2169 struct transform
*xfm
;
2172 bp
= dc
->ctx
->dc_bios
;
2173 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2174 xfm
= dc
->res_pool
->transforms
[i
];
2175 xfm
->funcs
->transform_reset(xfm
);
2177 dc
->hwss
.enable_display_power_gating(
2179 PIPE_GATING_CONTROL_INIT
);
2180 dc
->hwss
.enable_display_power_gating(
2182 PIPE_GATING_CONTROL_DISABLE
);
2183 dc
->hwss
.enable_display_pipe_clock_gating(
2188 dce_clock_gating_power_up(dc
->hwseq
, false);;
2189 /***************************************/
2191 for (i
= 0; i
< dc
->link_count
; i
++) {
2192 /****************************************/
2193 /* Power up AND update implementation according to the
2194 * required signal (which may be different from the
2195 * default signal on connector). */
2196 struct core_link
*link
= dc
->links
[i
];
2197 link
->link_enc
->funcs
->hw_init(link
->link_enc
);
2200 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2201 struct timing_generator
*tg
= dc
->res_pool
->timing_generators
[i
];
2203 tg
->funcs
->disable_vga(tg
);
2205 /* Blank controller using driver code instead of
2207 tg
->funcs
->set_blank(tg
, true);
2208 hwss_wait_for_blank_complete(tg
);
2211 for (i
= 0; i
< dc
->res_pool
->audio_count
; i
++) {
2212 struct audio
*audio
= dc
->res_pool
->audios
[i
];
2213 audio
->funcs
->hw_init(audio
);
2216 abm
= dc
->res_pool
->abm
;
2218 abm
->funcs
->abm_init(abm
);
2221 /* TODO: move this to apply_ctx_tohw some how?*/
2222 static void dce110_power_on_pipe_if_needed(
2224 struct pipe_ctx
*pipe_ctx
,
2225 struct validate_context
*context
)
2227 struct pipe_ctx
*old_pipe_ctx
= &dc
->current_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2228 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
2229 struct tg_color black_color
= {0};
2231 if (!old_pipe_ctx
->stream
&& pipe_ctx
->stream
) {
2232 dc
->hwss
.enable_display_power_gating(
2235 dcb
, PIPE_GATING_CONTROL_DISABLE
);
2238 * This is for powering on underlay, so crtc does not
2239 * need to be enabled
2242 pipe_ctx
->tg
->funcs
->program_timing(pipe_ctx
->tg
,
2243 &pipe_ctx
->stream
->public.timing
,
2246 pipe_ctx
->tg
->funcs
->enable_advanced_request(
2249 &pipe_ctx
->stream
->public.timing
);
2251 pipe_ctx
->mi
->funcs
->allocate_mem_input(pipe_ctx
->mi
,
2252 pipe_ctx
->stream
->public.timing
.h_total
,
2253 pipe_ctx
->stream
->public.timing
.v_total
,
2254 pipe_ctx
->stream
->public.timing
.pix_clk_khz
,
2255 context
->stream_count
);
2257 /* TODO unhardcode*/
2258 color_space_to_black_color(dc
,
2259 COLOR_SPACE_YCBCR601
, &black_color
);
2260 pipe_ctx
->tg
->funcs
->set_blank_color(
2266 static void dce110_increase_watermarks_for_pipe(
2268 struct pipe_ctx
*pipe_ctx
,
2269 struct validate_context
*context
)
2271 if (did_watermarks_increase(pipe_ctx
, context
, dc
->current_context
))
2272 program_wm_for_pipe(dc
, pipe_ctx
, context
);
2275 static void dce110_set_bandwidth(struct core_dc
*dc
)
2279 for (i
= 0; i
< dc
->current_context
->res_ctx
.pool
->pipe_count
; i
++) {
2280 struct pipe_ctx
*pipe_ctx
= &dc
->current_context
->res_ctx
.pipe_ctx
[i
];
2282 if (!pipe_ctx
->stream
)
2285 program_wm_for_pipe(dc
, pipe_ctx
, dc
->current_context
);
2288 dc
->current_context
->res_ctx
.pool
->display_clock
->funcs
->set_clock(
2289 dc
->current_context
->res_ctx
.pool
->display_clock
,
2290 dc
->current_context
->bw_results
.dispclk_khz
* 115 / 100);
2293 static void dce110_program_front_end_for_pipe(
2294 struct core_dc
*dc
, struct pipe_ctx
*pipe_ctx
)
2296 struct mem_input
*mi
= pipe_ctx
->mi
;
2297 struct pipe_ctx
*old_pipe
= NULL
;
2298 struct core_surface
*surface
= pipe_ctx
->surface
;
2299 struct xfm_grph_csc_adjustment adjust
;
2300 struct out_csc_color_matrix tbl_entry
;
2303 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2305 if (dc
->current_context
)
2306 old_pipe
= &dc
->current_context
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2308 memset(&adjust
, 0, sizeof(adjust
));
2309 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2311 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2313 set_default_colors(pipe_ctx
);
2314 if (pipe_ctx
->stream
->public.csc_color_matrix
.enable_adjustment
2316 tbl_entry
.color_space
=
2317 pipe_ctx
->stream
->public.output_color_space
;
2319 for (i
= 0; i
< 12; i
++)
2320 tbl_entry
.regval
[i
] =
2321 pipe_ctx
->stream
->public.csc_color_matrix
.matrix
[i
];
2323 pipe_ctx
->opp
->funcs
->opp_set_csc_adjustment
2324 (pipe_ctx
->opp
, &tbl_entry
);
2327 if (pipe_ctx
->stream
->public.gamut_remap_matrix
.enable_remap
== true) {
2328 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2329 adjust
.temperature_matrix
[0] =
2331 public.gamut_remap_matrix
.matrix
[0];
2332 adjust
.temperature_matrix
[1] =
2334 public.gamut_remap_matrix
.matrix
[1];
2335 adjust
.temperature_matrix
[2] =
2337 public.gamut_remap_matrix
.matrix
[2];
2338 adjust
.temperature_matrix
[3] =
2340 public.gamut_remap_matrix
.matrix
[4];
2341 adjust
.temperature_matrix
[4] =
2343 public.gamut_remap_matrix
.matrix
[5];
2344 adjust
.temperature_matrix
[5] =
2346 public.gamut_remap_matrix
.matrix
[6];
2347 adjust
.temperature_matrix
[6] =
2349 public.gamut_remap_matrix
.matrix
[8];
2350 adjust
.temperature_matrix
[7] =
2352 public.gamut_remap_matrix
.matrix
[9];
2353 adjust
.temperature_matrix
[8] =
2355 public.gamut_remap_matrix
.matrix
[10];
2358 pipe_ctx
->xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->xfm
, &adjust
);
2360 pipe_ctx
->scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2361 if (old_pipe
&& memcmp(&old_pipe
->scl_data
,
2362 &pipe_ctx
->scl_data
,
2363 sizeof(struct scaler_data
)) != 0)
2364 program_scaler(dc
, pipe_ctx
);
2366 mi
->funcs
->mem_input_program_surface_config(
2368 surface
->public.format
,
2369 &surface
->public.tiling_info
,
2370 &surface
->public.plane_size
,
2371 surface
->public.rotation
,
2374 pipe_ctx
->surface
->public.visible
);
2376 if (dc
->public.config
.gpu_vm_support
)
2377 mi
->funcs
->mem_input_program_pte_vm(
2379 surface
->public.format
,
2380 &surface
->public.tiling_info
,
2381 surface
->public.rotation
);
2383 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2384 "Pipe:%d 0x%x: addr hi:0x%x, "
2387 " %d; dst: %d, %d, %d, %d;"
2388 "clip: %d, %d, %d, %d\n",
2391 pipe_ctx
->surface
->public.address
.grph
.addr
.high_part
,
2392 pipe_ctx
->surface
->public.address
.grph
.addr
.low_part
,
2393 pipe_ctx
->surface
->public.src_rect
.x
,
2394 pipe_ctx
->surface
->public.src_rect
.y
,
2395 pipe_ctx
->surface
->public.src_rect
.width
,
2396 pipe_ctx
->surface
->public.src_rect
.height
,
2397 pipe_ctx
->surface
->public.dst_rect
.x
,
2398 pipe_ctx
->surface
->public.dst_rect
.y
,
2399 pipe_ctx
->surface
->public.dst_rect
.width
,
2400 pipe_ctx
->surface
->public.dst_rect
.height
,
2401 pipe_ctx
->surface
->public.clip_rect
.x
,
2402 pipe_ctx
->surface
->public.clip_rect
.y
,
2403 pipe_ctx
->surface
->public.clip_rect
.width
,
2404 pipe_ctx
->surface
->public.clip_rect
.height
);
2406 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2407 "Pipe %d: width, height, x, y\n"
2408 "viewport:%d, %d, %d, %d\n"
2409 "recout: %d, %d, %d, %d\n",
2411 pipe_ctx
->scl_data
.viewport
.width
,
2412 pipe_ctx
->scl_data
.viewport
.height
,
2413 pipe_ctx
->scl_data
.viewport
.x
,
2414 pipe_ctx
->scl_data
.viewport
.y
,
2415 pipe_ctx
->scl_data
.recout
.width
,
2416 pipe_ctx
->scl_data
.recout
.height
,
2417 pipe_ctx
->scl_data
.recout
.x
,
2418 pipe_ctx
->scl_data
.recout
.y
);
2421 static void dce110_prepare_pipe_for_context(
2423 struct pipe_ctx
*pipe_ctx
,
2424 struct validate_context
*context
)
2426 dce110_power_on_pipe_if_needed(dc
, pipe_ctx
, context
);
2427 dc
->hwss
.increase_watermarks_for_pipe(dc
, pipe_ctx
, context
);
2430 static void dce110_apply_ctx_for_surface(
2432 struct core_surface
*surface
,
2433 struct validate_context
*context
)
2437 /* TODO remove when removing the surface reset workaroud*/
2441 for (i
= 0; i
< context
->res_ctx
.pool
->pipe_count
; i
++) {
2442 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2444 if (pipe_ctx
->surface
!= surface
)
2447 dce110_program_front_end_for_pipe(dc
, pipe_ctx
);
2448 program_surface_visibility(dc
, pipe_ctx
);
2453 static void dce110_power_down_fe(struct core_dc
*dc
, struct pipe_ctx
*pipe
)
2457 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++)
2458 if (&dc
->current_context
->res_ctx
.pipe_ctx
[i
] == pipe
)
2461 if (i
== dc
->res_pool
->pipe_count
)
2464 dc
->hwss
.enable_display_power_gating(
2465 dc
, i
, dc
->ctx
->dc_bios
, PIPE_GATING_CONTROL_ENABLE
);
2467 pipe
->xfm
->funcs
->transform_reset(pipe
->xfm
);
2468 memset(&pipe
->scl_data
, 0, sizeof(struct scaler_data
));
2471 static const struct hw_sequencer_funcs dce110_funcs
= {
2473 .apply_ctx_to_hw
= dce110_apply_ctx_to_hw
,
2474 .prepare_pipe_for_context
= dce110_prepare_pipe_for_context
,
2475 .apply_ctx_for_surface
= dce110_apply_ctx_for_surface
,
2476 .set_plane_config
= set_plane_config
,
2477 .update_plane_addr
= update_plane_addr
,
2478 .update_pending_status
= dce110_update_pending_status
,
2479 .set_input_transfer_func
= dce110_set_input_transfer_func
,
2480 .set_output_transfer_func
= dce110_set_output_transfer_func
,
2481 .power_down
= dce110_power_down
,
2482 .enable_accelerated_mode
= dce110_enable_accelerated_mode
,
2483 .enable_timing_synchronization
= dce110_enable_timing_synchronization
,
2484 .update_info_frame
= dce110_update_info_frame
,
2485 .enable_stream
= dce110_enable_stream
,
2486 .disable_stream
= dce110_disable_stream
,
2487 .unblank_stream
= dce110_unblank_stream
,
2488 .enable_display_pipe_clock_gating
= enable_display_pipe_clock_gating
,
2489 .enable_display_power_gating
= dce110_enable_display_power_gating
,
2490 .power_down_front_end
= dce110_power_down_fe
,
2491 .pipe_control_lock
= dce_pipe_control_lock
,
2492 .set_displaymarks
= dce110_set_displaymarks
,
2493 .increase_watermarks_for_pipe
= dce110_increase_watermarks_for_pipe
,
2494 .set_bandwidth
= dce110_set_bandwidth
,
2496 .set_static_screen_control
= set_static_screen_control
,
2497 .reset_hw_ctx_wrap
= reset_hw_ctx_wrap
,
2498 .prog_pixclk_crtc_otg
= dce110_prog_pixclk_crtc_otg
,
2501 bool dce110_hw_sequencer_construct(struct core_dc
*dc
)
2503 dc
->hwss
= dce110_funcs
;