sde_encoder_phys_wb.c 92 KB

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