sde_rm.c 78 KB

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