sde_rm.h 11 KB

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