dcn10_resource.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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. /* raven smu dones't allow 0 disp clk,
  359. * smu min disp clk limit is 50Mhz
  360. * keep min disp clk 100Mhz avoid smu hang
  361. */
  362. .min_disp_clk_khz = 100000,
  363. .disable_pplib_clock_request = true,
  364. .disable_pplib_wm_range = false,
  365. .pplib_wm_report_mode = WM_REPORT_DEFAULT,
  366. .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
  367. .force_single_disp_pipe_split = true,
  368. .disable_dcc = DCC_ENABLE,
  369. .voltage_align_fclk = true,
  370. .disable_stereo_support = true,
  371. .vsr_support = true,
  372. .performance_trace = false,
  373. .az_endpoint_mute_only = true,
  374. };
  375. static const struct dc_debug debug_defaults_diags = {
  376. .disable_dmcu = true,
  377. .force_abm_enable = false,
  378. .timing_trace = true,
  379. .clock_trace = true,
  380. .disable_stutter = true,
  381. .disable_pplib_clock_request = true,
  382. .disable_pplib_wm_range = true
  383. };
  384. static void dcn10_dpp_destroy(struct dpp **dpp)
  385. {
  386. kfree(TO_DCN10_DPP(*dpp));
  387. *dpp = NULL;
  388. }
  389. static struct dpp *dcn10_dpp_create(
  390. struct dc_context *ctx,
  391. uint32_t inst)
  392. {
  393. struct dcn10_dpp *dpp =
  394. kzalloc(sizeof(struct dcn10_dpp), GFP_KERNEL);
  395. if (!dpp)
  396. return NULL;
  397. dpp1_construct(dpp, ctx, inst,
  398. &tf_regs[inst], &tf_shift, &tf_mask);
  399. return &dpp->base;
  400. }
  401. static struct input_pixel_processor *dcn10_ipp_create(
  402. struct dc_context *ctx, uint32_t inst)
  403. {
  404. struct dcn10_ipp *ipp =
  405. kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL);
  406. if (!ipp) {
  407. BREAK_TO_DEBUGGER();
  408. return NULL;
  409. }
  410. dcn10_ipp_construct(ipp, ctx, inst,
  411. &ipp_regs[inst], &ipp_shift, &ipp_mask);
  412. return &ipp->base;
  413. }
  414. static struct output_pixel_processor *dcn10_opp_create(
  415. struct dc_context *ctx, uint32_t inst)
  416. {
  417. struct dcn10_opp *opp =
  418. kzalloc(sizeof(struct dcn10_opp), GFP_KERNEL);
  419. if (!opp) {
  420. BREAK_TO_DEBUGGER();
  421. return NULL;
  422. }
  423. dcn10_opp_construct(opp, ctx, inst,
  424. &opp_regs[inst], &opp_shift, &opp_mask);
  425. return &opp->base;
  426. }
  427. static struct mpc *dcn10_mpc_create(struct dc_context *ctx)
  428. {
  429. struct dcn10_mpc *mpc10 = kzalloc(sizeof(struct dcn10_mpc),
  430. GFP_KERNEL);
  431. if (!mpc10)
  432. return NULL;
  433. dcn10_mpc_construct(mpc10, ctx,
  434. &mpc_regs,
  435. &mpc_shift,
  436. &mpc_mask,
  437. 4);
  438. return &mpc10->base;
  439. }
  440. static struct hubbub *dcn10_hubbub_create(struct dc_context *ctx)
  441. {
  442. struct hubbub *hubbub = kzalloc(sizeof(struct hubbub),
  443. GFP_KERNEL);
  444. if (!hubbub)
  445. return NULL;
  446. hubbub1_construct(hubbub, ctx,
  447. &hubbub_reg,
  448. &hubbub_shift,
  449. &hubbub_mask);
  450. return hubbub;
  451. }
  452. static struct timing_generator *dcn10_timing_generator_create(
  453. struct dc_context *ctx,
  454. uint32_t instance)
  455. {
  456. struct optc *tgn10 =
  457. kzalloc(sizeof(struct optc), GFP_KERNEL);
  458. if (!tgn10)
  459. return NULL;
  460. tgn10->base.inst = instance;
  461. tgn10->base.ctx = ctx;
  462. tgn10->tg_regs = &tg_regs[instance];
  463. tgn10->tg_shift = &tg_shift;
  464. tgn10->tg_mask = &tg_mask;
  465. dcn10_timing_generator_init(tgn10);
  466. return &tgn10->base;
  467. }
  468. static const struct encoder_feature_support link_enc_feature = {
  469. .max_hdmi_deep_color = COLOR_DEPTH_121212,
  470. .max_hdmi_pixel_clock = 600000,
  471. .ycbcr420_supported = true,
  472. .flags.bits.IS_HBR2_CAPABLE = true,
  473. .flags.bits.IS_HBR3_CAPABLE = true,
  474. .flags.bits.IS_TPS3_CAPABLE = true,
  475. .flags.bits.IS_TPS4_CAPABLE = true,
  476. .flags.bits.IS_YCBCR_CAPABLE = true
  477. };
  478. struct link_encoder *dcn10_link_encoder_create(
  479. const struct encoder_init_data *enc_init_data)
  480. {
  481. struct dce110_link_encoder *enc110 =
  482. kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
  483. if (!enc110)
  484. return NULL;
  485. dce110_link_encoder_construct(enc110,
  486. enc_init_data,
  487. &link_enc_feature,
  488. &link_enc_regs[enc_init_data->transmitter],
  489. &link_enc_aux_regs[enc_init_data->channel - 1],
  490. &link_enc_hpd_regs[enc_init_data->hpd_source]);
  491. return &enc110->base;
  492. }
  493. struct clock_source *dcn10_clock_source_create(
  494. struct dc_context *ctx,
  495. struct dc_bios *bios,
  496. enum clock_source_id id,
  497. const struct dce110_clk_src_regs *regs,
  498. bool dp_clk_src)
  499. {
  500. struct dce110_clk_src *clk_src =
  501. kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
  502. if (!clk_src)
  503. return NULL;
  504. if (dce110_clk_src_construct(clk_src, ctx, bios, id,
  505. regs, &cs_shift, &cs_mask)) {
  506. clk_src->base.dp_clk_src = dp_clk_src;
  507. return &clk_src->base;
  508. }
  509. BREAK_TO_DEBUGGER();
  510. return NULL;
  511. }
  512. static void read_dce_straps(
  513. struct dc_context *ctx,
  514. struct resource_straps *straps)
  515. {
  516. generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
  517. FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
  518. }
  519. static struct audio *create_audio(
  520. struct dc_context *ctx, unsigned int inst)
  521. {
  522. return dce_audio_create(ctx, inst,
  523. &audio_regs[inst], &audio_shift, &audio_mask);
  524. }
  525. static struct stream_encoder *dcn10_stream_encoder_create(
  526. enum engine_id eng_id,
  527. struct dc_context *ctx)
  528. {
  529. struct dce110_stream_encoder *enc110 =
  530. kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
  531. if (!enc110)
  532. return NULL;
  533. dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
  534. &stream_enc_regs[eng_id],
  535. &se_shift, &se_mask);
  536. return &enc110->base;
  537. }
  538. static const struct dce_hwseq_registers hwseq_reg = {
  539. HWSEQ_DCN1_REG_LIST()
  540. };
  541. static const struct dce_hwseq_shift hwseq_shift = {
  542. HWSEQ_DCN1_MASK_SH_LIST(__SHIFT)
  543. };
  544. static const struct dce_hwseq_mask hwseq_mask = {
  545. HWSEQ_DCN1_MASK_SH_LIST(_MASK)
  546. };
  547. static struct dce_hwseq *dcn10_hwseq_create(
  548. struct dc_context *ctx)
  549. {
  550. struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
  551. if (hws) {
  552. hws->ctx = ctx;
  553. hws->regs = &hwseq_reg;
  554. hws->shifts = &hwseq_shift;
  555. hws->masks = &hwseq_mask;
  556. hws->wa.DEGVIDCN10_253 = true;
  557. hws->wa.false_optc_underflow = true;
  558. }
  559. return hws;
  560. }
  561. static const struct resource_create_funcs res_create_funcs = {
  562. .read_dce_straps = read_dce_straps,
  563. .create_audio = create_audio,
  564. .create_stream_encoder = dcn10_stream_encoder_create,
  565. .create_hwseq = dcn10_hwseq_create,
  566. };
  567. static const struct resource_create_funcs res_create_maximus_funcs = {
  568. .read_dce_straps = NULL,
  569. .create_audio = NULL,
  570. .create_stream_encoder = NULL,
  571. .create_hwseq = dcn10_hwseq_create,
  572. };
  573. void dcn10_clock_source_destroy(struct clock_source **clk_src)
  574. {
  575. kfree(TO_DCE110_CLK_SRC(*clk_src));
  576. *clk_src = NULL;
  577. }
  578. static struct pp_smu_funcs_rv *dcn10_pp_smu_create(struct dc_context *ctx)
  579. {
  580. struct pp_smu_funcs_rv *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
  581. if (!pp_smu)
  582. return pp_smu;
  583. dm_pp_get_funcs_rv(ctx, pp_smu);
  584. return pp_smu;
  585. }
  586. static void destruct(struct dcn10_resource_pool *pool)
  587. {
  588. unsigned int i;
  589. for (i = 0; i < pool->base.stream_enc_count; i++) {
  590. if (pool->base.stream_enc[i] != NULL) {
  591. /* TODO: free dcn version of stream encoder once implemented
  592. * rather than using virtual stream encoder
  593. */
  594. kfree(pool->base.stream_enc[i]);
  595. pool->base.stream_enc[i] = NULL;
  596. }
  597. }
  598. if (pool->base.mpc != NULL) {
  599. kfree(TO_DCN10_MPC(pool->base.mpc));
  600. pool->base.mpc = NULL;
  601. }
  602. if (pool->base.hubbub != NULL) {
  603. kfree(pool->base.hubbub);
  604. pool->base.hubbub = NULL;
  605. }
  606. for (i = 0; i < pool->base.pipe_count; i++) {
  607. if (pool->base.opps[i] != NULL)
  608. pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
  609. if (pool->base.dpps[i] != NULL)
  610. dcn10_dpp_destroy(&pool->base.dpps[i]);
  611. if (pool->base.ipps[i] != NULL)
  612. pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
  613. if (pool->base.hubps[i] != NULL) {
  614. kfree(TO_DCN10_HUBP(pool->base.hubps[i]));
  615. pool->base.hubps[i] = NULL;
  616. }
  617. if (pool->base.irqs != NULL) {
  618. dal_irq_service_destroy(&pool->base.irqs);
  619. }
  620. if (pool->base.timing_generators[i] != NULL) {
  621. kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
  622. pool->base.timing_generators[i] = NULL;
  623. }
  624. }
  625. for (i = 0; i < pool->base.stream_enc_count; i++)
  626. kfree(pool->base.stream_enc[i]);
  627. for (i = 0; i < pool->base.audio_count; i++) {
  628. if (pool->base.audios[i])
  629. dce_aud_destroy(&pool->base.audios[i]);
  630. }
  631. for (i = 0; i < pool->base.clk_src_count; i++) {
  632. if (pool->base.clock_sources[i] != NULL) {
  633. dcn10_clock_source_destroy(&pool->base.clock_sources[i]);
  634. pool->base.clock_sources[i] = NULL;
  635. }
  636. }
  637. if (pool->base.dp_clock_source != NULL) {
  638. dcn10_clock_source_destroy(&pool->base.dp_clock_source);
  639. pool->base.dp_clock_source = NULL;
  640. }
  641. if (pool->base.abm != NULL)
  642. dce_abm_destroy(&pool->base.abm);
  643. if (pool->base.dmcu != NULL)
  644. dce_dmcu_destroy(&pool->base.dmcu);
  645. if (pool->base.display_clock != NULL)
  646. dce_disp_clk_destroy(&pool->base.display_clock);
  647. kfree(pool->base.pp_smu);
  648. }
  649. static struct hubp *dcn10_hubp_create(
  650. struct dc_context *ctx,
  651. uint32_t inst)
  652. {
  653. struct dcn10_hubp *hubp1 =
  654. kzalloc(sizeof(struct dcn10_hubp), GFP_KERNEL);
  655. if (!hubp1)
  656. return NULL;
  657. dcn10_hubp_construct(hubp1, ctx, inst,
  658. &hubp_regs[inst], &hubp_shift, &hubp_mask);
  659. return &hubp1->base;
  660. }
  661. static void get_pixel_clock_parameters(
  662. const struct pipe_ctx *pipe_ctx,
  663. struct pixel_clk_params *pixel_clk_params)
  664. {
  665. const struct dc_stream_state *stream = pipe_ctx->stream;
  666. pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
  667. pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
  668. pixel_clk_params->signal_type = pipe_ctx->stream->signal;
  669. pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
  670. /* TODO: un-hardcode*/
  671. pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
  672. LINK_RATE_REF_FREQ_IN_KHZ;
  673. pixel_clk_params->flags.ENABLE_SS = 0;
  674. pixel_clk_params->color_depth =
  675. stream->timing.display_color_depth;
  676. pixel_clk_params->flags.DISPLAY_BLANKED = 1;
  677. pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
  678. if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
  679. pixel_clk_params->color_depth = COLOR_DEPTH_888;
  680. if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
  681. pixel_clk_params->requested_pix_clk /= 2;
  682. }
  683. static void build_clamping_params(struct dc_stream_state *stream)
  684. {
  685. stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
  686. stream->clamping.c_depth = stream->timing.display_color_depth;
  687. stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
  688. }
  689. static void build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
  690. {
  691. get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
  692. pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
  693. pipe_ctx->clock_source,
  694. &pipe_ctx->stream_res.pix_clk_params,
  695. &pipe_ctx->pll_settings);
  696. pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
  697. resource_build_bit_depth_reduction_params(pipe_ctx->stream,
  698. &pipe_ctx->stream->bit_depth_params);
  699. build_clamping_params(pipe_ctx->stream);
  700. }
  701. static enum dc_status build_mapped_resource(
  702. const struct dc *dc,
  703. struct dc_state *context,
  704. struct dc_stream_state *stream)
  705. {
  706. struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
  707. /*TODO Seems unneeded anymore */
  708. /* if (old_context && resource_is_stream_unchanged(old_context, stream)) {
  709. if (stream != NULL && old_context->streams[i] != NULL) {
  710. todo: shouldn't have to copy missing parameter here
  711. resource_build_bit_depth_reduction_params(stream,
  712. &stream->bit_depth_params);
  713. stream->clamping.pixel_encoding =
  714. stream->timing.pixel_encoding;
  715. resource_build_bit_depth_reduction_params(stream,
  716. &stream->bit_depth_params);
  717. build_clamping_params(stream);
  718. continue;
  719. }
  720. }
  721. */
  722. if (!pipe_ctx)
  723. return DC_ERROR_UNEXPECTED;
  724. build_pipe_hw_param(pipe_ctx);
  725. return DC_OK;
  726. }
  727. enum dc_status dcn10_add_stream_to_ctx(
  728. struct dc *dc,
  729. struct dc_state *new_ctx,
  730. struct dc_stream_state *dc_stream)
  731. {
  732. enum dc_status result = DC_ERROR_UNEXPECTED;
  733. result = resource_map_pool_resources(dc, new_ctx, dc_stream);
  734. if (result == DC_OK)
  735. result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
  736. if (result == DC_OK)
  737. result = build_mapped_resource(dc, new_ctx, dc_stream);
  738. return result;
  739. }
  740. enum dc_status dcn10_validate_guaranteed(
  741. struct dc *dc,
  742. struct dc_stream_state *dc_stream,
  743. struct dc_state *context)
  744. {
  745. enum dc_status result = DC_ERROR_UNEXPECTED;
  746. context->streams[0] = dc_stream;
  747. dc_stream_retain(context->streams[0]);
  748. context->stream_count++;
  749. result = resource_map_pool_resources(dc, context, dc_stream);
  750. if (result == DC_OK)
  751. result = resource_map_phy_clock_resources(dc, context, dc_stream);
  752. if (result == DC_OK)
  753. result = build_mapped_resource(dc, context, dc_stream);
  754. if (result == DC_OK) {
  755. validate_guaranteed_copy_streams(
  756. context, dc->caps.max_streams);
  757. result = resource_build_scaling_params_for_context(dc, context);
  758. }
  759. if (result == DC_OK && !dcn_validate_bandwidth(dc, context))
  760. return DC_FAIL_BANDWIDTH_VALIDATE;
  761. return result;
  762. }
  763. static struct pipe_ctx *dcn10_acquire_idle_pipe_for_layer(
  764. struct dc_state *context,
  765. const struct resource_pool *pool,
  766. struct dc_stream_state *stream)
  767. {
  768. struct resource_context *res_ctx = &context->res_ctx;
  769. struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
  770. struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool);
  771. if (!head_pipe) {
  772. ASSERT(0);
  773. return NULL;
  774. }
  775. if (!idle_pipe)
  776. return NULL;
  777. idle_pipe->stream = head_pipe->stream;
  778. idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
  779. idle_pipe->stream_res.abm = head_pipe->stream_res.abm;
  780. idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
  781. idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
  782. idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
  783. idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
  784. idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;
  785. return idle_pipe;
  786. }
  787. enum dcc_control {
  788. dcc_control__256_256_xxx,
  789. dcc_control__128_128_xxx,
  790. dcc_control__256_64_64,
  791. };
  792. enum segment_order {
  793. segment_order__na,
  794. segment_order__contiguous,
  795. segment_order__non_contiguous,
  796. };
  797. static bool dcc_support_pixel_format(
  798. enum surface_pixel_format format,
  799. unsigned int *bytes_per_element)
  800. {
  801. /* DML: get_bytes_per_element */
  802. switch (format) {
  803. case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
  804. case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
  805. *bytes_per_element = 2;
  806. return true;
  807. case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
  808. case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
  809. case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
  810. case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
  811. *bytes_per_element = 4;
  812. return true;
  813. case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
  814. case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
  815. case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
  816. *bytes_per_element = 8;
  817. return true;
  818. default:
  819. return false;
  820. }
  821. }
  822. static bool dcc_support_swizzle(
  823. enum swizzle_mode_values swizzle,
  824. unsigned int bytes_per_element,
  825. enum segment_order *segment_order_horz,
  826. enum segment_order *segment_order_vert)
  827. {
  828. bool standard_swizzle = false;
  829. bool display_swizzle = false;
  830. switch (swizzle) {
  831. case DC_SW_4KB_S:
  832. case DC_SW_64KB_S:
  833. case DC_SW_VAR_S:
  834. case DC_SW_4KB_S_X:
  835. case DC_SW_64KB_S_X:
  836. case DC_SW_VAR_S_X:
  837. standard_swizzle = true;
  838. break;
  839. case DC_SW_4KB_D:
  840. case DC_SW_64KB_D:
  841. case DC_SW_VAR_D:
  842. case DC_SW_4KB_D_X:
  843. case DC_SW_64KB_D_X:
  844. case DC_SW_VAR_D_X:
  845. display_swizzle = true;
  846. break;
  847. default:
  848. break;
  849. }
  850. if (bytes_per_element == 1 && standard_swizzle) {
  851. *segment_order_horz = segment_order__contiguous;
  852. *segment_order_vert = segment_order__na;
  853. return true;
  854. }
  855. if (bytes_per_element == 2 && 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 == 4 && standard_swizzle) {
  861. *segment_order_horz = segment_order__non_contiguous;
  862. *segment_order_vert = segment_order__contiguous;
  863. return true;
  864. }
  865. if (bytes_per_element == 8 && standard_swizzle) {
  866. *segment_order_horz = segment_order__na;
  867. *segment_order_vert = segment_order__contiguous;
  868. return true;
  869. }
  870. if (bytes_per_element == 8 && display_swizzle) {
  871. *segment_order_horz = segment_order__contiguous;
  872. *segment_order_vert = segment_order__non_contiguous;
  873. return true;
  874. }
  875. return false;
  876. }
  877. static void get_blk256_size(unsigned int *blk256_width, unsigned int *blk256_height,
  878. unsigned int bytes_per_element)
  879. {
  880. /* copied from DML. might want to refactor DML to leverage from DML */
  881. /* DML : get_blk256_size */
  882. if (bytes_per_element == 1) {
  883. *blk256_width = 16;
  884. *blk256_height = 16;
  885. } else if (bytes_per_element == 2) {
  886. *blk256_width = 16;
  887. *blk256_height = 8;
  888. } else if (bytes_per_element == 4) {
  889. *blk256_width = 8;
  890. *blk256_height = 8;
  891. } else if (bytes_per_element == 8) {
  892. *blk256_width = 8;
  893. *blk256_height = 4;
  894. }
  895. }
  896. static void det_request_size(
  897. unsigned int height,
  898. unsigned int width,
  899. unsigned int bpe,
  900. bool *req128_horz_wc,
  901. bool *req128_vert_wc)
  902. {
  903. unsigned int detile_buf_size = 164 * 1024; /* 164KB for DCN1.0 */
  904. unsigned int blk256_height = 0;
  905. unsigned int blk256_width = 0;
  906. unsigned int swath_bytes_horz_wc, swath_bytes_vert_wc;
  907. get_blk256_size(&blk256_width, &blk256_height, bpe);
  908. swath_bytes_horz_wc = height * blk256_height * bpe;
  909. swath_bytes_vert_wc = width * blk256_width * bpe;
  910. *req128_horz_wc = (2 * swath_bytes_horz_wc <= detile_buf_size) ?
  911. false : /* full 256B request */
  912. true; /* half 128b request */
  913. *req128_vert_wc = (2 * swath_bytes_vert_wc <= detile_buf_size) ?
  914. false : /* full 256B request */
  915. true; /* half 128b request */
  916. }
  917. static bool get_dcc_compression_cap(const struct dc *dc,
  918. const struct dc_dcc_surface_param *input,
  919. struct dc_surface_dcc_cap *output)
  920. {
  921. /* implement section 1.6.2.1 of DCN1_Programming_Guide.docx */
  922. enum dcc_control dcc_control;
  923. unsigned int bpe;
  924. enum segment_order segment_order_horz, segment_order_vert;
  925. bool req128_horz_wc, req128_vert_wc;
  926. memset(output, 0, sizeof(*output));
  927. if (dc->debug.disable_dcc == DCC_DISABLE)
  928. return false;
  929. if (!dcc_support_pixel_format(input->format,
  930. &bpe))
  931. return false;
  932. if (!dcc_support_swizzle(input->swizzle_mode, bpe,
  933. &segment_order_horz, &segment_order_vert))
  934. return false;
  935. det_request_size(input->surface_size.height, input->surface_size.width,
  936. bpe, &req128_horz_wc, &req128_vert_wc);
  937. if (!req128_horz_wc && !req128_vert_wc) {
  938. dcc_control = dcc_control__256_256_xxx;
  939. } else if (input->scan == SCAN_DIRECTION_HORIZONTAL) {
  940. if (!req128_horz_wc)
  941. dcc_control = dcc_control__256_256_xxx;
  942. else if (segment_order_horz == segment_order__contiguous)
  943. dcc_control = dcc_control__128_128_xxx;
  944. else
  945. dcc_control = dcc_control__256_64_64;
  946. } else if (input->scan == SCAN_DIRECTION_VERTICAL) {
  947. if (!req128_vert_wc)
  948. dcc_control = dcc_control__256_256_xxx;
  949. else if (segment_order_vert == segment_order__contiguous)
  950. dcc_control = dcc_control__128_128_xxx;
  951. else
  952. dcc_control = dcc_control__256_64_64;
  953. } else {
  954. if ((req128_horz_wc &&
  955. segment_order_horz == segment_order__non_contiguous) ||
  956. (req128_vert_wc &&
  957. segment_order_vert == segment_order__non_contiguous))
  958. /* access_dir not known, must use most constraining */
  959. dcc_control = dcc_control__256_64_64;
  960. else
  961. /* reg128 is true for either horz and vert
  962. * but segment_order is contiguous
  963. */
  964. dcc_control = dcc_control__128_128_xxx;
  965. }
  966. if (dc->debug.disable_dcc == DCC_HALF_REQ_DISALBE &&
  967. dcc_control != dcc_control__256_256_xxx)
  968. return false;
  969. switch (dcc_control) {
  970. case dcc_control__256_256_xxx:
  971. output->grph.rgb.max_uncompressed_blk_size = 256;
  972. output->grph.rgb.max_compressed_blk_size = 256;
  973. output->grph.rgb.independent_64b_blks = false;
  974. break;
  975. case dcc_control__128_128_xxx:
  976. output->grph.rgb.max_uncompressed_blk_size = 128;
  977. output->grph.rgb.max_compressed_blk_size = 128;
  978. output->grph.rgb.independent_64b_blks = false;
  979. break;
  980. case dcc_control__256_64_64:
  981. output->grph.rgb.max_uncompressed_blk_size = 256;
  982. output->grph.rgb.max_compressed_blk_size = 64;
  983. output->grph.rgb.independent_64b_blks = true;
  984. break;
  985. }
  986. output->capable = true;
  987. output->const_color_support = false;
  988. return true;
  989. }
  990. static void dcn10_destroy_resource_pool(struct resource_pool **pool)
  991. {
  992. struct dcn10_resource_pool *dcn10_pool = TO_DCN10_RES_POOL(*pool);
  993. destruct(dcn10_pool);
  994. kfree(dcn10_pool);
  995. *pool = NULL;
  996. }
  997. static enum dc_status dcn10_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
  998. {
  999. if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
  1000. && caps->max_video_width != 0
  1001. && plane_state->src_rect.width > caps->max_video_width)
  1002. return DC_FAIL_SURFACE_VALIDATE;
  1003. return DC_OK;
  1004. }
  1005. static struct dc_cap_funcs cap_funcs = {
  1006. .get_dcc_compression_cap = get_dcc_compression_cap
  1007. };
  1008. static struct resource_funcs dcn10_res_pool_funcs = {
  1009. .destroy = dcn10_destroy_resource_pool,
  1010. .link_enc_create = dcn10_link_encoder_create,
  1011. .validate_guaranteed = dcn10_validate_guaranteed,
  1012. .validate_bandwidth = dcn_validate_bandwidth,
  1013. .acquire_idle_pipe_for_layer = dcn10_acquire_idle_pipe_for_layer,
  1014. .validate_plane = dcn10_validate_plane,
  1015. .add_stream_to_ctx = dcn10_add_stream_to_ctx
  1016. };
  1017. static uint32_t read_pipe_fuses(struct dc_context *ctx)
  1018. {
  1019. uint32_t value = dm_read_reg_soc15(ctx, mmCC_DC_PIPE_DIS, 0);
  1020. /* RV1 support max 4 pipes */
  1021. value = value & 0xf;
  1022. return value;
  1023. }
  1024. static bool construct(
  1025. uint8_t num_virtual_links,
  1026. struct dc *dc,
  1027. struct dcn10_resource_pool *pool)
  1028. {
  1029. int i;
  1030. int j;
  1031. struct dc_context *ctx = dc->ctx;
  1032. uint32_t pipe_fuses = read_pipe_fuses(ctx);
  1033. ctx->dc_bios->regs = &bios_regs;
  1034. pool->base.res_cap = &res_cap;
  1035. pool->base.funcs = &dcn10_res_pool_funcs;
  1036. /*
  1037. * TODO fill in from actual raven resource when we create
  1038. * more than virtual encoder
  1039. */
  1040. /*************************************************
  1041. * Resource + asic cap harcoding *
  1042. *************************************************/
  1043. pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
  1044. /* max pipe num for ASIC before check pipe fuses */
  1045. pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
  1046. dc->caps.max_video_width = 3840;
  1047. dc->caps.max_downscale_ratio = 200;
  1048. dc->caps.i2c_speed_in_khz = 100;
  1049. dc->caps.max_cursor_size = 256;
  1050. dc->caps.max_slave_planes = 1;
  1051. dc->caps.is_apu = true;
  1052. if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
  1053. dc->debug = debug_defaults_drv;
  1054. else
  1055. dc->debug = debug_defaults_diags;
  1056. /*************************************************
  1057. * Create resources *
  1058. *************************************************/
  1059. pool->base.clock_sources[DCN10_CLK_SRC_PLL0] =
  1060. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1061. CLOCK_SOURCE_COMBO_PHY_PLL0,
  1062. &clk_src_regs[0], false);
  1063. pool->base.clock_sources[DCN10_CLK_SRC_PLL1] =
  1064. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1065. CLOCK_SOURCE_COMBO_PHY_PLL1,
  1066. &clk_src_regs[1], false);
  1067. pool->base.clock_sources[DCN10_CLK_SRC_PLL2] =
  1068. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1069. CLOCK_SOURCE_COMBO_PHY_PLL2,
  1070. &clk_src_regs[2], false);
  1071. pool->base.clock_sources[DCN10_CLK_SRC_PLL3] =
  1072. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1073. CLOCK_SOURCE_COMBO_PHY_PLL3,
  1074. &clk_src_regs[3], false);
  1075. pool->base.clk_src_count = DCN10_CLK_SRC_TOTAL;
  1076. pool->base.dp_clock_source =
  1077. dcn10_clock_source_create(ctx, ctx->dc_bios,
  1078. CLOCK_SOURCE_ID_DP_DTO,
  1079. /* todo: not reuse phy_pll registers */
  1080. &clk_src_regs[0], true);
  1081. for (i = 0; i < pool->base.clk_src_count; i++) {
  1082. if (pool->base.clock_sources[i] == NULL) {
  1083. dm_error("DC: failed to create clock sources!\n");
  1084. BREAK_TO_DEBUGGER();
  1085. goto fail;
  1086. }
  1087. }
  1088. pool->base.display_clock = dce120_disp_clk_create(ctx);
  1089. if (pool->base.display_clock == NULL) {
  1090. dm_error("DC: failed to create display clock!\n");
  1091. BREAK_TO_DEBUGGER();
  1092. goto fail;
  1093. }
  1094. pool->base.dmcu = dcn10_dmcu_create(ctx,
  1095. &dmcu_regs,
  1096. &dmcu_shift,
  1097. &dmcu_mask);
  1098. if (pool->base.dmcu == NULL) {
  1099. dm_error("DC: failed to create dmcu!\n");
  1100. BREAK_TO_DEBUGGER();
  1101. goto fail;
  1102. }
  1103. pool->base.abm = dce_abm_create(ctx,
  1104. &abm_regs,
  1105. &abm_shift,
  1106. &abm_mask);
  1107. if (pool->base.abm == NULL) {
  1108. dm_error("DC: failed to create abm!\n");
  1109. BREAK_TO_DEBUGGER();
  1110. goto fail;
  1111. }
  1112. dml_init_instance(&dc->dml, DML_PROJECT_RAVEN1);
  1113. memcpy(dc->dcn_ip, &dcn10_ip_defaults, sizeof(dcn10_ip_defaults));
  1114. memcpy(dc->dcn_soc, &dcn10_soc_defaults, sizeof(dcn10_soc_defaults));
  1115. if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
  1116. dc->dcn_soc->urgent_latency = 3;
  1117. dc->debug.disable_dmcu = true;
  1118. dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 41.60f;
  1119. }
  1120. dc->dcn_soc->number_of_channels = dc->ctx->asic_id.vram_width / ddr4_dram_width;
  1121. ASSERT(dc->dcn_soc->number_of_channels < 3);
  1122. if (dc->dcn_soc->number_of_channels == 0)/*old sbios bug*/
  1123. dc->dcn_soc->number_of_channels = 2;
  1124. if (dc->dcn_soc->number_of_channels == 1) {
  1125. dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 19.2f;
  1126. dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 = 17.066f;
  1127. dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 = 14.933f;
  1128. dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 = 12.8f;
  1129. if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
  1130. dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 20.80f;
  1131. }
  1132. }
  1133. pool->base.pp_smu = dcn10_pp_smu_create(ctx);
  1134. if (!dc->debug.disable_pplib_clock_request)
  1135. dcn_bw_update_from_pplib(dc);
  1136. dcn_bw_sync_calcs_and_dml(dc);
  1137. if (!dc->debug.disable_pplib_wm_range) {
  1138. dc->res_pool = &pool->base;
  1139. dcn_bw_notify_pplib_of_wm_ranges(dc);
  1140. }
  1141. {
  1142. struct irq_service_init_data init_data;
  1143. init_data.ctx = dc->ctx;
  1144. pool->base.irqs = dal_irq_service_dcn10_create(&init_data);
  1145. if (!pool->base.irqs)
  1146. goto fail;
  1147. }
  1148. /* index to valid pipe resource */
  1149. j = 0;
  1150. /* mem input -> ipp -> dpp -> opp -> TG */
  1151. for (i = 0; i < pool->base.pipe_count; i++) {
  1152. /* if pipe is disabled, skip instance of HW pipe,
  1153. * i.e, skip ASIC register instance
  1154. */
  1155. if ((pipe_fuses & (1 << i)) != 0)
  1156. continue;
  1157. pool->base.hubps[j] = dcn10_hubp_create(ctx, i);
  1158. if (pool->base.hubps[j] == NULL) {
  1159. BREAK_TO_DEBUGGER();
  1160. dm_error(
  1161. "DC: failed to create memory input!\n");
  1162. goto fail;
  1163. }
  1164. pool->base.ipps[j] = dcn10_ipp_create(ctx, i);
  1165. if (pool->base.ipps[j] == NULL) {
  1166. BREAK_TO_DEBUGGER();
  1167. dm_error(
  1168. "DC: failed to create input pixel processor!\n");
  1169. goto fail;
  1170. }
  1171. pool->base.dpps[j] = dcn10_dpp_create(ctx, i);
  1172. if (pool->base.dpps[j] == NULL) {
  1173. BREAK_TO_DEBUGGER();
  1174. dm_error(
  1175. "DC: failed to create dpp!\n");
  1176. goto fail;
  1177. }
  1178. pool->base.opps[j] = dcn10_opp_create(ctx, i);
  1179. if (pool->base.opps[j] == NULL) {
  1180. BREAK_TO_DEBUGGER();
  1181. dm_error(
  1182. "DC: failed to create output pixel processor!\n");
  1183. goto fail;
  1184. }
  1185. pool->base.timing_generators[j] = dcn10_timing_generator_create(
  1186. ctx, i);
  1187. if (pool->base.timing_generators[j] == NULL) {
  1188. BREAK_TO_DEBUGGER();
  1189. dm_error("DC: failed to create tg!\n");
  1190. goto fail;
  1191. }
  1192. /* check next valid pipe */
  1193. j++;
  1194. }
  1195. /* valid pipe num */
  1196. pool->base.pipe_count = j;
  1197. pool->base.timing_generator_count = j;
  1198. /* within dml lib, it is hard code to 4. If ASIC pipe is fused,
  1199. * the value may be changed
  1200. */
  1201. dc->dml.ip.max_num_dpp = pool->base.pipe_count;
  1202. dc->dcn_ip->max_num_dpp = pool->base.pipe_count;
  1203. pool->base.mpc = dcn10_mpc_create(ctx);
  1204. if (pool->base.mpc == NULL) {
  1205. BREAK_TO_DEBUGGER();
  1206. dm_error("DC: failed to create mpc!\n");
  1207. goto fail;
  1208. }
  1209. pool->base.hubbub = dcn10_hubbub_create(ctx);
  1210. if (pool->base.hubbub == NULL) {
  1211. BREAK_TO_DEBUGGER();
  1212. dm_error("DC: failed to create hubbub!\n");
  1213. goto fail;
  1214. }
  1215. if (!resource_construct(num_virtual_links, dc, &pool->base,
  1216. (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
  1217. &res_create_funcs : &res_create_maximus_funcs)))
  1218. goto fail;
  1219. dcn10_hw_sequencer_construct(dc);
  1220. dc->caps.max_planes = pool->base.pipe_count;
  1221. dc->cap_funcs = cap_funcs;
  1222. return true;
  1223. fail:
  1224. destruct(pool);
  1225. return false;
  1226. }
  1227. struct resource_pool *dcn10_create_resource_pool(
  1228. uint8_t num_virtual_links,
  1229. struct dc *dc)
  1230. {
  1231. struct dcn10_resource_pool *pool =
  1232. kzalloc(sizeof(struct dcn10_resource_pool), GFP_KERNEL);
  1233. if (!pool)
  1234. return NULL;
  1235. if (construct(num_virtual_links, dc, pool))
  1236. return &pool->base;
  1237. BREAK_TO_DEBUGGER();
  1238. return NULL;
  1239. }