sde_encoder_phys_wb.c 60 KB

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