2 * Copyright 2016 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "dm_services.h"
30 #include "include/irq_service_interface.h"
31 #include "dcn10/dcn10_resource.h"
33 #include "dcn10/dcn10_ipp.h"
34 #include "dcn10/dcn10_mpc.h"
35 #include "irq/dcn10/irq_service_dcn10.h"
36 #include "dcn10/dcn10_dpp.h"
37 #include "dcn10/dcn10_timing_generator.h"
38 #include "dcn10/dcn10_hw_sequencer.h"
39 #include "dce110/dce110_hw_sequencer.h"
40 #include "dcn10/dcn10_opp.h"
41 #include "dce/dce_link_encoder.h"
42 #include "dce/dce_stream_encoder.h"
43 #include "dce/dce_clocks.h"
44 #include "dce/dce_clock_source.h"
45 #include "dce/dce_audio.h"
46 #include "dce/dce_hwseq.h"
47 #include "../virtual/virtual_stream_encoder.h"
48 #include "dce110/dce110_resource.h"
49 #include "dce112/dce112_resource.h"
50 #include "dcn10_hubp.h"
51 #include "dcn10_hubbub.h"
55 #include "dcn/dcn_1_0_offset.h"
56 #include "dcn/dcn_1_0_sh_mask.h"
58 #include "nbio/nbio_7_0_offset.h"
60 #include "mmhub/mmhub_9_1_offset.h"
61 #include "mmhub/mmhub_9_1_sh_mask.h"
63 #include "reg_helper.h"
64 #include "dce/dce_abm.h"
65 #include "dce/dce_dmcu.h"
67 #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
68 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x210f
69 #define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
70 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x220f
71 #define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
72 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x230f
73 #define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
74 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x240f
75 #define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
76 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x250f
77 #define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
78 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x260f
79 #define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
80 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x270f
81 #define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
85 enum dcn10_clk_src_array_id {
93 /* begin *********************
94 * macros to expend register list macro defined in HW object header file */
97 #define BASE_INNER(seg) \
98 DCE_BASE__INST0_SEG ## seg
103 #define SR(reg_name)\
104 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
107 #define SRI(reg_name, block, id)\
108 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
109 mm ## block ## id ## _ ## reg_name
112 #define SRII(reg_name, block, id)\
113 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
114 mm ## block ## id ## _ ## reg_name
117 #define NBIO_BASE_INNER(seg) \
118 NBIF_BASE__INST0_SEG ## seg
120 #define NBIO_BASE(seg) \
123 #define NBIO_SR(reg_name)\
124 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
128 #define MMHUB_BASE_INNER(seg) \
129 MMHUB_BASE__INST0_SEG ## seg
131 #define MMHUB_BASE(seg) \
132 MMHUB_BASE_INNER(seg)
134 #define MMHUB_SR(reg_name)\
135 .reg_name = MMHUB_BASE(mm ## reg_name ## _BASE_IDX) + \
138 /* macros to expend register list macro defined in HW object header file
139 * end *********************/
142 static const struct dce_dmcu_registers dmcu_regs = {
143 DMCU_DCN10_REG_LIST()
146 static const struct dce_dmcu_shift dmcu_shift = {
147 DMCU_MASK_SH_LIST_DCN10(__SHIFT)
150 static const struct dce_dmcu_mask dmcu_mask = {
151 DMCU_MASK_SH_LIST_DCN10(_MASK)
154 static const struct dce_abm_registers abm_regs = {
155 ABM_DCN10_REG_LIST(0)
158 static const struct dce_abm_shift abm_shift = {
159 ABM_MASK_SH_LIST_DCN10(__SHIFT)
162 static const struct dce_abm_mask abm_mask = {
163 ABM_MASK_SH_LIST_DCN10(_MASK)
166 #define stream_enc_regs(id)\
168 SE_DCN_REG_LIST(id),\
170 .AFMT_AVI_INFO0 = 0,\
171 .AFMT_AVI_INFO1 = 0,\
172 .AFMT_AVI_INFO2 = 0,\
173 .AFMT_AVI_INFO3 = 0,\
176 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
183 static const struct dce_stream_encoder_shift se_shift = {
184 SE_COMMON_MASK_SH_LIST_DCN10(__SHIFT)
187 static const struct dce_stream_encoder_mask se_mask = {
188 SE_COMMON_MASK_SH_LIST_DCN10(_MASK),
189 .AFMT_GENERIC0_UPDATE = 0,
190 .AFMT_GENERIC2_UPDATE = 0,
193 .HDMI_AVI_INFO_SEND = 0,
194 .HDMI_AVI_INFO_CONT = 0,
195 .HDMI_AVI_INFO_LINE = 0,
196 .DP_SEC_AVI_ENABLE = 0,
197 .AFMT_AVI_INFO_VERSION = 0
200 #define audio_regs(id)\
202 AUD_COMMON_REG_LIST(id)\
205 static const struct dce_audio_registers audio_regs[] = {
212 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
213 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
214 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
215 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
217 static const struct dce_audio_shift audio_shift = {
218 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
221 static const struct dce_aduio_mask audio_mask = {
222 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
225 #define aux_regs(id)\
230 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
239 #define hpd_regs(id)\
244 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
253 #define link_regs(id)\
255 LE_DCN10_REG_LIST(id), \
256 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
259 static const struct dce110_link_enc_registers link_enc_regs[] = {
269 #define ipp_regs(id)\
271 IPP_REG_LIST_DCN10(id),\
274 static const struct dcn10_ipp_registers ipp_regs[] = {
281 static const struct dcn10_ipp_shift ipp_shift = {
282 IPP_MASK_SH_LIST_DCN10(__SHIFT)
285 static const struct dcn10_ipp_mask ipp_mask = {
286 IPP_MASK_SH_LIST_DCN10(_MASK),
289 #define opp_regs(id)\
291 OPP_REG_LIST_DCN10(id),\
294 static const struct dcn10_opp_registers opp_regs[] = {
301 static const struct dcn10_opp_shift opp_shift = {
302 OPP_MASK_SH_LIST_DCN10(__SHIFT)
305 static const struct dcn10_opp_mask opp_mask = {
306 OPP_MASK_SH_LIST_DCN10(_MASK),
311 TF_REG_LIST_DCN10(id),\
314 static const struct dcn_dpp_registers tf_regs[] = {
321 static const struct dcn_dpp_shift tf_shift = {
322 TF_REG_LIST_SH_MASK_DCN10(__SHIFT)
325 static const struct dcn_dpp_mask tf_mask = {
326 TF_REG_LIST_SH_MASK_DCN10(_MASK),
329 static const struct dcn_mpc_registers mpc_regs = {
330 MPC_COMMON_REG_LIST_DCN1_0(0),
331 MPC_COMMON_REG_LIST_DCN1_0(1),
332 MPC_COMMON_REG_LIST_DCN1_0(2),
333 MPC_COMMON_REG_LIST_DCN1_0(3),
334 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(0),
335 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(1),
336 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(2),
337 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(3)
340 static const struct dcn_mpc_shift mpc_shift = {
341 MPC_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
344 static const struct dcn_mpc_mask mpc_mask = {
345 MPC_COMMON_MASK_SH_LIST_DCN1_0(_MASK),
349 [id] = {TG_COMMON_REG_LIST_DCN1_0(id)}
351 static const struct dcn_optc_registers tg_regs[] = {
358 static const struct dcn_optc_shift tg_shift = {
359 TG_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
362 static const struct dcn_optc_mask tg_mask = {
363 TG_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
367 static const struct bios_registers bios_regs = {
368 NBIO_SR(BIOS_SCRATCH_6)
371 #define hubp_regs(id)\
373 HUBP_REG_LIST_DCN10(id)\
377 static const struct dcn_mi_registers hubp_regs[] = {
384 static const struct dcn_mi_shift hubp_shift = {
385 HUBP_MASK_SH_LIST_DCN10(__SHIFT)
388 static const struct dcn_mi_mask hubp_mask = {
389 HUBP_MASK_SH_LIST_DCN10(_MASK)
393 static const struct dcn_hubbub_registers hubbub_reg = {
394 HUBBUB_REG_LIST_DCN10(0)
397 static const struct dcn_hubbub_shift hubbub_shift = {
398 HUBBUB_MASK_SH_LIST_DCN10(__SHIFT)
401 static const struct dcn_hubbub_mask hubbub_mask = {
402 HUBBUB_MASK_SH_LIST_DCN10(_MASK)
405 #define clk_src_regs(index, pllid)\
407 CS_COMMON_REG_LIST_DCN1_0(index, pllid),\
410 static const struct dce110_clk_src_regs clk_src_regs[] = {
417 static const struct dce110_clk_src_shift cs_shift = {
418 CS_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
421 static const struct dce110_clk_src_mask cs_mask = {
422 CS_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
426 static const struct resource_caps res_cap = {
427 .num_timing_generator = 4,
428 .num_video_plane = 4,
430 .num_stream_encoder = 4,
434 static const struct dc_debug debug_defaults_drv = {
435 .sanity_checks = true,
436 .disable_dmcu = true,
437 .force_abm_enable = false,
438 .timing_trace = false,
441 .min_disp_clk_khz = 300000,
443 .disable_pplib_clock_request = true,
444 .disable_pplib_wm_range = false,
445 .pplib_wm_report_mode = WM_REPORT_DEFAULT,
446 .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
447 .force_single_disp_pipe_split = true,
448 .disable_dcc = DCC_ENABLE,
449 .voltage_align_fclk = true,
450 .disable_stereo_support = true,
452 .performance_trace = false,
455 static const struct dc_debug debug_defaults_diags = {
456 .disable_dmcu = true,
457 .force_abm_enable = false,
458 .timing_trace = true,
460 .disable_stutter = true,
461 .disable_pplib_clock_request = true,
462 .disable_pplib_wm_range = true
465 static void dcn10_dpp_destroy(struct dpp **dpp)
467 kfree(TO_DCN10_DPP(*dpp));
471 static struct dpp *dcn10_dpp_create(
472 struct dc_context *ctx,
475 struct dcn10_dpp *dpp =
476 kzalloc(sizeof(struct dcn10_dpp), GFP_KERNEL);
481 dpp1_construct(dpp, ctx, inst,
482 &tf_regs[inst], &tf_shift, &tf_mask);
486 static struct input_pixel_processor *dcn10_ipp_create(
487 struct dc_context *ctx, uint32_t inst)
489 struct dcn10_ipp *ipp =
490 kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL);
497 dcn10_ipp_construct(ipp, ctx, inst,
498 &ipp_regs[inst], &ipp_shift, &ipp_mask);
503 static struct output_pixel_processor *dcn10_opp_create(
504 struct dc_context *ctx, uint32_t inst)
506 struct dcn10_opp *opp =
507 kzalloc(sizeof(struct dcn10_opp), GFP_KERNEL);
514 dcn10_opp_construct(opp, ctx, inst,
515 &opp_regs[inst], &opp_shift, &opp_mask);
519 static struct mpc *dcn10_mpc_create(struct dc_context *ctx)
521 struct dcn10_mpc *mpc10 = kzalloc(sizeof(struct dcn10_mpc),
527 dcn10_mpc_construct(mpc10, ctx,
536 static struct hubbub *dcn10_hubbub_create(struct dc_context *ctx)
538 struct hubbub *hubbub = kzalloc(sizeof(struct hubbub),
544 hubbub1_construct(hubbub, ctx,
552 static struct timing_generator *dcn10_timing_generator_create(
553 struct dc_context *ctx,
557 kzalloc(sizeof(struct optc), GFP_KERNEL);
562 tgn10->base.inst = instance;
563 tgn10->base.ctx = ctx;
565 tgn10->tg_regs = &tg_regs[instance];
566 tgn10->tg_shift = &tg_shift;
567 tgn10->tg_mask = &tg_mask;
569 dcn10_timing_generator_init(tgn10);
574 static const struct encoder_feature_support link_enc_feature = {
575 .max_hdmi_deep_color = COLOR_DEPTH_121212,
576 .max_hdmi_pixel_clock = 600000,
577 .ycbcr420_supported = true,
578 .flags.bits.IS_HBR2_CAPABLE = true,
579 .flags.bits.IS_HBR3_CAPABLE = true,
580 .flags.bits.IS_TPS3_CAPABLE = true,
581 .flags.bits.IS_TPS4_CAPABLE = true,
582 .flags.bits.IS_YCBCR_CAPABLE = true
585 struct link_encoder *dcn10_link_encoder_create(
586 const struct encoder_init_data *enc_init_data)
588 struct dce110_link_encoder *enc110 =
589 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
594 dce110_link_encoder_construct(enc110,
597 &link_enc_regs[enc_init_data->transmitter],
598 &link_enc_aux_regs[enc_init_data->channel - 1],
599 &link_enc_hpd_regs[enc_init_data->hpd_source]);
601 return &enc110->base;
604 struct clock_source *dcn10_clock_source_create(
605 struct dc_context *ctx,
606 struct dc_bios *bios,
607 enum clock_source_id id,
608 const struct dce110_clk_src_regs *regs,
611 struct dce110_clk_src *clk_src =
612 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
617 if (dce110_clk_src_construct(clk_src, ctx, bios, id,
618 regs, &cs_shift, &cs_mask)) {
619 clk_src->base.dp_clk_src = dp_clk_src;
620 return &clk_src->base;
627 static void read_dce_straps(
628 struct dc_context *ctx,
629 struct resource_straps *straps)
631 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
632 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
635 static struct audio *create_audio(
636 struct dc_context *ctx, unsigned int inst)
638 return dce_audio_create(ctx, inst,
639 &audio_regs[inst], &audio_shift, &audio_mask);
642 static struct stream_encoder *dcn10_stream_encoder_create(
643 enum engine_id eng_id,
644 struct dc_context *ctx)
646 struct dce110_stream_encoder *enc110 =
647 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
652 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
653 &stream_enc_regs[eng_id],
654 &se_shift, &se_mask);
655 return &enc110->base;
658 static const struct dce_hwseq_registers hwseq_reg = {
659 HWSEQ_DCN1_REG_LIST()
662 static const struct dce_hwseq_shift hwseq_shift = {
663 HWSEQ_DCN1_MASK_SH_LIST(__SHIFT)
666 static const struct dce_hwseq_mask hwseq_mask = {
667 HWSEQ_DCN1_MASK_SH_LIST(_MASK)
670 static struct dce_hwseq *dcn10_hwseq_create(
671 struct dc_context *ctx)
673 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
677 hws->regs = &hwseq_reg;
678 hws->shifts = &hwseq_shift;
679 hws->masks = &hwseq_mask;
680 hws->wa.DEGVIDCN10_253 = true;
681 hws->wa.false_optc_underflow = true;
686 static const struct resource_create_funcs res_create_funcs = {
687 .read_dce_straps = read_dce_straps,
688 .create_audio = create_audio,
689 .create_stream_encoder = dcn10_stream_encoder_create,
690 .create_hwseq = dcn10_hwseq_create,
693 static const struct resource_create_funcs res_create_maximus_funcs = {
694 .read_dce_straps = NULL,
695 .create_audio = NULL,
696 .create_stream_encoder = NULL,
697 .create_hwseq = dcn10_hwseq_create,
700 void dcn10_clock_source_destroy(struct clock_source **clk_src)
702 kfree(TO_DCE110_CLK_SRC(*clk_src));
706 static struct pp_smu_funcs_rv *dcn10_pp_smu_create(struct dc_context *ctx)
708 struct pp_smu_funcs_rv *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
713 dm_pp_get_funcs_rv(ctx, pp_smu);
717 static void destruct(struct dcn10_resource_pool *pool)
721 for (i = 0; i < pool->base.stream_enc_count; i++) {
722 if (pool->base.stream_enc[i] != NULL) {
723 /* TODO: free dcn version of stream encoder once implemented
724 * rather than using virtual stream encoder
726 kfree(pool->base.stream_enc[i]);
727 pool->base.stream_enc[i] = NULL;
731 if (pool->base.mpc != NULL) {
732 kfree(TO_DCN10_MPC(pool->base.mpc));
733 pool->base.mpc = NULL;
736 if (pool->base.hubbub != NULL) {
737 kfree(pool->base.hubbub);
738 pool->base.hubbub = NULL;
741 for (i = 0; i < pool->base.pipe_count; i++) {
742 if (pool->base.opps[i] != NULL)
743 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
745 if (pool->base.dpps[i] != NULL)
746 dcn10_dpp_destroy(&pool->base.dpps[i]);
748 if (pool->base.ipps[i] != NULL)
749 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
751 if (pool->base.hubps[i] != NULL) {
752 kfree(TO_DCN10_HUBP(pool->base.hubps[i]));
753 pool->base.hubps[i] = NULL;
756 if (pool->base.irqs != NULL) {
757 dal_irq_service_destroy(&pool->base.irqs);
760 if (pool->base.timing_generators[i] != NULL) {
761 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
762 pool->base.timing_generators[i] = NULL;
766 for (i = 0; i < pool->base.stream_enc_count; i++)
767 kfree(pool->base.stream_enc[i]);
769 for (i = 0; i < pool->base.audio_count; i++) {
770 if (pool->base.audios[i])
771 dce_aud_destroy(&pool->base.audios[i]);
774 for (i = 0; i < pool->base.clk_src_count; i++) {
775 if (pool->base.clock_sources[i] != NULL) {
776 dcn10_clock_source_destroy(&pool->base.clock_sources[i]);
777 pool->base.clock_sources[i] = NULL;
781 if (pool->base.dp_clock_source != NULL) {
782 dcn10_clock_source_destroy(&pool->base.dp_clock_source);
783 pool->base.dp_clock_source = NULL;
786 if (pool->base.abm != NULL)
787 dce_abm_destroy(&pool->base.abm);
789 if (pool->base.dmcu != NULL)
790 dce_dmcu_destroy(&pool->base.dmcu);
792 if (pool->base.display_clock != NULL)
793 dce_disp_clk_destroy(&pool->base.display_clock);
795 kfree(pool->base.pp_smu);
798 static struct hubp *dcn10_hubp_create(
799 struct dc_context *ctx,
802 struct dcn10_hubp *hubp1 =
803 kzalloc(sizeof(struct dcn10_hubp), GFP_KERNEL);
808 dcn10_hubp_construct(hubp1, ctx, inst,
809 &hubp_regs[inst], &hubp_shift, &hubp_mask);
813 static void get_pixel_clock_parameters(
814 const struct pipe_ctx *pipe_ctx,
815 struct pixel_clk_params *pixel_clk_params)
817 const struct dc_stream_state *stream = pipe_ctx->stream;
818 pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
819 pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
820 pixel_clk_params->signal_type = pipe_ctx->stream->signal;
821 pixel_clk_params->controller_id = pipe_ctx->pipe_idx + 1;
822 /* TODO: un-hardcode*/
823 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
824 LINK_RATE_REF_FREQ_IN_KHZ;
825 pixel_clk_params->flags.ENABLE_SS = 0;
826 pixel_clk_params->color_depth =
827 stream->timing.display_color_depth;
828 pixel_clk_params->flags.DISPLAY_BLANKED = 1;
829 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
831 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
832 pixel_clk_params->color_depth = COLOR_DEPTH_888;
834 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
835 pixel_clk_params->requested_pix_clk /= 2;
839 static void build_clamping_params(struct dc_stream_state *stream)
841 stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
842 stream->clamping.c_depth = stream->timing.display_color_depth;
843 stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
846 static void build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
849 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
851 pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
852 pipe_ctx->clock_source,
853 &pipe_ctx->stream_res.pix_clk_params,
854 &pipe_ctx->pll_settings);
856 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
858 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
859 &pipe_ctx->stream->bit_depth_params);
860 build_clamping_params(pipe_ctx->stream);
863 static enum dc_status build_mapped_resource(
865 struct dc_state *context,
866 struct dc_stream_state *stream)
868 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
870 /*TODO Seems unneeded anymore */
871 /* if (old_context && resource_is_stream_unchanged(old_context, stream)) {
872 if (stream != NULL && old_context->streams[i] != NULL) {
873 todo: shouldn't have to copy missing parameter here
874 resource_build_bit_depth_reduction_params(stream,
875 &stream->bit_depth_params);
876 stream->clamping.pixel_encoding =
877 stream->timing.pixel_encoding;
879 resource_build_bit_depth_reduction_params(stream,
880 &stream->bit_depth_params);
881 build_clamping_params(stream);
889 return DC_ERROR_UNEXPECTED;
891 build_pipe_hw_param(pipe_ctx);
895 enum dc_status dcn10_add_stream_to_ctx(
897 struct dc_state *new_ctx,
898 struct dc_stream_state *dc_stream)
900 enum dc_status result = DC_ERROR_UNEXPECTED;
902 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
905 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
909 result = build_mapped_resource(dc, new_ctx, dc_stream);
914 enum dc_status dcn10_validate_guaranteed(
916 struct dc_stream_state *dc_stream,
917 struct dc_state *context)
919 enum dc_status result = DC_ERROR_UNEXPECTED;
921 context->streams[0] = dc_stream;
922 dc_stream_retain(context->streams[0]);
923 context->stream_count++;
925 result = resource_map_pool_resources(dc, context, dc_stream);
928 result = resource_map_phy_clock_resources(dc, context, dc_stream);
931 result = build_mapped_resource(dc, context, dc_stream);
933 if (result == DC_OK) {
934 validate_guaranteed_copy_streams(
935 context, dc->caps.max_streams);
936 result = resource_build_scaling_params_for_context(dc, context);
938 if (result == DC_OK && !dcn_validate_bandwidth(dc, context))
939 return DC_FAIL_BANDWIDTH_VALIDATE;
944 static struct pipe_ctx *dcn10_acquire_idle_pipe_for_layer(
945 struct dc_state *context,
946 const struct resource_pool *pool,
947 struct dc_stream_state *stream)
949 struct resource_context *res_ctx = &context->res_ctx;
950 struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
951 struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool);
961 idle_pipe->stream = head_pipe->stream;
962 idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
963 idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
965 idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
966 idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
967 idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
973 dcc_control__256_256_xxx,
974 dcc_control__128_128_xxx,
975 dcc_control__256_64_64,
980 segment_order__contiguous,
981 segment_order__non_contiguous,
984 static bool dcc_support_pixel_format(
985 enum surface_pixel_format format,
986 unsigned int *bytes_per_element)
988 /* DML: get_bytes_per_element */
990 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
991 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
992 *bytes_per_element = 2;
994 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
995 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
996 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
997 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
998 *bytes_per_element = 4;
1000 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
1001 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
1002 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
1003 *bytes_per_element = 8;
1010 static bool dcc_support_swizzle(
1011 enum swizzle_mode_values swizzle,
1012 unsigned int bytes_per_element,
1013 enum segment_order *segment_order_horz,
1014 enum segment_order *segment_order_vert)
1016 bool standard_swizzle = false;
1017 bool display_swizzle = false;
1024 case DC_SW_64KB_S_X:
1026 standard_swizzle = true;
1032 case DC_SW_64KB_D_X:
1034 display_swizzle = true;
1040 if (bytes_per_element == 1 && standard_swizzle) {
1041 *segment_order_horz = segment_order__contiguous;
1042 *segment_order_vert = segment_order__na;
1045 if (bytes_per_element == 2 && standard_swizzle) {
1046 *segment_order_horz = segment_order__non_contiguous;
1047 *segment_order_vert = segment_order__contiguous;
1050 if (bytes_per_element == 4 && standard_swizzle) {
1051 *segment_order_horz = segment_order__non_contiguous;
1052 *segment_order_vert = segment_order__contiguous;
1055 if (bytes_per_element == 8 && standard_swizzle) {
1056 *segment_order_horz = segment_order__na;
1057 *segment_order_vert = segment_order__contiguous;
1060 if (bytes_per_element == 8 && display_swizzle) {
1061 *segment_order_horz = segment_order__contiguous;
1062 *segment_order_vert = segment_order__non_contiguous;
1069 static void get_blk256_size(unsigned int *blk256_width, unsigned int *blk256_height,
1070 unsigned int bytes_per_element)
1072 /* copied from DML. might want to refactor DML to leverage from DML */
1073 /* DML : get_blk256_size */
1074 if (bytes_per_element == 1) {
1076 *blk256_height = 16;
1077 } else if (bytes_per_element == 2) {
1080 } else if (bytes_per_element == 4) {
1083 } else if (bytes_per_element == 8) {
1089 static void det_request_size(
1090 unsigned int height,
1093 bool *req128_horz_wc,
1094 bool *req128_vert_wc)
1096 unsigned int detile_buf_size = 164 * 1024; /* 164KB for DCN1.0 */
1098 unsigned int blk256_height = 0;
1099 unsigned int blk256_width = 0;
1100 unsigned int swath_bytes_horz_wc, swath_bytes_vert_wc;
1102 get_blk256_size(&blk256_width, &blk256_height, bpe);
1104 swath_bytes_horz_wc = height * blk256_height * bpe;
1105 swath_bytes_vert_wc = width * blk256_width * bpe;
1107 *req128_horz_wc = (2 * swath_bytes_horz_wc <= detile_buf_size) ?
1108 false : /* full 256B request */
1109 true; /* half 128b request */
1111 *req128_vert_wc = (2 * swath_bytes_vert_wc <= detile_buf_size) ?
1112 false : /* full 256B request */
1113 true; /* half 128b request */
1116 static bool get_dcc_compression_cap(const struct dc *dc,
1117 const struct dc_dcc_surface_param *input,
1118 struct dc_surface_dcc_cap *output)
1120 /* implement section 1.6.2.1 of DCN1_Programming_Guide.docx */
1121 enum dcc_control dcc_control;
1123 enum segment_order segment_order_horz, segment_order_vert;
1124 bool req128_horz_wc, req128_vert_wc;
1126 memset(output, 0, sizeof(*output));
1128 if (dc->debug.disable_dcc == DCC_DISABLE)
1131 if (!dcc_support_pixel_format(input->format,
1135 if (!dcc_support_swizzle(input->swizzle_mode, bpe,
1136 &segment_order_horz, &segment_order_vert))
1139 det_request_size(input->surface_size.height, input->surface_size.width,
1140 bpe, &req128_horz_wc, &req128_vert_wc);
1142 if (!req128_horz_wc && !req128_vert_wc) {
1143 dcc_control = dcc_control__256_256_xxx;
1144 } else if (input->scan == SCAN_DIRECTION_HORIZONTAL) {
1145 if (!req128_horz_wc)
1146 dcc_control = dcc_control__256_256_xxx;
1147 else if (segment_order_horz == segment_order__contiguous)
1148 dcc_control = dcc_control__128_128_xxx;
1150 dcc_control = dcc_control__256_64_64;
1151 } else if (input->scan == SCAN_DIRECTION_VERTICAL) {
1152 if (!req128_vert_wc)
1153 dcc_control = dcc_control__256_256_xxx;
1154 else if (segment_order_vert == segment_order__contiguous)
1155 dcc_control = dcc_control__128_128_xxx;
1157 dcc_control = dcc_control__256_64_64;
1159 if ((req128_horz_wc &&
1160 segment_order_horz == segment_order__non_contiguous) ||
1162 segment_order_vert == segment_order__non_contiguous))
1163 /* access_dir not known, must use most constraining */
1164 dcc_control = dcc_control__256_64_64;
1166 /* reg128 is true for either horz and vert
1167 * but segment_order is contiguous
1169 dcc_control = dcc_control__128_128_xxx;
1172 if (dc->debug.disable_dcc == DCC_HALF_REQ_DISALBE &&
1173 dcc_control != dcc_control__256_256_xxx)
1176 switch (dcc_control) {
1177 case dcc_control__256_256_xxx:
1178 output->grph.rgb.max_uncompressed_blk_size = 256;
1179 output->grph.rgb.max_compressed_blk_size = 256;
1180 output->grph.rgb.independent_64b_blks = false;
1182 case dcc_control__128_128_xxx:
1183 output->grph.rgb.max_uncompressed_blk_size = 128;
1184 output->grph.rgb.max_compressed_blk_size = 128;
1185 output->grph.rgb.independent_64b_blks = false;
1187 case dcc_control__256_64_64:
1188 output->grph.rgb.max_uncompressed_blk_size = 256;
1189 output->grph.rgb.max_compressed_blk_size = 64;
1190 output->grph.rgb.independent_64b_blks = true;
1194 output->capable = true;
1195 output->const_color_support = false;
1201 static void dcn10_destroy_resource_pool(struct resource_pool **pool)
1203 struct dcn10_resource_pool *dcn10_pool = TO_DCN10_RES_POOL(*pool);
1205 destruct(dcn10_pool);
1210 static enum dc_status dcn10_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
1212 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1213 && caps->max_video_width != 0
1214 && plane_state->src_rect.width > caps->max_video_width)
1215 return DC_FAIL_SURFACE_VALIDATE;
1220 static struct dc_cap_funcs cap_funcs = {
1221 .get_dcc_compression_cap = get_dcc_compression_cap
1224 static struct resource_funcs dcn10_res_pool_funcs = {
1225 .destroy = dcn10_destroy_resource_pool,
1226 .link_enc_create = dcn10_link_encoder_create,
1227 .validate_guaranteed = dcn10_validate_guaranteed,
1228 .validate_bandwidth = dcn_validate_bandwidth,
1229 .acquire_idle_pipe_for_layer = dcn10_acquire_idle_pipe_for_layer,
1230 .validate_plane = dcn10_validate_plane,
1231 .add_stream_to_ctx = dcn10_add_stream_to_ctx
1234 static uint32_t read_pipe_fuses(struct dc_context *ctx)
1236 uint32_t value = dm_read_reg_soc15(ctx, mmCC_DC_PIPE_DIS, 0);
1237 /* RV1 support max 4 pipes */
1238 value = value & 0xf;
1242 static bool construct(
1243 uint8_t num_virtual_links,
1245 struct dcn10_resource_pool *pool)
1249 struct dc_context *ctx = dc->ctx;
1250 uint32_t pipe_fuses = read_pipe_fuses(ctx);
1252 ctx->dc_bios->regs = &bios_regs;
1254 pool->base.res_cap = &res_cap;
1255 pool->base.funcs = &dcn10_res_pool_funcs;
1258 * TODO fill in from actual raven resource when we create
1259 * more than virtual encoder
1262 /*************************************************
1263 * Resource + asic cap harcoding *
1264 *************************************************/
1265 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1267 /* max pipe num for ASIC before check pipe fuses */
1268 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1270 dc->caps.max_video_width = 3840;
1271 dc->caps.max_downscale_ratio = 200;
1272 dc->caps.i2c_speed_in_khz = 100;
1273 dc->caps.max_cursor_size = 256;
1274 dc->caps.max_slave_planes = 1;
1275 dc->caps.is_apu = true;
1277 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1278 dc->debug = debug_defaults_drv;
1280 dc->debug = debug_defaults_diags;
1282 /*************************************************
1283 * Create resources *
1284 *************************************************/
1286 pool->base.clock_sources[DCN10_CLK_SRC_PLL0] =
1287 dcn10_clock_source_create(ctx, ctx->dc_bios,
1288 CLOCK_SOURCE_COMBO_PHY_PLL0,
1289 &clk_src_regs[0], false);
1290 pool->base.clock_sources[DCN10_CLK_SRC_PLL1] =
1291 dcn10_clock_source_create(ctx, ctx->dc_bios,
1292 CLOCK_SOURCE_COMBO_PHY_PLL1,
1293 &clk_src_regs[1], false);
1294 pool->base.clock_sources[DCN10_CLK_SRC_PLL2] =
1295 dcn10_clock_source_create(ctx, ctx->dc_bios,
1296 CLOCK_SOURCE_COMBO_PHY_PLL2,
1297 &clk_src_regs[2], false);
1298 pool->base.clock_sources[DCN10_CLK_SRC_PLL3] =
1299 dcn10_clock_source_create(ctx, ctx->dc_bios,
1300 CLOCK_SOURCE_COMBO_PHY_PLL3,
1301 &clk_src_regs[3], false);
1303 pool->base.clk_src_count = DCN10_CLK_SRC_TOTAL;
1305 pool->base.dp_clock_source =
1306 dcn10_clock_source_create(ctx, ctx->dc_bios,
1307 CLOCK_SOURCE_ID_DP_DTO,
1308 /* todo: not reuse phy_pll registers */
1309 &clk_src_regs[0], true);
1311 for (i = 0; i < pool->base.clk_src_count; i++) {
1312 if (pool->base.clock_sources[i] == NULL) {
1313 dm_error("DC: failed to create clock sources!\n");
1314 BREAK_TO_DEBUGGER();
1319 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
1320 pool->base.display_clock = dce120_disp_clk_create(ctx);
1321 if (pool->base.display_clock == NULL) {
1322 dm_error("DC: failed to create display clock!\n");
1323 BREAK_TO_DEBUGGER();
1328 pool->base.dmcu = dcn10_dmcu_create(ctx,
1332 if (pool->base.dmcu == NULL) {
1333 dm_error("DC: failed to create dmcu!\n");
1334 BREAK_TO_DEBUGGER();
1338 pool->base.abm = dce_abm_create(ctx,
1342 if (pool->base.abm == NULL) {
1343 dm_error("DC: failed to create abm!\n");
1344 BREAK_TO_DEBUGGER();
1348 dml_init_instance(&dc->dml, DML_PROJECT_RAVEN1);
1349 memcpy(dc->dcn_ip, &dcn10_ip_defaults, sizeof(dcn10_ip_defaults));
1350 memcpy(dc->dcn_soc, &dcn10_soc_defaults, sizeof(dcn10_soc_defaults));
1352 if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
1353 dc->dcn_soc->urgent_latency = 3;
1354 dc->debug.disable_dmcu = true;
1355 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 41.60f;
1359 dc->dcn_soc->number_of_channels = dc->ctx->asic_id.vram_width / ddr4_dram_width;
1360 ASSERT(dc->dcn_soc->number_of_channels < 3);
1361 if (dc->dcn_soc->number_of_channels == 0)/*old sbios bug*/
1362 dc->dcn_soc->number_of_channels = 2;
1364 if (dc->dcn_soc->number_of_channels == 1) {
1365 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 19.2f;
1366 dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 = 17.066f;
1367 dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 = 14.933f;
1368 dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 = 12.8f;
1369 if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
1370 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 20.80f;
1374 pool->base.pp_smu = dcn10_pp_smu_create(ctx);
1376 if (!dc->debug.disable_pplib_clock_request)
1377 dcn_bw_update_from_pplib(dc);
1378 dcn_bw_sync_calcs_and_dml(dc);
1379 if (!dc->debug.disable_pplib_wm_range) {
1380 dc->res_pool = &pool->base;
1381 dcn_bw_notify_pplib_of_wm_ranges(dc);
1385 struct irq_service_init_data init_data;
1386 init_data.ctx = dc->ctx;
1387 pool->base.irqs = dal_irq_service_dcn10_create(&init_data);
1388 if (!pool->base.irqs)
1392 /* index to valid pipe resource */
1394 /* mem input -> ipp -> dpp -> opp -> TG */
1395 for (i = 0; i < pool->base.pipe_count; i++) {
1396 /* if pipe is disabled, skip instance of HW pipe,
1397 * i.e, skip ASIC register instance
1399 if ((pipe_fuses & (1 << i)) != 0)
1402 pool->base.hubps[j] = dcn10_hubp_create(ctx, i);
1403 if (pool->base.hubps[j] == NULL) {
1404 BREAK_TO_DEBUGGER();
1406 "DC: failed to create memory input!\n");
1410 pool->base.ipps[j] = dcn10_ipp_create(ctx, i);
1411 if (pool->base.ipps[j] == NULL) {
1412 BREAK_TO_DEBUGGER();
1414 "DC: failed to create input pixel processor!\n");
1418 pool->base.dpps[j] = dcn10_dpp_create(ctx, i);
1419 if (pool->base.dpps[j] == NULL) {
1420 BREAK_TO_DEBUGGER();
1422 "DC: failed to create dpp!\n");
1426 pool->base.opps[j] = dcn10_opp_create(ctx, i);
1427 if (pool->base.opps[j] == NULL) {
1428 BREAK_TO_DEBUGGER();
1430 "DC: failed to create output pixel processor!\n");
1434 pool->base.timing_generators[j] = dcn10_timing_generator_create(
1436 if (pool->base.timing_generators[j] == NULL) {
1437 BREAK_TO_DEBUGGER();
1438 dm_error("DC: failed to create tg!\n");
1442 /* check next valid pipe */
1446 /* valid pipe num */
1447 pool->base.pipe_count = j;
1449 /* within dml lib, it is hard code to 4. If ASIC pipe is fused,
1450 * the value may be changed
1452 dc->dml.ip.max_num_dpp = pool->base.pipe_count;
1453 dc->dcn_ip->max_num_dpp = pool->base.pipe_count;
1455 pool->base.mpc = dcn10_mpc_create(ctx);
1456 if (pool->base.mpc == NULL) {
1457 BREAK_TO_DEBUGGER();
1458 dm_error("DC: failed to create mpc!\n");
1462 pool->base.hubbub = dcn10_hubbub_create(ctx);
1463 if (pool->base.hubbub == NULL) {
1464 BREAK_TO_DEBUGGER();
1465 dm_error("DC: failed to create hubbub!\n");
1469 if (!resource_construct(num_virtual_links, dc, &pool->base,
1470 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
1471 &res_create_funcs : &res_create_maximus_funcs)))
1474 dcn10_hw_sequencer_construct(dc);
1475 dc->caps.max_planes = pool->base.pipe_count;
1477 dc->cap_funcs = cap_funcs;
1488 struct resource_pool *dcn10_create_resource_pool(
1489 uint8_t num_virtual_links,
1492 struct dcn10_resource_pool *pool =
1493 kzalloc(sizeof(struct dcn10_resource_pool), GFP_KERNEL);
1498 if (construct(num_virtual_links, dc, pool))
1501 BREAK_TO_DEBUGGER();