sde_encoder_phys_wb.c 79 KB

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