sde_encoder_phys_wb.c 95 KB

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