sde_rm.h 15 KB

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