sde_rm.c 75 KB

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