sde_rm.c 68 KB

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