sde_encoder_phys_wb.c 71 KB

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