dcn10_resource.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. /*
  2. * Copyright 2016 Advanced Micro Devices, Inc.
  3. *
  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:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  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.
  21. *
  22. * Authors: AMD
  23. *
  24. */
  25. #include "dm_services.h"
  26. #include "dc.h"
  27. #include "resource.h"
  28. #include "include/irq_service_interface.h"
  29. #include "dcn10/dcn10_resource.h"
  30. #include "dcn10/dcn10_ipp.h"
  31. #include "dcn10/dcn10_mpc.h"
  32. #include "irq/dcn10/irq_service_dcn10.h"
  33. #include "dcn10/dcn10_dpp.h"
  34. #include "dcn10_optc.h"
  35. #include "dcn10/dcn10_hw_sequencer.h"
  36. #include "dce110/dce110_hw_sequencer.h"
  37. #include "dcn10/dcn10_opp.h"
  38. #include "dce/dce_link_encoder.h"
  39. #include "dce/dce_stream_encoder.h"
  40. #include "dce/dce_clocks.h"
  41. #include "dce/dce_clock_source.h"
  42. #include "dce/dce_audio.h"
  43. #include "dce/dce_hwseq.h"
  44. #include "../virtual/virtual_stream_encoder.h"
  45. #include "dce110/dce110_resource.h"
  46. #include "dce112/dce112_resource.h"
  47. #include "dcn10_hubp.h"
  48. #include "dcn10_hubbub.h"
  49. #include "soc15_hw_ip.h"
  50. #include "vega10_ip_offset.h"
  51. #include "dcn/dcn_1_0_offset.h"
  52. #include "dcn/dcn_1_0_sh_mask.h"
  53. #include "nbio/nbio_7_0_offset.h"
  54. #include "mmhub/mmhub_9_1_offset.h"
  55. #include "mmhub/mmhub_9_1_sh_mask.h"
  56. #include "reg_helper.h"
  57. #include "dce/dce_abm.h"
  58. #include "dce/dce_dmcu.h"
  59. #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
  60. #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x210f
  61. #define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  62. #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x220f
  63. #define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  64. #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x230f
  65. #define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  66. #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x240f
  67. #define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  68. #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x250f
  69. #define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  70. #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x260f
  71. #define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  72. #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x270f
  73. #define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
  74. #endif
  75. enum dcn10_clk_src_array_id {
  76. DCN10_CLK_SRC_PLL0,
  77. DCN10_CLK_SRC_PLL1,
  78. DCN10_CLK_SRC_PLL2,
  79. DCN10_CLK_SRC_PLL3,
  80. DCN10_CLK_SRC_TOTAL
  81. };
  82. /* begin *********************
  83. * macros to expend register list macro defined in HW object header file */
  84. /* DCN */
  85. #define BASE_INNER(seg) \
  86. DCE_BASE__INST0_SEG ## seg
  87. #define BASE(seg) \
  88. BASE_INNER(seg)
  89. #define SR(reg_name)\
  90. .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
  91. mm ## reg_name
  92. #define SRI(reg_name, block, id)\
  93. .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
  94. mm ## block ## id ## _ ## reg_name
  95. #define SRII(reg_name, block, id)\
  96. .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
  97. mm ## block ## id ## _ ## reg_name
  98. /* NBIO */
  99. #define NBIO_BASE_INNER(seg) \
  100. NBIF_BASE__INST0_SEG ## seg
  101. #define NBIO_BASE(seg) \
  102. NBIO_BASE_INNER(seg)
  103. #define NBIO_SR(reg_name)\
  104. .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
  105. mm ## reg_name
  106. /* MMHUB */
  107. #define MMHUB_BASE_INNER(seg) \
  108. MMHUB_BASE__INST0_SEG ## seg
  109. #define MMHUB_BASE(seg) \
  110. MMHUB_BASE_INNER(seg)
  111. #define MMHUB_SR(reg_name)\
  112. .reg_name = MMHUB_BASE(mm ## reg_name ## _BASE_IDX) + \
  113. mm ## reg_name
  114. /* macros to expend register list macro defined in HW object header file
  115. * end *********************/
  116. static const struct dce_dmcu_registers dmcu_regs = {
  117. DMCU_DCN10_REG_LIST()
  118. };
  119. static const struct dce_dmcu_shift dmcu_shift = {
  120. DMCU_MASK_SH_LIST_DCN10(__SHIFT)
  121. };
  122. static const struct dce_dmcu_mask dmcu_mask = {
  123. DMCU_MASK_SH_LIST_DCN10(_MASK)
  124. };
  125. static const struct dce_abm_registers abm_regs = {
  126. ABM_DCN10_REG_LIST(0)
  127. };
  128. static const struct dce_abm_shift abm_shift = {
  129. ABM_MASK_SH_LIST_DCN10(__SHIFT)
  130. };
  131. static const struct dce_abm_mask abm_mask = {
  132. ABM_MASK_SH_LIST_DCN10(_MASK)
  133. };
  134. #define stream_enc_regs(id)\
  135. [id] = {\
  136. SE_DCN_REG_LIST(id),\
  137. .TMDS_CNTL = 0,\
  138. .AFMT_AVI_INFO0 = 0,\
  139. .AFMT_AVI_INFO1 = 0,\
  140. .AFMT_AVI_INFO2 = 0,\
  141. .AFMT_AVI_INFO3 = 0,\
  142. }
  143. static const struct dce110_stream_enc_registers stream_enc_regs[] = {
  144. stream_enc_regs(0),
  145. stream_enc_regs(1),
  146. stream_enc_regs(2),
  147. stream_enc_regs(3),
  148. };
  149. static const struct dce_stream_encoder_shift se_shift = {
  150. SE_COMMON_MASK_SH_LIST_DCN10(__SHIFT)
  151. };
  152. static const struct dce_stream_encoder_mask se_mask = {
  153. SE_COMMON_MASK_SH_LIST_DCN10(_MASK),
  154. .AFMT_GENERIC0_UPDATE = 0,
  155. .AFMT_GENERIC2_UPDATE = 0,
  156. .DP_DYN_RANGE = 0,
  157. .DP_YCBCR_RANGE = 0,
  158. .HDMI_AVI_INFO_SEND = 0,
  159. .HDMI_AVI_INFO_CONT = 0,
  160. .HDMI_AVI_INFO_LINE = 0,
  161. .DP_SEC_AVI_ENABLE = 0,
  162. .AFMT_AVI_INFO_VERSION = 0
  163. };
  164. #define audio_regs(id)\
  165. [id] = {\
  166. AUD_COMMON_REG_LIST(id)\
  167. }
  168. static const struct dce_audio_registers audio_regs[] = {
  169. audio_regs(0),
  170. audio_regs(1),
  171. audio_regs(2),
  172. audio_regs(3),
  173. };
  174. #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
  175. SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
  176. SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
  177. AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
  178. static const struct dce_audio_shift audio_shift = {
  179. DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
  180. };
  181. static const struct dce_aduio_mask audio_mask = {
  182. DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
  183. };
  184. #define aux_regs(id)\
  185. [id] = {\
  186. AUX_REG_LIST(id)\
  187. }
  188. static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
  189. aux_regs(0),
  190. aux_regs(1),
  191. aux_regs(2),
  192. aux_regs(3),
  193. aux_regs(4),
  194. aux_regs(5)
  195. };
  196. #define hpd_regs(id)\
  197. [id] = {\
  198. HPD_REG_LIST(id)\
  199. }
  200. static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
  201. hpd_regs(0),
  202. hpd_regs(1),
  203. hpd_regs(2),
  204. hpd_regs(3),
  205. hpd_regs(4),
  206. hpd_regs(5)
  207. };
  208. #define link_regs(id)\
  209. [id] = {\
  210. LE_DCN10_REG_LIST(id), \
  211. SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
  212. }
  213. static const struct dce110_link_enc_registers link_enc_regs[] = {
  214. link_regs(0),
  215. link_regs(1),
  216. link_regs(2),
  217. link_regs(3),
  218. link_regs(4),
  219. link_regs(5),
  220. link_regs(6),
  221. };
  222. #define ipp_regs(id)\
  223. [id] = {\
  224. IPP_REG_LIST_DCN10(id),\
  225. }
  226. static const struct dcn10_ipp_registers ipp_regs[] = {
  227. ipp_regs(0),
  228. ipp_regs(1),
  229. ipp_regs(2),
  230. ipp_regs(3),
  231. };
  232. static const struct dcn10_ipp_shift ipp_shift = {
  233. IPP_MASK_SH_LIST_DCN10(__SHIFT)
  234. };
  235. static const struct dcn10_ipp_mask ipp_mask = {
  236. IPP_MASK_SH_LIST_DCN10(_MASK),
  237. };
  238. #define opp_regs(id)\
  239. [id] = {\
  240. OPP_REG_LIST_DCN10(id),\
  241. }
  242. static const struct dcn10_opp_registers opp_regs[] = {
  243. opp_regs(0),
  244. opp_regs(1),
  245. opp_regs(2),
  246. opp_regs(3),
  247. };
  248. static const struct dcn10_opp_shift opp_shift = {
  249. OPP_MASK_SH_LIST_DCN10(__SHIFT)
  250. };
  251. static const struct dcn10_opp_mask opp_mask = {
  252. OPP_MASK_SH_LIST_DCN10(_MASK),
  253. };
  254. #define tf_regs(id)\
  255. [id] = {\
  256. TF_REG_LIST_DCN10(id),\
  257. }
  258. static const struct dcn_dpp_registers tf_regs[] = {
  259. tf_regs(0),
  260. tf_regs(1),
  261. tf_regs(2),
  262. tf_regs(3),
  263. };
  264. static const struct dcn_dpp_shift tf_shift = {
  265. TF_REG_LIST_SH_MASK_DCN10(__SHIFT)
  266. };
  267. static const struct dcn_dpp_mask tf_mask = {
  268. TF_REG_LIST_SH_MASK_DCN10(_MASK),
  269. };
  270. static const struct dcn_mpc_registers mpc_regs = {
  271. MPC_COMMON_REG_LIST_DCN1_0(0),
  272. MPC_COMMON_REG_LIST_DCN1_0(1),
  273. MPC_COMMON_REG_LIST_DCN1_0(2),
  274. MPC_COMMON_REG_LIST_DCN1_0(3),
  275. MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(0),
  276. MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(1),
  277. MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(2),
  278. MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(3)
  279. };
  280. static const struct dcn_mpc_shift mpc_shift = {
  281. MPC_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
  282. };
  283. static const struct dcn_mpc_mask mpc_mask = {
  284. MPC_COMMON_MASK_SH_LIST_DCN1_0(_MASK),
  285. };
  286. #define tg_regs(id)\
  287. [id] = {TG_COMMON_REG_LIST_DCN1_0(id)}
  288. static const struct dcn_optc_registers tg_regs[] = {
  289. tg_regs(0),
  290. tg_regs(1),
  291. tg_regs(2),
  292. tg_regs(3),
  293. };
  294. static const struct dcn_optc_shift tg_shift = {
  295. TG_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
  296. };
  297. static const struct dcn_optc_mask tg_mask = {
  298. TG_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
  299. };
  300. static const struct bios_registers bios_regs = {
  301. NBIO_SR(BIOS_SCRATCH_3),
  302. NBIO_SR(BIOS_SCRATCH_6)
  303. };
  304. #define hubp_regs(id)\
  305. [id] = {\
  306. HUBP_REG_LIST_DCN10(id)\
  307. }
  308. static const struct dcn_mi_registers hubp_regs[] = {
  309. hubp_regs(0),
  310. hubp_regs(1),
  311. hubp_regs(2),
  312. hubp_regs(3),
  313. };
  314. static const struct dcn_mi_shift hubp_shift = {
  315. HUBP_MASK_SH_LIST_DCN10(__SHIFT)
  316. };
  317. static const struct dcn_mi_mask hubp_mask = {
  318. HUBP_MASK_SH_LIST_DCN10(_MASK)
  319. };
  320. static const struct dcn_hubbub_registers hubbub_reg = {
  321. HUBBUB_REG_LIST_DCN10(0)
  322. };
  323. static const struct dcn_hubbub_shift hubbub_shift = {
  324. HUBBUB_MASK_SH_LIST_DCN10(__SHIFT)
  325. };
  326. static const struct dcn_hubbub_mask hubbub_mask = {
  327. HUBBUB_MASK_SH_LIST_DCN10(_MASK)
  328. };
  329. #define clk_src_regs(index, pllid)\
  330. [index] = {\
  331. CS_COMMON_REG_LIST_DCN1_0(index, pllid),\
  332. }
  333. static const struct dce110_clk_src_regs clk_src_regs[] = {
  334. clk_src_regs(0, A),
  335. clk_src_regs(1, B),
  336. clk_src_regs(2, C),
  337. clk_src_regs(3, D)
  338. };
  339. static const struct dce110_clk_src_shift cs_shift = {
  340. CS_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
  341. };
  342. static const struct dce110_clk_src_mask cs_mask = {
  343. CS_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
  344. };
  345. static const struct resource_caps res_cap = {
  346. .num_timing_generator = 4,
  347. .num_video_plane = 4,
  348. .num_audio = 4,
  349. .num_stream_encoder = 4,
  350. .num_pll = 4,
  351. };
  352. static const struct dc_debug debug_defaults_drv = {
  353. .sanity_checks = true,
  354. .disable_dmcu = true,
  355. .force_abm_enable = false,
  356. .timing_trace = false,
  357. .clock_trace = true,
  358. .min_disp_clk_khz = 300000,
  359. .disable_pplib_clock_request = true,
  360. .disable_pplib_wm_range = false,
  361. .pplib_wm_report_mode = WM_REPORT_DEFAULT,
  362. .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
  363. .force_single_disp_pipe_split = true,
  364. .disable_dcc = DCC_ENABLE,
  365. .voltage_align_fclk = true,
  366. .disable_stereo_support = true,
  367. .vsr_support = true,
  368. .performance_trace = false,
  369. .az_endpoint_mute_only = true,
  370. };
  371. static const struct dc_debug debug_defaults_diags = {
  372. .disable_dmcu = true,
  373. .force_abm_enable = false,
  374. .timing_trace = true,
  375. .clock_trace = true,
  376. .disable_stutter = true,
  377. .disable_pplib_clock_request = true,
  378. .disable_pplib_wm_range = true
  379. };
  380. static void dcn10_dpp_destroy(struct dpp **dpp)
  381. {
  382. kfree(TO_DCN10_DPP(*dpp));
  383. *dpp = NULL;
  384. }
  385. static struct dpp *dcn10_dpp_create(
  386. struct dc_context *ctx,
  387. uint32_t inst)
  388. {
  389. struct dcn10_dpp *dpp =
  390. kzalloc(sizeof(struct dcn10_dpp), GFP_KERNEL);
  391. if (!dpp)
  392. return NULL;
  393. dpp1_construct(dpp, ctx, inst,
  394. &tf_regs[inst], &tf_shift, &tf_mask);
  395. return &dpp->base;
  396. }
  397. static struct input_pixel_processor *dcn10_ipp_create(
  398. struct dc_context *ctx, uint32_t inst)
  399. {
  400. struct dcn10_ipp *ipp =
  401. kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL);
  402. if (!ipp) {
  403. BREAK_TO_DEBUGGER();
  404. return NULL;
  405. }
  406. dcn10_ipp_construct(ipp, ctx, inst,
  407. &ipp_regs[inst], &ipp_shift, &ipp_mask);
  408. return &ipp->base;
  409. }
  410. static struct output_pixel_processor *dcn10_opp_create(
  411. struct dc_context *ctx, uint32_t inst)
  412. {
  413. struct dcn10_opp *opp =
  414. kzalloc(sizeof(struct dcn10_opp), GFP_KERNEL);
  415. if (!opp) {
  416. BREAK_TO_DEBUGGER();
  417. return NULL;
  418. }
  419. dcn10_opp_construct(opp, ctx, inst,
  420. &opp_regs[inst], &opp_shift, &opp_mask);
  421. return &opp->base;
  422. }
  423. static struct mpc *dcn10_mpc_create(struct dc_context *ctx)
  424. {
  425. struct dcn10_mpc *mpc10 = kzalloc(sizeof(struct dcn10_mpc),
  426. GFP_KERNEL);
  427. if (!mpc10)
  428. return NULL;
  429. dcn10_mpc_construct(mpc10, ctx,
  430. &mpc_regs,
  431. &mpc_shift,
  432. &mpc_mask,
  433. 4);
  434. return &mpc10->base;
  435. }
  436. static struct hubbub *dcn10_hubbub_create(struct dc_context *ctx)
  437. {
  438. struct hubbub *hubbub = kzalloc(sizeof(struct hubbub),
  439. GFP_KERNEL);
  440. if (!hubbub)
  441. return NULL;
  442. hubbub1_construct(hubbub, ctx,
  443. &hubbub_reg,
  444. &hubbub_shift,
  445. &hubbub_mask);
  446. return hubbub;
  447. }
  448. static struct timing_generator *dcn10_timing_generator_create(
  449. struct dc_context *ctx,
  450. uint32_t instance)
  451. {
  452. struct optc *tgn10 =
  453. kzalloc(sizeof(struct optc), GFP_KERNEL);
  454. if (!tgn10)
  455. return NULL;
  456. tgn10->base.inst = instance;
  457. tgn10->base.ctx = ctx;
  458. tgn10->tg_regs = &tg_regs[instance];
  459. tgn10->tg_shift = &tg_shift;
  460. tgn10->tg_mask = &tg_mask;
  461. dcn10_timing_generator_init(tgn10);
  462. return &tgn10->base;
  463. }
  464. static const struct encoder_feature_support link_enc_feature = {
  465. .max_hdmi_deep_color = COLOR_DEPTH_121212,
  466. .max_hdmi_pixel_clock = 600000,
  467. .ycbcr420_supported = true,
  468. .flags.bits.IS_HBR2_CAPABLE = true,
  469. .flags.bits.IS_HBR3_CAPABLE = true,
  470. .flags.bits.IS_TPS3_CAPABLE = true,
  471. .flags.bits.IS_TPS4_CAPABLE = true,
  472. .flags.bits.IS_YCBCR_CAPABLE = true
  473. };
  474. struct link_encoder *dcn10_link_encoder_create(
  475. const struct encoder_init_data *enc_init_data)
  476. {
  477. struct dce110_link_encoder *enc110 =
  478. kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
  479. if (!enc110)
  480. return NULL;
  481. dce110_link_encoder_construct(enc110,
  482. enc_init_data,
  483. &link_enc_feature,
  484. &link_enc_regs[enc_init_data->transmitter],
  485. &link_enc_aux_regs[enc_init_data->channel - 1],
  486. &link_enc_hpd_regs[enc_init_data->hpd_source]);
  487. return &enc110->base;
  488. }
  489. struct clock_source *dcn10_clock_source_create(
  490. struct dc_context *ctx,
  491. struct dc_bios *bios,
  492. enum clock_source_id id,
  493. const struct dce110_clk_src_regs *regs,
  494. bool dp_clk_src)
  495. {
  496. struct dce110_clk_src *clk_src =
  497. kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
  498. if (!clk_src)
  499. return NULL;
  500. if (dce110_clk_src_construct(clk_src, ctx, bios, id,
  501. regs, &cs_shift, &cs_mask)) {
  502. clk_src->base.dp_clk_src = dp_clk_src;
  503. return &clk_src->base;
  504. }
  505. BREAK_TO_DEBUGGER();
  506. return NULL;
  507. }
  508. static void read_dce_straps(
  509. struct dc_context *ctx,
  510. struct resource_straps *straps)
  511. {
  512. generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
  513. FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
  514. }
  515. static struct audio *create_audio(
  516. struct dc_context *ctx, unsigned int inst)
  517. {
  518. return dce_audio_create(ctx, inst,
  519. &audio_regs[inst], &audio_shift, &audio_mask);
  520. }
  521. static struct stream_encoder *dcn10_stream_encoder_create(
  522. enum engine_id eng_id,
  523. struct dc_context *ctx)
  524. {
  525. struct dce110_stream_encoder *enc110 =
  526. kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
  527. if (!enc110)
  528. return NULL;
  529. dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
  530. &stream_enc_regs[eng_id],
  531. &se_shift, &se_mask);
  532. return &enc110->base;
  533. }
  534. static const struct dce_hwseq_registers hwseq_reg = {
  535. HWSEQ_DCN1_REG_LIST()
  536. };
  537. static const struct dce_hwseq_shift hwseq_shift = {
  538. HWSEQ_DCN1_MASK_SH_LIST(__SHIFT)
  539. };
  540. static const struct dce_hwseq_mask hwseq_mask = {
  541. HWSEQ_DCN1_MASK_SH_LIST(_MASK)
  542. };
  543. static struct dce_hwseq *dcn10_hwseq_create(
  544. struct dc_context *ctx)
  545. {
  546. struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
  547. if (hws) {
  548. hws->ctx = ctx;
  549. hws->regs = &hwseq_reg;
  550. hws->shifts = &hwseq_shift;
  551. hws->masks = &hwseq_mask;
  552. hws->wa.DEGVIDCN10_253 = true;
  553. hws->wa.false_optc_underflow = true;
  554. }
  555. return hws;
  556. }
  557. static const struct resource_create_funcs res_create_funcs = {
  558. .read_dce_straps = read_dce_straps,
  559. .create_audio = create_audio,
  560. .create_stream_encoder = dcn10_stream_encoder_create,
  561. .create_hwseq = dcn10_hwseq_create,
  562. };
  563. static const struct resource_create_funcs res_create_maximus_funcs = {
  564. .read_dce_straps = NULL,
  565. .create_audio = NULL,
  566. .create_stream_encoder = NULL,
  567. .create_hwseq = dcn10_hwseq_create,
  568. };
  569. void dcn10_clock_source_destroy(struct clock_source **clk_src)
  570. {
  571. kfree(TO_DCE110_CLK_SRC(*clk_src));
  572. *clk_src = NULL;
  573. }
  574. static struct pp_smu_funcs_rv *dcn10_pp_smu_create(struct dc_context *ctx)
  575. {
  576. struct pp_smu_funcs_rv *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
  577. if (!pp_smu)
  578. return pp_smu;
  579. dm_pp_get_funcs_rv(ctx, pp_smu);
  580. return pp_smu;
  581. }
  582. static void destruct(struct dcn10_resource_pool *pool)
  583. {
  584. unsigned int i;
  585. for (i = 0; i < pool->base.stream_enc_count; i++) {
  586. if (pool->base.stream_enc[i] != NULL) {
  587. /* TODO: free dcn version of stream encoder once implemented
  588. * rather than using virtual stream encoder
  589. */
  590. kfree(pool->base.stream_enc[i]);
  591. pool->base.stream_enc[i] = NULL;
  592. }
  593. }
  594. if (pool->base.mpc != NULL) {
  595. kfree(TO_DCN10_MPC(pool->base.mpc));
  596. pool->base.mpc = NULL;
  597. }
  598. if (pool->base.hubbub != NULL) {
  599. kfree(pool->base.hubbub);
  600. pool->base.hubbub = NULL;
  601. }
  602. for (i = 0; i < pool->base.pipe_count; i++) {
  603. if (pool->base.opps[i] != NULL)
  604. pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
  605. if (pool->base.dpps[i] != NULL)
  606. dcn10_dpp_destroy(&pool->base.dpps[i]);
  607. if (pool->base.ipps[i] != NULL)
  608. pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
  609. if (pool->base.hubps[i] != NULL) {
  610. kfree(TO_DCN10_HUBP(pool->base.hubps[i]));
  611. pool->base.hubps[i] = NULL;
  612. }
  613. if (pool->base.irqs != NULL) {
  614. dal_irq_service_destroy(&pool->base.irqs);
  615. }
  616. if (pool->base.timing_generators[i] != NULL) {
  617. kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
  618. pool->base.timing_generators[i] = NULL;
  619. }
  620. }
  621. for (i = 0; i < pool->base.stream_enc_count; i++)
  622. kfree(pool->base.stream_enc[i]);
  623. for (i = 0; i < pool->base.audio_count; i++) {
  624. if (pool->base.audios[i])
  625. dce_aud_destroy(&pool->base.audios[i]);
  626. }
  627. for (i = 0; i < pool->base.clk_src_count; i++) {
  628. if (pool->base.clock_sources[i] != NULL) {
  629. dcn10_clock_source_destroy(&pool->base.clock_sources[i]);
  630. pool->base.clock_sources[i] = NULL;
  631. }
  632. }
  633. if (pool->base.dp_clock_source != NULL) {
  634. dcn10_clock_source_destroy(&pool->base.dp_clock_source);
  635. pool->base.dp_clock_source = NULL;
  636. }
  637. if (pool->base.abm != NULL)
  638. dce_abm_destroy(&pool->base.abm);
  639. if (pool->base.dmcu != NULL)
  640. dce_dmcu_destroy(&pool->base.dmcu);
  641. if (pool->base.display_clock != NULL)
  642. dce_disp_clk_destroy(&pool->base.display_clock);
  643. kfree(pool->base.pp_smu);
  644. }
  645. static struct hubp *dcn10_hubp_create(
  646. struct dc_context *ctx,
  647. uint32_t inst)
  648. {
  649. struct dcn10_hubp *hubp1 =
  650. kzalloc(sizeof(struct dcn10_hubp), GFP_KERNEL);
  651. if (!hubp1)
  652. return NULL;
  653. dcn10_hubp_construct(hubp1, ctx, inst,
  654. &hubp_regs[inst], &hubp_shift, &hubp_mask);
  655. return &hubp1->base;
  656. }
  657. static void get_pixel_clock_parameters(
  658. const struct pipe_ctx *pipe_ctx,
  659. struct pixel_clk_params *pixel_clk_params)
  660. {
  661. const struct dc_stream_state *stream = pipe_ctx->stream;
  662. pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
  663. pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
  664. pixel_clk_params->signal_type = pipe_ctx->stream->signal;
  665. pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
  666. /* TODO: un-hardcode*/
  667. pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
  668. LINK_RATE_REF_FREQ_IN_KHZ;
  669. pixel_clk_params->flags.ENABLE_SS = 0;
  670. pixel_clk_params->color_depth =
  671. stream->timing.display_color_depth;
  672. pixel_clk_params->flags.DISPLAY_BLANKED = 1;
  673. pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
  674. if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
  675. pixel_clk_params->color_depth = COLOR_DEPTH_888;
  676. if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
  677. pixel_clk_params->requested_pix_clk /= 2;
  678. }
  679. static void build_clamping_params(struct dc_stream_state *stream)
  680. {
  681. stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
  682. stream->clamping.c_depth = stream->timing.display_color_depth;
  683. stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
  684. }
  685. static void build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
  686. {
  687. get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
  688. pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
  689. pipe_ctx->clock_source,
  690. &pipe_ctx->stream_res.pix_clk_params,
  691. &pipe_ctx->pll_settings);
  692. pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
  693. resource_build_bit_depth_reduction_params(pipe_ctx->stream,
  694. &pipe_ctx->stream->bit_depth_params);
  695. build_clamping_params(pipe_ctx->stream);
  696. }
  697. static enum dc_status build_mapped_resource(
  698. const struct dc *dc,
  699. struct dc_state *context,
  700. struct dc_stream_state *stream)
  701. {
  702. struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
  703. /*TODO Seems unneeded anymore */
  704. /* if (old_context && resource_is_stream_unchanged(old_context, stream)) {
  705. if (stream != NULL && old_context->streams[i] != NULL) {
  706. todo: shouldn't have to copy missing parameter here
  707. resource_build_bit_depth_reduction_params(stream,
  708. &stream->bit_depth_params);
  709. stream->clamping.pixel_encoding =
  710. stream->timing.pixel_encoding;
  711. resource_build_bit_depth_reduction_params(stream,
  712. &stream->bit_depth_params);
  713. build_clamping_params(stream);
  714. continue;
  715. }
  716. }
  717. */
  718. if (!pipe_ctx)
  719. return DC_ERROR_UNEXPECTED;
  720. build_pipe_hw_param(pipe_ctx);
  721. return DC_OK;
  722. }
  723. enum dc_status dcn10_add_stream_to_ctx(
  724. struct dc *dc,
  725. struct dc_state *new_ctx,
  726. struct dc_stream_state *dc_stream)
  727. {
  728. enum dc_status result = DC_ERROR_UNEXPECTED;
  729. result = resource_map_pool_resources(dc, new_ctx, dc_stream);
  730. if (result == DC_OK)
  731. result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
  732. if (result == DC_OK)
  733. result = build_mapped_resource(dc, new_ctx, dc_stream);
  734. return result;
  735. }
  736. enum dc_status dcn10_validate_guaranteed(
  737. struct dc *dc,
  738. struct dc_stream_state *dc_stream,
  739. struct dc_state *context)
  740. {
  741. enum dc_status result = DC_ERROR_UNEXPECTED;
  742. context->streams[0] = dc_stream;
  743. dc_stream_retain(context->streams[0]);
  744. context->stream_count++;
  745. result = resource_map_pool_resources(dc, context, dc_stream);
  746. if (result == DC_OK)
  747. result = resource_map_phy_clock_resources(dc, context, dc_stream);
  748. if (result == DC_OK)
  749. result = build_mapped_resource(dc, context, dc_stream);
  750. if (result == DC_OK) {
  751. validate_guaranteed_copy_streams(
  752. context, dc->caps.max_streams);
  753. result = resource_build_scaling_params_for_context(dc, context);
  754. }
  755. if (result == DC_OK && !dcn_validate_bandwidth(dc, context))
  756. return DC_FAIL_BANDWIDTH_VALIDATE;
  757. return result;
  758. }
  759. static struct pipe_ctx *dcn10_acquire_idle_pipe_for_layer(
  760. struct dc_state *context,
  761. const struct resource_pool *pool,
  762. struct dc_stream_state *stream)
  763. {
  764. struct resource_context *res_ctx = &context->res_ctx;
  765. struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
  766. struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool);
  767. if (!head_pipe) {
  768. ASSERT(0);
  769. return NULL;
  770. }
  771. if (!idle_pipe)
  772. return NULL;
  773. idle_pipe->stream = head_pipe->stream;
  774. idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
  775. idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
  776. idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
  777. idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
  778. idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
  779. idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;
  780. return idle_pipe;
  781. }
  782. enum dcc_control {
  783. dcc_control__256_256_xxx,
  784. dcc_control__128_128_xxx,
  785. dcc_control__256_64_64,
  786. };
  787. enum segment_order {
  788. segment_order__na,
  789. segment_order__contiguous,
  790. segment_order__non_contiguous,
  791. };
  792. static bool dcc_support_pixel_format(
  793. enum surface_pixel_format format,
  794. unsigned int *bytes_per_element)
  795. {
  796. /* DML: get_bytes_per_element */
  797. switch (format) {
  798. case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
  799. case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
  800. *bytes_per_element = 2;
  801. return true;
  802. case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
  803. case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
  804. case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
  805. case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
  806. *bytes_per_element = 4;
  807. return true;
  808. case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
  809. case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
  810. case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
  811. *bytes_per_element = 8;
  812. return true;
  813. default:
  814. return false;
  815. }
  816. }
  817. static bool dcc_support_swizzle(
  818. enum swizzle_mode_values swizzle,
  819. unsigned int bytes_per_element,
  820. enum segment_order *segment_order_horz,
  821. enum segment_order *segment_order_vert)
  822. {
  823. bool standard_swizzle = false;
  824. bool display_swizzle = false;
  825. switch (swizzle) {
  826. case DC_SW_4KB_S:
  827. case DC_SW_64KB_S:
  828. case DC_SW_VAR_S:
  829. case DC_SW_4KB_S_X:
  830. case DC_SW_64KB_S_X:
  831. case DC_SW_VAR_S_X:
  832. standard_swizzle = true;
  833. break;
  834. case DC_SW_4KB_D:
  835. case DC_SW_64KB_D:
  836. case DC_SW_VAR_D:
  837. case DC_SW_4KB_D_X:
  838. case DC_SW_64KB_D_X:
  839. case DC_SW_VAR_D_X:
  840. display_swizzle = true;
  841. break;
  842. default:
  843. break;
  844. }
  845. if (bytes_per_element == 1 && standard_swizzle) {
  846. *segment_order_horz = segment_order__contiguous;
  847. *segment_order_vert = segment_order__na;
  848. return true;
  849. }
  850. if (bytes_per_element == 2 && standard_swizzle) {
  851. *segment_order_horz = segment_order__non_contiguous;
  852. *segment_order_vert = segment_order__contiguous;
  853. return true;
  854. }
  855. if (bytes_per_element == 4 && standard_swizzle) {
  856. *segment_order_horz = segment_order__non_contiguous;
  857. *segment_order_vert = segment_order__contiguous;
  858. return true;
  859. }
  860. if (bytes_per_element == 8 && standard_swizzle) {
  861. *segment_order_horz = segment_order__na;
  862. *segment_order_vert = segment_order__contiguous;
  863. return true;
  864. }
  865. if (bytes_per_element == 8 && display_swizzle) {
  866. *segment_order_horz = segment_order__contiguous;
  867. *segment_order_vert = segment_order__non_contiguous;
  868. return true;
  869. }
  870. return false;
  871. }
  872. static void get_blk256_size(unsigned int *blk256_width, unsigned int *blk256_height,
  873. unsigned int bytes_per_element)
  874. {
  875. /* copied from DML. might want to refactor DML to leverage from DML */
  876. /* DML : get_blk256_size */
  877. if (bytes_per_element == 1) {
  878. *blk256_width = 16;
  879. *blk256_height = 16;
  880. } else if (bytes_per_element == 2) {
  881. *blk256_width = 16;
  882. *blk256_height = 8;
  883. } else if (bytes_per_element == 4) {
  884. *blk256_width = 8;
  885. *blk256_height = 8;
  886. } else if (bytes_per_element == 8) {
  887. *blk256_width = 8;
  888. *blk256_height = 4;
  889. }
  890. }
  891. static void det_request_size(
  892. unsigned int height,
  893. unsigned int width,
  894. unsigned int bpe,
  895. bool *req128_horz_wc,
  896. bool *req128_vert_wc)
  897. {
  898. unsigned int detile_buf_size = 164 * 1024; /* 164KB for DCN1.0 */
  899. unsigned int blk256_height = 0;
  900. unsigned int blk256_width = 0;
  901. unsigned int swath_bytes_horz_wc, swath_bytes_vert_wc;
  902. get_blk256_size(&blk256_width, &blk256_height, bpe);
  903. swath_bytes_horz_wc = height * blk256_height * bpe;
  904. swath_bytes_vert_wc = width * blk256_width * bpe;
  905. *req128_horz_wc = (2 * swath_bytes_horz_wc <= detile_buf_size) ?
  906. false : /* full 256B request */
  907. true; /* half 128b request */
  908. *req128_vert_wc = (2 * swath_bytes_vert_wc <= detile_buf_size) ?
  909. false : /* full 256B request */
  910. true; /* half 128b request */
  911. }
  912. static bool get_dcc_compression_cap(const struct dc *dc,
  913. const struct dc_dcc_surface_param *input,
  914. struct dc_surface_dcc_cap *output)
  915. {
  916. /* implement section 1.6.2.1 of DCN1_Programming_Guide.docx */
  917. enum dcc_control dcc_control;
  918. unsigned int bpe;
  919. enum segment_order segment_order_horz, segment_order_vert;
  920. bool req128_horz_wc, req128_vert_wc;
  921. memset(output, 0, sizeof(*output));
  922. if (dc->debug.disable_dcc == DCC_DISABLE)
  923. return false;
  924. if (!dcc_support_pixel_format(input->format,
  925. &bpe))
  926. return false;
  927. if (!dcc_support_swizzle(input->swizzle_mode, bpe,
  928. &segment_order_horz, &segment_order_vert))
  929. return false;
  930. det_request_size(input->surface_size.height, input->surface_size.width,
  931. bpe, &req128_horz_wc, &req128_vert_wc);
  932. if (!req128_horz_wc && !req128_vert_wc) {
  933. dcc_control = dcc_control__256_256_xxx;
  934. } else if (input->scan == SCAN_DIRECTION_HORIZONTAL) {
  935. if (!req128_horz_wc)
  936. dcc_control = dcc_control__256_256_xxx;
  937. else if (segment_order_horz == segment_order__contiguous)
  938. dcc_control = dcc_control__128_128_xxx;
  939. else
  940. dcc_control = dcc_control__256_64_64;
  941. } else if (input->scan == SCAN_DIRECTION_VERTICAL) {
  942. if (!req128_vert_wc)
  943. dcc_control = dcc_control__256_256_xxx;
  944. else if (segment_order_vert == segment_order__contiguous)
  945. dcc_control = dcc_control__128_128_xxx;
  946. else
  947. dcc_control = dcc_control__256_64_64;
  948. } else {
  949. if ((req128_horz_wc &&
  950. segment_order_horz == segment_order__non_contiguous) ||
  951. (req128_vert_wc &&
  952. segment_order_vert == segment_order__non_contiguous))
  953. /* access_dir not known, must use most constraining */
  954. dcc_control = dcc_control__256_64_64;
  955. else
  956. /* reg128 is true for either horz and vert
  957. * but segment_order is contiguous
  958. */
  959. dcc_control = dcc_control__128_128_xxx;
  960. }
  961. if (dc->debug.disable_dcc == DCC_HALF_REQ_DISALBE &&
  962. dcc_control != dcc_control__256_256_xxx)
  963. return false;
  964. switch (dcc_control) {
  965. case dcc_control__256_256_xxx:
  966. output->grph.rgb.max_uncompressed_blk_size = 256;
  967. output->grph.rgb.max_compressed_blk_size = 256;
  968. output->grph.rgb.independent_64b_blks = false;
  969. break;
  970. case dcc_control__128_128_xxx:
  971. output->grph.rgb.max_uncompressed_blk_size = 128;
  972. output->grph.rgb.max_compressed_blk_size = 128;
  973. output->grph.rgb.independent_64b_blks = false;
  974. break;
  975. case dcc_control__256_64_64:
  976. output->grph.rgb.max_uncompressed_blk_size = 256;
  977. output->grph.rgb.max_compressed_blk_size = 64;
  978. output->grph.rgb.independent_64b_blks = true;
  979. break;
  980. }
  981. output->capable = true;
  982. output->const_color_support = false;
  983. return true;
  984. }
  985. static void dcn10_destroy_resource_pool(struct resource_pool **pool)
  986. {
  987. struct dcn10_resource_pool *dcn10_pool = TO_DCN10_RES_POOL(*pool);
  988. destruct(dcn10_pool);
  989. kfree(dcn10_pool);
  990. *pool = NULL;
  991. }
  992. static enum dc_status dcn10_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
  993. {
  994. if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
  995. && caps->max_video_width != 0
  996. && plane_state->src_rect.width > caps->max_video_width)
  997. return DC_FAIL_SURFACE_VALIDATE;
  998. return DC_OK;
  999. }
  1000. static struct dc_cap_funcs cap_funcs = {
  1001. .get_dcc_compression_cap = get_dcc_compression_cap
  1002. };
  1003. static struct resource_funcs dcn10_res_pool_funcs = {
  1004. .destroy = dcn10_destroy_resource_pool,
  1005. .link_enc_create = dcn10_link_encoder_create,
  1006. .validate_guaranteed = dcn10_validate_guaranteed,
  1007. .validate_bandwidth = dcn_validate_bandwidth,
  1008. .acquire_idle_pipe_for_layer = dcn10_acquire_idle_pipe_for_layer,
  1009. .validate_plane = dcn10_validate_plane,
  1010. .add_stream_to_ctx = dcn10_add_stream_to_ctx
  1011. };
  1012. static uint32_t read_pipe_fuses(struct dc_context *ctx)
  1013. {
  1014. uint32_t value = dm_read_reg_soc15(ctx, mmCC_DC_PIPE_DIS, 0);
  1015. /* RV1 support max 4 pipes */
  1016. value = value & 0xf;
  1017. return value;
  1018. }
  1019. static bool construct(
  1020. uint8_t num_virtual_links,
  1021. struct dc *dc,
  1022. struct dcn10_resource_pool *pool)
  1023. {
  1024. int i;
  1025. int j;
  1026. struct dc_context *ctx = dc->ctx;
  1027. uint32_t pipe_fuses = read_pipe_fuses(ctx);
  1028. ctx->dc_bios->regs = &bios_regs;
  1029. pool->base.res_cap = &res_cap;
  1030. pool->base.funcs = &dcn10_res_pool_funcs;
  1031. /*
  1032. * TODO fill in from actual raven resource when we create
  1033. * more than virtual encoder
  1034. */
  1035. /*************************************************
  1036. * Resource + asic cap harcoding *
  1037. *************************************************/
  1038. pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
  1039. /* max pipe num for ASIC before check pipe fuses */
  1040. pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
  1041. dc->caps.max_video_width = 3840;
  1042. dc->caps.max_downscale_ratio = 200;
  1043. dc->caps.i2c_speed_in_khz = 100;
  1044. dc->caps.max_cursor_size = 256;
  1045. dc->caps.max_slave_planes = 1;
  1046. dc->caps.is_apu = true;
  1047. if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
  1048. dc->debug = debug_defaults_drv;
  1049. else
  1050. dc->debug = debug_defaults_diags;
  1051. /*************************************************
  1052. * Create resources *
  1053. *************************************************/
  1054. pool->base.clock_sources[DCN10_CLK_SRC_PLL0] =
  1055. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1056. CLOCK_SOURCE_COMBO_PHY_PLL0,
  1057. &clk_src_regs[0], false);
  1058. pool->base.clock_sources[DCN10_CLK_SRC_PLL1] =
  1059. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1060. CLOCK_SOURCE_COMBO_PHY_PLL1,
  1061. &clk_src_regs[1], false);
  1062. pool->base.clock_sources[DCN10_CLK_SRC_PLL2] =
  1063. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1064. CLOCK_SOURCE_COMBO_PHY_PLL2,
  1065. &clk_src_regs[2], false);
  1066. pool->base.clock_sources[DCN10_CLK_SRC_PLL3] =
  1067. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1068. CLOCK_SOURCE_COMBO_PHY_PLL3,
  1069. &clk_src_regs[3], false);
  1070. pool->base.clk_src_count = DCN10_CLK_SRC_TOTAL;
  1071. pool->base.dp_clock_source =
  1072. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1073. CLOCK_SOURCE_ID_DP_DTO,
  1074. /* todo: not reuse phy_pll registers */
  1075. &clk_src_regs[0], true);
  1076. for (i = 0; i < pool->base.clk_src_count; i++) {
  1077. if (pool->base.clock_sources[i] == NULL) {
  1078. dm_error("DC: failed to create clock sources!\n");
  1079. BREAK_TO_DEBUGGER();
  1080. goto fail;
  1081. }
  1082. }
  1083. pool->base.display_clock = dce120_disp_clk_create(ctx);
  1084. if (pool->base.display_clock == NULL) {
  1085. dm_error("DC: failed to create display clock!\n");
  1086. BREAK_TO_DEBUGGER();
  1087. goto fail;
  1088. }
  1089. pool->base.dmcu = dcn10_dmcu_create(ctx,
  1090. &dmcu_regs,
  1091. &dmcu_shift,
  1092. &dmcu_mask);
  1093. if (pool->base.dmcu == NULL) {
  1094. dm_error("DC: failed to create dmcu!\n");
  1095. BREAK_TO_DEBUGGER();
  1096. goto fail;
  1097. }
  1098. pool->base.abm = dce_abm_create(ctx,
  1099. &abm_regs,
  1100. &abm_shift,
  1101. &abm_mask);
  1102. if (pool->base.abm == NULL) {
  1103. dm_error("DC: failed to create abm!\n");
  1104. BREAK_TO_DEBUGGER();
  1105. goto fail;
  1106. }
  1107. dml_init_instance(&dc->dml, DML_PROJECT_RAVEN1);
  1108. memcpy(dc->dcn_ip, &dcn10_ip_defaults, sizeof(dcn10_ip_defaults));
  1109. memcpy(dc->dcn_soc, &dcn10_soc_defaults, sizeof(dcn10_soc_defaults));
  1110. if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
  1111. dc->dcn_soc->urgent_latency = 3;
  1112. dc->debug.disable_dmcu = true;
  1113. dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 41.60f;
  1114. }
  1115. dc->dcn_soc->number_of_channels = dc->ctx->asic_id.vram_width / ddr4_dram_width;
  1116. ASSERT(dc->dcn_soc->number_of_channels < 3);
  1117. if (dc->dcn_soc->number_of_channels == 0)/*old sbios bug*/
  1118. dc->dcn_soc->number_of_channels = 2;
  1119. if (dc->dcn_soc->number_of_channels == 1) {
  1120. dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 19.2f;
  1121. dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 = 17.066f;
  1122. dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 = 14.933f;
  1123. dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 = 12.8f;
  1124. if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
  1125. dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 20.80f;
  1126. }
  1127. }
  1128. pool->base.pp_smu = dcn10_pp_smu_create(ctx);
  1129. if (!dc->debug.disable_pplib_clock_request)
  1130. dcn_bw_update_from_pplib(dc);
  1131. dcn_bw_sync_calcs_and_dml(dc);
  1132. if (!dc->debug.disable_pplib_wm_range) {
  1133. dc->res_pool = &pool->base;
  1134. dcn_bw_notify_pplib_of_wm_ranges(dc);
  1135. }
  1136. {
  1137. struct irq_service_init_data init_data;
  1138. init_data.ctx = dc->ctx;
  1139. pool->base.irqs = dal_irq_service_dcn10_create(&init_data);
  1140. if (!pool->base.irqs)
  1141. goto fail;
  1142. }
  1143. /* index to valid pipe resource */
  1144. j = 0;
  1145. /* mem input -> ipp -> dpp -> opp -> TG */
  1146. for (i = 0; i < pool->base.pipe_count; i++) {
  1147. /* if pipe is disabled, skip instance of HW pipe,
  1148. * i.e, skip ASIC register instance
  1149. */
  1150. if ((pipe_fuses & (1 << i)) != 0)
  1151. continue;
  1152. pool->base.hubps[j] = dcn10_hubp_create(ctx, i);
  1153. if (pool->base.hubps[j] == NULL) {
  1154. BREAK_TO_DEBUGGER();
  1155. dm_error(
  1156. "DC: failed to create memory input!\n");
  1157. goto fail;
  1158. }
  1159. pool->base.ipps[j] = dcn10_ipp_create(ctx, i);
  1160. if (pool->base.ipps[j] == NULL) {
  1161. BREAK_TO_DEBUGGER();
  1162. dm_error(
  1163. "DC: failed to create input pixel processor!\n");
  1164. goto fail;
  1165. }
  1166. pool->base.dpps[j] = dcn10_dpp_create(ctx, i);
  1167. if (pool->base.dpps[j] == NULL) {
  1168. BREAK_TO_DEBUGGER();
  1169. dm_error(
  1170. "DC: failed to create dpp!\n");
  1171. goto fail;
  1172. }
  1173. pool->base.opps[j] = dcn10_opp_create(ctx, i);
  1174. if (pool->base.opps[j] == NULL) {
  1175. BREAK_TO_DEBUGGER();
  1176. dm_error(
  1177. "DC: failed to create output pixel processor!\n");
  1178. goto fail;
  1179. }
  1180. pool->base.timing_generators[j] = dcn10_timing_generator_create(
  1181. ctx, i);
  1182. if (pool->base.timing_generators[j] == NULL) {
  1183. BREAK_TO_DEBUGGER();
  1184. dm_error("DC: failed to create tg!\n");
  1185. goto fail;
  1186. }
  1187. /* check next valid pipe */
  1188. j++;
  1189. }
  1190. /* valid pipe num */
  1191. pool->base.pipe_count = j;
  1192. pool->base.timing_generator_count = j;
  1193. /* within dml lib, it is hard code to 4. If ASIC pipe is fused,
  1194. * the value may be changed
  1195. */
  1196. dc->dml.ip.max_num_dpp = pool->base.pipe_count;
  1197. dc->dcn_ip->max_num_dpp = pool->base.pipe_count;
  1198. pool->base.mpc = dcn10_mpc_create(ctx);
  1199. if (pool->base.mpc == NULL) {
  1200. BREAK_TO_DEBUGGER();
  1201. dm_error("DC: failed to create mpc!\n");
  1202. goto fail;
  1203. }
  1204. pool->base.hubbub = dcn10_hubbub_create(ctx);
  1205. if (pool->base.hubbub == NULL) {
  1206. BREAK_TO_DEBUGGER();
  1207. dm_error("DC: failed to create hubbub!\n");
  1208. goto fail;
  1209. }
  1210. if (!resource_construct(num_virtual_links, dc, &pool->base,
  1211. (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
  1212. &res_create_funcs : &res_create_maximus_funcs)))
  1213. goto fail;
  1214. dcn10_hw_sequencer_construct(dc);
  1215. dc->caps.max_planes = pool->base.pipe_count;
  1216. dc->cap_funcs = cap_funcs;
  1217. return true;
  1218. fail:
  1219. destruct(pool);
  1220. return false;
  1221. }
  1222. struct resource_pool *dcn10_create_resource_pool(
  1223. uint8_t num_virtual_links,
  1224. struct dc *dc)
  1225. {
  1226. struct dcn10_resource_pool *pool =
  1227. kzalloc(sizeof(struct dcn10_resource_pool), GFP_KERNEL);
  1228. if (!pool)
  1229. return NULL;
  1230. if (construct(num_virtual_links, dc, pool))
  1231. return &pool->base;
  1232. BREAK_TO_DEBUGGER();
  1233. return NULL;
  1234. }