sde_rm.c 51 KB

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