sde_rm.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2019, 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_crtc.h"
  19. #include "sde_hw_qdss.h"
  20. #define RESERVED_BY_OTHER(h, r) \
  21. (((h)->rsvp && ((h)->rsvp->enc_id != (r)->enc_id)) ||\
  22. ((h)->rsvp_nxt && ((h)->rsvp_nxt->enc_id != (r)->enc_id)))
  23. #define RM_RQ_LOCK(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK))
  24. #define RM_RQ_CLEAR(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_CLEAR))
  25. #define RM_RQ_DSPP(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DSPP))
  26. #define RM_RQ_DS(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DS))
  27. #define RM_RQ_CWB(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_CWB))
  28. #define RM_IS_TOPOLOGY_MATCH(t, r) ((t).num_lm == (r).num_lm && \
  29. (t).num_comp_enc == (r).num_enc && \
  30. (t).num_intf == (r).num_intf)
  31. /**
  32. * toplogy information to be used when ctl path version does not
  33. * support driving more than one interface per ctl_path
  34. */
  35. static const struct sde_rm_topology_def g_top_table[] = {
  36. { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false },
  37. { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false },
  38. { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false },
  39. { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 2, true },
  40. { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 2, true },
  41. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false },
  42. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false },
  43. { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false },
  44. { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, true },
  45. };
  46. /**
  47. * topology information to be used when the ctl path version
  48. * is SDE_CTL_CFG_VERSION_1_0_0
  49. */
  50. static const struct sde_rm_topology_def g_ctl_ver_1_top_table[] = {
  51. { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false },
  52. { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false },
  53. { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false },
  54. { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 1, true },
  55. { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 1, true },
  56. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false },
  57. { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false },
  58. { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false },
  59. { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, true },
  60. };
  61. /**
  62. * struct sde_rm_requirements - Reservation requirements parameter bundle
  63. * @top_ctrl: topology control preference from kernel client
  64. * @top: selected topology for the display
  65. * @hw_res: Hardware resources required as reported by the encoders
  66. */
  67. struct sde_rm_requirements {
  68. uint64_t top_ctrl;
  69. const struct sde_rm_topology_def *topology;
  70. struct sde_encoder_hw_resources hw_res;
  71. };
  72. /**
  73. * struct sde_rm_rsvp - Use Case Reservation tagging structure
  74. * Used to tag HW blocks as reserved by a CRTC->Encoder->Connector chain
  75. * By using as a tag, rather than lists of pointers to HW blocks used
  76. * we can avoid some list management since we don't know how many blocks
  77. * of each type a given use case may require.
  78. * @list: List head for list of all reservations
  79. * @seq: Global RSVP sequence number for debugging, especially for
  80. * differentiating differenct allocations for same encoder.
  81. * @enc_id: Reservations are tracked by Encoder DRM object ID.
  82. * CRTCs may be connected to multiple Encoders.
  83. * An encoder or connector id identifies the display path.
  84. * @topology DRM<->HW topology use case
  85. */
  86. struct sde_rm_rsvp {
  87. struct list_head list;
  88. uint32_t seq;
  89. uint32_t enc_id;
  90. enum sde_rm_topology_name topology;
  91. };
  92. /**
  93. * struct sde_rm_hw_blk - hardware block tracking list member
  94. * @list: List head for list of all hardware blocks tracking items
  95. * @rsvp: Pointer to use case reservation if reserved by a client
  96. * @rsvp_nxt: Temporary pointer used during reservation to the incoming
  97. * request. Will be swapped into rsvp if proposal is accepted
  98. * @type: Type of hardware block this structure tracks
  99. * @id: Hardware ID number, within it's own space, ie. LM_X
  100. * @catalog: Pointer to the hardware catalog entry for this block
  101. * @hw: Pointer to the hardware register access object for this block
  102. */
  103. struct sde_rm_hw_blk {
  104. struct list_head list;
  105. struct sde_rm_rsvp *rsvp;
  106. struct sde_rm_rsvp *rsvp_nxt;
  107. enum sde_hw_blk_type type;
  108. uint32_t id;
  109. struct sde_hw_blk *hw;
  110. };
  111. /**
  112. * sde_rm_dbg_rsvp_stage - enum of steps in making reservation for event logging
  113. */
  114. enum sde_rm_dbg_rsvp_stage {
  115. SDE_RM_STAGE_BEGIN,
  116. SDE_RM_STAGE_AFTER_CLEAR,
  117. SDE_RM_STAGE_AFTER_RSVPNEXT,
  118. SDE_RM_STAGE_FINAL
  119. };
  120. static void _sde_rm_print_rsvps(
  121. struct sde_rm *rm,
  122. enum sde_rm_dbg_rsvp_stage stage)
  123. {
  124. struct sde_rm_rsvp *rsvp;
  125. struct sde_rm_hw_blk *blk;
  126. enum sde_hw_blk_type type;
  127. SDE_DEBUG("%d\n", stage);
  128. list_for_each_entry(rsvp, &rm->rsvps, list) {
  129. SDE_DEBUG("%d rsvp[s%ue%u] topology %d\n", stage, rsvp->seq,
  130. rsvp->enc_id, rsvp->topology);
  131. SDE_EVT32(stage, rsvp->seq, rsvp->enc_id, rsvp->topology);
  132. }
  133. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  134. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  135. if (!blk->rsvp && !blk->rsvp_nxt)
  136. continue;
  137. SDE_DEBUG("%d rsvp[s%ue%u->s%ue%u] %d %d\n", stage,
  138. (blk->rsvp) ? blk->rsvp->seq : 0,
  139. (blk->rsvp) ? blk->rsvp->enc_id : 0,
  140. (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
  141. (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
  142. blk->type, blk->id);
  143. SDE_EVT32(stage,
  144. (blk->rsvp) ? blk->rsvp->seq : 0,
  145. (blk->rsvp) ? blk->rsvp->enc_id : 0,
  146. (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
  147. (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
  148. blk->type, blk->id);
  149. }
  150. }
  151. }
  152. struct sde_hw_mdp *sde_rm_get_mdp(struct sde_rm *rm)
  153. {
  154. return rm->hw_mdp;
  155. }
  156. void sde_rm_init_hw_iter(
  157. struct sde_rm_hw_iter *iter,
  158. uint32_t enc_id,
  159. enum sde_hw_blk_type type)
  160. {
  161. memset(iter, 0, sizeof(*iter));
  162. iter->enc_id = enc_id;
  163. iter->type = type;
  164. }
  165. enum sde_rm_topology_name sde_rm_get_topology_name(
  166. struct msm_display_topology topology)
  167. {
  168. int i;
  169. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
  170. if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], topology))
  171. return g_top_table[i].top_name;
  172. return SDE_RM_TOPOLOGY_NONE;
  173. }
  174. static bool _sde_rm_get_hw_locked(struct sde_rm *rm, struct sde_rm_hw_iter *i)
  175. {
  176. struct list_head *blk_list;
  177. if (!rm || !i || i->type >= SDE_HW_BLK_MAX) {
  178. SDE_ERROR("invalid rm\n");
  179. return false;
  180. }
  181. i->hw = NULL;
  182. blk_list = &rm->hw_blks[i->type];
  183. if (i->blk && (&i->blk->list == blk_list)) {
  184. SDE_DEBUG("attempt resume iteration past last\n");
  185. return false;
  186. }
  187. i->blk = list_prepare_entry(i->blk, blk_list, list);
  188. list_for_each_entry_continue(i->blk, blk_list, list) {
  189. struct sde_rm_rsvp *rsvp = i->blk->rsvp;
  190. if (i->blk->type != i->type) {
  191. SDE_ERROR("found incorrect block type %d on %d list\n",
  192. i->blk->type, i->type);
  193. return false;
  194. }
  195. if ((i->enc_id == 0) || (rsvp && rsvp->enc_id == i->enc_id)) {
  196. i->hw = i->blk->hw;
  197. SDE_DEBUG("found type %d id %d for enc %d\n",
  198. i->type, i->blk->id, i->enc_id);
  199. return true;
  200. }
  201. }
  202. SDE_DEBUG("no match, type %d for enc %d\n", i->type, i->enc_id);
  203. return false;
  204. }
  205. static bool _sde_rm_request_hw_blk_locked(struct sde_rm *rm,
  206. struct sde_rm_hw_request *hw_blk_info)
  207. {
  208. struct list_head *blk_list;
  209. struct sde_rm_hw_blk *blk = NULL;
  210. if (!rm || !hw_blk_info || hw_blk_info->type >= SDE_HW_BLK_MAX) {
  211. SDE_ERROR("invalid rm\n");
  212. return false;
  213. }
  214. hw_blk_info->hw = NULL;
  215. blk_list = &rm->hw_blks[hw_blk_info->type];
  216. blk = list_prepare_entry(blk, blk_list, list);
  217. list_for_each_entry_continue(blk, blk_list, list) {
  218. if (blk->type != hw_blk_info->type) {
  219. SDE_ERROR("found incorrect block type %d on %d list\n",
  220. blk->type, hw_blk_info->type);
  221. return false;
  222. }
  223. if (blk->hw->id == hw_blk_info->id) {
  224. hw_blk_info->hw = blk->hw;
  225. SDE_DEBUG("found type %d id %d\n",
  226. blk->type, blk->id);
  227. return true;
  228. }
  229. }
  230. SDE_DEBUG("no match, type %d id %d\n", hw_blk_info->type,
  231. hw_blk_info->id);
  232. return false;
  233. }
  234. bool sde_rm_get_hw(struct sde_rm *rm, struct sde_rm_hw_iter *i)
  235. {
  236. bool ret;
  237. mutex_lock(&rm->rm_lock);
  238. ret = _sde_rm_get_hw_locked(rm, i);
  239. mutex_unlock(&rm->rm_lock);
  240. return ret;
  241. }
  242. bool sde_rm_request_hw_blk(struct sde_rm *rm, struct sde_rm_hw_request *hw)
  243. {
  244. bool ret;
  245. mutex_lock(&rm->rm_lock);
  246. ret = _sde_rm_request_hw_blk_locked(rm, hw);
  247. mutex_unlock(&rm->rm_lock);
  248. return ret;
  249. }
  250. static void _sde_rm_hw_destroy(enum sde_hw_blk_type type, void *hw)
  251. {
  252. switch (type) {
  253. case SDE_HW_BLK_LM:
  254. sde_hw_lm_destroy(hw);
  255. break;
  256. case SDE_HW_BLK_DSPP:
  257. sde_hw_dspp_destroy(hw);
  258. break;
  259. case SDE_HW_BLK_DS:
  260. sde_hw_ds_destroy(hw);
  261. break;
  262. case SDE_HW_BLK_CTL:
  263. sde_hw_ctl_destroy(hw);
  264. break;
  265. case SDE_HW_BLK_CDM:
  266. sde_hw_cdm_destroy(hw);
  267. break;
  268. case SDE_HW_BLK_PINGPONG:
  269. sde_hw_pingpong_destroy(hw);
  270. break;
  271. case SDE_HW_BLK_INTF:
  272. sde_hw_intf_destroy(hw);
  273. break;
  274. case SDE_HW_BLK_WB:
  275. sde_hw_wb_destroy(hw);
  276. break;
  277. case SDE_HW_BLK_DSC:
  278. sde_hw_dsc_destroy(hw);
  279. break;
  280. case SDE_HW_BLK_QDSS:
  281. sde_hw_qdss_destroy(hw);
  282. break;
  283. case SDE_HW_BLK_SSPP:
  284. /* SSPPs are not managed by the resource manager */
  285. case SDE_HW_BLK_TOP:
  286. /* Top is a singleton, not managed in hw_blks list */
  287. case SDE_HW_BLK_MAX:
  288. default:
  289. SDE_ERROR("unsupported block type %d\n", type);
  290. break;
  291. }
  292. }
  293. int sde_rm_destroy(struct sde_rm *rm)
  294. {
  295. struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
  296. struct sde_rm_hw_blk *hw_cur, *hw_nxt;
  297. enum sde_hw_blk_type type;
  298. if (!rm) {
  299. SDE_ERROR("invalid rm\n");
  300. return -EINVAL;
  301. }
  302. list_for_each_entry_safe(rsvp_cur, rsvp_nxt, &rm->rsvps, list) {
  303. list_del(&rsvp_cur->list);
  304. kfree(rsvp_cur);
  305. }
  306. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  307. list_for_each_entry_safe(hw_cur, hw_nxt, &rm->hw_blks[type],
  308. list) {
  309. list_del(&hw_cur->list);
  310. _sde_rm_hw_destroy(hw_cur->type, hw_cur->hw);
  311. kfree(hw_cur);
  312. }
  313. }
  314. sde_hw_mdp_destroy(rm->hw_mdp);
  315. rm->hw_mdp = NULL;
  316. mutex_destroy(&rm->rm_lock);
  317. return 0;
  318. }
  319. static int _sde_rm_hw_blk_create(
  320. struct sde_rm *rm,
  321. struct sde_mdss_cfg *cat,
  322. void __iomem *mmio,
  323. enum sde_hw_blk_type type,
  324. uint32_t id,
  325. void *hw_catalog_info)
  326. {
  327. struct sde_rm_hw_blk *blk;
  328. struct sde_hw_mdp *hw_mdp;
  329. void *hw;
  330. hw_mdp = rm->hw_mdp;
  331. switch (type) {
  332. case SDE_HW_BLK_LM:
  333. hw = sde_hw_lm_init(id, mmio, cat);
  334. break;
  335. case SDE_HW_BLK_DSPP:
  336. hw = sde_hw_dspp_init(id, mmio, cat);
  337. break;
  338. case SDE_HW_BLK_DS:
  339. hw = sde_hw_ds_init(id, mmio, cat);
  340. break;
  341. case SDE_HW_BLK_CTL:
  342. hw = sde_hw_ctl_init(id, mmio, cat);
  343. break;
  344. case SDE_HW_BLK_CDM:
  345. hw = sde_hw_cdm_init(id, mmio, cat, hw_mdp);
  346. break;
  347. case SDE_HW_BLK_PINGPONG:
  348. hw = sde_hw_pingpong_init(id, mmio, cat);
  349. break;
  350. case SDE_HW_BLK_INTF:
  351. hw = sde_hw_intf_init(id, mmio, cat);
  352. break;
  353. case SDE_HW_BLK_WB:
  354. hw = sde_hw_wb_init(id, mmio, cat, hw_mdp);
  355. break;
  356. case SDE_HW_BLK_DSC:
  357. hw = sde_hw_dsc_init(id, mmio, cat);
  358. break;
  359. case SDE_HW_BLK_QDSS:
  360. hw = sde_hw_qdss_init(id, mmio, cat);
  361. break;
  362. case SDE_HW_BLK_SSPP:
  363. /* SSPPs are not managed by the resource manager */
  364. case SDE_HW_BLK_TOP:
  365. /* Top is a singleton, not managed in hw_blks list */
  366. case SDE_HW_BLK_MAX:
  367. default:
  368. SDE_ERROR("unsupported block type %d\n", type);
  369. return -EINVAL;
  370. }
  371. if (IS_ERR_OR_NULL(hw)) {
  372. SDE_ERROR("failed hw object creation: type %d, err %ld\n",
  373. type, PTR_ERR(hw));
  374. return -EFAULT;
  375. }
  376. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  377. if (!blk) {
  378. _sde_rm_hw_destroy(type, hw);
  379. return -ENOMEM;
  380. }
  381. blk->type = type;
  382. blk->id = id;
  383. blk->hw = hw;
  384. list_add_tail(&blk->list, &rm->hw_blks[type]);
  385. return 0;
  386. }
  387. static int _sde_rm_hw_blk_create_new(struct sde_rm *rm,
  388. struct sde_mdss_cfg *cat,
  389. void __iomem *mmio)
  390. {
  391. int i, rc = 0;
  392. for (i = 0; i < cat->dspp_count; i++) {
  393. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSPP,
  394. cat->dspp[i].id, &cat->dspp[i]);
  395. if (rc) {
  396. SDE_ERROR("failed: dspp hw not available\n");
  397. goto fail;
  398. }
  399. }
  400. if (cat->mdp[0].has_dest_scaler) {
  401. for (i = 0; i < cat->ds_count; i++) {
  402. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DS,
  403. cat->ds[i].id, &cat->ds[i]);
  404. if (rc) {
  405. SDE_ERROR("failed: ds hw not available\n");
  406. goto fail;
  407. }
  408. }
  409. }
  410. for (i = 0; i < cat->pingpong_count; i++) {
  411. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_PINGPONG,
  412. cat->pingpong[i].id, &cat->pingpong[i]);
  413. if (rc) {
  414. SDE_ERROR("failed: pp hw not available\n");
  415. goto fail;
  416. }
  417. }
  418. for (i = 0; i < cat->dsc_count; i++) {
  419. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSC,
  420. cat->dsc[i].id, &cat->dsc[i]);
  421. if (rc) {
  422. SDE_ERROR("failed: dsc hw not available\n");
  423. goto fail;
  424. }
  425. }
  426. for (i = 0; i < cat->intf_count; i++) {
  427. if (cat->intf[i].type == INTF_NONE) {
  428. SDE_DEBUG("skip intf %d with type none\n", i);
  429. continue;
  430. }
  431. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_INTF,
  432. cat->intf[i].id, &cat->intf[i]);
  433. if (rc) {
  434. SDE_ERROR("failed: intf hw not available\n");
  435. goto fail;
  436. }
  437. }
  438. for (i = 0; i < cat->wb_count; i++) {
  439. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_WB,
  440. cat->wb[i].id, &cat->wb[i]);
  441. if (rc) {
  442. SDE_ERROR("failed: wb hw not available\n");
  443. goto fail;
  444. }
  445. }
  446. for (i = 0; i < cat->ctl_count; i++) {
  447. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CTL,
  448. cat->ctl[i].id, &cat->ctl[i]);
  449. if (rc) {
  450. SDE_ERROR("failed: ctl hw not available\n");
  451. goto fail;
  452. }
  453. }
  454. for (i = 0; i < cat->cdm_count; i++) {
  455. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CDM,
  456. cat->cdm[i].id, &cat->cdm[i]);
  457. if (rc) {
  458. SDE_ERROR("failed: cdm hw not available\n");
  459. goto fail;
  460. }
  461. }
  462. for (i = 0; i < cat->qdss_count; i++) {
  463. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_QDSS,
  464. cat->qdss[i].id, &cat->qdss[i]);
  465. if (rc) {
  466. SDE_ERROR("failed: qdss hw not available\n");
  467. goto fail;
  468. }
  469. }
  470. fail:
  471. return rc;
  472. }
  473. int sde_rm_init(struct sde_rm *rm,
  474. struct sde_mdss_cfg *cat,
  475. void __iomem *mmio,
  476. struct drm_device *dev)
  477. {
  478. int i, rc = 0;
  479. enum sde_hw_blk_type type;
  480. if (!rm || !cat || !mmio || !dev) {
  481. SDE_ERROR("invalid input params\n");
  482. return -EINVAL;
  483. }
  484. /* Clear, setup lists */
  485. memset(rm, 0, sizeof(*rm));
  486. mutex_init(&rm->rm_lock);
  487. INIT_LIST_HEAD(&rm->rsvps);
  488. for (type = 0; type < SDE_HW_BLK_MAX; type++)
  489. INIT_LIST_HEAD(&rm->hw_blks[type]);
  490. rm->dev = dev;
  491. if (IS_SDE_CTL_REV_100(cat->ctl_rev))
  492. rm->topology_tbl = g_ctl_ver_1_top_table;
  493. else
  494. rm->topology_tbl = g_top_table;
  495. /* Some of the sub-blocks require an mdptop to be created */
  496. rm->hw_mdp = sde_hw_mdptop_init(MDP_TOP, mmio, cat);
  497. if (IS_ERR_OR_NULL(rm->hw_mdp)) {
  498. rc = PTR_ERR(rm->hw_mdp);
  499. rm->hw_mdp = NULL;
  500. SDE_ERROR("failed: mdp hw not available\n");
  501. goto fail;
  502. }
  503. /* Interrogate HW catalog and create tracking items for hw blocks */
  504. for (i = 0; i < cat->mixer_count; i++) {
  505. struct sde_lm_cfg *lm = &cat->mixer[i];
  506. if (lm->pingpong == PINGPONG_MAX) {
  507. SDE_ERROR("mixer %d without pingpong\n", lm->id);
  508. goto fail;
  509. }
  510. rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_LM,
  511. cat->mixer[i].id, &cat->mixer[i]);
  512. if (rc) {
  513. SDE_ERROR("failed: lm hw not available\n");
  514. goto fail;
  515. }
  516. if (!rm->lm_max_width) {
  517. rm->lm_max_width = lm->sblk->maxwidth;
  518. } else if (rm->lm_max_width != lm->sblk->maxwidth) {
  519. /*
  520. * Don't expect to have hw where lm max widths differ.
  521. * If found, take the min.
  522. */
  523. SDE_ERROR("unsupported: lm maxwidth differs\n");
  524. if (rm->lm_max_width > lm->sblk->maxwidth)
  525. rm->lm_max_width = lm->sblk->maxwidth;
  526. }
  527. }
  528. rc = _sde_rm_hw_blk_create_new(rm, cat, mmio);
  529. if (!rc)
  530. return 0;
  531. fail:
  532. sde_rm_destroy(rm);
  533. return rc;
  534. }
  535. static bool _sde_rm_check_lm(
  536. struct sde_rm *rm,
  537. struct sde_rm_rsvp *rsvp,
  538. struct sde_rm_requirements *reqs,
  539. const struct sde_lm_cfg *lm_cfg,
  540. struct sde_rm_hw_blk *lm,
  541. struct sde_rm_hw_blk **dspp,
  542. struct sde_rm_hw_blk **ds,
  543. struct sde_rm_hw_blk **pp)
  544. {
  545. bool is_valid_dspp, is_valid_ds, ret;
  546. is_valid_dspp = (lm_cfg->dspp != DSPP_MAX) ? true : false;
  547. is_valid_ds = (lm_cfg->ds != DS_MAX) ? true : false;
  548. /**
  549. * RM_RQ_X: specification of which LMs to choose
  550. * is_valid_X: indicates whether LM is tied with block X
  551. * ret: true if given LM matches the user requirement,
  552. * false otherwise
  553. */
  554. if (RM_RQ_DSPP(reqs) && RM_RQ_DS(reqs))
  555. ret = (is_valid_dspp && is_valid_ds);
  556. else if (RM_RQ_DSPP(reqs))
  557. ret = is_valid_dspp;
  558. else if (RM_RQ_DS(reqs))
  559. ret = is_valid_ds;
  560. else
  561. ret = !(is_valid_dspp || is_valid_ds);
  562. if (!ret) {
  563. SDE_DEBUG(
  564. "fail:lm(%d)req_dspp(%d)dspp(%d)req_ds(%d)ds(%d)\n",
  565. lm_cfg->id, (bool)(RM_RQ_DSPP(reqs)),
  566. lm_cfg->dspp, (bool)(RM_RQ_DS(reqs)),
  567. lm_cfg->ds);
  568. return ret;
  569. }
  570. return true;
  571. }
  572. static bool _sde_rm_reserve_dspp(
  573. struct sde_rm *rm,
  574. struct sde_rm_rsvp *rsvp,
  575. const struct sde_lm_cfg *lm_cfg,
  576. struct sde_rm_hw_blk *lm,
  577. struct sde_rm_hw_blk **dspp)
  578. {
  579. struct sde_rm_hw_iter iter;
  580. if (lm_cfg->dspp != DSPP_MAX) {
  581. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DSPP);
  582. while (_sde_rm_get_hw_locked(rm, &iter)) {
  583. if (iter.blk->id == lm_cfg->dspp) {
  584. *dspp = iter.blk;
  585. break;
  586. }
  587. }
  588. if (!*dspp) {
  589. SDE_DEBUG("lm %d failed to retrieve dspp %d\n", lm->id,
  590. lm_cfg->dspp);
  591. return false;
  592. }
  593. if (RESERVED_BY_OTHER(*dspp, rsvp)) {
  594. SDE_DEBUG("lm %d dspp %d already reserved\n",
  595. lm->id, (*dspp)->id);
  596. return false;
  597. }
  598. }
  599. return true;
  600. }
  601. static bool _sde_rm_reserve_ds(
  602. struct sde_rm *rm,
  603. struct sde_rm_rsvp *rsvp,
  604. const struct sde_lm_cfg *lm_cfg,
  605. struct sde_rm_hw_blk *lm,
  606. struct sde_rm_hw_blk **ds)
  607. {
  608. struct sde_rm_hw_iter iter;
  609. if (lm_cfg->ds != DS_MAX) {
  610. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DS);
  611. while (_sde_rm_get_hw_locked(rm, &iter)) {
  612. if (iter.blk->id == lm_cfg->ds) {
  613. *ds = iter.blk;
  614. break;
  615. }
  616. }
  617. if (!*ds) {
  618. SDE_DEBUG("lm %d failed to retrieve ds %d\n", lm->id,
  619. lm_cfg->ds);
  620. return false;
  621. }
  622. if (RESERVED_BY_OTHER(*ds, rsvp)) {
  623. SDE_DEBUG("lm %d ds %d already reserved\n",
  624. lm->id, (*ds)->id);
  625. return false;
  626. }
  627. }
  628. return true;
  629. }
  630. static bool _sde_rm_reserve_pp(
  631. struct sde_rm *rm,
  632. struct sde_rm_rsvp *rsvp,
  633. struct sde_rm_requirements *reqs,
  634. const struct sde_lm_cfg *lm_cfg,
  635. const struct sde_pingpong_cfg *pp_cfg,
  636. struct sde_rm_hw_blk *lm,
  637. struct sde_rm_hw_blk **dspp,
  638. struct sde_rm_hw_blk **ds,
  639. struct sde_rm_hw_blk **pp)
  640. {
  641. struct sde_rm_hw_iter iter;
  642. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_PINGPONG);
  643. while (_sde_rm_get_hw_locked(rm, &iter)) {
  644. if (iter.blk->id == lm_cfg->pingpong) {
  645. *pp = iter.blk;
  646. break;
  647. }
  648. }
  649. if (!*pp) {
  650. SDE_ERROR("failed to get pp on lm %d\n", lm_cfg->pingpong);
  651. return false;
  652. }
  653. if (RESERVED_BY_OTHER(*pp, rsvp)) {
  654. SDE_DEBUG("lm %d pp %d already reserved\n", lm->id,
  655. (*pp)->id);
  656. *dspp = NULL;
  657. *ds = NULL;
  658. return false;
  659. }
  660. pp_cfg = to_sde_hw_pingpong((*pp)->hw)->caps;
  661. if ((reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) &&
  662. !(test_bit(SDE_PINGPONG_SPLIT, &pp_cfg->features))) {
  663. SDE_DEBUG("pp %d doesn't support ppsplit\n", pp_cfg->id);
  664. *dspp = NULL;
  665. *ds = NULL;
  666. return false;
  667. }
  668. return true;
  669. }
  670. /**
  671. * _sde_rm_check_lm_and_get_connected_blks - check if proposed layer mixer meets
  672. * proposed use case requirements, incl. hardwired dependent blocks like
  673. * pingpong, and dspp.
  674. * @rm: sde resource manager handle
  675. * @rsvp: reservation currently being created
  676. * @reqs: proposed use case requirements
  677. * @lm: proposed layer mixer, function checks if lm, and all other hardwired
  678. * blocks connected to the lm (pp, dspp) are available and appropriate
  679. * @dspp: output parameter, dspp block attached to the layer mixer.
  680. * NULL if dspp was not available, or not matching requirements.
  681. * @pp: output parameter, pingpong block attached to the layer mixer.
  682. * NULL if dspp was not available, or not matching requirements.
  683. * @primary_lm: if non-null, this function check if lm is compatible primary_lm
  684. * as well as satisfying all other requirements
  685. * @Return: true if lm matches all requirements, false otherwise
  686. */
  687. static bool _sde_rm_check_lm_and_get_connected_blks(
  688. struct sde_rm *rm,
  689. struct sde_rm_rsvp *rsvp,
  690. struct sde_rm_requirements *reqs,
  691. struct sde_rm_hw_blk *lm,
  692. struct sde_rm_hw_blk **dspp,
  693. struct sde_rm_hw_blk **ds,
  694. struct sde_rm_hw_blk **pp,
  695. struct sde_rm_hw_blk *primary_lm)
  696. {
  697. const struct sde_lm_cfg *lm_cfg = to_sde_hw_mixer(lm->hw)->cap;
  698. const struct sde_pingpong_cfg *pp_cfg;
  699. bool ret;
  700. u32 display_pref, cwb_pref;
  701. *dspp = NULL;
  702. *ds = NULL;
  703. *pp = NULL;
  704. display_pref = lm_cfg->features & BIT(SDE_DISP_PRIMARY_PREF) ||
  705. lm_cfg->features & BIT(SDE_DISP_SECONDARY_PREF);
  706. cwb_pref = lm_cfg->features & BIT(SDE_DISP_CWB_PREF);
  707. SDE_DEBUG("check lm %d: dspp %d ds %d pp %d disp_pref: %d cwb_pref%d\n",
  708. lm_cfg->id, lm_cfg->dspp, lm_cfg->ds,
  709. lm_cfg->pingpong, display_pref, cwb_pref);
  710. /* Check if this layer mixer is a peer of the proposed primary LM */
  711. if (primary_lm) {
  712. const struct sde_lm_cfg *prim_lm_cfg =
  713. to_sde_hw_mixer(primary_lm->hw)->cap;
  714. if (!test_bit(lm_cfg->id, &prim_lm_cfg->lm_pair_mask)) {
  715. SDE_DEBUG("lm %d not peer of lm %d\n", lm_cfg->id,
  716. prim_lm_cfg->id);
  717. return false;
  718. }
  719. }
  720. /* bypass rest of the checks if LM for primary display is found */
  721. if (!display_pref) {
  722. /* Check lm for valid requirements */
  723. ret = _sde_rm_check_lm(rm, rsvp, reqs, lm_cfg, lm,
  724. dspp, ds, pp);
  725. if (!ret)
  726. return ret;
  727. /**
  728. * If CWB is enabled and LM is not CWB supported
  729. * then return false.
  730. */
  731. if (RM_RQ_CWB(reqs) && !cwb_pref) {
  732. SDE_DEBUG("fail: cwb supported lm not allocated\n");
  733. return false;
  734. }
  735. } else if (!(reqs->hw_res.display_type && display_pref)) {
  736. SDE_DEBUG(
  737. "display preference is not met. display_type: %d display_pref: %d\n",
  738. (int)reqs->hw_res.display_type, (int)display_pref);
  739. return false;
  740. }
  741. /* Already reserved? */
  742. if (RESERVED_BY_OTHER(lm, rsvp)) {
  743. SDE_DEBUG("lm %d already reserved\n", lm_cfg->id);
  744. return false;
  745. }
  746. /* Reserve dspp */
  747. ret = _sde_rm_reserve_dspp(rm, rsvp, lm_cfg, lm, dspp);
  748. if (!ret)
  749. return ret;
  750. /* Reserve ds */
  751. ret = _sde_rm_reserve_ds(rm, rsvp, lm_cfg, lm, ds);
  752. if (!ret)
  753. return ret;
  754. /* Reserve pp */
  755. ret = _sde_rm_reserve_pp(rm, rsvp, reqs, lm_cfg, pp_cfg, lm,
  756. dspp, ds, pp);
  757. if (!ret)
  758. return ret;
  759. return true;
  760. }
  761. static int _sde_rm_reserve_lms(
  762. struct sde_rm *rm,
  763. struct sde_rm_rsvp *rsvp,
  764. struct sde_rm_requirements *reqs,
  765. u8 *_lm_ids)
  766. {
  767. struct sde_rm_hw_blk *lm[MAX_BLOCKS];
  768. struct sde_rm_hw_blk *dspp[MAX_BLOCKS];
  769. struct sde_rm_hw_blk *ds[MAX_BLOCKS];
  770. struct sde_rm_hw_blk *pp[MAX_BLOCKS];
  771. struct sde_rm_hw_iter iter_i, iter_j;
  772. int lm_count = 0;
  773. int i, rc = 0;
  774. if (!reqs->topology->num_lm) {
  775. SDE_DEBUG("invalid number of lm: %d\n", reqs->topology->num_lm);
  776. return 0;
  777. }
  778. /* Find a primary mixer */
  779. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_LM);
  780. while (lm_count != reqs->topology->num_lm &&
  781. _sde_rm_get_hw_locked(rm, &iter_i)) {
  782. memset(&lm, 0, sizeof(lm));
  783. memset(&dspp, 0, sizeof(dspp));
  784. memset(&ds, 0, sizeof(ds));
  785. memset(&pp, 0, sizeof(pp));
  786. lm_count = 0;
  787. lm[lm_count] = iter_i.blk;
  788. SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n",
  789. iter_i.blk->id,
  790. lm_count,
  791. _lm_ids ? _lm_ids[lm_count] : -1);
  792. if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count])
  793. continue;
  794. if (!_sde_rm_check_lm_and_get_connected_blks(
  795. rm, rsvp, reqs, lm[lm_count],
  796. &dspp[lm_count], &ds[lm_count],
  797. &pp[lm_count], NULL))
  798. continue;
  799. ++lm_count;
  800. /* Valid primary mixer found, find matching peers */
  801. sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_LM);
  802. while (lm_count != reqs->topology->num_lm &&
  803. _sde_rm_get_hw_locked(rm, &iter_j)) {
  804. if (iter_i.blk == iter_j.blk)
  805. continue;
  806. if (!_sde_rm_check_lm_and_get_connected_blks(
  807. rm, rsvp, reqs, iter_j.blk,
  808. &dspp[lm_count], &ds[lm_count],
  809. &pp[lm_count], iter_i.blk))
  810. continue;
  811. lm[lm_count] = iter_j.blk;
  812. SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n",
  813. iter_i.blk->id,
  814. lm_count,
  815. _lm_ids ? _lm_ids[lm_count] : -1);
  816. if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count])
  817. continue;
  818. ++lm_count;
  819. }
  820. }
  821. if (lm_count != reqs->topology->num_lm) {
  822. SDE_DEBUG("unable to find appropriate mixers\n");
  823. return -ENAVAIL;
  824. }
  825. for (i = 0; i < ARRAY_SIZE(lm); i++) {
  826. if (!lm[i])
  827. break;
  828. lm[i]->rsvp_nxt = rsvp;
  829. pp[i]->rsvp_nxt = rsvp;
  830. if (dspp[i])
  831. dspp[i]->rsvp_nxt = rsvp;
  832. if (ds[i])
  833. ds[i]->rsvp_nxt = rsvp;
  834. SDE_EVT32(lm[i]->type, rsvp->enc_id, lm[i]->id, pp[i]->id,
  835. dspp[i] ? dspp[i]->id : 0,
  836. ds[i] ? ds[i]->id : 0);
  837. }
  838. if (reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) {
  839. /* reserve a free PINGPONG_SLAVE block */
  840. rc = -ENAVAIL;
  841. sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_PINGPONG);
  842. while (_sde_rm_get_hw_locked(rm, &iter_i)) {
  843. const struct sde_hw_pingpong *pp =
  844. to_sde_hw_pingpong(iter_i.blk->hw);
  845. const struct sde_pingpong_cfg *pp_cfg = pp->caps;
  846. if (!(test_bit(SDE_PINGPONG_SLAVE, &pp_cfg->features)))
  847. continue;
  848. if (RESERVED_BY_OTHER(iter_i.blk, rsvp))
  849. continue;
  850. iter_i.blk->rsvp_nxt = rsvp;
  851. rc = 0;
  852. break;
  853. }
  854. }
  855. return rc;
  856. }
  857. static int _sde_rm_reserve_ctls(
  858. struct sde_rm *rm,
  859. struct sde_rm_rsvp *rsvp,
  860. struct sde_rm_requirements *reqs,
  861. const struct sde_rm_topology_def *top,
  862. u8 *_ctl_ids)
  863. {
  864. struct sde_rm_hw_blk *ctls[MAX_BLOCKS];
  865. struct sde_rm_hw_iter iter;
  866. int i = 0;
  867. if (!top->num_ctl) {
  868. SDE_DEBUG("invalid number of ctl: %d\n", top->num_ctl);
  869. return 0;
  870. }
  871. memset(&ctls, 0, sizeof(ctls));
  872. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
  873. while (_sde_rm_get_hw_locked(rm, &iter)) {
  874. const struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
  875. unsigned long features = ctl->caps->features;
  876. bool has_split_display, has_ppsplit, primary_pref;
  877. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  878. continue;
  879. has_split_display = BIT(SDE_CTL_SPLIT_DISPLAY) & features;
  880. has_ppsplit = BIT(SDE_CTL_PINGPONG_SPLIT) & features;
  881. primary_pref = BIT(SDE_CTL_PRIMARY_PREF) & features;
  882. SDE_DEBUG("ctl %d caps 0x%lX\n", iter.blk->id, features);
  883. /*
  884. * bypass rest feature checks on finding CTL preferred
  885. * for primary displays.
  886. */
  887. if (!primary_pref && !_ctl_ids) {
  888. if (top->needs_split_display != has_split_display)
  889. continue;
  890. if (top->top_name == SDE_RM_TOPOLOGY_PPSPLIT &&
  891. !has_ppsplit)
  892. continue;
  893. } else if (!(reqs->hw_res.display_type ==
  894. SDE_CONNECTOR_PRIMARY && primary_pref) && !_ctl_ids) {
  895. SDE_DEBUG(
  896. "display pref not met. display_type: %d primary_pref: %d\n",
  897. reqs->hw_res.display_type, primary_pref);
  898. continue;
  899. }
  900. ctls[i] = iter.blk;
  901. SDE_DEBUG("blk id = %d, _ctl_ids[%d] = %d\n",
  902. iter.blk->id, i,
  903. _ctl_ids ? _ctl_ids[i] : -1);
  904. if (_ctl_ids && (ctls[i]->id != _ctl_ids[i]))
  905. continue;
  906. SDE_DEBUG("ctl %d match\n", iter.blk->id);
  907. if (++i == top->num_ctl)
  908. break;
  909. }
  910. if (i != top->num_ctl)
  911. return -ENAVAIL;
  912. for (i = 0; i < ARRAY_SIZE(ctls) && i < top->num_ctl; i++) {
  913. ctls[i]->rsvp_nxt = rsvp;
  914. SDE_EVT32(ctls[i]->type, rsvp->enc_id, ctls[i]->id);
  915. }
  916. return 0;
  917. }
  918. static int _sde_rm_reserve_dsc(
  919. struct sde_rm *rm,
  920. struct sde_rm_rsvp *rsvp,
  921. const struct sde_rm_topology_def *top,
  922. u8 *_dsc_ids)
  923. {
  924. struct sde_rm_hw_iter iter;
  925. int alloc_count = 0;
  926. int num_dsc_enc = top->num_lm;
  927. if (!top->num_comp_enc)
  928. return 0;
  929. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DSC);
  930. while (_sde_rm_get_hw_locked(rm, &iter)) {
  931. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  932. continue;
  933. SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
  934. iter.blk->id,
  935. alloc_count,
  936. _dsc_ids ? _dsc_ids[alloc_count] : -1);
  937. if (_dsc_ids && (iter.blk->id != _dsc_ids[alloc_count]))
  938. continue;
  939. iter.blk->rsvp_nxt = rsvp;
  940. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  941. if (++alloc_count == num_dsc_enc)
  942. return 0;
  943. }
  944. SDE_ERROR("couldn't reserve %d dsc blocks for enc id %d\n",
  945. num_dsc_enc, rsvp->enc_id);
  946. return -ENAVAIL;
  947. }
  948. static int _sde_rm_reserve_qdss(
  949. struct sde_rm *rm,
  950. struct sde_rm_rsvp *rsvp,
  951. const struct sde_rm_topology_def *top,
  952. u8 *_qdss_ids)
  953. {
  954. struct sde_rm_hw_iter iter;
  955. struct msm_drm_private *priv = rm->dev->dev_private;
  956. struct sde_kms *sde_kms;
  957. if (!priv->kms) {
  958. SDE_ERROR("invalid kms\n");
  959. return -EINVAL;
  960. }
  961. sde_kms = to_sde_kms(priv->kms);
  962. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_QDSS);
  963. while (_sde_rm_get_hw_locked(rm, &iter)) {
  964. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  965. continue;
  966. SDE_DEBUG("blk id = %d\n", iter.blk->id);
  967. iter.blk->rsvp_nxt = rsvp;
  968. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  969. return 0;
  970. }
  971. if (!iter.hw && sde_kms->catalog->qdss_count) {
  972. SDE_DEBUG("couldn't reserve qdss for type %d id %d\n",
  973. SDE_HW_BLK_QDSS, iter.blk->id);
  974. return -ENAVAIL;
  975. }
  976. return 0;
  977. }
  978. static int _sde_rm_reserve_cdm(
  979. struct sde_rm *rm,
  980. struct sde_rm_rsvp *rsvp,
  981. uint32_t id,
  982. enum sde_hw_blk_type type)
  983. {
  984. struct sde_rm_hw_iter iter;
  985. sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CDM);
  986. while (_sde_rm_get_hw_locked(rm, &iter)) {
  987. const struct sde_hw_cdm *cdm = to_sde_hw_cdm(iter.blk->hw);
  988. const struct sde_cdm_cfg *caps = cdm->caps;
  989. bool match = false;
  990. if (RESERVED_BY_OTHER(iter.blk, rsvp))
  991. continue;
  992. if (type == SDE_HW_BLK_INTF && id != INTF_MAX)
  993. match = test_bit(id, &caps->intf_connect);
  994. else if (type == SDE_HW_BLK_WB && id != WB_MAX)
  995. match = test_bit(id, &caps->wb_connect);
  996. SDE_DEBUG("type %d id %d, cdm intfs %lu wbs %lu match %d\n",
  997. type, id, caps->intf_connect, caps->wb_connect,
  998. match);
  999. if (!match)
  1000. continue;
  1001. iter.blk->rsvp_nxt = rsvp;
  1002. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1003. break;
  1004. }
  1005. if (!iter.hw) {
  1006. SDE_ERROR("couldn't reserve cdm for type %d id %d\n", type, id);
  1007. return -ENAVAIL;
  1008. }
  1009. return 0;
  1010. }
  1011. static int _sde_rm_reserve_intf_or_wb(
  1012. struct sde_rm *rm,
  1013. struct sde_rm_rsvp *rsvp,
  1014. uint32_t id,
  1015. enum sde_hw_blk_type type,
  1016. bool needs_cdm)
  1017. {
  1018. struct sde_rm_hw_iter iter;
  1019. int ret = 0;
  1020. /* Find the block entry in the rm, and note the reservation */
  1021. sde_rm_init_hw_iter(&iter, 0, type);
  1022. while (_sde_rm_get_hw_locked(rm, &iter)) {
  1023. if (iter.blk->id != id)
  1024. continue;
  1025. if (RESERVED_BY_OTHER(iter.blk, rsvp)) {
  1026. SDE_ERROR("type %d id %d already reserved\n", type, id);
  1027. return -ENAVAIL;
  1028. }
  1029. iter.blk->rsvp_nxt = rsvp;
  1030. SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
  1031. break;
  1032. }
  1033. /* Shouldn't happen since wbs / intfs are fixed at probe */
  1034. if (!iter.hw) {
  1035. SDE_ERROR("couldn't find type %d id %d\n", type, id);
  1036. return -EINVAL;
  1037. }
  1038. /* Expected only one intf or wb will request cdm */
  1039. if (needs_cdm)
  1040. ret = _sde_rm_reserve_cdm(rm, rsvp, id, type);
  1041. return ret;
  1042. }
  1043. static int _sde_rm_reserve_intf_related_hw(
  1044. struct sde_rm *rm,
  1045. struct sde_rm_rsvp *rsvp,
  1046. struct sde_encoder_hw_resources *hw_res)
  1047. {
  1048. int i, ret = 0;
  1049. u32 id;
  1050. for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) {
  1051. if (hw_res->intfs[i] == INTF_MODE_NONE)
  1052. continue;
  1053. id = i + INTF_0;
  1054. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id,
  1055. SDE_HW_BLK_INTF, hw_res->needs_cdm);
  1056. if (ret)
  1057. return ret;
  1058. }
  1059. for (i = 0; i < ARRAY_SIZE(hw_res->wbs); i++) {
  1060. if (hw_res->wbs[i] == INTF_MODE_NONE)
  1061. continue;
  1062. id = i + WB_0;
  1063. ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id,
  1064. SDE_HW_BLK_WB, hw_res->needs_cdm);
  1065. if (ret)
  1066. return ret;
  1067. }
  1068. return ret;
  1069. }
  1070. static bool _sde_rm_is_display_in_cont_splash(struct sde_kms *sde_kms,
  1071. struct drm_encoder *enc)
  1072. {
  1073. int i;
  1074. struct sde_splash_display *splash_dpy;
  1075. for (i = 0; i < MAX_DSI_DISPLAYS; i++) {
  1076. splash_dpy = &sde_kms->splash_data.splash_display[i];
  1077. if (splash_dpy->encoder == enc)
  1078. return splash_dpy->cont_splash_enabled;
  1079. }
  1080. return false;
  1081. }
  1082. static int _sde_rm_make_lm_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1083. struct sde_rm_requirements *reqs,
  1084. struct sde_splash_display *splash_display)
  1085. {
  1086. int ret, i;
  1087. u8 *hw_ids = NULL;
  1088. /* Check if splash data provided lm_ids */
  1089. if (splash_display) {
  1090. hw_ids = splash_display->lm_ids;
  1091. for (i = 0; i < splash_display->lm_cnt; i++)
  1092. SDE_DEBUG("splash_display->lm_ids[%d] = %d\n",
  1093. i, splash_display->lm_ids[i]);
  1094. if (splash_display->lm_cnt != reqs->topology->num_lm)
  1095. SDE_DEBUG("Configured splash LMs != needed LM cnt\n");
  1096. }
  1097. /*
  1098. * Assign LMs and blocks whose usage is tied to them: DSPP & Pingpong.
  1099. * Do assignment preferring to give away low-resource mixers first:
  1100. * - Check mixers without DSPPs
  1101. * - Only then allow to grab from mixers with DSPP capability
  1102. */
  1103. ret = _sde_rm_reserve_lms(rm, rsvp, reqs, hw_ids);
  1104. if (ret && !RM_RQ_DSPP(reqs)) {
  1105. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP);
  1106. ret = _sde_rm_reserve_lms(rm, rsvp, reqs, hw_ids);
  1107. }
  1108. return ret;
  1109. }
  1110. static int _sde_rm_make_ctl_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1111. struct sde_rm_requirements *reqs,
  1112. struct sde_splash_display *splash_display)
  1113. {
  1114. int ret, i;
  1115. u8 *hw_ids = NULL;
  1116. struct sde_rm_topology_def topology;
  1117. /* Check if splash data provided ctl_ids */
  1118. if (splash_display) {
  1119. hw_ids = splash_display->ctl_ids;
  1120. for (i = 0; i < splash_display->ctl_cnt; i++)
  1121. SDE_DEBUG("splash_display->ctl_ids[%d] = %d\n",
  1122. i, splash_display->ctl_ids[i]);
  1123. }
  1124. /*
  1125. * Do assignment preferring to give away low-resource CTLs first:
  1126. * - Check mixers without Split Display
  1127. * - Only then allow to grab from CTLs with split display capability
  1128. */
  1129. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, hw_ids);
  1130. if (ret && !reqs->topology->needs_split_display &&
  1131. reqs->topology->num_ctl > SINGLE_CTL) {
  1132. memcpy(&topology, reqs->topology, sizeof(topology));
  1133. topology.needs_split_display = true;
  1134. ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, hw_ids);
  1135. }
  1136. return ret;
  1137. }
  1138. static int _sde_rm_make_dsc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
  1139. struct sde_rm_requirements *reqs,
  1140. struct sde_splash_display *splash_display)
  1141. {
  1142. int ret, i;
  1143. u8 *hw_ids = NULL;
  1144. /* Check if splash data provided dsc_ids */
  1145. if (splash_display) {
  1146. hw_ids = splash_display->dsc_ids;
  1147. for (i = 0; i < splash_display->dsc_cnt; i++)
  1148. SDE_DEBUG("splash_data.dsc_ids[%d] = %d\n",
  1149. i, splash_display->dsc_ids[i]);
  1150. }
  1151. ret = _sde_rm_reserve_dsc(rm, rsvp, reqs->topology, hw_ids);
  1152. return ret;
  1153. }
  1154. static int _sde_rm_make_next_rsvp(struct sde_rm *rm, struct drm_encoder *enc,
  1155. struct drm_crtc_state *crtc_state,
  1156. struct drm_connector_state *conn_state,
  1157. struct sde_rm_rsvp *rsvp,
  1158. struct sde_rm_requirements *reqs)
  1159. {
  1160. struct msm_drm_private *priv;
  1161. struct sde_kms *sde_kms;
  1162. struct sde_splash_display *splash_display = NULL;
  1163. struct sde_splash_data *splash_data;
  1164. int i, ret;
  1165. priv = enc->dev->dev_private;
  1166. sde_kms = to_sde_kms(priv->kms);
  1167. splash_data = &sde_kms->splash_data;
  1168. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  1169. for (i = 0; i < ARRAY_SIZE(splash_data->splash_display); i++) {
  1170. if (enc == splash_data->splash_display[i].encoder)
  1171. splash_display =
  1172. &splash_data->splash_display[i];
  1173. }
  1174. if (!splash_display) {
  1175. SDE_ERROR("rm is in cont_splash but data not found\n");
  1176. return -EINVAL;
  1177. }
  1178. }
  1179. /* Create reservation info, tag reserved blocks with it as we go */
  1180. rsvp->seq = ++rm->rsvp_next_seq;
  1181. rsvp->enc_id = enc->base.id;
  1182. rsvp->topology = reqs->topology->top_name;
  1183. list_add_tail(&rsvp->list, &rm->rsvps);
  1184. ret = _sde_rm_make_lm_rsvp(rm, rsvp, reqs, splash_display);
  1185. if (ret) {
  1186. SDE_ERROR("unable to find appropriate mixers\n");
  1187. return ret;
  1188. }
  1189. ret = _sde_rm_make_ctl_rsvp(rm, rsvp, reqs, splash_display);
  1190. if (ret) {
  1191. SDE_ERROR("unable to find appropriate CTL\n");
  1192. return ret;
  1193. }
  1194. /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */
  1195. ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, &reqs->hw_res);
  1196. if (ret)
  1197. return ret;
  1198. ret = _sde_rm_make_dsc_rsvp(rm, rsvp, reqs, splash_display);
  1199. if (ret)
  1200. return ret;
  1201. ret = _sde_rm_reserve_qdss(rm, rsvp, reqs->topology, NULL);
  1202. if (ret)
  1203. return ret;
  1204. return ret;
  1205. }
  1206. /**
  1207. * _sde_rm_get_hw_blk_for_cont_splash - retrieve the LM blocks on given CTL
  1208. * and populate the connected HW blk ids in sde_splash_display
  1209. * @rm: Pointer to resource manager structure
  1210. * @ctl: Pointer to CTL hardware block
  1211. * @splash_display: Pointer to struct sde_splash_display
  1212. * return: number of active LM blocks for this CTL block
  1213. */
  1214. static int _sde_rm_get_hw_blk_for_cont_splash(struct sde_rm *rm,
  1215. struct sde_hw_ctl *ctl,
  1216. struct sde_splash_display *splash_display)
  1217. {
  1218. u32 lm_reg;
  1219. struct sde_rm_hw_iter iter_lm, iter_pp;
  1220. struct sde_hw_pingpong *pp;
  1221. if (!rm || !ctl || !splash_display) {
  1222. SDE_ERROR("invalid input parameters\n");
  1223. return 0;
  1224. }
  1225. sde_rm_init_hw_iter(&iter_lm, 0, SDE_HW_BLK_LM);
  1226. sde_rm_init_hw_iter(&iter_pp, 0, SDE_HW_BLK_PINGPONG);
  1227. while (_sde_rm_get_hw_locked(rm, &iter_lm)) {
  1228. _sde_rm_get_hw_locked(rm, &iter_pp);
  1229. if (splash_display->lm_cnt >= MAX_DATA_PATH_PER_DSIPLAY)
  1230. break;
  1231. lm_reg = ctl->ops.read_ctl_layers(ctl, iter_lm.blk->id);
  1232. if (!lm_reg)
  1233. continue;
  1234. splash_display->lm_ids[splash_display->lm_cnt++] =
  1235. iter_lm.blk->id;
  1236. SDE_DEBUG("lm_cnt=%d lm_reg[%d]=0x%x\n", splash_display->lm_cnt,
  1237. iter_lm.blk->id - LM_0, lm_reg);
  1238. if (ctl->ops.get_staged_sspp &&
  1239. ctl->ops.get_staged_sspp(ctl, iter_lm.blk->id,
  1240. &splash_display->pipes[
  1241. splash_display->pipe_cnt], 1)) {
  1242. splash_display->pipe_cnt++;
  1243. } else {
  1244. SDE_ERROR("no pipe detected on LM-%d\n",
  1245. iter_lm.blk->id - LM_0);
  1246. return 0;
  1247. }
  1248. pp = to_sde_hw_pingpong(iter_pp.blk->hw);
  1249. if (pp && pp->ops.get_dsc_status &&
  1250. pp->ops.get_dsc_status(pp)) {
  1251. splash_display->dsc_ids[splash_display->dsc_cnt++] =
  1252. iter_pp.blk->id;
  1253. SDE_DEBUG("lm/pp[%d] path, using dsc[%d]\n",
  1254. iter_lm.blk->id - LM_0,
  1255. iter_pp.blk->id - DSC_0);
  1256. }
  1257. }
  1258. return splash_display->lm_cnt;
  1259. }
  1260. int sde_rm_cont_splash_res_init(struct msm_drm_private *priv,
  1261. struct sde_rm *rm,
  1262. struct sde_splash_data *splash_data,
  1263. struct sde_mdss_cfg *cat)
  1264. {
  1265. struct sde_rm_hw_iter iter_c;
  1266. int index = 0, ctl_top_cnt;
  1267. struct sde_kms *sde_kms = NULL;
  1268. struct sde_hw_mdp *hw_mdp;
  1269. struct sde_splash_display *splash_display;
  1270. u8 intf_sel;
  1271. if (!priv || !rm || !cat || !splash_data) {
  1272. SDE_ERROR("invalid input parameters\n");
  1273. return -EINVAL;
  1274. }
  1275. SDE_DEBUG("mixer_count=%d, ctl_count=%d, dsc_count=%d\n",
  1276. cat->mixer_count,
  1277. cat->ctl_count,
  1278. cat->dsc_count);
  1279. ctl_top_cnt = cat->ctl_count;
  1280. if (!priv->kms) {
  1281. SDE_ERROR("invalid kms\n");
  1282. return -EINVAL;
  1283. }
  1284. sde_kms = to_sde_kms(priv->kms);
  1285. hw_mdp = sde_rm_get_mdp(rm);
  1286. sde_rm_init_hw_iter(&iter_c, 0, SDE_HW_BLK_CTL);
  1287. while (_sde_rm_get_hw_locked(rm, &iter_c)
  1288. && (index < splash_data->num_splash_displays)) {
  1289. struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter_c.blk->hw);
  1290. if (!ctl->ops.get_ctl_intf) {
  1291. SDE_ERROR("get_ctl_intf not initialized\n");
  1292. return -EINVAL;
  1293. }
  1294. intf_sel = ctl->ops.get_ctl_intf(ctl);
  1295. if (intf_sel) {
  1296. splash_display = &splash_data->splash_display[index];
  1297. SDE_DEBUG("finding resources for display=%d ctl=%d\n",
  1298. index, iter_c.blk->id - CTL_0);
  1299. _sde_rm_get_hw_blk_for_cont_splash(rm,
  1300. ctl, splash_display);
  1301. splash_display->cont_splash_enabled = true;
  1302. splash_display->ctl_ids[splash_display->ctl_cnt++] =
  1303. iter_c.blk->id;
  1304. }
  1305. index++;
  1306. }
  1307. return 0;
  1308. }
  1309. static int _sde_rm_populate_requirements(
  1310. struct sde_rm *rm,
  1311. struct drm_encoder *enc,
  1312. struct drm_crtc_state *crtc_state,
  1313. struct drm_connector_state *conn_state,
  1314. struct sde_rm_requirements *reqs)
  1315. {
  1316. const struct drm_display_mode *mode = &crtc_state->mode;
  1317. int i;
  1318. memset(reqs, 0, sizeof(*reqs));
  1319. reqs->top_ctrl = sde_connector_get_property(conn_state,
  1320. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  1321. sde_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state);
  1322. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) {
  1323. if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
  1324. reqs->hw_res.topology)) {
  1325. reqs->topology = &rm->topology_tbl[i];
  1326. break;
  1327. }
  1328. }
  1329. if (!reqs->topology) {
  1330. SDE_ERROR("invalid topology for the display\n");
  1331. return -EINVAL;
  1332. }
  1333. /*
  1334. * select dspp HW block for all dsi displays and ds for only
  1335. * primary dsi display.
  1336. */
  1337. if (conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI) {
  1338. if (!RM_RQ_DSPP(reqs))
  1339. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP);
  1340. if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler &&
  1341. sde_encoder_is_primary_display(enc))
  1342. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DS);
  1343. }
  1344. /**
  1345. * Set the requirement for LM which has CWB support if CWB is
  1346. * found enabled.
  1347. */
  1348. if (!RM_RQ_CWB(reqs) && sde_encoder_in_clone_mode(enc)) {
  1349. reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_CWB);
  1350. /*
  1351. * topology selection based on conn mode is not valid for CWB
  1352. * as WB conn populates modes based on max_mixer_width check
  1353. * but primary can be using dual LMs. This topology override for
  1354. * CWB is to check number of datapath active in primary and
  1355. * allocate same number of LM/PP blocks reserved for CWB
  1356. */
  1357. reqs->topology =
  1358. &rm->topology_tbl[SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE];
  1359. if (sde_crtc_get_num_datapath(crtc_state->crtc) == 1)
  1360. reqs->topology =
  1361. &rm->topology_tbl[SDE_RM_TOPOLOGY_SINGLEPIPE];
  1362. }
  1363. SDE_DEBUG("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl,
  1364. reqs->hw_res.display_num_of_h_tiles);
  1365. SDE_DEBUG("num_lm: %d num_ctl: %d topology: %d split_display: %d\n",
  1366. reqs->topology->num_lm, reqs->topology->num_ctl,
  1367. reqs->topology->top_name,
  1368. reqs->topology->needs_split_display);
  1369. SDE_EVT32(mode->hdisplay, rm->lm_max_width, reqs->topology->num_lm,
  1370. reqs->top_ctrl, reqs->topology->top_name,
  1371. reqs->topology->num_ctl);
  1372. return 0;
  1373. }
  1374. static struct sde_rm_rsvp *_sde_rm_get_rsvp(
  1375. struct sde_rm *rm,
  1376. struct drm_encoder *enc)
  1377. {
  1378. struct sde_rm_rsvp *i;
  1379. if (!rm || !enc) {
  1380. SDE_ERROR("invalid params\n");
  1381. return NULL;
  1382. }
  1383. if (list_empty(&rm->rsvps))
  1384. return NULL;
  1385. list_for_each_entry(i, &rm->rsvps, list)
  1386. if (i->enc_id == enc->base.id)
  1387. return i;
  1388. return NULL;
  1389. }
  1390. static struct sde_rm_rsvp *_sde_rm_get_rsvp_nxt(
  1391. struct sde_rm *rm,
  1392. struct drm_encoder *enc)
  1393. {
  1394. struct sde_rm_rsvp *i;
  1395. if (list_empty(&rm->rsvps))
  1396. return NULL;
  1397. list_for_each_entry(i, &rm->rsvps, list)
  1398. if (i->enc_id == enc->base.id)
  1399. break;
  1400. list_for_each_entry_continue(i, &rm->rsvps, list)
  1401. if (i->enc_id == enc->base.id)
  1402. return i;
  1403. return NULL;
  1404. }
  1405. static struct drm_connector *_sde_rm_get_connector(
  1406. struct drm_encoder *enc)
  1407. {
  1408. struct drm_connector *conn = NULL;
  1409. struct list_head *connector_list =
  1410. &enc->dev->mode_config.connector_list;
  1411. list_for_each_entry(conn, connector_list, head)
  1412. if (conn->encoder == enc)
  1413. return conn;
  1414. return NULL;
  1415. }
  1416. int sde_rm_update_topology(struct drm_connector_state *conn_state,
  1417. struct msm_display_topology *topology)
  1418. {
  1419. int i, ret = 0;
  1420. struct msm_display_topology top;
  1421. enum sde_rm_topology_name top_name = SDE_RM_TOPOLOGY_NONE;
  1422. if (!conn_state)
  1423. return -EINVAL;
  1424. if (topology) {
  1425. top = *topology;
  1426. for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
  1427. if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], top)) {
  1428. top_name = g_top_table[i].top_name;
  1429. break;
  1430. }
  1431. }
  1432. ret = msm_property_set_property(
  1433. sde_connector_get_propinfo(conn_state->connector),
  1434. sde_connector_get_property_state(conn_state),
  1435. CONNECTOR_PROP_TOPOLOGY_NAME, top_name);
  1436. return ret;
  1437. }
  1438. /**
  1439. * _sde_rm_release_rsvp - release resources and release a reservation
  1440. * @rm: KMS handle
  1441. * @rsvp: RSVP pointer to release and release resources for
  1442. */
  1443. static void _sde_rm_release_rsvp(
  1444. struct sde_rm *rm,
  1445. struct sde_rm_rsvp *rsvp,
  1446. struct drm_connector *conn)
  1447. {
  1448. struct sde_rm_rsvp *rsvp_c, *rsvp_n;
  1449. struct sde_rm_hw_blk *blk;
  1450. enum sde_hw_blk_type type;
  1451. if (!rsvp)
  1452. return;
  1453. SDE_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id);
  1454. list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) {
  1455. if (rsvp == rsvp_c) {
  1456. list_del(&rsvp_c->list);
  1457. break;
  1458. }
  1459. }
  1460. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  1461. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  1462. if (blk->rsvp == rsvp) {
  1463. blk->rsvp = NULL;
  1464. SDE_DEBUG("rel rsvp %d enc %d %d %d\n",
  1465. rsvp->seq, rsvp->enc_id,
  1466. blk->type, blk->id);
  1467. }
  1468. if (blk->rsvp_nxt == rsvp) {
  1469. blk->rsvp_nxt = NULL;
  1470. SDE_DEBUG("rel rsvp_nxt %d enc %d %d %d\n",
  1471. rsvp->seq, rsvp->enc_id,
  1472. blk->type, blk->id);
  1473. }
  1474. }
  1475. }
  1476. kfree(rsvp);
  1477. }
  1478. void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
  1479. {
  1480. struct sde_rm_rsvp *rsvp;
  1481. struct drm_connector *conn;
  1482. struct msm_drm_private *priv;
  1483. struct sde_kms *sde_kms;
  1484. uint64_t top_ctrl;
  1485. if (!rm || !enc) {
  1486. SDE_ERROR("invalid params\n");
  1487. return;
  1488. }
  1489. priv = enc->dev->dev_private;
  1490. if (!priv->kms) {
  1491. SDE_ERROR("invalid kms\n");
  1492. return;
  1493. }
  1494. sde_kms = to_sde_kms(priv->kms);
  1495. mutex_lock(&rm->rm_lock);
  1496. if (nxt)
  1497. rsvp = _sde_rm_get_rsvp_nxt(rm, enc);
  1498. else
  1499. rsvp = _sde_rm_get_rsvp(rm, enc);
  1500. if (!rsvp) {
  1501. SDE_DEBUG("failed to find rsvp for enc %d, nxt %d",
  1502. enc->base.id, nxt);
  1503. goto end;
  1504. }
  1505. if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
  1506. _sde_rm_release_rsvp(rm, rsvp, conn);
  1507. goto end;
  1508. }
  1509. conn = _sde_rm_get_connector(enc);
  1510. if (!conn) {
  1511. SDE_ERROR("failed to get connector for enc %d, nxt %d",
  1512. enc->base.id, nxt);
  1513. goto end;
  1514. }
  1515. top_ctrl = sde_connector_get_property(conn->state,
  1516. CONNECTOR_PROP_TOPOLOGY_CONTROL);
  1517. if (top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) {
  1518. SDE_DEBUG("rsvp[s%de%d] not releasing locked resources\n",
  1519. rsvp->seq, rsvp->enc_id);
  1520. } else {
  1521. SDE_DEBUG("release rsvp[s%de%d]\n", rsvp->seq,
  1522. rsvp->enc_id);
  1523. _sde_rm_release_rsvp(rm, rsvp, conn);
  1524. }
  1525. end:
  1526. mutex_unlock(&rm->rm_lock);
  1527. }
  1528. static int _sde_rm_commit_rsvp(
  1529. struct sde_rm *rm,
  1530. struct sde_rm_rsvp *rsvp,
  1531. struct drm_connector_state *conn_state)
  1532. {
  1533. struct sde_rm_hw_blk *blk;
  1534. enum sde_hw_blk_type type;
  1535. int ret = 0;
  1536. /* Swap next rsvp to be the active */
  1537. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  1538. list_for_each_entry(blk, &rm->hw_blks[type], list) {
  1539. if (blk->rsvp_nxt) {
  1540. blk->rsvp = blk->rsvp_nxt;
  1541. blk->rsvp_nxt = NULL;
  1542. }
  1543. }
  1544. }
  1545. if (!ret) {
  1546. SDE_DEBUG("rsrv enc %d topology %d\n", rsvp->enc_id,
  1547. rsvp->topology);
  1548. SDE_EVT32(rsvp->enc_id, rsvp->topology);
  1549. }
  1550. return ret;
  1551. }
  1552. int sde_rm_reserve(
  1553. struct sde_rm *rm,
  1554. struct drm_encoder *enc,
  1555. struct drm_crtc_state *crtc_state,
  1556. struct drm_connector_state *conn_state,
  1557. bool test_only)
  1558. {
  1559. struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
  1560. struct sde_rm_requirements reqs;
  1561. struct msm_drm_private *priv;
  1562. struct sde_kms *sde_kms;
  1563. int ret;
  1564. if (!rm || !enc || !crtc_state || !conn_state) {
  1565. SDE_ERROR("invalid arguments\n");
  1566. return -EINVAL;
  1567. }
  1568. if (!enc->dev || !enc->dev->dev_private) {
  1569. SDE_ERROR("drm device invalid\n");
  1570. return -EINVAL;
  1571. }
  1572. priv = enc->dev->dev_private;
  1573. if (!priv->kms) {
  1574. SDE_ERROR("invalid kms\n");
  1575. return -EINVAL;
  1576. }
  1577. sde_kms = to_sde_kms(priv->kms);
  1578. /* Check if this is just a page-flip */
  1579. if (!_sde_rm_is_display_in_cont_splash(sde_kms, enc) &&
  1580. !drm_atomic_crtc_needs_modeset(crtc_state))
  1581. return 0;
  1582. SDE_DEBUG("reserving hw for conn %d enc %d crtc %d test_only %d\n",
  1583. conn_state->connector->base.id, enc->base.id,
  1584. crtc_state->crtc->base.id, test_only);
  1585. SDE_EVT32(enc->base.id, conn_state->connector->base.id);
  1586. mutex_lock(&rm->rm_lock);
  1587. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_BEGIN);
  1588. rsvp_cur = _sde_rm_get_rsvp(rm, enc);
  1589. rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
  1590. if (!test_only && rsvp_nxt)
  1591. goto commit_rsvp;
  1592. ret = _sde_rm_populate_requirements(rm, enc, crtc_state,
  1593. conn_state, &reqs);
  1594. if (ret) {
  1595. SDE_ERROR("failed to populate hw requirements\n");
  1596. goto end;
  1597. }
  1598. /*
  1599. * We only support one active reservation per-hw-block. But to implement
  1600. * transactional semantics for test-only, and for allowing failure while
  1601. * modifying your existing reservation, over the course of this
  1602. * function we can have two reservations:
  1603. * Current: Existing reservation
  1604. * Next: Proposed reservation. The proposed reservation may fail, or may
  1605. * be discarded if in test-only mode.
  1606. * If reservation is successful, and we're not in test-only, then we
  1607. * replace the current with the next.
  1608. */
  1609. rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL);
  1610. if (!rsvp_nxt) {
  1611. ret = -ENOMEM;
  1612. goto end;
  1613. }
  1614. /*
  1615. * User can request that we clear out any reservation during the
  1616. * atomic_check phase by using this CLEAR bit
  1617. */
  1618. if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) {
  1619. SDE_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n",
  1620. rsvp_cur->seq, rsvp_cur->enc_id);
  1621. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  1622. rsvp_cur = NULL;
  1623. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_CLEAR);
  1624. }
  1625. /* Check the proposed reservation, store it in hw's "next" field */
  1626. ret = _sde_rm_make_next_rsvp(rm, enc, crtc_state, conn_state,
  1627. rsvp_nxt, &reqs);
  1628. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_RSVPNEXT);
  1629. if (ret) {
  1630. SDE_ERROR("failed to reserve hw resources: %d, test_only %d\n",
  1631. ret, test_only);
  1632. _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
  1633. goto end;
  1634. } else if (test_only && !RM_RQ_LOCK(&reqs)) {
  1635. /*
  1636. * Normally, if test_only, test the reservation and then undo
  1637. * However, if the user requests LOCK, then keep the reservation
  1638. * made during the atomic_check phase.
  1639. */
  1640. SDE_DEBUG("test_only: rsvp[s%de%d]\n",
  1641. rsvp_nxt->seq, rsvp_nxt->enc_id);
  1642. goto end;
  1643. } else {
  1644. if (test_only && RM_RQ_LOCK(&reqs))
  1645. SDE_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n",
  1646. rsvp_nxt->seq, rsvp_nxt->enc_id);
  1647. }
  1648. commit_rsvp:
  1649. _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
  1650. ret = _sde_rm_commit_rsvp(rm, rsvp_nxt, conn_state);
  1651. end:
  1652. _sde_rm_print_rsvps(rm, SDE_RM_STAGE_FINAL);
  1653. mutex_unlock(&rm->rm_lock);
  1654. return ret;
  1655. }
  1656. int sde_rm_ext_blk_create_reserve(struct sde_rm *rm,
  1657. struct sde_hw_blk *hw, struct drm_encoder *enc)
  1658. {
  1659. struct sde_rm_hw_blk *blk;
  1660. struct sde_rm_rsvp *rsvp;
  1661. int ret = 0;
  1662. if (!rm || !hw || !enc) {
  1663. SDE_ERROR("invalid parameters\n");
  1664. return -EINVAL;
  1665. }
  1666. if (hw->type >= SDE_HW_BLK_MAX) {
  1667. SDE_ERROR("invalid HW type\n");
  1668. return -EINVAL;
  1669. }
  1670. mutex_lock(&rm->rm_lock);
  1671. rsvp = _sde_rm_get_rsvp(rm, enc);
  1672. if (!rsvp) {
  1673. rsvp = kzalloc(sizeof(*rsvp), GFP_KERNEL);
  1674. if (!rsvp) {
  1675. ret = -ENOMEM;
  1676. goto end;
  1677. }
  1678. rsvp->seq = ++rm->rsvp_next_seq;
  1679. rsvp->enc_id = enc->base.id;
  1680. list_add_tail(&rsvp->list, &rm->rsvps);
  1681. SDE_DEBUG("create rsvp %d for enc %d\n",
  1682. rsvp->seq, rsvp->enc_id);
  1683. }
  1684. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  1685. if (!blk) {
  1686. ret = -ENOMEM;
  1687. goto end;
  1688. }
  1689. blk->type = hw->type;
  1690. blk->id = hw->id;
  1691. blk->hw = hw;
  1692. blk->rsvp = rsvp;
  1693. list_add_tail(&blk->list, &rm->hw_blks[hw->type]);
  1694. SDE_DEBUG("create blk %d %d for rsvp %d enc %d\n", blk->type, blk->id,
  1695. rsvp->seq, rsvp->enc_id);
  1696. end:
  1697. mutex_unlock(&rm->rm_lock);
  1698. return ret;
  1699. }
  1700. int sde_rm_ext_blk_destroy(struct sde_rm *rm,
  1701. struct drm_encoder *enc)
  1702. {
  1703. struct sde_rm_hw_blk *blk = NULL, *p;
  1704. struct sde_rm_rsvp *rsvp;
  1705. enum sde_hw_blk_type type;
  1706. int ret = 0;
  1707. if (!rm || !enc) {
  1708. SDE_ERROR("invalid parameters\n");
  1709. return -EINVAL;
  1710. }
  1711. mutex_lock(&rm->rm_lock);
  1712. rsvp = _sde_rm_get_rsvp(rm, enc);
  1713. if (!rsvp) {
  1714. ret = -ENOENT;
  1715. SDE_ERROR("failed to find rsvp for enc %d\n", enc->base.id);
  1716. goto end;
  1717. }
  1718. for (type = 0; type < SDE_HW_BLK_MAX; type++) {
  1719. list_for_each_entry_safe(blk, p, &rm->hw_blks[type], list) {
  1720. if (blk->rsvp == rsvp) {
  1721. list_del(&blk->list);
  1722. SDE_DEBUG("del blk %d %d from rsvp %d enc %d\n",
  1723. blk->type, blk->id,
  1724. rsvp->seq, rsvp->enc_id);
  1725. kfree(blk);
  1726. }
  1727. }
  1728. }
  1729. SDE_DEBUG("del rsvp %d\n", rsvp->seq);
  1730. list_del(&rsvp->list);
  1731. kfree(rsvp);
  1732. end:
  1733. mutex_unlock(&rm->rm_lock);
  1734. return ret;
  1735. }