12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256 |
- /*
- * Copyright 2016 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
- #include "dm_services.h"
- #include "dc.h"
- #include "resource.h"
- #include "include/irq_service_interface.h"
- #include "dcn10/dcn10_resource.h"
- #include "dcn10/dcn10_ipp.h"
- #include "dcn10/dcn10_mpc.h"
- #include "irq/dcn10/irq_service_dcn10.h"
- #include "dcn10/dcn10_dpp.h"
- #include "dcn10_optc.h"
- #include "dcn10/dcn10_hw_sequencer.h"
- #include "dce110/dce110_hw_sequencer.h"
- #include "dcn10/dcn10_opp.h"
- #include "dcn10/dcn10_link_encoder.h"
- #include "dcn10/dcn10_stream_encoder.h"
- #include "dce/dce_clocks.h"
- #include "dce/dce_clock_source.h"
- #include "dce/dce_audio.h"
- #include "dce/dce_hwseq.h"
- #include "../virtual/virtual_stream_encoder.h"
- #include "dce110/dce110_resource.h"
- #include "dce112/dce112_resource.h"
- #include "dcn10_hubp.h"
- #include "dcn10_hubbub.h"
- #include "soc15_hw_ip.h"
- #include "vega10_ip_offset.h"
- #include "dcn/dcn_1_0_offset.h"
- #include "dcn/dcn_1_0_sh_mask.h"
- #include "nbio/nbio_7_0_offset.h"
- #include "mmhub/mmhub_9_1_offset.h"
- #include "mmhub/mmhub_9_1_sh_mask.h"
- #include "reg_helper.h"
- #include "dce/dce_abm.h"
- #include "dce/dce_dmcu.h"
- #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
- #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x210f
- #define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x220f
- #define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x230f
- #define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x240f
- #define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x250f
- #define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x260f
- #define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x270f
- #define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
- #endif
- enum dcn10_clk_src_array_id {
- DCN10_CLK_SRC_PLL0,
- DCN10_CLK_SRC_PLL1,
- DCN10_CLK_SRC_PLL2,
- DCN10_CLK_SRC_PLL3,
- DCN10_CLK_SRC_TOTAL
- };
- /* begin *********************
- * macros to expend register list macro defined in HW object header file */
- /* DCN */
- #define BASE_INNER(seg) \
- DCE_BASE__INST0_SEG ## seg
- #define BASE(seg) \
- BASE_INNER(seg)
- #define SR(reg_name)\
- .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
- mm ## reg_name
- #define SRI(reg_name, block, id)\
- .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
- mm ## block ## id ## _ ## reg_name
- #define SRII(reg_name, block, id)\
- .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
- mm ## block ## id ## _ ## reg_name
- /* NBIO */
- #define NBIO_BASE_INNER(seg) \
- NBIF_BASE__INST0_SEG ## seg
- #define NBIO_BASE(seg) \
- NBIO_BASE_INNER(seg)
- #define NBIO_SR(reg_name)\
- .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
- mm ## reg_name
- /* MMHUB */
- #define MMHUB_BASE_INNER(seg) \
- MMHUB_BASE__INST0_SEG ## seg
- #define MMHUB_BASE(seg) \
- MMHUB_BASE_INNER(seg)
- #define MMHUB_SR(reg_name)\
- .reg_name = MMHUB_BASE(mm ## reg_name ## _BASE_IDX) + \
- mm ## reg_name
- /* macros to expend register list macro defined in HW object header file
- * end *********************/
- static const struct dce_dmcu_registers dmcu_regs = {
- DMCU_DCN10_REG_LIST()
- };
- static const struct dce_dmcu_shift dmcu_shift = {
- DMCU_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dce_dmcu_mask dmcu_mask = {
- DMCU_MASK_SH_LIST_DCN10(_MASK)
- };
- static const struct dce_abm_registers abm_regs = {
- ABM_DCN10_REG_LIST(0)
- };
- static const struct dce_abm_shift abm_shift = {
- ABM_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dce_abm_mask abm_mask = {
- ABM_MASK_SH_LIST_DCN10(_MASK)
- };
- #define stream_enc_regs(id)\
- [id] = {\
- SE_DCN_REG_LIST(id)\
- }
- static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
- stream_enc_regs(0),
- stream_enc_regs(1),
- stream_enc_regs(2),
- stream_enc_regs(3),
- };
- static const struct dcn10_stream_encoder_shift se_shift = {
- SE_COMMON_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dcn10_stream_encoder_mask se_mask = {
- SE_COMMON_MASK_SH_LIST_DCN10(_MASK)
- };
- #define audio_regs(id)\
- [id] = {\
- AUD_COMMON_REG_LIST(id)\
- }
- static const struct dce_audio_registers audio_regs[] = {
- audio_regs(0),
- audio_regs(1),
- audio_regs(2),
- audio_regs(3),
- };
- #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
- SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
- SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
- AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
- static const struct dce_audio_shift audio_shift = {
- DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
- };
- static const struct dce_aduio_mask audio_mask = {
- DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
- };
- #define aux_regs(id)\
- [id] = {\
- AUX_REG_LIST(id)\
- }
- static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
- aux_regs(0),
- aux_regs(1),
- aux_regs(2),
- aux_regs(3)
- };
- #define hpd_regs(id)\
- [id] = {\
- HPD_REG_LIST(id)\
- }
- static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
- hpd_regs(0),
- hpd_regs(1),
- hpd_regs(2),
- hpd_regs(3)
- };
- #define link_regs(id)\
- [id] = {\
- LE_DCN10_REG_LIST(id), \
- SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
- }
- static const struct dcn10_link_enc_registers link_enc_regs[] = {
- link_regs(0),
- link_regs(1),
- link_regs(2),
- link_regs(3)
- };
- static const struct dcn10_link_enc_shift le_shift = {
- LINK_ENCODER_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dcn10_link_enc_mask le_mask = {
- LINK_ENCODER_MASK_SH_LIST_DCN10(_MASK)
- };
- #define ipp_regs(id)\
- [id] = {\
- IPP_REG_LIST_DCN10(id),\
- }
- static const struct dcn10_ipp_registers ipp_regs[] = {
- ipp_regs(0),
- ipp_regs(1),
- ipp_regs(2),
- ipp_regs(3),
- };
- static const struct dcn10_ipp_shift ipp_shift = {
- IPP_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dcn10_ipp_mask ipp_mask = {
- IPP_MASK_SH_LIST_DCN10(_MASK),
- };
- #define opp_regs(id)\
- [id] = {\
- OPP_REG_LIST_DCN10(id),\
- }
- static const struct dcn10_opp_registers opp_regs[] = {
- opp_regs(0),
- opp_regs(1),
- opp_regs(2),
- opp_regs(3),
- };
- static const struct dcn10_opp_shift opp_shift = {
- OPP_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dcn10_opp_mask opp_mask = {
- OPP_MASK_SH_LIST_DCN10(_MASK),
- };
- #define tf_regs(id)\
- [id] = {\
- TF_REG_LIST_DCN10(id),\
- }
- static const struct dcn_dpp_registers tf_regs[] = {
- tf_regs(0),
- tf_regs(1),
- tf_regs(2),
- tf_regs(3),
- };
- static const struct dcn_dpp_shift tf_shift = {
- TF_REG_LIST_SH_MASK_DCN10(__SHIFT),
- TF_DEBUG_REG_LIST_SH_DCN10
- };
- static const struct dcn_dpp_mask tf_mask = {
- TF_REG_LIST_SH_MASK_DCN10(_MASK),
- TF_DEBUG_REG_LIST_MASK_DCN10
- };
- static const struct dcn_mpc_registers mpc_regs = {
- MPC_COMMON_REG_LIST_DCN1_0(0),
- MPC_COMMON_REG_LIST_DCN1_0(1),
- MPC_COMMON_REG_LIST_DCN1_0(2),
- MPC_COMMON_REG_LIST_DCN1_0(3),
- MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(0),
- MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(1),
- MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(2),
- MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(3)
- };
- static const struct dcn_mpc_shift mpc_shift = {
- MPC_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
- };
- static const struct dcn_mpc_mask mpc_mask = {
- MPC_COMMON_MASK_SH_LIST_DCN1_0(_MASK),
- };
- #define tg_regs(id)\
- [id] = {TG_COMMON_REG_LIST_DCN1_0(id)}
- static const struct dcn_optc_registers tg_regs[] = {
- tg_regs(0),
- tg_regs(1),
- tg_regs(2),
- tg_regs(3),
- };
- static const struct dcn_optc_shift tg_shift = {
- TG_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
- };
- static const struct dcn_optc_mask tg_mask = {
- TG_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
- };
- static const struct bios_registers bios_regs = {
- NBIO_SR(BIOS_SCRATCH_3),
- NBIO_SR(BIOS_SCRATCH_6)
- };
- #define hubp_regs(id)\
- [id] = {\
- HUBP_REG_LIST_DCN10(id)\
- }
- static const struct dcn_mi_registers hubp_regs[] = {
- hubp_regs(0),
- hubp_regs(1),
- hubp_regs(2),
- hubp_regs(3),
- };
- static const struct dcn_mi_shift hubp_shift = {
- HUBP_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dcn_mi_mask hubp_mask = {
- HUBP_MASK_SH_LIST_DCN10(_MASK)
- };
- static const struct dcn_hubbub_registers hubbub_reg = {
- HUBBUB_REG_LIST_DCN10(0)
- };
- static const struct dcn_hubbub_shift hubbub_shift = {
- HUBBUB_MASK_SH_LIST_DCN10(__SHIFT)
- };
- static const struct dcn_hubbub_mask hubbub_mask = {
- HUBBUB_MASK_SH_LIST_DCN10(_MASK)
- };
- #define clk_src_regs(index, pllid)\
- [index] = {\
- CS_COMMON_REG_LIST_DCN1_0(index, pllid),\
- }
- static const struct dce110_clk_src_regs clk_src_regs[] = {
- clk_src_regs(0, A),
- clk_src_regs(1, B),
- clk_src_regs(2, C),
- clk_src_regs(3, D)
- };
- static const struct dce110_clk_src_shift cs_shift = {
- CS_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
- };
- static const struct dce110_clk_src_mask cs_mask = {
- CS_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
- };
- static const struct resource_caps res_cap = {
- .num_timing_generator = 4,
- .num_video_plane = 4,
- .num_audio = 4,
- .num_stream_encoder = 4,
- .num_pll = 4,
- };
- static const struct dc_debug debug_defaults_drv = {
- .sanity_checks = true,
- .disable_dmcu = true,
- .force_abm_enable = false,
- .timing_trace = false,
- .clock_trace = true,
- /* raven smu dones't allow 0 disp clk,
- * smu min disp clk limit is 50Mhz
- * keep min disp clk 100Mhz avoid smu hang
- */
- .min_disp_clk_khz = 100000,
- .disable_pplib_clock_request = true,
- .disable_pplib_wm_range = false,
- .pplib_wm_report_mode = WM_REPORT_DEFAULT,
- .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
- .force_single_disp_pipe_split = true,
- .disable_dcc = DCC_ENABLE,
- .voltage_align_fclk = true,
- .disable_stereo_support = true,
- .vsr_support = true,
- .performance_trace = false,
- .az_endpoint_mute_only = true,
- .recovery_enabled = false, /*enable this by default after testing.*/
- .max_downscale_src_width = 3840,
- };
- static const struct dc_debug debug_defaults_diags = {
- .disable_dmcu = true,
- .force_abm_enable = false,
- .timing_trace = true,
- .clock_trace = true,
- .disable_stutter = true,
- .disable_pplib_clock_request = true,
- .disable_pplib_wm_range = true
- };
- static void dcn10_dpp_destroy(struct dpp **dpp)
- {
- kfree(TO_DCN10_DPP(*dpp));
- *dpp = NULL;
- }
- static struct dpp *dcn10_dpp_create(
- struct dc_context *ctx,
- uint32_t inst)
- {
- struct dcn10_dpp *dpp =
- kzalloc(sizeof(struct dcn10_dpp), GFP_KERNEL);
- if (!dpp)
- return NULL;
- dpp1_construct(dpp, ctx, inst,
- &tf_regs[inst], &tf_shift, &tf_mask);
- return &dpp->base;
- }
- static struct input_pixel_processor *dcn10_ipp_create(
- struct dc_context *ctx, uint32_t inst)
- {
- struct dcn10_ipp *ipp =
- kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL);
- if (!ipp) {
- BREAK_TO_DEBUGGER();
- return NULL;
- }
- dcn10_ipp_construct(ipp, ctx, inst,
- &ipp_regs[inst], &ipp_shift, &ipp_mask);
- return &ipp->base;
- }
- static struct output_pixel_processor *dcn10_opp_create(
- struct dc_context *ctx, uint32_t inst)
- {
- struct dcn10_opp *opp =
- kzalloc(sizeof(struct dcn10_opp), GFP_KERNEL);
- if (!opp) {
- BREAK_TO_DEBUGGER();
- return NULL;
- }
- dcn10_opp_construct(opp, ctx, inst,
- &opp_regs[inst], &opp_shift, &opp_mask);
- return &opp->base;
- }
- static struct mpc *dcn10_mpc_create(struct dc_context *ctx)
- {
- struct dcn10_mpc *mpc10 = kzalloc(sizeof(struct dcn10_mpc),
- GFP_KERNEL);
- if (!mpc10)
- return NULL;
- dcn10_mpc_construct(mpc10, ctx,
- &mpc_regs,
- &mpc_shift,
- &mpc_mask,
- 4);
- return &mpc10->base;
- }
- static struct hubbub *dcn10_hubbub_create(struct dc_context *ctx)
- {
- struct hubbub *hubbub = kzalloc(sizeof(struct hubbub),
- GFP_KERNEL);
- if (!hubbub)
- return NULL;
- hubbub1_construct(hubbub, ctx,
- &hubbub_reg,
- &hubbub_shift,
- &hubbub_mask);
- return hubbub;
- }
- static struct timing_generator *dcn10_timing_generator_create(
- struct dc_context *ctx,
- uint32_t instance)
- {
- struct optc *tgn10 =
- kzalloc(sizeof(struct optc), GFP_KERNEL);
- if (!tgn10)
- return NULL;
- tgn10->base.inst = instance;
- tgn10->base.ctx = ctx;
- tgn10->tg_regs = &tg_regs[instance];
- tgn10->tg_shift = &tg_shift;
- tgn10->tg_mask = &tg_mask;
- dcn10_timing_generator_init(tgn10);
- return &tgn10->base;
- }
- static const struct encoder_feature_support link_enc_feature = {
- .max_hdmi_deep_color = COLOR_DEPTH_121212,
- .max_hdmi_pixel_clock = 600000,
- .ycbcr420_supported = true,
- .flags.bits.IS_HBR2_CAPABLE = true,
- .flags.bits.IS_HBR3_CAPABLE = true,
- .flags.bits.IS_TPS3_CAPABLE = true,
- .flags.bits.IS_TPS4_CAPABLE = true,
- .flags.bits.IS_YCBCR_CAPABLE = true
- };
- struct link_encoder *dcn10_link_encoder_create(
- const struct encoder_init_data *enc_init_data)
- {
- struct dcn10_link_encoder *enc10 =
- kzalloc(sizeof(struct dcn10_link_encoder), GFP_KERNEL);
- if (!enc10)
- return NULL;
- dcn10_link_encoder_construct(enc10,
- enc_init_data,
- &link_enc_feature,
- &link_enc_regs[enc_init_data->transmitter],
- &link_enc_aux_regs[enc_init_data->channel - 1],
- &link_enc_hpd_regs[enc_init_data->hpd_source],
- &le_shift,
- &le_mask);
- return &enc10->base;
- }
- struct clock_source *dcn10_clock_source_create(
- struct dc_context *ctx,
- struct dc_bios *bios,
- enum clock_source_id id,
- const struct dce110_clk_src_regs *regs,
- bool dp_clk_src)
- {
- struct dce110_clk_src *clk_src =
- kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
- if (!clk_src)
- return NULL;
- if (dce110_clk_src_construct(clk_src, ctx, bios, id,
- regs, &cs_shift, &cs_mask)) {
- clk_src->base.dp_clk_src = dp_clk_src;
- return &clk_src->base;
- }
- BREAK_TO_DEBUGGER();
- return NULL;
- }
- static void read_dce_straps(
- struct dc_context *ctx,
- struct resource_straps *straps)
- {
- generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
- FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
- }
- static struct audio *create_audio(
- struct dc_context *ctx, unsigned int inst)
- {
- return dce_audio_create(ctx, inst,
- &audio_regs[inst], &audio_shift, &audio_mask);
- }
- static struct stream_encoder *dcn10_stream_encoder_create(
- enum engine_id eng_id,
- struct dc_context *ctx)
- {
- struct dcn10_stream_encoder *enc1 =
- kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
- if (!enc1)
- return NULL;
- dcn10_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id,
- &stream_enc_regs[eng_id],
- &se_shift, &se_mask);
- return &enc1->base;
- }
- static const struct dce_hwseq_registers hwseq_reg = {
- HWSEQ_DCN1_REG_LIST()
- };
- static const struct dce_hwseq_shift hwseq_shift = {
- HWSEQ_DCN1_MASK_SH_LIST(__SHIFT)
- };
- static const struct dce_hwseq_mask hwseq_mask = {
- HWSEQ_DCN1_MASK_SH_LIST(_MASK)
- };
- static struct dce_hwseq *dcn10_hwseq_create(
- struct dc_context *ctx)
- {
- struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
- if (hws) {
- hws->ctx = ctx;
- hws->regs = &hwseq_reg;
- hws->shifts = &hwseq_shift;
- hws->masks = &hwseq_mask;
- hws->wa.DEGVIDCN10_253 = true;
- hws->wa.false_optc_underflow = true;
- }
- return hws;
- }
- static const struct resource_create_funcs res_create_funcs = {
- .read_dce_straps = read_dce_straps,
- .create_audio = create_audio,
- .create_stream_encoder = dcn10_stream_encoder_create,
- .create_hwseq = dcn10_hwseq_create,
- };
- static const struct resource_create_funcs res_create_maximus_funcs = {
- .read_dce_straps = NULL,
- .create_audio = NULL,
- .create_stream_encoder = NULL,
- .create_hwseq = dcn10_hwseq_create,
- };
- void dcn10_clock_source_destroy(struct clock_source **clk_src)
- {
- kfree(TO_DCE110_CLK_SRC(*clk_src));
- *clk_src = NULL;
- }
- static struct pp_smu_funcs_rv *dcn10_pp_smu_create(struct dc_context *ctx)
- {
- struct pp_smu_funcs_rv *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
- if (!pp_smu)
- return pp_smu;
- dm_pp_get_funcs_rv(ctx, pp_smu);
- return pp_smu;
- }
- static void destruct(struct dcn10_resource_pool *pool)
- {
- unsigned int i;
- for (i = 0; i < pool->base.stream_enc_count; i++) {
- if (pool->base.stream_enc[i] != NULL) {
- /* TODO: free dcn version of stream encoder once implemented
- * rather than using virtual stream encoder
- */
- kfree(pool->base.stream_enc[i]);
- pool->base.stream_enc[i] = NULL;
- }
- }
- if (pool->base.mpc != NULL) {
- kfree(TO_DCN10_MPC(pool->base.mpc));
- pool->base.mpc = NULL;
- }
- if (pool->base.hubbub != NULL) {
- kfree(pool->base.hubbub);
- pool->base.hubbub = NULL;
- }
- for (i = 0; i < pool->base.pipe_count; i++) {
- if (pool->base.opps[i] != NULL)
- pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
- if (pool->base.dpps[i] != NULL)
- dcn10_dpp_destroy(&pool->base.dpps[i]);
- if (pool->base.ipps[i] != NULL)
- pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
- if (pool->base.hubps[i] != NULL) {
- kfree(TO_DCN10_HUBP(pool->base.hubps[i]));
- pool->base.hubps[i] = NULL;
- }
- if (pool->base.irqs != NULL) {
- dal_irq_service_destroy(&pool->base.irqs);
- }
- if (pool->base.timing_generators[i] != NULL) {
- kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
- pool->base.timing_generators[i] = NULL;
- }
- }
- for (i = 0; i < pool->base.stream_enc_count; i++)
- kfree(pool->base.stream_enc[i]);
- for (i = 0; i < pool->base.audio_count; i++) {
- if (pool->base.audios[i])
- dce_aud_destroy(&pool->base.audios[i]);
- }
- for (i = 0; i < pool->base.clk_src_count; i++) {
- if (pool->base.clock_sources[i] != NULL) {
- dcn10_clock_source_destroy(&pool->base.clock_sources[i]);
- pool->base.clock_sources[i] = NULL;
- }
- }
- if (pool->base.dp_clock_source != NULL) {
- dcn10_clock_source_destroy(&pool->base.dp_clock_source);
- pool->base.dp_clock_source = NULL;
- }
- if (pool->base.abm != NULL)
- dce_abm_destroy(&pool->base.abm);
- if (pool->base.dmcu != NULL)
- dce_dmcu_destroy(&pool->base.dmcu);
- if (pool->base.display_clock != NULL)
- dce_disp_clk_destroy(&pool->base.display_clock);
- kfree(pool->base.pp_smu);
- }
- static struct hubp *dcn10_hubp_create(
- struct dc_context *ctx,
- uint32_t inst)
- {
- struct dcn10_hubp *hubp1 =
- kzalloc(sizeof(struct dcn10_hubp), GFP_KERNEL);
- if (!hubp1)
- return NULL;
- dcn10_hubp_construct(hubp1, ctx, inst,
- &hubp_regs[inst], &hubp_shift, &hubp_mask);
- return &hubp1->base;
- }
- static void get_pixel_clock_parameters(
- const struct pipe_ctx *pipe_ctx,
- struct pixel_clk_params *pixel_clk_params)
- {
- const struct dc_stream_state *stream = pipe_ctx->stream;
- pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
- pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
- pixel_clk_params->signal_type = pipe_ctx->stream->signal;
- pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
- /* TODO: un-hardcode*/
- pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
- LINK_RATE_REF_FREQ_IN_KHZ;
- pixel_clk_params->flags.ENABLE_SS = 0;
- pixel_clk_params->color_depth =
- stream->timing.display_color_depth;
- pixel_clk_params->flags.DISPLAY_BLANKED = 1;
- pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
- if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
- pixel_clk_params->color_depth = COLOR_DEPTH_888;
- if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
- pixel_clk_params->requested_pix_clk /= 2;
- }
- static void build_clamping_params(struct dc_stream_state *stream)
- {
- stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
- stream->clamping.c_depth = stream->timing.display_color_depth;
- stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
- }
- static void build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
- {
- get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
- pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
- pipe_ctx->clock_source,
- &pipe_ctx->stream_res.pix_clk_params,
- &pipe_ctx->pll_settings);
- pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
- resource_build_bit_depth_reduction_params(pipe_ctx->stream,
- &pipe_ctx->stream->bit_depth_params);
- build_clamping_params(pipe_ctx->stream);
- }
- static enum dc_status build_mapped_resource(
- const struct dc *dc,
- struct dc_state *context,
- struct dc_stream_state *stream)
- {
- struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
- /*TODO Seems unneeded anymore */
- /* if (old_context && resource_is_stream_unchanged(old_context, stream)) {
- if (stream != NULL && old_context->streams[i] != NULL) {
- todo: shouldn't have to copy missing parameter here
- resource_build_bit_depth_reduction_params(stream,
- &stream->bit_depth_params);
- stream->clamping.pixel_encoding =
- stream->timing.pixel_encoding;
- resource_build_bit_depth_reduction_params(stream,
- &stream->bit_depth_params);
- build_clamping_params(stream);
- continue;
- }
- }
- */
- if (!pipe_ctx)
- return DC_ERROR_UNEXPECTED;
- build_pipe_hw_param(pipe_ctx);
- return DC_OK;
- }
- enum dc_status dcn10_add_stream_to_ctx(
- struct dc *dc,
- struct dc_state *new_ctx,
- struct dc_stream_state *dc_stream)
- {
- enum dc_status result = DC_ERROR_UNEXPECTED;
- result = resource_map_pool_resources(dc, new_ctx, dc_stream);
- if (result == DC_OK)
- result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
- if (result == DC_OK)
- result = build_mapped_resource(dc, new_ctx, dc_stream);
- return result;
- }
- static struct pipe_ctx *dcn10_acquire_idle_pipe_for_layer(
- struct dc_state *context,
- const struct resource_pool *pool,
- struct dc_stream_state *stream)
- {
- struct resource_context *res_ctx = &context->res_ctx;
- struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
- struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool);
- if (!head_pipe) {
- ASSERT(0);
- return NULL;
- }
- if (!idle_pipe)
- return NULL;
- idle_pipe->stream = head_pipe->stream;
- idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
- idle_pipe->stream_res.abm = head_pipe->stream_res.abm;
- idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
- idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
- idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
- idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
- idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;
- return idle_pipe;
- }
- static bool dcn10_get_dcc_compression_cap(const struct dc *dc,
- const struct dc_dcc_surface_param *input,
- struct dc_surface_dcc_cap *output)
- {
- return dc->res_pool->hubbub->funcs->get_dcc_compression_cap(
- dc->res_pool->hubbub,
- input,
- output);
- }
- static void dcn10_destroy_resource_pool(struct resource_pool **pool)
- {
- struct dcn10_resource_pool *dcn10_pool = TO_DCN10_RES_POOL(*pool);
- destruct(dcn10_pool);
- kfree(dcn10_pool);
- *pool = NULL;
- }
- static enum dc_status dcn10_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
- {
- if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
- && caps->max_video_width != 0
- && plane_state->src_rect.width > caps->max_video_width)
- return DC_FAIL_SURFACE_VALIDATE;
- return DC_OK;
- }
- static struct dc_cap_funcs cap_funcs = {
- .get_dcc_compression_cap = dcn10_get_dcc_compression_cap
- };
- static struct resource_funcs dcn10_res_pool_funcs = {
- .destroy = dcn10_destroy_resource_pool,
- .link_enc_create = dcn10_link_encoder_create,
- .validate_bandwidth = dcn_validate_bandwidth,
- .acquire_idle_pipe_for_layer = dcn10_acquire_idle_pipe_for_layer,
- .validate_plane = dcn10_validate_plane,
- .add_stream_to_ctx = dcn10_add_stream_to_ctx
- };
- static uint32_t read_pipe_fuses(struct dc_context *ctx)
- {
- uint32_t value = dm_read_reg_soc15(ctx, mmCC_DC_PIPE_DIS, 0);
- /* RV1 support max 4 pipes */
- value = value & 0xf;
- return value;
- }
- static bool construct(
- uint8_t num_virtual_links,
- struct dc *dc,
- struct dcn10_resource_pool *pool)
- {
- int i;
- int j;
- struct dc_context *ctx = dc->ctx;
- uint32_t pipe_fuses = read_pipe_fuses(ctx);
- ctx->dc_bios->regs = &bios_regs;
- pool->base.res_cap = &res_cap;
- pool->base.funcs = &dcn10_res_pool_funcs;
- /*
- * TODO fill in from actual raven resource when we create
- * more than virtual encoder
- */
- /*************************************************
- * Resource + asic cap harcoding *
- *************************************************/
- pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
- /* max pipe num for ASIC before check pipe fuses */
- pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
- dc->caps.max_video_width = 3840;
- dc->caps.max_downscale_ratio = 200;
- dc->caps.i2c_speed_in_khz = 100;
- dc->caps.max_cursor_size = 256;
- dc->caps.max_slave_planes = 1;
- dc->caps.is_apu = true;
- dc->caps.post_blend_color_processing = false;
- if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
- dc->debug = debug_defaults_drv;
- else
- dc->debug = debug_defaults_diags;
- /*************************************************
- * Create resources *
- *************************************************/
- pool->base.clock_sources[DCN10_CLK_SRC_PLL0] =
- dcn10_clock_source_create(ctx, ctx->dc_bios,
- CLOCK_SOURCE_COMBO_PHY_PLL0,
- &clk_src_regs[0], false);
- pool->base.clock_sources[DCN10_CLK_SRC_PLL1] =
- dcn10_clock_source_create(ctx, ctx->dc_bios,
- CLOCK_SOURCE_COMBO_PHY_PLL1,
- &clk_src_regs[1], false);
- pool->base.clock_sources[DCN10_CLK_SRC_PLL2] =
- dcn10_clock_source_create(ctx, ctx->dc_bios,
- CLOCK_SOURCE_COMBO_PHY_PLL2,
- &clk_src_regs[2], false);
- pool->base.clock_sources[DCN10_CLK_SRC_PLL3] =
- dcn10_clock_source_create(ctx, ctx->dc_bios,
- CLOCK_SOURCE_COMBO_PHY_PLL3,
- &clk_src_regs[3], false);
- pool->base.clk_src_count = DCN10_CLK_SRC_TOTAL;
- pool->base.dp_clock_source =
- dcn10_clock_source_create(ctx, ctx->dc_bios,
- CLOCK_SOURCE_ID_DP_DTO,
- /* todo: not reuse phy_pll registers */
- &clk_src_regs[0], true);
- for (i = 0; i < pool->base.clk_src_count; i++) {
- if (pool->base.clock_sources[i] == NULL) {
- dm_error("DC: failed to create clock sources!\n");
- BREAK_TO_DEBUGGER();
- goto fail;
- }
- }
- pool->base.display_clock = dce120_disp_clk_create(ctx);
- if (pool->base.display_clock == NULL) {
- dm_error("DC: failed to create display clock!\n");
- BREAK_TO_DEBUGGER();
- goto fail;
- }
- pool->base.dmcu = dcn10_dmcu_create(ctx,
- &dmcu_regs,
- &dmcu_shift,
- &dmcu_mask);
- if (pool->base.dmcu == NULL) {
- dm_error("DC: failed to create dmcu!\n");
- BREAK_TO_DEBUGGER();
- goto fail;
- }
- pool->base.abm = dce_abm_create(ctx,
- &abm_regs,
- &abm_shift,
- &abm_mask);
- if (pool->base.abm == NULL) {
- dm_error("DC: failed to create abm!\n");
- BREAK_TO_DEBUGGER();
- goto fail;
- }
- dml_init_instance(&dc->dml, DML_PROJECT_RAVEN1);
- memcpy(dc->dcn_ip, &dcn10_ip_defaults, sizeof(dcn10_ip_defaults));
- memcpy(dc->dcn_soc, &dcn10_soc_defaults, sizeof(dcn10_soc_defaults));
- if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
- dc->dcn_soc->urgent_latency = 3;
- dc->debug.disable_dmcu = true;
- dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 41.60f;
- }
- dc->dcn_soc->number_of_channels = dc->ctx->asic_id.vram_width / ddr4_dram_width;
- ASSERT(dc->dcn_soc->number_of_channels < 3);
- if (dc->dcn_soc->number_of_channels == 0)/*old sbios bug*/
- dc->dcn_soc->number_of_channels = 2;
- if (dc->dcn_soc->number_of_channels == 1) {
- dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 19.2f;
- dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 = 17.066f;
- dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 = 14.933f;
- dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 = 12.8f;
- if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
- dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 20.80f;
- }
- }
- pool->base.pp_smu = dcn10_pp_smu_create(ctx);
- if (!dc->debug.disable_pplib_clock_request)
- dcn_bw_update_from_pplib(dc);
- dcn_bw_sync_calcs_and_dml(dc);
- if (!dc->debug.disable_pplib_wm_range) {
- dc->res_pool = &pool->base;
- dcn_bw_notify_pplib_of_wm_ranges(dc);
- }
- {
- struct irq_service_init_data init_data;
- init_data.ctx = dc->ctx;
- pool->base.irqs = dal_irq_service_dcn10_create(&init_data);
- if (!pool->base.irqs)
- goto fail;
- }
- /* index to valid pipe resource */
- j = 0;
- /* mem input -> ipp -> dpp -> opp -> TG */
- for (i = 0; i < pool->base.pipe_count; i++) {
- /* if pipe is disabled, skip instance of HW pipe,
- * i.e, skip ASIC register instance
- */
- if ((pipe_fuses & (1 << i)) != 0)
- continue;
- pool->base.hubps[j] = dcn10_hubp_create(ctx, i);
- if (pool->base.hubps[j] == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error(
- "DC: failed to create memory input!\n");
- goto fail;
- }
- pool->base.ipps[j] = dcn10_ipp_create(ctx, i);
- if (pool->base.ipps[j] == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error(
- "DC: failed to create input pixel processor!\n");
- goto fail;
- }
- pool->base.dpps[j] = dcn10_dpp_create(ctx, i);
- if (pool->base.dpps[j] == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error(
- "DC: failed to create dpp!\n");
- goto fail;
- }
- pool->base.opps[j] = dcn10_opp_create(ctx, i);
- if (pool->base.opps[j] == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error(
- "DC: failed to create output pixel processor!\n");
- goto fail;
- }
- pool->base.timing_generators[j] = dcn10_timing_generator_create(
- ctx, i);
- if (pool->base.timing_generators[j] == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error("DC: failed to create tg!\n");
- goto fail;
- }
- /* check next valid pipe */
- j++;
- }
- /* valid pipe num */
- pool->base.pipe_count = j;
- pool->base.timing_generator_count = j;
- /* within dml lib, it is hard code to 4. If ASIC pipe is fused,
- * the value may be changed
- */
- dc->dml.ip.max_num_dpp = pool->base.pipe_count;
- dc->dcn_ip->max_num_dpp = pool->base.pipe_count;
- pool->base.mpc = dcn10_mpc_create(ctx);
- if (pool->base.mpc == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error("DC: failed to create mpc!\n");
- goto fail;
- }
- pool->base.hubbub = dcn10_hubbub_create(ctx);
- if (pool->base.hubbub == NULL) {
- BREAK_TO_DEBUGGER();
- dm_error("DC: failed to create hubbub!\n");
- goto fail;
- }
- if (!resource_construct(num_virtual_links, dc, &pool->base,
- (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
- &res_create_funcs : &res_create_maximus_funcs)))
- goto fail;
- dcn10_hw_sequencer_construct(dc);
- dc->caps.max_planes = pool->base.pipe_count;
- dc->cap_funcs = cap_funcs;
- return true;
- fail:
- destruct(pool);
- return false;
- }
- struct resource_pool *dcn10_create_resource_pool(
- uint8_t num_virtual_links,
- struct dc *dc)
- {
- struct dcn10_resource_pool *pool =
- kzalloc(sizeof(struct dcn10_resource_pool), GFP_KERNEL);
- if (!pool)
- return NULL;
- if (construct(num_virtual_links, dc, pool))
- return &pool->base;
- BREAK_TO_DEBUGGER();
- return NULL;
- }
|