sde_encoder_phys_wb.c 74 KB

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