sde_encoder_phys_wb.c 91 KB

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