sde_rm.h 13 KB

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