sde_rsc_priv.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _SDE_RSC_PRIV_H_
  7. #define _SDE_RSC_PRIV_H_
  8. #include <linux/kernel.h>
  9. #include <linux/sde_io_util.h>
  10. #include <linux/sde_rsc.h>
  11. #include <soc/qcom/tcs.h>
  12. #include "sde_power_handle.h"
  13. #define SDE_RSC_COMPATIBLE "disp_rscc"
  14. #define MAX_RSC_COUNT 5
  15. #define ALL_MODES_DISABLED 0x0
  16. #define ONLY_MODE_0_ENABLED 0x1
  17. #define ONLY_MODE_0_1_ENABLED 0x3
  18. #define ALL_MODES_ENABLED 0x7
  19. #define MAX_COUNT_SIZE_SUPPORTED 128
  20. #define SDE_RSC_REV_1 0x1
  21. #define SDE_RSC_REV_2 0x2
  22. #define SDE_RSC_REV_3 0x3
  23. #define SDE_RSC_REV_4 0x4
  24. #define SDE_RSC_REV_5 0x5
  25. #define SDE_RSC_HW_MAJOR_MINOR_STEP(major, minor, step) \
  26. (((major & 0xff) << 16) |\
  27. ((minor & 0xff) << 8) | \
  28. (step & 0xff))
  29. struct sde_rsc_priv;
  30. /**
  31. * rsc_mode_req: sde rsc mode request information
  32. * MODE_READ: read vsync status
  33. * MODE_UPDATE: mode timeslot update
  34. * 0x0: all modes are disabled.
  35. * 0x1: Mode-0 is enabled and other two modes are disabled.
  36. * 0x3: Mode-0 & Mode-1 are enabled and mode-2 is disabled.
  37. * 0x7: all modes are enabled.
  38. */
  39. enum rsc_mode_req {
  40. MODE_READ,
  41. MODE_UPDATE = 0x1,
  42. };
  43. /**
  44. * rsc_vsync_req: sde rsc vsync request information
  45. * VSYNC_READ: read vsync status
  46. * VSYNC_READ_VSYNC0: read value vsync0 timestamp (cast to int from u32)
  47. * VSYNC_ENABLE: enable rsc wrapper vsync status
  48. * VSYNC_DISABLE: disable rsc wrapper vsync status
  49. */
  50. enum rsc_vsync_req {
  51. VSYNC_READ,
  52. VSYNC_READ_VSYNC0,
  53. VSYNC_ENABLE,
  54. VSYNC_DISABLE,
  55. };
  56. /**
  57. * struct sde_rsc_hw_ops - sde resource state coordinator hardware ops
  58. * @init: Initialize the sequencer, solver, qtimer,
  59. etc. hardware blocks on RSC.
  60. * @timer_update: update the static wrapper time and pdc/rsc
  61. backoff time.
  62. * @tcs_wait: Waits for TCS block OK to allow sending a
  63. * TCS command.
  64. * @hw_vsync: Enables the vsync on RSC block.
  65. * @tcs_use_ok: set TCS set to high to allow RSC to use it.
  66. * @bwi_status: It updates the BW increase/decrease status.
  67. * @debug_dump: dump debug bus registers or enable debug bus
  68. * @state_update: Enable/override the solver based on rsc state
  69. * status (command/video)
  70. * @debug_show: Show current debug status.
  71. * @mode_ctrl: shows current mode status, mode0/1/2
  72. * @setup_counters: Enable/disable RSC profiling counters
  73. * @get_counters: Get current status of profiling counters
  74. */
  75. struct sde_rsc_hw_ops {
  76. int (*init)(struct sde_rsc_priv *rsc);
  77. int (*timer_update)(struct sde_rsc_priv *rsc);
  78. int (*tcs_wait)(struct sde_rsc_priv *rsc);
  79. int (*hw_vsync)(struct sde_rsc_priv *rsc, enum rsc_vsync_req request,
  80. char *buffer, int buffer_size, u32 mode);
  81. int (*tcs_use_ok)(struct sde_rsc_priv *rsc);
  82. int (*bwi_status)(struct sde_rsc_priv *rsc);
  83. void (*debug_dump)(struct sde_rsc_priv *rsc, u32 mux_sel);
  84. int (*state_update)(struct sde_rsc_priv *rsc, enum sde_rsc_state state);
  85. int (*debug_show)(struct seq_file *s, struct sde_rsc_priv *rsc);
  86. int (*mode_ctrl)(struct sde_rsc_priv *rsc, enum rsc_mode_req request,
  87. char *buffer, int buffer_size, u32 mode);
  88. int (*setup_counters)(struct sde_rsc_priv *rsc, bool enable);
  89. int (*get_counters)(struct sde_rsc_priv *rsc, u32 *counters);
  90. };
  91. /**
  92. * struct sde_rsc_timer_config: this is internal configuration between
  93. * rsc and rsc_hw API.
  94. *
  95. * @static_wakeup_time_ns: wrapper backoff time in nano seconds
  96. * @rsc_backoff_time_ns: rsc backoff time in nano seconds
  97. * @pdc_backoff_time_ns: pdc backoff time in nano seconds
  98. * @rsc_mode_threshold_time_ns: rsc mode threshold time in nano seconds
  99. * @rsc_time_slot_0_ns: mode-0 time slot threshold in nano seconds
  100. * @rsc_time_slot_1_ns: mode-1 time slot threshold in nano seconds
  101. * @rsc_time_slot_2_ns: mode-2 time slot threshold in nano seconds
  102. *
  103. * @min_threshold_time_ns: minimum time required to enter & exit mode0
  104. * @bwi_threshold_time_ns: worst case time to increase the BW vote
  105. */
  106. struct sde_rsc_timer_config {
  107. u32 static_wakeup_time_ns;
  108. u32 rsc_backoff_time_ns;
  109. u32 pdc_backoff_time_ns;
  110. u32 rsc_mode_threshold_time_ns;
  111. u32 rsc_time_slot_0_ns;
  112. u32 rsc_time_slot_1_ns;
  113. u32 rsc_time_slot_2_ns;
  114. u32 min_threshold_time_ns;
  115. u32 bwi_threshold_time_ns;
  116. };
  117. /**
  118. * struct sde_rsc_bw_config: bandwidth configuration
  119. *
  120. * @ab_vote: Stored ab_vote for SDE_POWER_HANDLE_DBUS_ID_MAX
  121. * @ib_vote: Stored ib_vote for SDE_POWER_HANDLE_DBUS_ID_MAX
  122. * @new_ab_vote: ab_vote for incoming frame.
  123. * @new_ib_vote: ib_vote for incoming frame.
  124. */
  125. struct sde_rsc_bw_config {
  126. u64 ab_vote[SDE_POWER_HANDLE_DBUS_ID_MAX];
  127. u64 ib_vote[SDE_POWER_HANDLE_DBUS_ID_MAX];
  128. u64 new_ab_vote[SDE_POWER_HANDLE_DBUS_ID_MAX];
  129. u64 new_ib_vote[SDE_POWER_HANDLE_DBUS_ID_MAX];
  130. };
  131. /**
  132. * enum sde_rsc_bw_delta bandwidth change
  133. *
  134. * @BW_HIGH_TO_LOW: Bandwidth vote from high to low
  135. * @BW_LOW_TO_HIGH: Bandwidth vote from low to high
  136. * @BW_NO_CHANGE: No change in Bandwidth vote
  137. * @BW_DELTA_MAX: Maximum value
  138. */
  139. enum sde_rsc_bw_delta {
  140. BW_HIGH_TO_LOW,
  141. BW_LOW_TO_HIGH,
  142. BW_NO_CHANGE,
  143. BW_DELTA_MAX,
  144. };
  145. /**
  146. * struct sde_rsc_priv: sde resource state coordinator(rsc) private handle
  147. * @version: rsc sequence version
  148. * @hw_drv_ver: rscc hw version
  149. * @phandle: module power handle for clocks
  150. * @fs: "MDSS GDSC" handle
  151. * @sw_fs_enabled: track "MDSS GDSC" sw vote during probe
  152. *
  153. * @rpmh_dev: rpmh device node
  154. * @drv_io: sde drv io data mapping
  155. * @wrapper_io: wrapper io data mapping
  156. *
  157. * @client_list: current rsc client list handle
  158. * @event_list: current rsc event list handle
  159. * @client_lock: current rsc client synchronization lock
  160. *
  161. * timer_config: current rsc timer configuration
  162. * cmd_config: current panel config
  163. * current_state: current rsc state (video/command), solver
  164. * override/enabled.
  165. * vsync_source: Interface index to provide the vsync ticks
  166. * update_tcs_content: WAKE & SLEEP / AMC TCS content needs update with same BW
  167. * vote if RSC state updates.
  168. * debug_mode: enables the logging for each register read/write
  169. * debugfs_root: debugfs file system root node
  170. *
  171. * hw_ops: sde rsc hardware operations
  172. * power_collapse: if all clients are in IDLE state then it enters in
  173. * mode2 state and enable the power collapse state
  174. * power_collapse_block:By default, rsc move to mode-2 if all clients are in
  175. * invalid state. It can be blocked by this boolean entry.
  176. * primary_client: A client which is allowed to make command state request
  177. * and ab/ib vote on display rsc
  178. * single_tcs_execution_time: worst case time to execute one tcs vote
  179. * (sleep/wake), in ns
  180. * backoff_time_ns: time to only wake tcs in any mode
  181. * mode_threshold_time_ns: time to wake TCS in mode-0, must be greater than
  182. * backoff time
  183. * time_slot_0_ns: time for sleep & wake TCS in mode-1
  184. * rsc_vsync_wait: Refcount to indicate if we have to wait for the vsync.
  185. * rsc_vsync_waitq: Queue to wait for the vsync.
  186. * bw_config: check sde_rsc_bw_config structure description.
  187. * dev: rsc device node
  188. * resource_refcount: Track rsc resource refcount
  189. * profiling_supp: Indicates if HW has support for profiling counters
  190. * profiling_en: Flag for rsc lpm profiling counters, true=enabled
  191. * post_poms: bool if a panel mode change occurred
  192. * bwi_update: enum to indidate a bandwitdh vote change
  193. */
  194. struct sde_rsc_priv {
  195. u32 version;
  196. u32 hw_drv_ver;
  197. struct sde_power_handle phandle;
  198. struct regulator *fs;
  199. bool sw_fs_enabled;
  200. struct device *rpmh_dev;
  201. struct dss_io_data drv_io;
  202. struct dss_io_data wrapper_io;
  203. struct list_head client_list;
  204. struct list_head event_list;
  205. struct mutex client_lock;
  206. struct sde_rsc_timer_config timer_config;
  207. struct sde_rsc_cmd_config cmd_config;
  208. u32 current_state;
  209. u32 vsync_source;
  210. bool update_tcs_content;
  211. u32 debug_mode;
  212. struct dentry *debugfs_root;
  213. struct sde_rsc_hw_ops hw_ops;
  214. bool power_collapse;
  215. bool power_collapse_block;
  216. struct sde_rsc_client *primary_client;
  217. u32 single_tcs_execution_time;
  218. u32 backoff_time_ns;
  219. u32 mode_threshold_time_ns;
  220. u32 time_slot_0_ns;
  221. atomic_t rsc_vsync_wait;
  222. wait_queue_head_t rsc_vsync_waitq;
  223. struct sde_rsc_bw_config bw_config;
  224. struct device *dev;
  225. atomic_t resource_refcount;
  226. bool profiling_supp;
  227. bool profiling_en;
  228. bool post_poms;
  229. enum sde_rsc_bw_delta bwi_update;
  230. };
  231. /**
  232. * sde_rsc_hw_register() - register hardware API. It manages V1 and V2 support.
  233. *
  234. * @client: Client pointer provided by sde_rsc_client_create().
  235. *
  236. * Return: error code.
  237. */
  238. int sde_rsc_hw_register(struct sde_rsc_priv *rsc);
  239. /**
  240. * sde_rsc_hw_register_v3() - register hardware API. It manages V3 support.
  241. *
  242. * @client: Client pointer provided by sde_rsc_client_create().
  243. *
  244. * Return: error code.
  245. */
  246. int sde_rsc_hw_register_v3(struct sde_rsc_priv *rsc);
  247. #endif /* _SDE_RSC_PRIV_H_ */