sde_encoder_phys_wb.c 93 KB

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