2 * Copyright 2012-15 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 "../dce/dce_dccg.h"
27 #include "dm_services.h"
29 #include "link_encoder.h"
30 #include "stream_encoder.h"
33 #include "include/irq_service_interface.h"
34 #include "dce110/dce110_resource.h"
35 #include "dce110/dce110_timing_generator.h"
37 #include "irq/dce110/irq_service_dce110.h"
39 #include "dce/dce_mem_input.h"
40 #include "dce/dce_transform.h"
41 #include "dce/dce_link_encoder.h"
42 #include "dce/dce_stream_encoder.h"
43 #include "dce/dce_audio.h"
44 #include "dce/dce_opp.h"
45 #include "dce/dce_ipp.h"
46 #include "dce/dce_clock_source.h"
48 #include "dce/dce_hwseq.h"
49 #include "dce112/dce112_hw_sequencer.h"
50 #include "dce/dce_abm.h"
51 #include "dce/dce_dmcu.h"
52 #include "dce/dce_aux.h"
53 #include "dce/dce_i2c.h"
55 #include "reg_helper.h"
57 #include "dce/dce_11_2_d.h"
58 #include "dce/dce_11_2_sh_mask.h"
60 #include "dce100/dce100_resource.h"
64 #ifndef mmDP_DPHY_INTERNAL_CTRL
65 #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
66 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
67 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
68 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
69 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
70 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
71 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
72 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
73 #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
74 #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
77 #ifndef mmBIOS_SCRATCH_2
78 #define mmBIOS_SCRATCH_2 0x05CB
79 #define mmBIOS_SCRATCH_6 0x05CF
82 #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
83 #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
84 #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
85 #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
86 #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
87 #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
88 #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
89 #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
90 #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
93 #ifndef mmDP_DPHY_FAST_TRAINING
94 #define mmDP_DPHY_FAST_TRAINING 0x4ABC
95 #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
96 #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
97 #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
98 #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
99 #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
100 #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
101 #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
104 enum dce112_clk_src_array_id {
115 static const struct dce110_timing_generator_offsets dce112_tg_offsets[] = {
117 .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
118 .dcp = (mmDCP0_GRPH_CONTROL - mmGRPH_CONTROL),
121 .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
122 .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
125 .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
126 .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
129 .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
130 .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
133 .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
134 .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
137 .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
138 .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
142 /* set register offset */
143 #define SR(reg_name)\
144 .reg_name = mm ## reg_name
146 /* set register offset with instance */
147 #define SRI(reg_name, block, id)\
148 .reg_name = mm ## block ## id ## _ ## reg_name
151 static const struct dccg_registers disp_clk_regs = {
152 CLK_COMMON_REG_LIST_DCE_BASE()
155 static const struct dccg_shift disp_clk_shift = {
156 CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
159 static const struct dccg_mask disp_clk_mask = {
160 CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
163 static const struct dce_dmcu_registers dmcu_regs = {
164 DMCU_DCE110_COMMON_REG_LIST()
167 static const struct dce_dmcu_shift dmcu_shift = {
168 DMCU_MASK_SH_LIST_DCE110(__SHIFT)
171 static const struct dce_dmcu_mask dmcu_mask = {
172 DMCU_MASK_SH_LIST_DCE110(_MASK)
175 static const struct dce_abm_registers abm_regs = {
176 ABM_DCE110_COMMON_REG_LIST()
179 static const struct dce_abm_shift abm_shift = {
180 ABM_MASK_SH_LIST_DCE110(__SHIFT)
183 static const struct dce_abm_mask abm_mask = {
184 ABM_MASK_SH_LIST_DCE110(_MASK)
187 #define ipp_regs(id)\
189 IPP_DCE110_REG_LIST_DCE_BASE(id)\
192 static const struct dce_ipp_registers ipp_regs[] = {
201 static const struct dce_ipp_shift ipp_shift = {
202 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
205 static const struct dce_ipp_mask ipp_mask = {
206 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
209 #define transform_regs(id)\
211 XFM_COMMON_REG_LIST_DCE110(id)\
214 static const struct dce_transform_registers xfm_regs[] = {
223 static const struct dce_transform_shift xfm_shift = {
224 XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
227 static const struct dce_transform_mask xfm_mask = {
228 XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
231 #define aux_regs(id)\
236 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
245 #define hpd_regs(id)\
250 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
259 #define link_regs(id)\
261 LE_DCE110_REG_LIST(id)\
264 static const struct dce110_link_enc_registers link_enc_regs[] = {
274 #define stream_enc_regs(id)\
276 SE_COMMON_REG_LIST(id),\
280 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
289 static const struct dce_stream_encoder_shift se_shift = {
290 SE_COMMON_MASK_SH_LIST_DCE112(__SHIFT)
293 static const struct dce_stream_encoder_mask se_mask = {
294 SE_COMMON_MASK_SH_LIST_DCE112(_MASK)
297 #define opp_regs(id)\
299 OPP_DCE_112_REG_LIST(id),\
302 static const struct dce_opp_registers opp_regs[] = {
311 static const struct dce_opp_shift opp_shift = {
312 OPP_COMMON_MASK_SH_LIST_DCE_112(__SHIFT)
315 static const struct dce_opp_mask opp_mask = {
316 OPP_COMMON_MASK_SH_LIST_DCE_112(_MASK)
319 #define aux_engine_regs(id)\
321 AUX_COMMON_REG_LIST(id), \
322 .AUX_RESET_MASK = 0 \
325 static const struct dce110_aux_registers aux_engine_regs[] = {
334 #define audio_regs(id)\
336 AUD_COMMON_REG_LIST(id)\
339 static const struct dce_audio_registers audio_regs[] = {
348 static const struct dce_audio_shift audio_shift = {
349 AUD_COMMON_MASK_SH_LIST(__SHIFT)
352 static const struct dce_aduio_mask audio_mask = {
353 AUD_COMMON_MASK_SH_LIST(_MASK)
356 #define clk_src_regs(index, id)\
358 CS_COMMON_REG_LIST_DCE_112(id),\
361 static const struct dce110_clk_src_regs clk_src_regs[] = {
370 static const struct dce110_clk_src_shift cs_shift = {
371 CS_COMMON_MASK_SH_LIST_DCE_112(__SHIFT)
374 static const struct dce110_clk_src_mask cs_mask = {
375 CS_COMMON_MASK_SH_LIST_DCE_112(_MASK)
378 static const struct bios_registers bios_regs = {
379 .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
382 static const struct resource_caps polaris_10_resource_cap = {
383 .num_timing_generator = 6,
385 .num_stream_encoder = 6,
386 .num_pll = 8, /* why 8? 6 combo PHY PLL + 2 regular PLLs? */
390 static const struct resource_caps polaris_11_resource_cap = {
391 .num_timing_generator = 5,
393 .num_stream_encoder = 5,
394 .num_pll = 8, /* why 8? 6 combo PHY PLL + 2 regular PLLs? */
399 #define REG(reg) mm ## reg
401 #ifndef mmCC_DC_HDMI_STRAPS
402 #define mmCC_DC_HDMI_STRAPS 0x4819
403 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
404 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
405 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
406 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
409 static void read_dce_straps(
410 struct dc_context *ctx,
411 struct resource_straps *straps)
413 REG_GET_2(CC_DC_HDMI_STRAPS,
414 HDMI_DISABLE, &straps->hdmi_disable,
415 AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
417 REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
420 static struct audio *create_audio(
421 struct dc_context *ctx, unsigned int inst)
423 return dce_audio_create(ctx, inst,
424 &audio_regs[inst], &audio_shift, &audio_mask);
428 static struct timing_generator *dce112_timing_generator_create(
429 struct dc_context *ctx,
431 const struct dce110_timing_generator_offsets *offsets)
433 struct dce110_timing_generator *tg110 =
434 kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
439 dce110_timing_generator_construct(tg110, ctx, instance, offsets);
443 static struct stream_encoder *dce112_stream_encoder_create(
444 enum engine_id eng_id,
445 struct dc_context *ctx)
447 struct dce110_stream_encoder *enc110 =
448 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
453 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
454 &stream_enc_regs[eng_id],
455 &se_shift, &se_mask);
456 return &enc110->base;
459 #define SRII(reg_name, block, id)\
460 .reg_name[id] = mm ## block ## id ## _ ## reg_name
462 static const struct dce_hwseq_registers hwseq_reg = {
463 HWSEQ_DCE112_REG_LIST()
466 static const struct dce_hwseq_shift hwseq_shift = {
467 HWSEQ_DCE112_MASK_SH_LIST(__SHIFT)
470 static const struct dce_hwseq_mask hwseq_mask = {
471 HWSEQ_DCE112_MASK_SH_LIST(_MASK)
474 static struct dce_hwseq *dce112_hwseq_create(
475 struct dc_context *ctx)
477 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
481 hws->regs = &hwseq_reg;
482 hws->shifts = &hwseq_shift;
483 hws->masks = &hwseq_mask;
488 static const struct resource_create_funcs res_create_funcs = {
489 .read_dce_straps = read_dce_straps,
490 .create_audio = create_audio,
491 .create_stream_encoder = dce112_stream_encoder_create,
492 .create_hwseq = dce112_hwseq_create,
495 #define mi_inst_regs(id) { MI_DCE11_2_REG_LIST(id) }
496 static const struct dce_mem_input_registers mi_regs[] = {
505 static const struct dce_mem_input_shift mi_shifts = {
506 MI_DCE11_2_MASK_SH_LIST(__SHIFT)
509 static const struct dce_mem_input_mask mi_masks = {
510 MI_DCE11_2_MASK_SH_LIST(_MASK)
513 static struct mem_input *dce112_mem_input_create(
514 struct dc_context *ctx,
517 struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
525 dce112_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
526 return &dce_mi->base;
529 static void dce112_transform_destroy(struct transform **xfm)
531 kfree(TO_DCE_TRANSFORM(*xfm));
535 static struct transform *dce112_transform_create(
536 struct dc_context *ctx,
539 struct dce_transform *transform =
540 kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
545 dce_transform_construct(transform, ctx, inst,
546 &xfm_regs[inst], &xfm_shift, &xfm_mask);
547 transform->lb_memory_size = 0x1404; /*5124*/
548 return &transform->base;
551 static const struct encoder_feature_support link_enc_feature = {
552 .max_hdmi_deep_color = COLOR_DEPTH_121212,
553 .max_hdmi_pixel_clock = 600000,
554 .hdmi_ycbcr420_supported = true,
555 .dp_ycbcr420_supported = false,
556 .flags.bits.IS_HBR2_CAPABLE = true,
557 .flags.bits.IS_HBR3_CAPABLE = true,
558 .flags.bits.IS_TPS3_CAPABLE = true,
559 .flags.bits.IS_TPS4_CAPABLE = true
562 struct link_encoder *dce112_link_encoder_create(
563 const struct encoder_init_data *enc_init_data)
565 struct dce110_link_encoder *enc110 =
566 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
571 dce110_link_encoder_construct(enc110,
574 &link_enc_regs[enc_init_data->transmitter],
575 &link_enc_aux_regs[enc_init_data->channel - 1],
576 &link_enc_hpd_regs[enc_init_data->hpd_source]);
577 return &enc110->base;
580 static struct input_pixel_processor *dce112_ipp_create(
581 struct dc_context *ctx, uint32_t inst)
583 struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
590 dce_ipp_construct(ipp, ctx, inst,
591 &ipp_regs[inst], &ipp_shift, &ipp_mask);
595 struct output_pixel_processor *dce112_opp_create(
596 struct dc_context *ctx,
599 struct dce110_opp *opp =
600 kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
605 dce110_opp_construct(opp,
606 ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
610 struct aux_engine *dce112_aux_engine_create(
611 struct dc_context *ctx,
614 struct aux_engine_dce110 *aux_engine =
615 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
620 dce110_aux_engine_construct(aux_engine, ctx, inst,
621 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
622 &aux_engine_regs[inst]);
624 return &aux_engine->base;
626 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
628 static const struct dce_i2c_registers i2c_hw_regs[] = {
637 static const struct dce_i2c_shift i2c_shifts = {
638 I2C_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
641 static const struct dce_i2c_mask i2c_masks = {
642 I2C_COMMON_MASK_SH_LIST_DCE110(_MASK)
645 struct dce_i2c_hw *dce112_i2c_hw_create(
646 struct dc_context *ctx,
649 struct dce_i2c_hw *dce_i2c_hw =
650 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
655 dce112_i2c_hw_construct(dce_i2c_hw, ctx, inst,
656 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
660 struct clock_source *dce112_clock_source_create(
661 struct dc_context *ctx,
662 struct dc_bios *bios,
663 enum clock_source_id id,
664 const struct dce110_clk_src_regs *regs,
667 struct dce110_clk_src *clk_src =
668 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
673 if (dce112_clk_src_construct(clk_src, ctx, bios, id,
674 regs, &cs_shift, &cs_mask)) {
675 clk_src->base.dp_clk_src = dp_clk_src;
676 return &clk_src->base;
683 void dce112_clock_source_destroy(struct clock_source **clk_src)
685 kfree(TO_DCE110_CLK_SRC(*clk_src));
689 static void destruct(struct dce110_resource_pool *pool)
693 for (i = 0; i < pool->base.pipe_count; i++) {
694 if (pool->base.opps[i] != NULL)
695 dce110_opp_destroy(&pool->base.opps[i]);
697 if (pool->base.transforms[i] != NULL)
698 dce112_transform_destroy(&pool->base.transforms[i]);
700 if (pool->base.ipps[i] != NULL)
701 dce_ipp_destroy(&pool->base.ipps[i]);
703 if (pool->base.mis[i] != NULL) {
704 kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
705 pool->base.mis[i] = NULL;
708 if (pool->base.timing_generators[i] != NULL) {
709 kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
710 pool->base.timing_generators[i] = NULL;
714 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
715 if (pool->base.engines[i] != NULL)
716 dce110_engine_destroy(&pool->base.engines[i]);
717 if (pool->base.hw_i2cs[i] != NULL) {
718 kfree(pool->base.hw_i2cs[i]);
719 pool->base.hw_i2cs[i] = NULL;
721 if (pool->base.sw_i2cs[i] != NULL) {
722 kfree(pool->base.sw_i2cs[i]);
723 pool->base.sw_i2cs[i] = NULL;
727 for (i = 0; i < pool->base.stream_enc_count; i++) {
728 if (pool->base.stream_enc[i] != NULL)
729 kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
732 for (i = 0; i < pool->base.clk_src_count; i++) {
733 if (pool->base.clock_sources[i] != NULL) {
734 dce112_clock_source_destroy(&pool->base.clock_sources[i]);
738 if (pool->base.dp_clock_source != NULL)
739 dce112_clock_source_destroy(&pool->base.dp_clock_source);
741 for (i = 0; i < pool->base.audio_count; i++) {
742 if (pool->base.audios[i] != NULL) {
743 dce_aud_destroy(&pool->base.audios[i]);
747 if (pool->base.abm != NULL)
748 dce_abm_destroy(&pool->base.abm);
750 if (pool->base.dmcu != NULL)
751 dce_dmcu_destroy(&pool->base.dmcu);
753 if (pool->base.dccg != NULL)
754 dce_dccg_destroy(&pool->base.dccg);
756 if (pool->base.irqs != NULL) {
757 dal_irq_service_destroy(&pool->base.irqs);
761 static struct clock_source *find_matching_pll(
762 struct resource_context *res_ctx,
763 const struct resource_pool *pool,
764 const struct dc_stream_state *const stream)
766 switch (stream->sink->link->link_enc->transmitter) {
767 case TRANSMITTER_UNIPHY_A:
768 return pool->clock_sources[DCE112_CLK_SRC_PLL0];
769 case TRANSMITTER_UNIPHY_B:
770 return pool->clock_sources[DCE112_CLK_SRC_PLL1];
771 case TRANSMITTER_UNIPHY_C:
772 return pool->clock_sources[DCE112_CLK_SRC_PLL2];
773 case TRANSMITTER_UNIPHY_D:
774 return pool->clock_sources[DCE112_CLK_SRC_PLL3];
775 case TRANSMITTER_UNIPHY_E:
776 return pool->clock_sources[DCE112_CLK_SRC_PLL4];
777 case TRANSMITTER_UNIPHY_F:
778 return pool->clock_sources[DCE112_CLK_SRC_PLL5];
786 static enum dc_status build_mapped_resource(
788 struct dc_state *context,
789 struct dc_stream_state *stream)
791 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
794 return DC_ERROR_UNEXPECTED;
796 dce110_resource_build_pipe_hw_param(pipe_ctx);
798 resource_build_info_frame(pipe_ctx);
803 bool dce112_validate_bandwidth(
805 struct dc_state *context)
809 DC_LOG_BANDWIDTH_CALCS(
817 context->res_ctx.pipe_ctx,
818 dc->res_pool->pipe_count,
823 DC_LOG_BANDWIDTH_VALIDATION(
824 "%s: Bandwidth validation failed!",
827 if (memcmp(&dc->current_state->bw.dce,
828 &context->bw.dce, sizeof(context->bw.dce))) {
830 DC_LOG_BANDWIDTH_CALCS(
832 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
833 "stutMark_b: %d stutMark_a: %d\n"
834 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
835 "stutMark_b: %d stutMark_a: %d\n"
836 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
837 "stutMark_b: %d stutMark_a: %d stutter_mode_enable: %d\n"
838 "cstate: %d pstate: %d nbpstate: %d sync: %d dispclk: %d\n"
839 "sclk: %d sclk_sleep: %d yclk: %d blackout_recovery_time_us: %d\n"
842 context->bw.dce.nbp_state_change_wm_ns[0].b_mark,
843 context->bw.dce.nbp_state_change_wm_ns[0].a_mark,
844 context->bw.dce.urgent_wm_ns[0].b_mark,
845 context->bw.dce.urgent_wm_ns[0].a_mark,
846 context->bw.dce.stutter_exit_wm_ns[0].b_mark,
847 context->bw.dce.stutter_exit_wm_ns[0].a_mark,
848 context->bw.dce.nbp_state_change_wm_ns[1].b_mark,
849 context->bw.dce.nbp_state_change_wm_ns[1].a_mark,
850 context->bw.dce.urgent_wm_ns[1].b_mark,
851 context->bw.dce.urgent_wm_ns[1].a_mark,
852 context->bw.dce.stutter_exit_wm_ns[1].b_mark,
853 context->bw.dce.stutter_exit_wm_ns[1].a_mark,
854 context->bw.dce.nbp_state_change_wm_ns[2].b_mark,
855 context->bw.dce.nbp_state_change_wm_ns[2].a_mark,
856 context->bw.dce.urgent_wm_ns[2].b_mark,
857 context->bw.dce.urgent_wm_ns[2].a_mark,
858 context->bw.dce.stutter_exit_wm_ns[2].b_mark,
859 context->bw.dce.stutter_exit_wm_ns[2].a_mark,
860 context->bw.dce.stutter_mode_enable,
861 context->bw.dce.cpuc_state_change_enable,
862 context->bw.dce.cpup_state_change_enable,
863 context->bw.dce.nbp_state_change_enable,
864 context->bw.dce.all_displays_in_sync,
865 context->bw.dce.dispclk_khz,
866 context->bw.dce.sclk_khz,
867 context->bw.dce.sclk_deep_sleep_khz,
868 context->bw.dce.yclk_khz,
869 context->bw.dce.blackout_recovery_time_us);
874 enum dc_status resource_map_phy_clock_resources(
876 struct dc_state *context,
877 struct dc_stream_state *stream)
880 /* acquire new resources */
881 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(
882 &context->res_ctx, stream);
885 return DC_ERROR_UNEXPECTED;
887 if (dc_is_dp_signal(pipe_ctx->stream->signal)
888 || pipe_ctx->stream->signal == SIGNAL_TYPE_VIRTUAL)
889 pipe_ctx->clock_source =
890 dc->res_pool->dp_clock_source;
892 pipe_ctx->clock_source = find_matching_pll(
893 &context->res_ctx, dc->res_pool,
896 if (pipe_ctx->clock_source == NULL)
897 return DC_NO_CLOCK_SOURCE_RESOURCE;
899 resource_reference_clock_source(
902 pipe_ctx->clock_source);
907 static bool dce112_validate_surface_sets(
908 struct dc_state *context)
912 for (i = 0; i < context->stream_count; i++) {
913 if (context->stream_status[i].plane_count == 0)
916 if (context->stream_status[i].plane_count > 1)
919 if (context->stream_status[i].plane_states[0]->format
920 >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
927 enum dc_status dce112_add_stream_to_ctx(
929 struct dc_state *new_ctx,
930 struct dc_stream_state *dc_stream)
932 enum dc_status result = DC_ERROR_UNEXPECTED;
934 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
937 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
941 result = build_mapped_resource(dc, new_ctx, dc_stream);
946 enum dc_status dce112_validate_global(
948 struct dc_state *context)
950 if (!dce112_validate_surface_sets(context))
951 return DC_FAIL_SURFACE_VALIDATE;
956 static void dce112_destroy_resource_pool(struct resource_pool **pool)
958 struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
960 destruct(dce110_pool);
965 static const struct resource_funcs dce112_res_pool_funcs = {
966 .destroy = dce112_destroy_resource_pool,
967 .link_enc_create = dce112_link_encoder_create,
968 .validate_bandwidth = dce112_validate_bandwidth,
969 .validate_plane = dce100_validate_plane,
970 .add_stream_to_ctx = dce112_add_stream_to_ctx,
971 .validate_global = dce112_validate_global
974 static void bw_calcs_data_update_from_pplib(struct dc *dc)
976 struct dm_pp_clock_levels_with_latency eng_clks = {0};
977 struct dm_pp_clock_levels_with_latency mem_clks = {0};
978 struct dm_pp_wm_sets_with_clock_ranges clk_ranges = {0};
979 struct dm_pp_clock_levels clks = {0};
981 /*do system clock TODO PPLIB: after PPLIB implement,
982 * then remove old way
984 if (!dm_pp_get_clock_levels_by_type_with_latency(
986 DM_PP_CLOCK_TYPE_ENGINE_CLK,
989 /* This is only for temporary */
990 dm_pp_get_clock_levels_by_type(
992 DM_PP_CLOCK_TYPE_ENGINE_CLK,
994 /* convert all the clock fro kHz to fix point mHz */
995 dc->bw_vbios->high_sclk = bw_frc_to_fixed(
996 clks.clocks_in_khz[clks.num_levels-1], 1000);
997 dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
998 clks.clocks_in_khz[clks.num_levels/8], 1000);
999 dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
1000 clks.clocks_in_khz[clks.num_levels*2/8], 1000);
1001 dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
1002 clks.clocks_in_khz[clks.num_levels*3/8], 1000);
1003 dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
1004 clks.clocks_in_khz[clks.num_levels*4/8], 1000);
1005 dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
1006 clks.clocks_in_khz[clks.num_levels*5/8], 1000);
1007 dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
1008 clks.clocks_in_khz[clks.num_levels*6/8], 1000);
1009 dc->bw_vbios->low_sclk = bw_frc_to_fixed(
1010 clks.clocks_in_khz[0], 1000);
1013 dm_pp_get_clock_levels_by_type(
1015 DM_PP_CLOCK_TYPE_MEMORY_CLK,
1018 dc->bw_vbios->low_yclk = bw_frc_to_fixed(
1019 clks.clocks_in_khz[0] * MEMORY_TYPE_MULTIPLIER_CZ, 1000);
1020 dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
1021 clks.clocks_in_khz[clks.num_levels>>1] * MEMORY_TYPE_MULTIPLIER_CZ,
1023 dc->bw_vbios->high_yclk = bw_frc_to_fixed(
1024 clks.clocks_in_khz[clks.num_levels-1] * MEMORY_TYPE_MULTIPLIER_CZ,
1030 /* convert all the clock fro kHz to fix point mHz TODO: wloop data */
1031 dc->bw_vbios->high_sclk = bw_frc_to_fixed(
1032 eng_clks.data[eng_clks.num_levels-1].clocks_in_khz, 1000);
1033 dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
1034 eng_clks.data[eng_clks.num_levels/8].clocks_in_khz, 1000);
1035 dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
1036 eng_clks.data[eng_clks.num_levels*2/8].clocks_in_khz, 1000);
1037 dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
1038 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz, 1000);
1039 dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
1040 eng_clks.data[eng_clks.num_levels*4/8].clocks_in_khz, 1000);
1041 dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
1042 eng_clks.data[eng_clks.num_levels*5/8].clocks_in_khz, 1000);
1043 dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
1044 eng_clks.data[eng_clks.num_levels*6/8].clocks_in_khz, 1000);
1045 dc->bw_vbios->low_sclk = bw_frc_to_fixed(
1046 eng_clks.data[0].clocks_in_khz, 1000);
1049 dm_pp_get_clock_levels_by_type_with_latency(
1051 DM_PP_CLOCK_TYPE_MEMORY_CLK,
1054 /* we don't need to call PPLIB for validation clock since they
1055 * also give us the highest sclk and highest mclk (UMA clock).
1056 * ALSO always convert UMA clock (from PPLIB) to YCLK (HW formula):
1057 * YCLK = UMACLK*m_memoryTypeMultiplier
1059 dc->bw_vbios->low_yclk = bw_frc_to_fixed(
1060 mem_clks.data[0].clocks_in_khz * MEMORY_TYPE_MULTIPLIER_CZ, 1000);
1061 dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
1062 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz * MEMORY_TYPE_MULTIPLIER_CZ,
1064 dc->bw_vbios->high_yclk = bw_frc_to_fixed(
1065 mem_clks.data[mem_clks.num_levels-1].clocks_in_khz * MEMORY_TYPE_MULTIPLIER_CZ,
1068 /* Now notify PPLib/SMU about which Watermarks sets they should select
1069 * depending on DPM state they are in. And update BW MGR GFX Engine and
1070 * Memory clock member variables for Watermarks calculations for each
1073 clk_ranges.num_wm_sets = 4;
1074 clk_ranges.wm_clk_ranges[0].wm_set_id = WM_SET_A;
1075 clk_ranges.wm_clk_ranges[0].wm_min_eng_clk_in_khz =
1076 eng_clks.data[0].clocks_in_khz;
1077 clk_ranges.wm_clk_ranges[0].wm_max_eng_clk_in_khz =
1078 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz - 1;
1079 clk_ranges.wm_clk_ranges[0].wm_min_mem_clk_in_khz =
1080 mem_clks.data[0].clocks_in_khz;
1081 clk_ranges.wm_clk_ranges[0].wm_max_mem_clk_in_khz =
1082 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz - 1;
1084 clk_ranges.wm_clk_ranges[1].wm_set_id = WM_SET_B;
1085 clk_ranges.wm_clk_ranges[1].wm_min_eng_clk_in_khz =
1086 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz;
1087 /* 5 GHz instead of data[7].clockInKHz to cover Overdrive */
1088 clk_ranges.wm_clk_ranges[1].wm_max_eng_clk_in_khz = 5000000;
1089 clk_ranges.wm_clk_ranges[1].wm_min_mem_clk_in_khz =
1090 mem_clks.data[0].clocks_in_khz;
1091 clk_ranges.wm_clk_ranges[1].wm_max_mem_clk_in_khz =
1092 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz - 1;
1094 clk_ranges.wm_clk_ranges[2].wm_set_id = WM_SET_C;
1095 clk_ranges.wm_clk_ranges[2].wm_min_eng_clk_in_khz =
1096 eng_clks.data[0].clocks_in_khz;
1097 clk_ranges.wm_clk_ranges[2].wm_max_eng_clk_in_khz =
1098 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz - 1;
1099 clk_ranges.wm_clk_ranges[2].wm_min_mem_clk_in_khz =
1100 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz;
1101 /* 5 GHz instead of data[2].clockInKHz to cover Overdrive */
1102 clk_ranges.wm_clk_ranges[2].wm_max_mem_clk_in_khz = 5000000;
1104 clk_ranges.wm_clk_ranges[3].wm_set_id = WM_SET_D;
1105 clk_ranges.wm_clk_ranges[3].wm_min_eng_clk_in_khz =
1106 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz;
1107 /* 5 GHz instead of data[7].clockInKHz to cover Overdrive */
1108 clk_ranges.wm_clk_ranges[3].wm_max_eng_clk_in_khz = 5000000;
1109 clk_ranges.wm_clk_ranges[3].wm_min_mem_clk_in_khz =
1110 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz;
1111 /* 5 GHz instead of data[2].clockInKHz to cover Overdrive */
1112 clk_ranges.wm_clk_ranges[3].wm_max_mem_clk_in_khz = 5000000;
1114 /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
1115 dm_pp_notify_wm_clock_changes(dc->ctx, &clk_ranges);
1118 const struct resource_caps *dce112_resource_cap(
1119 struct hw_asic_id *asic_id)
1121 if (ASIC_REV_IS_POLARIS11_M(asic_id->hw_internal_rev) ||
1122 ASIC_REV_IS_POLARIS12_V(asic_id->hw_internal_rev))
1123 return &polaris_11_resource_cap;
1125 return &polaris_10_resource_cap;
1128 static bool construct(
1129 uint8_t num_virtual_links,
1131 struct dce110_resource_pool *pool)
1134 struct dc_context *ctx = dc->ctx;
1136 ctx->dc_bios->regs = &bios_regs;
1138 pool->base.res_cap = dce112_resource_cap(&ctx->asic_id);
1139 pool->base.funcs = &dce112_res_pool_funcs;
1141 /*************************************************
1142 * Resource + asic cap harcoding *
1143 *************************************************/
1144 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1145 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1146 pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
1147 dc->caps.max_downscale_ratio = 200;
1148 dc->caps.i2c_speed_in_khz = 100;
1149 dc->caps.max_cursor_size = 128;
1150 dc->caps.dual_link_dvi = true;
1153 /*************************************************
1154 * Create resources *
1155 *************************************************/
1157 pool->base.clock_sources[DCE112_CLK_SRC_PLL0] =
1158 dce112_clock_source_create(
1160 CLOCK_SOURCE_COMBO_PHY_PLL0,
1161 &clk_src_regs[0], false);
1162 pool->base.clock_sources[DCE112_CLK_SRC_PLL1] =
1163 dce112_clock_source_create(
1165 CLOCK_SOURCE_COMBO_PHY_PLL1,
1166 &clk_src_regs[1], false);
1167 pool->base.clock_sources[DCE112_CLK_SRC_PLL2] =
1168 dce112_clock_source_create(
1170 CLOCK_SOURCE_COMBO_PHY_PLL2,
1171 &clk_src_regs[2], false);
1172 pool->base.clock_sources[DCE112_CLK_SRC_PLL3] =
1173 dce112_clock_source_create(
1175 CLOCK_SOURCE_COMBO_PHY_PLL3,
1176 &clk_src_regs[3], false);
1177 pool->base.clock_sources[DCE112_CLK_SRC_PLL4] =
1178 dce112_clock_source_create(
1180 CLOCK_SOURCE_COMBO_PHY_PLL4,
1181 &clk_src_regs[4], false);
1182 pool->base.clock_sources[DCE112_CLK_SRC_PLL5] =
1183 dce112_clock_source_create(
1185 CLOCK_SOURCE_COMBO_PHY_PLL5,
1186 &clk_src_regs[5], false);
1187 pool->base.clk_src_count = DCE112_CLK_SRC_TOTAL;
1189 pool->base.dp_clock_source = dce112_clock_source_create(
1191 CLOCK_SOURCE_ID_DP_DTO, &clk_src_regs[0], true);
1194 for (i = 0; i < pool->base.clk_src_count; i++) {
1195 if (pool->base.clock_sources[i] == NULL) {
1196 dm_error("DC: failed to create clock sources!\n");
1197 BREAK_TO_DEBUGGER();
1198 goto res_create_fail;
1202 pool->base.dccg = dce112_dccg_create(ctx,
1206 if (pool->base.dccg == NULL) {
1207 dm_error("DC: failed to create display clock!\n");
1208 BREAK_TO_DEBUGGER();
1209 goto res_create_fail;
1212 pool->base.dmcu = dce_dmcu_create(ctx,
1216 if (pool->base.dmcu == NULL) {
1217 dm_error("DC: failed to create dmcu!\n");
1218 BREAK_TO_DEBUGGER();
1219 goto res_create_fail;
1222 pool->base.abm = dce_abm_create(ctx,
1226 if (pool->base.abm == NULL) {
1227 dm_error("DC: failed to create abm!\n");
1228 BREAK_TO_DEBUGGER();
1229 goto res_create_fail;
1233 struct irq_service_init_data init_data;
1234 init_data.ctx = dc->ctx;
1235 pool->base.irqs = dal_irq_service_dce110_create(&init_data);
1236 if (!pool->base.irqs)
1237 goto res_create_fail;
1240 for (i = 0; i < pool->base.pipe_count; i++) {
1241 pool->base.timing_generators[i] =
1242 dce112_timing_generator_create(
1245 &dce112_tg_offsets[i]);
1246 if (pool->base.timing_generators[i] == NULL) {
1247 BREAK_TO_DEBUGGER();
1248 dm_error("DC: failed to create tg!\n");
1249 goto res_create_fail;
1252 pool->base.mis[i] = dce112_mem_input_create(ctx, i);
1253 if (pool->base.mis[i] == NULL) {
1254 BREAK_TO_DEBUGGER();
1256 "DC: failed to create memory input!\n");
1257 goto res_create_fail;
1260 pool->base.ipps[i] = dce112_ipp_create(ctx, i);
1261 if (pool->base.ipps[i] == NULL) {
1262 BREAK_TO_DEBUGGER();
1264 "DC:failed to create input pixel processor!\n");
1265 goto res_create_fail;
1268 pool->base.transforms[i] = dce112_transform_create(ctx, i);
1269 if (pool->base.transforms[i] == NULL) {
1270 BREAK_TO_DEBUGGER();
1272 "DC: failed to create transform!\n");
1273 goto res_create_fail;
1276 pool->base.opps[i] = dce112_opp_create(
1279 if (pool->base.opps[i] == NULL) {
1280 BREAK_TO_DEBUGGER();
1282 "DC:failed to create output pixel processor!\n");
1283 goto res_create_fail;
1287 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1288 pool->base.engines[i] = dce112_aux_engine_create(ctx, i);
1289 if (pool->base.engines[i] == NULL) {
1290 BREAK_TO_DEBUGGER();
1292 "DC:failed to create aux engine!!\n");
1293 goto res_create_fail;
1295 pool->base.hw_i2cs[i] = dce112_i2c_hw_create(ctx, i);
1296 if (pool->base.hw_i2cs[i] == NULL) {
1297 BREAK_TO_DEBUGGER();
1299 "DC:failed to create i2c engine!!\n");
1300 goto res_create_fail;
1302 pool->base.sw_i2cs[i] = NULL;
1305 if (!resource_construct(num_virtual_links, dc, &pool->base,
1307 goto res_create_fail;
1309 dc->caps.max_planes = pool->base.pipe_count;
1311 /* Create hardware sequencer */
1312 dce112_hw_sequencer_construct(dc);
1314 bw_calcs_init(dc->bw_dceip, dc->bw_vbios, dc->ctx->asic_id);
1316 bw_calcs_data_update_from_pplib(dc);
1325 struct resource_pool *dce112_create_resource_pool(
1326 uint8_t num_virtual_links,
1329 struct dce110_resource_pool *pool =
1330 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1335 if (construct(num_virtual_links, dc, pool))
1338 BREAK_TO_DEBUGGER();