sde_rm.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __SDE_RM_H__
  6. #define __SDE_RM_H__
  7. #include <linux/list.h>
  8. #include "msm_kms.h"
  9. #include "sde_hw_top.h"
  10. #define SINGLE_CTL 1
  11. #define DUAL_CTL 2
  12. #define TOPOLOGY_SINGLEPIPE_MODE(x) \
  13. (x == SDE_RM_TOPOLOGY_SINGLEPIPE ||\
  14. x == SDE_RM_TOPOLOGY_SINGLEPIPE_DSC ||\
  15. x == SDE_RM_TOPOLOGY_SINGLEPIPE_VDC)
  16. #define TOPOLOGY_DUALPIPE_MODE(x) \
  17. (x == SDE_RM_TOPOLOGY_DUALPIPE ||\
  18. x == SDE_RM_TOPOLOGY_DUALPIPE_DSC ||\
  19. x == SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE ||\
  20. x == SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE ||\
  21. x == SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_VDC ||\
  22. x == SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC)
  23. #define TOPOLOGY_QUADPIPE_MODE(x) \
  24. (x == SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE ||\
  25. x == SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE_DSC ||\
  26. x == SDE_RM_TOPOLOGY_QUADPIPE_DSCMERGE ||\
  27. x == SDE_RM_TOPOLOGY_QUADPIPE_DSC4HSMERGE)
  28. #define TOPOLOGY_DSC_MODE(x) \
  29. (x == SDE_RM_TOPOLOGY_SINGLEPIPE_DSC ||\
  30. x == SDE_RM_TOPOLOGY_DUALPIPE_DSC ||\
  31. x == SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC ||\
  32. x == SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE ||\
  33. x == SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE_DSC ||\
  34. x == SDE_RM_TOPOLOGY_QUADPIPE_DSCMERGE ||\
  35. x == SDE_RM_TOPOLOGY_QUADPIPE_DSC4HSMERGE)
  36. /**
  37. * enum sde_rm_topology_name - HW resource use case in use by connector
  38. * @SDE_RM_TOPOLOGY_NONE: No topology in use currently
  39. * @SDE_RM_TOPOLOGY_SINGLEPIPE: 1 LM, 1 PP, 1 INTF/WB
  40. * @SDE_RM_TOPOLOGY_SINGLEPIPE_DSC: 1 LM, 1 DSC, 1 PP, 1 INTF/WB
  41. * @SDE_RM_TOPOLOGY_SINGLEPIPE_VDC: 1 LM, 1 VDC, 1 PP, 1 INTF/WB
  42. * @SDE_RM_TOPOLOGY_DUALPIPE: 2 LM, 2 PP, 2 INTF/WB
  43. * @SDE_RM_TOPOLOGY_DUALPIPE_DSC: 2 LM, 2 DSC, 2 PP, 2 INTF/WB
  44. * @SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE: 2 LM, 2 PP, 3DMux, 1 INTF/WB
  45. * @SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC: 2 LM, 2 PP, 3DMux, 1 DSC, 1 INTF/WB
  46. * @SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_VDC: 2 LM, 2 PP, 3DMux, 1 VDC, 1 INTF/WB
  47. * @SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE: 2 LM, 2 PP, 2 DSC Merge, 1 INTF/WB
  48. * @SDE_RM_TOPOLOGY_PPSPLIT: 1 LM, 2 PPs, 2 INTF/WB
  49. * @SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE 4 LM, 4 PP, 3DMux, 2 INTF
  50. * @SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE_DSC 4 LM, 4 PP, 3DMux, 3 DSC, 2 INTF
  51. * @SDE_RM_TOPOLOGY_QUADPIPE_DSCMERE 4 LM, 4 PP, 4 DSC Merge, 2 INTF
  52. * @SDE_RM_TOPOLOGY_QUADPIPE_DSC4HSMERGE 4 LM, 4 PP, 4 DSC Merge, 1 INTF
  53. */
  54. enum sde_rm_topology_name {
  55. SDE_RM_TOPOLOGY_NONE = 0,
  56. SDE_RM_TOPOLOGY_SINGLEPIPE,
  57. SDE_RM_TOPOLOGY_SINGLEPIPE_DSC,
  58. SDE_RM_TOPOLOGY_SINGLEPIPE_VDC,
  59. SDE_RM_TOPOLOGY_DUALPIPE,
  60. SDE_RM_TOPOLOGY_DUALPIPE_DSC,
  61. SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE,
  62. SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC,
  63. SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_VDC,
  64. SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE,
  65. SDE_RM_TOPOLOGY_PPSPLIT,
  66. SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE,
  67. SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE_DSC,
  68. SDE_RM_TOPOLOGY_QUADPIPE_DSCMERGE,
  69. SDE_RM_TOPOLOGY_QUADPIPE_DSC4HSMERGE,
  70. SDE_RM_TOPOLOGY_MAX,
  71. };
  72. /**
  73. * enum sde_rm_topology_group - Topology group selection
  74. * @SDE_RM_TOPOLOGY_GROUP_NONE: No topology group in use currently
  75. * @SDE_RM_TOPOLOGY_GROUP_SINGLEPIPE: Any topology that uses 1 LM
  76. * @SDE_RM_TOPOLOGY_GROUP_DUALPIPE: Any topology that uses 2 LM
  77. * @SDE_RM_TOPOLOGY_GROUP_QUADPIPE: Any topology that uses 4 LM
  78. * @SDE_RM_TOPOLOGY_GROUP_3DMERGE: Any topology that uses 3D merge only
  79. * @SDE_RM_TOPOLOGY_GROUP_3DMERGE_DSC: Any topology that uses 3D merge + DSC
  80. * @SDE_RM_TOPOLOGY_GROUP_DSCMERGE: Any topology that uses DSC merge
  81. */
  82. enum sde_rm_topology_group {
  83. SDE_RM_TOPOLOGY_GROUP_NONE = 0,
  84. SDE_RM_TOPOLOGY_GROUP_SINGLEPIPE,
  85. SDE_RM_TOPOLOGY_GROUP_DUALPIPE,
  86. SDE_RM_TOPOLOGY_GROUP_QUADPIPE,
  87. SDE_RM_TOPOLOGY_GROUP_3DMERGE,
  88. SDE_RM_TOPOLOGY_GROUP_3DMERGE_DSC,
  89. SDE_RM_TOPOLOGY_GROUP_DSCMERGE,
  90. SDE_RM_TOPOLOGY_GROUP_MAX,
  91. };
  92. /**
  93. * enum sde_rm_topology_control - HW resource use case in use by connector
  94. * @SDE_RM_TOPCTL_RESERVE_LOCK: If set, in AtomicTest phase, after a successful
  95. * test, reserve the resources for this display.
  96. * Normal behavior would not impact the reservation
  97. * list during the AtomicTest phase.
  98. * @SDE_RM_TOPCTL_RESERVE_CLEAR: If set, in AtomicTest phase, before testing,
  99. * release any reservation held by this display.
  100. * Normal behavior would not impact the
  101. * reservation list during the AtomicTest phase.
  102. * @SDE_RM_TOPCTL_DSPP: Require layer mixers with DSPP capabilities
  103. * @SDE_RM_TOPCTL_DS : Require layer mixers with DS capabilities
  104. * @SDE_RM_TOPCTL_CWB : Require layer mixers with CWB capabilities
  105. * @SDE_RM_TOPCTL_DCWB : Require layer mixers with DCWB capabilities
  106. */
  107. enum sde_rm_topology_control {
  108. SDE_RM_TOPCTL_RESERVE_LOCK,
  109. SDE_RM_TOPCTL_RESERVE_CLEAR,
  110. SDE_RM_TOPCTL_DSPP,
  111. SDE_RM_TOPCTL_DS,
  112. SDE_RM_TOPCTL_CWB,
  113. SDE_RM_TOPCTL_DCWB,
  114. };
  115. /**
  116. * enum sde_rm_topology_control - HW resource use case in use by connector
  117. * @SDE_RM_QSYNC_DISABLED: If set, Qsync feature is supported and in
  118. * disable state.
  119. * @SDE_RM_QSYNC_CONTINUOUS_MODE: If set, Qsync is enabled in continuous
  120. * mode.
  121. * @SDE_RM_QSYNC_ONE_SHOT_MODE: If set, Qsync is enabled in one shot mode.
  122. *
  123. */
  124. enum sde_rm_qsync_modes {
  125. SDE_RM_QSYNC_DISABLED,
  126. SDE_RM_QSYNC_CONTINUOUS_MODE,
  127. SDE_RM_QSYNC_ONE_SHOT_MODE
  128. };
  129. /**
  130. * struct sde_rm_topology_def - Topology table definition
  131. * @top_name: name identifying this topology
  132. * @num_lm: number of layer mixers used
  133. * @num_comp_enc: number of encoders used
  134. * @num_intf: number of interface used
  135. * @num_ctl: number of control path used
  136. * @needs_split_display: If set split display is enabled
  137. * @comp_type: type of compression supported
  138. */
  139. struct sde_rm_topology_def {
  140. enum sde_rm_topology_name top_name;
  141. int num_lm;
  142. int num_comp_enc;
  143. int num_intf;
  144. int num_ctl;
  145. bool needs_split_display;
  146. enum msm_display_compression_type comp_type;
  147. };
  148. /**
  149. * struct sde_rm - SDE dynamic hardware resource manager
  150. * @dev: device handle for event logging purposes
  151. * @rsvps: list of hardware reservations by each crtc->encoder->connector
  152. * @hw_blks: array of lists of hardware resources present in the system, one
  153. * list per type of hardware block
  154. * @hw_mdp: hardware object for mdp_top
  155. * @lm_max_width: cached layer mixer maximum width
  156. * @rsvp_next_seq: sequence number for next reservation for debugging purposes
  157. * @rm_lock: resource manager mutex
  158. * @avail_res: Pointer with curr available resources
  159. */
  160. struct sde_rm {
  161. struct drm_device *dev;
  162. struct list_head rsvps;
  163. struct list_head hw_blks[SDE_HW_BLK_MAX];
  164. struct sde_hw_mdp *hw_mdp;
  165. uint32_t lm_max_width;
  166. uint32_t rsvp_next_seq;
  167. struct mutex rm_lock;
  168. const struct sde_rm_topology_def *topology_tbl;
  169. struct msm_resource_caps_info avail_res;
  170. };
  171. /**
  172. * struct sde_rm_hw_blk - resource manager internal structure
  173. * forward declaration for single iterator definition without void pointer
  174. */
  175. struct sde_rm_hw_blk;
  176. /**
  177. * struct sde_rm_hw_iter - iterator for use with sde_rm
  178. * @hw: sde_hw object requested, or NULL on failure
  179. * @blk: sde_rm internal block representation. Clients ignore. Used as iterator.
  180. * @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder
  181. * @type: Hardware Block Type client wishes to search for.
  182. */
  183. struct sde_rm_hw_iter {
  184. void *hw;
  185. struct sde_rm_hw_blk *blk;
  186. uint32_t enc_id;
  187. enum sde_hw_blk_type type;
  188. };
  189. /**
  190. * struct sde_rm_hw_request - data for requesting hw blk
  191. * @hw: sde_hw object requested, or NULL on failure
  192. * @type: Hardware Block Type client wishes to search for
  193. * @id: Hardware block id
  194. */
  195. struct sde_rm_hw_request {
  196. void *hw;
  197. enum sde_hw_blk_type type;
  198. int id;
  199. };
  200. /**
  201. * sde_rm_get_topology_name - get the name of the given topology config
  202. * @rm: SDE resource manager handle
  203. * @topology: msm_display_topology topology config
  204. * @Return: name of the given topology
  205. */
  206. enum sde_rm_topology_name sde_rm_get_topology_name(struct sde_rm *rm,
  207. struct msm_display_topology topology);
  208. /**
  209. * sde_rm_debugfs_init - setup debugfs node for rm module
  210. * @rm: SDE resource manager handle
  211. * @parent: debugfs parent directory node
  212. */
  213. void sde_rm_debugfs_init(struct sde_rm *rm, struct dentry *parent);
  214. /**
  215. * sde_rm_init - Read hardware catalog and create reservation tracking objects
  216. * for all HW blocks.
  217. * @rm: SDE Resource Manager handle
  218. * @cat: Pointer to hardware catalog
  219. * @mmio: mapped register io address of MDP
  220. * @dev: device handle for event logging purposes
  221. * @Return: 0 on Success otherwise -ERROR
  222. */
  223. int sde_rm_init(struct sde_rm *rm,
  224. struct sde_mdss_cfg *cat,
  225. void __iomem *mmio,
  226. struct drm_device *dev);
  227. /**
  228. * sde_rm_destroy - Free all memory allocated by sde_rm_init
  229. * @rm: SDE Resource Manager handle
  230. * @Return: 0 on Success otherwise -ERROR
  231. */
  232. int sde_rm_destroy(struct sde_rm *rm);
  233. /**
  234. * sde_rm_reserve - Given a CRTC->Encoder->Connector display chain, analyze
  235. * the use connections and user requirements, specified through related
  236. * topology control properties, and reserve hardware blocks to that
  237. * display chain.
  238. * HW blocks can then be accessed through sde_rm_get_* functions.
  239. * HW Reservations should be released via sde_rm_release_hw.
  240. * @rm: SDE Resource Manager handle
  241. * @drm_enc: DRM Encoder handle
  242. * @crtc_state: Proposed Atomic DRM CRTC State handle
  243. * @conn_state: Proposed Atomic DRM Connector State handle
  244. * @test_only: Atomic-Test phase, discard results (unless property overrides)
  245. * @Return: 0 on Success otherwise -ERROR
  246. */
  247. int sde_rm_reserve(struct sde_rm *rm,
  248. struct drm_encoder *drm_enc,
  249. struct drm_crtc_state *crtc_state,
  250. struct drm_connector_state *conn_state,
  251. bool test_only);
  252. /**
  253. * sde_rm_release - Given the encoder for the display chain, release any
  254. * HW blocks previously reserved for that use case.
  255. * @rm: SDE Resource Manager handle
  256. * @enc: DRM Encoder handle
  257. * @nxt: Choose option to release rsvp_nxt
  258. * @Return: 0 on Success otherwise -ERROR
  259. */
  260. void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc, bool nxt);
  261. /**
  262. * sde_rm_get_mdp - Retrieve HW block for MDP TOP.
  263. * This is never reserved, and is usable by any display.
  264. * @rm: SDE Resource Manager handle
  265. * @Return: Pointer to hw block or NULL
  266. */
  267. struct sde_hw_mdp *sde_rm_get_mdp(struct sde_rm *rm);
  268. /**
  269. * sde_rm_init_hw_iter - setup given iterator for new iteration over hw list
  270. * using sde_rm_get_hw
  271. * @iter: iter object to initialize
  272. * @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder
  273. * @type: Hardware Block Type client wishes to search for.
  274. */
  275. void sde_rm_init_hw_iter(
  276. struct sde_rm_hw_iter *iter,
  277. uint32_t enc_id,
  278. enum sde_hw_blk_type type);
  279. /**
  280. * sde_rm_get_hw - retrieve reserved hw object given encoder and hw type
  281. * Meant to do a single pass through the hardware list to iteratively
  282. * retrieve hardware blocks of a given type for a given encoder.
  283. * Initialize an iterator object.
  284. * Set hw block type of interest. Set encoder id of interest, 0 for any.
  285. * Function returns first hw of type for that encoder.
  286. * Subsequent calls will return the next reserved hw of that type in-order.
  287. * Iterator HW pointer will be null on failure to find hw.
  288. * @rm: SDE Resource Manager handle
  289. * @iter: iterator object
  290. * @Return: true on match found, false on no match found
  291. */
  292. bool sde_rm_get_hw(struct sde_rm *rm, struct sde_rm_hw_iter *iter);
  293. /**
  294. * sde_rm_request_hw_blk - retrieve the requested hardware block
  295. * @rm: SDE Resource Manager handle
  296. * @hw: holds the input and output information of the requested hw block
  297. * @Return: true on match found, false on no match found
  298. */
  299. bool sde_rm_request_hw_blk(struct sde_rm *rm, struct sde_rm_hw_request *hw);
  300. /**
  301. * sde_rm_cont_splash_res_init - Read the current MDSS configuration
  302. * to update the splash data structure with the topology
  303. * configured by the bootloader.
  304. * @priv: DRM private structure handle
  305. * @rm: SDE Resource Manager handle
  306. * @splash_data: Pointer to the splash_data structure to be updated.
  307. * @cat: Pointer to the SDE catalog
  308. * @Return: 0 on success or error
  309. */
  310. int sde_rm_cont_splash_res_init(struct msm_drm_private *priv,
  311. struct sde_rm *rm,
  312. struct sde_splash_data *splash_data,
  313. struct sde_mdss_cfg *cat);
  314. /**
  315. * sde_rm_update_topology - sets topology property of the connector
  316. * @rm: SDE resource manager handle
  317. * @conn_state: drm state of the connector
  318. * @topology: topology selected for the display
  319. * @return: 0 on success or error
  320. */
  321. int sde_rm_update_topology(struct sde_rm *rm,
  322. struct drm_connector_state *conn_state,
  323. struct msm_display_topology *topology);
  324. /**
  325. * sde_rm_topology_get_topology_def - returns the information about num
  326. * of hw blocks used in this topology
  327. * @rm: SDE Resource Manager handle
  328. * @topology: topology selected for the display
  329. * @return: pointer to struct containing topology definition
  330. */
  331. static inline const struct sde_rm_topology_def*
  332. sde_rm_topology_get_topology_def(
  333. struct sde_rm *rm,
  334. enum sde_rm_topology_name topology)
  335. {
  336. if ((!rm) || (topology <= SDE_RM_TOPOLOGY_NONE) ||
  337. (topology >= SDE_RM_TOPOLOGY_MAX)) {
  338. pr_err("invalid arguments: rm:%d topology:%d\n",
  339. rm == NULL, topology);
  340. return ERR_PTR(-EINVAL);
  341. }
  342. return &rm->topology_tbl[topology];
  343. }
  344. /**
  345. * sde_rm_topology_get_num_lm - returns number of mixers
  346. * used for this topology
  347. * @rm: SDE Resource Manager handle
  348. * @topology: topology selected for the display
  349. * @return: number of lms
  350. */
  351. static inline int sde_rm_topology_get_num_lm(struct sde_rm *rm,
  352. enum sde_rm_topology_name topology)
  353. {
  354. if ((!rm) || (topology <= SDE_RM_TOPOLOGY_NONE) ||
  355. (topology >= SDE_RM_TOPOLOGY_MAX)) {
  356. pr_err("invalid arguments: rm:%d topology:%d\n",
  357. rm == NULL, topology);
  358. return -EINVAL;
  359. }
  360. return rm->topology_tbl[topology].num_lm;
  361. }
  362. /**
  363. * sde_rm_topology_is_group - check if the topology in use
  364. * is part of the requested group
  365. * @rm: SDE Resource Manager handle
  366. * @state: drm state of the crtc
  367. * @group: topology group to check
  368. * @return: true if attached connector is in the topology group
  369. */
  370. bool sde_rm_topology_is_group(struct sde_rm *rm,
  371. struct drm_crtc_state *state,
  372. enum sde_rm_topology_group group);
  373. /**
  374. * sde_rm_ext_blk_destroy - Given the encoder for the display chain, release
  375. * external HW blocks created for that.
  376. * @rm: SDE Resource Manager handle
  377. * @enc: DRM Encoder handle
  378. * @Return: 0 on Success otherwise -ERROR
  379. */
  380. int sde_rm_ext_blk_destroy(struct sde_rm *rm,
  381. struct drm_encoder *enc);
  382. /**
  383. * sde_rm_get_resource_info - returns avail hw resource info
  384. * @mr: sde rm object
  385. * @drm_enc: drm encoder object
  386. * @avail_res: out parameter, available resource object
  387. */
  388. void sde_rm_get_resource_info(struct sde_rm *rm,
  389. struct drm_encoder *drm_enc,
  390. struct msm_resource_caps_info *avail_res);
  391. #endif /* __SDE_RM_H__ */