sde_encoder_phys_wb.c 93 KB

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