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 <linux/slab.h>
28 #include "dm_services.h"
30 #include "link_encoder.h"
31 #include "stream_encoder.h"
34 #include "include/irq_service_interface.h"
35 #include "../virtual/virtual_stream_encoder.h"
36 #include "dce110/dce110_resource.h"
37 #include "dce110/dce110_timing_generator.h"
38 #include "irq/dce110/irq_service_dce110.h"
39 #include "dce/dce_link_encoder.h"
40 #include "dce/dce_stream_encoder.h"
41 #include "dce/dce_mem_input.h"
42 #include "dce/dce_ipp.h"
43 #include "dce/dce_transform.h"
44 #include "dce/dce_opp.h"
45 #include "dce/dce_clock_source.h"
46 #include "dce/dce_audio.h"
47 #include "dce/dce_hwseq.h"
48 #include "dce100/dce100_hw_sequencer.h"
50 #include "reg_helper.h"
52 #include "dce/dce_10_0_d.h"
53 #include "dce/dce_10_0_sh_mask.h"
55 #include "dce/dce_dmcu.h"
56 #include "dce/dce_aux.h"
57 #include "dce/dce_abm.h"
58 #include "dce/dce_i2c.h"
60 #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
61 #include "gmc/gmc_8_2_d.h"
62 #include "gmc/gmc_8_2_sh_mask.h"
65 #ifndef mmDP_DPHY_INTERNAL_CTRL
66 #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
67 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
68 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
69 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
70 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
71 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
72 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
73 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
74 #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
75 #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
78 #ifndef mmBIOS_SCRATCH_2
79 #define mmBIOS_SCRATCH_2 0x05CB
80 #define mmBIOS_SCRATCH_3 0x05CC
81 #define mmBIOS_SCRATCH_6 0x05CF
84 #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
85 #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
86 #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
87 #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
88 #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
89 #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
90 #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
91 #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
92 #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
95 #ifndef mmDP_DPHY_FAST_TRAINING
96 #define mmDP_DPHY_FAST_TRAINING 0x4ABC
97 #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
98 #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
99 #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
100 #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
101 #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
102 #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
103 #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
106 static const struct dce110_timing_generator_offsets dce100_tg_offsets[] = {
108 .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
109 .dcp = (mmDCP0_GRPH_CONTROL - mmGRPH_CONTROL),
112 .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
113 .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
116 .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
117 .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
120 .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
121 .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
124 .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
125 .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
128 .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
129 .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
133 /* set register offset */
134 #define SR(reg_name)\
135 .reg_name = mm ## reg_name
137 /* set register offset with instance */
138 #define SRI(reg_name, block, id)\
139 .reg_name = mm ## block ## id ## _ ## reg_name
141 #define ipp_regs(id)\
143 IPP_DCE100_REG_LIST_DCE_BASE(id)\
146 static const struct dce_ipp_registers ipp_regs[] = {
155 static const struct dce_ipp_shift ipp_shift = {
156 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
159 static const struct dce_ipp_mask ipp_mask = {
160 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
163 #define transform_regs(id)\
165 XFM_COMMON_REG_LIST_DCE100(id)\
168 static const struct dce_transform_registers xfm_regs[] = {
177 static const struct dce_transform_shift xfm_shift = {
178 XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
181 static const struct dce_transform_mask xfm_mask = {
182 XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
185 #define aux_regs(id)\
190 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
199 #define hpd_regs(id)\
204 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
213 #define link_regs(id)\
215 LE_DCE100_REG_LIST(id)\
218 static const struct dce110_link_enc_registers link_enc_regs[] = {
228 #define stream_enc_regs(id)\
230 SE_COMMON_REG_LIST_DCE_BASE(id),\
234 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
244 static const struct dce_stream_encoder_shift se_shift = {
245 SE_COMMON_MASK_SH_LIST_DCE80_100(__SHIFT)
248 static const struct dce_stream_encoder_mask se_mask = {
249 SE_COMMON_MASK_SH_LIST_DCE80_100(_MASK)
252 #define opp_regs(id)\
254 OPP_DCE_100_REG_LIST(id),\
257 static const struct dce_opp_registers opp_regs[] = {
266 static const struct dce_opp_shift opp_shift = {
267 OPP_COMMON_MASK_SH_LIST_DCE_100(__SHIFT)
270 static const struct dce_opp_mask opp_mask = {
271 OPP_COMMON_MASK_SH_LIST_DCE_100(_MASK)
273 #define aux_engine_regs(id)\
275 AUX_COMMON_REG_LIST(id), \
276 .AUX_RESET_MASK = 0 \
279 static const struct dce110_aux_registers aux_engine_regs[] = {
288 #define audio_regs(id)\
290 AUD_COMMON_REG_LIST(id)\
293 static const struct dce_audio_registers audio_regs[] = {
303 static const struct dce_audio_shift audio_shift = {
304 AUD_COMMON_MASK_SH_LIST(__SHIFT)
307 static const struct dce_aduio_mask audio_mask = {
308 AUD_COMMON_MASK_SH_LIST(_MASK)
311 #define clk_src_regs(id)\
313 CS_COMMON_REG_LIST_DCE_100_110(id),\
316 static const struct dce110_clk_src_regs clk_src_regs[] = {
322 static const struct dce110_clk_src_shift cs_shift = {
323 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
326 static const struct dce110_clk_src_mask cs_mask = {
327 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
330 static const struct dce_dmcu_registers dmcu_regs = {
331 DMCU_DCE110_COMMON_REG_LIST()
334 static const struct dce_dmcu_shift dmcu_shift = {
335 DMCU_MASK_SH_LIST_DCE110(__SHIFT)
338 static const struct dce_dmcu_mask dmcu_mask = {
339 DMCU_MASK_SH_LIST_DCE110(_MASK)
342 static const struct dce_abm_registers abm_regs = {
343 ABM_DCE110_COMMON_REG_LIST()
346 static const struct dce_abm_shift abm_shift = {
347 ABM_MASK_SH_LIST_DCE110(__SHIFT)
350 static const struct dce_abm_mask abm_mask = {
351 ABM_MASK_SH_LIST_DCE110(_MASK)
354 #define DCFE_MEM_PWR_CTRL_REG_BASE 0x1b03
356 static const struct bios_registers bios_regs = {
357 .BIOS_SCRATCH_3 = mmBIOS_SCRATCH_3,
358 .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
361 static const struct resource_caps res_cap = {
362 .num_timing_generator = 6,
364 .num_stream_encoder = 6,
369 static const struct dc_plane_cap plane_cap = {
370 .type = DC_PLANE_TYPE_DCE_RGB,
372 .pixel_format_support = {
378 .max_upscale_factor = {
384 .max_downscale_factor = {
392 #define REG(reg) mm ## reg
394 #ifndef mmCC_DC_HDMI_STRAPS
395 #define mmCC_DC_HDMI_STRAPS 0x1918
396 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
397 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
398 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
399 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
402 static void read_dce_straps(
403 struct dc_context *ctx,
404 struct resource_straps *straps)
406 REG_GET_2(CC_DC_HDMI_STRAPS,
407 HDMI_DISABLE, &straps->hdmi_disable,
408 AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
410 REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
413 static struct audio *create_audio(
414 struct dc_context *ctx, unsigned int inst)
416 return dce_audio_create(ctx, inst,
417 &audio_regs[inst], &audio_shift, &audio_mask);
420 static struct timing_generator *dce100_timing_generator_create(
421 struct dc_context *ctx,
423 const struct dce110_timing_generator_offsets *offsets)
425 struct dce110_timing_generator *tg110 =
426 kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
431 dce110_timing_generator_construct(tg110, ctx, instance, offsets);
435 static struct stream_encoder *dce100_stream_encoder_create(
436 enum engine_id eng_id,
437 struct dc_context *ctx)
439 struct dce110_stream_encoder *enc110 =
440 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
445 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
446 &stream_enc_regs[eng_id], &se_shift, &se_mask);
447 return &enc110->base;
450 #define SRII(reg_name, block, id)\
451 .reg_name[id] = mm ## block ## id ## _ ## reg_name
453 static const struct dce_hwseq_registers hwseq_reg = {
454 HWSEQ_DCE10_REG_LIST()
457 static const struct dce_hwseq_shift hwseq_shift = {
458 HWSEQ_DCE10_MASK_SH_LIST(__SHIFT)
461 static const struct dce_hwseq_mask hwseq_mask = {
462 HWSEQ_DCE10_MASK_SH_LIST(_MASK)
465 static struct dce_hwseq *dce100_hwseq_create(
466 struct dc_context *ctx)
468 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
472 hws->regs = &hwseq_reg;
473 hws->shifts = &hwseq_shift;
474 hws->masks = &hwseq_mask;
479 static const struct resource_create_funcs res_create_funcs = {
480 .read_dce_straps = read_dce_straps,
481 .create_audio = create_audio,
482 .create_stream_encoder = dce100_stream_encoder_create,
483 .create_hwseq = dce100_hwseq_create,
486 #define mi_inst_regs(id) { \
487 MI_DCE8_REG_LIST(id), \
488 .MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
490 static const struct dce_mem_input_registers mi_regs[] = {
499 static const struct dce_mem_input_shift mi_shifts = {
500 MI_DCE8_MASK_SH_LIST(__SHIFT),
501 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
504 static const struct dce_mem_input_mask mi_masks = {
505 MI_DCE8_MASK_SH_LIST(_MASK),
506 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
509 static struct mem_input *dce100_mem_input_create(
510 struct dc_context *ctx,
513 struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
521 dce_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
522 dce_mi->wa.single_head_rdreq_dmif_limit = 2;
523 return &dce_mi->base;
526 static void dce100_transform_destroy(struct transform **xfm)
528 kfree(TO_DCE_TRANSFORM(*xfm));
532 static struct transform *dce100_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 return &transform->base;
547 static struct input_pixel_processor *dce100_ipp_create(
548 struct dc_context *ctx, uint32_t inst)
550 struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
557 dce_ipp_construct(ipp, ctx, inst,
558 &ipp_regs[inst], &ipp_shift, &ipp_mask);
562 static const struct encoder_feature_support link_enc_feature = {
563 .max_hdmi_deep_color = COLOR_DEPTH_121212,
564 .max_hdmi_pixel_clock = 300000,
565 .flags.bits.IS_HBR2_CAPABLE = true,
566 .flags.bits.IS_TPS3_CAPABLE = true
569 struct link_encoder *dce100_link_encoder_create(
570 const struct encoder_init_data *enc_init_data)
572 struct dce110_link_encoder *enc110 =
573 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
578 dce110_link_encoder_construct(enc110,
581 &link_enc_regs[enc_init_data->transmitter],
582 &link_enc_aux_regs[enc_init_data->channel - 1],
583 &link_enc_hpd_regs[enc_init_data->hpd_source]);
584 return &enc110->base;
587 struct output_pixel_processor *dce100_opp_create(
588 struct dc_context *ctx,
591 struct dce110_opp *opp =
592 kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
597 dce110_opp_construct(opp,
598 ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
602 struct dce_aux *dce100_aux_engine_create(
603 struct dc_context *ctx,
606 struct aux_engine_dce110 *aux_engine =
607 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
612 dce110_aux_engine_construct(aux_engine, ctx, inst,
613 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
614 &aux_engine_regs[inst]);
616 return &aux_engine->base;
618 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
620 static const struct dce_i2c_registers i2c_hw_regs[] = {
629 static const struct dce_i2c_shift i2c_shifts = {
630 I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
633 static const struct dce_i2c_mask i2c_masks = {
634 I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
637 struct dce_i2c_hw *dce100_i2c_hw_create(
638 struct dc_context *ctx,
641 struct dce_i2c_hw *dce_i2c_hw =
642 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
647 dce100_i2c_hw_construct(dce_i2c_hw, ctx, inst,
648 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
652 struct clock_source *dce100_clock_source_create(
653 struct dc_context *ctx,
654 struct dc_bios *bios,
655 enum clock_source_id id,
656 const struct dce110_clk_src_regs *regs,
659 struct dce110_clk_src *clk_src =
660 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
665 if (dce110_clk_src_construct(clk_src, ctx, bios, id,
666 regs, &cs_shift, &cs_mask)) {
667 clk_src->base.dp_clk_src = dp_clk_src;
668 return &clk_src->base;
676 void dce100_clock_source_destroy(struct clock_source **clk_src)
678 kfree(TO_DCE110_CLK_SRC(*clk_src));
682 static void destruct(struct dce110_resource_pool *pool)
686 for (i = 0; i < pool->base.pipe_count; i++) {
687 if (pool->base.opps[i] != NULL)
688 dce110_opp_destroy(&pool->base.opps[i]);
690 if (pool->base.transforms[i] != NULL)
691 dce100_transform_destroy(&pool->base.transforms[i]);
693 if (pool->base.ipps[i] != NULL)
694 dce_ipp_destroy(&pool->base.ipps[i]);
696 if (pool->base.mis[i] != NULL) {
697 kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
698 pool->base.mis[i] = NULL;
701 if (pool->base.timing_generators[i] != NULL) {
702 kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
703 pool->base.timing_generators[i] = NULL;
707 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
708 if (pool->base.engines[i] != NULL)
709 dce110_engine_destroy(&pool->base.engines[i]);
710 if (pool->base.hw_i2cs[i] != NULL) {
711 kfree(pool->base.hw_i2cs[i]);
712 pool->base.hw_i2cs[i] = NULL;
714 if (pool->base.sw_i2cs[i] != NULL) {
715 kfree(pool->base.sw_i2cs[i]);
716 pool->base.sw_i2cs[i] = NULL;
720 for (i = 0; i < pool->base.stream_enc_count; i++) {
721 if (pool->base.stream_enc[i] != NULL)
722 kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
725 for (i = 0; i < pool->base.clk_src_count; i++) {
726 if (pool->base.clock_sources[i] != NULL)
727 dce100_clock_source_destroy(&pool->base.clock_sources[i]);
730 if (pool->base.dp_clock_source != NULL)
731 dce100_clock_source_destroy(&pool->base.dp_clock_source);
733 for (i = 0; i < pool->base.audio_count; i++) {
734 if (pool->base.audios[i] != NULL)
735 dce_aud_destroy(&pool->base.audios[i]);
738 if (pool->base.abm != NULL)
739 dce_abm_destroy(&pool->base.abm);
741 if (pool->base.dmcu != NULL)
742 dce_dmcu_destroy(&pool->base.dmcu);
744 if (pool->base.irqs != NULL)
745 dal_irq_service_destroy(&pool->base.irqs);
748 static enum dc_status build_mapped_resource(
750 struct dc_state *context,
751 struct dc_stream_state *stream)
753 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
756 return DC_ERROR_UNEXPECTED;
758 dce110_resource_build_pipe_hw_param(pipe_ctx);
760 resource_build_info_frame(pipe_ctx);
765 bool dce100_validate_bandwidth(
767 struct dc_state *context,
771 bool at_least_one_pipe = false;
773 for (i = 0; i < dc->res_pool->pipe_count; i++) {
774 if (context->res_ctx.pipe_ctx[i].stream)
775 at_least_one_pipe = true;
778 if (at_least_one_pipe) {
779 /* TODO implement when needed but for now hardcode max value*/
780 context->bw_ctx.bw.dce.dispclk_khz = 681000;
781 context->bw_ctx.bw.dce.yclk_khz = 250000 * MEMORY_TYPE_MULTIPLIER_CZ;
783 context->bw_ctx.bw.dce.dispclk_khz = 0;
784 context->bw_ctx.bw.dce.yclk_khz = 0;
790 static bool dce100_validate_surface_sets(
791 struct dc_state *context)
795 for (i = 0; i < context->stream_count; i++) {
796 if (context->stream_status[i].plane_count == 0)
799 if (context->stream_status[i].plane_count > 1)
802 if (context->stream_status[i].plane_states[0]->format
803 >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
810 enum dc_status dce100_validate_global(
812 struct dc_state *context)
814 if (!dce100_validate_surface_sets(context))
815 return DC_FAIL_SURFACE_VALIDATE;
820 enum dc_status dce100_add_stream_to_ctx(
822 struct dc_state *new_ctx,
823 struct dc_stream_state *dc_stream)
825 enum dc_status result = DC_ERROR_UNEXPECTED;
827 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
830 result = resource_map_clock_resources(dc, new_ctx, dc_stream);
833 result = build_mapped_resource(dc, new_ctx, dc_stream);
838 static void dce100_destroy_resource_pool(struct resource_pool **pool)
840 struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
842 destruct(dce110_pool);
847 enum dc_status dce100_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
850 if (plane_state->format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
853 return DC_FAIL_SURFACE_VALIDATE;
856 struct stream_encoder *dce100_find_first_free_match_stream_enc_for_link(
857 struct resource_context *res_ctx,
858 const struct resource_pool *pool,
859 struct dc_stream_state *stream)
863 struct dc_link *link = stream->link;
865 for (i = 0; i < pool->stream_enc_count; i++) {
866 if (!res_ctx->is_stream_enc_acquired[i] &&
867 pool->stream_enc[i]) {
868 /* Store first available for MST second display
869 * in daisy chain use case
872 if (pool->stream_enc[i]->id ==
873 link->link_enc->preferred_engine)
874 return pool->stream_enc[i];
879 * below can happen in cases when stream encoder is acquired:
880 * 1) for second MST display in chain, so preferred engine already
882 * 2) for another link, which preferred engine already acquired by any
885 * If signal is of DP type and preferred engine not found, return last available
887 * TODO - This is just a patch up and a generic solution is
888 * required for non DP connectors.
891 if (j >= 0 && link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT)
892 return pool->stream_enc[j];
897 static const struct resource_funcs dce100_res_pool_funcs = {
898 .destroy = dce100_destroy_resource_pool,
899 .link_enc_create = dce100_link_encoder_create,
900 .validate_bandwidth = dce100_validate_bandwidth,
901 .validate_plane = dce100_validate_plane,
902 .add_stream_to_ctx = dce100_add_stream_to_ctx,
903 .validate_global = dce100_validate_global,
904 .find_first_free_match_stream_enc_for_link = dce100_find_first_free_match_stream_enc_for_link
907 static bool construct(
908 uint8_t num_virtual_links,
910 struct dce110_resource_pool *pool)
913 struct dc_context *ctx = dc->ctx;
914 struct dc_firmware_info info;
917 ctx->dc_bios->regs = &bios_regs;
919 pool->base.res_cap = &res_cap;
920 pool->base.funcs = &dce100_res_pool_funcs;
921 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
925 if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
926 info.external_clock_source_frequency_for_dp != 0) {
927 pool->base.dp_clock_source =
928 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
930 pool->base.clock_sources[0] =
931 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
932 pool->base.clock_sources[1] =
933 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
934 pool->base.clock_sources[2] =
935 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
936 pool->base.clk_src_count = 3;
939 pool->base.dp_clock_source =
940 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
942 pool->base.clock_sources[0] =
943 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
944 pool->base.clock_sources[1] =
945 dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
946 pool->base.clk_src_count = 2;
949 if (pool->base.dp_clock_source == NULL) {
950 dm_error("DC: failed to create dp clock source!\n");
952 goto res_create_fail;
955 for (i = 0; i < pool->base.clk_src_count; i++) {
956 if (pool->base.clock_sources[i] == NULL) {
957 dm_error("DC: failed to create clock sources!\n");
959 goto res_create_fail;
963 pool->base.dmcu = dce_dmcu_create(ctx,
967 if (pool->base.dmcu == NULL) {
968 dm_error("DC: failed to create dmcu!\n");
970 goto res_create_fail;
973 pool->base.abm = dce_abm_create(ctx,
977 if (pool->base.abm == NULL) {
978 dm_error("DC: failed to create abm!\n");
980 goto res_create_fail;
984 struct irq_service_init_data init_data;
985 init_data.ctx = dc->ctx;
986 pool->base.irqs = dal_irq_service_dce110_create(&init_data);
987 if (!pool->base.irqs)
988 goto res_create_fail;
991 /*************************************************
992 * Resource + asic cap harcoding *
993 *************************************************/
994 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
995 pool->base.pipe_count = res_cap.num_timing_generator;
996 pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
997 dc->caps.max_downscale_ratio = 200;
998 dc->caps.i2c_speed_in_khz = 40;
999 dc->caps.max_cursor_size = 128;
1000 dc->caps.dual_link_dvi = true;
1001 dc->caps.disable_dp_clk_share = true;
1002 for (i = 0; i < pool->base.pipe_count; i++) {
1003 pool->base.timing_generators[i] =
1004 dce100_timing_generator_create(
1007 &dce100_tg_offsets[i]);
1008 if (pool->base.timing_generators[i] == NULL) {
1009 BREAK_TO_DEBUGGER();
1010 dm_error("DC: failed to create tg!\n");
1011 goto res_create_fail;
1014 pool->base.mis[i] = dce100_mem_input_create(ctx, i);
1015 if (pool->base.mis[i] == NULL) {
1016 BREAK_TO_DEBUGGER();
1018 "DC: failed to create memory input!\n");
1019 goto res_create_fail;
1022 pool->base.ipps[i] = dce100_ipp_create(ctx, i);
1023 if (pool->base.ipps[i] == NULL) {
1024 BREAK_TO_DEBUGGER();
1026 "DC: failed to create input pixel processor!\n");
1027 goto res_create_fail;
1030 pool->base.transforms[i] = dce100_transform_create(ctx, i);
1031 if (pool->base.transforms[i] == NULL) {
1032 BREAK_TO_DEBUGGER();
1034 "DC: failed to create transform!\n");
1035 goto res_create_fail;
1038 pool->base.opps[i] = dce100_opp_create(ctx, i);
1039 if (pool->base.opps[i] == NULL) {
1040 BREAK_TO_DEBUGGER();
1042 "DC: failed to create output pixel processor!\n");
1043 goto res_create_fail;
1047 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1048 pool->base.engines[i] = dce100_aux_engine_create(ctx, i);
1049 if (pool->base.engines[i] == NULL) {
1050 BREAK_TO_DEBUGGER();
1052 "DC:failed to create aux engine!!\n");
1053 goto res_create_fail;
1055 pool->base.hw_i2cs[i] = dce100_i2c_hw_create(ctx, i);
1056 if (pool->base.hw_i2cs[i] == NULL) {
1057 BREAK_TO_DEBUGGER();
1059 "DC:failed to create i2c engine!!\n");
1060 goto res_create_fail;
1062 pool->base.sw_i2cs[i] = NULL;
1065 dc->caps.max_planes = pool->base.pipe_count;
1067 for (i = 0; i < dc->caps.max_planes; ++i)
1068 dc->caps.planes[i] = plane_cap;
1070 if (!resource_construct(num_virtual_links, dc, &pool->base,
1072 goto res_create_fail;
1074 /* Create hardware sequencer */
1075 dce100_hw_sequencer_construct(dc);
1084 struct resource_pool *dce100_create_resource_pool(
1085 uint8_t num_virtual_links,
1088 struct dce110_resource_pool *pool =
1089 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1094 if (construct(num_virtual_links, dc, pool))
1097 BREAK_TO_DEBUGGER();