sde_rm.c 70 KB

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