sde_encoder_phys_wb.c 79 KB

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