sde_rm.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2023 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. {
  1307. const struct sde_dsc_cfg *dsc_cfg = to_sde_hw_dsc(dsc->hw)->caps;
  1308. /* Already reserved? */
  1309. if (RESERVED_BY_OTHER(dsc, rsvp)) {
  1310. SDE_DEBUG("dsc %d already reserved\n", dsc_cfg->id);
  1311. return false;
  1312. }
  1313. /**
  1314. * This check is required for routing even numbered DSC
  1315. * blks to any of the even numbered PP blks and odd numbered
  1316. * DSC blks to any of the odd numbered PP blks.
  1317. */
  1318. if (!pp_blk || !IS_COMPATIBLE_PP_DSC(pp_blk->id, dsc->id)) {
  1319. SDE_DEBUG("dsc %d can't match of pp %d\n", dsc_cfg->id, pp_blk ? pp_blk->id : -1);
  1320. return false;
  1321. }
  1322. /* Check if this dsc is a peer of the proposed paired DSC */
  1323. if (paired_dsc) {
  1324. const struct sde_dsc_cfg *paired_dsc_cfg =
  1325. to_sde_hw_dsc(paired_dsc->hw)->caps;
  1326. if (!test_bit(dsc_cfg->id, paired_dsc_cfg->dsc_pair_mask)) {
  1327. SDE_DEBUG("dsc %d not peer of dsc %d\n", dsc_cfg->id,
  1328. paired_dsc_cfg->id);
  1329. return false;
  1330. }
  1331. }
  1332. return true;
  1333. }
  1334. static bool _sde_rm_check_vdc(struct sde_rm *rm,
  1335. struct sde_rm_rsvp *rsvp,
  1336. struct sde_rm_hw_blk *vdc)
  1337. {
  1338. const struct sde_vdc_cfg *vdc_cfg = to_sde_hw_vdc(vdc->hw)->caps;
  1339. /* Already reserved? */
  1340. if (RESERVED_BY_OTHER(vdc, rsvp)) {
  1341. SDE_DEBUG("vdc %d already reserved\n", vdc_cfg->id);
  1342. return false;
  1343. }
  1344. return true;
  1345. }
  1346. static void sde_rm_get_rsvp_nxt_hw_blks(
  1347. struct sde_rm *rm,
  1348. struct sde_rm_rsvp *rsvp,
  1349. int type,
  1350. struct sde_rm_hw_blk **blk_arr,
  1351. bool list_forward)
  1352. {
  1353. struct sde_rm_hw_blk *blk;
  1354. int i = 0;
  1355. if (list_forward) {
  1356. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  1357. if (blk->rsvp_nxt && blk->rsvp_nxt->seq ==
  1358. rsvp->seq)
  1359. blk_arr[i++] = blk;
  1360. }
  1361. } else {
  1362. list_for_each_entry_reverse(blk, &rm->hw_blks[type], list) {
  1363. if (blk->rsvp_nxt && blk->rsvp_nxt->seq ==
  1364. rsvp->seq)
  1365. blk_arr[i++] = blk;
  1366. }
  1367. }
  1368. }
  1369. static int _sde_rm_reserve_dsc(
  1370. struct sde_rm *rm,
  1371. struct sde_rm_rsvp *rsvp,
  1372. struct sde_rm_requirements *reqs,
  1373. u8 *_dsc_ids)
  1374. {
  1375. struct sde_rm_hw_iter iter_i, iter_j;
  1376. struct sde_rm_hw_blk *dsc[MAX_BLOCKS];
  1377. u32 reserve_mask = 0;
  1378. struct sde_rm_hw_blk *pp[MAX_BLOCKS];
  1379. int alloc_count = 0;
  1380. int num_dsc_enc;
  1381. struct msm_display_dsc_info *dsc_info;
  1382. bool list_forward = false;
  1383. struct drm_encoder *encoder;
  1384. int i;
  1385. if (reqs->hw_res.comp_info->comp_type != MSM_DISPLAY_COMPRESSION_DSC) {
  1386. SDE_DEBUG("compression blk dsc not required\n");
  1387. return 0;
  1388. }
  1389. num_dsc_enc = reqs->topology->num_comp_enc;
  1390. dsc_info = &reqs->hw_res.comp_info->dsc_info;
  1391. if ((!num_dsc_enc) || !dsc_info) {
  1392. SDE_DEBUG("invalid topoplogy params: %d, %d\n",
  1393. num_dsc_enc, !(dsc_info == NULL));
  1394. return 0;
  1395. }
  1396. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_DSC);
  1397. drm_for_each_encoder(encoder, rm->dev) {
  1398. /* backwards allocate DSC modules for non built-in case */
  1399. if (encoder->base.id == rsvp ->enc_id)
  1400. list_forward = sde_encoder_is_dsi_display(encoder);
  1401. }
  1402. sde_rm_get_rsvp_nxt_hw_blks(rm, rsvp, SDE_HW_BLK_PINGPONG, pp, list_forward);
  1403. /* Find a first DSC */
  1404. while (alloc_count != num_dsc_enc &&
  1405. _sde_rm_get_hw_locked(rm, &iter_i, list_forward)) {
  1406. int req_index = list_forward ? alloc_count : (num_dsc_enc - alloc_count - 1);
  1407. const struct sde_hw_dsc *hw_dsc = to_sde_hw_dsc(iter_i.blk->hw);
  1408. unsigned long features = hw_dsc->caps->features;
  1409. bool has_422_420_support = BIT(SDE_DSC_NATIVE_422_EN) & features;
  1410. if (reserve_mask & (1 << iter_i.blk->id))
  1411. continue;
  1412. if (_dsc_ids && (iter_i.blk->id != _dsc_ids[req_index]))
  1413. continue;
  1414. /* if this hw block does not support required feature */
  1415. if (!_dsc_ids && (dsc_info->config.native_422 ||
  1416. dsc_info->config.native_420) && !has_422_420_support)
  1417. continue;
  1418. if (!_sde_rm_check_dsc(rm, rsvp, iter_i.blk, NULL,
  1419. pp[alloc_count]))
  1420. continue;
  1421. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  1422. iter_i.blk->id,
  1423. alloc_count,
  1424. _dsc_ids ? _dsc_ids[req_index] : -1);
  1425. /* reset and restart from current block if allocated dsc blocks are not contiguous */
  1426. if (alloc_count >= 1 && (abs(dsc[alloc_count - 1]->id - iter_i.blk->id) != 1)) {
  1427. reserve_mask = 0;
  1428. alloc_count = 0;
  1429. }
  1430. reserve_mask |= (1 << iter_i.blk->id);
  1431. dsc[alloc_count++] = iter_i.blk;
  1432. /* Return if peer is not needed */
  1433. if (alloc_count == num_dsc_enc)
  1434. break;
  1435. /* Valid first dsc found, find matching peers */
  1436. sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_DSC);
  1437. while (_sde_rm_get_hw_locked(rm, &iter_j, list_forward)) {
  1438. req_index = list_forward ? alloc_count : (num_dsc_enc - alloc_count - 1);
  1439. if (reserve_mask & (1 << iter_j.blk->id))
  1440. continue;
  1441. if (_dsc_ids && (iter_j.blk->id !=
  1442. _dsc_ids[req_index]))
  1443. continue;
  1444. if (!_sde_rm_check_dsc(rm, rsvp, iter_j.blk,
  1445. iter_i.blk, pp[alloc_count]))
  1446. continue;
  1447. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  1448. iter_j.blk->id,
  1449. alloc_count,
  1450. _dsc_ids ? _dsc_ids[req_index] : -1);
  1451. reserve_mask |= (1 << iter_j.blk->id);
  1452. dsc[alloc_count++] = iter_j.blk;
  1453. break;
  1454. }
  1455. /* Rollback primary DSC if peer is not found */
  1456. if (!iter_j.hw) {
  1457. reserve_mask &= ~(1 << iter_i.blk->id);
  1458. --alloc_count;
  1459. }
  1460. }
  1461. if (alloc_count != num_dsc_enc) {
  1462. SDE_ERROR("couldn't reserve %d dsc blocks for enc id %d\n",
  1463. num_dsc_enc, rsvp->enc_id);
  1464. return -EINVAL;
  1465. }
  1466. for (i = 0; i < alloc_count; i++) {
  1467. if (!dsc[i])
  1468. break;
  1469. dsc[i]->rsvp_nxt = rsvp;
  1470. SDE_EVT32(dsc[i]->type, rsvp->enc_id, dsc[i]->id);
  1471. }
  1472. return 0;
  1473. }
  1474. static int _sde_rm_reserve_vdc(
  1475. struct sde_rm *rm,
  1476. struct sde_rm_rsvp *rsvp,
  1477. struct sde_rm_requirements *reqs,
  1478. const struct sde_rm_topology_def *top,
  1479. u8 *_vdc_ids)
  1480. {
  1481. struct sde_rm_hw_iter iter_i;
  1482. struct sde_rm_hw_blk *vdc[MAX_BLOCKS];
  1483. int alloc_count = 0;
  1484. int num_vdc_enc = top->num_comp_enc;
  1485. int i;
  1486. if (!top->num_comp_enc)
  1487. return 0;
  1488. if (reqs->hw_res.comp_info->comp_type != MSM_DISPLAY_COMPRESSION_VDC)
  1489. return 0;
  1490. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_VDC);
  1491. /* Find a VDC */
  1492. while (alloc_count != num_vdc_enc &&
  1493. _sde_rm_get_hw_locked(rm, &iter_i, true)) {
  1494. memset(&vdc, 0, sizeof(vdc));
  1495. alloc_count = 0;
  1496. if (_vdc_ids && (iter_i.blk->id != _vdc_ids[alloc_count]))
  1497. continue;
  1498. if (!_sde_rm_check_vdc(rm, rsvp, iter_i.blk))
  1499. continue;
  1500. SDE_DEBUG("blk id = %d, _vdc_ids[%d] = %d\n",
  1501. iter_i.blk->id,
  1502. alloc_count,
  1503. _vdc_ids ? _vdc_ids[alloc_count] : -1);
  1504. vdc[alloc_count++] = iter_i.blk;
  1505. }
  1506. if (alloc_count != num_vdc_enc) {
  1507. SDE_ERROR("couldn't reserve %d vdc blocks for enc id %d\n",
  1508. num_vdc_enc, rsvp->enc_id);
  1509. return -EINVAL;
  1510. }
  1511. for (i = 0; i < ARRAY_SIZE(vdc); i++) {
  1512. if (!vdc[i])
  1513. break;
  1514. vdc[i]->rsvp_nxt = rsvp;
  1515. SDE_EVT32(vdc[i]->type, rsvp->enc_id, vdc[i]->id);
  1516. }
  1517. return 0;
  1518. }
  1519. static int _sde_rm_reserve_qdss(
  1520. struct sde_rm *rm,
  1521. struct sde_rm_rsvp *rsvp,
  1522. const struct sde_rm_topology_def *top,
  1523. u8 *_qdss_ids)
  1524. {
  1525. struct sde_rm_hw_iter iter;
  1526. struct msm_drm_private *priv = rm->dev->dev_private;
  1527. struct sde_kms *sde_kms;
  1528. if (!priv->kms) {
  1529. SDE_ERROR("invalid kms\n");
  1530. return -EINVAL;
  1531. }
  1532. sde_kms = to_sde_kms(priv->kms);
  1533. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_QDSS);
  1534. while (_sde_rm_get_hw_locked(rm, &iter, true)) {
  1535. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1536. continue;
  1537. SDE_DEBUG("blk id = %d\n", iter.blk->id);
  1538. iter.blk->rsvp_nxt = rsvp;
  1539. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1540. return 0;
  1541. }
  1542. if (!iter.hw && sde_kms->catalog->qdss_count) {
  1543. SDE_DEBUG("couldn't reserve qdss for type %d id %d\n",
  1544. SDE_HW_BLK_QDSS, iter.blk->id);
  1545. return -ENAVAIL;
  1546. }
  1547. return 0;
  1548. }
  1549. static int _sde_rm_reserve_dnsc_blur(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1550. uint32_t id, enum sde_hw_blk_type type)
  1551. {
  1552. struct sde_rm_hw_iter iter;
  1553. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DNSC_BLUR);
  1554. while (_sde_rm_get_hw_locked(rm, &iter, true)) {
  1555. struct sde_hw_dnsc_blur *dnsc_blur = to_sde_hw_dnsc_blur(iter.blk->hw);
  1556. bool match = false;
  1557. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1558. continue;
  1559. if ((type == SDE_HW_BLK_WB) && (id != WB_MAX))
  1560. match = test_bit(id, &dnsc_blur->caps->wb_connect);
  1561. SDE_DEBUG("type %d id %d, dnsc_blur wbs %lu match %d\n",
  1562. type, id, dnsc_blur->caps->wb_connect, match);
  1563. if (!match)
  1564. continue;
  1565. iter.blk->rsvp_nxt = rsvp;
  1566. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1567. break;
  1568. }
  1569. if (!iter.hw) {
  1570. SDE_ERROR("couldn't reserve dnsc_blur for type %d id %d\n", type, id);
  1571. return -ENAVAIL;
  1572. }
  1573. return 0;
  1574. }
  1575. static int _sde_rm_reserve_cdm(
  1576. struct sde_rm *rm,
  1577. struct sde_rm_rsvp *rsvp,
  1578. uint32_t id,
  1579. enum sde_hw_blk_type type)
  1580. {
  1581. struct sde_rm_hw_iter iter;
  1582. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CDM);
  1583. while (_sde_rm_get_hw_locked(rm, &iter, true)) {
  1584. const struct sde_hw_cdm *cdm = to_sde_hw_cdm(iter.blk->hw);
  1585. const struct sde_cdm_cfg *caps = cdm->caps;
  1586. bool match = false;
  1587. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1588. continue;
  1589. if (type == SDE_HW_BLK_INTF && id != INTF_MAX)
  1590. match = test_bit(id, &caps->intf_connect);
  1591. else if (type == SDE_HW_BLK_WB && id != WB_MAX)
  1592. match = test_bit(id, &caps->wb_connect);
  1593. SDE_DEBUG("type %d id %d, cdm intfs %lu wbs %lu match %d\n",
  1594. type, id, caps->intf_connect, caps->wb_connect,
  1595. match);
  1596. if (!match)
  1597. continue;
  1598. iter.blk->rsvp_nxt = rsvp;
  1599. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1600. break;
  1601. }
  1602. if (!iter.hw) {
  1603. SDE_ERROR("couldn't reserve cdm for type %d id %d\n", type, id);
  1604. return -ENAVAIL;
  1605. }
  1606. return 0;
  1607. }
  1608. static int _sde_rm_reserve_intf_or_wb(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1609. uint32_t id, enum sde_hw_blk_type type, struct sde_rm_requirements *reqs)
  1610. {
  1611. struct sde_encoder_hw_resources *hw_res = &reqs->hw_res;
  1612. struct sde_rm_hw_iter iter;
  1613. int ret = 0;
  1614. /* Find the block entry in the rm, and note the reservation */
  1615. sde_rm_init_hw_iter(&iter, 0, type);
  1616. while (_sde_rm_get_hw_locked(rm, &iter, true)) {
  1617. if (iter.blk->id != id)
  1618. continue;
  1619. if (RESERVED_BY_OTHER(iter.blk, rsvp)) {
  1620. SDE_ERROR("type %d id %d already reserved\n", type, id);
  1621. return -ENAVAIL;
  1622. }
  1623. iter.blk->rsvp_nxt = rsvp;
  1624. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1625. break;
  1626. }
  1627. /* Shouldn't happen since wbs / intfs are fixed at probe */
  1628. if (!iter.hw) {
  1629. SDE_ERROR("couldn't find type %d id %d\n", type, id);
  1630. return -EINVAL;
  1631. }
  1632. /* Expected only one intf or wb will request cdm */
  1633. if (hw_res->needs_cdm || RM_RQ_CDM(reqs)) {
  1634. ret = _sde_rm_reserve_cdm(rm, rsvp, id, type);
  1635. if (ret)
  1636. return ret;
  1637. }
  1638. if (RM_RQ_DNSC_BLUR(reqs))
  1639. ret = _sde_rm_reserve_dnsc_blur(rm, rsvp, id, type);
  1640. return ret;
  1641. }
  1642. static int _sde_rm_reserve_intf_related_hw(struct sde_rm *rm,
  1643. struct sde_rm_rsvp *rsvp, struct sde_rm_requirements *reqs)
  1644. {
  1645. struct sde_encoder_hw_resources *hw_res = &reqs->hw_res;
  1646. int i, ret = 0;
  1647. u32 id;
  1648. for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) {
  1649. if (hw_res->intfs[i] == INTF_MODE_NONE)
  1650. continue;
  1651. id = i + INTF_0;
  1652. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, SDE_HW_BLK_INTF, reqs);
  1653. if (ret)
  1654. return ret;
  1655. }
  1656. for (i = 0; i < ARRAY_SIZE(hw_res->wbs); i++) {
  1657. if (hw_res->wbs[i] == INTF_MODE_NONE)
  1658. continue;
  1659. id = i + WB_0;
  1660. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, SDE_HW_BLK_WB, reqs);
  1661. if (ret)
  1662. return ret;
  1663. }
  1664. return ret;
  1665. }
  1666. static bool _sde_rm_is_display_in_cont_splash(struct sde_kms *sde_kms,
  1667. struct drm_encoder *enc)
  1668. {
  1669. int i;
  1670. struct sde_splash_display *splash_dpy;
  1671. for (i = 0; i < MAX_DSI_DISPLAYS; i++) {
  1672. splash_dpy = &sde_kms->splash_data.splash_display[i];
  1673. if (splash_dpy->encoder == enc)
  1674. return splash_dpy->cont_splash_enabled;
  1675. }
  1676. return false;
  1677. }
  1678. static int _sde_rm_make_lm_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1679. struct sde_rm_requirements *reqs,
  1680. struct sde_splash_display *splash_display)
  1681. {
  1682. int ret, i;
  1683. u8 *hw_ids = NULL;
  1684. /* Check if splash data provided lm_ids */
  1685. if (splash_display) {
  1686. hw_ids = splash_display->lm_ids;
  1687. for (i = 0; i < splash_display->lm_cnt; i++)
  1688. SDE_DEBUG("splash_display->lm_ids[%d] = %d\n",
  1689. i, splash_display->lm_ids[i]);
  1690. if (splash_display->lm_cnt != reqs->topology->num_lm)
  1691. SDE_DEBUG("Configured splash LMs != needed LM cnt\n");
  1692. }
  1693. /*
  1694. * Assign LMs and blocks whose usage is tied to them:
  1695. * DSPP & Pingpong.
  1696. */
  1697. ret = _sde_rm_reserve_lms(rm, rsvp, reqs, hw_ids);
  1698. return ret;
  1699. }
  1700. static int _sde_rm_make_ctl_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1701. struct sde_rm_requirements *reqs,
  1702. struct sde_splash_display *splash_display)
  1703. {
  1704. int ret, i;
  1705. u8 *hw_ids = NULL;
  1706. struct sde_rm_topology_def topology;
  1707. /* Check if splash data provided ctl_ids */
  1708. if (splash_display) {
  1709. hw_ids = splash_display->ctl_ids;
  1710. for (i = 0; i < splash_display->ctl_cnt; i++)
  1711. SDE_DEBUG("splash_display->ctl_ids[%d] = %d\n",
  1712. i, splash_display->ctl_ids[i]);
  1713. }
  1714. /*
  1715. * Do assignment preferring to give away low-resource CTLs first:
  1716. * - Check mixers without Split Display
  1717. * - Only then allow to grab from CTLs with split display capability
  1718. */
  1719. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, hw_ids);
  1720. if (ret && !reqs->topology->needs_split_display &&
  1721. reqs->topology->num_ctl > SINGLE_CTL) {
  1722. memcpy(&topology, reqs->topology, sizeof(topology));
  1723. topology.needs_split_display = true;
  1724. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, hw_ids);
  1725. }
  1726. return ret;
  1727. }
  1728. /*
  1729. * Returns number of dsc hw blocks previously owned by this encoder.
  1730. * Returns 0 if not found or error
  1731. */
  1732. static int _sde_rm_find_prev_dsc(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1733. u8 *prev_dsc, u32 max_cnt)
  1734. {
  1735. int i = 0;
  1736. struct sde_rm_hw_iter iter_dsc;
  1737. if ((!prev_dsc) || (max_cnt < MAX_DATA_PATH_PER_DSIPLAY))
  1738. return 0;
  1739. sde_rm_init_hw_iter(&iter_dsc, 0, SDE_HW_BLK_DSC);
  1740. while (_sde_rm_get_hw_locked(rm, &iter_dsc, true)) {
  1741. if (RESERVED_BY_CURRENT(iter_dsc.blk, rsvp))
  1742. prev_dsc[i++] = iter_dsc.blk->id;
  1743. if (i >= MAX_DATA_PATH_PER_DSIPLAY)
  1744. return 0;
  1745. }
  1746. return i;
  1747. }
  1748. static int _sde_rm_make_dsc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1749. struct sde_rm_requirements *reqs,
  1750. struct sde_splash_display *splash_display)
  1751. {
  1752. int i;
  1753. u8 *hw_ids = NULL;
  1754. u8 prev_dsc[MAX_DATA_PATH_PER_DSIPLAY] = {0,};
  1755. /* Check if splash data provided dsc_ids */
  1756. if (splash_display) {
  1757. hw_ids = splash_display->dsc_ids;
  1758. if (splash_display->dsc_cnt)
  1759. reqs->hw_res.comp_info->comp_type =
  1760. MSM_DISPLAY_COMPRESSION_DSC;
  1761. for (i = 0; i < splash_display->dsc_cnt; i++)
  1762. SDE_DEBUG("splash_data.dsc_ids[%d] = %d\n",
  1763. i, splash_display->dsc_ids[i]);
  1764. }
  1765. /*
  1766. * find if this encoder has previously allocated dsc hw blocks, use same dsc blocks
  1767. * if found to avoid switching dsc encoders during each modeset, as currently we
  1768. * dont have feasible way of decoupling previously owned dsc blocks by resetting
  1769. * respective dsc encoders mux control and flush them from commit path
  1770. */
  1771. if (!hw_ids && _sde_rm_find_prev_dsc(rm, rsvp, prev_dsc, MAX_DATA_PATH_PER_DSIPLAY))
  1772. return _sde_rm_reserve_dsc(rm, rsvp, reqs, prev_dsc);
  1773. else
  1774. return _sde_rm_reserve_dsc(rm, rsvp, reqs, hw_ids);
  1775. }
  1776. static int _sde_rm_make_vdc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1777. struct sde_rm_requirements *reqs,
  1778. struct sde_splash_display *splash_display)
  1779. {
  1780. int ret, i;
  1781. u8 *hw_ids = NULL;
  1782. /* Check if splash data provided vdc_ids */
  1783. if (splash_display) {
  1784. hw_ids = splash_display->vdc_ids;
  1785. for (i = 0; i < splash_display->vdc_cnt; i++)
  1786. SDE_DEBUG("splash_data.vdc_ids[%d] = %d\n",
  1787. i, splash_display->vdc_ids[i]);
  1788. }
  1789. ret = _sde_rm_reserve_vdc(rm, rsvp, reqs, reqs->topology, hw_ids);
  1790. return ret;
  1791. }
  1792. static int _sde_rm_make_next_rsvp(struct sde_rm *rm, struct drm_encoder *enc,
  1793. struct drm_crtc_state *crtc_state,
  1794. struct drm_connector_state *conn_state,
  1795. struct sde_rm_rsvp *rsvp,
  1796. struct sde_rm_requirements *reqs)
  1797. {
  1798. struct msm_drm_private *priv;
  1799. struct sde_kms *sde_kms;
  1800. struct sde_splash_display *splash_display = NULL;
  1801. struct sde_splash_data *splash_data;
  1802. int i, ret;
  1803. priv = enc->dev->dev_private;
  1804. sde_kms = to_sde_kms(priv->kms);
  1805. splash_data = &sde_kms->splash_data;
  1806. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  1807. for (i = 0; i < ARRAY_SIZE(splash_data->splash_display); i++) {
  1808. if (enc == splash_data->splash_display[i].encoder)
  1809. splash_display =
  1810. &splash_data->splash_display[i];
  1811. }
  1812. if (!splash_display) {
  1813. SDE_ERROR("rm is in cont_splash but data not found\n");
  1814. return -EINVAL;
  1815. }
  1816. }
  1817. /* Create reservation info, tag reserved blocks with it as we go */
  1818. rsvp->seq = ++rm->rsvp_next_seq;
  1819. rsvp->enc_id = enc->base.id;
  1820. rsvp->topology = reqs->topology->top_name;
  1821. rsvp->pending = true;
  1822. list_add_tail(&rsvp->list, &rm->rsvps);
  1823. ret = _sde_rm_make_lm_rsvp(rm, rsvp, reqs, splash_display);
  1824. if (ret) {
  1825. SDE_ERROR("unable to find appropriate mixers\n");
  1826. _sde_rm_print_rsvps_by_type(rm, SDE_HW_BLK_LM);
  1827. return ret;
  1828. }
  1829. ret = _sde_rm_make_ctl_rsvp(rm, rsvp, reqs, splash_display);
  1830. if (ret) {
  1831. SDE_ERROR("unable to find appropriate CTL\n");
  1832. return ret;
  1833. }
  1834. /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */
  1835. ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, reqs);
  1836. if (ret)
  1837. return ret;
  1838. ret = _sde_rm_make_dsc_rsvp(rm, rsvp, reqs, splash_display);
  1839. if (ret)
  1840. return ret;
  1841. ret = _sde_rm_make_vdc_rsvp(rm, rsvp, reqs, splash_display);
  1842. if (ret)
  1843. return ret;
  1844. ret = _sde_rm_reserve_qdss(rm, rsvp, reqs->topology, NULL);
  1845. if (ret)
  1846. return ret;
  1847. return ret;
  1848. }
  1849. static int _sde_rm_update_active_only_pipes(
  1850. struct sde_splash_display *splash_display,
  1851. u32 active_pipes_mask)
  1852. {
  1853. struct sde_sspp_index_info *pipe_info;
  1854. int i;
  1855. if (!active_pipes_mask) {
  1856. return 0;
  1857. } else if (!splash_display) {
  1858. SDE_ERROR("invalid splash display provided\n");
  1859. return -EINVAL;
  1860. }
  1861. pipe_info = &splash_display->pipe_info;
  1862. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  1863. if (!(active_pipes_mask & BIT(i)))
  1864. continue;
  1865. if (test_bit(i, pipe_info->pipes) || test_bit(i, pipe_info->virt_pipes))
  1866. continue;
  1867. /*
  1868. * A pipe is active but not staged indicates a non-pixel
  1869. * plane. Register both rectangles as we can't differentiate
  1870. */
  1871. set_bit(i, pipe_info->pipes);
  1872. set_bit(i, pipe_info->virt_pipes);
  1873. SDE_DEBUG("pipe %d is active:0x%x but not staged\n", i, active_pipes_mask);
  1874. }
  1875. return 0;
  1876. }
  1877. /**
  1878. * _sde_rm_get_hw_blk_for_cont_splash - retrieve the LM blocks on given CTL
  1879. * and populate the connected HW blk ids in sde_splash_display
  1880. * @rm: Pointer to resource manager structure
  1881. * @ctl: Pointer to CTL hardware block
  1882. * @splash_display: Pointer to struct sde_splash_display
  1883. * return: number of active LM blocks for this CTL block
  1884. */
  1885. static int _sde_rm_get_hw_blk_for_cont_splash(struct sde_rm *rm,
  1886. struct sde_hw_ctl *ctl,
  1887. struct sde_splash_display *splash_display)
  1888. {
  1889. u32 active_pipes_mask = 0;
  1890. struct sde_rm_hw_iter iter_lm, iter_dsc;
  1891. struct sde_kms *sde_kms;
  1892. size_t pipes_per_lm;
  1893. if (!rm || !ctl || !splash_display) {
  1894. SDE_ERROR("invalid input parameters\n");
  1895. return 0;
  1896. }
  1897. sde_kms = container_of(rm, struct sde_kms, rm);
  1898. sde_rm_init_hw_iter(&iter_lm, 0, SDE_HW_BLK_LM);
  1899. sde_rm_init_hw_iter(&iter_dsc, 0, SDE_HW_BLK_DSC);
  1900. while (_sde_rm_get_hw_locked(rm, &iter_lm, true)) {
  1901. if (splash_display->lm_cnt >= MAX_DATA_PATH_PER_DSIPLAY)
  1902. break;
  1903. if (ctl->ops.get_staged_sspp) {
  1904. // reset bordercolor from previous LM
  1905. splash_display->pipe_info.bordercolor = false;
  1906. pipes_per_lm = ctl->ops.get_staged_sspp(
  1907. ctl, iter_lm.blk->id,
  1908. &splash_display->pipe_info);
  1909. if (pipes_per_lm ||
  1910. splash_display->pipe_info.bordercolor) {
  1911. splash_display->lm_ids[splash_display->lm_cnt++] =
  1912. iter_lm.blk->id;
  1913. SDE_DEBUG("lm_cnt=%d lm_id %d pipe_cnt%d\n",
  1914. splash_display->lm_cnt,
  1915. iter_lm.blk->id - LM_0,
  1916. pipes_per_lm);
  1917. }
  1918. }
  1919. }
  1920. if (ctl->ops.get_active_pipes)
  1921. active_pipes_mask = ctl->ops.get_active_pipes(ctl);
  1922. if (_sde_rm_update_active_only_pipes(splash_display, active_pipes_mask))
  1923. return 0;
  1924. while (_sde_rm_get_hw_locked(rm, &iter_dsc, true)) {
  1925. if (ctl->ops.read_active_status &&
  1926. !(ctl->ops.read_active_status(ctl,
  1927. SDE_HW_BLK_DSC,
  1928. iter_dsc.blk->id)))
  1929. continue;
  1930. splash_display->dsc_ids[splash_display->dsc_cnt++] =
  1931. iter_dsc.blk->id;
  1932. SDE_DEBUG("CTL[%d] path, using dsc[%d]\n",
  1933. ctl->idx,
  1934. iter_dsc.blk->id - DSC_0);
  1935. }
  1936. return splash_display->lm_cnt;
  1937. }
  1938. int sde_rm_cont_splash_res_init(struct msm_drm_private *priv,
  1939. struct sde_rm *rm,
  1940. struct sde_splash_data *splash_data,
  1941. struct sde_mdss_cfg *cat)
  1942. {
  1943. struct sde_rm_hw_iter iter_c;
  1944. int index = 0, ctl_top_cnt;
  1945. struct sde_kms *sde_kms = NULL;
  1946. struct sde_hw_mdp *hw_mdp;
  1947. struct sde_splash_display *splash_display;
  1948. u8 intf_sel;
  1949. if (!priv || !rm || !cat || !splash_data) {
  1950. SDE_ERROR("invalid input parameters\n");
  1951. return -EINVAL;
  1952. }
  1953. SDE_DEBUG("mixer_count=%d, ctl_count=%d, dsc_count=%d\n",
  1954. cat->mixer_count,
  1955. cat->ctl_count,
  1956. cat->dsc_count);
  1957. ctl_top_cnt = cat->ctl_count;
  1958. if (!priv->kms) {
  1959. SDE_ERROR("invalid kms\n");
  1960. return -EINVAL;
  1961. }
  1962. sde_kms = to_sde_kms(priv->kms);
  1963. hw_mdp = sde_rm_get_mdp(rm);
  1964. sde_rm_init_hw_iter(&iter_c, 0, SDE_HW_BLK_CTL);
  1965. while (_sde_rm_get_hw_locked(rm, &iter_c, true)
  1966. && (index < splash_data->num_splash_displays)) {
  1967. struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter_c.blk->hw);
  1968. if (!ctl->ops.get_ctl_intf) {
  1969. SDE_ERROR("get_ctl_intf not initialized\n");
  1970. return -EINVAL;
  1971. }
  1972. intf_sel = ctl->ops.get_ctl_intf(ctl);
  1973. if (intf_sel) {
  1974. splash_display = &splash_data->splash_display[index];
  1975. SDE_DEBUG("finding resources for display=%d ctl=%d\n",
  1976. index, iter_c.blk->id - CTL_0);
  1977. _sde_rm_get_hw_blk_for_cont_splash(rm,
  1978. ctl, splash_display);
  1979. splash_display->cont_splash_enabled = true;
  1980. splash_display->ctl_ids[splash_display->ctl_cnt++] =
  1981. iter_c.blk->id;
  1982. }
  1983. index++;
  1984. }
  1985. return 0;
  1986. }
  1987. static struct drm_connector *_sde_rm_get_connector(
  1988. struct drm_encoder *enc)
  1989. {
  1990. struct drm_connector *conn = NULL, *conn_search;
  1991. struct sde_connector *c_conn = NULL;
  1992. struct drm_connector_list_iter conn_iter;
  1993. drm_connector_list_iter_begin(enc->dev, &conn_iter);
  1994. drm_for_each_connector_iter(conn_search, &conn_iter) {
  1995. c_conn = to_sde_connector(conn_search);
  1996. if (c_conn->encoder == enc) {
  1997. conn = conn_search;
  1998. break;
  1999. }
  2000. }
  2001. drm_connector_list_iter_end(&conn_iter);
  2002. return conn;
  2003. }
  2004. static int _sde_rm_populate_requirements(
  2005. struct sde_rm *rm,
  2006. struct drm_encoder *enc,
  2007. struct drm_crtc_state *crtc_state,
  2008. struct drm_connector_state *conn_state,
  2009. struct sde_mdss_cfg *cfg,
  2010. struct sde_rm_requirements *reqs)
  2011. {
  2012. const struct drm_display_mode *mode = &crtc_state->mode;
  2013. struct drm_encoder *encoder_iter;
  2014. struct drm_connector *conn;
  2015. int i, num_lm;
  2016. reqs->top_ctrl = sde_connector_get_property(conn_state,
  2017. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  2018. sde_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state);
  2019. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) {
  2020. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
  2021. reqs->hw_res.topology)) {
  2022. reqs->topology = &rm->topology_tbl[i];
  2023. break;
  2024. }
  2025. }
  2026. if (!reqs->topology) {
  2027. SDE_ERROR("invalid topology for the display\n");
  2028. return -EINVAL;
  2029. }
  2030. /*
  2031. * select dspp HW block for all dsi displays and ds for only
  2032. * primary dsi display.
  2033. */
  2034. if (conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI) {
  2035. if (!RM_RQ_DSPP(reqs))
  2036. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP);
  2037. if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler &&
  2038. sde_encoder_is_primary_display(enc))
  2039. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DS);
  2040. }
  2041. /**
  2042. * Set the requirement for LM which has CWB support if CWB is
  2043. * found enabled.
  2044. */
  2045. if ((!RM_RQ_CWB(reqs) || !RM_RQ_DCWB(reqs))
  2046. && sde_crtc_state_in_clone_mode(enc, crtc_state)) {
  2047. if (test_bit(SDE_FEATURE_DEDICATED_CWB, cfg->features))
  2048. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DCWB);
  2049. else
  2050. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_CWB);
  2051. /*
  2052. * topology selection based on conn mode is not valid for CWB
  2053. * as WB conn populates modes based on max_mixer_width check
  2054. * but primary can be using dual LMs. This topology override for
  2055. * CWB is to check number of datapath active in primary and
  2056. * allocate same number of LM/PP blocks reserved for CWB
  2057. */
  2058. reqs->topology =
  2059. &rm->topology_tbl[SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE];
  2060. num_lm = sde_crtc_get_num_datapath(crtc_state->crtc,
  2061. conn_state->connector, crtc_state);
  2062. if (num_lm == 1)
  2063. reqs->topology =
  2064. &rm->topology_tbl[SDE_RM_TOPOLOGY_SINGLEPIPE];
  2065. else if (num_lm == 0)
  2066. SDE_ERROR("Primary layer mixer is not set\n");
  2067. SDE_EVT32(num_lm, reqs->topology->num_lm,
  2068. reqs->topology->top_name, reqs->topology->num_ctl);
  2069. }
  2070. if (RM_RQ_DCWB(reqs)) {
  2071. drm_for_each_encoder_mask(encoder_iter, enc->dev,
  2072. crtc_state->encoder_mask) {
  2073. if (drm_encoder_mask(encoder_iter) == drm_encoder_mask(enc))
  2074. continue;
  2075. conn = _sde_rm_get_connector(encoder_iter);
  2076. if (conn)
  2077. reqs->conn_lm_mask = to_sde_connector(conn)->lm_mask;
  2078. break;
  2079. }
  2080. }
  2081. SDE_DEBUG("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl,
  2082. reqs->hw_res.display_num_of_h_tiles);
  2083. SDE_DEBUG("num_lm: %d num_ctl: %d topology: %d split_display: %d mask: 0x%llX\n",
  2084. reqs->topology->num_lm, reqs->topology->num_ctl,
  2085. reqs->topology->top_name,
  2086. reqs->topology->needs_split_display, reqs->conn_lm_mask);
  2087. SDE_EVT32(mode->hdisplay, rm->lm_max_width, reqs->topology->num_lm,
  2088. reqs->top_ctrl, reqs->topology->top_name,
  2089. reqs->topology->num_ctl, reqs->conn_lm_mask);
  2090. return 0;
  2091. }
  2092. static struct sde_rm_rsvp *_sde_rm_get_rsvp(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
  2093. {
  2094. struct sde_rm_rsvp *i;
  2095. if (!rm || !enc) {
  2096. SDE_ERROR("invalid params\n");
  2097. return NULL;
  2098. }
  2099. if (list_empty(&rm->rsvps))
  2100. return NULL;
  2101. list_for_each_entry(i, &rm->rsvps, list)
  2102. if (i->pending == nxt && i->enc_id == enc->base.id)
  2103. return i;
  2104. return NULL;
  2105. }
  2106. static struct sde_rm_rsvp *_sde_rm_get_rsvp_nxt(struct sde_rm *rm, struct drm_encoder *enc)
  2107. {
  2108. return _sde_rm_get_rsvp(rm, enc, true);
  2109. }
  2110. static struct sde_rm_rsvp *_sde_rm_get_rsvp_cur(struct sde_rm *rm, struct drm_encoder *enc)
  2111. {
  2112. return _sde_rm_get_rsvp(rm, enc, false);
  2113. }
  2114. int sde_rm_update_topology(struct sde_rm *rm,
  2115. struct drm_connector_state *conn_state,
  2116. struct msm_display_topology *topology)
  2117. {
  2118. int i, ret = 0;
  2119. struct msm_display_topology top;
  2120. enum sde_rm_topology_name top_name = SDE_RM_TOPOLOGY_NONE;
  2121. if (!conn_state)
  2122. return -EINVAL;
  2123. if (topology) {
  2124. top = *topology;
  2125. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
  2126. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i], top)) {
  2127. top_name = rm->topology_tbl[i].top_name;
  2128. break;
  2129. }
  2130. }
  2131. ret = msm_property_set_property(
  2132. sde_connector_get_propinfo(conn_state->connector),
  2133. sde_connector_get_property_state(conn_state),
  2134. CONNECTOR_PROP_TOPOLOGY_NAME, top_name);
  2135. return ret;
  2136. }
  2137. bool sde_rm_topology_is_group(struct sde_rm *rm,
  2138. struct drm_crtc_state *state,
  2139. enum sde_rm_topology_group group)
  2140. {
  2141. int i, ret = 0;
  2142. struct sde_crtc_state *cstate;
  2143. struct drm_connector *conn;
  2144. struct drm_connector_state *conn_state;
  2145. struct msm_display_topology topology;
  2146. enum sde_rm_topology_name name;
  2147. if ((!rm) || (!state) || (!state->state)) {
  2148. pr_err("invalid arguments: rm:%d state:%d atomic state:%d\n",
  2149. !rm, !state, state ? (!state->state) : 0);
  2150. return false;
  2151. }
  2152. cstate = to_sde_crtc_state(state);
  2153. for (i = 0; i < cstate->num_connectors; i++) {
  2154. conn = cstate->connectors[i];
  2155. if (!conn) {
  2156. SDE_DEBUG("invalid connector\n");
  2157. continue;
  2158. }
  2159. conn_state = drm_atomic_get_new_connector_state(state->state,
  2160. conn);
  2161. if (!conn_state) {
  2162. SDE_DEBUG("%s invalid connector state\n", conn->name);
  2163. continue;
  2164. }
  2165. ret = sde_connector_state_get_topology(conn_state, &topology);
  2166. if (ret) {
  2167. SDE_DEBUG("%s invalid topology\n", conn->name);
  2168. continue;
  2169. }
  2170. name = sde_rm_get_topology_name(rm, topology);
  2171. switch (group) {
  2172. case SDE_RM_TOPOLOGY_GROUP_SINGLEPIPE:
  2173. if (TOPOLOGY_SINGLEPIPE_MODE(name))
  2174. return true;
  2175. break;
  2176. case SDE_RM_TOPOLOGY_GROUP_DUALPIPE:
  2177. if (TOPOLOGY_DUALPIPE_MODE(name))
  2178. return true;
  2179. break;
  2180. case SDE_RM_TOPOLOGY_GROUP_QUADPIPE:
  2181. if (TOPOLOGY_QUADPIPE_MODE(name))
  2182. return true;
  2183. break;
  2184. case SDE_RM_TOPOLOGY_GROUP_3DMERGE:
  2185. if (topology.num_lm > topology.num_intf &&
  2186. !topology.num_enc)
  2187. return true;
  2188. break;
  2189. case SDE_RM_TOPOLOGY_GROUP_3DMERGE_DSC:
  2190. if (topology.num_lm > topology.num_enc &&
  2191. topology.num_enc)
  2192. return true;
  2193. break;
  2194. case SDE_RM_TOPOLOGY_GROUP_DSCMERGE:
  2195. if (topology.num_lm == topology.num_enc &&
  2196. topology.num_enc)
  2197. return true;
  2198. break;
  2199. default:
  2200. SDE_ERROR("invalid topology group\n");
  2201. return false;
  2202. }
  2203. }
  2204. return false;
  2205. }
  2206. /**
  2207. * _sde_rm_release_rsvp - release resources and release a reservation
  2208. * @rm: KMS handle
  2209. * @rsvp: RSVP pointer to release and release resources for
  2210. */
  2211. static void _sde_rm_release_rsvp(
  2212. struct sde_rm *rm,
  2213. struct sde_rm_rsvp *rsvp,
  2214. struct drm_connector *conn)
  2215. {
  2216. struct sde_rm_rsvp *rsvp_c, *rsvp_n;
  2217. struct sde_rm_hw_blk *blk;
  2218. enum sde_hw_blk_type type;
  2219. if (!rsvp)
  2220. return;
  2221. SDE_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id);
  2222. list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) {
  2223. if (rsvp == rsvp_c) {
  2224. list_del(&rsvp_c->list);
  2225. break;
  2226. }
  2227. }
  2228. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  2229. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  2230. if (blk->rsvp == rsvp) {
  2231. blk->rsvp = NULL;
  2232. SDE_DEBUG("rel rsvp %d enc %d %d %d\n",
  2233. rsvp->seq, rsvp->enc_id,
  2234. blk->type, blk->id);
  2235. _sde_rm_inc_resource_info(rm,
  2236. &rm->avail_res, blk);
  2237. }
  2238. if (blk->rsvp_nxt == rsvp) {
  2239. blk->rsvp_nxt = NULL;
  2240. SDE_DEBUG("rel rsvp_nxt %d enc %d %d %d\n",
  2241. rsvp->seq, rsvp->enc_id,
  2242. blk->type, blk->id);
  2243. }
  2244. }
  2245. }
  2246. kfree(rsvp);
  2247. }
  2248. void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
  2249. {
  2250. struct sde_rm_rsvp *rsvp;
  2251. struct drm_connector *conn = NULL;
  2252. struct msm_drm_private *priv;
  2253. struct sde_kms *sde_kms;
  2254. uint64_t top_ctrl = 0;
  2255. if (!rm || !enc) {
  2256. SDE_ERROR("invalid params\n");
  2257. return;
  2258. }
  2259. priv = enc->dev->dev_private;
  2260. if (!priv->kms) {
  2261. SDE_ERROR("invalid kms\n");
  2262. return;
  2263. }
  2264. sde_kms = to_sde_kms(priv->kms);
  2265. mutex_lock(&rm->rm_lock);
  2266. rsvp = _sde_rm_get_rsvp(rm, enc, nxt);
  2267. if (!rsvp) {
  2268. SDE_DEBUG("failed to find rsvp for enc %d, nxt %d",
  2269. enc->base.id, nxt);
  2270. goto end;
  2271. }
  2272. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  2273. _sde_rm_release_rsvp(rm, rsvp, conn);
  2274. goto end;
  2275. }
  2276. conn = _sde_rm_get_connector(enc);
  2277. if (!conn) {
  2278. SDE_EVT32(enc->base.id, 0x0, 0xffffffff);
  2279. _sde_rm_release_rsvp(rm, rsvp, conn);
  2280. SDE_DEBUG("failed to get conn for enc %d nxt %d\n",
  2281. enc->base.id, nxt);
  2282. goto end;
  2283. }
  2284. top_ctrl = sde_connector_get_property(conn->state,
  2285. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  2286. SDE_EVT32(enc->base.id, conn->base.id, rsvp->seq, top_ctrl, nxt);
  2287. if (top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) {
  2288. SDE_DEBUG("rsvp[s%de%d] not releasing locked resources\n",
  2289. rsvp->seq, rsvp->enc_id);
  2290. } else {
  2291. SDE_DEBUG("release rsvp[s%de%d]\n", rsvp->seq,
  2292. rsvp->enc_id);
  2293. _sde_rm_release_rsvp(rm, rsvp, conn);
  2294. }
  2295. end:
  2296. mutex_unlock(&rm->rm_lock);
  2297. }
  2298. static void _sde_rm_commit_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  2299. struct drm_connector_state *conn_state)
  2300. {
  2301. struct sde_rm_hw_blk *blk;
  2302. enum sde_hw_blk_type type;
  2303. /* Swap next rsvp to be the active */
  2304. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  2305. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  2306. if (blk->rsvp_nxt && conn_state->best_encoder->base.id
  2307. == blk->rsvp_nxt->enc_id) {
  2308. blk->rsvp = blk->rsvp_nxt;
  2309. blk->rsvp_nxt = NULL;
  2310. _sde_rm_dec_resource_info(rm,
  2311. &rm->avail_res, blk);
  2312. }
  2313. }
  2314. }
  2315. rsvp->pending = false;
  2316. SDE_DEBUG("rsrv enc %d topology %d\n", rsvp->enc_id, rsvp->topology);
  2317. SDE_EVT32(rsvp->enc_id, rsvp->topology);
  2318. }
  2319. static void _sde_rm_populate_dp_lm_mask(struct sde_rm *rm,
  2320. struct drm_connector *conn)
  2321. {
  2322. struct sde_connector *c_conn = NULL;
  2323. struct sde_rm_hw_blk *blk;
  2324. if (!rm || !conn) {
  2325. SDE_ERROR("invalid arguments\n");
  2326. return;
  2327. }
  2328. if (conn->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  2329. return;
  2330. c_conn = to_sde_connector(conn);
  2331. if (!c_conn || !c_conn->encoder)
  2332. return;
  2333. list_for_each_entry(blk, &rm->hw_blks[SDE_HW_BLK_LM], list) {
  2334. if (!blk->rsvp)
  2335. continue;
  2336. if (blk->rsvp->enc_id == c_conn->encoder->base.id)
  2337. c_conn->lm_mask |= BIT(blk->id - 1);
  2338. }
  2339. SDE_DEBUG("conn lm_mask %d for conn %d enc %d\n", c_conn->lm_mask,
  2340. conn->base.id, c_conn->encoder->base.id);
  2341. SDE_EVT32(c_conn->encoder->base.id, conn->base.id, c_conn->lm_mask);
  2342. }
  2343. /* call this only after rm_mutex held */
  2344. struct sde_rm_rsvp *_sde_rm_poll_get_rsvp_nxt_locked(struct sde_rm *rm,
  2345. struct drm_encoder *enc)
  2346. {
  2347. int i;
  2348. u32 loop_count = 20;
  2349. struct sde_rm_rsvp *rsvp_nxt = NULL;
  2350. u32 sleep = RM_NXT_CLEAR_POLL_TIMEOUT_US / loop_count;
  2351. for (i = 0; i < loop_count; i++) {
  2352. rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
  2353. if (!rsvp_nxt)
  2354. return rsvp_nxt;
  2355. mutex_unlock(&rm->rm_lock);
  2356. SDE_DEBUG("iteration i:%d sleep range:%uus to %uus\n",
  2357. i, sleep, sleep * 2);
  2358. usleep_range(sleep, sleep * 2);
  2359. mutex_lock(&rm->rm_lock);
  2360. }
  2361. /* make sure to get latest rsvp_next to avoid use after free issues */
  2362. return _sde_rm_get_rsvp_nxt(rm, enc);
  2363. }
  2364. int sde_rm_reserve(
  2365. struct sde_rm *rm,
  2366. struct drm_encoder *enc,
  2367. struct drm_crtc_state *crtc_state,
  2368. struct drm_connector_state *conn_state,
  2369. bool test_only)
  2370. {
  2371. struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
  2372. struct sde_rm_requirements reqs = {0,};
  2373. struct msm_drm_private *priv;
  2374. struct sde_kms *sde_kms;
  2375. struct msm_compression_info *comp_info;
  2376. int ret = 0;
  2377. if (!rm || !enc || !crtc_state || !conn_state) {
  2378. SDE_ERROR("invalid arguments\n");
  2379. return -EINVAL;
  2380. }
  2381. if (!enc->dev || !enc->dev->dev_private) {
  2382. SDE_ERROR("drm device invalid\n");
  2383. return -EINVAL;
  2384. }
  2385. priv = enc->dev->dev_private;
  2386. if (!priv->kms) {
  2387. SDE_ERROR("invalid kms\n");
  2388. return -EINVAL;
  2389. }
  2390. sde_kms = to_sde_kms(priv->kms);
  2391. /* Check if this is just a page-flip */
  2392. if (!_sde_rm_is_display_in_cont_splash(sde_kms, enc) &&
  2393. !msm_atomic_needs_modeset(crtc_state, conn_state))
  2394. return 0;
  2395. comp_info = kzalloc(sizeof(*comp_info), GFP_KERNEL);
  2396. if (!comp_info)
  2397. return -ENOMEM;
  2398. SDE_DEBUG("reserving hw for conn %d enc %d crtc %d test_only %d\n",
  2399. conn_state->connector->base.id, enc->base.id,
  2400. crtc_state->crtc->base.id, test_only);
  2401. SDE_EVT32(enc->base.id, conn_state->connector->base.id, test_only);
  2402. mutex_lock(&rm->rm_lock);
  2403. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_BEGIN);
  2404. rsvp_cur = _sde_rm_get_rsvp_cur(rm, enc);
  2405. rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
  2406. /*
  2407. * RM currently relies on rsvp_nxt assigned to the hw blocks to
  2408. * commit rsvps. This rsvp_nxt can be cleared by a back to back
  2409. * check_only commit with modeset when its predecessor atomic
  2410. * commit is delayed / not committed the reservation yet.
  2411. * Poll for rsvp_nxt clear, allow the check_only commit if rsvp_nxt
  2412. * gets cleared and bailout if it does not get cleared before timeout.
  2413. */
  2414. if (test_only && rsvp_nxt) {
  2415. rsvp_nxt = _sde_rm_poll_get_rsvp_nxt_locked(rm, enc);
  2416. rsvp_cur = _sde_rm_get_rsvp_cur(rm, enc);
  2417. if (rsvp_nxt) {
  2418. pr_err("poll timeout cur %d nxt %d enc %d\n",
  2419. (rsvp_cur) ? rsvp_cur->seq : -1,
  2420. rsvp_nxt->seq, enc->base.id);
  2421. SDE_EVT32(enc->base.id, (rsvp_cur) ? rsvp_cur->seq : -1,
  2422. rsvp_nxt->seq, SDE_EVTLOG_ERROR);
  2423. ret = -EAGAIN;
  2424. goto end;
  2425. }
  2426. }
  2427. if (!test_only && rsvp_nxt)
  2428. goto commit_rsvp;
  2429. reqs.hw_res.comp_info = comp_info;
  2430. ret = _sde_rm_populate_requirements(rm, enc, crtc_state,
  2431. conn_state, sde_kms->catalog, &reqs);
  2432. if (ret) {
  2433. SDE_ERROR("failed to populate hw requirements\n");
  2434. goto end;
  2435. }
  2436. /*
  2437. * We only support one active reservation per-hw-block. But to implement
  2438. * transactional semantics for test-only, and for allowing failure while
  2439. * modifying your existing reservation, over the course of this
  2440. * function we can have two reservations:
  2441. * Current: Existing reservation
  2442. * Next: Proposed reservation. The proposed reservation may fail, or may
  2443. * be discarded if in test-only mode.
  2444. * If reservation is successful, and we're not in test-only, then we
  2445. * replace the current with the next.
  2446. */
  2447. rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL);
  2448. if (!rsvp_nxt) {
  2449. ret = -ENOMEM;
  2450. goto end;
  2451. }
  2452. /*
  2453. * User can request that we clear out any reservation during the
  2454. * atomic_check phase by using this CLEAR bit
  2455. */
  2456. if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) {
  2457. SDE_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n",
  2458. rsvp_cur->seq, rsvp_cur->enc_id);
  2459. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  2460. rsvp_cur = NULL;
  2461. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_CLEAR);
  2462. }
  2463. /* Check the proposed reservation, store it in hw's "next" field */
  2464. ret = _sde_rm_make_next_rsvp(rm, enc, crtc_state, conn_state,
  2465. rsvp_nxt, &reqs);
  2466. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_RSVPNEXT);
  2467. if (ret) {
  2468. SDE_ERROR("failed to reserve hw resources: %d, test_only %d\n",
  2469. ret, test_only);
  2470. _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
  2471. goto end;
  2472. } else if (test_only && !RM_RQ_LOCK(&reqs)) {
  2473. /*
  2474. * Normally, if test_only, test the reservation and then undo
  2475. * However, if the user requests LOCK, then keep the reservation
  2476. * made during the atomic_check phase.
  2477. */
  2478. SDE_DEBUG("test_only: rsvp[s%de%d]\n",
  2479. rsvp_nxt->seq, rsvp_nxt->enc_id);
  2480. goto end;
  2481. } else {
  2482. if (test_only && RM_RQ_LOCK(&reqs))
  2483. SDE_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n",
  2484. rsvp_nxt->seq, rsvp_nxt->enc_id);
  2485. }
  2486. commit_rsvp:
  2487. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  2488. _sde_rm_commit_rsvp(rm, rsvp_nxt, conn_state);
  2489. _sde_rm_populate_dp_lm_mask(rm, conn_state->connector);
  2490. end:
  2491. kfree(comp_info);
  2492. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_FINAL);
  2493. mutex_unlock(&rm->rm_lock);
  2494. return ret;
  2495. }