sde_encoder_phys_wb.c 93 KB

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