sde_encoder_phys_wb.c 91 KB

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