sde_rm.c 69 KB

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