sde_encoder_phys_wb.c 92 KB

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