dcn10_resource.c 37 KB

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