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 "dce110/dce110_resource.h"
34 #include "include/irq_service_interface.h"
35 #include "dce/dce_audio.h"
36 #include "dce110/dce110_timing_generator.h"
37 #include "irq/dce110/irq_service_dce110.h"
38 #include "dce110/dce110_timing_generator_v.h"
39 #include "dce/dce_link_encoder.h"
40 #include "dce/dce_stream_encoder.h"
41 #include "dce/dce_mem_input.h"
42 #include "dce110/dce110_mem_input_v.h"
43 #include "dce/dce_ipp.h"
44 #include "dce/dce_transform.h"
45 #include "dce110/dce110_transform_v.h"
46 #include "dce/dce_opp.h"
47 #include "dce110/dce110_opp_v.h"
48 #include "dce/dce_clocks.h"
49 #include "dce/dce_clock_source.h"
50 #include "dce/dce_hwseq.h"
51 #include "dce110/dce110_hw_sequencer.h"
52 #include "dce/dce_aux.h"
53 #include "dce/dce_abm.h"
54 #include "dce/dce_dmcu.h"
59 #include "dce110/dce110_compressor.h"
61 #include "reg_helper.h"
63 #include "dce/dce_11_0_d.h"
64 #include "dce/dce_11_0_sh_mask.h"
66 #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
67 #include "gmc/gmc_8_2_d.h"
68 #include "gmc/gmc_8_2_sh_mask.h"
71 #ifndef mmDP_DPHY_INTERNAL_CTRL
72 #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
73 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
74 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
75 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
76 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
77 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
78 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
79 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
80 #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
81 #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
84 #ifndef mmBIOS_SCRATCH_2
85 #define mmBIOS_SCRATCH_2 0x05CB
86 #define mmBIOS_SCRATCH_6 0x05CF
89 #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
90 #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
91 #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
92 #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
93 #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
94 #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
95 #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
96 #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
97 #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
100 #ifndef mmDP_DPHY_FAST_TRAINING
101 #define mmDP_DPHY_FAST_TRAINING 0x4ABC
102 #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
103 #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
104 #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
105 #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
106 #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
107 #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
108 #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
111 #ifndef DPHY_RX_FAST_TRAINING_CAPABLE
112 #define DPHY_RX_FAST_TRAINING_CAPABLE 0x1
115 static const struct dce110_timing_generator_offsets dce110_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
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[] = {
197 static const struct dce_ipp_shift ipp_shift = {
198 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
201 static const struct dce_ipp_mask ipp_mask = {
202 IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
205 #define transform_regs(id)\
207 XFM_COMMON_REG_LIST_DCE110(id)\
210 static const struct dce_transform_registers xfm_regs[] = {
216 static const struct dce_transform_shift xfm_shift = {
217 XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
220 static const struct dce_transform_mask xfm_mask = {
221 XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
224 #define aux_regs(id)\
229 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
238 #define hpd_regs(id)\
243 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
253 #define link_regs(id)\
255 LE_DCE110_REG_LIST(id)\
258 static const struct dce110_link_enc_registers link_enc_regs[] = {
268 #define stream_enc_regs(id)\
270 SE_COMMON_REG_LIST(id),\
274 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
280 static const struct dce_stream_encoder_shift se_shift = {
281 SE_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
284 static const struct dce_stream_encoder_mask se_mask = {
285 SE_COMMON_MASK_SH_LIST_DCE110(_MASK)
288 #define opp_regs(id)\
290 OPP_DCE_110_REG_LIST(id),\
293 static const struct dce_opp_registers opp_regs[] = {
302 static const struct dce_opp_shift opp_shift = {
303 OPP_COMMON_MASK_SH_LIST_DCE_110(__SHIFT)
306 static const struct dce_opp_mask opp_mask = {
307 OPP_COMMON_MASK_SH_LIST_DCE_110(_MASK)
310 #define aux_engine_regs(id)\
312 AUX_COMMON_REG_LIST(id), \
313 .AUX_RESET_MASK = 0 \
316 static const struct dce110_aux_registers aux_engine_regs[] = {
325 #define audio_regs(id)\
327 AUD_COMMON_REG_LIST(id)\
330 static const struct dce_audio_registers audio_regs[] = {
340 static const struct dce_audio_shift audio_shift = {
341 AUD_COMMON_MASK_SH_LIST(__SHIFT)
344 static const struct dce_aduio_mask audio_mask = {
345 AUD_COMMON_MASK_SH_LIST(_MASK)
348 /* AG TBD Needs to be reduced back to 3 pipes once dce10 hw sequencer implemented. */
351 #define clk_src_regs(id)\
353 CS_COMMON_REG_LIST_DCE_100_110(id),\
356 static const struct dce110_clk_src_regs clk_src_regs[] = {
362 static const struct dce110_clk_src_shift cs_shift = {
363 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
366 static const struct dce110_clk_src_mask cs_mask = {
367 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
370 static const struct bios_registers bios_regs = {
371 .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
374 static const struct resource_caps carrizo_resource_cap = {
375 .num_timing_generator = 3,
376 .num_video_plane = 1,
378 .num_stream_encoder = 3,
382 static const struct resource_caps stoney_resource_cap = {
383 .num_timing_generator = 2,
384 .num_video_plane = 1,
386 .num_stream_encoder = 3,
391 #define REG(reg) mm ## reg
393 #ifndef mmCC_DC_HDMI_STRAPS
394 #define mmCC_DC_HDMI_STRAPS 0x4819
395 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
396 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
397 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
398 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
401 static void read_dce_straps(
402 struct dc_context *ctx,
403 struct resource_straps *straps)
405 REG_GET_2(CC_DC_HDMI_STRAPS,
406 HDMI_DISABLE, &straps->hdmi_disable,
407 AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
409 REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
412 static struct audio *create_audio(
413 struct dc_context *ctx, unsigned int inst)
415 return dce_audio_create(ctx, inst,
416 &audio_regs[inst], &audio_shift, &audio_mask);
419 static struct timing_generator *dce110_timing_generator_create(
420 struct dc_context *ctx,
422 const struct dce110_timing_generator_offsets *offsets)
424 struct dce110_timing_generator *tg110 =
425 kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
430 dce110_timing_generator_construct(tg110, ctx, instance, offsets);
434 static struct stream_encoder *dce110_stream_encoder_create(
435 enum engine_id eng_id,
436 struct dc_context *ctx)
438 struct dce110_stream_encoder *enc110 =
439 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
444 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
445 &stream_enc_regs[eng_id],
446 &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_stoney_reg = {
457 static const struct dce_hwseq_registers hwseq_cz_reg = {
461 static const struct dce_hwseq_shift hwseq_shift = {
462 HWSEQ_DCE11_MASK_SH_LIST(__SHIFT),
465 static const struct dce_hwseq_mask hwseq_mask = {
466 HWSEQ_DCE11_MASK_SH_LIST(_MASK),
469 static struct dce_hwseq *dce110_hwseq_create(
470 struct dc_context *ctx)
472 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
476 hws->regs = ASIC_REV_IS_STONEY(ctx->asic_id.hw_internal_rev) ?
477 &hwseq_stoney_reg : &hwseq_cz_reg;
478 hws->shifts = &hwseq_shift;
479 hws->masks = &hwseq_mask;
480 hws->wa.blnd_crtc_trigger = true;
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 = dce110_stream_encoder_create,
489 .create_hwseq = dce110_hwseq_create,
492 #define mi_inst_regs(id) { \
493 MI_DCE11_REG_LIST(id), \
494 .MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
496 static const struct dce_mem_input_registers mi_regs[] = {
502 static const struct dce_mem_input_shift mi_shifts = {
503 MI_DCE11_MASK_SH_LIST(__SHIFT),
504 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
507 static const struct dce_mem_input_mask mi_masks = {
508 MI_DCE11_MASK_SH_LIST(_MASK),
509 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
513 static struct mem_input *dce110_mem_input_create(
514 struct dc_context *ctx,
517 struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
525 dce_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
526 dce_mi->wa.single_head_rdreq_dmif_limit = 3;
527 return &dce_mi->base;
530 static void dce110_transform_destroy(struct transform **xfm)
532 kfree(TO_DCE_TRANSFORM(*xfm));
536 static struct transform *dce110_transform_create(
537 struct dc_context *ctx,
540 struct dce_transform *transform =
541 kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
546 dce_transform_construct(transform, ctx, inst,
547 &xfm_regs[inst], &xfm_shift, &xfm_mask);
548 return &transform->base;
551 static struct input_pixel_processor *dce110_ipp_create(
552 struct dc_context *ctx, uint32_t inst)
554 struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
561 dce_ipp_construct(ipp, ctx, inst,
562 &ipp_regs[inst], &ipp_shift, &ipp_mask);
566 static const struct encoder_feature_support link_enc_feature = {
567 .max_hdmi_deep_color = COLOR_DEPTH_121212,
568 .max_hdmi_pixel_clock = 594000,
569 .flags.bits.IS_HBR2_CAPABLE = true,
570 .flags.bits.IS_TPS3_CAPABLE = true,
571 .flags.bits.IS_YCBCR_CAPABLE = true
574 static struct link_encoder *dce110_link_encoder_create(
575 const struct encoder_init_data *enc_init_data)
577 struct dce110_link_encoder *enc110 =
578 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
583 dce110_link_encoder_construct(enc110,
586 &link_enc_regs[enc_init_data->transmitter],
587 &link_enc_aux_regs[enc_init_data->channel - 1],
588 &link_enc_hpd_regs[enc_init_data->hpd_source]);
589 return &enc110->base;
592 static struct output_pixel_processor *dce110_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 *dce110_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 *dce110_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 dce110_clock_source_destroy(struct clock_source **clk_src)
649 struct dce110_clk_src *dce110_clk_src;
654 dce110_clk_src = TO_DCE110_CLK_SRC(*clk_src);
656 kfree(dce110_clk_src->dp_ss_params);
657 kfree(dce110_clk_src->hdmi_ss_params);
658 kfree(dce110_clk_src->dvi_ss_params);
660 kfree(dce110_clk_src);
664 static void destruct(struct dce110_resource_pool *pool)
668 for (i = 0; i < pool->base.pipe_count; i++) {
669 if (pool->base.opps[i] != NULL)
670 dce110_opp_destroy(&pool->base.opps[i]);
672 if (pool->base.transforms[i] != NULL)
673 dce110_transform_destroy(&pool->base.transforms[i]);
675 if (pool->base.ipps[i] != NULL)
676 dce_ipp_destroy(&pool->base.ipps[i]);
678 if (pool->base.mis[i] != NULL) {
679 kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
680 pool->base.mis[i] = NULL;
683 if (pool->base.timing_generators[i] != NULL) {
684 kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
685 pool->base.timing_generators[i] = NULL;
688 if (pool->base.engines[i] != NULL)
689 dce110_engine_destroy(&pool->base.engines[i]);
693 for (i = 0; i < pool->base.stream_enc_count; i++) {
694 if (pool->base.stream_enc[i] != NULL)
695 kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
698 for (i = 0; i < pool->base.clk_src_count; i++) {
699 if (pool->base.clock_sources[i] != NULL) {
700 dce110_clock_source_destroy(&pool->base.clock_sources[i]);
704 if (pool->base.dp_clock_source != NULL)
705 dce110_clock_source_destroy(&pool->base.dp_clock_source);
707 for (i = 0; i < pool->base.audio_count; i++) {
708 if (pool->base.audios[i] != NULL) {
709 dce_aud_destroy(&pool->base.audios[i]);
713 if (pool->base.abm != NULL)
714 dce_abm_destroy(&pool->base.abm);
716 if (pool->base.dmcu != NULL)
717 dce_dmcu_destroy(&pool->base.dmcu);
719 if (pool->base.dccg != NULL)
720 dce_dccg_destroy(&pool->base.dccg);
722 if (pool->base.irqs != NULL) {
723 dal_irq_service_destroy(&pool->base.irqs);
728 static void get_pixel_clock_parameters(
729 const struct pipe_ctx *pipe_ctx,
730 struct pixel_clk_params *pixel_clk_params)
732 const struct dc_stream_state *stream = pipe_ctx->stream;
734 /*TODO: is this halved for YCbCr 420? in that case we might want to move
735 * the pixel clock normalization for hdmi up to here instead of doing it
736 * in pll_adjust_pix_clk
738 pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
739 pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
740 pixel_clk_params->signal_type = pipe_ctx->stream->signal;
741 pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
742 /* TODO: un-hardcode*/
743 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
744 LINK_RATE_REF_FREQ_IN_KHZ;
745 pixel_clk_params->flags.ENABLE_SS = 0;
746 pixel_clk_params->color_depth =
747 stream->timing.display_color_depth;
748 pixel_clk_params->flags.DISPLAY_BLANKED = 1;
749 pixel_clk_params->flags.SUPPORT_YCBCR420 = (stream->timing.pixel_encoding ==
750 PIXEL_ENCODING_YCBCR420);
751 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
752 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) {
753 pixel_clk_params->color_depth = COLOR_DEPTH_888;
755 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
756 pixel_clk_params->requested_pix_clk = pixel_clk_params->requested_pix_clk / 2;
760 void dce110_resource_build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
762 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
763 pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
764 pipe_ctx->clock_source,
765 &pipe_ctx->stream_res.pix_clk_params,
766 &pipe_ctx->pll_settings);
767 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
768 &pipe_ctx->stream->bit_depth_params);
769 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
772 static bool is_surface_pixel_format_supported(struct pipe_ctx *pipe_ctx, unsigned int underlay_idx)
774 if (pipe_ctx->pipe_idx != underlay_idx)
776 if (!pipe_ctx->plane_state)
778 if (pipe_ctx->plane_state->format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
783 static enum dc_status build_mapped_resource(
785 struct dc_state *context,
786 struct dc_stream_state *stream)
788 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
791 return DC_ERROR_UNEXPECTED;
793 if (!is_surface_pixel_format_supported(pipe_ctx,
794 dc->res_pool->underlay_pipe_index))
795 return DC_SURFACE_PIXEL_FORMAT_UNSUPPORTED;
797 dce110_resource_build_pipe_hw_param(pipe_ctx);
799 /* TODO: validate audio ASIC caps, encoder */
801 resource_build_info_frame(pipe_ctx);
806 static bool dce110_validate_bandwidth(
808 struct dc_state *context)
812 DC_LOG_BANDWIDTH_CALCS(
820 context->res_ctx.pipe_ctx,
821 dc->res_pool->pipe_count,
826 DC_LOG_BANDWIDTH_VALIDATION("%s: %dx%d@%d Bandwidth validation failed!\n",
828 context->streams[0]->timing.h_addressable,
829 context->streams[0]->timing.v_addressable,
830 context->streams[0]->timing.pix_clk_khz);
832 if (memcmp(&dc->current_state->bw.dce,
833 &context->bw.dce, sizeof(context->bw.dce))) {
835 DC_LOG_BANDWIDTH_CALCS(
837 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
838 "stutMark_b: %d stutMark_a: %d\n"
839 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
840 "stutMark_b: %d stutMark_a: %d\n"
841 "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
842 "stutMark_b: %d stutMark_a: %d stutter_mode_enable: %d\n"
843 "cstate: %d pstate: %d nbpstate: %d sync: %d dispclk: %d\n"
844 "sclk: %d sclk_sleep: %d yclk: %d blackout_recovery_time_us: %d\n"
847 context->bw.dce.nbp_state_change_wm_ns[0].b_mark,
848 context->bw.dce.nbp_state_change_wm_ns[0].a_mark,
849 context->bw.dce.urgent_wm_ns[0].b_mark,
850 context->bw.dce.urgent_wm_ns[0].a_mark,
851 context->bw.dce.stutter_exit_wm_ns[0].b_mark,
852 context->bw.dce.stutter_exit_wm_ns[0].a_mark,
853 context->bw.dce.nbp_state_change_wm_ns[1].b_mark,
854 context->bw.dce.nbp_state_change_wm_ns[1].a_mark,
855 context->bw.dce.urgent_wm_ns[1].b_mark,
856 context->bw.dce.urgent_wm_ns[1].a_mark,
857 context->bw.dce.stutter_exit_wm_ns[1].b_mark,
858 context->bw.dce.stutter_exit_wm_ns[1].a_mark,
859 context->bw.dce.nbp_state_change_wm_ns[2].b_mark,
860 context->bw.dce.nbp_state_change_wm_ns[2].a_mark,
861 context->bw.dce.urgent_wm_ns[2].b_mark,
862 context->bw.dce.urgent_wm_ns[2].a_mark,
863 context->bw.dce.stutter_exit_wm_ns[2].b_mark,
864 context->bw.dce.stutter_exit_wm_ns[2].a_mark,
865 context->bw.dce.stutter_mode_enable,
866 context->bw.dce.cpuc_state_change_enable,
867 context->bw.dce.cpup_state_change_enable,
868 context->bw.dce.nbp_state_change_enable,
869 context->bw.dce.all_displays_in_sync,
870 context->bw.dce.dispclk_khz,
871 context->bw.dce.sclk_khz,
872 context->bw.dce.sclk_deep_sleep_khz,
873 context->bw.dce.yclk_khz,
874 context->bw.dce.blackout_recovery_time_us);
879 enum dc_status dce110_validate_plane(const struct dc_plane_state *plane_state,
880 struct dc_caps *caps)
882 if (((plane_state->dst_rect.width * 2) < plane_state->src_rect.width) ||
883 ((plane_state->dst_rect.height * 2) < plane_state->src_rect.height))
884 return DC_FAIL_SURFACE_VALIDATE;
889 static bool dce110_validate_surface_sets(
890 struct dc_state *context)
894 for (i = 0; i < context->stream_count; i++) {
895 if (context->stream_status[i].plane_count == 0)
898 if (context->stream_status[i].plane_count > 2)
901 for (j = 0; j < context->stream_status[i].plane_count; j++) {
902 struct dc_plane_state *plane =
903 context->stream_status[i].plane_states[j];
905 /* underlay validation */
906 if (plane->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) {
908 if ((plane->src_rect.width > 1920 ||
909 plane->src_rect.height > 1080))
912 /* we don't have the logic to support underlay
913 * only yet so block the use case where we get
914 * NV12 plane as top layer
919 /* irrespective of plane format,
920 * stream should be RGB encoded
922 if (context->streams[i]->timing.pixel_encoding
923 != PIXEL_ENCODING_RGB)
934 enum dc_status dce110_validate_global(
936 struct dc_state *context)
938 if (!dce110_validate_surface_sets(context))
939 return DC_FAIL_SURFACE_VALIDATE;
944 static enum dc_status dce110_add_stream_to_ctx(
946 struct dc_state *new_ctx,
947 struct dc_stream_state *dc_stream)
949 enum dc_status result = DC_ERROR_UNEXPECTED;
951 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
954 result = resource_map_clock_resources(dc, new_ctx, dc_stream);
958 result = build_mapped_resource(dc, new_ctx, dc_stream);
963 static struct pipe_ctx *dce110_acquire_underlay(
964 struct dc_state *context,
965 const struct resource_pool *pool,
966 struct dc_stream_state *stream)
968 struct dc *dc = stream->ctx->dc;
969 struct resource_context *res_ctx = &context->res_ctx;
970 unsigned int underlay_idx = pool->underlay_pipe_index;
971 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[underlay_idx];
973 if (res_ctx->pipe_ctx[underlay_idx].stream)
976 pipe_ctx->stream_res.tg = pool->timing_generators[underlay_idx];
977 pipe_ctx->plane_res.mi = pool->mis[underlay_idx];
978 /*pipe_ctx->plane_res.ipp = res_ctx->pool->ipps[underlay_idx];*/
979 pipe_ctx->plane_res.xfm = pool->transforms[underlay_idx];
980 pipe_ctx->stream_res.opp = pool->opps[underlay_idx];
981 pipe_ctx->pipe_idx = underlay_idx;
983 pipe_ctx->stream = stream;
985 if (!dc->current_state->res_ctx.pipe_ctx[underlay_idx].stream) {
986 struct tg_color black_color = {0};
987 struct dc_bios *dcb = dc->ctx->dc_bios;
989 dc->hwss.enable_display_power_gating(
991 pipe_ctx->stream_res.tg->inst,
992 dcb, PIPE_GATING_CONTROL_DISABLE);
995 * This is for powering on underlay, so crtc does not
999 pipe_ctx->stream_res.tg->funcs->program_timing(pipe_ctx->stream_res.tg,
1003 pipe_ctx->stream_res.tg->funcs->enable_advanced_request(
1004 pipe_ctx->stream_res.tg,
1008 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(pipe_ctx->plane_res.mi,
1009 stream->timing.h_total,
1010 stream->timing.v_total,
1011 stream->timing.pix_clk_khz,
1012 context->stream_count);
1014 color_space_to_black_color(dc,
1015 COLOR_SPACE_YCBCR601, &black_color);
1016 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1017 pipe_ctx->stream_res.tg,
1024 static void dce110_destroy_resource_pool(struct resource_pool **pool)
1026 struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
1028 destruct(dce110_pool);
1034 static const struct resource_funcs dce110_res_pool_funcs = {
1035 .destroy = dce110_destroy_resource_pool,
1036 .link_enc_create = dce110_link_encoder_create,
1037 .validate_bandwidth = dce110_validate_bandwidth,
1038 .validate_plane = dce110_validate_plane,
1039 .acquire_idle_pipe_for_layer = dce110_acquire_underlay,
1040 .add_stream_to_ctx = dce110_add_stream_to_ctx,
1041 .validate_global = dce110_validate_global
1044 static bool underlay_create(struct dc_context *ctx, struct resource_pool *pool)
1046 struct dce110_timing_generator *dce110_tgv = kzalloc(sizeof(*dce110_tgv),
1048 struct dce_transform *dce110_xfmv = kzalloc(sizeof(*dce110_xfmv),
1050 struct dce_mem_input *dce110_miv = kzalloc(sizeof(*dce110_miv),
1052 struct dce110_opp *dce110_oppv = kzalloc(sizeof(*dce110_oppv),
1055 if (!dce110_tgv || !dce110_xfmv || !dce110_miv || !dce110_oppv) {
1063 dce110_opp_v_construct(dce110_oppv, ctx);
1065 dce110_timing_generator_v_construct(dce110_tgv, ctx);
1066 dce110_mem_input_v_construct(dce110_miv, ctx);
1067 dce110_transform_v_construct(dce110_xfmv, ctx);
1069 pool->opps[pool->pipe_count] = &dce110_oppv->base;
1070 pool->timing_generators[pool->pipe_count] = &dce110_tgv->base;
1071 pool->mis[pool->pipe_count] = &dce110_miv->base;
1072 pool->transforms[pool->pipe_count] = &dce110_xfmv->base;
1075 /* update the public caps to indicate an underlay is available */
1076 ctx->dc->caps.max_slave_planes = 1;
1077 ctx->dc->caps.max_slave_planes = 1;
1082 static void bw_calcs_data_update_from_pplib(struct dc *dc)
1084 struct dm_pp_clock_levels clks = {0};
1087 dm_pp_get_clock_levels_by_type(
1089 DM_PP_CLOCK_TYPE_ENGINE_CLK,
1091 /* convert all the clock fro kHz to fix point mHz */
1092 dc->bw_vbios->high_sclk = bw_frc_to_fixed(
1093 clks.clocks_in_khz[clks.num_levels-1], 1000);
1094 dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
1095 clks.clocks_in_khz[clks.num_levels/8], 1000);
1096 dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
1097 clks.clocks_in_khz[clks.num_levels*2/8], 1000);
1098 dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
1099 clks.clocks_in_khz[clks.num_levels*3/8], 1000);
1100 dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
1101 clks.clocks_in_khz[clks.num_levels*4/8], 1000);
1102 dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
1103 clks.clocks_in_khz[clks.num_levels*5/8], 1000);
1104 dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
1105 clks.clocks_in_khz[clks.num_levels*6/8], 1000);
1106 dc->bw_vbios->low_sclk = bw_frc_to_fixed(
1107 clks.clocks_in_khz[0], 1000);
1108 dc->sclk_lvls = clks;
1110 /*do display clock*/
1111 dm_pp_get_clock_levels_by_type(
1113 DM_PP_CLOCK_TYPE_DISPLAY_CLK,
1115 dc->bw_vbios->high_voltage_max_dispclk = bw_frc_to_fixed(
1116 clks.clocks_in_khz[clks.num_levels-1], 1000);
1117 dc->bw_vbios->mid_voltage_max_dispclk = bw_frc_to_fixed(
1118 clks.clocks_in_khz[clks.num_levels>>1], 1000);
1119 dc->bw_vbios->low_voltage_max_dispclk = bw_frc_to_fixed(
1120 clks.clocks_in_khz[0], 1000);
1123 dm_pp_get_clock_levels_by_type(
1125 DM_PP_CLOCK_TYPE_MEMORY_CLK,
1128 dc->bw_vbios->low_yclk = bw_frc_to_fixed(
1129 clks.clocks_in_khz[0] * MEMORY_TYPE_MULTIPLIER, 1000);
1130 dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
1131 clks.clocks_in_khz[clks.num_levels>>1] * MEMORY_TYPE_MULTIPLIER,
1133 dc->bw_vbios->high_yclk = bw_frc_to_fixed(
1134 clks.clocks_in_khz[clks.num_levels-1] * MEMORY_TYPE_MULTIPLIER,
1138 const struct resource_caps *dce110_resource_cap(
1139 struct hw_asic_id *asic_id)
1141 if (ASIC_REV_IS_STONEY(asic_id->hw_internal_rev))
1142 return &stoney_resource_cap;
1144 return &carrizo_resource_cap;
1147 static bool construct(
1148 uint8_t num_virtual_links,
1150 struct dce110_resource_pool *pool,
1151 struct hw_asic_id asic_id)
1154 struct dc_context *ctx = dc->ctx;
1155 struct dc_firmware_info info;
1157 struct dm_pp_static_clock_info static_clk_info = {0};
1159 ctx->dc_bios->regs = &bios_regs;
1161 pool->base.res_cap = dce110_resource_cap(&ctx->asic_id);
1162 pool->base.funcs = &dce110_res_pool_funcs;
1164 /*************************************************
1165 * Resource + asic cap harcoding *
1166 *************************************************/
1168 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1169 pool->base.underlay_pipe_index = pool->base.pipe_count;
1170 pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
1171 dc->caps.max_downscale_ratio = 150;
1172 dc->caps.i2c_speed_in_khz = 100;
1173 dc->caps.max_cursor_size = 128;
1174 dc->caps.is_apu = true;
1176 /*************************************************
1177 * Create resources *
1178 *************************************************/
1182 if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
1183 info.external_clock_source_frequency_for_dp != 0) {
1184 pool->base.dp_clock_source =
1185 dce110_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1187 pool->base.clock_sources[0] =
1188 dce110_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0,
1189 &clk_src_regs[0], false);
1190 pool->base.clock_sources[1] =
1191 dce110_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1,
1192 &clk_src_regs[1], false);
1194 pool->base.clk_src_count = 2;
1196 /* TODO: find out if CZ support 3 PLLs */
1199 if (pool->base.dp_clock_source == NULL) {
1200 dm_error("DC: failed to create dp clock source!\n");
1201 BREAK_TO_DEBUGGER();
1202 goto res_create_fail;
1205 for (i = 0; i < pool->base.clk_src_count; i++) {
1206 if (pool->base.clock_sources[i] == NULL) {
1207 dm_error("DC: failed to create clock sources!\n");
1208 BREAK_TO_DEBUGGER();
1209 goto res_create_fail;
1213 pool->base.dccg = dce110_dccg_create(ctx,
1217 if (pool->base.dccg == NULL) {
1218 dm_error("DC: failed to create display clock!\n");
1219 BREAK_TO_DEBUGGER();
1220 goto res_create_fail;
1223 pool->base.dmcu = dce_dmcu_create(ctx,
1227 if (pool->base.dmcu == NULL) {
1228 dm_error("DC: failed to create dmcu!\n");
1229 BREAK_TO_DEBUGGER();
1230 goto res_create_fail;
1233 pool->base.abm = dce_abm_create(ctx,
1237 if (pool->base.abm == NULL) {
1238 dm_error("DC: failed to create abm!\n");
1239 BREAK_TO_DEBUGGER();
1240 goto res_create_fail;
1243 /* get static clock information for PPLIB or firmware, save
1246 if (dm_pp_get_static_clocks(ctx, &static_clk_info))
1247 pool->base.dccg->max_clks_state =
1248 static_clk_info.max_clocks_state;
1251 struct irq_service_init_data init_data;
1252 init_data.ctx = dc->ctx;
1253 pool->base.irqs = dal_irq_service_dce110_create(&init_data);
1254 if (!pool->base.irqs)
1255 goto res_create_fail;
1258 for (i = 0; i < pool->base.pipe_count; i++) {
1259 pool->base.timing_generators[i] = dce110_timing_generator_create(
1260 ctx, i, &dce110_tg_offsets[i]);
1261 if (pool->base.timing_generators[i] == NULL) {
1262 BREAK_TO_DEBUGGER();
1263 dm_error("DC: failed to create tg!\n");
1264 goto res_create_fail;
1267 pool->base.mis[i] = dce110_mem_input_create(ctx, i);
1268 if (pool->base.mis[i] == NULL) {
1269 BREAK_TO_DEBUGGER();
1271 "DC: failed to create memory input!\n");
1272 goto res_create_fail;
1275 pool->base.ipps[i] = dce110_ipp_create(ctx, i);
1276 if (pool->base.ipps[i] == NULL) {
1277 BREAK_TO_DEBUGGER();
1279 "DC: failed to create input pixel processor!\n");
1280 goto res_create_fail;
1283 pool->base.transforms[i] = dce110_transform_create(ctx, i);
1284 if (pool->base.transforms[i] == NULL) {
1285 BREAK_TO_DEBUGGER();
1287 "DC: failed to create transform!\n");
1288 goto res_create_fail;
1291 pool->base.opps[i] = dce110_opp_create(ctx, i);
1292 if (pool->base.opps[i] == NULL) {
1293 BREAK_TO_DEBUGGER();
1295 "DC: failed to create output pixel processor!\n");
1296 goto res_create_fail;
1299 pool->base.engines[i] = dce110_aux_engine_create(ctx, i);
1300 if (pool->base.engines[i] == NULL) {
1301 BREAK_TO_DEBUGGER();
1303 "DC:failed to create aux engine!!\n");
1304 goto res_create_fail;
1308 dc->fbc_compressor = dce110_compressor_create(ctx);
1310 if (!underlay_create(ctx, &pool->base))
1311 goto res_create_fail;
1313 if (!resource_construct(num_virtual_links, dc, &pool->base,
1315 goto res_create_fail;
1317 /* Create hardware sequencer */
1318 dce110_hw_sequencer_construct(dc);
1320 dc->caps.max_planes = pool->base.pipe_count;
1322 bw_calcs_init(dc->bw_dceip, dc->bw_vbios, dc->ctx->asic_id);
1324 bw_calcs_data_update_from_pplib(dc);
1333 struct resource_pool *dce110_create_resource_pool(
1334 uint8_t num_virtual_links,
1336 struct hw_asic_id asic_id)
1338 struct dce110_resource_pool *pool =
1339 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1344 if (construct(num_virtual_links, dc, pool, asic_id))
1348 BREAK_TO_DEBUGGER();