sde_rm.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258
  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_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. const struct sde_rm_topology_def *top,
  1050. u8 *_dsc_ids)
  1051. {
  1052. struct sde_rm_hw_iter iter_i, iter_j;
  1053. struct sde_rm_hw_blk *dsc[MAX_BLOCKS];
  1054. int alloc_count = 0;
  1055. int num_dsc_enc = top->num_comp_enc;
  1056. int i;
  1057. if (!top->num_comp_enc)
  1058. return 0;
  1059. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_DSC);
  1060. /* Find a first DSC */
  1061. while (alloc_count != num_dsc_enc &&
  1062. _sde_rm_get_hw_locked(rm, &iter_i)) {
  1063. memset(&dsc, 0, sizeof(dsc));
  1064. alloc_count = 0;
  1065. if (_dsc_ids && (iter_i.blk->id != _dsc_ids[alloc_count]))
  1066. continue;
  1067. if (!_sde_rm_check_dsc(rm, rsvp, iter_i.blk, NULL))
  1068. continue;
  1069. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  1070. iter_i.blk->id,
  1071. alloc_count,
  1072. _dsc_ids ? _dsc_ids[alloc_count] : -1);
  1073. dsc[alloc_count++] = iter_i.blk;
  1074. /* Valid first dsc found, find matching peers */
  1075. sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_DSC);
  1076. while (alloc_count != num_dsc_enc &&
  1077. _sde_rm_get_hw_locked(rm, &iter_j)) {
  1078. if (iter_i.blk == iter_j.blk)
  1079. continue;
  1080. if (_dsc_ids && (iter_j.blk->id !=
  1081. _dsc_ids[alloc_count]))
  1082. continue;
  1083. if (!_sde_rm_check_dsc(rm, rsvp,
  1084. iter_j.blk, iter_i.blk))
  1085. continue;
  1086. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  1087. iter_j.blk->id,
  1088. alloc_count,
  1089. _dsc_ids ? _dsc_ids[alloc_count] : -1);
  1090. dsc[alloc_count++] = iter_j.blk;
  1091. }
  1092. }
  1093. if (alloc_count != num_dsc_enc) {
  1094. SDE_ERROR("couldn't reserve %d dsc blocks for enc id %d\n",
  1095. num_dsc_enc, rsvp->enc_id);
  1096. return -EINVAL;
  1097. }
  1098. for (i = 0; i < ARRAY_SIZE(dsc); i++) {
  1099. if (!dsc[i])
  1100. break;
  1101. dsc[i]->rsvp_nxt = rsvp;
  1102. SDE_EVT32(dsc[i]->type, rsvp->enc_id, dsc[i]->id);
  1103. }
  1104. return 0;
  1105. }
  1106. static int _sde_rm_reserve_qdss(
  1107. struct sde_rm *rm,
  1108. struct sde_rm_rsvp *rsvp,
  1109. const struct sde_rm_topology_def *top,
  1110. u8 *_qdss_ids)
  1111. {
  1112. struct sde_rm_hw_iter iter;
  1113. struct msm_drm_private *priv = rm->dev->dev_private;
  1114. struct sde_kms *sde_kms;
  1115. if (!priv->kms) {
  1116. SDE_ERROR("invalid kms\n");
  1117. return -EINVAL;
  1118. }
  1119. sde_kms = to_sde_kms(priv->kms);
  1120. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_QDSS);
  1121. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1122. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1123. continue;
  1124. SDE_DEBUG("blk id = %d\n", iter.blk->id);
  1125. iter.blk->rsvp_nxt = rsvp;
  1126. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1127. return 0;
  1128. }
  1129. if (!iter.hw && sde_kms->catalog->qdss_count) {
  1130. SDE_DEBUG("couldn't reserve qdss for type %d id %d\n",
  1131. SDE_HW_BLK_QDSS, iter.blk->id);
  1132. return -ENAVAIL;
  1133. }
  1134. return 0;
  1135. }
  1136. static int _sde_rm_reserve_cdm(
  1137. struct sde_rm *rm,
  1138. struct sde_rm_rsvp *rsvp,
  1139. uint32_t id,
  1140. enum sde_hw_blk_type type)
  1141. {
  1142. struct sde_rm_hw_iter iter;
  1143. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CDM);
  1144. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1145. const struct sde_hw_cdm *cdm = to_sde_hw_cdm(iter.blk->hw);
  1146. const struct sde_cdm_cfg *caps = cdm->caps;
  1147. bool match = false;
  1148. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  1149. continue;
  1150. if (type == SDE_HW_BLK_INTF && id != INTF_MAX)
  1151. match = test_bit(id, &caps->intf_connect);
  1152. else if (type == SDE_HW_BLK_WB && id != WB_MAX)
  1153. match = test_bit(id, &caps->wb_connect);
  1154. SDE_DEBUG("type %d id %d, cdm intfs %lu wbs %lu match %d\n",
  1155. type, id, caps->intf_connect, caps->wb_connect,
  1156. match);
  1157. if (!match)
  1158. continue;
  1159. iter.blk->rsvp_nxt = rsvp;
  1160. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1161. break;
  1162. }
  1163. if (!iter.hw) {
  1164. SDE_ERROR("couldn't reserve cdm for type %d id %d\n", type, id);
  1165. return -ENAVAIL;
  1166. }
  1167. return 0;
  1168. }
  1169. static int _sde_rm_reserve_intf_or_wb(
  1170. struct sde_rm *rm,
  1171. struct sde_rm_rsvp *rsvp,
  1172. uint32_t id,
  1173. enum sde_hw_blk_type type,
  1174. bool needs_cdm)
  1175. {
  1176. struct sde_rm_hw_iter iter;
  1177. int ret = 0;
  1178. /* Find the block entry in the rm, and note the reservation */
  1179. sde_rm_init_hw_iter(&iter, 0, type);
  1180. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1181. if (iter.blk->id != id)
  1182. continue;
  1183. if (RESERVED_BY_OTHER(iter.blk, rsvp)) {
  1184. SDE_ERROR("type %d id %d already reserved\n", type, id);
  1185. return -ENAVAIL;
  1186. }
  1187. iter.blk->rsvp_nxt = rsvp;
  1188. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1189. break;
  1190. }
  1191. /* Shouldn't happen since wbs / intfs are fixed at probe */
  1192. if (!iter.hw) {
  1193. SDE_ERROR("couldn't find type %d id %d\n", type, id);
  1194. return -EINVAL;
  1195. }
  1196. /* Expected only one intf or wb will request cdm */
  1197. if (needs_cdm)
  1198. ret = _sde_rm_reserve_cdm(rm, rsvp, id, type);
  1199. return ret;
  1200. }
  1201. static int _sde_rm_reserve_intf_related_hw(
  1202. struct sde_rm *rm,
  1203. struct sde_rm_rsvp *rsvp,
  1204. struct sde_encoder_hw_resources *hw_res)
  1205. {
  1206. int i, ret = 0;
  1207. u32 id;
  1208. for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) {
  1209. if (hw_res->intfs[i] == INTF_MODE_NONE)
  1210. continue;
  1211. id = i + INTF_0;
  1212. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id,
  1213. SDE_HW_BLK_INTF, hw_res->needs_cdm);
  1214. if (ret)
  1215. return ret;
  1216. }
  1217. for (i = 0; i < ARRAY_SIZE(hw_res->wbs); i++) {
  1218. if (hw_res->wbs[i] == INTF_MODE_NONE)
  1219. continue;
  1220. id = i + WB_0;
  1221. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id,
  1222. SDE_HW_BLK_WB, hw_res->needs_cdm);
  1223. if (ret)
  1224. return ret;
  1225. }
  1226. return ret;
  1227. }
  1228. static bool _sde_rm_is_display_in_cont_splash(struct sde_kms *sde_kms,
  1229. struct drm_encoder *enc)
  1230. {
  1231. int i;
  1232. struct sde_splash_display *splash_dpy;
  1233. for (i = 0; i < MAX_DSI_DISPLAYS; i++) {
  1234. splash_dpy = &sde_kms->splash_data.splash_display[i];
  1235. if (splash_dpy->encoder == enc)
  1236. return splash_dpy->cont_splash_enabled;
  1237. }
  1238. return false;
  1239. }
  1240. static int _sde_rm_make_lm_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1241. struct sde_rm_requirements *reqs,
  1242. struct sde_splash_display *splash_display)
  1243. {
  1244. int ret, i;
  1245. u8 *hw_ids = NULL;
  1246. /* Check if splash data provided lm_ids */
  1247. if (splash_display) {
  1248. hw_ids = splash_display->lm_ids;
  1249. for (i = 0; i < splash_display->lm_cnt; i++)
  1250. SDE_DEBUG("splash_display->lm_ids[%d] = %d\n",
  1251. i, splash_display->lm_ids[i]);
  1252. if (splash_display->lm_cnt != reqs->topology->num_lm)
  1253. SDE_DEBUG("Configured splash LMs != needed LM cnt\n");
  1254. }
  1255. /*
  1256. * Assign LMs and blocks whose usage is tied to them:
  1257. * DSPP & Pingpong.
  1258. */
  1259. ret = _sde_rm_reserve_lms(rm, rsvp, reqs, hw_ids);
  1260. return ret;
  1261. }
  1262. static int _sde_rm_make_ctl_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1263. struct sde_rm_requirements *reqs,
  1264. struct sde_splash_display *splash_display)
  1265. {
  1266. int ret, i;
  1267. u8 *hw_ids = NULL;
  1268. struct sde_rm_topology_def topology;
  1269. /* Check if splash data provided ctl_ids */
  1270. if (splash_display) {
  1271. hw_ids = splash_display->ctl_ids;
  1272. for (i = 0; i < splash_display->ctl_cnt; i++)
  1273. SDE_DEBUG("splash_display->ctl_ids[%d] = %d\n",
  1274. i, splash_display->ctl_ids[i]);
  1275. }
  1276. /*
  1277. * Do assignment preferring to give away low-resource CTLs first:
  1278. * - Check mixers without Split Display
  1279. * - Only then allow to grab from CTLs with split display capability
  1280. */
  1281. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, hw_ids);
  1282. if (ret && !reqs->topology->needs_split_display &&
  1283. reqs->topology->num_ctl > SINGLE_CTL) {
  1284. memcpy(&topology, reqs->topology, sizeof(topology));
  1285. topology.needs_split_display = true;
  1286. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, hw_ids);
  1287. }
  1288. return ret;
  1289. }
  1290. static int _sde_rm_make_dsc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1291. struct sde_rm_requirements *reqs,
  1292. struct sde_splash_display *splash_display)
  1293. {
  1294. int ret, i;
  1295. u8 *hw_ids = NULL;
  1296. /* Check if splash data provided dsc_ids */
  1297. if (splash_display) {
  1298. hw_ids = splash_display->dsc_ids;
  1299. for (i = 0; i < splash_display->dsc_cnt; i++)
  1300. SDE_DEBUG("splash_data.dsc_ids[%d] = %d\n",
  1301. i, splash_display->dsc_ids[i]);
  1302. }
  1303. ret = _sde_rm_reserve_dsc(rm, rsvp, reqs->topology, hw_ids);
  1304. return ret;
  1305. }
  1306. static int _sde_rm_make_next_rsvp(struct sde_rm *rm, struct drm_encoder *enc,
  1307. struct drm_crtc_state *crtc_state,
  1308. struct drm_connector_state *conn_state,
  1309. struct sde_rm_rsvp *rsvp,
  1310. struct sde_rm_requirements *reqs)
  1311. {
  1312. struct msm_drm_private *priv;
  1313. struct sde_kms *sde_kms;
  1314. struct sde_splash_display *splash_display = NULL;
  1315. struct sde_splash_data *splash_data;
  1316. int i, ret;
  1317. priv = enc->dev->dev_private;
  1318. sde_kms = to_sde_kms(priv->kms);
  1319. splash_data = &sde_kms->splash_data;
  1320. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  1321. for (i = 0; i < ARRAY_SIZE(splash_data->splash_display); i++) {
  1322. if (enc == splash_data->splash_display[i].encoder)
  1323. splash_display =
  1324. &splash_data->splash_display[i];
  1325. }
  1326. if (!splash_display) {
  1327. SDE_ERROR("rm is in cont_splash but data not found\n");
  1328. return -EINVAL;
  1329. }
  1330. }
  1331. /* Create reservation info, tag reserved blocks with it as we go */
  1332. rsvp->seq = ++rm->rsvp_next_seq;
  1333. rsvp->enc_id = enc->base.id;
  1334. rsvp->topology = reqs->topology->top_name;
  1335. list_add_tail(&rsvp->list, &rm->rsvps);
  1336. ret = _sde_rm_make_lm_rsvp(rm, rsvp, reqs, splash_display);
  1337. if (ret) {
  1338. SDE_ERROR("unable to find appropriate mixers\n");
  1339. _sde_rm_print_rsvps_by_type(rm, SDE_HW_BLK_LM);
  1340. return ret;
  1341. }
  1342. ret = _sde_rm_make_ctl_rsvp(rm, rsvp, reqs, splash_display);
  1343. if (ret) {
  1344. SDE_ERROR("unable to find appropriate CTL\n");
  1345. return ret;
  1346. }
  1347. /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */
  1348. ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, &reqs->hw_res);
  1349. if (ret)
  1350. return ret;
  1351. ret = _sde_rm_make_dsc_rsvp(rm, rsvp, reqs, splash_display);
  1352. if (ret)
  1353. return ret;
  1354. ret = _sde_rm_reserve_qdss(rm, rsvp, reqs->topology, NULL);
  1355. if (ret)
  1356. return ret;
  1357. return ret;
  1358. }
  1359. /**
  1360. * _sde_rm_get_hw_blk_for_cont_splash - retrieve the LM blocks on given CTL
  1361. * and populate the connected HW blk ids in sde_splash_display
  1362. * @rm: Pointer to resource manager structure
  1363. * @ctl: Pointer to CTL hardware block
  1364. * @splash_display: Pointer to struct sde_splash_display
  1365. * return: number of active LM blocks for this CTL block
  1366. */
  1367. static int _sde_rm_get_hw_blk_for_cont_splash(struct sde_rm *rm,
  1368. struct sde_hw_ctl *ctl,
  1369. struct sde_splash_display *splash_display)
  1370. {
  1371. u32 lm_reg;
  1372. struct sde_rm_hw_iter iter_lm, iter_pp;
  1373. struct sde_hw_pingpong *pp;
  1374. if (!rm || !ctl || !splash_display) {
  1375. SDE_ERROR("invalid input parameters\n");
  1376. return 0;
  1377. }
  1378. sde_rm_init_hw_iter(&iter_lm, 0, SDE_HW_BLK_LM);
  1379. sde_rm_init_hw_iter(&iter_pp, 0, SDE_HW_BLK_PINGPONG);
  1380. while (_sde_rm_get_hw_locked(rm, &iter_lm)) {
  1381. _sde_rm_get_hw_locked(rm, &iter_pp);
  1382. if (splash_display->lm_cnt >= MAX_DATA_PATH_PER_DSIPLAY)
  1383. break;
  1384. lm_reg = ctl->ops.read_ctl_layers(ctl, iter_lm.blk->id);
  1385. if (!lm_reg)
  1386. continue;
  1387. splash_display->lm_ids[splash_display->lm_cnt++] =
  1388. iter_lm.blk->id;
  1389. SDE_DEBUG("lm_cnt=%d lm_reg[%d]=0x%x\n", splash_display->lm_cnt,
  1390. iter_lm.blk->id - LM_0, lm_reg);
  1391. if (ctl->ops.get_staged_sspp &&
  1392. ctl->ops.get_staged_sspp(ctl, iter_lm.blk->id,
  1393. &splash_display->pipes[
  1394. splash_display->pipe_cnt], 1)) {
  1395. splash_display->pipe_cnt++;
  1396. } else {
  1397. SDE_ERROR("no pipe detected on LM-%d\n",
  1398. iter_lm.blk->id - LM_0);
  1399. return 0;
  1400. }
  1401. pp = to_sde_hw_pingpong(iter_pp.blk->hw);
  1402. if (pp && pp->ops.get_dsc_status &&
  1403. pp->ops.get_dsc_status(pp)) {
  1404. splash_display->dsc_ids[splash_display->dsc_cnt++] =
  1405. iter_pp.blk->id;
  1406. SDE_DEBUG("lm/pp[%d] path, using dsc[%d]\n",
  1407. iter_lm.blk->id - LM_0,
  1408. iter_pp.blk->id - DSC_0);
  1409. }
  1410. }
  1411. return splash_display->lm_cnt;
  1412. }
  1413. int sde_rm_cont_splash_res_init(struct msm_drm_private *priv,
  1414. struct sde_rm *rm,
  1415. struct sde_splash_data *splash_data,
  1416. struct sde_mdss_cfg *cat)
  1417. {
  1418. struct sde_rm_hw_iter iter_c;
  1419. int index = 0, ctl_top_cnt;
  1420. struct sde_kms *sde_kms = NULL;
  1421. struct sde_hw_mdp *hw_mdp;
  1422. struct sde_splash_display *splash_display;
  1423. u8 intf_sel;
  1424. if (!priv || !rm || !cat || !splash_data) {
  1425. SDE_ERROR("invalid input parameters\n");
  1426. return -EINVAL;
  1427. }
  1428. SDE_DEBUG("mixer_count=%d, ctl_count=%d, dsc_count=%d\n",
  1429. cat->mixer_count,
  1430. cat->ctl_count,
  1431. cat->dsc_count);
  1432. ctl_top_cnt = cat->ctl_count;
  1433. if (!priv->kms) {
  1434. SDE_ERROR("invalid kms\n");
  1435. return -EINVAL;
  1436. }
  1437. sde_kms = to_sde_kms(priv->kms);
  1438. hw_mdp = sde_rm_get_mdp(rm);
  1439. sde_rm_init_hw_iter(&iter_c, 0, SDE_HW_BLK_CTL);
  1440. while (_sde_rm_get_hw_locked(rm, &iter_c)
  1441. && (index < splash_data->num_splash_displays)) {
  1442. struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter_c.blk->hw);
  1443. if (!ctl->ops.get_ctl_intf) {
  1444. SDE_ERROR("get_ctl_intf not initialized\n");
  1445. return -EINVAL;
  1446. }
  1447. intf_sel = ctl->ops.get_ctl_intf(ctl);
  1448. if (intf_sel) {
  1449. splash_display = &splash_data->splash_display[index];
  1450. SDE_DEBUG("finding resources for display=%d ctl=%d\n",
  1451. index, iter_c.blk->id - CTL_0);
  1452. _sde_rm_get_hw_blk_for_cont_splash(rm,
  1453. ctl, splash_display);
  1454. splash_display->cont_splash_enabled = true;
  1455. splash_display->ctl_ids[splash_display->ctl_cnt++] =
  1456. iter_c.blk->id;
  1457. index++;
  1458. }
  1459. }
  1460. return 0;
  1461. }
  1462. static int _sde_rm_populate_requirements(
  1463. struct sde_rm *rm,
  1464. struct drm_encoder *enc,
  1465. struct drm_crtc_state *crtc_state,
  1466. struct drm_connector_state *conn_state,
  1467. struct sde_rm_requirements *reqs)
  1468. {
  1469. const struct drm_display_mode *mode = &crtc_state->mode;
  1470. int i;
  1471. memset(reqs, 0, sizeof(*reqs));
  1472. reqs->top_ctrl = sde_connector_get_property(conn_state,
  1473. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  1474. sde_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state);
  1475. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) {
  1476. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
  1477. reqs->hw_res.topology)) {
  1478. reqs->topology = &rm->topology_tbl[i];
  1479. break;
  1480. }
  1481. }
  1482. if (!reqs->topology) {
  1483. SDE_ERROR("invalid topology for the display\n");
  1484. return -EINVAL;
  1485. }
  1486. /*
  1487. * select dspp HW block for all dsi displays and ds for only
  1488. * primary dsi display.
  1489. */
  1490. if (conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI) {
  1491. if (!RM_RQ_DSPP(reqs))
  1492. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP);
  1493. if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler &&
  1494. sde_encoder_is_primary_display(enc))
  1495. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DS);
  1496. }
  1497. /**
  1498. * Set the requirement for LM which has CWB support if CWB is
  1499. * found enabled.
  1500. */
  1501. if (!RM_RQ_CWB(reqs) && sde_encoder_in_clone_mode(enc)) {
  1502. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_CWB);
  1503. /*
  1504. * topology selection based on conn mode is not valid for CWB
  1505. * as WB conn populates modes based on max_mixer_width check
  1506. * but primary can be using dual LMs. This topology override for
  1507. * CWB is to check number of datapath active in primary and
  1508. * allocate same number of LM/PP blocks reserved for CWB
  1509. */
  1510. reqs->topology =
  1511. &rm->topology_tbl[SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE];
  1512. if (sde_crtc_get_num_datapath(crtc_state->crtc) == 1)
  1513. reqs->topology =
  1514. &rm->topology_tbl[SDE_RM_TOPOLOGY_SINGLEPIPE];
  1515. }
  1516. SDE_DEBUG("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl,
  1517. reqs->hw_res.display_num_of_h_tiles);
  1518. SDE_DEBUG("num_lm: %d num_ctl: %d topology: %d split_display: %d\n",
  1519. reqs->topology->num_lm, reqs->topology->num_ctl,
  1520. reqs->topology->top_name,
  1521. reqs->topology->needs_split_display);
  1522. SDE_EVT32(mode->hdisplay, rm->lm_max_width, reqs->topology->num_lm,
  1523. reqs->top_ctrl, reqs->topology->top_name,
  1524. reqs->topology->num_ctl);
  1525. return 0;
  1526. }
  1527. static struct sde_rm_rsvp *_sde_rm_get_rsvp(
  1528. struct sde_rm *rm,
  1529. struct drm_encoder *enc)
  1530. {
  1531. struct sde_rm_rsvp *i;
  1532. if (!rm || !enc) {
  1533. SDE_ERROR("invalid params\n");
  1534. return NULL;
  1535. }
  1536. if (list_empty(&rm->rsvps))
  1537. return NULL;
  1538. list_for_each_entry(i, &rm->rsvps, list)
  1539. if (i->enc_id == enc->base.id)
  1540. return i;
  1541. return NULL;
  1542. }
  1543. static struct sde_rm_rsvp *_sde_rm_get_rsvp_nxt(
  1544. struct sde_rm *rm,
  1545. struct drm_encoder *enc)
  1546. {
  1547. struct sde_rm_rsvp *i;
  1548. if (list_empty(&rm->rsvps))
  1549. return NULL;
  1550. list_for_each_entry(i, &rm->rsvps, list)
  1551. if (i->enc_id == enc->base.id)
  1552. break;
  1553. list_for_each_entry_continue(i, &rm->rsvps, list)
  1554. if (i->enc_id == enc->base.id)
  1555. return i;
  1556. return NULL;
  1557. }
  1558. static struct drm_connector *_sde_rm_get_connector(
  1559. struct drm_encoder *enc)
  1560. {
  1561. struct drm_connector *conn = NULL;
  1562. struct list_head *connector_list =
  1563. &enc->dev->mode_config.connector_list;
  1564. list_for_each_entry(conn, connector_list, head)
  1565. if (conn->encoder == enc)
  1566. return conn;
  1567. return NULL;
  1568. }
  1569. int sde_rm_update_topology(struct drm_connector_state *conn_state,
  1570. struct msm_display_topology *topology)
  1571. {
  1572. int i, ret = 0;
  1573. struct msm_display_topology top;
  1574. enum sde_rm_topology_name top_name = SDE_RM_TOPOLOGY_NONE;
  1575. if (!conn_state)
  1576. return -EINVAL;
  1577. if (topology) {
  1578. top = *topology;
  1579. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
  1580. if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], top)) {
  1581. top_name = g_top_table[i].top_name;
  1582. break;
  1583. }
  1584. }
  1585. ret = msm_property_set_property(
  1586. sde_connector_get_propinfo(conn_state->connector),
  1587. sde_connector_get_property_state(conn_state),
  1588. CONNECTOR_PROP_TOPOLOGY_NAME, top_name);
  1589. return ret;
  1590. }
  1591. /**
  1592. * _sde_rm_release_rsvp - release resources and release a reservation
  1593. * @rm: KMS handle
  1594. * @rsvp: RSVP pointer to release and release resources for
  1595. */
  1596. static void _sde_rm_release_rsvp(
  1597. struct sde_rm *rm,
  1598. struct sde_rm_rsvp *rsvp,
  1599. struct drm_connector *conn)
  1600. {
  1601. struct sde_rm_rsvp *rsvp_c, *rsvp_n;
  1602. struct sde_rm_hw_blk *blk;
  1603. enum sde_hw_blk_type type;
  1604. if (!rsvp)
  1605. return;
  1606. SDE_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id);
  1607. list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) {
  1608. if (rsvp == rsvp_c) {
  1609. list_del(&rsvp_c->list);
  1610. break;
  1611. }
  1612. }
  1613. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  1614. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  1615. if (blk->rsvp == rsvp) {
  1616. blk->rsvp = NULL;
  1617. SDE_DEBUG("rel rsvp %d enc %d %d %d\n",
  1618. rsvp->seq, rsvp->enc_id,
  1619. blk->type, blk->id);
  1620. _sde_rm_inc_resource_info(rm,
  1621. &rm->avail_res, blk);
  1622. }
  1623. if (blk->rsvp_nxt == rsvp) {
  1624. blk->rsvp_nxt = NULL;
  1625. SDE_DEBUG("rel rsvp_nxt %d enc %d %d %d\n",
  1626. rsvp->seq, rsvp->enc_id,
  1627. blk->type, blk->id);
  1628. }
  1629. }
  1630. }
  1631. kfree(rsvp);
  1632. }
  1633. void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
  1634. {
  1635. struct sde_rm_rsvp *rsvp;
  1636. struct drm_connector *conn;
  1637. struct msm_drm_private *priv;
  1638. struct sde_kms *sde_kms;
  1639. uint64_t top_ctrl;
  1640. if (!rm || !enc) {
  1641. SDE_ERROR("invalid params\n");
  1642. return;
  1643. }
  1644. priv = enc->dev->dev_private;
  1645. if (!priv->kms) {
  1646. SDE_ERROR("invalid kms\n");
  1647. return;
  1648. }
  1649. sde_kms = to_sde_kms(priv->kms);
  1650. mutex_lock(&rm->rm_lock);
  1651. if (nxt)
  1652. rsvp = _sde_rm_get_rsvp_nxt(rm, enc);
  1653. else
  1654. rsvp = _sde_rm_get_rsvp(rm, enc);
  1655. if (!rsvp) {
  1656. SDE_DEBUG("failed to find rsvp for enc %d, nxt %d",
  1657. enc->base.id, nxt);
  1658. goto end;
  1659. }
  1660. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  1661. _sde_rm_release_rsvp(rm, rsvp, conn);
  1662. goto end;
  1663. }
  1664. conn = _sde_rm_get_connector(enc);
  1665. if (!conn) {
  1666. SDE_ERROR("failed to get connector for enc %d, nxt %d",
  1667. enc->base.id, nxt);
  1668. goto end;
  1669. }
  1670. top_ctrl = sde_connector_get_property(conn->state,
  1671. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  1672. if (top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) {
  1673. SDE_DEBUG("rsvp[s%de%d] not releasing locked resources\n",
  1674. rsvp->seq, rsvp->enc_id);
  1675. } else {
  1676. SDE_DEBUG("release rsvp[s%de%d]\n", rsvp->seq,
  1677. rsvp->enc_id);
  1678. _sde_rm_release_rsvp(rm, rsvp, conn);
  1679. }
  1680. end:
  1681. mutex_unlock(&rm->rm_lock);
  1682. }
  1683. static int _sde_rm_commit_rsvp(
  1684. struct sde_rm *rm,
  1685. struct sde_rm_rsvp *rsvp,
  1686. struct drm_connector_state *conn_state)
  1687. {
  1688. struct sde_rm_hw_blk *blk;
  1689. enum sde_hw_blk_type type;
  1690. int ret = 0;
  1691. /* Swap next rsvp to be the active */
  1692. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  1693. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  1694. if (blk->rsvp_nxt) {
  1695. blk->rsvp = blk->rsvp_nxt;
  1696. blk->rsvp_nxt = NULL;
  1697. _sde_rm_dec_resource_info(rm,
  1698. &rm->avail_res, blk);
  1699. }
  1700. }
  1701. }
  1702. if (!ret) {
  1703. SDE_DEBUG("rsrv enc %d topology %d\n", rsvp->enc_id,
  1704. rsvp->topology);
  1705. SDE_EVT32(rsvp->enc_id, rsvp->topology);
  1706. }
  1707. return ret;
  1708. }
  1709. int sde_rm_reserve(
  1710. struct sde_rm *rm,
  1711. struct drm_encoder *enc,
  1712. struct drm_crtc_state *crtc_state,
  1713. struct drm_connector_state *conn_state,
  1714. bool test_only)
  1715. {
  1716. struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
  1717. struct sde_rm_requirements reqs;
  1718. struct msm_drm_private *priv;
  1719. struct sde_kms *sde_kms;
  1720. int ret;
  1721. if (!rm || !enc || !crtc_state || !conn_state) {
  1722. SDE_ERROR("invalid arguments\n");
  1723. return -EINVAL;
  1724. }
  1725. if (!enc->dev || !enc->dev->dev_private) {
  1726. SDE_ERROR("drm device invalid\n");
  1727. return -EINVAL;
  1728. }
  1729. priv = enc->dev->dev_private;
  1730. if (!priv->kms) {
  1731. SDE_ERROR("invalid kms\n");
  1732. return -EINVAL;
  1733. }
  1734. sde_kms = to_sde_kms(priv->kms);
  1735. /* Check if this is just a page-flip */
  1736. if (!_sde_rm_is_display_in_cont_splash(sde_kms, enc) &&
  1737. !drm_atomic_crtc_needs_modeset(crtc_state))
  1738. return 0;
  1739. SDE_DEBUG("reserving hw for conn %d enc %d crtc %d test_only %d\n",
  1740. conn_state->connector->base.id, enc->base.id,
  1741. crtc_state->crtc->base.id, test_only);
  1742. SDE_EVT32(enc->base.id, conn_state->connector->base.id);
  1743. mutex_lock(&rm->rm_lock);
  1744. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_BEGIN);
  1745. rsvp_cur = _sde_rm_get_rsvp(rm, enc);
  1746. rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
  1747. if (!test_only && rsvp_nxt)
  1748. goto commit_rsvp;
  1749. ret = _sde_rm_populate_requirements(rm, enc, crtc_state,
  1750. conn_state, &reqs);
  1751. if (ret) {
  1752. SDE_ERROR("failed to populate hw requirements\n");
  1753. goto end;
  1754. }
  1755. /*
  1756. * We only support one active reservation per-hw-block. But to implement
  1757. * transactional semantics for test-only, and for allowing failure while
  1758. * modifying your existing reservation, over the course of this
  1759. * function we can have two reservations:
  1760. * Current: Existing reservation
  1761. * Next: Proposed reservation. The proposed reservation may fail, or may
  1762. * be discarded if in test-only mode.
  1763. * If reservation is successful, and we're not in test-only, then we
  1764. * replace the current with the next.
  1765. */
  1766. rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL);
  1767. if (!rsvp_nxt) {
  1768. ret = -ENOMEM;
  1769. goto end;
  1770. }
  1771. /*
  1772. * User can request that we clear out any reservation during the
  1773. * atomic_check phase by using this CLEAR bit
  1774. */
  1775. if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) {
  1776. SDE_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n",
  1777. rsvp_cur->seq, rsvp_cur->enc_id);
  1778. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  1779. rsvp_cur = NULL;
  1780. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_CLEAR);
  1781. }
  1782. /* Check the proposed reservation, store it in hw's "next" field */
  1783. ret = _sde_rm_make_next_rsvp(rm, enc, crtc_state, conn_state,
  1784. rsvp_nxt, &reqs);
  1785. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_RSVPNEXT);
  1786. if (ret) {
  1787. SDE_ERROR("failed to reserve hw resources: %d, test_only %d\n",
  1788. ret, test_only);
  1789. _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
  1790. goto end;
  1791. } else if (test_only && !RM_RQ_LOCK(&reqs)) {
  1792. /*
  1793. * Normally, if test_only, test the reservation and then undo
  1794. * However, if the user requests LOCK, then keep the reservation
  1795. * made during the atomic_check phase.
  1796. */
  1797. SDE_DEBUG("test_only: rsvp[s%de%d]\n",
  1798. rsvp_nxt->seq, rsvp_nxt->enc_id);
  1799. goto end;
  1800. } else {
  1801. if (test_only && RM_RQ_LOCK(&reqs))
  1802. SDE_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n",
  1803. rsvp_nxt->seq, rsvp_nxt->enc_id);
  1804. }
  1805. commit_rsvp:
  1806. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  1807. ret = _sde_rm_commit_rsvp(rm, rsvp_nxt, conn_state);
  1808. end:
  1809. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_FINAL);
  1810. mutex_unlock(&rm->rm_lock);
  1811. return ret;
  1812. }
  1813. int sde_rm_ext_blk_create_reserve(struct sde_rm *rm,
  1814. struct sde_hw_blk *hw, struct drm_encoder *enc)
  1815. {
  1816. struct sde_rm_hw_blk *blk;
  1817. struct sde_rm_rsvp *rsvp;
  1818. int ret = 0;
  1819. if (!rm || !hw || !enc) {
  1820. SDE_ERROR("invalid parameters\n");
  1821. return -EINVAL;
  1822. }
  1823. if (hw->type >= SDE_HW_BLK_MAX) {
  1824. SDE_ERROR("invalid HW type\n");
  1825. return -EINVAL;
  1826. }
  1827. mutex_lock(&rm->rm_lock);
  1828. rsvp = _sde_rm_get_rsvp(rm, enc);
  1829. if (!rsvp) {
  1830. rsvp = kzalloc(sizeof(*rsvp), GFP_KERNEL);
  1831. if (!rsvp) {
  1832. ret = -ENOMEM;
  1833. goto end;
  1834. }
  1835. rsvp->seq = ++rm->rsvp_next_seq;
  1836. rsvp->enc_id = enc->base.id;
  1837. list_add_tail(&rsvp->list, &rm->rsvps);
  1838. SDE_DEBUG("create rsvp %d for enc %d\n",
  1839. rsvp->seq, rsvp->enc_id);
  1840. }
  1841. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  1842. if (!blk) {
  1843. ret = -ENOMEM;
  1844. goto end;
  1845. }
  1846. blk->type = hw->type;
  1847. blk->id = hw->id;
  1848. blk->hw = hw;
  1849. blk->rsvp = rsvp;
  1850. list_add_tail(&blk->list, &rm->hw_blks[hw->type]);
  1851. SDE_DEBUG("create blk %d %d for rsvp %d enc %d\n", blk->type, blk->id,
  1852. rsvp->seq, rsvp->enc_id);
  1853. end:
  1854. mutex_unlock(&rm->rm_lock);
  1855. return ret;
  1856. }
  1857. int sde_rm_ext_blk_destroy(struct sde_rm *rm,
  1858. struct drm_encoder *enc)
  1859. {
  1860. struct sde_rm_hw_blk *blk = NULL, *p;
  1861. struct sde_rm_rsvp *rsvp;
  1862. enum sde_hw_blk_type type;
  1863. int ret = 0;
  1864. if (!rm || !enc) {
  1865. SDE_ERROR("invalid parameters\n");
  1866. return -EINVAL;
  1867. }
  1868. mutex_lock(&rm->rm_lock);
  1869. rsvp = _sde_rm_get_rsvp(rm, enc);
  1870. if (!rsvp) {
  1871. ret = -ENOENT;
  1872. SDE_ERROR("failed to find rsvp for enc %d\n", enc->base.id);
  1873. goto end;
  1874. }
  1875. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  1876. list_for_each_entry_safe(blk, p, &rm->hw_blks[type], list) {
  1877. if (blk->rsvp == rsvp) {
  1878. list_del(&blk->list);
  1879. SDE_DEBUG("del blk %d %d from rsvp %d enc %d\n",
  1880. blk->type, blk->id,
  1881. rsvp->seq, rsvp->enc_id);
  1882. kfree(blk);
  1883. }
  1884. }
  1885. }
  1886. SDE_DEBUG("del rsvp %d\n", rsvp->seq);
  1887. list_del(&rsvp->list);
  1888. kfree(rsvp);
  1889. end:
  1890. mutex_unlock(&rm->rm_lock);
  1891. return ret;
  1892. }