sde_encoder_phys_wb.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  6. #include <linux/debugfs.h>
  7. #include <drm/sde_drm.h>
  8. #include "sde_encoder_phys.h"
  9. #include "sde_formats.h"
  10. #include "sde_hw_top.h"
  11. #include "sde_hw_interrupts.h"
  12. #include "sde_core_irq.h"
  13. #include "sde_wb.h"
  14. #include "sde_vbif.h"
  15. #include "sde_crtc.h"
  16. #define to_sde_encoder_phys_wb(x) \
  17. container_of(x, struct sde_encoder_phys_wb, base)
  18. #define WBID(wb_enc) \
  19. ((wb_enc && wb_enc->wb_dev) ? wb_enc->wb_dev->wb_idx - WB_0 : -1)
  20. #define TO_S15D16(_x_) ((_x_) << 7)
  21. #define SDE_WB_MAX_LINEWIDTH(fmt, wb_cfg) \
  22. (SDE_FORMAT_IS_UBWC(fmt) ? wb_cfg->sblk->maxlinewidth : \
  23. wb_cfg->sblk->maxlinewidth_linear)
  24. static const u32 cwb_irq_tbl[PINGPONG_MAX] = {SDE_NONE, INTR_IDX_PP1_OVFL,
  25. INTR_IDX_PP2_OVFL, INTR_IDX_PP3_OVFL, INTR_IDX_PP4_OVFL,
  26. INTR_IDX_PP5_OVFL, INTR_IDX_PP_CWB_OVFL, SDE_NONE};
  27. /**
  28. * sde_rgb2yuv_601l - rgb to yuv color space conversion matrix
  29. *
  30. */
  31. static struct sde_csc_cfg sde_encoder_phys_wb_rgb2yuv_601l = {
  32. {
  33. TO_S15D16(0x0083), TO_S15D16(0x0102), TO_S15D16(0x0032),
  34. TO_S15D16(0x1fb5), TO_S15D16(0x1f6c), TO_S15D16(0x00e1),
  35. TO_S15D16(0x00e1), TO_S15D16(0x1f45), TO_S15D16(0x1fdc)
  36. },
  37. { 0x00, 0x00, 0x00 },
  38. { 0x0040, 0x0200, 0x0200 },
  39. { 0x000, 0x3ff, 0x000, 0x3ff, 0x000, 0x3ff },
  40. { 0x040, 0x3ac, 0x040, 0x3c0, 0x040, 0x3c0 },
  41. };
  42. /**
  43. * sde_encoder_phys_wb_is_master - report wb always as master encoder
  44. */
  45. static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc)
  46. {
  47. return true;
  48. }
  49. /**
  50. * sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode
  51. * @hw_wb: Pointer to h/w writeback driver
  52. */
  53. static enum sde_intr_type sde_encoder_phys_wb_get_intr_type(
  54. struct sde_hw_wb *hw_wb)
  55. {
  56. return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ?
  57. SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP;
  58. }
  59. /**
  60. * sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface
  61. * @phys_enc: Pointer to physical encoder
  62. */
  63. static void sde_encoder_phys_wb_set_ot_limit(
  64. struct sde_encoder_phys *phys_enc)
  65. {
  66. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  67. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  68. struct sde_vbif_set_ot_params ot_params;
  69. memset(&ot_params, 0, sizeof(ot_params));
  70. ot_params.xin_id = hw_wb->caps->xin_id;
  71. ot_params.num = hw_wb->idx - WB_0;
  72. ot_params.width = wb_enc->wb_roi.w;
  73. ot_params.height = wb_enc->wb_roi.h;
  74. ot_params.is_wfd = true;
  75. ot_params.frame_rate = drm_mode_vrefresh(&phys_enc->cached_mode);
  76. ot_params.vbif_idx = hw_wb->caps->vbif_idx;
  77. ot_params.clk_ctrl = hw_wb->caps->clk_ctrl;
  78. ot_params.rd = false;
  79. sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params);
  80. }
  81. /**
  82. * sde_encoder_phys_wb_set_qos_remap - set QoS remapper for writeback
  83. * @phys_enc: Pointer to physical encoder
  84. */
  85. static void sde_encoder_phys_wb_set_qos_remap(
  86. struct sde_encoder_phys *phys_enc)
  87. {
  88. struct sde_encoder_phys_wb *wb_enc;
  89. struct sde_hw_wb *hw_wb;
  90. struct drm_crtc *crtc;
  91. struct sde_vbif_set_qos_params qos_params;
  92. if (!phys_enc || !phys_enc->parent || !phys_enc->parent->crtc) {
  93. SDE_ERROR("invalid arguments\n");
  94. return;
  95. }
  96. wb_enc = to_sde_encoder_phys_wb(phys_enc);
  97. if (!wb_enc->crtc) {
  98. SDE_ERROR("invalid crtc");
  99. return;
  100. }
  101. crtc = wb_enc->crtc;
  102. if (!wb_enc->hw_wb || !wb_enc->hw_wb->caps) {
  103. SDE_ERROR("invalid writeback hardware\n");
  104. return;
  105. }
  106. hw_wb = wb_enc->hw_wb;
  107. memset(&qos_params, 0, sizeof(qos_params));
  108. qos_params.vbif_idx = hw_wb->caps->vbif_idx;
  109. qos_params.xin_id = hw_wb->caps->xin_id;
  110. qos_params.clk_ctrl = hw_wb->caps->clk_ctrl;
  111. qos_params.num = hw_wb->idx - WB_0;
  112. qos_params.client_type = phys_enc->in_clone_mode ?
  113. VBIF_CWB_CLIENT : VBIF_NRT_CLIENT;
  114. SDE_DEBUG("[qos_remap] wb:%d vbif:%d xin:%d clone:%d\n",
  115. qos_params.num,
  116. qos_params.vbif_idx,
  117. qos_params.xin_id, qos_params.client_type);
  118. sde_vbif_set_qos_remap(phys_enc->sde_kms, &qos_params);
  119. }
  120. /**
  121. * sde_encoder_phys_wb_set_qos - set QoS/danger/safe LUTs for writeback
  122. * @phys_enc: Pointer to physical encoder
  123. */
  124. static void sde_encoder_phys_wb_set_qos(struct sde_encoder_phys *phys_enc)
  125. {
  126. struct sde_encoder_phys_wb *wb_enc;
  127. struct sde_hw_wb *hw_wb;
  128. struct sde_hw_wb_qos_cfg qos_cfg = {0};
  129. struct sde_perf_cfg *perf;
  130. u32 fps_index = 0, lut_index, index, frame_rate, qos_count;
  131. if (!phys_enc || !phys_enc->sde_kms || !phys_enc->sde_kms->catalog) {
  132. SDE_ERROR("invalid parameter(s)\n");
  133. return;
  134. }
  135. wb_enc = to_sde_encoder_phys_wb(phys_enc);
  136. if (!wb_enc->hw_wb) {
  137. SDE_ERROR("invalid writeback hardware\n");
  138. return;
  139. }
  140. perf = &phys_enc->sde_kms->catalog->perf;
  141. frame_rate = drm_mode_vrefresh(&phys_enc->cached_mode);
  142. hw_wb = wb_enc->hw_wb;
  143. qos_count = perf->qos_refresh_count;
  144. while ((fps_index < qos_count) && perf->qos_refresh_rate) {
  145. if ((frame_rate <= perf->qos_refresh_rate[fps_index]) ||
  146. (fps_index == qos_count - 1))
  147. break;
  148. fps_index++;
  149. }
  150. qos_cfg.danger_safe_en = true;
  151. if (phys_enc->in_clone_mode)
  152. lut_index = SDE_QOS_LUT_USAGE_CWB;
  153. else
  154. lut_index = SDE_QOS_LUT_USAGE_NRT;
  155. index = (fps_index * SDE_QOS_LUT_USAGE_MAX) + lut_index;
  156. qos_cfg.danger_lut = perf->danger_lut[index];
  157. qos_cfg.safe_lut = (u32) perf->safe_lut[index];
  158. qos_cfg.creq_lut = perf->creq_lut[index];
  159. SDE_DEBUG("wb_enc:%d hw idx:%d fps:%d mode:%d luts[0x%x,0x%x 0x%llx]\n",
  160. DRMID(phys_enc->parent), hw_wb->idx - WB_0,
  161. frame_rate, phys_enc->in_clone_mode,
  162. qos_cfg.danger_lut, qos_cfg.safe_lut, qos_cfg.creq_lut);
  163. if (hw_wb->ops.setup_qos_lut)
  164. hw_wb->ops.setup_qos_lut(hw_wb, &qos_cfg);
  165. }
  166. /**
  167. * sde_encoder_phys_setup_cdm - setup chroma down block
  168. * @phys_enc: Pointer to physical encoder
  169. * @fb: Pointer to output framebuffer
  170. * @format: Output format
  171. */
  172. void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
  173. struct drm_framebuffer *fb, const struct sde_format *format,
  174. struct sde_rect *wb_roi)
  175. {
  176. struct sde_hw_cdm *hw_cdm;
  177. struct sde_hw_cdm_cfg *cdm_cfg;
  178. struct sde_hw_pingpong *hw_pp;
  179. int ret;
  180. if (!phys_enc || !format)
  181. return;
  182. cdm_cfg = &phys_enc->cdm_cfg;
  183. hw_pp = phys_enc->hw_pp;
  184. hw_cdm = phys_enc->hw_cdm;
  185. if (!hw_cdm)
  186. return;
  187. if (!SDE_FORMAT_IS_YUV(format)) {
  188. SDE_DEBUG("[cdm_disable fmt:%x]\n",
  189. format->base.pixel_format);
  190. if (hw_cdm && hw_cdm->ops.disable)
  191. hw_cdm->ops.disable(hw_cdm);
  192. return;
  193. }
  194. memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg));
  195. if (!wb_roi)
  196. return;
  197. cdm_cfg->output_width = wb_roi->w;
  198. cdm_cfg->output_height = wb_roi->h;
  199. cdm_cfg->output_fmt = format;
  200. cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB;
  201. cdm_cfg->output_bit_depth = SDE_FORMAT_IS_DX(format) ?
  202. CDM_CDWN_OUTPUT_10BIT : CDM_CDWN_OUTPUT_8BIT;
  203. /* enable 10 bit logic */
  204. switch (cdm_cfg->output_fmt->chroma_sample) {
  205. case SDE_CHROMA_RGB:
  206. cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
  207. cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
  208. break;
  209. case SDE_CHROMA_H2V1:
  210. cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
  211. cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
  212. break;
  213. case SDE_CHROMA_420:
  214. cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
  215. cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE;
  216. break;
  217. case SDE_CHROMA_H1V2:
  218. default:
  219. SDE_ERROR("unsupported chroma sampling type\n");
  220. cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
  221. cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
  222. break;
  223. }
  224. SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n",
  225. cdm_cfg->output_width,
  226. cdm_cfg->output_height,
  227. cdm_cfg->output_fmt->base.pixel_format,
  228. cdm_cfg->output_type,
  229. cdm_cfg->output_bit_depth,
  230. cdm_cfg->h_cdwn_type,
  231. cdm_cfg->v_cdwn_type);
  232. if (hw_cdm && hw_cdm->ops.setup_csc_data) {
  233. ret = hw_cdm->ops.setup_csc_data(hw_cdm,
  234. &sde_encoder_phys_wb_rgb2yuv_601l);
  235. if (ret < 0) {
  236. SDE_ERROR("failed to setup CSC %d\n", ret);
  237. return;
  238. }
  239. }
  240. if (hw_cdm && hw_cdm->ops.setup_cdwn) {
  241. ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg);
  242. if (ret < 0) {
  243. SDE_ERROR("failed to setup CDM %d\n", ret);
  244. return;
  245. }
  246. }
  247. if (hw_cdm && hw_pp && hw_cdm->ops.enable) {
  248. cdm_cfg->pp_id = hw_pp->idx;
  249. ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg);
  250. if (ret < 0) {
  251. SDE_ERROR("failed to enable CDM %d\n", ret);
  252. return;
  253. }
  254. }
  255. }
  256. /**
  257. * sde_encoder_phys_wb_setup_fb - setup output framebuffer
  258. * @phys_enc: Pointer to physical encoder
  259. * @fb: Pointer to output framebuffer
  260. * @wb_roi: Pointer to output region of interest
  261. */
  262. static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc,
  263. struct drm_framebuffer *fb, struct sde_rect *wb_roi)
  264. {
  265. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  266. struct sde_hw_wb *hw_wb;
  267. struct sde_hw_wb_cfg *wb_cfg;
  268. struct sde_hw_wb_cdp_cfg *cdp_cfg;
  269. const struct msm_format *format;
  270. struct sde_crtc_state *cstate;
  271. struct sde_rect pu_roi = {0,};
  272. int ret;
  273. struct msm_gem_address_space *aspace;
  274. u32 fb_mode;
  275. if (!phys_enc || !phys_enc->sde_kms || !phys_enc->sde_kms->catalog ||
  276. !phys_enc->connector) {
  277. SDE_ERROR("invalid encoder\n");
  278. return;
  279. }
  280. cstate = to_sde_crtc_state(wb_enc->crtc->state);
  281. hw_wb = wb_enc->hw_wb;
  282. wb_cfg = &wb_enc->wb_cfg;
  283. cdp_cfg = &wb_enc->cdp_cfg;
  284. memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg));
  285. wb_cfg->intf_mode = phys_enc->intf_mode;
  286. fb_mode = sde_connector_get_property(phys_enc->connector->state,
  287. CONNECTOR_PROP_FB_TRANSLATION_MODE);
  288. if (phys_enc->enable_state == SDE_ENC_DISABLING)
  289. wb_cfg->is_secure = false;
  290. else if (fb_mode == SDE_DRM_FB_SEC)
  291. wb_cfg->is_secure = true;
  292. else
  293. wb_cfg->is_secure = false;
  294. aspace = (wb_cfg->is_secure) ?
  295. wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] :
  296. wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE];
  297. SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure);
  298. ret = msm_framebuffer_prepare(fb, aspace);
  299. if (ret) {
  300. SDE_ERROR("prep fb failed, %d\n", ret);
  301. return;
  302. }
  303. /* cache framebuffer for cleanup in writeback done */
  304. wb_enc->wb_fb = fb;
  305. wb_enc->wb_aspace = aspace;
  306. drm_framebuffer_get(fb);
  307. format = msm_framebuffer_format(fb);
  308. if (!format) {
  309. SDE_DEBUG("invalid format for fb\n");
  310. return;
  311. }
  312. wb_cfg->dest.format = sde_get_sde_format_ext(
  313. format->pixel_format,
  314. fb->modifier);
  315. if (!wb_cfg->dest.format) {
  316. /* this error should be detected during atomic_check */
  317. SDE_ERROR("failed to get format %x\n", format->pixel_format);
  318. return;
  319. }
  320. wb_cfg->roi = *wb_roi;
  321. ret = sde_format_populate_layout(aspace, fb, &wb_cfg->dest);
  322. if (ret) {
  323. SDE_DEBUG("failed to populate layout %d\n", ret);
  324. return;
  325. }
  326. wb_cfg->dest.width = fb->width;
  327. wb_cfg->dest.height = fb->height;
  328. wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes;
  329. if (hw_wb->ops.setup_crop && phys_enc->in_clone_mode) {
  330. wb_cfg->crop.x = wb_cfg->roi.x;
  331. wb_cfg->crop.y = wb_cfg->roi.y;
  332. if (cstate->user_roi_list.num_rects) {
  333. sde_kms_rect_merge_rectangles(&cstate->user_roi_list, &pu_roi);
  334. if ((wb_cfg->roi.w != pu_roi.w) || (wb_cfg->roi.h != pu_roi.h)) {
  335. /* offset cropping region to PU region */
  336. wb_cfg->crop.x = wb_cfg->crop.x - pu_roi.x;
  337. wb_cfg->crop.y = wb_cfg->crop.y - pu_roi.y;
  338. hw_wb->ops.setup_crop(hw_wb, wb_cfg, true);
  339. }
  340. } else if ((wb_cfg->roi.w != wb_cfg->dest.width) ||
  341. (wb_cfg->roi.h != wb_cfg->dest.height)) {
  342. hw_wb->ops.setup_crop(hw_wb, wb_cfg, true);
  343. } else {
  344. hw_wb->ops.setup_crop(hw_wb, wb_cfg, false);
  345. }
  346. }
  347. if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
  348. (wb_cfg->dest.format->element[0] == C1_B_Cb))
  349. swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
  350. SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
  351. wb_cfg->dest.plane_addr[0],
  352. wb_cfg->dest.plane_addr[1],
  353. wb_cfg->dest.plane_addr[2],
  354. wb_cfg->dest.plane_addr[3]);
  355. SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
  356. wb_cfg->dest.plane_pitch[0],
  357. wb_cfg->dest.plane_pitch[1],
  358. wb_cfg->dest.plane_pitch[2],
  359. wb_cfg->dest.plane_pitch[3]);
  360. if (hw_wb->ops.setup_roi)
  361. hw_wb->ops.setup_roi(hw_wb, wb_cfg);
  362. if (hw_wb->ops.setup_outformat)
  363. hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
  364. if (hw_wb->ops.setup_cdp) {
  365. memset(cdp_cfg, 0, sizeof(struct sde_hw_wb_cdp_cfg));
  366. cdp_cfg->enable = phys_enc->sde_kms->catalog->perf.cdp_cfg
  367. [SDE_PERF_CDP_USAGE_NRT].wr_enable;
  368. cdp_cfg->ubwc_meta_enable =
  369. SDE_FORMAT_IS_UBWC(wb_cfg->dest.format);
  370. cdp_cfg->tile_amortize_enable =
  371. SDE_FORMAT_IS_UBWC(wb_cfg->dest.format) ||
  372. SDE_FORMAT_IS_TILE(wb_cfg->dest.format);
  373. cdp_cfg->preload_ahead = SDE_WB_CDP_PRELOAD_AHEAD_64;
  374. hw_wb->ops.setup_cdp(hw_wb, cdp_cfg);
  375. }
  376. if (hw_wb->ops.setup_outaddress) {
  377. SDE_EVT32(hw_wb->idx,
  378. wb_cfg->dest.width,
  379. wb_cfg->dest.height,
  380. wb_cfg->dest.plane_addr[0],
  381. wb_cfg->dest.plane_size[0],
  382. wb_cfg->dest.plane_addr[1],
  383. wb_cfg->dest.plane_size[1],
  384. wb_cfg->dest.plane_addr[2],
  385. wb_cfg->dest.plane_size[2],
  386. wb_cfg->dest.plane_addr[3],
  387. wb_cfg->dest.plane_size[3]);
  388. hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
  389. }
  390. }
  391. static void _sde_encoder_phys_wb_setup_cwb(struct sde_encoder_phys *phys_enc,
  392. bool enable)
  393. {
  394. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  395. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  396. struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
  397. struct sde_crtc *crtc = to_sde_crtc(wb_enc->crtc);
  398. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  399. bool need_merge = (crtc->num_mixers > 1);
  400. int i = 0;
  401. if (!phys_enc->in_clone_mode) {
  402. SDE_DEBUG("not in CWB mode. early return\n");
  403. return;
  404. }
  405. if (!hw_pp || !hw_ctl || !hw_wb || hw_pp->idx >= PINGPONG_MAX) {
  406. SDE_ERROR("invalid hw resources - return\n");
  407. return;
  408. }
  409. hw_ctl = crtc->mixers[0].hw_ctl;
  410. if (hw_ctl && hw_ctl->ops.setup_intf_cfg_v1 &&
  411. (test_bit(SDE_WB_CWB_CTRL, &hw_wb->caps->features) ||
  412. test_bit(SDE_WB_DCWB_CTRL, &hw_wb->caps->features))) {
  413. struct sde_hw_intf_cfg_v1 intf_cfg = { 0, };
  414. for (i = 0; i < crtc->num_mixers; i++)
  415. intf_cfg.cwb[intf_cfg.cwb_count++] = (enum sde_cwb)
  416. (test_bit(SDE_WB_DCWB_CTRL, &hw_wb->caps->features) ?
  417. ((hw_pp->idx % 2) + i) : (hw_pp->idx + i));
  418. if (hw_pp->merge_3d && (intf_cfg.merge_3d_count <
  419. MAX_MERGE_3D_PER_CTL_V1) && need_merge)
  420. intf_cfg.merge_3d[intf_cfg.merge_3d_count++] =
  421. hw_pp->merge_3d->idx;
  422. if (hw_pp->ops.setup_3d_mode)
  423. hw_pp->ops.setup_3d_mode(hw_pp, (enable && need_merge) ?
  424. BLEND_3D_H_ROW_INT : 0);
  425. if ((hw_wb->ops.bind_pingpong_blk) &&
  426. test_bit(SDE_WB_CWB_CTRL, &hw_wb->caps->features))
  427. hw_wb->ops.bind_pingpong_blk(hw_wb, enable, hw_pp->idx);
  428. if ((hw_wb->ops.bind_dcwb_pp_blk) &&
  429. test_bit(SDE_WB_DCWB_CTRL, &hw_wb->caps->features))
  430. hw_wb->ops.bind_dcwb_pp_blk(hw_wb, enable, hw_pp->idx);
  431. if (hw_ctl->ops.update_intf_cfg) {
  432. hw_ctl->ops.update_intf_cfg(hw_ctl, &intf_cfg, enable);
  433. SDE_DEBUG("in CWB/DCWB mode on CTL_%d PP-%d merge3d:%d\n",
  434. hw_ctl->idx - CTL_0,
  435. hw_pp->idx - PINGPONG_0,
  436. hw_pp->merge_3d ?
  437. hw_pp->merge_3d->idx - MERGE_3D_0 : -1);
  438. }
  439. } else {
  440. struct sde_hw_intf_cfg *intf_cfg = &phys_enc->intf_cfg;
  441. memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
  442. intf_cfg->intf = SDE_NONE;
  443. intf_cfg->wb = hw_wb->idx;
  444. if (hw_ctl && hw_ctl->ops.update_wb_cfg) {
  445. hw_ctl->ops.update_wb_cfg(hw_ctl, intf_cfg, enable);
  446. SDE_DEBUG("in CWB/DCWB mode adding WB for CTL_%d\n",
  447. hw_ctl->idx - CTL_0);
  448. }
  449. }
  450. }
  451. /**
  452. * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
  453. * @phys_enc: Pointer to physical encoder
  454. */
  455. static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc,
  456. const struct sde_format *format)
  457. {
  458. struct sde_encoder_phys_wb *wb_enc;
  459. struct sde_hw_wb *hw_wb;
  460. struct sde_hw_cdm *hw_cdm;
  461. struct sde_hw_ctl *ctl;
  462. const int num_wb = 1;
  463. if (!phys_enc) {
  464. SDE_ERROR("invalid encoder\n");
  465. return;
  466. }
  467. if (phys_enc->in_clone_mode) {
  468. SDE_DEBUG("in CWB mode. early return\n");
  469. return;
  470. }
  471. wb_enc = to_sde_encoder_phys_wb(phys_enc);
  472. hw_wb = wb_enc->hw_wb;
  473. hw_cdm = phys_enc->hw_cdm;
  474. ctl = phys_enc->hw_ctl;
  475. if (test_bit(SDE_CTL_ACTIVE_CFG, &ctl->caps->features) &&
  476. (phys_enc->hw_ctl &&
  477. phys_enc->hw_ctl->ops.setup_intf_cfg_v1)) {
  478. struct sde_hw_intf_cfg_v1 *intf_cfg_v1 = &phys_enc->intf_cfg_v1;
  479. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  480. enum sde_3d_blend_mode mode_3d;
  481. memset(intf_cfg_v1, 0, sizeof(struct sde_hw_intf_cfg_v1));
  482. mode_3d = sde_encoder_helper_get_3d_blend_mode(phys_enc);
  483. intf_cfg_v1->intf_count = SDE_NONE;
  484. intf_cfg_v1->wb_count = num_wb;
  485. intf_cfg_v1->wb[0] = hw_wb->idx;
  486. if (SDE_FORMAT_IS_YUV(format)) {
  487. intf_cfg_v1->cdm_count = num_wb;
  488. intf_cfg_v1->cdm[0] = hw_cdm->idx;
  489. }
  490. if (mode_3d && hw_pp && hw_pp->merge_3d &&
  491. intf_cfg_v1->merge_3d_count < MAX_MERGE_3D_PER_CTL_V1)
  492. intf_cfg_v1->merge_3d[intf_cfg_v1->merge_3d_count++] =
  493. hw_pp->merge_3d->idx;
  494. if (hw_pp && hw_pp->ops.setup_3d_mode)
  495. hw_pp->ops.setup_3d_mode(hw_pp, mode_3d);
  496. /* setup which pp blk will connect to this wb */
  497. if (hw_pp && hw_wb->ops.bind_pingpong_blk)
  498. hw_wb->ops.bind_pingpong_blk(hw_wb, true,
  499. hw_pp->idx);
  500. phys_enc->hw_ctl->ops.setup_intf_cfg_v1(phys_enc->hw_ctl,
  501. intf_cfg_v1);
  502. } else if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg) {
  503. struct sde_hw_intf_cfg *intf_cfg = &phys_enc->intf_cfg;
  504. memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
  505. intf_cfg->intf = SDE_NONE;
  506. intf_cfg->wb = hw_wb->idx;
  507. intf_cfg->mode_3d =
  508. sde_encoder_helper_get_3d_blend_mode(phys_enc);
  509. phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
  510. intf_cfg);
  511. }
  512. }
  513. static void _sde_enc_phys_wb_detect_cwb(struct sde_encoder_phys *phys_enc,
  514. struct drm_crtc_state *crtc_state)
  515. {
  516. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  517. const struct sde_wb_cfg *wb_cfg = wb_enc->hw_wb->caps;
  518. u32 encoder_mask = 0;
  519. /* Check if WB has CWB support */
  520. if ((wb_cfg->features & BIT(SDE_WB_HAS_CWB))
  521. || (wb_cfg->features & BIT(SDE_WB_HAS_DCWB))) {
  522. encoder_mask = crtc_state->encoder_mask;
  523. encoder_mask &= ~drm_encoder_mask(phys_enc->parent);
  524. }
  525. phys_enc->in_clone_mode = encoder_mask ? true : false;
  526. SDE_DEBUG("detect CWB(OR)DCWB - status:%d\n", phys_enc->in_clone_mode);
  527. }
  528. static int _sde_enc_phys_wb_validate_cwb(struct sde_encoder_phys *phys_enc,
  529. struct drm_crtc_state *crtc_state,
  530. struct drm_connector_state *conn_state)
  531. {
  532. struct drm_framebuffer *fb;
  533. struct sde_crtc_state *cstate = to_sde_crtc_state(crtc_state);
  534. const struct drm_display_mode *mode = &crtc_state->mode;
  535. struct sde_rect wb_roi = {0,};
  536. struct sde_rect pu_roi = {0,};
  537. int out_width = 0, out_height = 0;
  538. int ds_srcw = 0, ds_srch = 0, ds_outw = 0, ds_outh = 0;
  539. const struct sde_format *fmt;
  540. int data_pt;
  541. int ds_in_use = false;
  542. int i = 0;
  543. int ret = 0;
  544. fb = sde_wb_connector_state_get_output_fb(conn_state);
  545. if (!fb) {
  546. SDE_DEBUG("no output framebuffer\n");
  547. return 0;
  548. }
  549. fmt = sde_get_sde_format_ext(fb->format->format, fb->modifier);
  550. if (!fmt) {
  551. SDE_ERROR("unsupported output pixel format:%x\n", fb->format->format);
  552. return -EINVAL;
  553. }
  554. ret = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
  555. if (ret) {
  556. SDE_ERROR("failed to get roi %d\n", ret);
  557. return ret;
  558. }
  559. if (!wb_roi.w || !wb_roi.h) {
  560. SDE_ERROR("cwb roi is not set wxh:%dx%d\n", wb_roi.w, wb_roi.h);
  561. return -EINVAL;
  562. }
  563. data_pt = sde_crtc_get_property(cstate, CRTC_PROP_CAPTURE_OUTPUT);
  564. /* compute cumulative ds output dimensions if in use */
  565. for (i = 0; i < cstate->num_ds; i++) {
  566. if (cstate->ds_cfg[i].scl3_cfg.enable) {
  567. ds_in_use = true;
  568. ds_outw += cstate->ds_cfg[i].scl3_cfg.dst_width;
  569. ds_outh = cstate->ds_cfg[i].scl3_cfg.dst_height;
  570. ds_srcw += cstate->ds_cfg[i].lm_width;
  571. ds_srch = cstate->ds_cfg[i].lm_height;
  572. }
  573. }
  574. if ((ds_in_use && (!ds_outw || !ds_outh || !ds_srcw || !ds_srch))) {
  575. SDE_ERROR("invalid ds cfg src:%dx%d dst:%dx%d\n",
  576. ds_srcw, ds_srch, ds_outw, ds_outh);
  577. return -EINVAL;
  578. }
  579. /* 1) No DS case: same restrictions for LM & DSSPP tap point
  580. * a) wb-roi should be inside FB
  581. * b) mode resolution & wb-roi should be same
  582. * 2) With DS case: restrictions would change based on tap point
  583. * 2.1) LM Tap Point:
  584. * a) wb-roi should be inside FB
  585. * b) wb-roi should be same as crtc-LM bounds
  586. * 2.2) DSPP Tap point: same as No DS case
  587. * a) wb-roi should be inside FB
  588. * b) mode resolution & wb-roi should be same
  589. * 3) Partial Update case: additional stride check
  590. * a) cwb roi should be inside PU region or FB
  591. * b) cropping is only allowed for fully sampled data
  592. * c) add check for stride and QOS setting by 256B
  593. */
  594. if (ds_in_use && data_pt == CAPTURE_DSPP_OUT) {
  595. out_width = ds_outw;
  596. out_height = ds_outh;
  597. } else if (ds_in_use) { /* LM tap point */
  598. out_width = ds_srcw;
  599. out_height = ds_srch;
  600. } else {
  601. out_width = mode->hdisplay;
  602. out_height = mode->vdisplay;
  603. }
  604. if (SDE_FORMAT_IS_YUV(fmt) && ((wb_roi.w != out_width) || (wb_roi.h != out_height))) {
  605. SDE_ERROR("invalid wb roi[%dx%d] with ds_use:%d out[%dx%d] fmt:%x\n",
  606. wb_roi.w, wb_roi.h, ds_in_use, out_width, out_height,
  607. fmt->base.pixel_format);
  608. return -EINVAL;
  609. }
  610. if ((wb_roi.w > out_width) || (wb_roi.h > out_height)) {
  611. SDE_ERROR("invalid wb roi[%dx%d] with ds_use:%d out[%dx%d]\n",
  612. wb_roi.w, wb_roi.h, ds_in_use, out_width, out_height);
  613. return -EINVAL;
  614. }
  615. if (((wb_roi.w < out_width) || (wb_roi.h < out_height)) &&
  616. (wb_roi.w * wb_roi.h * fmt->bpp) % 256) {
  617. SDE_ERROR("invalid stride w = %d h = %d bpp =%d out_width = %d, out_height = %d\n",
  618. wb_roi.w, wb_roi.h, fmt->bpp, out_width, out_height);
  619. return -EINVAL;
  620. }
  621. if (((wb_roi.x + wb_roi.w) > fb->width) ||
  622. ((wb_roi.y + wb_roi.h) > fb->height)) {
  623. SDE_ERROR("invalid wb roi[%d,%d,%d,%d] fb[%dx%d]\n",
  624. wb_roi.x, wb_roi.y, wb_roi.w, wb_roi.h,
  625. fb->width, fb->height);
  626. return -EINVAL;
  627. }
  628. /* validate wb roi against pu rect */
  629. if (cstate->user_roi_list.num_rects) {
  630. sde_kms_rect_merge_rectangles(&cstate->user_roi_list, &pu_roi);
  631. if (wb_roi.w > pu_roi.w || wb_roi.h > pu_roi.h) {
  632. SDE_ERROR("invalid wb roi with pu [%dx%d vs %dx%d]\n",
  633. wb_roi.w, wb_roi.h, pu_roi.w, pu_roi.h);
  634. return -EINVAL;
  635. }
  636. }
  637. return ret;
  638. }
  639. /**
  640. * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
  641. * @phys_enc: Pointer to physical encoder
  642. * @crtc_state: Pointer to CRTC atomic state
  643. * @conn_state: Pointer to connector atomic state
  644. */
  645. static int sde_encoder_phys_wb_atomic_check(
  646. struct sde_encoder_phys *phys_enc,
  647. struct drm_crtc_state *crtc_state,
  648. struct drm_connector_state *conn_state)
  649. {
  650. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  651. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  652. const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
  653. struct drm_framebuffer *fb;
  654. const struct sde_format *fmt;
  655. struct sde_rect wb_roi;
  656. const struct drm_display_mode *mode = &crtc_state->mode;
  657. int rc;
  658. bool clone_mode_curr = false;
  659. SDE_DEBUG("[atomic_check:%d,\"%s\",%d,%d]\n",
  660. hw_wb->idx - WB_0, mode->name,
  661. mode->hdisplay, mode->vdisplay);
  662. if (!conn_state || !conn_state->connector) {
  663. SDE_ERROR("invalid connector state\n");
  664. return -EINVAL;
  665. } else if (conn_state->connector->status !=
  666. connector_status_connected) {
  667. SDE_ERROR("connector not connected %d\n",
  668. conn_state->connector->status);
  669. return -EINVAL;
  670. }
  671. clone_mode_curr = phys_enc->in_clone_mode;
  672. _sde_enc_phys_wb_detect_cwb(phys_enc, crtc_state);
  673. if (clone_mode_curr && !phys_enc->in_clone_mode) {
  674. SDE_ERROR("WB commit before CWB disable\n");
  675. return -EINVAL;
  676. }
  677. memset(&wb_roi, 0, sizeof(struct sde_rect));
  678. rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
  679. if (rc) {
  680. SDE_ERROR("failed to get roi %d\n", rc);
  681. return rc;
  682. }
  683. SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
  684. wb_roi.w, wb_roi.h);
  685. /* bypass check if commit with no framebuffer */
  686. fb = sde_wb_connector_state_get_output_fb(conn_state);
  687. if (!fb) {
  688. SDE_DEBUG("no output framebuffer\n");
  689. return 0;
  690. }
  691. SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
  692. fb->width, fb->height);
  693. fmt = sde_get_sde_format_ext(fb->format->format, fb->modifier);
  694. if (!fmt) {
  695. SDE_ERROR("unsupported output pixel format:%x\n",
  696. fb->format->format);
  697. return -EINVAL;
  698. }
  699. SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->format->format,
  700. fb->modifier);
  701. if (SDE_FORMAT_IS_YUV(fmt) &&
  702. !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
  703. SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
  704. return -EINVAL;
  705. }
  706. if (SDE_FORMAT_IS_UBWC(fmt) &&
  707. !(wb_cfg->features & BIT(SDE_WB_UBWC))) {
  708. SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
  709. return -EINVAL;
  710. }
  711. if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
  712. crtc_state->mode_changed = true;
  713. /* if in clone mode, return after cwb validation */
  714. if (phys_enc->in_clone_mode) {
  715. rc = _sde_enc_phys_wb_validate_cwb(phys_enc, crtc_state,
  716. conn_state);
  717. if (rc)
  718. SDE_ERROR("failed in cwb validation %d\n", rc);
  719. return rc;
  720. }
  721. if (wb_roi.w && wb_roi.h) {
  722. if (wb_roi.w != mode->hdisplay) {
  723. SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
  724. mode->hdisplay);
  725. return -EINVAL;
  726. } else if (wb_roi.h != mode->vdisplay) {
  727. SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
  728. mode->vdisplay);
  729. return -EINVAL;
  730. } else if (wb_roi.x + wb_roi.w > fb->width) {
  731. SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
  732. wb_roi.x, wb_roi.w, fb->width);
  733. return -EINVAL;
  734. } else if (wb_roi.y + wb_roi.h > fb->height) {
  735. SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
  736. wb_roi.y, wb_roi.h, fb->height);
  737. return -EINVAL;
  738. } else if (wb_roi.w > SDE_WB_MAX_LINEWIDTH(fmt, wb_cfg)) {
  739. SDE_ERROR("invalid roi ubwc=%d w=%d, maxlinewidth=%u\n",
  740. SDE_FORMAT_IS_UBWC(fmt), wb_roi.w,
  741. SDE_WB_MAX_LINEWIDTH(fmt, wb_cfg));
  742. return -EINVAL;
  743. }
  744. } else {
  745. if (wb_roi.x || wb_roi.y) {
  746. SDE_ERROR("invalid roi x=%d, y=%d\n",
  747. wb_roi.x, wb_roi.y);
  748. return -EINVAL;
  749. } else if (fb->width != mode->hdisplay) {
  750. SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
  751. mode->hdisplay);
  752. return -EINVAL;
  753. } else if (fb->height != mode->vdisplay) {
  754. SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
  755. mode->vdisplay);
  756. return -EINVAL;
  757. } else if (fb->width > SDE_WB_MAX_LINEWIDTH(fmt, wb_cfg)) {
  758. SDE_ERROR("invalid fb ubwc=%d w=%d, maxlinewidth=%u\n",
  759. SDE_FORMAT_IS_UBWC(fmt), fb->width,
  760. SDE_WB_MAX_LINEWIDTH(fmt, wb_cfg));
  761. return -EINVAL;
  762. }
  763. }
  764. return rc;
  765. }
  766. static void _sde_encoder_phys_wb_update_cwb_flush(
  767. struct sde_encoder_phys *phys_enc, bool enable)
  768. {
  769. struct sde_encoder_phys_wb *wb_enc;
  770. struct sde_hw_wb *hw_wb;
  771. struct sde_hw_ctl *hw_ctl;
  772. struct sde_hw_cdm *hw_cdm;
  773. struct sde_hw_pingpong *hw_pp;
  774. struct sde_crtc *crtc;
  775. struct sde_crtc_state *crtc_state;
  776. int i = 0;
  777. int cwb_capture_mode = 0;
  778. enum sde_cwb cwb_idx = 0;
  779. enum sde_dcwb dcwb_idx = 0;
  780. enum sde_cwb src_pp_idx = 0;
  781. bool dspp_out = false;
  782. bool need_merge = false;
  783. if (!phys_enc->in_clone_mode) {
  784. SDE_DEBUG("not in CWB mode. early return\n");
  785. return;
  786. }
  787. wb_enc = to_sde_encoder_phys_wb(phys_enc);
  788. crtc = to_sde_crtc(wb_enc->crtc);
  789. crtc_state = to_sde_crtc_state(wb_enc->crtc->state);
  790. cwb_capture_mode = sde_crtc_get_property(crtc_state,
  791. CRTC_PROP_CAPTURE_OUTPUT);
  792. hw_pp = phys_enc->hw_pp;
  793. hw_wb = wb_enc->hw_wb;
  794. hw_cdm = phys_enc->hw_cdm;
  795. /* In CWB mode, program actual source master sde_hw_ctl from crtc */
  796. hw_ctl = crtc->mixers[0].hw_ctl;
  797. if (!hw_ctl || !hw_wb || !hw_pp) {
  798. SDE_ERROR("[wb] HW resource not available for CWB\n");
  799. return;
  800. }
  801. /* treating LM idx of primary display ctl path as source ping-pong idx*/
  802. src_pp_idx = (enum sde_cwb)crtc->mixers[0].hw_lm->idx;
  803. cwb_idx = (enum sde_cwb)hw_pp->idx;
  804. dspp_out = (cwb_capture_mode == CAPTURE_DSPP_OUT);
  805. need_merge = (crtc->num_mixers > 1) ? true : false;
  806. if (test_bit(SDE_WB_DCWB_CTRL, &hw_wb->caps->features)) {
  807. dcwb_idx = (enum sde_dcwb) ((hw_pp->idx % 2) + i);
  808. if ((dcwb_idx + crtc->num_mixers) > DCWB_MAX) {
  809. SDE_ERROR("invalid hw config for DCWB. dcwb_idx=%d, num_mixers=%d\n",
  810. dcwb_idx, crtc->num_mixers);
  811. return;
  812. }
  813. } else {
  814. if (src_pp_idx > CWB_0 || ((cwb_idx + crtc->num_mixers) > CWB_MAX)) {
  815. SDE_ERROR("invalid hw config for CWB. pp_idx-%d, cwb_idx=%d, num_mixers=%d\n",
  816. src_pp_idx, dcwb_idx, crtc->num_mixers);
  817. return;
  818. }
  819. }
  820. if (hw_ctl->ops.update_bitmask)
  821. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_WB,
  822. hw_wb->idx, 1);
  823. if (hw_ctl->ops.update_bitmask && hw_cdm)
  824. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_CDM,
  825. hw_cdm->idx, 1);
  826. if (test_bit(SDE_WB_CWB_CTRL, &hw_wb->caps->features) ||
  827. test_bit(SDE_WB_DCWB_CTRL, &hw_wb->caps->features)) {
  828. for (i = 0; i < crtc->num_mixers; i++) {
  829. src_pp_idx = (enum sde_cwb) (src_pp_idx + i);
  830. if (test_bit(SDE_WB_DCWB_CTRL, &hw_wb->caps->features)) {
  831. dcwb_idx = (enum sde_dcwb) ((hw_pp->idx % 2) + i);
  832. if (hw_wb->ops.program_dcwb_ctrl)
  833. hw_wb->ops.program_dcwb_ctrl(hw_wb, dcwb_idx,
  834. src_pp_idx, cwb_capture_mode,
  835. enable);
  836. if (hw_ctl->ops.update_bitmask)
  837. hw_ctl->ops.update_bitmask(hw_ctl,
  838. SDE_HW_FLUSH_CWB, dcwb_idx, 1);
  839. } else if (test_bit(SDE_WB_CWB_CTRL, &hw_wb->caps->features)) {
  840. cwb_idx = (enum sde_cwb) (hw_pp->idx + i);
  841. if (hw_wb->ops.program_cwb_ctrl)
  842. hw_wb->ops.program_cwb_ctrl(hw_wb, cwb_idx,
  843. src_pp_idx, dspp_out, enable);
  844. if (hw_ctl->ops.update_bitmask)
  845. hw_ctl->ops.update_bitmask(hw_ctl,
  846. SDE_HW_FLUSH_CWB, cwb_idx, 1);
  847. }
  848. }
  849. if (need_merge && hw_ctl->ops.update_bitmask
  850. && hw_pp && hw_pp->merge_3d)
  851. hw_ctl->ops.update_bitmask(hw_ctl,
  852. SDE_HW_FLUSH_MERGE_3D,
  853. hw_pp->merge_3d->idx, 1);
  854. } else {
  855. phys_enc->hw_mdptop->ops.set_cwb_ppb_cntl(phys_enc->hw_mdptop,
  856. need_merge, dspp_out);
  857. }
  858. }
  859. /**
  860. * _sde_encoder_phys_wb_update_flush - flush hardware update
  861. * @phys_enc: Pointer to physical encoder
  862. */
  863. static void _sde_encoder_phys_wb_update_flush(struct sde_encoder_phys *phys_enc)
  864. {
  865. struct sde_encoder_phys_wb *wb_enc;
  866. struct sde_hw_wb *hw_wb;
  867. struct sde_hw_ctl *hw_ctl;
  868. struct sde_hw_cdm *hw_cdm;
  869. struct sde_hw_pingpong *hw_pp;
  870. struct sde_ctl_flush_cfg pending_flush = {0,};
  871. if (!phys_enc)
  872. return;
  873. wb_enc = to_sde_encoder_phys_wb(phys_enc);
  874. hw_wb = wb_enc->hw_wb;
  875. hw_cdm = phys_enc->hw_cdm;
  876. hw_pp = phys_enc->hw_pp;
  877. hw_ctl = phys_enc->hw_ctl;
  878. SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
  879. if (phys_enc->in_clone_mode) {
  880. SDE_DEBUG("in CWB mode. early return\n");
  881. return;
  882. }
  883. if (!hw_ctl) {
  884. SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
  885. return;
  886. }
  887. if (hw_ctl->ops.update_bitmask)
  888. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_WB,
  889. hw_wb->idx, 1);
  890. if (hw_ctl->ops.update_bitmask && hw_cdm)
  891. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_CDM,
  892. hw_cdm->idx, 1);
  893. if (hw_ctl->ops.update_bitmask && hw_pp && hw_pp->merge_3d)
  894. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_MERGE_3D,
  895. hw_pp->merge_3d->idx, 1);
  896. if (hw_ctl->ops.get_pending_flush)
  897. hw_ctl->ops.get_pending_flush(hw_ctl,
  898. &pending_flush);
  899. SDE_DEBUG("Pending flush mask for CTL_%d is 0x%x, WB %d\n",
  900. hw_ctl->idx - CTL_0, pending_flush.pending_flush_mask,
  901. hw_wb->idx - WB_0);
  902. }
  903. /**
  904. * sde_encoder_phys_wb_setup - setup writeback encoder
  905. * @phys_enc: Pointer to physical encoder
  906. */
  907. static void sde_encoder_phys_wb_setup(
  908. struct sde_encoder_phys *phys_enc)
  909. {
  910. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  911. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  912. struct drm_display_mode mode = phys_enc->cached_mode;
  913. struct drm_framebuffer *fb;
  914. struct sde_rect *wb_roi = &wb_enc->wb_roi;
  915. SDE_DEBUG("[mode_set:%d,\"%s\",%d,%d]\n",
  916. hw_wb->idx - WB_0, mode.name,
  917. mode.hdisplay, mode.vdisplay);
  918. memset(wb_roi, 0, sizeof(struct sde_rect));
  919. /* clear writeback framebuffer - will be updated in setup_fb */
  920. wb_enc->wb_fb = NULL;
  921. wb_enc->wb_aspace = NULL;
  922. if (phys_enc->enable_state == SDE_ENC_DISABLING) {
  923. fb = wb_enc->fb_disable;
  924. wb_roi->w = 0;
  925. wb_roi->h = 0;
  926. } else {
  927. fb = sde_wb_get_output_fb(wb_enc->wb_dev);
  928. sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
  929. }
  930. if (!fb) {
  931. SDE_DEBUG("no output framebuffer\n");
  932. return;
  933. }
  934. SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
  935. fb->width, fb->height);
  936. if (wb_roi->w == 0 || wb_roi->h == 0) {
  937. wb_roi->x = 0;
  938. wb_roi->y = 0;
  939. wb_roi->w = fb->width;
  940. wb_roi->h = fb->height;
  941. }
  942. SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
  943. wb_roi->w, wb_roi->h);
  944. wb_enc->wb_fmt = sde_get_sde_format_ext(fb->format->format,
  945. fb->modifier);
  946. if (!wb_enc->wb_fmt) {
  947. SDE_ERROR("unsupported output pixel format: %d\n",
  948. fb->format->format);
  949. return;
  950. }
  951. SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->format->format,
  952. fb->modifier);
  953. sde_encoder_phys_wb_set_ot_limit(phys_enc);
  954. sde_encoder_phys_wb_set_qos_remap(phys_enc);
  955. sde_encoder_phys_wb_set_qos(phys_enc);
  956. sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
  957. sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
  958. sde_encoder_phys_wb_setup_cdp(phys_enc, wb_enc->wb_fmt);
  959. _sde_encoder_phys_wb_setup_cwb(phys_enc, true);
  960. }
  961. static void _sde_encoder_phys_wb_frame_done_helper(void *arg, bool frame_error)
  962. {
  963. struct sde_encoder_phys_wb *wb_enc = arg;
  964. struct sde_encoder_phys *phys_enc = &wb_enc->base;
  965. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  966. u32 event = frame_error ? SDE_ENCODER_FRAME_EVENT_ERROR : 0;
  967. SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0, wb_enc->frame_count);
  968. /* don't notify upper layer for internal commit */
  969. if (phys_enc->enable_state == SDE_ENC_DISABLING &&
  970. !phys_enc->in_clone_mode)
  971. goto complete;
  972. if (phys_enc->parent_ops.handle_frame_done &&
  973. atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0)) {
  974. event |= SDE_ENCODER_FRAME_EVENT_DONE |
  975. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE;
  976. if (phys_enc->in_clone_mode)
  977. event |= SDE_ENCODER_FRAME_EVENT_CWB_DONE;
  978. else
  979. event |= SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  980. phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
  981. phys_enc, event);
  982. }
  983. if (!phys_enc->in_clone_mode && phys_enc->parent_ops.handle_vblank_virt)
  984. phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
  985. phys_enc);
  986. SDE_EVT32_IRQ(DRMID(phys_enc->parent), hw_wb->idx - WB_0, event,
  987. frame_error);
  988. complete:
  989. wake_up_all(&phys_enc->pending_kickoff_wq);
  990. }
  991. /**
  992. * sde_encoder_phys_wb_done_irq - Pingpong overflow interrupt handler for CWB
  993. * @arg: Pointer to writeback encoder
  994. * @irq_idx: interrupt index
  995. */
  996. static void sde_encoder_phys_cwb_ovflow(void *arg, int irq_idx)
  997. {
  998. _sde_encoder_phys_wb_frame_done_helper(arg, true);
  999. }
  1000. /**
  1001. * sde_encoder_phys_wb_done_irq - writeback interrupt handler
  1002. * @arg: Pointer to writeback encoder
  1003. * @irq_idx: interrupt index
  1004. */
  1005. static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
  1006. {
  1007. _sde_encoder_phys_wb_frame_done_helper(arg, false);
  1008. }
  1009. /**
  1010. * sde_encoder_phys_wb_irq_ctrl - irq control of WB
  1011. * @phys: Pointer to physical encoder
  1012. * @enable: indicates enable or disable interrupts
  1013. */
  1014. static void sde_encoder_phys_wb_irq_ctrl(
  1015. struct sde_encoder_phys *phys, bool enable)
  1016. {
  1017. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys);
  1018. const struct sde_wb_cfg *wb_cfg;
  1019. int index = 0, refcount;
  1020. int ret = 0, pp = 0;
  1021. u32 max_num_of_irqs = 0;
  1022. if (!wb_enc)
  1023. return;
  1024. if (wb_enc->bypass_irqreg)
  1025. return;
  1026. pp = phys->hw_pp->idx - PINGPONG_0;
  1027. if ((pp + CRTC_DUAL_MIXERS_ONLY) >= PINGPONG_MAX) {
  1028. SDE_ERROR("invalid pingpong index for WB or CWB\n");
  1029. return;
  1030. }
  1031. refcount = atomic_read(&phys->wbirq_refcount);
  1032. /*
  1033. * For Dedicated CWB, only one overflow IRQ is used for
  1034. * both the PP_CWB blks. Make sure only one IRQ is registered
  1035. * when D-CWB is enabled.
  1036. */
  1037. wb_cfg = wb_enc->hw_wb->caps;
  1038. max_num_of_irqs = (wb_cfg->features & BIT(SDE_WB_HAS_DCWB)) ?
  1039. 1 : CRTC_DUAL_MIXERS_ONLY;
  1040. if (enable && atomic_inc_return(&phys->wbirq_refcount) == 1) {
  1041. sde_encoder_helper_register_irq(phys, INTR_IDX_WB_DONE);
  1042. if (ret)
  1043. atomic_dec_return(&phys->wbirq_refcount);
  1044. for (index = 0; index < max_num_of_irqs; index++)
  1045. if (cwb_irq_tbl[index + pp] != SDE_NONE)
  1046. sde_encoder_helper_register_irq(phys,
  1047. cwb_irq_tbl[index + pp]);
  1048. } else if (!enable &&
  1049. atomic_dec_return(&phys->wbirq_refcount) == 0) {
  1050. sde_encoder_helper_unregister_irq(phys, INTR_IDX_WB_DONE);
  1051. if (ret)
  1052. atomic_inc_return(&phys->wbirq_refcount);
  1053. for (index = 0; index < max_num_of_irqs; index++)
  1054. if (cwb_irq_tbl[index + pp] != SDE_NONE)
  1055. sde_encoder_helper_unregister_irq(phys,
  1056. cwb_irq_tbl[index + pp]);
  1057. }
  1058. }
  1059. /**
  1060. * sde_encoder_phys_wb_mode_set - set display mode
  1061. * @phys_enc: Pointer to physical encoder
  1062. * @mode: Pointer to requested display mode
  1063. * @adj_mode: Pointer to adjusted display mode
  1064. */
  1065. static void sde_encoder_phys_wb_mode_set(
  1066. struct sde_encoder_phys *phys_enc,
  1067. struct drm_display_mode *mode,
  1068. struct drm_display_mode *adj_mode)
  1069. {
  1070. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1071. struct sde_rm *rm = &phys_enc->sde_kms->rm;
  1072. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  1073. struct sde_rm_hw_iter iter;
  1074. int i, instance;
  1075. phys_enc->cached_mode = *adj_mode;
  1076. instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
  1077. SDE_DEBUG("[mode_set_cache:%d,\"%s\",%d,%d]\n",
  1078. hw_wb->idx - WB_0, mode->name,
  1079. mode->hdisplay, mode->vdisplay);
  1080. phys_enc->hw_ctl = NULL;
  1081. phys_enc->hw_cdm = NULL;
  1082. /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
  1083. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
  1084. for (i = 0; i <= instance; i++) {
  1085. sde_rm_get_hw(rm, &iter);
  1086. if (i == instance)
  1087. phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
  1088. }
  1089. if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
  1090. SDE_ERROR("failed init ctl: %ld\n",
  1091. (!phys_enc->hw_ctl) ?
  1092. -EINVAL : PTR_ERR(phys_enc->hw_ctl));
  1093. phys_enc->hw_ctl = NULL;
  1094. return;
  1095. }
  1096. /* CDM is optional */
  1097. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
  1098. for (i = 0; i <= instance; i++) {
  1099. sde_rm_get_hw(rm, &iter);
  1100. if (i == instance)
  1101. phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
  1102. }
  1103. if (IS_ERR(phys_enc->hw_cdm)) {
  1104. SDE_ERROR("CDM required but not allocated: %ld\n",
  1105. PTR_ERR(phys_enc->hw_cdm));
  1106. phys_enc->hw_cdm = NULL;
  1107. }
  1108. }
  1109. static int sde_encoder_phys_wb_frame_timeout(struct sde_encoder_phys *phys_enc)
  1110. {
  1111. u32 event = 0;
  1112. while (atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0) &&
  1113. phys_enc->parent_ops.handle_frame_done) {
  1114. event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE
  1115. | SDE_ENCODER_FRAME_EVENT_ERROR;
  1116. if (phys_enc->in_clone_mode)
  1117. event |= SDE_ENCODER_FRAME_EVENT_CWB_DONE;
  1118. else
  1119. event |= SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  1120. phys_enc->parent_ops.handle_frame_done(
  1121. phys_enc->parent, phys_enc, event);
  1122. SDE_EVT32(DRMID(phys_enc->parent), event,
  1123. atomic_read(&phys_enc->pending_retire_fence_cnt));
  1124. }
  1125. return event;
  1126. }
  1127. static bool _sde_encoder_phys_wb_is_idle(
  1128. struct sde_encoder_phys *phys_enc)
  1129. {
  1130. bool ret = false;
  1131. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1132. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  1133. struct sde_vbif_get_xin_status_params xin_status = {0};
  1134. xin_status.vbif_idx = hw_wb->caps->vbif_idx;
  1135. xin_status.xin_id = hw_wb->caps->xin_id;
  1136. xin_status.clk_ctrl = hw_wb->caps->clk_ctrl;
  1137. if (sde_vbif_get_xin_status(phys_enc->sde_kms, &xin_status)) {
  1138. _sde_encoder_phys_wb_frame_done_helper(wb_enc, false);
  1139. ret = true;
  1140. }
  1141. return ret;
  1142. }
  1143. static void _sde_encoder_phys_wb_reset_state(
  1144. struct sde_encoder_phys *phys_enc)
  1145. {
  1146. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1147. /*
  1148. * frame count and kickoff count are only used for debug purpose. Frame
  1149. * count can be more than kickoff count at the end of disable call due
  1150. * to extra frame_done wait. It does not cause any issue because
  1151. * frame_done wait is based on retire_fence count. Leaving these
  1152. * counters for debugging purpose.
  1153. */
  1154. if (wb_enc->frame_count != wb_enc->kickoff_count) {
  1155. SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
  1156. wb_enc->kickoff_count, wb_enc->frame_count,
  1157. phys_enc->in_clone_mode);
  1158. wb_enc->frame_count = wb_enc->kickoff_count;
  1159. }
  1160. phys_enc->enable_state = SDE_ENC_DISABLED;
  1161. wb_enc->crtc = NULL;
  1162. phys_enc->hw_cdm = NULL;
  1163. phys_enc->hw_ctl = NULL;
  1164. phys_enc->in_clone_mode = false;
  1165. }
  1166. static int _sde_encoder_phys_wb_wait_for_commit_done(
  1167. struct sde_encoder_phys *phys_enc, bool is_disable)
  1168. {
  1169. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1170. u32 event = 0;
  1171. u64 wb_time = 0;
  1172. int rc = 0;
  1173. struct sde_encoder_wait_info wait_info = {0};
  1174. /* Return EWOULDBLOCK since we know the wait isn't necessary */
  1175. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1176. SDE_ERROR("encoder already disabled\n");
  1177. return -EWOULDBLOCK;
  1178. }
  1179. SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count,
  1180. wb_enc->kickoff_count, !!wb_enc->wb_fb, is_disable,
  1181. phys_enc->in_clone_mode);
  1182. if (!is_disable && phys_enc->in_clone_mode &&
  1183. (atomic_read(&phys_enc->pending_retire_fence_cnt) <= 1))
  1184. goto skip_wait;
  1185. /* signal completion if commit with no framebuffer */
  1186. if (!wb_enc->wb_fb) {
  1187. SDE_DEBUG("no output framebuffer\n");
  1188. _sde_encoder_phys_wb_frame_done_helper(wb_enc, false);
  1189. }
  1190. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1191. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1192. wait_info.timeout_ms = max_t(u32, wb_enc->wbdone_timeout,
  1193. KICKOFF_TIMEOUT_MS);
  1194. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WB_DONE,
  1195. &wait_info);
  1196. if (rc == -ETIMEDOUT && _sde_encoder_phys_wb_is_idle(phys_enc)) {
  1197. rc = 0;
  1198. } else if (rc == -ETIMEDOUT) {
  1199. SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
  1200. wb_enc->frame_count, SDE_EVTLOG_ERROR);
  1201. SDE_ERROR("wb:%d kickoff timed out\n", WBID(wb_enc));
  1202. event = sde_encoder_phys_wb_frame_timeout(phys_enc);
  1203. }
  1204. /* cleanup writeback framebuffer */
  1205. if (wb_enc->wb_fb && wb_enc->wb_aspace) {
  1206. msm_framebuffer_cleanup(wb_enc->wb_fb, wb_enc->wb_aspace);
  1207. drm_framebuffer_put(wb_enc->wb_fb);
  1208. wb_enc->wb_fb = NULL;
  1209. wb_enc->wb_aspace = NULL;
  1210. }
  1211. skip_wait:
  1212. /* remove vote for iommu/clk/bus */
  1213. wb_enc->frame_count++;
  1214. if (!rc) {
  1215. wb_enc->end_time = ktime_get();
  1216. wb_time = (u64)ktime_to_us(wb_enc->end_time) -
  1217. (u64)ktime_to_us(wb_enc->start_time);
  1218. SDE_DEBUG("wb:%d took %llu us\n", WBID(wb_enc), wb_time);
  1219. }
  1220. /* cleanup previous buffer if pending */
  1221. if (wb_enc->cwb_old_fb && wb_enc->cwb_old_aspace) {
  1222. msm_framebuffer_cleanup(wb_enc->cwb_old_fb, wb_enc->cwb_old_aspace);
  1223. drm_framebuffer_put(wb_enc->cwb_old_fb);
  1224. wb_enc->cwb_old_fb = NULL;
  1225. wb_enc->cwb_old_aspace = NULL;
  1226. }
  1227. SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count,
  1228. wb_time, event, rc);
  1229. return rc;
  1230. }
  1231. /**
  1232. * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
  1233. * @phys_enc: Pointer to physical encoder
  1234. */
  1235. static int sde_encoder_phys_wb_wait_for_commit_done(
  1236. struct sde_encoder_phys *phys_enc)
  1237. {
  1238. int rc;
  1239. if (phys_enc->enable_state == SDE_ENC_DISABLING &&
  1240. phys_enc->in_clone_mode) {
  1241. rc = _sde_encoder_phys_wb_wait_for_commit_done(phys_enc, true);
  1242. _sde_encoder_phys_wb_reset_state(phys_enc);
  1243. sde_encoder_phys_wb_irq_ctrl(phys_enc, false);
  1244. } else {
  1245. rc = _sde_encoder_phys_wb_wait_for_commit_done(phys_enc, false);
  1246. }
  1247. return rc;
  1248. }
  1249. static int sde_encoder_phys_wb_wait_for_tx_complete(
  1250. struct sde_encoder_phys *phys_enc)
  1251. {
  1252. if (!atomic_read(&phys_enc->pending_retire_fence_cnt))
  1253. return 0;
  1254. return _sde_encoder_phys_wb_wait_for_commit_done(phys_enc, true);
  1255. }
  1256. /**
  1257. * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
  1258. * @phys_enc: Pointer to physical encoder
  1259. * @params: kickoff parameters
  1260. * Returns: Zero on success
  1261. */
  1262. static int sde_encoder_phys_wb_prepare_for_kickoff(
  1263. struct sde_encoder_phys *phys_enc,
  1264. struct sde_encoder_kickoff_params *params)
  1265. {
  1266. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1267. SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
  1268. wb_enc->kickoff_count);
  1269. if (phys_enc->in_clone_mode) {
  1270. wb_enc->cwb_old_fb = wb_enc->wb_fb;
  1271. wb_enc->cwb_old_aspace = wb_enc->wb_aspace;
  1272. }
  1273. wb_enc->kickoff_count++;
  1274. /* set OT limit & enable traffic shaper */
  1275. sde_encoder_phys_wb_setup(phys_enc);
  1276. _sde_encoder_phys_wb_update_flush(phys_enc);
  1277. _sde_encoder_phys_wb_update_cwb_flush(phys_enc, true);
  1278. /* vote for iommu/clk/bus */
  1279. wb_enc->start_time = ktime_get();
  1280. SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
  1281. wb_enc->kickoff_count, wb_enc->frame_count,
  1282. phys_enc->in_clone_mode);
  1283. return 0;
  1284. }
  1285. /**
  1286. * sde_encoder_phys_wb_trigger_flush - trigger flush processing
  1287. * @phys_enc: Pointer to physical encoder
  1288. */
  1289. static void sde_encoder_phys_wb_trigger_flush(struct sde_encoder_phys *phys_enc)
  1290. {
  1291. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1292. if (!phys_enc || !wb_enc->hw_wb) {
  1293. SDE_ERROR("invalid encoder\n");
  1294. return;
  1295. }
  1296. /*
  1297. * Bail out iff in CWB mode. In case of CWB, primary control-path
  1298. * which is actually driving would trigger the flush
  1299. */
  1300. if (phys_enc->in_clone_mode) {
  1301. SDE_DEBUG("in CWB mode. early return\n");
  1302. return;
  1303. }
  1304. SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
  1305. /* clear pending flush if commit with no framebuffer */
  1306. if (!wb_enc->wb_fb) {
  1307. SDE_DEBUG("no output framebuffer\n");
  1308. return;
  1309. }
  1310. sde_encoder_helper_trigger_flush(phys_enc);
  1311. }
  1312. /**
  1313. * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
  1314. * @phys_enc: Pointer to physical encoder
  1315. */
  1316. static void sde_encoder_phys_wb_handle_post_kickoff(
  1317. struct sde_encoder_phys *phys_enc)
  1318. {
  1319. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1320. SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
  1321. SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc));
  1322. }
  1323. /**
  1324. * _sde_encoder_phys_wb_init_internal_fb - create fb for internal commit
  1325. * @wb_enc: Pointer to writeback encoder
  1326. * @pixel_format: DRM pixel format
  1327. * @width: Desired fb width
  1328. * @height: Desired fb height
  1329. * @pitch: Desired fb pitch
  1330. */
  1331. static int _sde_encoder_phys_wb_init_internal_fb(
  1332. struct sde_encoder_phys_wb *wb_enc,
  1333. uint32_t pixel_format, uint32_t width,
  1334. uint32_t height, uint32_t pitch)
  1335. {
  1336. struct drm_device *dev;
  1337. struct drm_framebuffer *fb;
  1338. struct drm_mode_fb_cmd2 mode_cmd;
  1339. uint32_t size;
  1340. int nplanes, i, ret;
  1341. struct msm_gem_address_space *aspace;
  1342. const struct drm_format_info *info;
  1343. if (!wb_enc || !wb_enc->base.parent || !wb_enc->base.sde_kms) {
  1344. SDE_ERROR("invalid params\n");
  1345. return -EINVAL;
  1346. }
  1347. aspace = wb_enc->base.sde_kms->aspace[SDE_IOMMU_DOMAIN_UNSECURE];
  1348. if (!aspace) {
  1349. SDE_ERROR("invalid address space\n");
  1350. return -EINVAL;
  1351. }
  1352. dev = wb_enc->base.sde_kms->dev;
  1353. if (!dev) {
  1354. SDE_ERROR("invalid dev\n");
  1355. return -EINVAL;
  1356. }
  1357. memset(&mode_cmd, 0, sizeof(mode_cmd));
  1358. mode_cmd.pixel_format = pixel_format;
  1359. mode_cmd.width = width;
  1360. mode_cmd.height = height;
  1361. mode_cmd.pitches[0] = pitch;
  1362. size = sde_format_get_framebuffer_size(pixel_format,
  1363. mode_cmd.width, mode_cmd.height,
  1364. mode_cmd.pitches, 0);
  1365. if (!size) {
  1366. SDE_DEBUG("not creating zero size buffer\n");
  1367. return -EINVAL;
  1368. }
  1369. /* allocate gem tracking object */
  1370. info = drm_get_format_info(dev, &mode_cmd);
  1371. nplanes = info->num_planes;
  1372. if (nplanes >= SDE_MAX_PLANES) {
  1373. SDE_ERROR("requested format has too many planes\n");
  1374. return -EINVAL;
  1375. }
  1376. wb_enc->bo_disable[0] = msm_gem_new(dev, size,
  1377. MSM_BO_SCANOUT | MSM_BO_WC);
  1378. if (IS_ERR_OR_NULL(wb_enc->bo_disable[0])) {
  1379. ret = PTR_ERR(wb_enc->bo_disable[0]);
  1380. wb_enc->bo_disable[0] = NULL;
  1381. SDE_ERROR("failed to create bo, %d\n", ret);
  1382. return ret;
  1383. }
  1384. for (i = 0; i < nplanes; ++i) {
  1385. wb_enc->bo_disable[i] = wb_enc->bo_disable[0];
  1386. mode_cmd.pitches[i] = width * info->cpp[i];
  1387. }
  1388. fb = msm_framebuffer_init(dev, &mode_cmd, wb_enc->bo_disable);
  1389. if (IS_ERR_OR_NULL(fb)) {
  1390. ret = PTR_ERR(fb);
  1391. drm_gem_object_put(wb_enc->bo_disable[0]);
  1392. wb_enc->bo_disable[0] = NULL;
  1393. SDE_ERROR("failed to init fb, %d\n", ret);
  1394. return ret;
  1395. }
  1396. /* prepare the backing buffer now so that it's available later */
  1397. ret = msm_framebuffer_prepare(fb, aspace);
  1398. if (!ret)
  1399. wb_enc->fb_disable = fb;
  1400. return ret;
  1401. }
  1402. /**
  1403. * _sde_encoder_phys_wb_destroy_internal_fb - deconstruct internal fb
  1404. * @wb_enc: Pointer to writeback encoder
  1405. */
  1406. static void _sde_encoder_phys_wb_destroy_internal_fb(
  1407. struct sde_encoder_phys_wb *wb_enc)
  1408. {
  1409. if (!wb_enc)
  1410. return;
  1411. if (wb_enc->fb_disable) {
  1412. drm_framebuffer_unregister_private(wb_enc->fb_disable);
  1413. drm_framebuffer_remove(wb_enc->fb_disable);
  1414. wb_enc->fb_disable = NULL;
  1415. }
  1416. if (wb_enc->bo_disable[0]) {
  1417. drm_gem_object_put(wb_enc->bo_disable[0]);
  1418. wb_enc->bo_disable[0] = NULL;
  1419. }
  1420. }
  1421. /**
  1422. * sde_encoder_phys_wb_enable - enable writeback encoder
  1423. * @phys_enc: Pointer to physical encoder
  1424. */
  1425. static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
  1426. {
  1427. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1428. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  1429. struct drm_device *dev;
  1430. struct drm_connector *connector;
  1431. SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
  1432. if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
  1433. SDE_ERROR("invalid drm device\n");
  1434. return;
  1435. }
  1436. dev = wb_enc->base.parent->dev;
  1437. /* find associated writeback connector */
  1438. connector = phys_enc->connector;
  1439. if (!connector || connector->encoder != phys_enc->parent) {
  1440. SDE_ERROR("failed to find writeback connector\n");
  1441. return;
  1442. }
  1443. wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
  1444. phys_enc->enable_state = SDE_ENC_ENABLED;
  1445. /*
  1446. * cache the crtc in wb_enc on enable for duration of use case
  1447. * for correctly servicing asynchronous irq events and timers
  1448. */
  1449. wb_enc->crtc = phys_enc->parent->crtc;
  1450. }
  1451. /**
  1452. * sde_encoder_phys_wb_disable - disable writeback encoder
  1453. * @phys_enc: Pointer to physical encoder
  1454. */
  1455. static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
  1456. {
  1457. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1458. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  1459. SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
  1460. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1461. SDE_ERROR("encoder is already disabled\n");
  1462. return;
  1463. }
  1464. SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
  1465. hw_wb->idx - WB_0, wb_enc->frame_count,
  1466. wb_enc->kickoff_count);
  1467. if (!phys_enc->in_clone_mode || !wb_enc->crtc->state->active)
  1468. _sde_encoder_phys_wb_wait_for_commit_done(phys_enc, true);
  1469. if (!phys_enc->hw_ctl || !phys_enc->parent ||
  1470. !phys_enc->sde_kms || !wb_enc->fb_disable) {
  1471. SDE_DEBUG("invalid enc, skipping extra commit\n");
  1472. goto exit;
  1473. }
  1474. if (phys_enc->in_clone_mode) {
  1475. _sde_encoder_phys_wb_setup_cwb(phys_enc, false);
  1476. _sde_encoder_phys_wb_update_cwb_flush(phys_enc, false);
  1477. phys_enc->enable_state = SDE_ENC_DISABLING;
  1478. if (wb_enc->crtc->state->active) {
  1479. sde_encoder_phys_wb_irq_ctrl(phys_enc, true);
  1480. return;
  1481. }
  1482. goto exit;
  1483. }
  1484. /* reset h/w before final flush */
  1485. if (phys_enc->hw_ctl->ops.clear_pending_flush)
  1486. phys_enc->hw_ctl->ops.clear_pending_flush(phys_enc->hw_ctl);
  1487. /*
  1488. * New CTL reset sequence from 5.0 MDP onwards.
  1489. * If has_3d_merge_reset is not set, legacy reset
  1490. * sequence is executed.
  1491. */
  1492. if (hw_wb->catalog->has_3d_merge_reset) {
  1493. sde_encoder_helper_phys_disable(phys_enc, wb_enc);
  1494. goto exit;
  1495. }
  1496. if (sde_encoder_helper_reset_mixers(phys_enc, NULL))
  1497. goto exit;
  1498. phys_enc->enable_state = SDE_ENC_DISABLING;
  1499. sde_encoder_phys_wb_prepare_for_kickoff(phys_enc, NULL);
  1500. sde_encoder_phys_wb_irq_ctrl(phys_enc, true);
  1501. if (phys_enc->hw_ctl->ops.trigger_flush)
  1502. phys_enc->hw_ctl->ops.trigger_flush(phys_enc->hw_ctl);
  1503. sde_encoder_helper_trigger_start(phys_enc);
  1504. _sde_encoder_phys_wb_wait_for_commit_done(phys_enc, true);
  1505. sde_encoder_phys_wb_irq_ctrl(phys_enc, false);
  1506. exit:
  1507. _sde_encoder_phys_wb_reset_state(phys_enc);
  1508. }
  1509. /**
  1510. * sde_encoder_phys_wb_get_hw_resources - get hardware resources
  1511. * @phys_enc: Pointer to physical encoder
  1512. * @hw_res: Pointer to encoder resources
  1513. */
  1514. static void sde_encoder_phys_wb_get_hw_resources(
  1515. struct sde_encoder_phys *phys_enc,
  1516. struct sde_encoder_hw_resources *hw_res,
  1517. struct drm_connector_state *conn_state)
  1518. {
  1519. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1520. struct sde_hw_wb *hw_wb;
  1521. struct drm_framebuffer *fb;
  1522. const struct sde_format *fmt = NULL;
  1523. if (!phys_enc) {
  1524. SDE_ERROR("invalid encoder\n");
  1525. return;
  1526. }
  1527. fb = sde_wb_connector_state_get_output_fb(conn_state);
  1528. if (fb) {
  1529. fmt = sde_get_sde_format_ext(fb->format->format, fb->modifier);
  1530. if (!fmt) {
  1531. SDE_ERROR("unsupported output pixel format:%d\n",
  1532. fb->format->format);
  1533. return;
  1534. }
  1535. }
  1536. hw_wb = wb_enc->hw_wb;
  1537. hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
  1538. hw_res->needs_cdm = fmt ? SDE_FORMAT_IS_YUV(fmt) : false;
  1539. SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
  1540. hw_res->wbs[hw_wb->idx - WB_0],
  1541. hw_res->needs_cdm);
  1542. }
  1543. #ifdef CONFIG_DEBUG_FS
  1544. /**
  1545. * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
  1546. * @phys_enc: Pointer to physical encoder
  1547. * @debugfs_root: Pointer to virtual encoder's debugfs_root dir
  1548. */
  1549. static int sde_encoder_phys_wb_init_debugfs(
  1550. struct sde_encoder_phys *phys_enc, struct dentry *debugfs_root)
  1551. {
  1552. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1553. if (!phys_enc || !wb_enc->hw_wb || !debugfs_root)
  1554. return -EINVAL;
  1555. debugfs_create_u32("wbdone_timeout", 0600, debugfs_root, &wb_enc->wbdone_timeout);
  1556. return 0;
  1557. }
  1558. #else
  1559. static int sde_encoder_phys_wb_init_debugfs(
  1560. struct sde_encoder_phys *phys_enc, struct dentry *debugfs_root)
  1561. {
  1562. return 0;
  1563. }
  1564. #endif
  1565. static int sde_encoder_phys_wb_late_register(struct sde_encoder_phys *phys_enc,
  1566. struct dentry *debugfs_root)
  1567. {
  1568. return sde_encoder_phys_wb_init_debugfs(phys_enc, debugfs_root);
  1569. }
  1570. /**
  1571. * sde_encoder_phys_wb_destroy - destroy writeback encoder
  1572. * @phys_enc: Pointer to physical encoder
  1573. */
  1574. static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
  1575. {
  1576. struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
  1577. struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
  1578. SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
  1579. if (!phys_enc)
  1580. return;
  1581. _sde_encoder_phys_wb_destroy_internal_fb(wb_enc);
  1582. kfree(wb_enc);
  1583. }
  1584. /**
  1585. * sde_encoder_phys_wb_init_ops - initialize writeback operations
  1586. * @ops: Pointer to encoder operation table
  1587. */
  1588. static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
  1589. {
  1590. ops->late_register = sde_encoder_phys_wb_late_register;
  1591. ops->is_master = sde_encoder_phys_wb_is_master;
  1592. ops->mode_set = sde_encoder_phys_wb_mode_set;
  1593. ops->enable = sde_encoder_phys_wb_enable;
  1594. ops->disable = sde_encoder_phys_wb_disable;
  1595. ops->destroy = sde_encoder_phys_wb_destroy;
  1596. ops->atomic_check = sde_encoder_phys_wb_atomic_check;
  1597. ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
  1598. ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
  1599. ops->wait_for_tx_complete = sde_encoder_phys_wb_wait_for_tx_complete;
  1600. ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
  1601. ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
  1602. ops->trigger_flush = sde_encoder_phys_wb_trigger_flush;
  1603. ops->trigger_start = sde_encoder_helper_trigger_start;
  1604. ops->hw_reset = sde_encoder_helper_hw_reset;
  1605. ops->irq_control = sde_encoder_phys_wb_irq_ctrl;
  1606. }
  1607. /**
  1608. * sde_encoder_phys_wb_init - initialize writeback encoder
  1609. * @init: Pointer to init info structure with initialization params
  1610. */
  1611. struct sde_encoder_phys *sde_encoder_phys_wb_init(
  1612. struct sde_enc_phys_init_params *p)
  1613. {
  1614. struct sde_encoder_phys *phys_enc;
  1615. struct sde_encoder_phys_wb *wb_enc;
  1616. const struct sde_wb_cfg *wb_cfg;
  1617. struct sde_hw_mdp *hw_mdp;
  1618. struct sde_encoder_irq *irq;
  1619. int ret = 0;
  1620. SDE_DEBUG("\n");
  1621. if (!p || !p->parent) {
  1622. SDE_ERROR("invalid params\n");
  1623. ret = -EINVAL;
  1624. goto fail_alloc;
  1625. }
  1626. wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
  1627. if (!wb_enc) {
  1628. SDE_ERROR("failed to allocate wb enc\n");
  1629. ret = -ENOMEM;
  1630. goto fail_alloc;
  1631. }
  1632. wb_enc->wbdone_timeout = KICKOFF_TIMEOUT_MS;
  1633. phys_enc = &wb_enc->base;
  1634. if (p->sde_kms->vbif[VBIF_NRT]) {
  1635. wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE] =
  1636. p->sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_UNSECURE];
  1637. wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] =
  1638. p->sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_SECURE];
  1639. } else {
  1640. wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE] =
  1641. p->sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE];
  1642. wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] =
  1643. p->sde_kms->aspace[MSM_SMMU_DOMAIN_SECURE];
  1644. }
  1645. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  1646. if (IS_ERR_OR_NULL(hw_mdp)) {
  1647. ret = PTR_ERR(hw_mdp);
  1648. SDE_ERROR("failed to init hw_top: %d\n", ret);
  1649. goto fail_mdp_init;
  1650. }
  1651. phys_enc->hw_mdptop = hw_mdp;
  1652. /**
  1653. * hw_wb resource permanently assigned to this encoder
  1654. * Other resources allocated at atomic commit time by use case
  1655. */
  1656. if (p->wb_idx != SDE_NONE) {
  1657. struct sde_rm_hw_iter iter;
  1658. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
  1659. while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
  1660. struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
  1661. if (hw_wb->idx == p->wb_idx) {
  1662. wb_enc->hw_wb = hw_wb;
  1663. break;
  1664. }
  1665. }
  1666. if (!wb_enc->hw_wb) {
  1667. ret = -EINVAL;
  1668. SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
  1669. goto fail_wb_init;
  1670. }
  1671. } else {
  1672. ret = -EINVAL;
  1673. SDE_ERROR("invalid wb_idx\n");
  1674. goto fail_wb_check;
  1675. }
  1676. sde_encoder_phys_wb_init_ops(&phys_enc->ops);
  1677. phys_enc->parent = p->parent;
  1678. phys_enc->parent_ops = p->parent_ops;
  1679. phys_enc->sde_kms = p->sde_kms;
  1680. phys_enc->split_role = p->split_role;
  1681. phys_enc->intf_mode = INTF_MODE_WB_LINE;
  1682. phys_enc->intf_idx = p->intf_idx;
  1683. phys_enc->enc_spinlock = p->enc_spinlock;
  1684. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  1685. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  1686. atomic_set(&phys_enc->wbirq_refcount, 0);
  1687. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  1688. wb_cfg = wb_enc->hw_wb->caps;
  1689. irq = &phys_enc->irq[INTR_IDX_WB_DONE];
  1690. INIT_LIST_HEAD(&irq->cb.list);
  1691. irq->name = "wb_done";
  1692. irq->hw_idx = wb_enc->hw_wb->idx;
  1693. irq->irq_idx = -1;
  1694. irq->intr_type = sde_encoder_phys_wb_get_intr_type(wb_enc->hw_wb);
  1695. irq->intr_idx = INTR_IDX_WB_DONE;
  1696. irq->cb.arg = wb_enc;
  1697. irq->cb.func = sde_encoder_phys_wb_done_irq;
  1698. if (wb_cfg && (wb_cfg->features & BIT(SDE_WB_HAS_DCWB))) {
  1699. irq = &phys_enc->irq[INTR_IDX_PP_CWB_OVFL];
  1700. INIT_LIST_HEAD(&irq->cb.list);
  1701. irq->name = "pp_cwb0_overflow";
  1702. irq->hw_idx = PINGPONG_CWB_0;
  1703. irq->irq_idx = -1;
  1704. irq->intr_type = SDE_IRQ_TYPE_CWB_OVERFLOW;
  1705. irq->intr_idx = INTR_IDX_PP_CWB_OVFL;
  1706. irq->cb.arg = wb_enc;
  1707. irq->cb.func = sde_encoder_phys_cwb_ovflow;
  1708. } else {
  1709. irq = &phys_enc->irq[INTR_IDX_PP1_OVFL];
  1710. INIT_LIST_HEAD(&irq->cb.list);
  1711. irq->name = "pp1_overflow";
  1712. irq->hw_idx = CWB_1;
  1713. irq->irq_idx = -1;
  1714. irq->intr_type = SDE_IRQ_TYPE_CWB_OVERFLOW;
  1715. irq->intr_idx = INTR_IDX_PP1_OVFL;
  1716. irq->cb.arg = wb_enc;
  1717. irq->cb.func = sde_encoder_phys_cwb_ovflow;
  1718. irq = &phys_enc->irq[INTR_IDX_PP2_OVFL];
  1719. INIT_LIST_HEAD(&irq->cb.list);
  1720. irq->name = "pp2_overflow";
  1721. irq->hw_idx = CWB_2;
  1722. irq->irq_idx = -1;
  1723. irq->intr_type = SDE_IRQ_TYPE_CWB_OVERFLOW;
  1724. irq->intr_idx = INTR_IDX_PP2_OVFL;
  1725. irq->cb.arg = wb_enc;
  1726. irq->cb.func = sde_encoder_phys_cwb_ovflow;
  1727. irq = &phys_enc->irq[INTR_IDX_PP3_OVFL];
  1728. INIT_LIST_HEAD(&irq->cb.list);
  1729. irq->name = "pp3_overflow";
  1730. irq->hw_idx = CWB_3;
  1731. irq->irq_idx = -1;
  1732. irq->intr_type = SDE_IRQ_TYPE_CWB_OVERFLOW;
  1733. irq->intr_idx = INTR_IDX_PP3_OVFL;
  1734. irq->cb.arg = wb_enc;
  1735. irq->cb.func = sde_encoder_phys_cwb_ovflow;
  1736. irq = &phys_enc->irq[INTR_IDX_PP4_OVFL];
  1737. INIT_LIST_HEAD(&irq->cb.list);
  1738. irq->name = "pp4_overflow";
  1739. irq->hw_idx = CWB_4;
  1740. irq->irq_idx = -1;
  1741. irq->intr_type = SDE_IRQ_TYPE_CWB_OVERFLOW;
  1742. irq->intr_idx = INTR_IDX_PP4_OVFL;
  1743. irq->cb.arg = wb_enc;
  1744. irq->cb.func = sde_encoder_phys_cwb_ovflow;
  1745. irq = &phys_enc->irq[INTR_IDX_PP5_OVFL];
  1746. INIT_LIST_HEAD(&irq->cb.list);
  1747. irq->name = "pp5_overflow";
  1748. irq->hw_idx = CWB_5;
  1749. irq->irq_idx = -1;
  1750. irq->intr_type = SDE_IRQ_TYPE_CWB_OVERFLOW;
  1751. irq->intr_idx = INTR_IDX_PP5_OVFL;
  1752. irq->cb.arg = wb_enc;
  1753. irq->cb.func = sde_encoder_phys_cwb_ovflow;
  1754. }
  1755. /* create internal buffer for disable logic */
  1756. if (_sde_encoder_phys_wb_init_internal_fb(wb_enc,
  1757. DRM_FORMAT_RGB888, 2, 1, 6)) {
  1758. SDE_ERROR("failed to init internal fb\n");
  1759. goto fail_wb_init;
  1760. }
  1761. SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
  1762. wb_enc->hw_wb->idx - WB_0);
  1763. return phys_enc;
  1764. fail_wb_init:
  1765. fail_wb_check:
  1766. fail_mdp_init:
  1767. kfree(wb_enc);
  1768. fail_alloc:
  1769. return ERR_PTR(ret);
  1770. }