sde_rm.c 74 KB

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