sde_encoder_phys_wb.c 59 KB

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