sde_rm.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include "sde_kms.h"
  8. #include "sde_hw_lm.h"
  9. #include "sde_hw_ctl.h"
  10. #include "sde_hw_cdm.h"
  11. #include "sde_hw_dspp.h"
  12. #include "sde_hw_ds.h"
  13. #include "sde_hw_pingpong.h"
  14. #include "sde_hw_intf.h"
  15. #include "sde_hw_wb.h"
  16. #include "sde_encoder.h"
  17. #include "sde_connector.h"
  18. #include "sde_hw_dsc.h"
  19. #include "sde_hw_vdc.h"
  20. #include "sde_crtc.h"
  21. #include "sde_hw_qdss.h"
  22. #include "sde_vbif.h"
  23. #include "sde_hw_dnsc_blur.h"
  24. #define RESERVED_BY_OTHER(h, r) \
  25. (((h)->rsvp && ((h)->rsvp->enc_id != (r)->enc_id)) ||\
  26. ((h)->rsvp_nxt && ((h)->rsvp_nxt->enc_id != (r)->enc_id)))
  27. #define RESERVED_BY_CURRENT(h, r) \
  28. (((h)->rsvp && ((h)->rsvp->enc_id == (r)->enc_id)))
  29. #define RM_RQ_LOCK(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK))
  30. #define RM_RQ_CLEAR(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_CLEAR))
  31. #define RM_RQ_DSPP(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DSPP))
  32. #define RM_RQ_DS(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DS))
  33. #define RM_RQ_CWB(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_CWB))
  34. #define RM_RQ_DCWB(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DCWB))
  35. #define RM_RQ_DNSC_BLUR(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DNSC_BLUR))
  36. #define RM_IS_TOPOLOGY_MATCH(t, r) ((t).num_lm == (r).num_lm && \
  37. (t).num_comp_enc == (r).num_enc && \
  38. (t).num_intf == (r).num_intf && \
  39. (t).comp_type == (r).comp_type)
  40. #define IS_COMPATIBLE_PP_DSC(p, d) (p % 2 == d % 2)
  41. /* ~one vsync poll time for rsvp_nxt to cleared by modeset from commit thread */
  42. #define RM_NXT_CLEAR_POLL_TIMEOUT_US 33000
  43. /**
  44. * toplogy information to be used when ctl path version does not
  45. * support driving more than one interface per ctl_path
  46. */
  47. static const struct sde_rm_topology_def g_top_table[SDE_RM_TOPOLOGY_MAX] = {
  48. { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false,
  49. MSM_DISPLAY_COMPRESSION_NONE },
  50. { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false,
  51. MSM_DISPLAY_COMPRESSION_NONE },
  52. { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false,
  53. MSM_DISPLAY_COMPRESSION_DSC },
  54. { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 2, true,
  55. MSM_DISPLAY_COMPRESSION_NONE },
  56. { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 2, true,
  57. MSM_DISPLAY_COMPRESSION_DSC },
  58. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false,
  59. MSM_DISPLAY_COMPRESSION_NONE },
  60. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false,
  61. MSM_DISPLAY_COMPRESSION_DSC },
  62. { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false,
  63. MSM_DISPLAY_COMPRESSION_DSC },
  64. { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, true,
  65. MSM_DISPLAY_COMPRESSION_NONE },
  66. };
  67. /**
  68. * topology information to be used when the ctl path version
  69. * is SDE_CTL_CFG_VERSION_1_0_0
  70. */
  71. static const struct sde_rm_topology_def g_top_table_v1[SDE_RM_TOPOLOGY_MAX] = {
  72. { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false,
  73. MSM_DISPLAY_COMPRESSION_NONE },
  74. { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false,
  75. MSM_DISPLAY_COMPRESSION_NONE },
  76. { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false,
  77. MSM_DISPLAY_COMPRESSION_DSC },
  78. { SDE_RM_TOPOLOGY_SINGLEPIPE_VDC, 1, 1, 1, 1, false,
  79. MSM_DISPLAY_COMPRESSION_VDC },
  80. { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 1, false,
  81. MSM_DISPLAY_COMPRESSION_NONE },
  82. { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 1, false,
  83. MSM_DISPLAY_COMPRESSION_DSC },
  84. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false,
  85. MSM_DISPLAY_COMPRESSION_NONE },
  86. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false,
  87. MSM_DISPLAY_COMPRESSION_DSC },
  88. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_VDC, 2, 1, 1, 1, false,
  89. MSM_DISPLAY_COMPRESSION_VDC },
  90. { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false,
  91. MSM_DISPLAY_COMPRESSION_DSC },
  92. { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, false,
  93. MSM_DISPLAY_COMPRESSION_NONE },
  94. { SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE, 4, 0, 2, 1, false,
  95. MSM_DISPLAY_COMPRESSION_NONE },
  96. { SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE_DSC, 4, 3, 2, 1, false,
  97. MSM_DISPLAY_COMPRESSION_DSC },
  98. { SDE_RM_TOPOLOGY_QUADPIPE_DSCMERGE, 4, 4, 2, 1, false,
  99. MSM_DISPLAY_COMPRESSION_DSC },
  100. { SDE_RM_TOPOLOGY_QUADPIPE_DSC4HSMERGE, 4, 4, 1, 1, false,
  101. MSM_DISPLAY_COMPRESSION_DSC },
  102. };
  103. char sde_hw_blk_str[SDE_HW_BLK_MAX][SDE_HW_BLK_NAME_LEN] = {
  104. "top",
  105. "sspp",
  106. "lm",
  107. "dspp",
  108. "ds",
  109. "ctl",
  110. "cdm",
  111. "pingpong",
  112. "intf",
  113. "wb",
  114. "dsc",
  115. "vdc",
  116. "merge_3d",
  117. "qdss",
  118. "dnsc_blur"
  119. };
  120. /**
  121. * struct sde_rm_requirements - Reservation requirements parameter bundle
  122. * @top_ctrl: topology control preference from kernel client
  123. * @top: selected topology for the display
  124. * @hw_res: Hardware resources required as reported by the encoders
  125. */
  126. struct sde_rm_requirements {
  127. uint64_t top_ctrl;
  128. const struct sde_rm_topology_def *topology;
  129. struct sde_encoder_hw_resources hw_res;
  130. };
  131. /**
  132. * struct sde_rm_rsvp - Use Case Reservation tagging structure
  133. * Used to tag HW blocks as reserved by a CRTC->Encoder->Connector chain
  134. * By using as a tag, rather than lists of pointers to HW blocks used
  135. * we can avoid some list management since we don't know how many blocks
  136. * of each type a given use case may require.
  137. * @list: List head for list of all reservations
  138. * @seq: Global RSVP sequence number for debugging, especially for
  139. * differentiating differenct allocations for same encoder.
  140. * @enc_id: Reservations are tracked by Encoder DRM object ID.
  141. * CRTCs may be connected to multiple Encoders.
  142. * An encoder or connector id identifies the display path.
  143. * @topology: DRM<->HW topology use case
  144. * @pending: True for pending rsvp-nxt, cleared when the rsvp is committed
  145. */
  146. struct sde_rm_rsvp {
  147. struct list_head list;
  148. uint32_t seq;
  149. uint32_t enc_id;
  150. enum sde_rm_topology_name topology;
  151. bool pending;
  152. };
  153. /**
  154. * struct sde_rm_hw_blk - hardware block tracking list member
  155. * @list: List head for list of all hardware blocks tracking items
  156. * @rsvp: Pointer to use case reservation if reserved by a client
  157. * @rsvp_nxt: Temporary pointer used during reservation to the incoming
  158. * request. Will be swapped into rsvp if proposal is accepted
  159. * @type: Type of hardware block this structure tracks
  160. * @id: Hardware ID number, within it's own space, ie. LM_X
  161. * @catalog: Pointer to the hardware catalog entry for this block
  162. * @hw: Pointer to the hardware register access object for this block
  163. */
  164. struct sde_rm_hw_blk {
  165. struct list_head list;
  166. struct sde_rm_rsvp *rsvp;
  167. struct sde_rm_rsvp *rsvp_nxt;
  168. enum sde_hw_blk_type type;
  169. uint32_t id;
  170. struct sde_hw_blk_reg_map *hw;
  171. };
  172. /**
  173. * sde_rm_dbg_rsvp_stage - enum of steps in making reservation for event logging
  174. */
  175. enum sde_rm_dbg_rsvp_stage {
  176. SDE_RM_STAGE_BEGIN,
  177. SDE_RM_STAGE_AFTER_CLEAR,
  178. SDE_RM_STAGE_AFTER_RSVPNEXT,
  179. SDE_RM_STAGE_FINAL
  180. };
  181. static void _sde_rm_inc_resource_info_lm(struct sde_rm *rm,
  182. struct msm_resource_caps_info *avail_res,
  183. struct sde_rm_hw_blk *blk)
  184. {
  185. struct sde_rm_hw_blk *blk2;
  186. const struct sde_lm_cfg *lm_cfg, *lm_cfg2;
  187. lm_cfg = to_sde_hw_mixer(blk->hw)->cap;
  188. /* Do not track & expose dummy mixers */
  189. if (lm_cfg->dummy_mixer)
  190. return;
  191. avail_res->num_lm++;
  192. /* Check for 3d muxes by comparing paired lms */
  193. list_for_each_entry(blk2, &rm->hw_blks[SDE_HW_BLK_LM], list) {
  194. lm_cfg2 = to_sde_hw_mixer(blk2->hw)->cap;
  195. /*
  196. * If lm2 is free, or
  197. * lm1 & lm2 reserved by same enc, check mask
  198. */
  199. if ((!blk2->rsvp || (blk->rsvp &&
  200. blk2->rsvp->enc_id == blk->rsvp->enc_id
  201. && lm_cfg->id > lm_cfg2->id)) &&
  202. test_bit(lm_cfg->id, &lm_cfg2->lm_pair_mask))
  203. avail_res->num_3dmux++;
  204. }
  205. }
  206. static void _sde_rm_dec_resource_info_lm(struct sde_rm *rm,
  207. struct msm_resource_caps_info *avail_res,
  208. struct sde_rm_hw_blk *blk)
  209. {
  210. struct sde_rm_hw_blk *blk2;
  211. const struct sde_lm_cfg *lm_cfg, *lm_cfg2;
  212. lm_cfg = to_sde_hw_mixer(blk->hw)->cap;
  213. /* Do not track & expose dummy mixers */
  214. if (lm_cfg->dummy_mixer)
  215. return;
  216. avail_res->num_lm--;
  217. /* Check for 3d muxes by comparing paired lms */
  218. list_for_each_entry(blk2, &rm->hw_blks[SDE_HW_BLK_LM], list) {
  219. lm_cfg2 = to_sde_hw_mixer(blk2->hw)->cap;
  220. /* If lm2 is free and lm1 is now being reserved */
  221. if (!blk2->rsvp &&
  222. test_bit(lm_cfg->id, &lm_cfg2->lm_pair_mask))
  223. avail_res->num_3dmux--;
  224. }
  225. }
  226. static void _sde_rm_inc_resource_info(struct sde_rm *rm,
  227. struct msm_resource_caps_info *avail_res,
  228. struct sde_rm_hw_blk *blk)
  229. {
  230. enum sde_hw_blk_type type = blk->type;
  231. if (type == SDE_HW_BLK_LM)
  232. _sde_rm_inc_resource_info_lm(rm, avail_res, blk);
  233. else if (type == SDE_HW_BLK_CTL)
  234. avail_res->num_ctl++;
  235. else if (type == SDE_HW_BLK_DSC)
  236. avail_res->num_dsc++;
  237. else if (type == SDE_HW_BLK_VDC)
  238. avail_res->num_vdc++;
  239. }
  240. static void _sde_rm_dec_resource_info(struct sde_rm *rm,
  241. struct msm_resource_caps_info *avail_res,
  242. struct sde_rm_hw_blk *blk)
  243. {
  244. enum sde_hw_blk_type type = blk->type;
  245. if (type == SDE_HW_BLK_LM)
  246. _sde_rm_dec_resource_info_lm(rm, avail_res, blk);
  247. else if (type == SDE_HW_BLK_CTL)
  248. avail_res->num_ctl--;
  249. else if (type == SDE_HW_BLK_DSC)
  250. avail_res->num_dsc--;
  251. else if (type == SDE_HW_BLK_VDC)
  252. avail_res->num_vdc--;
  253. }
  254. void sde_rm_get_resource_info(struct sde_rm *rm,
  255. struct drm_encoder *drm_enc,
  256. struct msm_resource_caps_info *avail_res)
  257. {
  258. struct sde_rm_hw_blk *blk;
  259. enum sde_hw_blk_type type;
  260. const struct sde_lm_cfg *lm_cfg;
  261. bool is_built_in, is_pref;
  262. u32 lm_pref = (BIT(SDE_DISP_PRIMARY_PREF) | BIT(SDE_DISP_SECONDARY_PREF));
  263. mutex_lock(&rm->rm_lock);
  264. /* Get all currently available resources */
  265. memcpy(avail_res, &rm->avail_res,
  266. sizeof(rm->avail_res));
  267. /**
  268. * When the encoder is null, assume display is external in order to return the count of
  269. * availalbe non-preferred LMs
  270. */
  271. if (!drm_enc)
  272. is_built_in = false;
  273. else
  274. is_built_in = sde_encoder_is_built_in_display(drm_enc);
  275. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  276. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  277. /* Add back resources allocated to the given encoder */
  278. if (blk->rsvp && drm_enc && blk->rsvp->enc_id == drm_enc->base.id) {
  279. _sde_rm_inc_resource_info(rm, avail_res, blk);
  280. if (type == SDE_HW_BLK_LM)
  281. avail_res->num_lm_in_use++;
  282. }
  283. /**
  284. * Remove unallocated preferred lms that cannot reserved
  285. * by non built-in displays.
  286. */
  287. if (type == SDE_HW_BLK_LM) {
  288. lm_cfg = to_sde_hw_mixer(blk->hw)->cap;
  289. is_pref = lm_cfg->features & lm_pref;
  290. if (!blk->rsvp && !blk->rsvp_nxt && !is_built_in && is_pref)
  291. _sde_rm_dec_resource_info(rm, avail_res, blk);
  292. }
  293. }
  294. }
  295. mutex_unlock(&rm->rm_lock);
  296. }
  297. static void _sde_rm_print_rsvps(
  298. struct sde_rm *rm,
  299. enum sde_rm_dbg_rsvp_stage stage)
  300. {
  301. struct sde_rm_rsvp *rsvp;
  302. struct sde_rm_hw_blk *blk;
  303. enum sde_hw_blk_type type;
  304. SDE_DEBUG("%d\n", stage);
  305. list_for_each_entry(rsvp, &rm->rsvps, list) {
  306. SDE_DEBUG("%d rsvp%s[s%ue%u] topology %d\n", stage, rsvp->pending ? "_nxt" : "",
  307. rsvp->seq, rsvp->enc_id, rsvp->topology);
  308. SDE_EVT32(stage, rsvp->seq, rsvp->enc_id, rsvp->topology, rsvp->pending);
  309. }
  310. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  311. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  312. if (!blk->rsvp && !blk->rsvp_nxt)
  313. continue;
  314. SDE_DEBUG("%d rsvp[s%ue%u->s%ue%u] %d %d\n", stage,
  315. (blk->rsvp) ? blk->rsvp->seq : 0,
  316. (blk->rsvp) ? blk->rsvp->enc_id : 0,
  317. (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
  318. (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
  319. blk->type, blk->id);
  320. SDE_EVT32(stage,
  321. (blk->rsvp) ? blk->rsvp->seq : 0,
  322. (blk->rsvp) ? blk->rsvp->enc_id : 0,
  323. (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
  324. (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
  325. blk->type, blk->id);
  326. }
  327. }
  328. }
  329. static void _sde_rm_print_rsvps_by_type(
  330. struct sde_rm *rm,
  331. enum sde_hw_blk_type type)
  332. {
  333. struct sde_rm_hw_blk *blk;
  334. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  335. if (!blk->rsvp && !blk->rsvp_nxt)
  336. continue;
  337. SDE_ERROR("rsvp[s%ue%u->s%ue%u] %d %d\n",
  338. (blk->rsvp) ? blk->rsvp->seq : 0,
  339. (blk->rsvp) ? blk->rsvp->enc_id : 0,
  340. (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
  341. (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
  342. blk->type, blk->id);
  343. SDE_EVT32((blk->rsvp) ? blk->rsvp->seq : 0,
  344. (blk->rsvp) ? blk->rsvp->enc_id : 0,
  345. (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
  346. (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
  347. blk->type, blk->id);
  348. }
  349. }
  350. struct sde_hw_mdp *sde_rm_get_mdp(struct sde_rm *rm)
  351. {
  352. return rm->hw_mdp;
  353. }
  354. void sde_rm_init_hw_iter(
  355. struct sde_rm_hw_iter *iter,
  356. uint32_t enc_id,
  357. enum sde_hw_blk_type type)
  358. {
  359. memset(iter, 0, sizeof(*iter));
  360. iter->enc_id = enc_id;
  361. iter->type = type;
  362. }
  363. enum sde_rm_topology_name sde_rm_get_topology_name(struct sde_rm *rm,
  364. struct msm_display_topology topology)
  365. {
  366. int i;
  367. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
  368. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
  369. topology))
  370. return rm->topology_tbl[i].top_name;
  371. return SDE_RM_TOPOLOGY_NONE;
  372. }
  373. static bool _sde_rm_get_hw_locked(struct sde_rm *rm, struct sde_rm_hw_iter *i)
  374. {
  375. struct list_head *blk_list;
  376. if (!rm || !i || i->type >= SDE_HW_BLK_MAX) {
  377. SDE_ERROR("invalid rm\n");
  378. return false;
  379. }
  380. i->hw = NULL;
  381. blk_list = &rm->hw_blks[i->type];
  382. if (i->blk && (&i->blk->list == blk_list)) {
  383. SDE_DEBUG("attempt resume iteration past last\n");
  384. return false;
  385. }
  386. i->blk = list_prepare_entry(i->blk, blk_list, list);
  387. list_for_each_entry_continue(i->blk, blk_list, list) {
  388. struct sde_rm_rsvp *rsvp = i->blk->rsvp;
  389. if (i->blk->type != i->type) {
  390. SDE_ERROR("found incorrect block type %d on %d list\n",
  391. i->blk->type, i->type);
  392. return false;
  393. }
  394. if ((i->enc_id == 0) || (rsvp && rsvp->enc_id == i->enc_id)) {
  395. i->hw = i->blk->hw;
  396. SDE_DEBUG("found type %d id %d for enc %d\n",
  397. i->type, i->blk->id, i->enc_id);
  398. return true;
  399. }
  400. }
  401. SDE_DEBUG("no match, type %d for enc %d\n", i->type, i->enc_id);
  402. return false;
  403. }
  404. static bool _sde_rm_request_hw_blk_locked(struct sde_rm *rm,
  405. struct sde_rm_hw_request *hw_blk_info)
  406. {
  407. struct list_head *blk_list;
  408. struct sde_rm_hw_blk *blk = NULL;
  409. if (!rm || !hw_blk_info || hw_blk_info->type >= SDE_HW_BLK_MAX) {
  410. SDE_ERROR("invalid rm\n");
  411. return false;
  412. }
  413. hw_blk_info->hw = NULL;
  414. blk_list = &rm->hw_blks[hw_blk_info->type];
  415. blk = list_prepare_entry(blk, blk_list, list);
  416. list_for_each_entry_continue(blk, blk_list, list) {
  417. if (blk->type != hw_blk_info->type) {
  418. SDE_ERROR("found incorrect block type %d on %d list\n",
  419. blk->type, hw_blk_info->type);
  420. return false;
  421. }
  422. if (blk->id == hw_blk_info->id) {
  423. hw_blk_info->hw = blk->hw;
  424. SDE_DEBUG("found type %d id %d\n",
  425. blk->type, blk->id);
  426. return true;
  427. }
  428. }
  429. SDE_DEBUG("no match, type %d id %d\n", hw_blk_info->type,
  430. hw_blk_info->id);
  431. return false;
  432. }
  433. bool sde_rm_get_hw(struct sde_rm *rm, struct sde_rm_hw_iter *i)
  434. {
  435. bool ret;
  436. mutex_lock(&rm->rm_lock);
  437. ret = _sde_rm_get_hw_locked(rm, i);
  438. mutex_unlock(&rm->rm_lock);
  439. return ret;
  440. }
  441. bool sde_rm_request_hw_blk(struct sde_rm *rm, struct sde_rm_hw_request *hw)
  442. {
  443. bool ret;
  444. mutex_lock(&rm->rm_lock);
  445. ret = _sde_rm_request_hw_blk_locked(rm, hw);
  446. mutex_unlock(&rm->rm_lock);
  447. return ret;
  448. }
  449. static void _sde_rm_hw_destroy(enum sde_hw_blk_type type, struct sde_hw_blk_reg_map *hw)
  450. {
  451. switch (type) {
  452. case SDE_HW_BLK_LM:
  453. sde_hw_lm_destroy(hw);
  454. break;
  455. case SDE_HW_BLK_DSPP:
  456. sde_hw_dspp_destroy(hw);
  457. break;
  458. case SDE_HW_BLK_DS:
  459. sde_hw_ds_destroy(hw);
  460. break;
  461. case SDE_HW_BLK_CTL:
  462. sde_hw_ctl_destroy(hw);
  463. break;
  464. case SDE_HW_BLK_CDM:
  465. sde_hw_cdm_destroy(hw);
  466. break;
  467. case SDE_HW_BLK_PINGPONG:
  468. sde_hw_pingpong_destroy(hw);
  469. break;
  470. case SDE_HW_BLK_INTF:
  471. sde_hw_intf_destroy(hw);
  472. break;
  473. case SDE_HW_BLK_WB:
  474. sde_hw_wb_destroy(hw);
  475. break;
  476. case SDE_HW_BLK_DSC:
  477. sde_hw_dsc_destroy(hw);
  478. break;
  479. case SDE_HW_BLK_VDC:
  480. sde_hw_vdc_destroy(hw);
  481. break;
  482. case SDE_HW_BLK_QDSS:
  483. sde_hw_qdss_destroy(hw);
  484. break;
  485. case SDE_HW_BLK_DNSC_BLUR:
  486. sde_hw_dnsc_blur_destroy(hw);
  487. break;
  488. case SDE_HW_BLK_SSPP:
  489. /* SSPPs are not managed by the resource manager */
  490. case SDE_HW_BLK_TOP:
  491. /* Top is a singleton, not managed in hw_blks list */
  492. case SDE_HW_BLK_MAX:
  493. default:
  494. SDE_ERROR("unsupported block type %d\n", type);
  495. break;
  496. }
  497. }
  498. static void _deinit_hw_fences(struct sde_rm *rm)
  499. {
  500. struct sde_rm_hw_iter iter;
  501. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
  502. while (_sde_rm_get_hw_locked(rm, &iter)) {
  503. struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
  504. sde_hw_fence_deinit(ctl);
  505. }
  506. }
  507. int sde_rm_destroy(struct sde_rm *rm)
  508. {
  509. struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
  510. struct sde_rm_hw_blk *hw_cur, *hw_nxt;
  511. enum sde_hw_blk_type type;
  512. if (!rm) {
  513. SDE_ERROR("invalid rm\n");
  514. return -EINVAL;
  515. }
  516. _deinit_hw_fences(rm);
  517. list_for_each_entry_safe(rsvp_cur, rsvp_nxt, &rm->rsvps, list) {
  518. list_del(&rsvp_cur->list);
  519. kfree(rsvp_cur);
  520. }
  521. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  522. list_for_each_entry_safe(hw_cur, hw_nxt, &rm->hw_blks[type],
  523. list) {
  524. list_del(&hw_cur->list);
  525. _sde_rm_hw_destroy(hw_cur->type, hw_cur->hw);
  526. kfree(hw_cur);
  527. }
  528. }
  529. sde_hw_mdp_destroy(rm->hw_mdp);
  530. rm->hw_mdp = NULL;
  531. mutex_destroy(&rm->rm_lock);
  532. return 0;
  533. }
  534. static int _sde_rm_hw_blk_create(
  535. struct sde_rm *rm,
  536. struct sde_mdss_cfg *cat,
  537. void __iomem *mmio,
  538. enum sde_hw_blk_type type,
  539. uint32_t id,
  540. void *hw_catalog_info)
  541. {
  542. int rc;
  543. struct sde_rm_hw_blk *blk;
  544. struct sde_hw_mdp *hw_mdp;
  545. struct sde_hw_blk_reg_map *hw;
  546. struct sde_kms *sde_kms = to_sde_kms(ddev_to_msm_kms(rm->dev));
  547. struct sde_vbif_clk_client clk_client = {0};
  548. hw_mdp = rm->hw_mdp;
  549. switch (type) {
  550. case SDE_HW_BLK_LM:
  551. hw = sde_hw_lm_init(id, mmio, cat);
  552. break;
  553. case SDE_HW_BLK_DSPP:
  554. hw = sde_hw_dspp_init(id, mmio, cat);
  555. break;
  556. case SDE_HW_BLK_DS:
  557. hw = sde_hw_ds_init(id, mmio, cat);
  558. break;
  559. case SDE_HW_BLK_CTL:
  560. hw = sde_hw_ctl_init(id, mmio, cat);
  561. break;
  562. case SDE_HW_BLK_CDM:
  563. hw = sde_hw_cdm_init(id, mmio, cat, hw_mdp);
  564. break;
  565. case SDE_HW_BLK_PINGPONG:
  566. hw = sde_hw_pingpong_init(id, mmio, cat);
  567. break;
  568. case SDE_HW_BLK_INTF:
  569. hw = sde_hw_intf_init(id, mmio, cat);
  570. break;
  571. case SDE_HW_BLK_WB:
  572. hw = sde_hw_wb_init(id, mmio, cat, hw_mdp, &clk_client);
  573. break;
  574. case SDE_HW_BLK_DSC:
  575. hw = sde_hw_dsc_init(id, mmio, cat);
  576. break;
  577. case SDE_HW_BLK_VDC:
  578. hw = sde_hw_vdc_init(id, mmio, cat);
  579. break;
  580. case SDE_HW_BLK_QDSS:
  581. hw = sde_hw_qdss_init(id, mmio, cat);
  582. break;
  583. case SDE_HW_BLK_DNSC_BLUR:
  584. hw = sde_hw_dnsc_blur_init(id, mmio, cat);
  585. break;
  586. case SDE_HW_BLK_SSPP:
  587. /* SSPPs are not managed by the resource manager */
  588. case SDE_HW_BLK_TOP:
  589. /* Top is a singleton, not managed in hw_blks list */
  590. case SDE_HW_BLK_MAX:
  591. default:
  592. SDE_ERROR("unsupported block type %d\n", type);
  593. return -EINVAL;
  594. }
  595. if (IS_ERR_OR_NULL(hw)) {
  596. SDE_ERROR("failed hw object creation: type %d, err %ld\n",
  597. type, PTR_ERR(hw));
  598. return -EFAULT;
  599. }
  600. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  601. if (!blk) {
  602. _sde_rm_hw_destroy(type, hw);
  603. return -ENOMEM;
  604. }
  605. blk->type = type;
  606. blk->id = id;
  607. blk->hw = hw;
  608. list_add_tail(&blk->list, &rm->hw_blks[type]);
  609. _sde_rm_inc_resource_info(rm, &rm->avail_res, blk);
  610. if (sde_kms && sde_kms->catalog &&
  611. test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, sde_kms->catalog->features) &&
  612. SDE_CLK_CTRL_VALID(clk_client.clk_ctrl)) {
  613. rc = sde_vbif_clk_register(sde_kms, &clk_client);
  614. if (rc) {
  615. SDE_ERROR("failed to register vbif client %d\n", clk_client.clk_ctrl);
  616. return -EFAULT;
  617. }
  618. }
  619. return 0;
  620. }
  621. static int _init_hw_fences(struct sde_rm *rm, bool use_ipcc)
  622. {
  623. struct sde_rm_hw_iter iter;
  624. int ret = 0;
  625. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
  626. while (_sde_rm_get_hw_locked(rm, &iter)) {
  627. struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
  628. if (sde_hw_fence_init(ctl, use_ipcc)) {
  629. pr_err("failed to init hw_fence idx:%d\n", ctl->idx);
  630. ret = -EINVAL;
  631. break;
  632. }
  633. SDE_DEBUG("init hw-fence for ctl %d", iter.blk->id);
  634. }
  635. if (ret)
  636. _deinit_hw_fences(rm);
  637. return ret;
  638. }
  639. static int _sde_rm_hw_blk_create_new(struct sde_rm *rm,
  640. struct sde_mdss_cfg *cat,
  641. void __iomem *mmio)
  642. {
  643. int i, rc = 0;
  644. for (i = 0; i < cat->dspp_count; i++) {
  645. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSPP,
  646. cat->dspp[i].id, &cat->dspp[i]);
  647. if (rc) {
  648. SDE_ERROR("failed: dspp hw not available\n");
  649. goto fail;
  650. }
  651. }
  652. if (cat->mdp[0].has_dest_scaler) {
  653. for (i = 0; i < cat->ds_count; i++) {
  654. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DS,
  655. cat->ds[i].id, &cat->ds[i]);
  656. if (rc) {
  657. SDE_ERROR("failed: ds hw not available\n");
  658. goto fail;
  659. }
  660. }
  661. }
  662. for (i = 0; i < cat->pingpong_count; i++) {
  663. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_PINGPONG,
  664. cat->pingpong[i].id, &cat->pingpong[i]);
  665. if (rc) {
  666. SDE_ERROR("failed: pp hw not available\n");
  667. goto fail;
  668. }
  669. }
  670. for (i = 0; i < cat->dsc_count; i++) {
  671. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSC,
  672. cat->dsc[i].id, &cat->dsc[i]);
  673. if (rc) {
  674. SDE_ERROR("failed: dsc hw not available\n");
  675. goto fail;
  676. }
  677. }
  678. for (i = 0; i < cat->vdc_count; i++) {
  679. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_VDC,
  680. cat->vdc[i].id, &cat->vdc[i]);
  681. if (rc) {
  682. SDE_ERROR("failed: vdc hw not available\n");
  683. goto fail;
  684. }
  685. }
  686. for (i = 0; i < cat->intf_count; i++) {
  687. if (cat->intf[i].type == INTF_NONE) {
  688. SDE_DEBUG("skip intf %d with type none\n", i);
  689. continue;
  690. }
  691. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_INTF,
  692. cat->intf[i].id, &cat->intf[i]);
  693. if (rc) {
  694. SDE_ERROR("failed: intf hw not available\n");
  695. goto fail;
  696. }
  697. }
  698. for (i = 0; i < cat->wb_count; i++) {
  699. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_WB,
  700. cat->wb[i].id, &cat->wb[i]);
  701. if (rc) {
  702. SDE_ERROR("failed: wb hw not available\n");
  703. goto fail;
  704. }
  705. }
  706. for (i = 0; i < cat->ctl_count; i++) {
  707. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CTL,
  708. cat->ctl[i].id, &cat->ctl[i]);
  709. if (rc) {
  710. SDE_ERROR("failed: ctl hw not available\n");
  711. goto fail;
  712. }
  713. }
  714. if (cat->hw_fence_rev) {
  715. if (_init_hw_fences(rm, test_bit(SDE_FEATURE_HW_FENCE_IPCC, cat->features))) {
  716. SDE_INFO("failed to init hw-fences, disabling hw-fences\n");
  717. cat->hw_fence_rev = 0;
  718. }
  719. }
  720. for (i = 0; i < cat->cdm_count; i++) {
  721. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CDM,
  722. cat->cdm[i].id, &cat->cdm[i]);
  723. if (rc) {
  724. SDE_ERROR("failed: cdm hw not available\n");
  725. goto fail;
  726. }
  727. }
  728. for (i = 0; i < cat->dnsc_blur_count; i++) {
  729. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DNSC_BLUR,
  730. cat->dnsc_blur[i].id, &cat->dnsc_blur[i]);
  731. if (rc) {
  732. SDE_ERROR("failed: dnsc_blur hw not available\n");
  733. goto fail;
  734. }
  735. }
  736. for (i = 0; i < cat->qdss_count; i++) {
  737. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_QDSS,
  738. cat->qdss[i].id, &cat->qdss[i]);
  739. if (rc) {
  740. SDE_ERROR("failed: qdss hw not available\n");
  741. goto fail;
  742. }
  743. }
  744. fail:
  745. return rc;
  746. }
  747. #if IS_ENABLED(CONFIG_DEBUG_FS)
  748. static int _sde_rm_status_show(struct seq_file *s, void *data)
  749. {
  750. struct sde_rm *rm;
  751. struct sde_rm_hw_blk *blk;
  752. u32 type, allocated, unallocated;
  753. if (!s || !s->private)
  754. return -EINVAL;
  755. rm = s->private;
  756. for (type = SDE_HW_BLK_LM; type < SDE_HW_BLK_MAX; type++) {
  757. allocated = 0;
  758. unallocated = 0;
  759. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  760. if (!blk->rsvp && !blk->rsvp_nxt)
  761. unallocated++;
  762. else
  763. allocated++;
  764. }
  765. seq_printf(s, "type:%d blk:%s allocated:%d unallocated:%d\n",
  766. type, sde_hw_blk_str[type], allocated, unallocated);
  767. }
  768. return 0;
  769. }
  770. static int _sde_rm_debugfs_status_open(struct inode *inode,
  771. struct file *file)
  772. {
  773. return single_open(file, _sde_rm_status_show, inode->i_private);
  774. }
  775. void sde_rm_debugfs_init(struct sde_rm *sde_rm, struct dentry *parent)
  776. {
  777. static const struct file_operations debugfs_rm_status_fops = {
  778. .open = _sde_rm_debugfs_status_open,
  779. .read = seq_read,
  780. };
  781. debugfs_create_file("rm_status", 0400, parent, sde_rm, &debugfs_rm_status_fops);
  782. }
  783. #else
  784. void sde_rm_debugfs_init(struct sde_rm *rm, struct dentry *parent)
  785. {
  786. }
  787. #endif /* CONFIG_DEBUG_FS */
  788. int sde_rm_init(struct sde_rm *rm,
  789. struct sde_mdss_cfg *cat,
  790. void __iomem *mmio,
  791. struct drm_device *dev)
  792. {
  793. int i, rc = 0;
  794. enum sde_hw_blk_type type;
  795. if (!rm || !cat || !mmio || !dev) {
  796. SDE_ERROR("invalid input params\n");
  797. return -EINVAL;
  798. }
  799. /* Clear, setup lists */
  800. memset(rm, 0, sizeof(*rm));
  801. mutex_init(&rm->rm_lock);
  802. INIT_LIST_HEAD(&rm->rsvps);
  803. for (type = 0; type < SDE_HW_BLK_MAX; type++)
  804. INIT_LIST_HEAD(&rm->hw_blks[type]);
  805. rm->dev = dev;
  806. if (IS_SDE_CTL_REV_100(cat->ctl_rev))
  807. rm->topology_tbl = g_top_table_v1;
  808. else
  809. rm->topology_tbl = g_top_table;
  810. /* Some of the sub-blocks require an mdptop to be created */
  811. rm->hw_mdp = sde_hw_mdptop_init(MDP_TOP, mmio, cat);
  812. if (IS_ERR_OR_NULL(rm->hw_mdp)) {
  813. rc = PTR_ERR(rm->hw_mdp);
  814. rm->hw_mdp = NULL;
  815. SDE_ERROR("failed: mdp hw not available\n");
  816. goto fail;
  817. }
  818. /* Interrogate HW catalog and create tracking items for hw blocks */
  819. for (i = 0; i < cat->mixer_count; i++) {
  820. struct sde_lm_cfg *lm = &cat->mixer[i];
  821. if (lm->pingpong == PINGPONG_MAX) {
  822. SDE_ERROR("mixer %d without pingpong\n", lm->id);
  823. goto fail;
  824. }
  825. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_LM,
  826. cat->mixer[i].id, &cat->mixer[i]);
  827. if (rc) {
  828. SDE_ERROR("failed: lm hw not available\n");
  829. goto fail;
  830. }
  831. if (!rm->lm_max_width) {
  832. rm->lm_max_width = lm->sblk->maxwidth;
  833. } else if (rm->lm_max_width != lm->sblk->maxwidth) {
  834. /*
  835. * Don't expect to have hw where lm max widths differ.
  836. * If found, take the min.
  837. */
  838. SDE_ERROR("unsupported: lm maxwidth differs\n");
  839. if (rm->lm_max_width > lm->sblk->maxwidth)
  840. rm->lm_max_width = lm->sblk->maxwidth;
  841. }
  842. }
  843. rc = _sde_rm_hw_blk_create_new(rm, cat, mmio);
  844. if (!rc)
  845. return 0;
  846. fail:
  847. sde_rm_destroy(rm);
  848. return rc;
  849. }
  850. static bool _sde_rm_check_lm(
  851. struct sde_rm *rm,
  852. struct sde_rm_rsvp *rsvp,
  853. struct sde_rm_requirements *reqs,
  854. const struct sde_lm_cfg *lm_cfg,
  855. struct sde_rm_hw_blk *lm,
  856. struct sde_rm_hw_blk **dspp,
  857. struct sde_rm_hw_blk **ds,
  858. struct sde_rm_hw_blk **pp)
  859. {
  860. bool is_valid_dspp, is_valid_ds, ret = true;
  861. is_valid_dspp = (lm_cfg->dspp != DSPP_MAX) ? true : false;
  862. is_valid_ds = (lm_cfg->ds != DS_MAX) ? true : false;
  863. /**
  864. * RM_RQ_X: specification of which LMs to choose
  865. * is_valid_X: indicates whether LM is tied with block X
  866. * ret: true if given LM matches the user requirement,
  867. * false otherwise
  868. */
  869. if (RM_RQ_DSPP(reqs) && RM_RQ_DS(reqs))
  870. ret = (is_valid_dspp && is_valid_ds);
  871. else if (RM_RQ_DSPP(reqs))
  872. ret = is_valid_dspp;
  873. else if (RM_RQ_DS(reqs))
  874. ret = is_valid_ds;
  875. if (!ret) {
  876. SDE_DEBUG(
  877. "fail:lm(%d)req_dspp(%d)dspp(%d)req_ds(%d)ds(%d)\n",
  878. lm_cfg->id, (bool)(RM_RQ_DSPP(reqs)),
  879. lm_cfg->dspp, (bool)(RM_RQ_DS(reqs)),
  880. lm_cfg->ds);
  881. return ret;
  882. }
  883. return true;
  884. }
  885. static bool _sde_rm_reserve_dspp(
  886. struct sde_rm *rm,
  887. struct sde_rm_rsvp *rsvp,
  888. const struct sde_lm_cfg *lm_cfg,
  889. struct sde_rm_hw_blk *lm,
  890. struct sde_rm_hw_blk **dspp)
  891. {
  892. struct sde_rm_hw_iter iter;
  893. if (lm_cfg->dspp != DSPP_MAX) {
  894. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DSPP);
  895. while (_sde_rm_get_hw_locked(rm, &iter)) {
  896. if (iter.blk->id == lm_cfg->dspp) {
  897. *dspp = iter.blk;
  898. break;
  899. }
  900. }
  901. if (!*dspp) {
  902. SDE_DEBUG("lm %d failed to retrieve dspp %d\n", lm->id,
  903. lm_cfg->dspp);
  904. return false;
  905. }
  906. if (RESERVED_BY_OTHER(*dspp, rsvp)) {
  907. SDE_DEBUG("lm %d dspp %d already reserved\n",
  908. lm->id, (*dspp)->id);
  909. return false;
  910. }
  911. }
  912. return true;
  913. }
  914. static bool _sde_rm_reserve_ds(
  915. struct sde_rm *rm,
  916. struct sde_rm_rsvp *rsvp,
  917. const struct sde_lm_cfg *lm_cfg,
  918. struct sde_rm_hw_blk *lm,
  919. struct sde_rm_hw_blk **ds)
  920. {
  921. struct sde_rm_hw_iter iter;
  922. if (lm_cfg->ds != DS_MAX) {
  923. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DS);
  924. while (_sde_rm_get_hw_locked(rm, &iter)) {
  925. if (iter.blk->id == lm_cfg->ds) {
  926. *ds = iter.blk;
  927. break;
  928. }
  929. }
  930. if (!*ds) {
  931. SDE_DEBUG("lm %d failed to retrieve ds %d\n", lm->id,
  932. lm_cfg->ds);
  933. return false;
  934. }
  935. if (RESERVED_BY_OTHER(*ds, rsvp)) {
  936. SDE_DEBUG("lm %d ds %d already reserved\n",
  937. lm->id, (*ds)->id);
  938. return false;
  939. }
  940. }
  941. return true;
  942. }
  943. static bool _sde_rm_reserve_pp(
  944. struct sde_rm *rm,
  945. struct sde_rm_rsvp *rsvp,
  946. struct sde_rm_requirements *reqs,
  947. const struct sde_lm_cfg *lm_cfg,
  948. const struct sde_pingpong_cfg *pp_cfg,
  949. struct sde_rm_hw_blk *lm,
  950. struct sde_rm_hw_blk **dspp,
  951. struct sde_rm_hw_blk **ds,
  952. struct sde_rm_hw_blk **pp)
  953. {
  954. struct sde_rm_hw_iter iter;
  955. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_PINGPONG);
  956. while (_sde_rm_get_hw_locked(rm, &iter)) {
  957. if (iter.blk->id == lm_cfg->pingpong) {
  958. *pp = iter.blk;
  959. break;
  960. }
  961. }
  962. if (!*pp) {
  963. SDE_ERROR("failed to get pp on lm %d\n", lm_cfg->pingpong);
  964. return false;
  965. }
  966. if (RESERVED_BY_OTHER(*pp, rsvp)) {
  967. SDE_DEBUG("lm %d pp %d already reserved\n", lm->id,
  968. (*pp)->id);
  969. *dspp = NULL;
  970. *ds = NULL;
  971. return false;
  972. }
  973. pp_cfg = to_sde_hw_pingpong((*pp)->hw)->caps;
  974. if ((reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) &&
  975. !(test_bit(SDE_PINGPONG_SPLIT, &pp_cfg->features))) {
  976. SDE_DEBUG("pp %d doesn't support ppsplit\n", pp_cfg->id);
  977. *dspp = NULL;
  978. *ds = NULL;
  979. return false;
  980. }
  981. return true;
  982. }
  983. /**
  984. * _sde_rm_check_lm_and_get_connected_blks - check if proposed layer mixer meets
  985. * proposed use case requirements, incl. hardwired dependent blocks like
  986. * pingpong, and dspp.
  987. * @rm: sde resource manager handle
  988. * @rsvp: reservation currently being created
  989. * @reqs: proposed use case requirements
  990. * @lm: proposed layer mixer, function checks if lm, and all other hardwired
  991. * blocks connected to the lm (pp, dspp) are available and appropriate
  992. * @dspp: output parameter, dspp block attached to the layer mixer.
  993. * NULL if dspp was not available, or not matching requirements.
  994. * @pp: output parameter, pingpong block attached to the layer mixer.
  995. * NULL if dspp was not available, or not matching requirements.
  996. * @primary_lm: if non-null, this function check if lm is compatible primary_lm
  997. * as well as satisfying all other requirements
  998. * @Return: true if lm matches all requirements, false otherwise
  999. */
  1000. static bool _sde_rm_check_lm_and_get_connected_blks(
  1001. struct sde_rm *rm,
  1002. struct sde_rm_rsvp *rsvp,
  1003. struct sde_rm_requirements *reqs,
  1004. struct sde_rm_hw_blk *lm,
  1005. struct sde_rm_hw_blk **dspp,
  1006. struct sde_rm_hw_blk **ds,
  1007. struct sde_rm_hw_blk **pp,
  1008. struct sde_rm_hw_blk *primary_lm)
  1009. {
  1010. const struct sde_lm_cfg *lm_cfg = to_sde_hw_mixer(lm->hw)->cap;
  1011. const struct sde_pingpong_cfg *pp_cfg;
  1012. bool ret, is_conn_primary, is_conn_secondary;
  1013. u32 lm_primary_pref, lm_secondary_pref, cwb_pref, dcwb_pref;
  1014. *dspp = NULL;
  1015. *ds = NULL;
  1016. *pp = NULL;
  1017. lm_primary_pref = lm_cfg->features & BIT(SDE_DISP_PRIMARY_PREF);
  1018. lm_secondary_pref = lm_cfg->features & BIT(SDE_DISP_SECONDARY_PREF);
  1019. cwb_pref = lm_cfg->features & BIT(SDE_DISP_CWB_PREF);
  1020. dcwb_pref = lm_cfg->features & BIT(SDE_DISP_DCWB_PREF);
  1021. is_conn_primary = (reqs->hw_res.display_type ==
  1022. SDE_CONNECTOR_PRIMARY) ? true : false;
  1023. is_conn_secondary = (reqs->hw_res.display_type ==
  1024. SDE_CONNECTOR_SECONDARY) ? true : false;
  1025. SDE_DEBUG("check lm %d: dspp %d ds %d pp %d features %ld disp type %d\n",
  1026. lm_cfg->id, lm_cfg->dspp, lm_cfg->ds, lm_cfg->pingpong,
  1027. lm_cfg->features, (int)reqs->hw_res.display_type);
  1028. /* Check if this layer mixer is a peer of the proposed primary LM */
  1029. if (primary_lm) {
  1030. const struct sde_lm_cfg *prim_lm_cfg =
  1031. to_sde_hw_mixer(primary_lm->hw)->cap;
  1032. if (!test_bit(lm_cfg->id, &prim_lm_cfg->lm_pair_mask)) {
  1033. SDE_DEBUG("lm %d not peer of lm %d\n", lm_cfg->id,
  1034. prim_lm_cfg->id);
  1035. return false;
  1036. }
  1037. }
  1038. /* bypass rest of the checks if LM for primary display is found */
  1039. if (!lm_primary_pref && !lm_secondary_pref) {
  1040. /* Check lm for valid requirements */
  1041. ret = _sde_rm_check_lm(rm, rsvp, reqs, lm_cfg, lm,
  1042. dspp, ds, pp);
  1043. if (!ret)
  1044. return ret;
  1045. /**
  1046. * If CWB is enabled and LM is not CWB supported
  1047. * then return false.
  1048. */
  1049. if ((RM_RQ_CWB(reqs) && !cwb_pref) ||
  1050. (RM_RQ_DCWB(reqs) && !dcwb_pref)) {
  1051. SDE_DEBUG("fail: cwb/dcwb supported lm not allocated\n");
  1052. return false;
  1053. } else if (!RM_RQ_DCWB(reqs) && dcwb_pref) {
  1054. SDE_DEBUG("fail: dcwb supported dummy lm incorrectly allocated\n");
  1055. return false;
  1056. }
  1057. } else if ((!is_conn_primary && lm_primary_pref) ||
  1058. (!is_conn_secondary && lm_secondary_pref)) {
  1059. SDE_DEBUG(
  1060. "display preference is not met. display_type: %d lm_features: %lx\n",
  1061. (int)reqs->hw_res.display_type, lm_cfg->features);
  1062. return false;
  1063. }
  1064. /* Already reserved? */
  1065. if (RESERVED_BY_OTHER(lm, rsvp)) {
  1066. SDE_DEBUG("lm %d already reserved\n", lm_cfg->id);
  1067. return false;
  1068. }
  1069. /* Reserve dspp */
  1070. ret = _sde_rm_reserve_dspp(rm, rsvp, lm_cfg, lm, dspp);
  1071. if (!ret)
  1072. return ret;
  1073. /* Reserve ds */
  1074. ret = _sde_rm_reserve_ds(rm, rsvp, lm_cfg, lm, ds);
  1075. if (!ret)
  1076. return ret;
  1077. /* Reserve pp */
  1078. ret = _sde_rm_reserve_pp(rm, rsvp, reqs, lm_cfg, pp_cfg, lm,
  1079. dspp, ds, pp);
  1080. if (!ret)
  1081. return ret;
  1082. return true;
  1083. }
  1084. static int _sde_rm_reserve_lms(
  1085. struct sde_rm *rm,
  1086. struct sde_rm_rsvp *rsvp,
  1087. struct sde_rm_requirements *reqs,
  1088. u8 *_lm_ids)
  1089. {
  1090. struct sde_rm_hw_blk *lm[MAX_BLOCKS];
  1091. struct sde_rm_hw_blk *dspp[MAX_BLOCKS];
  1092. struct sde_rm_hw_blk *ds[MAX_BLOCKS];
  1093. struct sde_rm_hw_blk *pp[MAX_BLOCKS];
  1094. struct sde_rm_hw_iter iter_i, iter_j;
  1095. u32 lm_mask = 0;
  1096. int lm_count = 0;
  1097. int i, rc = 0;
  1098. if (!reqs->topology->num_lm) {
  1099. SDE_DEBUG("invalid number of lm: %d\n", reqs->topology->num_lm);
  1100. return 0;
  1101. }
  1102. /* Find a primary mixer */
  1103. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_LM);
  1104. while (lm_count != reqs->topology->num_lm &&
  1105. _sde_rm_get_hw_locked(rm, &iter_i)) {
  1106. if (lm_mask & (1 << iter_i.blk->id))
  1107. continue;
  1108. lm[lm_count] = iter_i.blk;
  1109. dspp[lm_count] = NULL;
  1110. ds[lm_count] = NULL;
  1111. pp[lm_count] = NULL;
  1112. SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n",
  1113. iter_i.blk->id,
  1114. lm_count,
  1115. _lm_ids ? _lm_ids[lm_count] : -1);
  1116. if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count])
  1117. continue;
  1118. if (!_sde_rm_check_lm_and_get_connected_blks(
  1119. rm, rsvp, reqs, lm[lm_count],
  1120. &dspp[lm_count], &ds[lm_count],
  1121. &pp[lm_count], NULL))
  1122. continue;
  1123. lm_mask |= (1 << iter_i.blk->id);
  1124. ++lm_count;
  1125. /* Return if peer is not needed */
  1126. if (lm_count == reqs->topology->num_lm)
  1127. break;
  1128. /* Valid primary mixer found, find matching peers */
  1129. sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_LM);
  1130. while (_sde_rm_get_hw_locked(rm, &iter_j)) {
  1131. if (lm_mask & (1 << iter_j.blk->id))
  1132. continue;
  1133. lm[lm_count] = iter_j.blk;
  1134. dspp[lm_count] = NULL;
  1135. ds[lm_count] = NULL;
  1136. pp[lm_count] = NULL;
  1137. if (!_sde_rm_check_lm_and_get_connected_blks(
  1138. rm, rsvp, reqs, iter_j.blk,
  1139. &dspp[lm_count], &ds[lm_count],
  1140. &pp[lm_count], iter_i.blk))
  1141. continue;
  1142. SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n",
  1143. iter_j.blk->id,
  1144. lm_count,
  1145. _lm_ids ? _lm_ids[lm_count] : -1);
  1146. if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count])
  1147. continue;
  1148. lm_mask |= (1 << iter_j.blk->id);
  1149. ++lm_count;
  1150. break;
  1151. }
  1152. /* Rollback primary LM if peer is not found */
  1153. if (!iter_j.hw) {
  1154. lm_mask &= ~(1 << iter_i.blk->id);
  1155. --lm_count;
  1156. }
  1157. }
  1158. if (lm_count != reqs->topology->num_lm) {
  1159. SDE_DEBUG("unable to find appropriate mixers\n");
  1160. return -ENAVAIL;
  1161. }
  1162. for (i = 0; i < lm_count; i++) {
  1163. lm[i]->rsvp_nxt = rsvp;
  1164. pp[i]->rsvp_nxt = rsvp;
  1165. if (dspp[i])
  1166. dspp[i]->rsvp_nxt = rsvp;
  1167. if (ds[i])
  1168. ds[i]->rsvp_nxt = rsvp;
  1169. SDE_EVT32(lm[i]->type, rsvp->enc_id, lm[i]->id, pp[i]->id,
  1170. dspp[i] ? dspp[i]->id : 0,
  1171. ds[i] ? ds[i]->id : 0);
  1172. }
  1173. if (reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) {
  1174. /* reserve a free PINGPONG_SLAVE block */
  1175. rc = -ENAVAIL;
  1176. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_PINGPONG);
  1177. while (_sde_rm_get_hw_locked(rm, &iter_i)) {
  1178. const struct sde_hw_pingpong *pp =
  1179. to_sde_hw_pingpong(iter_i.blk->hw);
  1180. const struct sde_pingpong_cfg *pp_cfg = pp->caps;
  1181. if (!(test_bit(SDE_PINGPONG_SLAVE, &pp_cfg->features)))
  1182. continue;
  1183. if (RESERVED_BY_OTHER(iter_i.blk, rsvp))
  1184. continue;
  1185. iter_i.blk->rsvp_nxt = rsvp;
  1186. rc = 0;
  1187. break;
  1188. }
  1189. }
  1190. return rc;
  1191. }
  1192. static int _sde_rm_reserve_ctls(
  1193. struct sde_rm *rm,
  1194. struct sde_rm_rsvp *rsvp,
  1195. struct sde_rm_requirements *reqs,
  1196. const struct sde_rm_topology_def *top,
  1197. u8 *_ctl_ids)
  1198. {
  1199. struct sde_rm_hw_blk *ctls[MAX_BLOCKS];
  1200. struct sde_rm_hw_iter iter, curr;
  1201. int i = 0;
  1202. if (!top->num_ctl) {
  1203. SDE_DEBUG("invalid number of ctl: %d\n", top->num_ctl);
  1204. return 0;
  1205. }
  1206. memset(&ctls, 0, sizeof(ctls));
  1207. sde_rm_init_hw_iter(&curr, rsvp->enc_id, SDE_HW_BLK_CTL);
  1208. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
  1209. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1210. const struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
  1211. unsigned long features = ctl->caps->features;
  1212. bool has_split_display, has_ppsplit, primary_pref;
  1213. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1214. continue;
  1215. has_split_display = BIT(SDE_CTL_SPLIT_DISPLAY) & features;
  1216. has_ppsplit = BIT(SDE_CTL_PINGPONG_SPLIT) & features;
  1217. primary_pref = BIT(SDE_CTL_PRIMARY_PREF) & features;
  1218. SDE_DEBUG("ctl %d caps 0x%lX\n", iter.blk->id, features);
  1219. /*
  1220. * bypass rest feature checks on finding CTL preferred
  1221. * for primary displays.
  1222. */
  1223. if (!primary_pref && !_ctl_ids) {
  1224. if (top->needs_split_display != has_split_display)
  1225. continue;
  1226. if (top->top_name == SDE_RM_TOPOLOGY_PPSPLIT &&
  1227. !has_ppsplit)
  1228. continue;
  1229. } else if (!(reqs->hw_res.display_type ==
  1230. SDE_CONNECTOR_PRIMARY && primary_pref) && !_ctl_ids) {
  1231. SDE_DEBUG(
  1232. "display pref not met. display_type: %d primary_pref: %d\n",
  1233. reqs->hw_res.display_type, primary_pref);
  1234. continue;
  1235. }
  1236. if (_sde_rm_get_hw_locked(rm, &curr) && (curr.blk->id != iter.blk->id)) {
  1237. SDE_EVT32(curr.blk->id, iter.blk->id, SDE_EVTLOG_FUNC_CASE1);
  1238. SDE_DEBUG("ctl in use:%d avoiding new:%d\n", curr.blk->id, iter.blk->id);
  1239. continue;
  1240. }
  1241. ctls[i] = iter.blk;
  1242. SDE_DEBUG("blk id = %d, _ctl_ids[%d] = %d\n",
  1243. iter.blk->id, i,
  1244. _ctl_ids ? _ctl_ids[i] : -1);
  1245. if (_ctl_ids && (ctls[i]->id != _ctl_ids[i]))
  1246. continue;
  1247. SDE_DEBUG("ctl %d match\n", iter.blk->id);
  1248. if (++i == top->num_ctl)
  1249. break;
  1250. }
  1251. if (i != top->num_ctl)
  1252. return -ENAVAIL;
  1253. for (i = 0; i < ARRAY_SIZE(ctls) && i < top->num_ctl; i++) {
  1254. ctls[i]->rsvp_nxt = rsvp;
  1255. SDE_EVT32(ctls[i]->type, rsvp->enc_id, ctls[i]->id);
  1256. }
  1257. return 0;
  1258. }
  1259. static bool _sde_rm_check_dsc(struct sde_rm *rm,
  1260. struct sde_rm_rsvp *rsvp,
  1261. struct sde_rm_hw_blk *dsc,
  1262. struct sde_rm_hw_blk *paired_dsc,
  1263. struct sde_rm_hw_blk *pp_blk)
  1264. {
  1265. const struct sde_dsc_cfg *dsc_cfg = to_sde_hw_dsc(dsc->hw)->caps;
  1266. /* Already reserved? */
  1267. if (RESERVED_BY_OTHER(dsc, rsvp)) {
  1268. SDE_DEBUG("dsc %d already reserved\n", dsc_cfg->id);
  1269. return false;
  1270. }
  1271. /**
  1272. * This check is required for routing even numbered DSC
  1273. * blks to any of the even numbered PP blks and odd numbered
  1274. * DSC blks to any of the odd numbered PP blks.
  1275. */
  1276. if (!pp_blk || !IS_COMPATIBLE_PP_DSC(pp_blk->id, dsc->id))
  1277. return false;
  1278. /* Check if this dsc is a peer of the proposed paired DSC */
  1279. if (paired_dsc) {
  1280. const struct sde_dsc_cfg *paired_dsc_cfg =
  1281. to_sde_hw_dsc(paired_dsc->hw)->caps;
  1282. if (!test_bit(dsc_cfg->id, paired_dsc_cfg->dsc_pair_mask)) {
  1283. SDE_DEBUG("dsc %d not peer of dsc %d\n", dsc_cfg->id,
  1284. paired_dsc_cfg->id);
  1285. return false;
  1286. }
  1287. }
  1288. return true;
  1289. }
  1290. static bool _sde_rm_check_vdc(struct sde_rm *rm,
  1291. struct sde_rm_rsvp *rsvp,
  1292. struct sde_rm_hw_blk *vdc)
  1293. {
  1294. const struct sde_vdc_cfg *vdc_cfg = to_sde_hw_vdc(vdc->hw)->caps;
  1295. /* Already reserved? */
  1296. if (RESERVED_BY_OTHER(vdc, rsvp)) {
  1297. SDE_DEBUG("vdc %d already reserved\n", vdc_cfg->id);
  1298. return false;
  1299. }
  1300. return true;
  1301. }
  1302. static void sde_rm_get_rsvp_nxt_hw_blks(
  1303. struct sde_rm *rm,
  1304. struct sde_rm_rsvp *rsvp,
  1305. int type,
  1306. struct sde_rm_hw_blk **blk_arr)
  1307. {
  1308. struct sde_rm_hw_blk *blk;
  1309. int i = 0;
  1310. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  1311. if (blk->rsvp_nxt && blk->rsvp_nxt->seq ==
  1312. rsvp->seq)
  1313. blk_arr[i++] = blk;
  1314. }
  1315. }
  1316. static int _sde_rm_reserve_dsc(
  1317. struct sde_rm *rm,
  1318. struct sde_rm_rsvp *rsvp,
  1319. struct sde_rm_requirements *reqs,
  1320. u8 *_dsc_ids)
  1321. {
  1322. struct sde_rm_hw_iter iter_i, iter_j;
  1323. struct sde_rm_hw_blk *dsc[MAX_BLOCKS];
  1324. u32 reserve_mask = 0;
  1325. struct sde_rm_hw_blk *pp[MAX_BLOCKS];
  1326. int alloc_count = 0;
  1327. int num_dsc_enc;
  1328. struct msm_display_dsc_info *dsc_info;
  1329. int i;
  1330. if (reqs->hw_res.comp_info->comp_type != MSM_DISPLAY_COMPRESSION_DSC) {
  1331. SDE_DEBUG("compression blk dsc not required\n");
  1332. return 0;
  1333. }
  1334. num_dsc_enc = reqs->topology->num_comp_enc;
  1335. dsc_info = &reqs->hw_res.comp_info->dsc_info;
  1336. if ((!num_dsc_enc) || !dsc_info) {
  1337. SDE_DEBUG("invalid topoplogy params: %d, %d\n",
  1338. num_dsc_enc, !(dsc_info == NULL));
  1339. return 0;
  1340. }
  1341. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_DSC);
  1342. sde_rm_get_rsvp_nxt_hw_blks(rm, rsvp, SDE_HW_BLK_PINGPONG, pp);
  1343. /* Find a first DSC */
  1344. while (alloc_count != num_dsc_enc &&
  1345. _sde_rm_get_hw_locked(rm, &iter_i)) {
  1346. const struct sde_hw_dsc *hw_dsc = to_sde_hw_dsc(
  1347. iter_i.blk->hw);
  1348. unsigned long features = hw_dsc->caps->features;
  1349. bool has_422_420_support =
  1350. BIT(SDE_DSC_NATIVE_422_EN) & features;
  1351. if (reserve_mask & (1 << iter_i.blk->id))
  1352. continue;
  1353. if (_dsc_ids && (iter_i.blk->id != _dsc_ids[alloc_count]))
  1354. continue;
  1355. /* if this hw block does not support required feature */
  1356. if (!_dsc_ids && (dsc_info->config.native_422 ||
  1357. dsc_info->config.native_420) && !has_422_420_support)
  1358. continue;
  1359. if (!_sde_rm_check_dsc(rm, rsvp, iter_i.blk, NULL,
  1360. pp[alloc_count]))
  1361. continue;
  1362. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  1363. iter_i.blk->id,
  1364. alloc_count,
  1365. _dsc_ids ? _dsc_ids[alloc_count] : -1);
  1366. reserve_mask |= (1 << iter_i.blk->id);
  1367. dsc[alloc_count++] = iter_i.blk;
  1368. /* Return if peer is not needed */
  1369. if (alloc_count == num_dsc_enc)
  1370. break;
  1371. /* Valid first dsc found, find matching peers */
  1372. sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_DSC);
  1373. while (_sde_rm_get_hw_locked(rm, &iter_j)) {
  1374. if (reserve_mask & (1 << iter_j.blk->id))
  1375. continue;
  1376. if (_dsc_ids && (iter_j.blk->id !=
  1377. _dsc_ids[alloc_count]))
  1378. continue;
  1379. if (!_sde_rm_check_dsc(rm, rsvp, iter_j.blk,
  1380. iter_i.blk, pp[alloc_count]))
  1381. continue;
  1382. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  1383. iter_j.blk->id,
  1384. alloc_count,
  1385. _dsc_ids ? _dsc_ids[alloc_count] : -1);
  1386. reserve_mask |= (1 << iter_j.blk->id);
  1387. dsc[alloc_count++] = iter_j.blk;
  1388. break;
  1389. }
  1390. /* Rollback primary DSC if peer is not found */
  1391. if (!iter_j.hw) {
  1392. reserve_mask &= ~(1 << iter_i.blk->id);
  1393. --alloc_count;
  1394. }
  1395. }
  1396. if (alloc_count != num_dsc_enc) {
  1397. SDE_ERROR("couldn't reserve %d dsc blocks for enc id %d\n",
  1398. num_dsc_enc, rsvp->enc_id);
  1399. return -EINVAL;
  1400. }
  1401. for (i = 0; i < alloc_count; i++) {
  1402. if (!dsc[i])
  1403. break;
  1404. dsc[i]->rsvp_nxt = rsvp;
  1405. SDE_EVT32(dsc[i]->type, rsvp->enc_id, dsc[i]->id);
  1406. }
  1407. return 0;
  1408. }
  1409. static int _sde_rm_reserve_vdc(
  1410. struct sde_rm *rm,
  1411. struct sde_rm_rsvp *rsvp,
  1412. struct sde_rm_requirements *reqs,
  1413. const struct sde_rm_topology_def *top,
  1414. u8 *_vdc_ids)
  1415. {
  1416. struct sde_rm_hw_iter iter_i;
  1417. struct sde_rm_hw_blk *vdc[MAX_BLOCKS];
  1418. int alloc_count = 0;
  1419. int num_vdc_enc = top->num_comp_enc;
  1420. int i;
  1421. if (!top->num_comp_enc)
  1422. return 0;
  1423. if (reqs->hw_res.comp_info->comp_type != MSM_DISPLAY_COMPRESSION_VDC)
  1424. return 0;
  1425. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_VDC);
  1426. /* Find a VDC */
  1427. while (alloc_count != num_vdc_enc &&
  1428. _sde_rm_get_hw_locked(rm, &iter_i)) {
  1429. memset(&vdc, 0, sizeof(vdc));
  1430. alloc_count = 0;
  1431. if (_vdc_ids && (iter_i.blk->id != _vdc_ids[alloc_count]))
  1432. continue;
  1433. if (!_sde_rm_check_vdc(rm, rsvp, iter_i.blk))
  1434. continue;
  1435. SDE_DEBUG("blk id = %d, _vdc_ids[%d] = %d\n",
  1436. iter_i.blk->id,
  1437. alloc_count,
  1438. _vdc_ids ? _vdc_ids[alloc_count] : -1);
  1439. vdc[alloc_count++] = iter_i.blk;
  1440. }
  1441. if (alloc_count != num_vdc_enc) {
  1442. SDE_ERROR("couldn't reserve %d vdc blocks for enc id %d\n",
  1443. num_vdc_enc, rsvp->enc_id);
  1444. return -EINVAL;
  1445. }
  1446. for (i = 0; i < ARRAY_SIZE(vdc); i++) {
  1447. if (!vdc[i])
  1448. break;
  1449. vdc[i]->rsvp_nxt = rsvp;
  1450. SDE_EVT32(vdc[i]->type, rsvp->enc_id, vdc[i]->id);
  1451. }
  1452. return 0;
  1453. }
  1454. static int _sde_rm_reserve_qdss(
  1455. struct sde_rm *rm,
  1456. struct sde_rm_rsvp *rsvp,
  1457. const struct sde_rm_topology_def *top,
  1458. u8 *_qdss_ids)
  1459. {
  1460. struct sde_rm_hw_iter iter;
  1461. struct msm_drm_private *priv = rm->dev->dev_private;
  1462. struct sde_kms *sde_kms;
  1463. if (!priv->kms) {
  1464. SDE_ERROR("invalid kms\n");
  1465. return -EINVAL;
  1466. }
  1467. sde_kms = to_sde_kms(priv->kms);
  1468. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_QDSS);
  1469. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1470. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1471. continue;
  1472. SDE_DEBUG("blk id = %d\n", iter.blk->id);
  1473. iter.blk->rsvp_nxt = rsvp;
  1474. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1475. return 0;
  1476. }
  1477. if (!iter.hw && sde_kms->catalog->qdss_count) {
  1478. SDE_DEBUG("couldn't reserve qdss for type %d id %d\n",
  1479. SDE_HW_BLK_QDSS, iter.blk->id);
  1480. return -ENAVAIL;
  1481. }
  1482. return 0;
  1483. }
  1484. static int _sde_rm_reserve_dnsc_blur(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1485. uint32_t id, enum sde_hw_blk_type type)
  1486. {
  1487. struct sde_rm_hw_iter iter;
  1488. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DNSC_BLUR);
  1489. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1490. struct sde_hw_dnsc_blur *dnsc_blur = to_sde_hw_dnsc_blur(iter.blk->hw);
  1491. bool match = false;
  1492. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1493. continue;
  1494. if ((type == SDE_HW_BLK_WB) && (id != WB_MAX))
  1495. match = test_bit(id, &dnsc_blur->caps->wb_connect);
  1496. SDE_DEBUG("type %d id %d, dnsc_blur wbs %lu match %d\n",
  1497. type, id, dnsc_blur->caps->wb_connect, match);
  1498. if (!match)
  1499. continue;
  1500. iter.blk->rsvp_nxt = rsvp;
  1501. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1502. break;
  1503. }
  1504. if (!iter.hw) {
  1505. SDE_ERROR("couldn't reserve dnsc_blur for type %d id %d\n", type, id);
  1506. return -ENAVAIL;
  1507. }
  1508. return 0;
  1509. }
  1510. static int _sde_rm_reserve_cdm(
  1511. struct sde_rm *rm,
  1512. struct sde_rm_rsvp *rsvp,
  1513. uint32_t id,
  1514. enum sde_hw_blk_type type)
  1515. {
  1516. struct sde_rm_hw_iter iter;
  1517. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CDM);
  1518. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1519. const struct sde_hw_cdm *cdm = to_sde_hw_cdm(iter.blk->hw);
  1520. const struct sde_cdm_cfg *caps = cdm->caps;
  1521. bool match = false;
  1522. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1523. continue;
  1524. if (type == SDE_HW_BLK_INTF && id != INTF_MAX)
  1525. match = test_bit(id, &caps->intf_connect);
  1526. else if (type == SDE_HW_BLK_WB && id != WB_MAX)
  1527. match = test_bit(id, &caps->wb_connect);
  1528. SDE_DEBUG("type %d id %d, cdm intfs %lu wbs %lu match %d\n",
  1529. type, id, caps->intf_connect, caps->wb_connect,
  1530. match);
  1531. if (!match)
  1532. continue;
  1533. iter.blk->rsvp_nxt = rsvp;
  1534. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1535. break;
  1536. }
  1537. if (!iter.hw) {
  1538. SDE_ERROR("couldn't reserve cdm for type %d id %d\n", type, id);
  1539. return -ENAVAIL;
  1540. }
  1541. return 0;
  1542. }
  1543. static int _sde_rm_reserve_intf_or_wb(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1544. uint32_t id, enum sde_hw_blk_type type, struct sde_rm_requirements *reqs)
  1545. {
  1546. struct sde_encoder_hw_resources *hw_res = &reqs->hw_res;
  1547. struct sde_rm_hw_iter iter;
  1548. int ret = 0;
  1549. /* Find the block entry in the rm, and note the reservation */
  1550. sde_rm_init_hw_iter(&iter, 0, type);
  1551. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1552. if (iter.blk->id != id)
  1553. continue;
  1554. if (RESERVED_BY_OTHER(iter.blk, rsvp)) {
  1555. SDE_ERROR("type %d id %d already reserved\n", type, id);
  1556. return -ENAVAIL;
  1557. }
  1558. iter.blk->rsvp_nxt = rsvp;
  1559. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1560. break;
  1561. }
  1562. /* Shouldn't happen since wbs / intfs are fixed at probe */
  1563. if (!iter.hw) {
  1564. SDE_ERROR("couldn't find type %d id %d\n", type, id);
  1565. return -EINVAL;
  1566. }
  1567. /* Expected only one intf or wb will request cdm */
  1568. if (hw_res->needs_cdm)
  1569. ret = _sde_rm_reserve_cdm(rm, rsvp, id, type);
  1570. if (RM_RQ_DNSC_BLUR(reqs))
  1571. ret = _sde_rm_reserve_dnsc_blur(rm, rsvp, id, type);
  1572. return ret;
  1573. }
  1574. static int _sde_rm_reserve_intf_related_hw(struct sde_rm *rm,
  1575. struct sde_rm_rsvp *rsvp, struct sde_rm_requirements *reqs)
  1576. {
  1577. struct sde_encoder_hw_resources *hw_res = &reqs->hw_res;
  1578. int i, ret = 0;
  1579. u32 id;
  1580. for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) {
  1581. if (hw_res->intfs[i] == INTF_MODE_NONE)
  1582. continue;
  1583. id = i + INTF_0;
  1584. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, SDE_HW_BLK_INTF, reqs);
  1585. if (ret)
  1586. return ret;
  1587. }
  1588. for (i = 0; i < ARRAY_SIZE(hw_res->wbs); i++) {
  1589. if (hw_res->wbs[i] == INTF_MODE_NONE)
  1590. continue;
  1591. id = i + WB_0;
  1592. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, SDE_HW_BLK_WB, reqs);
  1593. if (ret)
  1594. return ret;
  1595. }
  1596. return ret;
  1597. }
  1598. static bool _sde_rm_is_display_in_cont_splash(struct sde_kms *sde_kms,
  1599. struct drm_encoder *enc)
  1600. {
  1601. int i;
  1602. struct sde_splash_display *splash_dpy;
  1603. for (i = 0; i < MAX_DSI_DISPLAYS; i++) {
  1604. splash_dpy = &sde_kms->splash_data.splash_display[i];
  1605. if (splash_dpy->encoder == enc)
  1606. return splash_dpy->cont_splash_enabled;
  1607. }
  1608. return false;
  1609. }
  1610. static int _sde_rm_make_lm_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1611. struct sde_rm_requirements *reqs,
  1612. struct sde_splash_display *splash_display)
  1613. {
  1614. int ret, i;
  1615. u8 *hw_ids = NULL;
  1616. /* Check if splash data provided lm_ids */
  1617. if (splash_display) {
  1618. hw_ids = splash_display->lm_ids;
  1619. for (i = 0; i < splash_display->lm_cnt; i++)
  1620. SDE_DEBUG("splash_display->lm_ids[%d] = %d\n",
  1621. i, splash_display->lm_ids[i]);
  1622. if (splash_display->lm_cnt != reqs->topology->num_lm)
  1623. SDE_DEBUG("Configured splash LMs != needed LM cnt\n");
  1624. }
  1625. /*
  1626. * Assign LMs and blocks whose usage is tied to them:
  1627. * DSPP & Pingpong.
  1628. */
  1629. ret = _sde_rm_reserve_lms(rm, rsvp, reqs, hw_ids);
  1630. return ret;
  1631. }
  1632. static int _sde_rm_make_ctl_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1633. struct sde_rm_requirements *reqs,
  1634. struct sde_splash_display *splash_display)
  1635. {
  1636. int ret, i;
  1637. u8 *hw_ids = NULL;
  1638. struct sde_rm_topology_def topology;
  1639. /* Check if splash data provided ctl_ids */
  1640. if (splash_display) {
  1641. hw_ids = splash_display->ctl_ids;
  1642. for (i = 0; i < splash_display->ctl_cnt; i++)
  1643. SDE_DEBUG("splash_display->ctl_ids[%d] = %d\n",
  1644. i, splash_display->ctl_ids[i]);
  1645. }
  1646. /*
  1647. * Do assignment preferring to give away low-resource CTLs first:
  1648. * - Check mixers without Split Display
  1649. * - Only then allow to grab from CTLs with split display capability
  1650. */
  1651. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, hw_ids);
  1652. if (ret && !reqs->topology->needs_split_display &&
  1653. reqs->topology->num_ctl > SINGLE_CTL) {
  1654. memcpy(&topology, reqs->topology, sizeof(topology));
  1655. topology.needs_split_display = true;
  1656. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, hw_ids);
  1657. }
  1658. return ret;
  1659. }
  1660. /*
  1661. * Returns number of dsc hw blocks previously owned by this encoder.
  1662. * Returns 0 if not found or error
  1663. */
  1664. static int _sde_rm_find_prev_dsc(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1665. u8 *prev_dsc, u32 max_cnt)
  1666. {
  1667. int i = 0;
  1668. struct sde_rm_hw_iter iter_dsc;
  1669. if ((!prev_dsc) || (max_cnt < MAX_DATA_PATH_PER_DSIPLAY))
  1670. return 0;
  1671. sde_rm_init_hw_iter(&iter_dsc, 0, SDE_HW_BLK_DSC);
  1672. while (_sde_rm_get_hw_locked(rm, &iter_dsc)) {
  1673. if (RESERVED_BY_CURRENT(iter_dsc.blk, rsvp))
  1674. prev_dsc[i++] = iter_dsc.blk->id;
  1675. if (i >= MAX_DATA_PATH_PER_DSIPLAY)
  1676. return 0;
  1677. }
  1678. return i;
  1679. }
  1680. static int _sde_rm_make_dsc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1681. struct sde_rm_requirements *reqs,
  1682. struct sde_splash_display *splash_display)
  1683. {
  1684. int i;
  1685. u8 *hw_ids = NULL;
  1686. u8 prev_dsc[MAX_DATA_PATH_PER_DSIPLAY] = {0,};
  1687. /* Check if splash data provided dsc_ids */
  1688. if (splash_display) {
  1689. hw_ids = splash_display->dsc_ids;
  1690. if (splash_display->dsc_cnt)
  1691. reqs->hw_res.comp_info->comp_type =
  1692. MSM_DISPLAY_COMPRESSION_DSC;
  1693. for (i = 0; i < splash_display->dsc_cnt; i++)
  1694. SDE_DEBUG("splash_data.dsc_ids[%d] = %d\n",
  1695. i, splash_display->dsc_ids[i]);
  1696. }
  1697. /*
  1698. * find if this encoder has previously allocated dsc hw blocks, use same dsc blocks
  1699. * if found to avoid switching dsc encoders during each modeset, as currently we
  1700. * dont have feasible way of decoupling previously owned dsc blocks by resetting
  1701. * respective dsc encoders mux control and flush them from commit path
  1702. */
  1703. if (!hw_ids && _sde_rm_find_prev_dsc(rm, rsvp, prev_dsc, MAX_DATA_PATH_PER_DSIPLAY))
  1704. return _sde_rm_reserve_dsc(rm, rsvp, reqs, prev_dsc);
  1705. else
  1706. return _sde_rm_reserve_dsc(rm, rsvp, reqs, hw_ids);
  1707. }
  1708. static int _sde_rm_make_vdc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1709. struct sde_rm_requirements *reqs,
  1710. struct sde_splash_display *splash_display)
  1711. {
  1712. int ret, i;
  1713. u8 *hw_ids = NULL;
  1714. /* Check if splash data provided vdc_ids */
  1715. if (splash_display) {
  1716. hw_ids = splash_display->vdc_ids;
  1717. for (i = 0; i < splash_display->vdc_cnt; i++)
  1718. SDE_DEBUG("splash_data.vdc_ids[%d] = %d\n",
  1719. i, splash_display->vdc_ids[i]);
  1720. }
  1721. ret = _sde_rm_reserve_vdc(rm, rsvp, reqs, reqs->topology, hw_ids);
  1722. return ret;
  1723. }
  1724. static int _sde_rm_make_next_rsvp(struct sde_rm *rm, struct drm_encoder *enc,
  1725. struct drm_crtc_state *crtc_state,
  1726. struct drm_connector_state *conn_state,
  1727. struct sde_rm_rsvp *rsvp,
  1728. struct sde_rm_requirements *reqs)
  1729. {
  1730. struct msm_drm_private *priv;
  1731. struct sde_kms *sde_kms;
  1732. struct sde_splash_display *splash_display = NULL;
  1733. struct sde_splash_data *splash_data;
  1734. int i, ret;
  1735. priv = enc->dev->dev_private;
  1736. sde_kms = to_sde_kms(priv->kms);
  1737. splash_data = &sde_kms->splash_data;
  1738. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  1739. for (i = 0; i < ARRAY_SIZE(splash_data->splash_display); i++) {
  1740. if (enc == splash_data->splash_display[i].encoder)
  1741. splash_display =
  1742. &splash_data->splash_display[i];
  1743. }
  1744. if (!splash_display) {
  1745. SDE_ERROR("rm is in cont_splash but data not found\n");
  1746. return -EINVAL;
  1747. }
  1748. }
  1749. /* Create reservation info, tag reserved blocks with it as we go */
  1750. rsvp->seq = ++rm->rsvp_next_seq;
  1751. rsvp->enc_id = enc->base.id;
  1752. rsvp->topology = reqs->topology->top_name;
  1753. rsvp->pending = true;
  1754. list_add_tail(&rsvp->list, &rm->rsvps);
  1755. ret = _sde_rm_make_lm_rsvp(rm, rsvp, reqs, splash_display);
  1756. if (ret) {
  1757. SDE_ERROR("unable to find appropriate mixers\n");
  1758. _sde_rm_print_rsvps_by_type(rm, SDE_HW_BLK_LM);
  1759. return ret;
  1760. }
  1761. ret = _sde_rm_make_ctl_rsvp(rm, rsvp, reqs, splash_display);
  1762. if (ret) {
  1763. SDE_ERROR("unable to find appropriate CTL\n");
  1764. return ret;
  1765. }
  1766. /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */
  1767. ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, reqs);
  1768. if (ret)
  1769. return ret;
  1770. ret = _sde_rm_make_dsc_rsvp(rm, rsvp, reqs, splash_display);
  1771. if (ret)
  1772. return ret;
  1773. ret = _sde_rm_make_vdc_rsvp(rm, rsvp, reqs, splash_display);
  1774. if (ret)
  1775. return ret;
  1776. ret = _sde_rm_reserve_qdss(rm, rsvp, reqs->topology, NULL);
  1777. if (ret)
  1778. return ret;
  1779. return ret;
  1780. }
  1781. static int _sde_rm_update_active_only_pipes(
  1782. struct sde_splash_display *splash_display,
  1783. u32 active_pipes_mask)
  1784. {
  1785. struct sde_sspp_index_info *pipe_info;
  1786. int i;
  1787. if (!active_pipes_mask) {
  1788. return 0;
  1789. } else if (!splash_display) {
  1790. SDE_ERROR("invalid splash display provided\n");
  1791. return -EINVAL;
  1792. }
  1793. pipe_info = &splash_display->pipe_info;
  1794. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  1795. if (!(active_pipes_mask & BIT(i)))
  1796. continue;
  1797. if (test_bit(i, pipe_info->pipes) || test_bit(i, pipe_info->virt_pipes))
  1798. continue;
  1799. /*
  1800. * A pipe is active but not staged indicates a non-pixel
  1801. * plane. Register both rectangles as we can't differentiate
  1802. */
  1803. set_bit(i, pipe_info->pipes);
  1804. set_bit(i, pipe_info->virt_pipes);
  1805. SDE_DEBUG("pipe %d is active:0x%x but not staged\n", i, active_pipes_mask);
  1806. }
  1807. return 0;
  1808. }
  1809. /**
  1810. * _sde_rm_get_hw_blk_for_cont_splash - retrieve the LM blocks on given CTL
  1811. * and populate the connected HW blk ids in sde_splash_display
  1812. * @rm: Pointer to resource manager structure
  1813. * @ctl: Pointer to CTL hardware block
  1814. * @splash_display: Pointer to struct sde_splash_display
  1815. * return: number of active LM blocks for this CTL block
  1816. */
  1817. static int _sde_rm_get_hw_blk_for_cont_splash(struct sde_rm *rm,
  1818. struct sde_hw_ctl *ctl,
  1819. struct sde_splash_display *splash_display)
  1820. {
  1821. u32 active_pipes_mask = 0;
  1822. struct sde_rm_hw_iter iter_lm, iter_dsc;
  1823. struct sde_kms *sde_kms;
  1824. size_t pipes_per_lm;
  1825. if (!rm || !ctl || !splash_display) {
  1826. SDE_ERROR("invalid input parameters\n");
  1827. return 0;
  1828. }
  1829. sde_kms = container_of(rm, struct sde_kms, rm);
  1830. sde_rm_init_hw_iter(&iter_lm, 0, SDE_HW_BLK_LM);
  1831. sde_rm_init_hw_iter(&iter_dsc, 0, SDE_HW_BLK_DSC);
  1832. while (_sde_rm_get_hw_locked(rm, &iter_lm)) {
  1833. if (splash_display->lm_cnt >= MAX_DATA_PATH_PER_DSIPLAY)
  1834. break;
  1835. if (ctl->ops.get_staged_sspp) {
  1836. // reset bordercolor from previous LM
  1837. splash_display->pipe_info.bordercolor = false;
  1838. pipes_per_lm = ctl->ops.get_staged_sspp(
  1839. ctl, iter_lm.blk->id,
  1840. &splash_display->pipe_info);
  1841. if (pipes_per_lm ||
  1842. splash_display->pipe_info.bordercolor) {
  1843. splash_display->lm_ids[splash_display->lm_cnt++] =
  1844. iter_lm.blk->id;
  1845. SDE_DEBUG("lm_cnt=%d lm_id %d pipe_cnt%d\n",
  1846. splash_display->lm_cnt,
  1847. iter_lm.blk->id - LM_0,
  1848. pipes_per_lm);
  1849. }
  1850. }
  1851. }
  1852. if (ctl->ops.get_active_pipes)
  1853. active_pipes_mask = ctl->ops.get_active_pipes(ctl);
  1854. if (_sde_rm_update_active_only_pipes(splash_display, active_pipes_mask))
  1855. return 0;
  1856. while (_sde_rm_get_hw_locked(rm, &iter_dsc)) {
  1857. if (ctl->ops.read_active_status &&
  1858. !(ctl->ops.read_active_status(ctl,
  1859. SDE_HW_BLK_DSC,
  1860. iter_dsc.blk->id)))
  1861. continue;
  1862. splash_display->dsc_ids[splash_display->dsc_cnt++] =
  1863. iter_dsc.blk->id;
  1864. SDE_DEBUG("CTL[%d] path, using dsc[%d]\n",
  1865. ctl->idx,
  1866. iter_dsc.blk->id - DSC_0);
  1867. }
  1868. return splash_display->lm_cnt;
  1869. }
  1870. int sde_rm_cont_splash_res_init(struct msm_drm_private *priv,
  1871. struct sde_rm *rm,
  1872. struct sde_splash_data *splash_data,
  1873. struct sde_mdss_cfg *cat)
  1874. {
  1875. struct sde_rm_hw_iter iter_c;
  1876. int index = 0, ctl_top_cnt;
  1877. struct sde_kms *sde_kms = NULL;
  1878. struct sde_hw_mdp *hw_mdp;
  1879. struct sde_splash_display *splash_display;
  1880. u8 intf_sel;
  1881. if (!priv || !rm || !cat || !splash_data) {
  1882. SDE_ERROR("invalid input parameters\n");
  1883. return -EINVAL;
  1884. }
  1885. SDE_DEBUG("mixer_count=%d, ctl_count=%d, dsc_count=%d\n",
  1886. cat->mixer_count,
  1887. cat->ctl_count,
  1888. cat->dsc_count);
  1889. ctl_top_cnt = cat->ctl_count;
  1890. if (!priv->kms) {
  1891. SDE_ERROR("invalid kms\n");
  1892. return -EINVAL;
  1893. }
  1894. sde_kms = to_sde_kms(priv->kms);
  1895. hw_mdp = sde_rm_get_mdp(rm);
  1896. sde_rm_init_hw_iter(&iter_c, 0, SDE_HW_BLK_CTL);
  1897. while (_sde_rm_get_hw_locked(rm, &iter_c)
  1898. && (index < splash_data->num_splash_displays)) {
  1899. struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter_c.blk->hw);
  1900. if (!ctl->ops.get_ctl_intf) {
  1901. SDE_ERROR("get_ctl_intf not initialized\n");
  1902. return -EINVAL;
  1903. }
  1904. intf_sel = ctl->ops.get_ctl_intf(ctl);
  1905. if (intf_sel) {
  1906. splash_display = &splash_data->splash_display[index];
  1907. SDE_DEBUG("finding resources for display=%d ctl=%d\n",
  1908. index, iter_c.blk->id - CTL_0);
  1909. _sde_rm_get_hw_blk_for_cont_splash(rm,
  1910. ctl, splash_display);
  1911. splash_display->cont_splash_enabled = true;
  1912. splash_display->ctl_ids[splash_display->ctl_cnt++] =
  1913. iter_c.blk->id;
  1914. }
  1915. index++;
  1916. }
  1917. return 0;
  1918. }
  1919. static int _sde_rm_populate_requirements(
  1920. struct sde_rm *rm,
  1921. struct drm_encoder *enc,
  1922. struct drm_crtc_state *crtc_state,
  1923. struct drm_connector_state *conn_state,
  1924. struct sde_mdss_cfg *cfg,
  1925. struct sde_rm_requirements *reqs)
  1926. {
  1927. const struct drm_display_mode *mode = &crtc_state->mode;
  1928. int i, num_lm;
  1929. reqs->top_ctrl = sde_connector_get_property(conn_state,
  1930. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  1931. sde_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state);
  1932. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) {
  1933. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
  1934. reqs->hw_res.topology)) {
  1935. reqs->topology = &rm->topology_tbl[i];
  1936. break;
  1937. }
  1938. }
  1939. if (!reqs->topology) {
  1940. SDE_ERROR("invalid topology for the display\n");
  1941. return -EINVAL;
  1942. }
  1943. /*
  1944. * select dspp HW block for all dsi displays and ds for only
  1945. * primary dsi display.
  1946. */
  1947. if (conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI) {
  1948. if (!RM_RQ_DSPP(reqs))
  1949. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP);
  1950. if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler &&
  1951. sde_encoder_is_primary_display(enc))
  1952. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DS);
  1953. }
  1954. /**
  1955. * Set the requirement for LM which has CWB support if CWB is
  1956. * found enabled.
  1957. */
  1958. if ((!RM_RQ_CWB(reqs) || !RM_RQ_DCWB(reqs))
  1959. && sde_crtc_state_in_clone_mode(enc, crtc_state)) {
  1960. if (test_bit(SDE_FEATURE_DEDICATED_CWB, cfg->features))
  1961. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DCWB);
  1962. else
  1963. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_CWB);
  1964. /*
  1965. * topology selection based on conn mode is not valid for CWB
  1966. * as WB conn populates modes based on max_mixer_width check
  1967. * but primary can be using dual LMs. This topology override for
  1968. * CWB is to check number of datapath active in primary and
  1969. * allocate same number of LM/PP blocks reserved for CWB
  1970. */
  1971. reqs->topology =
  1972. &rm->topology_tbl[SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE];
  1973. num_lm = sde_crtc_get_num_datapath(crtc_state->crtc,
  1974. conn_state->connector, crtc_state);
  1975. if (num_lm == 1)
  1976. reqs->topology =
  1977. &rm->topology_tbl[SDE_RM_TOPOLOGY_SINGLEPIPE];
  1978. else if (num_lm == 0)
  1979. SDE_ERROR("Primary layer mixer is not set\n");
  1980. SDE_EVT32(num_lm, reqs->topology->num_lm,
  1981. reqs->topology->top_name, reqs->topology->num_ctl);
  1982. }
  1983. SDE_DEBUG("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl,
  1984. reqs->hw_res.display_num_of_h_tiles);
  1985. SDE_DEBUG("num_lm: %d num_ctl: %d topology: %d split_display: %d\n",
  1986. reqs->topology->num_lm, reqs->topology->num_ctl,
  1987. reqs->topology->top_name,
  1988. reqs->topology->needs_split_display);
  1989. SDE_EVT32(mode->hdisplay, rm->lm_max_width, reqs->topology->num_lm,
  1990. reqs->top_ctrl, reqs->topology->top_name,
  1991. reqs->topology->num_ctl);
  1992. return 0;
  1993. }
  1994. static struct sde_rm_rsvp *_sde_rm_get_rsvp(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
  1995. {
  1996. struct sde_rm_rsvp *i;
  1997. if (!rm || !enc) {
  1998. SDE_ERROR("invalid params\n");
  1999. return NULL;
  2000. }
  2001. if (list_empty(&rm->rsvps))
  2002. return NULL;
  2003. list_for_each_entry(i, &rm->rsvps, list)
  2004. if (i->pending == nxt && i->enc_id == enc->base.id)
  2005. return i;
  2006. return NULL;
  2007. }
  2008. static struct sde_rm_rsvp *_sde_rm_get_rsvp_nxt(struct sde_rm *rm, struct drm_encoder *enc)
  2009. {
  2010. return _sde_rm_get_rsvp(rm, enc, true);
  2011. }
  2012. static struct sde_rm_rsvp *_sde_rm_get_rsvp_cur(struct sde_rm *rm, struct drm_encoder *enc)
  2013. {
  2014. return _sde_rm_get_rsvp(rm, enc, false);
  2015. }
  2016. static struct drm_connector *_sde_rm_get_connector(
  2017. struct drm_encoder *enc)
  2018. {
  2019. struct drm_connector *conn = NULL, *conn_search;
  2020. struct sde_connector *c_conn = NULL;
  2021. struct drm_connector_list_iter conn_iter;
  2022. drm_connector_list_iter_begin(enc->dev, &conn_iter);
  2023. drm_for_each_connector_iter(conn_search, &conn_iter) {
  2024. c_conn = to_sde_connector(conn_search);
  2025. if (c_conn->encoder == enc) {
  2026. conn = conn_search;
  2027. break;
  2028. }
  2029. }
  2030. drm_connector_list_iter_end(&conn_iter);
  2031. return conn;
  2032. }
  2033. int sde_rm_update_topology(struct sde_rm *rm,
  2034. struct drm_connector_state *conn_state,
  2035. struct msm_display_topology *topology)
  2036. {
  2037. int i, ret = 0;
  2038. struct msm_display_topology top;
  2039. enum sde_rm_topology_name top_name = SDE_RM_TOPOLOGY_NONE;
  2040. if (!conn_state)
  2041. return -EINVAL;
  2042. if (topology) {
  2043. top = *topology;
  2044. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
  2045. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i], top)) {
  2046. top_name = rm->topology_tbl[i].top_name;
  2047. break;
  2048. }
  2049. }
  2050. ret = msm_property_set_property(
  2051. sde_connector_get_propinfo(conn_state->connector),
  2052. sde_connector_get_property_state(conn_state),
  2053. CONNECTOR_PROP_TOPOLOGY_NAME, top_name);
  2054. return ret;
  2055. }
  2056. bool sde_rm_topology_is_group(struct sde_rm *rm,
  2057. struct drm_crtc_state *state,
  2058. enum sde_rm_topology_group group)
  2059. {
  2060. int i, ret = 0;
  2061. struct sde_crtc_state *cstate;
  2062. struct drm_connector *conn;
  2063. struct drm_connector_state *conn_state;
  2064. struct msm_display_topology topology;
  2065. enum sde_rm_topology_name name;
  2066. if ((!rm) || (!state) || (!state->state)) {
  2067. pr_err("invalid arguments: rm:%d state:%d atomic state:%d\n",
  2068. !rm, !state, state ? (!state->state) : 0);
  2069. return false;
  2070. }
  2071. cstate = to_sde_crtc_state(state);
  2072. for (i = 0; i < cstate->num_connectors; i++) {
  2073. conn = cstate->connectors[i];
  2074. if (!conn) {
  2075. SDE_DEBUG("invalid connector\n");
  2076. continue;
  2077. }
  2078. conn_state = drm_atomic_get_new_connector_state(state->state,
  2079. conn);
  2080. if (!conn_state) {
  2081. SDE_DEBUG("%s invalid connector state\n", conn->name);
  2082. continue;
  2083. }
  2084. ret = sde_connector_state_get_topology(conn_state, &topology);
  2085. if (ret) {
  2086. SDE_DEBUG("%s invalid topology\n", conn->name);
  2087. continue;
  2088. }
  2089. name = sde_rm_get_topology_name(rm, topology);
  2090. switch (group) {
  2091. case SDE_RM_TOPOLOGY_GROUP_SINGLEPIPE:
  2092. if (TOPOLOGY_SINGLEPIPE_MODE(name))
  2093. return true;
  2094. break;
  2095. case SDE_RM_TOPOLOGY_GROUP_DUALPIPE:
  2096. if (TOPOLOGY_DUALPIPE_MODE(name))
  2097. return true;
  2098. break;
  2099. case SDE_RM_TOPOLOGY_GROUP_QUADPIPE:
  2100. if (TOPOLOGY_QUADPIPE_MODE(name))
  2101. return true;
  2102. break;
  2103. case SDE_RM_TOPOLOGY_GROUP_3DMERGE:
  2104. if (topology.num_lm > topology.num_intf &&
  2105. !topology.num_enc)
  2106. return true;
  2107. break;
  2108. case SDE_RM_TOPOLOGY_GROUP_3DMERGE_DSC:
  2109. if (topology.num_lm > topology.num_enc &&
  2110. topology.num_enc)
  2111. return true;
  2112. break;
  2113. case SDE_RM_TOPOLOGY_GROUP_DSCMERGE:
  2114. if (topology.num_lm == topology.num_enc &&
  2115. topology.num_enc)
  2116. return true;
  2117. break;
  2118. default:
  2119. SDE_ERROR("invalid topology group\n");
  2120. return false;
  2121. }
  2122. }
  2123. return false;
  2124. }
  2125. /**
  2126. * _sde_rm_release_rsvp - release resources and release a reservation
  2127. * @rm: KMS handle
  2128. * @rsvp: RSVP pointer to release and release resources for
  2129. */
  2130. static void _sde_rm_release_rsvp(
  2131. struct sde_rm *rm,
  2132. struct sde_rm_rsvp *rsvp,
  2133. struct drm_connector *conn)
  2134. {
  2135. struct sde_rm_rsvp *rsvp_c, *rsvp_n;
  2136. struct sde_rm_hw_blk *blk;
  2137. enum sde_hw_blk_type type;
  2138. if (!rsvp)
  2139. return;
  2140. SDE_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id);
  2141. list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) {
  2142. if (rsvp == rsvp_c) {
  2143. list_del(&rsvp_c->list);
  2144. break;
  2145. }
  2146. }
  2147. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  2148. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  2149. if (blk->rsvp == rsvp) {
  2150. blk->rsvp = NULL;
  2151. SDE_DEBUG("rel rsvp %d enc %d %d %d\n",
  2152. rsvp->seq, rsvp->enc_id,
  2153. blk->type, blk->id);
  2154. _sde_rm_inc_resource_info(rm,
  2155. &rm->avail_res, blk);
  2156. }
  2157. if (blk->rsvp_nxt == rsvp) {
  2158. blk->rsvp_nxt = NULL;
  2159. SDE_DEBUG("rel rsvp_nxt %d enc %d %d %d\n",
  2160. rsvp->seq, rsvp->enc_id,
  2161. blk->type, blk->id);
  2162. }
  2163. }
  2164. }
  2165. kfree(rsvp);
  2166. }
  2167. void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
  2168. {
  2169. struct sde_rm_rsvp *rsvp;
  2170. struct drm_connector *conn = NULL;
  2171. struct msm_drm_private *priv;
  2172. struct sde_kms *sde_kms;
  2173. uint64_t top_ctrl = 0;
  2174. if (!rm || !enc) {
  2175. SDE_ERROR("invalid params\n");
  2176. return;
  2177. }
  2178. priv = enc->dev->dev_private;
  2179. if (!priv->kms) {
  2180. SDE_ERROR("invalid kms\n");
  2181. return;
  2182. }
  2183. sde_kms = to_sde_kms(priv->kms);
  2184. mutex_lock(&rm->rm_lock);
  2185. rsvp = _sde_rm_get_rsvp(rm, enc, nxt);
  2186. if (!rsvp) {
  2187. SDE_DEBUG("failed to find rsvp for enc %d, nxt %d",
  2188. enc->base.id, nxt);
  2189. goto end;
  2190. }
  2191. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  2192. _sde_rm_release_rsvp(rm, rsvp, conn);
  2193. goto end;
  2194. }
  2195. conn = _sde_rm_get_connector(enc);
  2196. if (!conn) {
  2197. SDE_EVT32(enc->base.id, 0x0, 0xffffffff);
  2198. _sde_rm_release_rsvp(rm, rsvp, conn);
  2199. SDE_DEBUG("failed to get conn for enc %d nxt %d\n",
  2200. enc->base.id, nxt);
  2201. goto end;
  2202. }
  2203. top_ctrl = sde_connector_get_property(conn->state,
  2204. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  2205. SDE_EVT32(enc->base.id, conn->base.id, rsvp->seq, top_ctrl, nxt);
  2206. if (top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) {
  2207. SDE_DEBUG("rsvp[s%de%d] not releasing locked resources\n",
  2208. rsvp->seq, rsvp->enc_id);
  2209. } else {
  2210. SDE_DEBUG("release rsvp[s%de%d]\n", rsvp->seq,
  2211. rsvp->enc_id);
  2212. _sde_rm_release_rsvp(rm, rsvp, conn);
  2213. }
  2214. end:
  2215. mutex_unlock(&rm->rm_lock);
  2216. }
  2217. static void _sde_rm_commit_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  2218. struct drm_connector_state *conn_state)
  2219. {
  2220. struct sde_rm_hw_blk *blk;
  2221. enum sde_hw_blk_type type;
  2222. /* Swap next rsvp to be the active */
  2223. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  2224. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  2225. if (blk->rsvp_nxt && conn_state->best_encoder->base.id
  2226. == blk->rsvp_nxt->enc_id) {
  2227. blk->rsvp = blk->rsvp_nxt;
  2228. blk->rsvp_nxt = NULL;
  2229. _sde_rm_dec_resource_info(rm,
  2230. &rm->avail_res, blk);
  2231. }
  2232. }
  2233. }
  2234. rsvp->pending = false;
  2235. SDE_DEBUG("rsrv enc %d topology %d\n", rsvp->enc_id, rsvp->topology);
  2236. SDE_EVT32(rsvp->enc_id, rsvp->topology);
  2237. }
  2238. /* call this only after rm_mutex held */
  2239. struct sde_rm_rsvp *_sde_rm_poll_get_rsvp_nxt_locked(struct sde_rm *rm,
  2240. struct drm_encoder *enc)
  2241. {
  2242. int i;
  2243. u32 loop_count = 20;
  2244. struct sde_rm_rsvp *rsvp_nxt = NULL;
  2245. u32 sleep = RM_NXT_CLEAR_POLL_TIMEOUT_US / loop_count;
  2246. for (i = 0; i < loop_count; i++) {
  2247. rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
  2248. if (!rsvp_nxt)
  2249. return rsvp_nxt;
  2250. mutex_unlock(&rm->rm_lock);
  2251. SDE_DEBUG("iteration i:%d sleep range:%uus to %uus\n",
  2252. i, sleep, sleep * 2);
  2253. usleep_range(sleep, sleep * 2);
  2254. mutex_lock(&rm->rm_lock);
  2255. }
  2256. /* make sure to get latest rsvp_next to avoid use after free issues */
  2257. return _sde_rm_get_rsvp_nxt(rm, enc);
  2258. }
  2259. int sde_rm_reserve(
  2260. struct sde_rm *rm,
  2261. struct drm_encoder *enc,
  2262. struct drm_crtc_state *crtc_state,
  2263. struct drm_connector_state *conn_state,
  2264. bool test_only)
  2265. {
  2266. struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
  2267. struct sde_rm_requirements reqs = {0,};
  2268. struct msm_drm_private *priv;
  2269. struct sde_kms *sde_kms;
  2270. struct msm_compression_info *comp_info;
  2271. int ret = 0;
  2272. if (!rm || !enc || !crtc_state || !conn_state) {
  2273. SDE_ERROR("invalid arguments\n");
  2274. return -EINVAL;
  2275. }
  2276. if (!enc->dev || !enc->dev->dev_private) {
  2277. SDE_ERROR("drm device invalid\n");
  2278. return -EINVAL;
  2279. }
  2280. priv = enc->dev->dev_private;
  2281. if (!priv->kms) {
  2282. SDE_ERROR("invalid kms\n");
  2283. return -EINVAL;
  2284. }
  2285. sde_kms = to_sde_kms(priv->kms);
  2286. /* Check if this is just a page-flip */
  2287. if (!_sde_rm_is_display_in_cont_splash(sde_kms, enc) &&
  2288. !msm_atomic_needs_modeset(crtc_state, conn_state))
  2289. return 0;
  2290. comp_info = kzalloc(sizeof(*comp_info), GFP_KERNEL);
  2291. if (!comp_info)
  2292. return -ENOMEM;
  2293. SDE_DEBUG("reserving hw for conn %d enc %d crtc %d test_only %d\n",
  2294. conn_state->connector->base.id, enc->base.id,
  2295. crtc_state->crtc->base.id, test_only);
  2296. SDE_EVT32(enc->base.id, conn_state->connector->base.id, test_only);
  2297. mutex_lock(&rm->rm_lock);
  2298. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_BEGIN);
  2299. rsvp_cur = _sde_rm_get_rsvp_cur(rm, enc);
  2300. rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
  2301. /*
  2302. * RM currently relies on rsvp_nxt assigned to the hw blocks to
  2303. * commit rsvps. This rsvp_nxt can be cleared by a back to back
  2304. * check_only commit with modeset when its predecessor atomic
  2305. * commit is delayed / not committed the reservation yet.
  2306. * Poll for rsvp_nxt clear, allow the check_only commit if rsvp_nxt
  2307. * gets cleared and bailout if it does not get cleared before timeout.
  2308. */
  2309. if (test_only && rsvp_nxt) {
  2310. rsvp_nxt = _sde_rm_poll_get_rsvp_nxt_locked(rm, enc);
  2311. rsvp_cur = _sde_rm_get_rsvp_cur(rm, enc);
  2312. if (rsvp_nxt) {
  2313. pr_err("poll timeout cur %d nxt %d enc %d\n",
  2314. (rsvp_cur) ? rsvp_cur->seq : -1,
  2315. rsvp_nxt->seq, enc->base.id);
  2316. SDE_EVT32(enc->base.id, (rsvp_cur) ? rsvp_cur->seq : -1,
  2317. rsvp_nxt->seq, SDE_EVTLOG_ERROR);
  2318. ret = -EAGAIN;
  2319. goto end;
  2320. }
  2321. }
  2322. if (!test_only && rsvp_nxt)
  2323. goto commit_rsvp;
  2324. reqs.hw_res.comp_info = comp_info;
  2325. ret = _sde_rm_populate_requirements(rm, enc, crtc_state,
  2326. conn_state, sde_kms->catalog, &reqs);
  2327. if (ret) {
  2328. SDE_ERROR("failed to populate hw requirements\n");
  2329. goto end;
  2330. }
  2331. /*
  2332. * We only support one active reservation per-hw-block. But to implement
  2333. * transactional semantics for test-only, and for allowing failure while
  2334. * modifying your existing reservation, over the course of this
  2335. * function we can have two reservations:
  2336. * Current: Existing reservation
  2337. * Next: Proposed reservation. The proposed reservation may fail, or may
  2338. * be discarded if in test-only mode.
  2339. * If reservation is successful, and we're not in test-only, then we
  2340. * replace the current with the next.
  2341. */
  2342. rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL);
  2343. if (!rsvp_nxt) {
  2344. ret = -ENOMEM;
  2345. goto end;
  2346. }
  2347. /*
  2348. * User can request that we clear out any reservation during the
  2349. * atomic_check phase by using this CLEAR bit
  2350. */
  2351. if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) {
  2352. SDE_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n",
  2353. rsvp_cur->seq, rsvp_cur->enc_id);
  2354. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  2355. rsvp_cur = NULL;
  2356. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_CLEAR);
  2357. }
  2358. /* Check the proposed reservation, store it in hw's "next" field */
  2359. ret = _sde_rm_make_next_rsvp(rm, enc, crtc_state, conn_state,
  2360. rsvp_nxt, &reqs);
  2361. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_RSVPNEXT);
  2362. if (ret) {
  2363. SDE_ERROR("failed to reserve hw resources: %d, test_only %d\n",
  2364. ret, test_only);
  2365. _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
  2366. goto end;
  2367. } else if (test_only && !RM_RQ_LOCK(&reqs)) {
  2368. /*
  2369. * Normally, if test_only, test the reservation and then undo
  2370. * However, if the user requests LOCK, then keep the reservation
  2371. * made during the atomic_check phase.
  2372. */
  2373. SDE_DEBUG("test_only: rsvp[s%de%d]\n",
  2374. rsvp_nxt->seq, rsvp_nxt->enc_id);
  2375. goto end;
  2376. } else {
  2377. if (test_only && RM_RQ_LOCK(&reqs))
  2378. SDE_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n",
  2379. rsvp_nxt->seq, rsvp_nxt->enc_id);
  2380. }
  2381. commit_rsvp:
  2382. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  2383. _sde_rm_commit_rsvp(rm, rsvp_nxt, conn_state);
  2384. end:
  2385. kfree(comp_info);
  2386. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_FINAL);
  2387. mutex_unlock(&rm->rm_lock);
  2388. return ret;
  2389. }