sde_rm.c 72 KB

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