sde_rm.c 68 KB

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