sde_rm.c 64 KB

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