dce100_resource.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /*
  2. * Copyright 2012-15 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 "link_encoder.h"
  27. #include "stream_encoder.h"
  28. #include "resource.h"
  29. #include "include/irq_service_interface.h"
  30. #include "../virtual/virtual_stream_encoder.h"
  31. #include "dce110/dce110_resource.h"
  32. #include "dce110/dce110_timing_generator.h"
  33. #include "irq/dce110/irq_service_dce110.h"
  34. #include "dce/dce_link_encoder.h"
  35. #include "dce/dce_stream_encoder.h"
  36. #include "dce/dce_mem_input.h"
  37. #include "dce/dce_ipp.h"
  38. #include "dce/dce_transform.h"
  39. #include "dce/dce_opp.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 "dce100/dce100_hw_sequencer.h"
  45. #include "reg_helper.h"
  46. #include "dce/dce_10_0_d.h"
  47. #include "dce/dce_10_0_sh_mask.h"
  48. #include "dce/dce_dmcu.h"
  49. #include "dce/dce_aux.h"
  50. #include "dce/dce_abm.h"
  51. #include "dce/dce_i2c.h"
  52. #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
  53. #include "gmc/gmc_8_2_d.h"
  54. #include "gmc/gmc_8_2_sh_mask.h"
  55. #endif
  56. #ifndef mmDP_DPHY_INTERNAL_CTRL
  57. #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
  58. #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
  59. #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
  60. #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
  61. #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
  62. #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
  63. #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
  64. #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
  65. #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
  66. #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
  67. #endif
  68. #ifndef mmBIOS_SCRATCH_2
  69. #define mmBIOS_SCRATCH_2 0x05CB
  70. #define mmBIOS_SCRATCH_6 0x05CF
  71. #endif
  72. #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
  73. #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
  74. #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
  75. #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
  76. #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
  77. #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
  78. #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
  79. #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
  80. #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
  81. #endif
  82. #ifndef mmDP_DPHY_FAST_TRAINING
  83. #define mmDP_DPHY_FAST_TRAINING 0x4ABC
  84. #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
  85. #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
  86. #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
  87. #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
  88. #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
  89. #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
  90. #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
  91. #endif
  92. static const struct dce110_timing_generator_offsets dce100_tg_offsets[] = {
  93. {
  94. .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
  95. .dcp = (mmDCP0_GRPH_CONTROL - mmGRPH_CONTROL),
  96. },
  97. {
  98. .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
  99. .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
  100. },
  101. {
  102. .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
  103. .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
  104. },
  105. {
  106. .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
  107. .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
  108. },
  109. {
  110. .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
  111. .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
  112. },
  113. {
  114. .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
  115. .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
  116. }
  117. };
  118. /* set register offset */
  119. #define SR(reg_name)\
  120. .reg_name = mm ## reg_name
  121. /* set register offset with instance */
  122. #define SRI(reg_name, block, id)\
  123. .reg_name = mm ## block ## id ## _ ## reg_name
  124. static const struct dccg_registers disp_clk_regs = {
  125. CLK_COMMON_REG_LIST_DCE_BASE()
  126. };
  127. static const struct dccg_shift disp_clk_shift = {
  128. CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
  129. };
  130. static const struct dccg_mask disp_clk_mask = {
  131. CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
  132. };
  133. #define ipp_regs(id)\
  134. [id] = {\
  135. IPP_DCE100_REG_LIST_DCE_BASE(id)\
  136. }
  137. static const struct dce_ipp_registers ipp_regs[] = {
  138. ipp_regs(0),
  139. ipp_regs(1),
  140. ipp_regs(2),
  141. ipp_regs(3),
  142. ipp_regs(4),
  143. ipp_regs(5)
  144. };
  145. static const struct dce_ipp_shift ipp_shift = {
  146. IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
  147. };
  148. static const struct dce_ipp_mask ipp_mask = {
  149. IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
  150. };
  151. #define transform_regs(id)\
  152. [id] = {\
  153. XFM_COMMON_REG_LIST_DCE100(id)\
  154. }
  155. static const struct dce_transform_registers xfm_regs[] = {
  156. transform_regs(0),
  157. transform_regs(1),
  158. transform_regs(2),
  159. transform_regs(3),
  160. transform_regs(4),
  161. transform_regs(5)
  162. };
  163. static const struct dce_transform_shift xfm_shift = {
  164. XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
  165. };
  166. static const struct dce_transform_mask xfm_mask = {
  167. XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
  168. };
  169. #define aux_regs(id)\
  170. [id] = {\
  171. AUX_REG_LIST(id)\
  172. }
  173. static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
  174. aux_regs(0),
  175. aux_regs(1),
  176. aux_regs(2),
  177. aux_regs(3),
  178. aux_regs(4),
  179. aux_regs(5)
  180. };
  181. #define hpd_regs(id)\
  182. [id] = {\
  183. HPD_REG_LIST(id)\
  184. }
  185. static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
  186. hpd_regs(0),
  187. hpd_regs(1),
  188. hpd_regs(2),
  189. hpd_regs(3),
  190. hpd_regs(4),
  191. hpd_regs(5)
  192. };
  193. #define link_regs(id)\
  194. [id] = {\
  195. LE_DCE100_REG_LIST(id)\
  196. }
  197. static const struct dce110_link_enc_registers link_enc_regs[] = {
  198. link_regs(0),
  199. link_regs(1),
  200. link_regs(2),
  201. link_regs(3),
  202. link_regs(4),
  203. link_regs(5),
  204. link_regs(6),
  205. };
  206. #define stream_enc_regs(id)\
  207. [id] = {\
  208. SE_COMMON_REG_LIST_DCE_BASE(id),\
  209. .AFMT_CNTL = 0,\
  210. }
  211. static const struct dce110_stream_enc_registers stream_enc_regs[] = {
  212. stream_enc_regs(0),
  213. stream_enc_regs(1),
  214. stream_enc_regs(2),
  215. stream_enc_regs(3),
  216. stream_enc_regs(4),
  217. stream_enc_regs(5),
  218. stream_enc_regs(6)
  219. };
  220. static const struct dce_stream_encoder_shift se_shift = {
  221. SE_COMMON_MASK_SH_LIST_DCE80_100(__SHIFT)
  222. };
  223. static const struct dce_stream_encoder_mask se_mask = {
  224. SE_COMMON_MASK_SH_LIST_DCE80_100(_MASK)
  225. };
  226. #define opp_regs(id)\
  227. [id] = {\
  228. OPP_DCE_100_REG_LIST(id),\
  229. }
  230. static const struct dce_opp_registers opp_regs[] = {
  231. opp_regs(0),
  232. opp_regs(1),
  233. opp_regs(2),
  234. opp_regs(3),
  235. opp_regs(4),
  236. opp_regs(5)
  237. };
  238. static const struct dce_opp_shift opp_shift = {
  239. OPP_COMMON_MASK_SH_LIST_DCE_100(__SHIFT)
  240. };
  241. static const struct dce_opp_mask opp_mask = {
  242. OPP_COMMON_MASK_SH_LIST_DCE_100(_MASK)
  243. };
  244. #define aux_engine_regs(id)\
  245. [id] = {\
  246. AUX_COMMON_REG_LIST(id), \
  247. .AUX_RESET_MASK = 0 \
  248. }
  249. static const struct dce110_aux_registers aux_engine_regs[] = {
  250. aux_engine_regs(0),
  251. aux_engine_regs(1),
  252. aux_engine_regs(2),
  253. aux_engine_regs(3),
  254. aux_engine_regs(4),
  255. aux_engine_regs(5)
  256. };
  257. #define audio_regs(id)\
  258. [id] = {\
  259. AUD_COMMON_REG_LIST(id)\
  260. }
  261. static const struct dce_audio_registers audio_regs[] = {
  262. audio_regs(0),
  263. audio_regs(1),
  264. audio_regs(2),
  265. audio_regs(3),
  266. audio_regs(4),
  267. audio_regs(5),
  268. audio_regs(6),
  269. };
  270. static const struct dce_audio_shift audio_shift = {
  271. AUD_COMMON_MASK_SH_LIST(__SHIFT)
  272. };
  273. static const struct dce_aduio_mask audio_mask = {
  274. AUD_COMMON_MASK_SH_LIST(_MASK)
  275. };
  276. #define clk_src_regs(id)\
  277. [id] = {\
  278. CS_COMMON_REG_LIST_DCE_100_110(id),\
  279. }
  280. static const struct dce110_clk_src_regs clk_src_regs[] = {
  281. clk_src_regs(0),
  282. clk_src_regs(1),
  283. clk_src_regs(2)
  284. };
  285. static const struct dce110_clk_src_shift cs_shift = {
  286. CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
  287. };
  288. static const struct dce110_clk_src_mask cs_mask = {
  289. CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
  290. };
  291. static const struct dce_dmcu_registers dmcu_regs = {
  292. DMCU_DCE110_COMMON_REG_LIST()
  293. };
  294. static const struct dce_dmcu_shift dmcu_shift = {
  295. DMCU_MASK_SH_LIST_DCE110(__SHIFT)
  296. };
  297. static const struct dce_dmcu_mask dmcu_mask = {
  298. DMCU_MASK_SH_LIST_DCE110(_MASK)
  299. };
  300. static const struct dce_abm_registers abm_regs = {
  301. ABM_DCE110_COMMON_REG_LIST()
  302. };
  303. static const struct dce_abm_shift abm_shift = {
  304. ABM_MASK_SH_LIST_DCE110(__SHIFT)
  305. };
  306. static const struct dce_abm_mask abm_mask = {
  307. ABM_MASK_SH_LIST_DCE110(_MASK)
  308. };
  309. #define DCFE_MEM_PWR_CTRL_REG_BASE 0x1b03
  310. static const struct bios_registers bios_regs = {
  311. .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
  312. };
  313. static const struct resource_caps res_cap = {
  314. .num_timing_generator = 6,
  315. .num_audio = 6,
  316. .num_stream_encoder = 6,
  317. .num_pll = 3,
  318. .num_ddc = 6,
  319. };
  320. #define CTX ctx
  321. #define REG(reg) mm ## reg
  322. #ifndef mmCC_DC_HDMI_STRAPS
  323. #define mmCC_DC_HDMI_STRAPS 0x1918
  324. #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
  325. #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
  326. #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
  327. #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
  328. #endif
  329. static void read_dce_straps(
  330. struct dc_context *ctx,
  331. struct resource_straps *straps)
  332. {
  333. REG_GET_2(CC_DC_HDMI_STRAPS,
  334. HDMI_DISABLE, &straps->hdmi_disable,
  335. AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
  336. REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
  337. }
  338. static struct audio *create_audio(
  339. struct dc_context *ctx, unsigned int inst)
  340. {
  341. return dce_audio_create(ctx, inst,
  342. &audio_regs[inst], &audio_shift, &audio_mask);
  343. }
  344. static struct timing_generator *dce100_timing_generator_create(
  345. struct dc_context *ctx,
  346. uint32_t instance,
  347. const struct dce110_timing_generator_offsets *offsets)
  348. {
  349. struct dce110_timing_generator *tg110 =
  350. kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
  351. if (!tg110)
  352. return NULL;
  353. dce110_timing_generator_construct(tg110, ctx, instance, offsets);
  354. return &tg110->base;
  355. }
  356. static struct stream_encoder *dce100_stream_encoder_create(
  357. enum engine_id eng_id,
  358. struct dc_context *ctx)
  359. {
  360. struct dce110_stream_encoder *enc110 =
  361. kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
  362. if (!enc110)
  363. return NULL;
  364. dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
  365. &stream_enc_regs[eng_id], &se_shift, &se_mask);
  366. return &enc110->base;
  367. }
  368. #define SRII(reg_name, block, id)\
  369. .reg_name[id] = mm ## block ## id ## _ ## reg_name
  370. static const struct dce_hwseq_registers hwseq_reg = {
  371. HWSEQ_DCE10_REG_LIST()
  372. };
  373. static const struct dce_hwseq_shift hwseq_shift = {
  374. HWSEQ_DCE10_MASK_SH_LIST(__SHIFT)
  375. };
  376. static const struct dce_hwseq_mask hwseq_mask = {
  377. HWSEQ_DCE10_MASK_SH_LIST(_MASK)
  378. };
  379. static struct dce_hwseq *dce100_hwseq_create(
  380. struct dc_context *ctx)
  381. {
  382. struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
  383. if (hws) {
  384. hws->ctx = ctx;
  385. hws->regs = &hwseq_reg;
  386. hws->shifts = &hwseq_shift;
  387. hws->masks = &hwseq_mask;
  388. }
  389. return hws;
  390. }
  391. static const struct resource_create_funcs res_create_funcs = {
  392. .read_dce_straps = read_dce_straps,
  393. .create_audio = create_audio,
  394. .create_stream_encoder = dce100_stream_encoder_create,
  395. .create_hwseq = dce100_hwseq_create,
  396. };
  397. #define mi_inst_regs(id) { \
  398. MI_DCE8_REG_LIST(id), \
  399. .MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
  400. }
  401. static const struct dce_mem_input_registers mi_regs[] = {
  402. mi_inst_regs(0),
  403. mi_inst_regs(1),
  404. mi_inst_regs(2),
  405. mi_inst_regs(3),
  406. mi_inst_regs(4),
  407. mi_inst_regs(5),
  408. };
  409. static const struct dce_mem_input_shift mi_shifts = {
  410. MI_DCE8_MASK_SH_LIST(__SHIFT),
  411. .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
  412. };
  413. static const struct dce_mem_input_mask mi_masks = {
  414. MI_DCE8_MASK_SH_LIST(_MASK),
  415. .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
  416. };
  417. static struct mem_input *dce100_mem_input_create(
  418. struct dc_context *ctx,
  419. uint32_t inst)
  420. {
  421. struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
  422. GFP_KERNEL);
  423. if (!dce_mi) {
  424. BREAK_TO_DEBUGGER();
  425. return NULL;
  426. }
  427. dce_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
  428. dce_mi->wa.single_head_rdreq_dmif_limit = 2;
  429. return &dce_mi->base;
  430. }
  431. static void dce100_transform_destroy(struct transform **xfm)
  432. {
  433. kfree(TO_DCE_TRANSFORM(*xfm));
  434. *xfm = NULL;
  435. }
  436. static struct transform *dce100_transform_create(
  437. struct dc_context *ctx,
  438. uint32_t inst)
  439. {
  440. struct dce_transform *transform =
  441. kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
  442. if (!transform)
  443. return NULL;
  444. dce_transform_construct(transform, ctx, inst,
  445. &xfm_regs[inst], &xfm_shift, &xfm_mask);
  446. return &transform->base;
  447. }
  448. static struct input_pixel_processor *dce100_ipp_create(
  449. struct dc_context *ctx, uint32_t inst)
  450. {
  451. struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
  452. if (!ipp) {
  453. BREAK_TO_DEBUGGER();
  454. return NULL;
  455. }
  456. dce_ipp_construct(ipp, ctx, inst,
  457. &ipp_regs[inst], &ipp_shift, &ipp_mask);
  458. return &ipp->base;
  459. }
  460. static const struct encoder_feature_support link_enc_feature = {
  461. .max_hdmi_deep_color = COLOR_DEPTH_121212,
  462. .max_hdmi_pixel_clock = 300000,
  463. .flags.bits.IS_HBR2_CAPABLE = true,
  464. .flags.bits.IS_TPS3_CAPABLE = true
  465. };
  466. struct link_encoder *dce100_link_encoder_create(
  467. const struct encoder_init_data *enc_init_data)
  468. {
  469. struct dce110_link_encoder *enc110 =
  470. kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
  471. if (!enc110)
  472. return NULL;
  473. dce110_link_encoder_construct(enc110,
  474. enc_init_data,
  475. &link_enc_feature,
  476. &link_enc_regs[enc_init_data->transmitter],
  477. &link_enc_aux_regs[enc_init_data->channel - 1],
  478. &link_enc_hpd_regs[enc_init_data->hpd_source]);
  479. return &enc110->base;
  480. }
  481. struct output_pixel_processor *dce100_opp_create(
  482. struct dc_context *ctx,
  483. uint32_t inst)
  484. {
  485. struct dce110_opp *opp =
  486. kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
  487. if (!opp)
  488. return NULL;
  489. dce110_opp_construct(opp,
  490. ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
  491. return &opp->base;
  492. }
  493. struct aux_engine *dce100_aux_engine_create(
  494. struct dc_context *ctx,
  495. uint32_t inst)
  496. {
  497. struct aux_engine_dce110 *aux_engine =
  498. kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
  499. if (!aux_engine)
  500. return NULL;
  501. dce110_aux_engine_construct(aux_engine, ctx, inst,
  502. SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
  503. &aux_engine_regs[inst]);
  504. return &aux_engine->base;
  505. }
  506. #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
  507. static const struct dce_i2c_registers i2c_hw_regs[] = {
  508. i2c_inst_regs(1),
  509. i2c_inst_regs(2),
  510. i2c_inst_regs(3),
  511. i2c_inst_regs(4),
  512. i2c_inst_regs(5),
  513. i2c_inst_regs(6),
  514. };
  515. static const struct dce_i2c_shift i2c_shifts = {
  516. I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
  517. };
  518. static const struct dce_i2c_mask i2c_masks = {
  519. I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
  520. };
  521. struct dce_i2c_hw *dce100_i2c_hw_create(
  522. struct dc_context *ctx,
  523. uint32_t inst)
  524. {
  525. struct dce_i2c_hw *dce_i2c_hw =
  526. kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
  527. if (!dce_i2c_hw)
  528. return NULL;
  529. dce100_i2c_hw_construct(dce_i2c_hw, ctx, inst,
  530. &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
  531. return dce_i2c_hw;
  532. }
  533. struct clock_source *dce100_clock_source_create(
  534. struct dc_context *ctx,
  535. struct dc_bios *bios,
  536. enum clock_source_id id,
  537. const struct dce110_clk_src_regs *regs,
  538. bool dp_clk_src)
  539. {
  540. struct dce110_clk_src *clk_src =
  541. kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
  542. if (!clk_src)
  543. return NULL;
  544. if (dce110_clk_src_construct(clk_src, ctx, bios, id,
  545. regs, &cs_shift, &cs_mask)) {
  546. clk_src->base.dp_clk_src = dp_clk_src;
  547. return &clk_src->base;
  548. }
  549. BREAK_TO_DEBUGGER();
  550. return NULL;
  551. }
  552. void dce100_clock_source_destroy(struct clock_source **clk_src)
  553. {
  554. kfree(TO_DCE110_CLK_SRC(*clk_src));
  555. *clk_src = NULL;
  556. }
  557. static void destruct(struct dce110_resource_pool *pool)
  558. {
  559. unsigned int i;
  560. for (i = 0; i < pool->base.pipe_count; i++) {
  561. if (pool->base.opps[i] != NULL)
  562. dce110_opp_destroy(&pool->base.opps[i]);
  563. if (pool->base.transforms[i] != NULL)
  564. dce100_transform_destroy(&pool->base.transforms[i]);
  565. if (pool->base.ipps[i] != NULL)
  566. dce_ipp_destroy(&pool->base.ipps[i]);
  567. if (pool->base.mis[i] != NULL) {
  568. kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
  569. pool->base.mis[i] = NULL;
  570. }
  571. if (pool->base.timing_generators[i] != NULL) {
  572. kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
  573. pool->base.timing_generators[i] = NULL;
  574. }
  575. }
  576. for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
  577. if (pool->base.engines[i] != NULL)
  578. dce110_engine_destroy(&pool->base.engines[i]);
  579. if (pool->base.hw_i2cs[i] != NULL) {
  580. kfree(pool->base.hw_i2cs[i]);
  581. pool->base.hw_i2cs[i] = NULL;
  582. }
  583. if (pool->base.sw_i2cs[i] != NULL) {
  584. kfree(pool->base.sw_i2cs[i]);
  585. pool->base.sw_i2cs[i] = NULL;
  586. }
  587. }
  588. for (i = 0; i < pool->base.stream_enc_count; i++) {
  589. if (pool->base.stream_enc[i] != NULL)
  590. kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
  591. }
  592. for (i = 0; i < pool->base.clk_src_count; i++) {
  593. if (pool->base.clock_sources[i] != NULL)
  594. dce100_clock_source_destroy(&pool->base.clock_sources[i]);
  595. }
  596. if (pool->base.dp_clock_source != NULL)
  597. dce100_clock_source_destroy(&pool->base.dp_clock_source);
  598. for (i = 0; i < pool->base.audio_count; i++) {
  599. if (pool->base.audios[i] != NULL)
  600. dce_aud_destroy(&pool->base.audios[i]);
  601. }
  602. if (pool->base.dccg != NULL)
  603. dce_dccg_destroy(&pool->base.dccg);
  604. if (pool->base.abm != NULL)
  605. dce_abm_destroy(&pool->base.abm);
  606. if (pool->base.dmcu != NULL)
  607. dce_dmcu_destroy(&pool->base.dmcu);
  608. if (pool->base.irqs != NULL)
  609. dal_irq_service_destroy(&pool->base.irqs);
  610. }
  611. static enum dc_status build_mapped_resource(
  612. const struct dc *dc,
  613. struct dc_state *context,
  614. struct dc_stream_state *stream)
  615. {
  616. struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
  617. if (!pipe_ctx)
  618. return DC_ERROR_UNEXPECTED;
  619. dce110_resource_build_pipe_hw_param(pipe_ctx);
  620. resource_build_info_frame(pipe_ctx);
  621. return DC_OK;
  622. }
  623. bool dce100_validate_bandwidth(
  624. struct dc *dc,
  625. struct dc_state *context)
  626. {
  627. int i;
  628. bool at_least_one_pipe = false;
  629. for (i = 0; i < dc->res_pool->pipe_count; i++) {
  630. if (context->res_ctx.pipe_ctx[i].stream)
  631. at_least_one_pipe = true;
  632. }
  633. if (at_least_one_pipe) {
  634. /* TODO implement when needed but for now hardcode max value*/
  635. context->bw.dce.dispclk_khz = 681000;
  636. context->bw.dce.yclk_khz = 250000 * MEMORY_TYPE_MULTIPLIER;
  637. } else {
  638. context->bw.dce.dispclk_khz = 0;
  639. context->bw.dce.yclk_khz = 0;
  640. }
  641. return true;
  642. }
  643. static bool dce100_validate_surface_sets(
  644. struct dc_state *context)
  645. {
  646. int i;
  647. for (i = 0; i < context->stream_count; i++) {
  648. if (context->stream_status[i].plane_count == 0)
  649. continue;
  650. if (context->stream_status[i].plane_count > 1)
  651. return false;
  652. if (context->stream_status[i].plane_states[0]->format
  653. >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
  654. return false;
  655. }
  656. return true;
  657. }
  658. enum dc_status dce100_validate_global(
  659. struct dc *dc,
  660. struct dc_state *context)
  661. {
  662. if (!dce100_validate_surface_sets(context))
  663. return DC_FAIL_SURFACE_VALIDATE;
  664. return DC_OK;
  665. }
  666. enum dc_status dce100_add_stream_to_ctx(
  667. struct dc *dc,
  668. struct dc_state *new_ctx,
  669. struct dc_stream_state *dc_stream)
  670. {
  671. enum dc_status result = DC_ERROR_UNEXPECTED;
  672. result = resource_map_pool_resources(dc, new_ctx, dc_stream);
  673. if (result == DC_OK)
  674. result = resource_map_clock_resources(dc, new_ctx, dc_stream);
  675. if (result == DC_OK)
  676. result = build_mapped_resource(dc, new_ctx, dc_stream);
  677. return result;
  678. }
  679. static void dce100_destroy_resource_pool(struct resource_pool **pool)
  680. {
  681. struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
  682. destruct(dce110_pool);
  683. kfree(dce110_pool);
  684. *pool = NULL;
  685. }
  686. enum dc_status dce100_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
  687. {
  688. if (plane_state->format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
  689. return DC_OK;
  690. return DC_FAIL_SURFACE_VALIDATE;
  691. }
  692. static const struct resource_funcs dce100_res_pool_funcs = {
  693. .destroy = dce100_destroy_resource_pool,
  694. .link_enc_create = dce100_link_encoder_create,
  695. .validate_bandwidth = dce100_validate_bandwidth,
  696. .validate_plane = dce100_validate_plane,
  697. .add_stream_to_ctx = dce100_add_stream_to_ctx,
  698. .validate_global = dce100_validate_global
  699. };
  700. static bool construct(
  701. uint8_t num_virtual_links,
  702. struct dc *dc,
  703. struct dce110_resource_pool *pool)
  704. {
  705. unsigned int i;
  706. struct dc_context *ctx = dc->ctx;
  707. struct dc_firmware_info info;
  708. struct dc_bios *bp;
  709. struct dm_pp_static_clock_info static_clk_info = {0};
  710. ctx->dc_bios->regs = &bios_regs;
  711. pool->base.res_cap = &res_cap;
  712. pool->base.funcs = &dce100_res_pool_funcs;
  713. pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
  714. bp = ctx->dc_bios;
  715. if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
  716. info.external_clock_source_frequency_for_dp != 0) {
  717. pool->base.dp_clock_source =
  718. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
  719. pool->base.clock_sources[0] =
  720. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
  721. pool->base.clock_sources[1] =
  722. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
  723. pool->base.clock_sources[2] =
  724. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
  725. pool->base.clk_src_count = 3;
  726. } else {
  727. pool->base.dp_clock_source =
  728. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
  729. pool->base.clock_sources[0] =
  730. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
  731. pool->base.clock_sources[1] =
  732. dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
  733. pool->base.clk_src_count = 2;
  734. }
  735. if (pool->base.dp_clock_source == NULL) {
  736. dm_error("DC: failed to create dp clock source!\n");
  737. BREAK_TO_DEBUGGER();
  738. goto res_create_fail;
  739. }
  740. for (i = 0; i < pool->base.clk_src_count; i++) {
  741. if (pool->base.clock_sources[i] == NULL) {
  742. dm_error("DC: failed to create clock sources!\n");
  743. BREAK_TO_DEBUGGER();
  744. goto res_create_fail;
  745. }
  746. }
  747. pool->base.dccg = dce_dccg_create(ctx,
  748. &disp_clk_regs,
  749. &disp_clk_shift,
  750. &disp_clk_mask);
  751. if (pool->base.dccg == NULL) {
  752. dm_error("DC: failed to create display clock!\n");
  753. BREAK_TO_DEBUGGER();
  754. goto res_create_fail;
  755. }
  756. pool->base.dmcu = dce_dmcu_create(ctx,
  757. &dmcu_regs,
  758. &dmcu_shift,
  759. &dmcu_mask);
  760. if (pool->base.dmcu == NULL) {
  761. dm_error("DC: failed to create dmcu!\n");
  762. BREAK_TO_DEBUGGER();
  763. goto res_create_fail;
  764. }
  765. pool->base.abm = dce_abm_create(ctx,
  766. &abm_regs,
  767. &abm_shift,
  768. &abm_mask);
  769. if (pool->base.abm == NULL) {
  770. dm_error("DC: failed to create abm!\n");
  771. BREAK_TO_DEBUGGER();
  772. goto res_create_fail;
  773. }
  774. /* get static clock information for PPLIB or firmware, save
  775. * max_clock_state
  776. */
  777. if (dm_pp_get_static_clocks(ctx, &static_clk_info))
  778. pool->base.dccg->max_clks_state =
  779. static_clk_info.max_clocks_state;
  780. {
  781. struct irq_service_init_data init_data;
  782. init_data.ctx = dc->ctx;
  783. pool->base.irqs = dal_irq_service_dce110_create(&init_data);
  784. if (!pool->base.irqs)
  785. goto res_create_fail;
  786. }
  787. /*************************************************
  788. * Resource + asic cap harcoding *
  789. *************************************************/
  790. pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
  791. pool->base.pipe_count = res_cap.num_timing_generator;
  792. pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
  793. dc->caps.max_downscale_ratio = 200;
  794. dc->caps.i2c_speed_in_khz = 40;
  795. dc->caps.max_cursor_size = 128;
  796. dc->caps.dual_link_dvi = true;
  797. dc->caps.disable_dp_clk_share = true;
  798. for (i = 0; i < pool->base.pipe_count; i++) {
  799. pool->base.timing_generators[i] =
  800. dce100_timing_generator_create(
  801. ctx,
  802. i,
  803. &dce100_tg_offsets[i]);
  804. if (pool->base.timing_generators[i] == NULL) {
  805. BREAK_TO_DEBUGGER();
  806. dm_error("DC: failed to create tg!\n");
  807. goto res_create_fail;
  808. }
  809. pool->base.mis[i] = dce100_mem_input_create(ctx, i);
  810. if (pool->base.mis[i] == NULL) {
  811. BREAK_TO_DEBUGGER();
  812. dm_error(
  813. "DC: failed to create memory input!\n");
  814. goto res_create_fail;
  815. }
  816. pool->base.ipps[i] = dce100_ipp_create(ctx, i);
  817. if (pool->base.ipps[i] == NULL) {
  818. BREAK_TO_DEBUGGER();
  819. dm_error(
  820. "DC: failed to create input pixel processor!\n");
  821. goto res_create_fail;
  822. }
  823. pool->base.transforms[i] = dce100_transform_create(ctx, i);
  824. if (pool->base.transforms[i] == NULL) {
  825. BREAK_TO_DEBUGGER();
  826. dm_error(
  827. "DC: failed to create transform!\n");
  828. goto res_create_fail;
  829. }
  830. pool->base.opps[i] = dce100_opp_create(ctx, i);
  831. if (pool->base.opps[i] == NULL) {
  832. BREAK_TO_DEBUGGER();
  833. dm_error(
  834. "DC: failed to create output pixel processor!\n");
  835. goto res_create_fail;
  836. }
  837. }
  838. for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
  839. pool->base.engines[i] = dce100_aux_engine_create(ctx, i);
  840. if (pool->base.engines[i] == NULL) {
  841. BREAK_TO_DEBUGGER();
  842. dm_error(
  843. "DC:failed to create aux engine!!\n");
  844. goto res_create_fail;
  845. }
  846. pool->base.hw_i2cs[i] = dce100_i2c_hw_create(ctx, i);
  847. if (pool->base.hw_i2cs[i] == NULL) {
  848. BREAK_TO_DEBUGGER();
  849. dm_error(
  850. "DC:failed to create i2c engine!!\n");
  851. goto res_create_fail;
  852. }
  853. pool->base.sw_i2cs[i] = NULL;
  854. }
  855. dc->caps.max_planes = pool->base.pipe_count;
  856. if (!resource_construct(num_virtual_links, dc, &pool->base,
  857. &res_create_funcs))
  858. goto res_create_fail;
  859. /* Create hardware sequencer */
  860. dce100_hw_sequencer_construct(dc);
  861. return true;
  862. res_create_fail:
  863. destruct(pool);
  864. return false;
  865. }
  866. struct resource_pool *dce100_create_resource_pool(
  867. uint8_t num_virtual_links,
  868. struct dc *dc)
  869. {
  870. struct dce110_resource_pool *pool =
  871. kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
  872. if (!pool)
  873. return NULL;
  874. if (construct(num_virtual_links, dc, pool))
  875. return &pool->base;
  876. BREAK_TO_DEBUGGER();
  877. return NULL;
  878. }