sde_rm.h 12 KB

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