sde_encoder_phys_wb.c 79 KB

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