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"
53 #include "vega10/soc15ip.h"
55 #include "raven1/DCN/dcn_1_0_offset.h"
56 #include "raven1/DCN/dcn_1_0_sh_mask.h"
58 #include "raven1/NBIO/nbio_7_0_offset.h"
60 #include "raven1/MMHUB/mmhub_9_1_offset.h"
61 #include "raven1/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_tg_registers tg_regs[] = {
358 static const struct dcn_tg_shift tg_shift = {
359 TG_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
362 static const struct dcn_tg_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,
556 struct dcn10_timing_generator *tgn10 =
557 kzalloc(sizeof(struct dcn10_timing_generator), 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;
684 static const struct resource_create_funcs res_create_funcs = {
685 .read_dce_straps = read_dce_straps,
686 .create_audio = create_audio,
687 .create_stream_encoder = dcn10_stream_encoder_create,
688 .create_hwseq = dcn10_hwseq_create,
691 static const struct resource_create_funcs res_create_maximus_funcs = {
692 .read_dce_straps = NULL,
693 .create_audio = NULL,
694 .create_stream_encoder = NULL,
695 .create_hwseq = dcn10_hwseq_create,
698 void dcn10_clock_source_destroy(struct clock_source **clk_src)
700 kfree(TO_DCE110_CLK_SRC(*clk_src));
704 static struct pp_smu_funcs_rv *dcn10_pp_smu_create(struct dc_context *ctx)
706 struct pp_smu_funcs_rv *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
711 dm_pp_get_funcs_rv(ctx, pp_smu);
715 static void destruct(struct dcn10_resource_pool *pool)
719 for (i = 0; i < pool->base.stream_enc_count; i++) {
720 if (pool->base.stream_enc[i] != NULL) {
721 /* TODO: free dcn version of stream encoder once implemented
722 * rather than using virtual stream encoder
724 kfree(pool->base.stream_enc[i]);
725 pool->base.stream_enc[i] = NULL;
729 if (pool->base.mpc != NULL) {
730 kfree(TO_DCN10_MPC(pool->base.mpc));
731 pool->base.mpc = NULL;
734 if (pool->base.hubbub != NULL) {
735 kfree(pool->base.hubbub);
736 pool->base.hubbub = NULL;
739 for (i = 0; i < pool->base.pipe_count; i++) {
740 if (pool->base.opps[i] != NULL)
741 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
743 if (pool->base.dpps[i] != NULL)
744 dcn10_dpp_destroy(&pool->base.dpps[i]);
746 if (pool->base.ipps[i] != NULL)
747 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
749 if (pool->base.hubps[i] != NULL) {
750 kfree(TO_DCN10_HUBP(pool->base.hubps[i]));
751 pool->base.hubps[i] = NULL;
754 if (pool->base.irqs != NULL) {
755 dal_irq_service_destroy(&pool->base.irqs);
758 if (pool->base.timing_generators[i] != NULL) {
759 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
760 pool->base.timing_generators[i] = NULL;
764 for (i = 0; i < pool->base.stream_enc_count; i++)
765 kfree(pool->base.stream_enc[i]);
767 for (i = 0; i < pool->base.audio_count; i++) {
768 if (pool->base.audios[i])
769 dce_aud_destroy(&pool->base.audios[i]);
772 for (i = 0; i < pool->base.clk_src_count; i++) {
773 if (pool->base.clock_sources[i] != NULL) {
774 dcn10_clock_source_destroy(&pool->base.clock_sources[i]);
775 pool->base.clock_sources[i] = NULL;
779 if (pool->base.dp_clock_source != NULL) {
780 dcn10_clock_source_destroy(&pool->base.dp_clock_source);
781 pool->base.dp_clock_source = NULL;
784 if (pool->base.abm != NULL)
785 dce_abm_destroy(&pool->base.abm);
787 if (pool->base.dmcu != NULL)
788 dce_dmcu_destroy(&pool->base.dmcu);
790 if (pool->base.display_clock != NULL)
791 dce_disp_clk_destroy(&pool->base.display_clock);
793 kfree(pool->base.pp_smu);
796 static struct hubp *dcn10_hubp_create(
797 struct dc_context *ctx,
800 struct dcn10_hubp *hubp1 =
801 kzalloc(sizeof(struct dcn10_hubp), GFP_KERNEL);
806 dcn10_hubp_construct(hubp1, ctx, inst,
807 &hubp_regs[inst], &hubp_shift, &hubp_mask);
811 static void get_pixel_clock_parameters(
812 const struct pipe_ctx *pipe_ctx,
813 struct pixel_clk_params *pixel_clk_params)
815 const struct dc_stream_state *stream = pipe_ctx->stream;
816 pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
817 pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
818 pixel_clk_params->signal_type = pipe_ctx->stream->signal;
819 pixel_clk_params->controller_id = pipe_ctx->pipe_idx + 1;
820 /* TODO: un-hardcode*/
821 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
822 LINK_RATE_REF_FREQ_IN_KHZ;
823 pixel_clk_params->flags.ENABLE_SS = 0;
824 pixel_clk_params->color_depth =
825 stream->timing.display_color_depth;
826 pixel_clk_params->flags.DISPLAY_BLANKED = 1;
827 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
829 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
830 pixel_clk_params->color_depth = COLOR_DEPTH_888;
832 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
833 pixel_clk_params->requested_pix_clk /= 2;
837 static void build_clamping_params(struct dc_stream_state *stream)
839 stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
840 stream->clamping.c_depth = stream->timing.display_color_depth;
841 stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
844 static void build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
847 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
849 pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
850 pipe_ctx->clock_source,
851 &pipe_ctx->stream_res.pix_clk_params,
852 &pipe_ctx->pll_settings);
854 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
856 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
857 &pipe_ctx->stream->bit_depth_params);
858 build_clamping_params(pipe_ctx->stream);
861 static enum dc_status build_mapped_resource(
863 struct dc_state *context,
864 struct dc_stream_state *stream)
866 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
868 /*TODO Seems unneeded anymore */
869 /* if (old_context && resource_is_stream_unchanged(old_context, stream)) {
870 if (stream != NULL && old_context->streams[i] != NULL) {
871 todo: shouldn't have to copy missing parameter here
872 resource_build_bit_depth_reduction_params(stream,
873 &stream->bit_depth_params);
874 stream->clamping.pixel_encoding =
875 stream->timing.pixel_encoding;
877 resource_build_bit_depth_reduction_params(stream,
878 &stream->bit_depth_params);
879 build_clamping_params(stream);
887 return DC_ERROR_UNEXPECTED;
889 build_pipe_hw_param(pipe_ctx);
893 enum dc_status dcn10_add_stream_to_ctx(
895 struct dc_state *new_ctx,
896 struct dc_stream_state *dc_stream)
898 enum dc_status result = DC_ERROR_UNEXPECTED;
900 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
903 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
907 result = build_mapped_resource(dc, new_ctx, dc_stream);
912 enum dc_status dcn10_validate_guaranteed(
914 struct dc_stream_state *dc_stream,
915 struct dc_state *context)
917 enum dc_status result = DC_ERROR_UNEXPECTED;
919 context->streams[0] = dc_stream;
920 dc_stream_retain(context->streams[0]);
921 context->stream_count++;
923 result = resource_map_pool_resources(dc, context, dc_stream);
926 result = resource_map_phy_clock_resources(dc, context, dc_stream);
929 result = build_mapped_resource(dc, context, dc_stream);
931 if (result == DC_OK) {
932 validate_guaranteed_copy_streams(
933 context, dc->caps.max_streams);
934 result = resource_build_scaling_params_for_context(dc, context);
936 if (result == DC_OK && !dcn_validate_bandwidth(dc, context))
937 return DC_FAIL_BANDWIDTH_VALIDATE;
942 static struct pipe_ctx *dcn10_acquire_idle_pipe_for_layer(
943 struct dc_state *context,
944 const struct resource_pool *pool,
945 struct dc_stream_state *stream)
947 struct resource_context *res_ctx = &context->res_ctx;
948 struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
949 struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool);
959 idle_pipe->stream = head_pipe->stream;
960 idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
961 idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
963 idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
964 idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
965 idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
971 dcc_control__256_256_xxx,
972 dcc_control__128_128_xxx,
973 dcc_control__256_64_64,
978 segment_order__contiguous,
979 segment_order__non_contiguous,
982 static bool dcc_support_pixel_format(
983 enum surface_pixel_format format,
984 unsigned int *bytes_per_element)
986 /* DML: get_bytes_per_element */
988 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
989 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
990 *bytes_per_element = 2;
992 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
993 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
994 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
995 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
996 *bytes_per_element = 4;
998 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
999 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
1000 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
1001 *bytes_per_element = 8;
1008 static bool dcc_support_swizzle(
1009 enum swizzle_mode_values swizzle,
1010 unsigned int bytes_per_element,
1011 enum segment_order *segment_order_horz,
1012 enum segment_order *segment_order_vert)
1014 bool standard_swizzle = false;
1015 bool display_swizzle = false;
1022 case DC_SW_64KB_S_X:
1024 standard_swizzle = true;
1030 case DC_SW_64KB_D_X:
1032 display_swizzle = true;
1038 if (bytes_per_element == 1 && standard_swizzle) {
1039 *segment_order_horz = segment_order__contiguous;
1040 *segment_order_vert = segment_order__na;
1043 if (bytes_per_element == 2 && standard_swizzle) {
1044 *segment_order_horz = segment_order__non_contiguous;
1045 *segment_order_vert = segment_order__contiguous;
1048 if (bytes_per_element == 4 && standard_swizzle) {
1049 *segment_order_horz = segment_order__non_contiguous;
1050 *segment_order_vert = segment_order__contiguous;
1053 if (bytes_per_element == 8 && standard_swizzle) {
1054 *segment_order_horz = segment_order__na;
1055 *segment_order_vert = segment_order__contiguous;
1058 if (bytes_per_element == 8 && display_swizzle) {
1059 *segment_order_horz = segment_order__contiguous;
1060 *segment_order_vert = segment_order__non_contiguous;
1067 static void get_blk256_size(unsigned int *blk256_width, unsigned int *blk256_height,
1068 unsigned int bytes_per_element)
1070 /* copied from DML. might want to refactor DML to leverage from DML */
1071 /* DML : get_blk256_size */
1072 if (bytes_per_element == 1) {
1074 *blk256_height = 16;
1075 } else if (bytes_per_element == 2) {
1078 } else if (bytes_per_element == 4) {
1081 } else if (bytes_per_element == 8) {
1087 static void det_request_size(
1088 unsigned int height,
1091 bool *req128_horz_wc,
1092 bool *req128_vert_wc)
1094 unsigned int detile_buf_size = 164 * 1024; /* 164KB for DCN1.0 */
1096 unsigned int blk256_height = 0;
1097 unsigned int blk256_width = 0;
1098 unsigned int swath_bytes_horz_wc, swath_bytes_vert_wc;
1100 get_blk256_size(&blk256_width, &blk256_height, bpe);
1102 swath_bytes_horz_wc = height * blk256_height * bpe;
1103 swath_bytes_vert_wc = width * blk256_width * bpe;
1105 *req128_horz_wc = (2 * swath_bytes_horz_wc <= detile_buf_size) ?
1106 false : /* full 256B request */
1107 true; /* half 128b request */
1109 *req128_vert_wc = (2 * swath_bytes_vert_wc <= detile_buf_size) ?
1110 false : /* full 256B request */
1111 true; /* half 128b request */
1114 static bool get_dcc_compression_cap(const struct dc *dc,
1115 const struct dc_dcc_surface_param *input,
1116 struct dc_surface_dcc_cap *output)
1118 /* implement section 1.6.2.1 of DCN1_Programming_Guide.docx */
1119 enum dcc_control dcc_control;
1121 enum segment_order segment_order_horz, segment_order_vert;
1122 bool req128_horz_wc, req128_vert_wc;
1124 memset(output, 0, sizeof(*output));
1126 if (dc->debug.disable_dcc == DCC_DISABLE)
1129 if (!dcc_support_pixel_format(input->format,
1133 if (!dcc_support_swizzle(input->swizzle_mode, bpe,
1134 &segment_order_horz, &segment_order_vert))
1137 det_request_size(input->surface_size.height, input->surface_size.width,
1138 bpe, &req128_horz_wc, &req128_vert_wc);
1140 if (!req128_horz_wc && !req128_vert_wc) {
1141 dcc_control = dcc_control__256_256_xxx;
1142 } else if (input->scan == SCAN_DIRECTION_HORIZONTAL) {
1143 if (!req128_horz_wc)
1144 dcc_control = dcc_control__256_256_xxx;
1145 else if (segment_order_horz == segment_order__contiguous)
1146 dcc_control = dcc_control__128_128_xxx;
1148 dcc_control = dcc_control__256_64_64;
1149 } else if (input->scan == SCAN_DIRECTION_VERTICAL) {
1150 if (!req128_vert_wc)
1151 dcc_control = dcc_control__256_256_xxx;
1152 else if (segment_order_vert == segment_order__contiguous)
1153 dcc_control = dcc_control__128_128_xxx;
1155 dcc_control = dcc_control__256_64_64;
1157 if ((req128_horz_wc &&
1158 segment_order_horz == segment_order__non_contiguous) ||
1160 segment_order_vert == segment_order__non_contiguous))
1161 /* access_dir not known, must use most constraining */
1162 dcc_control = dcc_control__256_64_64;
1164 /* reg128 is true for either horz and vert
1165 * but segment_order is contiguous
1167 dcc_control = dcc_control__128_128_xxx;
1170 if (dc->debug.disable_dcc == DCC_HALF_REQ_DISALBE &&
1171 dcc_control != dcc_control__256_256_xxx)
1174 switch (dcc_control) {
1175 case dcc_control__256_256_xxx:
1176 output->grph.rgb.max_uncompressed_blk_size = 256;
1177 output->grph.rgb.max_compressed_blk_size = 256;
1178 output->grph.rgb.independent_64b_blks = false;
1180 case dcc_control__128_128_xxx:
1181 output->grph.rgb.max_uncompressed_blk_size = 128;
1182 output->grph.rgb.max_compressed_blk_size = 128;
1183 output->grph.rgb.independent_64b_blks = false;
1185 case dcc_control__256_64_64:
1186 output->grph.rgb.max_uncompressed_blk_size = 256;
1187 output->grph.rgb.max_compressed_blk_size = 64;
1188 output->grph.rgb.independent_64b_blks = true;
1192 output->capable = true;
1193 output->const_color_support = false;
1199 static void dcn10_destroy_resource_pool(struct resource_pool **pool)
1201 struct dcn10_resource_pool *dcn10_pool = TO_DCN10_RES_POOL(*pool);
1203 destruct(dcn10_pool);
1208 static enum dc_status dcn10_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
1210 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1211 && caps->max_video_width != 0
1212 && plane_state->src_rect.width > caps->max_video_width)
1213 return DC_FAIL_SURFACE_VALIDATE;
1218 static struct dc_cap_funcs cap_funcs = {
1219 .get_dcc_compression_cap = get_dcc_compression_cap
1222 static struct resource_funcs dcn10_res_pool_funcs = {
1223 .destroy = dcn10_destroy_resource_pool,
1224 .link_enc_create = dcn10_link_encoder_create,
1225 .validate_guaranteed = dcn10_validate_guaranteed,
1226 .validate_bandwidth = dcn_validate_bandwidth,
1227 .acquire_idle_pipe_for_layer = dcn10_acquire_idle_pipe_for_layer,
1228 .validate_plane = dcn10_validate_plane,
1229 .add_stream_to_ctx = dcn10_add_stream_to_ctx
1232 static uint32_t read_pipe_fuses(struct dc_context *ctx)
1234 uint32_t value = dm_read_reg_soc15(ctx, mmCC_DC_PIPE_DIS, 0);
1235 /* RV1 support max 4 pipes */
1236 value = value & 0xf;
1240 static bool construct(
1241 uint8_t num_virtual_links,
1243 struct dcn10_resource_pool *pool)
1247 struct dc_context *ctx = dc->ctx;
1248 uint32_t pipe_fuses = read_pipe_fuses(ctx);
1250 ctx->dc_bios->regs = &bios_regs;
1252 pool->base.res_cap = &res_cap;
1253 pool->base.funcs = &dcn10_res_pool_funcs;
1256 * TODO fill in from actual raven resource when we create
1257 * more than virtual encoder
1260 /*************************************************
1261 * Resource + asic cap harcoding *
1262 *************************************************/
1263 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1265 /* max pipe num for ASIC before check pipe fuses */
1266 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1268 dc->caps.max_video_width = 3840;
1269 dc->caps.max_downscale_ratio = 200;
1270 dc->caps.i2c_speed_in_khz = 100;
1271 dc->caps.max_cursor_size = 256;
1273 dc->caps.max_slave_planes = 1;
1274 dc->caps.is_apu = true;
1276 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1277 dc->debug = debug_defaults_drv;
1279 dc->debug = debug_defaults_diags;
1281 /*************************************************
1282 * Create resources *
1283 *************************************************/
1285 pool->base.clock_sources[DCN10_CLK_SRC_PLL0] =
1286 dcn10_clock_source_create(ctx, ctx->dc_bios,
1287 CLOCK_SOURCE_COMBO_PHY_PLL0,
1288 &clk_src_regs[0], false);
1289 pool->base.clock_sources[DCN10_CLK_SRC_PLL1] =
1290 dcn10_clock_source_create(ctx, ctx->dc_bios,
1291 CLOCK_SOURCE_COMBO_PHY_PLL1,
1292 &clk_src_regs[1], false);
1293 pool->base.clock_sources[DCN10_CLK_SRC_PLL2] =
1294 dcn10_clock_source_create(ctx, ctx->dc_bios,
1295 CLOCK_SOURCE_COMBO_PHY_PLL2,
1296 &clk_src_regs[2], false);
1297 pool->base.clock_sources[DCN10_CLK_SRC_PLL3] =
1298 dcn10_clock_source_create(ctx, ctx->dc_bios,
1299 CLOCK_SOURCE_COMBO_PHY_PLL3,
1300 &clk_src_regs[3], false);
1302 pool->base.clk_src_count = DCN10_CLK_SRC_TOTAL;
1304 pool->base.dp_clock_source =
1305 dcn10_clock_source_create(ctx, ctx->dc_bios,
1306 CLOCK_SOURCE_ID_DP_DTO,
1307 /* todo: not reuse phy_pll registers */
1308 &clk_src_regs[0], true);
1310 for (i = 0; i < pool->base.clk_src_count; i++) {
1311 if (pool->base.clock_sources[i] == NULL) {
1312 dm_error("DC: failed to create clock sources!\n");
1313 BREAK_TO_DEBUGGER();
1318 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
1319 pool->base.display_clock = dce120_disp_clk_create(ctx);
1320 if (pool->base.display_clock == NULL) {
1321 dm_error("DC: failed to create display clock!\n");
1322 BREAK_TO_DEBUGGER();
1327 pool->base.dmcu = dcn10_dmcu_create(ctx,
1331 if (pool->base.dmcu == NULL) {
1332 dm_error("DC: failed to create dmcu!\n");
1333 BREAK_TO_DEBUGGER();
1337 pool->base.abm = dce_abm_create(ctx,
1341 if (pool->base.abm == NULL) {
1342 dm_error("DC: failed to create abm!\n");
1343 BREAK_TO_DEBUGGER();
1347 dml_init_instance(&dc->dml, DML_PROJECT_RAVEN1);
1348 memcpy(dc->dcn_ip, &dcn10_ip_defaults, sizeof(dcn10_ip_defaults));
1349 memcpy(dc->dcn_soc, &dcn10_soc_defaults, sizeof(dcn10_soc_defaults));
1351 if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
1352 dc->dcn_soc->urgent_latency = 3;
1353 dc->debug.disable_dmcu = true;
1354 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 41.60f;
1358 dc->dcn_soc->number_of_channels = dc->ctx->asic_id.vram_width / ddr4_dram_width;
1359 ASSERT(dc->dcn_soc->number_of_channels < 3);
1360 if (dc->dcn_soc->number_of_channels == 0)/*old sbios bug*/
1361 dc->dcn_soc->number_of_channels = 2;
1363 if (dc->dcn_soc->number_of_channels == 1) {
1364 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 19.2f;
1365 dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 = 17.066f;
1366 dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 = 14.933f;
1367 dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 = 12.8f;
1368 if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
1369 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 20.80f;
1373 pool->base.pp_smu = dcn10_pp_smu_create(ctx);
1375 if (!dc->debug.disable_pplib_clock_request)
1376 dcn_bw_update_from_pplib(dc);
1377 dcn_bw_sync_calcs_and_dml(dc);
1378 if (!dc->debug.disable_pplib_wm_range) {
1379 dc->res_pool = &pool->base;
1380 dcn_bw_notify_pplib_of_wm_ranges(dc);
1384 struct irq_service_init_data init_data;
1385 init_data.ctx = dc->ctx;
1386 pool->base.irqs = dal_irq_service_dcn10_create(&init_data);
1387 if (!pool->base.irqs)
1391 /* index to valid pipe resource */
1393 /* mem input -> ipp -> dpp -> opp -> TG */
1394 for (i = 0; i < pool->base.pipe_count; i++) {
1395 /* if pipe is disabled, skip instance of HW pipe,
1396 * i.e, skip ASIC register instance
1398 if ((pipe_fuses & (1 << i)) != 0)
1401 pool->base.hubps[j] = dcn10_hubp_create(ctx, i);
1402 if (pool->base.hubps[j] == NULL) {
1403 BREAK_TO_DEBUGGER();
1405 "DC: failed to create memory input!\n");
1409 pool->base.ipps[j] = dcn10_ipp_create(ctx, i);
1410 if (pool->base.ipps[j] == NULL) {
1411 BREAK_TO_DEBUGGER();
1413 "DC: failed to create input pixel processor!\n");
1417 pool->base.dpps[j] = dcn10_dpp_create(ctx, i);
1418 if (pool->base.dpps[j] == NULL) {
1419 BREAK_TO_DEBUGGER();
1421 "DC: failed to create dpp!\n");
1425 pool->base.opps[j] = dcn10_opp_create(ctx, i);
1426 if (pool->base.opps[j] == NULL) {
1427 BREAK_TO_DEBUGGER();
1429 "DC: failed to create output pixel processor!\n");
1433 pool->base.timing_generators[j] = dcn10_timing_generator_create(
1435 if (pool->base.timing_generators[j] == NULL) {
1436 BREAK_TO_DEBUGGER();
1437 dm_error("DC: failed to create tg!\n");
1441 /* check next valid pipe */
1445 /* valid pipe num */
1446 pool->base.pipe_count = j;
1448 /* within dml lib, it is hard code to 4. If ASIC pipe is fused,
1449 * the value may be changed
1451 dc->dml.ip.max_num_dpp = pool->base.pipe_count;
1452 dc->dcn_ip->max_num_dpp = pool->base.pipe_count;
1454 pool->base.mpc = dcn10_mpc_create(ctx);
1455 if (pool->base.mpc == NULL) {
1456 BREAK_TO_DEBUGGER();
1457 dm_error("DC: failed to create mpc!\n");
1461 pool->base.hubbub = dcn10_hubbub_create(ctx);
1462 if (pool->base.hubbub == NULL) {
1463 BREAK_TO_DEBUGGER();
1464 dm_error("DC: failed to create mpc!\n");
1468 if (!resource_construct(num_virtual_links, dc, &pool->base,
1469 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
1470 &res_create_funcs : &res_create_maximus_funcs)))
1473 dcn10_hw_sequencer_construct(dc);
1474 dc->caps.max_planes = pool->base.pipe_count;
1476 dc->cap_funcs = cap_funcs;
1487 struct resource_pool *dcn10_create_resource_pool(
1488 uint8_t num_virtual_links,
1491 struct dcn10_resource_pool *pool =
1492 kzalloc(sizeof(struct dcn10_resource_pool), GFP_KERNEL);
1497 if (construct(num_virtual_links, dc, pool))
1500 BREAK_TO_DEBUGGER();