sde_rm.c 74 KB

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