sde_rm.h 12 KB

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