sde_rm.c 57 KB

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