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 "dm_services.h"
28 #include "link_encoder.h"
29 #include "stream_encoder.h"
32 #include "include/irq_service_interface.h"
33 #include "dce110/dce110_resource.h"
34 #include "dce110/dce110_timing_generator.h"
36 #include "irq/dce110/irq_service_dce110.h"
38 #include "dce/dce_mem_input.h"
39 #include "dce/dce_transform.h"
40 #include "dce/dce_link_encoder.h"
41 #include "dce/dce_stream_encoder.h"
42 #include "dce/dce_audio.h"
43 #include "dce/dce_opp.h"
44 #include "dce/dce_ipp.h"
45 #include "dce/dce_clocks.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"
54 #include "reg_helper.h"
56 #include "dce/dce_11_2_d.h"
57 #include "dce/dce_11_2_sh_mask.h"
59 #include "dce100/dce100_resource.h"
63 #ifndef mmDP_DPHY_INTERNAL_CTRL
64 #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
65 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
66 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
67 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
68 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
69 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
70 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
71 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
72 #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
73 #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
76 #ifndef mmBIOS_SCRATCH_2
77 #define mmBIOS_SCRATCH_2 0x05CB
78 #define mmBIOS_SCRATCH_6 0x05CF
81 #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
82 #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
83 #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
84 #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
85 #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
86 #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
87 #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
88 #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
89 #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
92 #ifndef mmDP_DPHY_FAST_TRAINING
93 #define mmDP_DPHY_FAST_TRAINING 0x4ABC
94 #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
95 #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
96 #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
97 #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
98 #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
99 #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
100 #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
103 enum dce112_clk_src_array_id {
114 static const struct dce110_timing_generator_offsets dce112_tg_offsets[] = {
116 .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
117 .dcp = (mmDCP0_GRPH_CONTROL - mmGRPH_CONTROL),
120 .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
121 .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
124 .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
125 .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
128 .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
129 .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
132 .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
133 .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
136 .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
137 .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
141 /* set register offset */
142 #define SR(reg_name)\
143 .reg_name = mm ## reg_name
145 /* set register offset with instance */
146 #define SRI(reg_name, block, id)\
147 .reg_name = mm ## block ## id ## _ ## reg_name
150 static const struct dccg_registers disp_clk_regs = {
151 CLK_COMMON_REG_LIST_DCE_BASE()
154 static const struct dccg_shift disp_clk_shift = {
155 CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
158 static const struct dccg_mask disp_clk_mask = {
159 CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
162 static const struct dce_dmcu_registers dmcu_regs = {
163 DMCU_DCE110_COMMON_REG_LIST()
166 static const struct dce_dmcu_shift dmcu_shift = {
167 DMCU_MASK_SH_LIST_DCE110(__SHIFT)
170 static const struct dce_dmcu_mask dmcu_mask = {
171 DMCU_MASK_SH_LIST_DCE110(_MASK)
174 static const struct dce_abm_registers abm_regs = {
175 ABM_DCE110_COMMON_REG_LIST()
178 static const struct dce_abm_shift abm_shift = {
179 ABM_MASK_SH_LIST_DCE110(__SHIFT)
182 static const struct dce_abm_mask abm_mask = {
183 ABM_MASK_SH_LIST_DCE110(_MASK)
186 #define ipp_regs(id)\
188 IPP_DCE110_REG_LIST_DCE_BASE(id)\
191 static const struct dce_ipp_registers ipp_regs[] = {
200 static const struct dce_ipp_shift ipp_shift = {
201 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
204 static const struct dce_ipp_mask ipp_mask = {
205 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
208 #define transform_regs(id)\
210 XFM_COMMON_REG_LIST_DCE110(id)\
213 static const struct dce_transform_registers xfm_regs[] = {
222 static const struct dce_transform_shift xfm_shift = {
223 XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
226 static const struct dce_transform_mask xfm_mask = {
227 XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
230 #define aux_regs(id)\
235 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
244 #define hpd_regs(id)\
249 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
258 #define link_regs(id)\
260 LE_DCE110_REG_LIST(id)\
263 static const struct dce110_link_enc_registers link_enc_regs[] = {
273 #define stream_enc_regs(id)\
275 SE_COMMON_REG_LIST(id),\
279 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
288 static const struct dce_stream_encoder_shift se_shift = {
289 SE_COMMON_MASK_SH_LIST_DCE112(__SHIFT)
292 static const struct dce_stream_encoder_mask se_mask = {
293 SE_COMMON_MASK_SH_LIST_DCE112(_MASK)
296 #define opp_regs(id)\
298 OPP_DCE_112_REG_LIST(id),\
301 static const struct dce_opp_registers opp_regs[] = {
310 static const struct dce_opp_shift opp_shift = {
311 OPP_COMMON_MASK_SH_LIST_DCE_112(__SHIFT)
314 static const struct dce_opp_mask opp_mask = {
315 OPP_COMMON_MASK_SH_LIST_DCE_112(_MASK)
318 #define aux_engine_regs(id)\
320 AUX_COMMON_REG_LIST(id), \
321 .AUX_RESET_MASK = 0 \
324 static const struct dce110_aux_registers aux_engine_regs[] = {
333 #define audio_regs(id)\
335 AUD_COMMON_REG_LIST(id)\
338 static const struct dce_audio_registers audio_regs[] = {
347 static const struct dce_audio_shift audio_shift = {
348 AUD_COMMON_MASK_SH_LIST(__SHIFT)
351 static const struct dce_aduio_mask audio_mask = {
352 AUD_COMMON_MASK_SH_LIST(_MASK)
355 #define clk_src_regs(index, id)\
357 CS_COMMON_REG_LIST_DCE_112(id),\
360 static const struct dce110_clk_src_regs clk_src_regs[] = {
369 static const struct dce110_clk_src_shift cs_shift = {
370 CS_COMMON_MASK_SH_LIST_DCE_112(__SHIFT)
373 static const struct dce110_clk_src_mask cs_mask = {
374 CS_COMMON_MASK_SH_LIST_DCE_112(_MASK)
377 static const struct bios_registers bios_regs = {
378 .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
381 static const struct resource_caps polaris_10_resource_cap = {
382 .num_timing_generator = 6,
384 .num_stream_encoder = 6,
385 .num_pll = 8, /* why 8? 6 combo PHY PLL + 2 regular PLLs? */
388 static const struct resource_caps polaris_11_resource_cap = {
389 .num_timing_generator = 5,
391 .num_stream_encoder = 5,
392 .num_pll = 8, /* why 8? 6 combo PHY PLL + 2 regular PLLs? */
396 #define REG(reg) mm ## reg
398 #ifndef mmCC_DC_HDMI_STRAPS
399 #define mmCC_DC_HDMI_STRAPS 0x4819
400 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
401 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
402 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
403 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
406 static void read_dce_straps(
407 struct dc_context *ctx,
408 struct resource_straps *straps)
410 REG_GET_2(CC_DC_HDMI_STRAPS,
411 HDMI_DISABLE, &straps->hdmi_disable,
412 AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
414 REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
417 static struct audio *create_audio(
418 struct dc_context *ctx, unsigned int inst)
420 return dce_audio_create(ctx, inst,
421 &audio_regs[inst], &audio_shift, &audio_mask);
425 static struct timing_generator *dce112_timing_generator_create(
426 struct dc_context *ctx,
428 const struct dce110_timing_generator_offsets *offsets)
430 struct dce110_timing_generator *tg110 =
431 kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
436 dce110_timing_generator_construct(tg110, ctx, instance, offsets);
440 static struct stream_encoder *dce112_stream_encoder_create(
441 enum engine_id eng_id,
442 struct dc_context *ctx)
444 struct dce110_stream_encoder *enc110 =
445 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
450 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
451 &stream_enc_regs[eng_id],
452 &se_shift, &se_mask);
453 return &enc110->base;
456 #define SRII(reg_name, block, id)\
457 .reg_name[id] = mm ## block ## id ## _ ## reg_name
459 static const struct dce_hwseq_registers hwseq_reg = {
460 HWSEQ_DCE112_REG_LIST()
463 static const struct dce_hwseq_shift hwseq_shift = {
464 HWSEQ_DCE112_MASK_SH_LIST(__SHIFT)
467 static const struct dce_hwseq_mask hwseq_mask = {
468 HWSEQ_DCE112_MASK_SH_LIST(_MASK)
471 static struct dce_hwseq *dce112_hwseq_create(
472 struct dc_context *ctx)
474 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
478 hws->regs = &hwseq_reg;
479 hws->shifts = &hwseq_shift;
480 hws->masks = &hwseq_mask;
485 static const struct resource_create_funcs res_create_funcs = {
486 .read_dce_straps = read_dce_straps,
487 .create_audio = create_audio,
488 .create_stream_encoder = dce112_stream_encoder_create,
489 .create_hwseq = dce112_hwseq_create,
492 #define mi_inst_regs(id) { MI_DCE11_2_REG_LIST(id) }
493 static const struct dce_mem_input_registers mi_regs[] = {
502 static const struct dce_mem_input_shift mi_shifts = {
503 MI_DCE11_2_MASK_SH_LIST(__SHIFT)
506 static const struct dce_mem_input_mask mi_masks = {
507 MI_DCE11_2_MASK_SH_LIST(_MASK)
510 static struct mem_input *dce112_mem_input_create(
511 struct dc_context *ctx,
514 struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
522 dce112_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
523 return &dce_mi->base;
526 static void dce112_transform_destroy(struct transform **xfm)
528 kfree(TO_DCE_TRANSFORM(*xfm));
532 static struct transform *dce112_transform_create(
533 struct dc_context *ctx,
536 struct dce_transform *transform =
537 kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
542 dce_transform_construct(transform, ctx, inst,
543 &xfm_regs[inst], &xfm_shift, &xfm_mask);
544 transform->lb_memory_size = 0x1404; /*5124*/
545 return &transform->base;
548 static const struct encoder_feature_support link_enc_feature = {
549 .max_hdmi_deep_color = COLOR_DEPTH_121212,
550 .max_hdmi_pixel_clock = 600000,
551 .ycbcr420_supported = true,
552 .flags.bits.IS_HBR2_CAPABLE = true,
553 .flags.bits.IS_HBR3_CAPABLE = true,
554 .flags.bits.IS_TPS3_CAPABLE = true,
555 .flags.bits.IS_TPS4_CAPABLE = true,
556 .flags.bits.IS_YCBCR_CAPABLE = true
559 struct link_encoder *dce112_link_encoder_create(
560 const struct encoder_init_data *enc_init_data)
562 struct dce110_link_encoder *enc110 =
563 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
568 dce110_link_encoder_construct(enc110,
571 &link_enc_regs[enc_init_data->transmitter],
572 &link_enc_aux_regs[enc_init_data->channel - 1],
573 &link_enc_hpd_regs[enc_init_data->hpd_source]);
574 return &enc110->base;
577 static struct input_pixel_processor *dce112_ipp_create(
578 struct dc_context *ctx, uint32_t inst)
580 struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
587 dce_ipp_construct(ipp, ctx, inst,
588 &ipp_regs[inst], &ipp_shift, &ipp_mask);
592 struct output_pixel_processor *dce112_opp_create(
593 struct dc_context *ctx,
596 struct dce110_opp *opp =
597 kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
602 dce110_opp_construct(opp,
603 ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
607 struct aux_engine *dce112_aux_engine_create(
608 struct dc_context *ctx,
611 struct aux_engine_dce110 *aux_engine =
612 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
617 dce110_aux_engine_construct(aux_engine, ctx, inst,
618 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
619 &aux_engine_regs[inst]);
621 return &aux_engine->base;
624 struct clock_source *dce112_clock_source_create(
625 struct dc_context *ctx,
626 struct dc_bios *bios,
627 enum clock_source_id id,
628 const struct dce110_clk_src_regs *regs,
631 struct dce110_clk_src *clk_src =
632 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
637 if (dce110_clk_src_construct(clk_src, ctx, bios, id,
638 regs, &cs_shift, &cs_mask)) {
639 clk_src->base.dp_clk_src = dp_clk_src;
640 return &clk_src->base;
647 void dce112_clock_source_destroy(struct clock_source **clk_src)
649 kfree(TO_DCE110_CLK_SRC(*clk_src));
653 static void destruct(struct dce110_resource_pool *pool)
657 for (i = 0; i < pool->base.pipe_count; i++) {
658 if (pool->base.opps[i] != NULL)
659 dce110_opp_destroy(&pool->base.opps[i]);
661 if (pool->base.engines[i] != NULL)
662 dce110_engine_destroy(&pool->base.engines[i]);
664 if (pool->base.transforms[i] != NULL)
665 dce112_transform_destroy(&pool->base.transforms[i]);
667 if (pool->base.ipps[i] != NULL)
668 dce_ipp_destroy(&pool->base.ipps[i]);
670 if (pool->base.mis[i] != NULL) {
671 kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
672 pool->base.mis[i] = NULL;
675 if (pool->base.timing_generators[i] != NULL) {
676 kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
677 pool->base.timing_generators[i] = NULL;
682 for (i = 0; i < pool->base.stream_enc_count; i++) {
683 if (pool->base.stream_enc[i] != NULL)
684 kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
687 for (i = 0; i < pool->base.clk_src_count; i++) {
688 if (pool->base.clock_sources[i] != NULL) {
689 dce112_clock_source_destroy(&pool->base.clock_sources[i]);
693 if (pool->base.dp_clock_source != NULL)
694 dce112_clock_source_destroy(&pool->base.dp_clock_source);
696 for (i = 0; i < pool->base.audio_count; i++) {
697 if (pool->base.audios[i] != NULL) {
698 dce_aud_destroy(&pool->base.audios[i]);
702 if (pool->base.abm != NULL)
703 dce_abm_destroy(&pool->base.abm);
705 if (pool->base.dmcu != NULL)
706 dce_dmcu_destroy(&pool->base.dmcu);
708 if (pool->base.dccg != NULL)
709 dce_dccg_destroy(&pool->base.dccg);
711 if (pool->base.irqs != NULL) {
712 dal_irq_service_destroy(&pool->base.irqs);
716 static struct clock_source *find_matching_pll(
717 struct resource_context *res_ctx,
718 const struct resource_pool *pool,
719 const struct dc_stream_state *const stream)
721 switch (stream->sink->link->link_enc->transmitter) {
722 case TRANSMITTER_UNIPHY_A:
723 return pool->clock_sources[DCE112_CLK_SRC_PLL0];
724 case TRANSMITTER_UNIPHY_B:
725 return pool->clock_sources[DCE112_CLK_SRC_PLL1];
726 case TRANSMITTER_UNIPHY_C:
727 return pool->clock_sources[DCE112_CLK_SRC_PLL2];
728 case TRANSMITTER_UNIPHY_D:
729 return pool->clock_sources[DCE112_CLK_SRC_PLL3];
730 case TRANSMITTER_UNIPHY_E:
731 return pool->clock_sources[DCE112_CLK_SRC_PLL4];
732 case TRANSMITTER_UNIPHY_F:
733 return pool->clock_sources[DCE112_CLK_SRC_PLL5];
741 static enum dc_status build_mapped_resource(
743 struct dc_state *context,
744 struct dc_stream_state *stream)
746 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
749 return DC_ERROR_UNEXPECTED;
751 dce110_resource_build_pipe_hw_param(pipe_ctx);
753 resource_build_info_frame(pipe_ctx);
758 bool dce112_validate_bandwidth(
760 struct dc_state *context)
764 DC_LOG_BANDWIDTH_CALCS(
772 context->res_ctx.pipe_ctx,
773 dc->res_pool->pipe_count,
778 DC_LOG_BANDWIDTH_VALIDATION(
779 "%s: Bandwidth validation failed!",
782 if (memcmp(&dc->current_state->bw.dce,
783 &context->bw.dce, sizeof(context->bw.dce))) {
785 DC_LOG_BANDWIDTH_CALCS(
787 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
788 "stutMark_b: %d stutMark_a: %d\n"
789 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
790 "stutMark_b: %d stutMark_a: %d\n"
791 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
792 "stutMark_b: %d stutMark_a: %d stutter_mode_enable: %d\n"
793 "cstate: %d pstate: %d nbpstate: %d sync: %d dispclk: %d\n"
794 "sclk: %d sclk_sleep: %d yclk: %d blackout_recovery_time_us: %d\n"
797 context->bw.dce.nbp_state_change_wm_ns[0].b_mark,
798 context->bw.dce.nbp_state_change_wm_ns[0].a_mark,
799 context->bw.dce.urgent_wm_ns[0].b_mark,
800 context->bw.dce.urgent_wm_ns[0].a_mark,
801 context->bw.dce.stutter_exit_wm_ns[0].b_mark,
802 context->bw.dce.stutter_exit_wm_ns[0].a_mark,
803 context->bw.dce.nbp_state_change_wm_ns[1].b_mark,
804 context->bw.dce.nbp_state_change_wm_ns[1].a_mark,
805 context->bw.dce.urgent_wm_ns[1].b_mark,
806 context->bw.dce.urgent_wm_ns[1].a_mark,
807 context->bw.dce.stutter_exit_wm_ns[1].b_mark,
808 context->bw.dce.stutter_exit_wm_ns[1].a_mark,
809 context->bw.dce.nbp_state_change_wm_ns[2].b_mark,
810 context->bw.dce.nbp_state_change_wm_ns[2].a_mark,
811 context->bw.dce.urgent_wm_ns[2].b_mark,
812 context->bw.dce.urgent_wm_ns[2].a_mark,
813 context->bw.dce.stutter_exit_wm_ns[2].b_mark,
814 context->bw.dce.stutter_exit_wm_ns[2].a_mark,
815 context->bw.dce.stutter_mode_enable,
816 context->bw.dce.cpuc_state_change_enable,
817 context->bw.dce.cpup_state_change_enable,
818 context->bw.dce.nbp_state_change_enable,
819 context->bw.dce.all_displays_in_sync,
820 context->bw.dce.dispclk_khz,
821 context->bw.dce.sclk_khz,
822 context->bw.dce.sclk_deep_sleep_khz,
823 context->bw.dce.yclk_khz,
824 context->bw.dce.blackout_recovery_time_us);
829 enum dc_status resource_map_phy_clock_resources(
831 struct dc_state *context,
832 struct dc_stream_state *stream)
835 /* acquire new resources */
836 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(
837 &context->res_ctx, stream);
840 return DC_ERROR_UNEXPECTED;
842 if (dc_is_dp_signal(pipe_ctx->stream->signal)
843 || pipe_ctx->stream->signal == SIGNAL_TYPE_VIRTUAL)
844 pipe_ctx->clock_source =
845 dc->res_pool->dp_clock_source;
847 pipe_ctx->clock_source = find_matching_pll(
848 &context->res_ctx, dc->res_pool,
851 if (pipe_ctx->clock_source == NULL)
852 return DC_NO_CLOCK_SOURCE_RESOURCE;
854 resource_reference_clock_source(
857 pipe_ctx->clock_source);
862 static bool dce112_validate_surface_sets(
863 struct dc_state *context)
867 for (i = 0; i < context->stream_count; i++) {
868 if (context->stream_status[i].plane_count == 0)
871 if (context->stream_status[i].plane_count > 1)
874 if (context->stream_status[i].plane_states[0]->format
875 >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
882 enum dc_status dce112_add_stream_to_ctx(
884 struct dc_state *new_ctx,
885 struct dc_stream_state *dc_stream)
887 enum dc_status result = DC_ERROR_UNEXPECTED;
889 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
892 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
896 result = build_mapped_resource(dc, new_ctx, dc_stream);
901 enum dc_status dce112_validate_global(
903 struct dc_state *context)
905 if (!dce112_validate_surface_sets(context))
906 return DC_FAIL_SURFACE_VALIDATE;
911 static void dce112_destroy_resource_pool(struct resource_pool **pool)
913 struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
915 destruct(dce110_pool);
920 static const struct resource_funcs dce112_res_pool_funcs = {
921 .destroy = dce112_destroy_resource_pool,
922 .link_enc_create = dce112_link_encoder_create,
923 .validate_bandwidth = dce112_validate_bandwidth,
924 .validate_plane = dce100_validate_plane,
925 .add_stream_to_ctx = dce112_add_stream_to_ctx,
926 .validate_global = dce112_validate_global
929 static void bw_calcs_data_update_from_pplib(struct dc *dc)
931 struct dm_pp_clock_levels_with_latency eng_clks = {0};
932 struct dm_pp_clock_levels_with_latency mem_clks = {0};
933 struct dm_pp_wm_sets_with_clock_ranges clk_ranges = {0};
934 struct dm_pp_clock_levels clks = {0};
936 /*do system clock TODO PPLIB: after PPLIB implement,
937 * then remove old way
939 if (!dm_pp_get_clock_levels_by_type_with_latency(
941 DM_PP_CLOCK_TYPE_ENGINE_CLK,
944 /* This is only for temporary */
945 dm_pp_get_clock_levels_by_type(
947 DM_PP_CLOCK_TYPE_ENGINE_CLK,
949 /* convert all the clock fro kHz to fix point mHz */
950 dc->bw_vbios->high_sclk = bw_frc_to_fixed(
951 clks.clocks_in_khz[clks.num_levels-1], 1000);
952 dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
953 clks.clocks_in_khz[clks.num_levels/8], 1000);
954 dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
955 clks.clocks_in_khz[clks.num_levels*2/8], 1000);
956 dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
957 clks.clocks_in_khz[clks.num_levels*3/8], 1000);
958 dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
959 clks.clocks_in_khz[clks.num_levels*4/8], 1000);
960 dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
961 clks.clocks_in_khz[clks.num_levels*5/8], 1000);
962 dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
963 clks.clocks_in_khz[clks.num_levels*6/8], 1000);
964 dc->bw_vbios->low_sclk = bw_frc_to_fixed(
965 clks.clocks_in_khz[0], 1000);
968 dm_pp_get_clock_levels_by_type(
970 DM_PP_CLOCK_TYPE_MEMORY_CLK,
973 dc->bw_vbios->low_yclk = bw_frc_to_fixed(
974 clks.clocks_in_khz[0] * MEMORY_TYPE_MULTIPLIER, 1000);
975 dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
976 clks.clocks_in_khz[clks.num_levels>>1] * MEMORY_TYPE_MULTIPLIER,
978 dc->bw_vbios->high_yclk = bw_frc_to_fixed(
979 clks.clocks_in_khz[clks.num_levels-1] * MEMORY_TYPE_MULTIPLIER,
985 /* convert all the clock fro kHz to fix point mHz TODO: wloop data */
986 dc->bw_vbios->high_sclk = bw_frc_to_fixed(
987 eng_clks.data[eng_clks.num_levels-1].clocks_in_khz, 1000);
988 dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
989 eng_clks.data[eng_clks.num_levels/8].clocks_in_khz, 1000);
990 dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
991 eng_clks.data[eng_clks.num_levels*2/8].clocks_in_khz, 1000);
992 dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
993 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz, 1000);
994 dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
995 eng_clks.data[eng_clks.num_levels*4/8].clocks_in_khz, 1000);
996 dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
997 eng_clks.data[eng_clks.num_levels*5/8].clocks_in_khz, 1000);
998 dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
999 eng_clks.data[eng_clks.num_levels*6/8].clocks_in_khz, 1000);
1000 dc->bw_vbios->low_sclk = bw_frc_to_fixed(
1001 eng_clks.data[0].clocks_in_khz, 1000);
1004 dm_pp_get_clock_levels_by_type_with_latency(
1006 DM_PP_CLOCK_TYPE_MEMORY_CLK,
1009 /* we don't need to call PPLIB for validation clock since they
1010 * also give us the highest sclk and highest mclk (UMA clock).
1011 * ALSO always convert UMA clock (from PPLIB) to YCLK (HW formula):
1012 * YCLK = UMACLK*m_memoryTypeMultiplier
1014 dc->bw_vbios->low_yclk = bw_frc_to_fixed(
1015 mem_clks.data[0].clocks_in_khz * MEMORY_TYPE_MULTIPLIER, 1000);
1016 dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
1017 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz * MEMORY_TYPE_MULTIPLIER,
1019 dc->bw_vbios->high_yclk = bw_frc_to_fixed(
1020 mem_clks.data[mem_clks.num_levels-1].clocks_in_khz * MEMORY_TYPE_MULTIPLIER,
1023 /* Now notify PPLib/SMU about which Watermarks sets they should select
1024 * depending on DPM state they are in. And update BW MGR GFX Engine and
1025 * Memory clock member variables for Watermarks calculations for each
1028 clk_ranges.num_wm_sets = 4;
1029 clk_ranges.wm_clk_ranges[0].wm_set_id = WM_SET_A;
1030 clk_ranges.wm_clk_ranges[0].wm_min_eng_clk_in_khz =
1031 eng_clks.data[0].clocks_in_khz;
1032 clk_ranges.wm_clk_ranges[0].wm_max_eng_clk_in_khz =
1033 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz - 1;
1034 clk_ranges.wm_clk_ranges[0].wm_min_mem_clk_in_khz =
1035 mem_clks.data[0].clocks_in_khz;
1036 clk_ranges.wm_clk_ranges[0].wm_max_mem_clk_in_khz =
1037 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz - 1;
1039 clk_ranges.wm_clk_ranges[1].wm_set_id = WM_SET_B;
1040 clk_ranges.wm_clk_ranges[1].wm_min_eng_clk_in_khz =
1041 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz;
1042 /* 5 GHz instead of data[7].clockInKHz to cover Overdrive */
1043 clk_ranges.wm_clk_ranges[1].wm_max_eng_clk_in_khz = 5000000;
1044 clk_ranges.wm_clk_ranges[1].wm_min_mem_clk_in_khz =
1045 mem_clks.data[0].clocks_in_khz;
1046 clk_ranges.wm_clk_ranges[1].wm_max_mem_clk_in_khz =
1047 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz - 1;
1049 clk_ranges.wm_clk_ranges[2].wm_set_id = WM_SET_C;
1050 clk_ranges.wm_clk_ranges[2].wm_min_eng_clk_in_khz =
1051 eng_clks.data[0].clocks_in_khz;
1052 clk_ranges.wm_clk_ranges[2].wm_max_eng_clk_in_khz =
1053 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz - 1;
1054 clk_ranges.wm_clk_ranges[2].wm_min_mem_clk_in_khz =
1055 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz;
1056 /* 5 GHz instead of data[2].clockInKHz to cover Overdrive */
1057 clk_ranges.wm_clk_ranges[2].wm_max_mem_clk_in_khz = 5000000;
1059 clk_ranges.wm_clk_ranges[3].wm_set_id = WM_SET_D;
1060 clk_ranges.wm_clk_ranges[3].wm_min_eng_clk_in_khz =
1061 eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz;
1062 /* 5 GHz instead of data[7].clockInKHz to cover Overdrive */
1063 clk_ranges.wm_clk_ranges[3].wm_max_eng_clk_in_khz = 5000000;
1064 clk_ranges.wm_clk_ranges[3].wm_min_mem_clk_in_khz =
1065 mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz;
1066 /* 5 GHz instead of data[2].clockInKHz to cover Overdrive */
1067 clk_ranges.wm_clk_ranges[3].wm_max_mem_clk_in_khz = 5000000;
1069 /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
1070 dm_pp_notify_wm_clock_changes(dc->ctx, &clk_ranges);
1073 const struct resource_caps *dce112_resource_cap(
1074 struct hw_asic_id *asic_id)
1076 if (ASIC_REV_IS_POLARIS11_M(asic_id->hw_internal_rev) ||
1077 ASIC_REV_IS_POLARIS12_V(asic_id->hw_internal_rev))
1078 return &polaris_11_resource_cap;
1080 return &polaris_10_resource_cap;
1083 static bool construct(
1084 uint8_t num_virtual_links,
1086 struct dce110_resource_pool *pool)
1089 struct dc_context *ctx = dc->ctx;
1090 struct dm_pp_static_clock_info static_clk_info = {0};
1092 ctx->dc_bios->regs = &bios_regs;
1094 pool->base.res_cap = dce112_resource_cap(&ctx->asic_id);
1095 pool->base.funcs = &dce112_res_pool_funcs;
1097 /*************************************************
1098 * Resource + asic cap harcoding *
1099 *************************************************/
1100 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1101 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1102 pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
1103 dc->caps.max_downscale_ratio = 200;
1104 dc->caps.i2c_speed_in_khz = 100;
1105 dc->caps.max_cursor_size = 128;
1106 dc->caps.dual_link_dvi = true;
1109 /*************************************************
1110 * Create resources *
1111 *************************************************/
1113 pool->base.clock_sources[DCE112_CLK_SRC_PLL0] =
1114 dce112_clock_source_create(
1116 CLOCK_SOURCE_COMBO_PHY_PLL0,
1117 &clk_src_regs[0], false);
1118 pool->base.clock_sources[DCE112_CLK_SRC_PLL1] =
1119 dce112_clock_source_create(
1121 CLOCK_SOURCE_COMBO_PHY_PLL1,
1122 &clk_src_regs[1], false);
1123 pool->base.clock_sources[DCE112_CLK_SRC_PLL2] =
1124 dce112_clock_source_create(
1126 CLOCK_SOURCE_COMBO_PHY_PLL2,
1127 &clk_src_regs[2], false);
1128 pool->base.clock_sources[DCE112_CLK_SRC_PLL3] =
1129 dce112_clock_source_create(
1131 CLOCK_SOURCE_COMBO_PHY_PLL3,
1132 &clk_src_regs[3], false);
1133 pool->base.clock_sources[DCE112_CLK_SRC_PLL4] =
1134 dce112_clock_source_create(
1136 CLOCK_SOURCE_COMBO_PHY_PLL4,
1137 &clk_src_regs[4], false);
1138 pool->base.clock_sources[DCE112_CLK_SRC_PLL5] =
1139 dce112_clock_source_create(
1141 CLOCK_SOURCE_COMBO_PHY_PLL5,
1142 &clk_src_regs[5], false);
1143 pool->base.clk_src_count = DCE112_CLK_SRC_TOTAL;
1145 pool->base.dp_clock_source = dce112_clock_source_create(
1147 CLOCK_SOURCE_ID_DP_DTO, &clk_src_regs[0], true);
1150 for (i = 0; i < pool->base.clk_src_count; i++) {
1151 if (pool->base.clock_sources[i] == NULL) {
1152 dm_error("DC: failed to create clock sources!\n");
1153 BREAK_TO_DEBUGGER();
1154 goto res_create_fail;
1158 pool->base.dccg = dce112_dccg_create(ctx,
1162 if (pool->base.dccg == NULL) {
1163 dm_error("DC: failed to create display clock!\n");
1164 BREAK_TO_DEBUGGER();
1165 goto res_create_fail;
1168 pool->base.dmcu = dce_dmcu_create(ctx,
1172 if (pool->base.dmcu == NULL) {
1173 dm_error("DC: failed to create dmcu!\n");
1174 BREAK_TO_DEBUGGER();
1175 goto res_create_fail;
1178 pool->base.abm = dce_abm_create(ctx,
1182 if (pool->base.abm == NULL) {
1183 dm_error("DC: failed to create abm!\n");
1184 BREAK_TO_DEBUGGER();
1185 goto res_create_fail;
1188 /* get static clock information for PPLIB or firmware, save
1191 if (dm_pp_get_static_clocks(ctx, &static_clk_info))
1192 pool->base.dccg->max_clks_state =
1193 static_clk_info.max_clocks_state;
1196 struct irq_service_init_data init_data;
1197 init_data.ctx = dc->ctx;
1198 pool->base.irqs = dal_irq_service_dce110_create(&init_data);
1199 if (!pool->base.irqs)
1200 goto res_create_fail;
1203 for (i = 0; i < pool->base.pipe_count; i++) {
1204 pool->base.timing_generators[i] =
1205 dce112_timing_generator_create(
1208 &dce112_tg_offsets[i]);
1209 if (pool->base.timing_generators[i] == NULL) {
1210 BREAK_TO_DEBUGGER();
1211 dm_error("DC: failed to create tg!\n");
1212 goto res_create_fail;
1215 pool->base.mis[i] = dce112_mem_input_create(ctx, i);
1216 if (pool->base.mis[i] == NULL) {
1217 BREAK_TO_DEBUGGER();
1219 "DC: failed to create memory input!\n");
1220 goto res_create_fail;
1223 pool->base.ipps[i] = dce112_ipp_create(ctx, i);
1224 if (pool->base.ipps[i] == NULL) {
1225 BREAK_TO_DEBUGGER();
1227 "DC:failed to create input pixel processor!\n");
1228 goto res_create_fail;
1231 pool->base.transforms[i] = dce112_transform_create(ctx, i);
1232 if (pool->base.transforms[i] == NULL) {
1233 BREAK_TO_DEBUGGER();
1235 "DC: failed to create transform!\n");
1236 goto res_create_fail;
1239 pool->base.opps[i] = dce112_opp_create(
1242 if (pool->base.opps[i] == NULL) {
1243 BREAK_TO_DEBUGGER();
1245 "DC:failed to create output pixel processor!\n");
1246 goto res_create_fail;
1248 pool->base.engines[i] = dce112_aux_engine_create(ctx, i);
1249 if (pool->base.engines[i] == NULL) {
1250 BREAK_TO_DEBUGGER();
1252 "DC:failed to create aux engine!!\n");
1253 goto res_create_fail;
1257 if (!resource_construct(num_virtual_links, dc, &pool->base,
1259 goto res_create_fail;
1261 dc->caps.max_planes = pool->base.pipe_count;
1263 /* Create hardware sequencer */
1264 dce112_hw_sequencer_construct(dc);
1266 bw_calcs_init(dc->bw_dceip, dc->bw_vbios, dc->ctx->asic_id);
1268 bw_calcs_data_update_from_pplib(dc);
1277 struct resource_pool *dce112_create_resource_pool(
1278 uint8_t num_virtual_links,
1281 struct dce110_resource_pool *pool =
1282 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1287 if (construct(num_virtual_links, dc, pool))
1290 BREAK_TO_DEBUGGER();