sde_rsc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SDE_RSC_H_
  6. #define _SDE_RSC_H_
  7. #include <linux/kernel.h>
  8. /* primary display rsc index */
  9. #define SDE_RSC_INDEX 0
  10. #define MAX_RSC_CLIENT_NAME_LEN 128
  11. #define NUM_RSC_PROFILING_COUNTERS 3
  12. /* DRM Object IDs are numbered excluding 0, use 0 to indicate invalid CRTC */
  13. #define SDE_RSC_INVALID_CRTC_ID 0
  14. /**
  15. * event will be triggered before sde core power collapse,
  16. * mdss gdsc is still on
  17. */
  18. #define SDE_RSC_EVENT_PRE_CORE_PC 0x1
  19. /**
  20. * event will be triggered after sde core collapse complete,
  21. * mdss gdsc is off now
  22. */
  23. #define SDE_RSC_EVENT_POST_CORE_PC 0x2
  24. /**
  25. * event will be triggered before restoring the sde core from power collapse,
  26. * mdss gdsc is still off
  27. */
  28. #define SDE_RSC_EVENT_PRE_CORE_RESTORE 0x4
  29. /**
  30. * event will be triggered after restoring the sde core from power collapse,
  31. * mdss gdsc is on now
  32. */
  33. #define SDE_RSC_EVENT_POST_CORE_RESTORE 0x8
  34. /**
  35. * event attached with solver state enabled
  36. * all clients in clk_state or cmd_state
  37. */
  38. #define SDE_RSC_EVENT_SOLVER_ENABLED 0x10
  39. /**
  40. * event attached with solver state disabled
  41. * one of the client requested for vid state
  42. */
  43. #define SDE_RSC_EVENT_SOLVER_DISABLED 0x20
  44. /**
  45. * sde_rsc_client_type: sde rsc client type information
  46. * SDE_RSC_PRIMARY_DISP_CLIENT: A primary display client which can request
  47. * vid or cmd state switch.
  48. * SDE_RSC_EXTERNAL_DISPLAY_CLIENT:An external display client which can
  49. * request only clk state switch.
  50. * SDE_RSC_CLK_CLIENT: A clk client request for only rsc clocks
  51. * enabled and mode_2 exit state.
  52. */
  53. enum sde_rsc_client_type {
  54. SDE_RSC_PRIMARY_DISP_CLIENT,
  55. SDE_RSC_EXTERNAL_DISP_CLIENT,
  56. SDE_RSC_CLK_CLIENT,
  57. SDE_RSC_INVALID_CLIENT,
  58. };
  59. /**
  60. * sde_rsc_state: sde rsc state information
  61. * SDE_RSC_IDLE_STATE: A client requests for idle state when there is no
  62. * pixel or cmd transfer expected. An idle vote from
  63. * all clients lead to power collapse state.
  64. * SDE_RSC_CLK_STATE: A client requests for clk state when it wants to
  65. * only avoid mode-2 entry/exit. For ex: V4L2 driver,
  66. * sde power handle, etc.
  67. * SDE_RSC_CMD_STATE: A client requests for cmd state when it wants to
  68. * enable the solver mode.
  69. * SDE_RSC_VID_STATE: A client requests for vid state it wants to avoid
  70. * solver enable because client is fetching data from
  71. * continuously.
  72. */
  73. enum sde_rsc_state {
  74. SDE_RSC_IDLE_STATE,
  75. SDE_RSC_CLK_STATE,
  76. SDE_RSC_CMD_STATE,
  77. SDE_RSC_VID_STATE,
  78. };
  79. /**
  80. * struct sde_rsc_client: stores the rsc client for sde driver
  81. * @name: name of the client
  82. * @current_state: current client state
  83. * @crtc_id: crtc_id associated with this rsc client.
  84. * @rsc_index: rsc index of a client - only index "0" valid.
  85. * @id: Index of client. It will be assigned during client_create call
  86. * @client_type: check sde_rsc_client_type information
  87. * @list: list to attach client master list
  88. */
  89. struct sde_rsc_client {
  90. char name[MAX_RSC_CLIENT_NAME_LEN];
  91. short current_state;
  92. int crtc_id;
  93. u32 rsc_index;
  94. u32 id;
  95. enum sde_rsc_client_type client_type;
  96. struct list_head list;
  97. };
  98. /**
  99. * struct sde_rsc_event: local event registration entry structure
  100. * @cb_func: Pointer to desired callback function
  101. * @usr: User pointer to pass to callback on event trigger
  102. * @rsc_index: rsc index of a client - only index "0" valid.
  103. * @event_type: refer comments in event_register
  104. * @list: list to attach event master list
  105. */
  106. struct sde_rsc_event {
  107. void (*cb_func)(uint32_t event_type, void *usr);
  108. void *usr;
  109. u32 rsc_index;
  110. uint32_t event_type;
  111. struct list_head list;
  112. };
  113. /**
  114. * struct sde_rsc_cmd_config: provides panel configuration to rsc
  115. * when client is command mode. It is not required to set it during
  116. * video mode.
  117. *
  118. * @fps: panel te interval
  119. * @vtotal: current vertical total (height + vbp + vfp)
  120. * @jitter_numer: panel jitter numerator value. This config causes rsc/solver
  121. * early before te. Default is 0.8% jitter.
  122. * @jitter_denom: panel jitter denominator.
  123. * @prefill_lines: max prefill lines based on panel
  124. */
  125. struct sde_rsc_cmd_config {
  126. u32 fps;
  127. u32 vtotal;
  128. u32 jitter_numer;
  129. u32 jitter_denom;
  130. u32 prefill_lines;
  131. };
  132. #if IS_ENABLED(CONFIG_DRM_SDE_RSC)
  133. /**
  134. * sde_rsc_client_create() - create the client for sde rsc.
  135. * Different displays like DSI, HDMI, DP, WB, etc should call this
  136. * api to register their vote for rpmh. They still need to vote for
  137. * power handle to get the clocks.
  138. * @rsc_index: A client will be created on this RSC. As of now only
  139. * SDE_RSC_INDEX is valid rsc index.
  140. * @name: Caller needs to provide some valid string to identify
  141. * the client. "primary", "dp", "hdmi" are suggested name.
  142. * @client_type: check client_type enum for information
  143. * @vsync_source: This parameter is only valid for primary display. It provides
  144. * vsync source information
  145. *
  146. * Return: client node pointer.
  147. */
  148. struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, char *name,
  149. enum sde_rsc_client_type client_type, u32 vsync_source);
  150. /**
  151. * sde_rsc_client_destroy() - Destroy the sde rsc client.
  152. *
  153. * @client: Client pointer provided by sde_rsc_client_create().
  154. *
  155. * Return: none
  156. */
  157. void sde_rsc_client_destroy(struct sde_rsc_client *client);
  158. /**
  159. * sde_rsc_client_state_update() - rsc client state update
  160. * Video mode, cmd mode and clk state are supported as modes. A client need to
  161. * set this property during panel time. A switching client can set the
  162. * property to change the state
  163. *
  164. * @client: Client pointer provided by sde_rsc_client_create().
  165. * @state: Client state - video/cmd
  166. * @config: fps, vtotal, porches, etc configuration for command mode
  167. * panel
  168. * @crtc_id: current client's crtc id
  169. * @wait_vblank_crtc_id: Output parameter. If set to non-zero, rsc hw
  170. * state update requires a wait for one vblank on
  171. * the primary crtc. In that case, this output
  172. * param will be set to the crtc on which to wait.
  173. * If SDE_RSC_INVALID_CRTC_ID, no wait necessary
  174. *
  175. * Return: error code.
  176. */
  177. int sde_rsc_client_state_update(struct sde_rsc_client *client,
  178. enum sde_rsc_state state,
  179. struct sde_rsc_cmd_config *config, int crtc_id,
  180. int *wait_vblank_crtc_id);
  181. /**
  182. * sde_rsc_client_get_vsync_refcount() - returns the status of the vsync
  183. * refcount, to signal if the client needs to reset the refcounting logic
  184. * @client: Client pointer provided by sde_rsc_client_create().
  185. *
  186. * Return: true if the state update has completed.
  187. */
  188. int sde_rsc_client_get_vsync_refcount(
  189. struct sde_rsc_client *caller_client);
  190. /**
  191. * sde_rsc_client_reset_vsync_refcount() - reduces the refcounting
  192. * logic that waits for the vsync.
  193. * @client: Client pointer provided by sde_rsc_client_create().
  194. *
  195. * Return: true if the state update has completed.
  196. */
  197. int sde_rsc_client_reset_vsync_refcount(
  198. struct sde_rsc_client *caller_client);
  199. /**
  200. * sde_rsc_client_is_state_update_complete() - check if state update is complete
  201. * RSC state transition is not complete until HW receives VBLANK signal. This
  202. * function checks RSC HW to determine whether that signal has been received.
  203. * @client: Client pointer provided by sde_rsc_client_create().
  204. *
  205. * Return: true if the state update has completed.
  206. */
  207. bool sde_rsc_client_is_state_update_complete(
  208. struct sde_rsc_client *caller_client);
  209. /**
  210. * sde_rsc_client_vote() - stores ab/ib vote for rsc client
  211. *
  212. * @client: Client pointer provided by sde_rsc_client_create().
  213. * @bus_id: data bus identifier
  214. * @ab: aggregated bandwidth vote from client.
  215. * @ib: instant bandwidth vote from client.
  216. *
  217. * Return: error code.
  218. */
  219. int sde_rsc_client_vote(struct sde_rsc_client *caller_client,
  220. u32 bus_id, u64 ab_vote, u64 ib_vote);
  221. /**
  222. * sde_rsc_register_event - register a callback function for an event
  223. * @rsc_index: A client will be created on this RSC. As of now only
  224. * SDE_RSC_INDEX is valid rsc index.
  225. * @event_type: event type to register; client sets 0x3 if it wants
  226. * to register for CORE_PC and CORE_RESTORE - both events.
  227. * @cb_func: Pointer to desired callback function
  228. * @usr: User pointer to pass to callback on event trigger
  229. * Returns: sde_rsc_event pointer on success
  230. */
  231. struct sde_rsc_event *sde_rsc_register_event(int rsc_index, uint32_t event_type,
  232. void (*cb_func)(uint32_t event_type, void *usr), void *usr);
  233. /**
  234. * sde_rsc_unregister_event - unregister callback for an event
  235. * @sde_rsc_event: event returned by sde_rsc_register_event
  236. */
  237. void sde_rsc_unregister_event(struct sde_rsc_event *event);
  238. /**
  239. * is_sde_rsc_available - check if display rsc available.
  240. * @rsc_index: A client will be created on this RSC. As of now only
  241. * SDE_RSC_INDEX is valid rsc index.
  242. * Returns: true if rsc is available; false in all other cases
  243. */
  244. bool is_sde_rsc_available(int rsc_index);
  245. /**
  246. * get_sde_rsc_current_state - gets the current state of sde rsc.
  247. * @rsc_index: A client will be created on this RSC. As of now only
  248. * SDE_RSC_INDEX is valid rsc index.
  249. * Returns: current state if rsc available; SDE_RSC_IDLE_STATE for
  250. * all other cases
  251. */
  252. enum sde_rsc_state get_sde_rsc_current_state(int rsc_index);
  253. /**
  254. * sde_rsc_client_trigger_vote() - triggers ab/ib vote for rsc client
  255. *
  256. * @client: Client pointer provided by sde_rsc_client_create().
  257. * @delta_vote: if bw vote is increased or decreased
  258. *
  259. * Return: error code.
  260. */
  261. int sde_rsc_client_trigger_vote(struct sde_rsc_client *caller_client,
  262. bool delta_vote);
  263. #else
  264. static inline struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index,
  265. char *name, enum sde_rsc_client_type client_type, u32 vsync_source)
  266. {
  267. return NULL;
  268. }
  269. static inline void sde_rsc_client_destroy(struct sde_rsc_client *client)
  270. {
  271. }
  272. static inline int sde_rsc_client_state_update(struct sde_rsc_client *client,
  273. enum sde_rsc_state state,
  274. struct sde_rsc_cmd_config *config, int crtc_id,
  275. int *wait_vblank_crtc_id)
  276. {
  277. return 0;
  278. }
  279. static inline int sde_rsc_client_get_vsync_refcount(
  280. struct sde_rsc_client *caller_client)
  281. {
  282. return 0;
  283. }
  284. static inline int sde_rsc_client_reset_vsync_refcount(
  285. struct sde_rsc_client *caller_client)
  286. {
  287. return 0;
  288. }
  289. static inline bool sde_rsc_client_is_state_update_complete(
  290. struct sde_rsc_client *caller_client)
  291. {
  292. return false;
  293. }
  294. static inline int sde_rsc_client_vote(struct sde_rsc_client *caller_client,
  295. u32 bus_id, u64 ab_vote, u64 ib_vote)
  296. {
  297. return 0;
  298. }
  299. static inline struct sde_rsc_event *sde_rsc_register_event(int rsc_index,
  300. uint32_t event_type,
  301. void (*cb_func)(uint32_t event_type, void *usr), void *usr)
  302. {
  303. return NULL;
  304. }
  305. static inline void sde_rsc_unregister_event(struct sde_rsc_event *event)
  306. {
  307. }
  308. static inline bool is_sde_rsc_available(int rsc_index)
  309. {
  310. return false;
  311. }
  312. static inline enum sde_rsc_state get_sde_rsc_current_state(int rsc_index)
  313. {
  314. return SDE_RSC_IDLE_STATE;
  315. }
  316. static inline int sde_rsc_client_trigger_vote(
  317. struct sde_rsc_client *caller_client, bool delta_vote)
  318. {
  319. return 0;
  320. }
  321. #endif /* CONFIG_DRM_SDE_RSC */
  322. #endif /* _SDE_RSC_H_ */