sde_encoder_phys_wb.c 57 KB

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