sde_rm.c 75 KB

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