sde_rm.c 62 KB

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