sde_rm.c 78 KB

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