sde_crtc.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. /*
  2. * Copyright (c) 2015-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _SDE_CRTC_H_
  19. #define _SDE_CRTC_H_
  20. #include <linux/kthread.h>
  21. #include <linux/of_fdt.h>
  22. #include <drm/drm_crtc.h>
  23. #include <drm/drm_vblank.h>
  24. #include "msm_prop.h"
  25. #include "sde_fence.h"
  26. #include "sde_kms.h"
  27. #include "sde_core_perf.h"
  28. #include "sde_hw_ds.h"
  29. #include "sde_color_processing.h"
  30. #define SDE_CRTC_NAME_SIZE 12
  31. /* define the maximum number of in-flight frame events */
  32. /* Expand it to 2x for handling atleast 2 connectors safely */
  33. #define SDE_CRTC_FRAME_EVENT_SIZE (4 * 2)
  34. /**
  35. * enum sde_crtc_client_type: crtc client type
  36. * @RT_CLIENT: RealTime client like video/cmd mode display
  37. * voting through apps rsc
  38. * @NRT_CLIENT: Non-RealTime client like WB display
  39. * voting through apps rsc
  40. * @RT_RSC_CLIENT: Realtime display RSC voting client
  41. */
  42. enum sde_crtc_client_type {
  43. RT_CLIENT,
  44. NRT_CLIENT,
  45. RT_RSC_CLIENT,
  46. };
  47. /**
  48. * enum sde_crtc_output_capture_point
  49. * @MIXER_OUT : capture mixer output
  50. * @DSPP_OUT : capture output of dspp
  51. * @CAPTURE_DEMURA_OUT : capture output of demura
  52. */
  53. enum sde_crtc_output_capture_point {
  54. CAPTURE_MIXER_OUT,
  55. CAPTURE_DSPP_OUT,
  56. CAPTURE_DEMURA_OUT
  57. };
  58. /**
  59. * enum sde_crtc_idle_pc_state: states of idle power collapse
  60. * @IDLE_PC_NONE: no-op
  61. * @IDLE_PC_ENABLE: enable idle power-collapse
  62. * @IDLE_PC_DISABLE: disable idle power-collapse
  63. */
  64. enum sde_crtc_idle_pc_state {
  65. IDLE_PC_NONE,
  66. IDLE_PC_ENABLE,
  67. IDLE_PC_DISABLE,
  68. };
  69. /**
  70. * enum sde_crtc_cache_state: states of disp system cache
  71. * CACHE_STATE_DISABLED: sys cache has been disabled
  72. * CACHE_STATE_ENABLED: sys cache has been enabled
  73. * CACHE_STATE_NORMAL: sys cache is normal state
  74. * CACHE_STATE_PRE_CACHE: frame cache is being prepared
  75. * CACHE_STATE_FRAME_WRITE: sys cache is being written to
  76. * CACHE_STATE_FRAME_READ: sys cache is being read
  77. */
  78. enum sde_crtc_cache_state {
  79. CACHE_STATE_DISABLED,
  80. CACHE_STATE_ENABLED,
  81. CACHE_STATE_NORMAL,
  82. CACHE_STATE_PRE_CACHE,
  83. CACHE_STATE_FRAME_WRITE,
  84. CACHE_STATE_FRAME_READ
  85. };
  86. /**
  87. * enum sde_crtc_vm_req: request for VM operations
  88. * @VM_REQ_NONE: no request. Normal VM operations.
  89. * @VM_REQ_RELEASE: request to release the HW resources from the current VM
  90. * @VM_REQ_ACQUIRE: request to acquire the HW resources in the current VM
  91. */
  92. enum sde_crtc_vm_req {
  93. VM_REQ_NONE,
  94. VM_REQ_RELEASE,
  95. VM_REQ_ACQUIRE,
  96. };
  97. /**
  98. * @connectors : Currently associated drm connectors for retire event
  99. * @num_connectors: Number of associated drm connectors for retire event
  100. * @list: event list
  101. */
  102. struct sde_crtc_retire_event {
  103. struct drm_connector *connectors[MAX_CONNECTORS];
  104. int num_connectors;
  105. struct list_head list;
  106. };
  107. /**
  108. * struct sde_crtc_mixer: stores the map for each virtual pipeline in the CRTC
  109. * @hw_lm: LM HW Driver context
  110. * @hw_ctl: CTL Path HW driver context
  111. * @hw_dspp: DSPP HW driver context
  112. * @hw_ds: DS HW driver context
  113. * @encoder: Encoder attached to this lm & ctl
  114. * @mixer_op_mode: mixer blending operation mode
  115. */
  116. struct sde_crtc_mixer {
  117. struct sde_hw_mixer *hw_lm;
  118. struct sde_hw_ctl *hw_ctl;
  119. struct sde_hw_dspp *hw_dspp;
  120. struct sde_hw_ds *hw_ds;
  121. struct drm_encoder *encoder;
  122. u32 mixer_op_mode;
  123. };
  124. /**
  125. * struct sde_crtc_frame_event: stores crtc frame event for crtc processing
  126. * @work: base work structure
  127. * @crtc: Pointer to crtc handling this event
  128. * @connector: pointer to drm connector which is source of frame event
  129. * @list: event list
  130. * @ts: timestamp at queue entry
  131. * @event: event identifier
  132. */
  133. struct sde_crtc_frame_event {
  134. struct kthread_work work;
  135. struct drm_crtc *crtc;
  136. struct drm_connector *connector;
  137. struct list_head list;
  138. ktime_t ts;
  139. u32 event;
  140. };
  141. /**
  142. * struct sde_crtc_event - event callback tracking structure
  143. * @list: Linked list tracking node
  144. * @kt_work: Kthread worker structure
  145. * @sde_crtc: Pointer to associated sde_crtc structure
  146. * @cb_func: Pointer to callback function
  147. * @usr: Pointer to user data to be provided to the callback
  148. */
  149. struct sde_crtc_event {
  150. struct list_head list;
  151. struct kthread_work kt_work;
  152. void *sde_crtc;
  153. void (*cb_func)(struct drm_crtc *crtc, void *usr);
  154. void *usr;
  155. };
  156. /**
  157. * struct sde_crtc_fps_info - structure for measuring fps periodicity
  158. * @frame_count : Total frames during configured periodic duration
  159. * @last_sampled_time_us: Stores the last ktime in microsecs when fps
  160. * was calculated
  161. * @measured_fps : Last measured fps value
  162. * @fps_periodic_duration : Duration in milliseconds to measure the fps.
  163. * Default value is 1 second.
  164. * @time_buf : Buffer for storing ktime of the commits
  165. * @next_time_index : index into time_buf for storing ktime for next commit
  166. */
  167. struct sde_crtc_fps_info {
  168. u32 frame_count;
  169. ktime_t last_sampled_time_us;
  170. u32 measured_fps;
  171. u32 fps_periodic_duration;
  172. ktime_t *time_buf;
  173. u32 next_time_index;
  174. };
  175. /**
  176. * struct sde_ltm_buffer - defines LTM buffer structure.
  177. * @fb: frm framebuffer for the buffer
  178. * @gem: drm gem handle for the buffer
  179. * @asapce : pointer to address space
  180. * @drm_fb_id: framebuffer id associated with this buffer
  181. * @offset: offset for alignment
  182. * @iova: device address
  183. * @kva: kernel virtual address
  184. * @node: list node for LTM buffer list;
  185. */
  186. struct sde_ltm_buffer {
  187. struct drm_framebuffer *fb;
  188. struct drm_gem_object *gem;
  189. struct msm_gem_address_space *aspace;
  190. u32 drm_fb_id;
  191. u32 offset;
  192. u64 iova;
  193. void *kva;
  194. struct list_head node;
  195. };
  196. /**
  197. * struct sde_crtc_misr_info - structure for misr information
  198. * @misr_enable : enable/disable flag
  199. * @misr_frame_count : Number of frames for misr calculation.
  200. */
  201. struct sde_crtc_misr_info {
  202. bool misr_enable;
  203. u32 misr_frame_count;
  204. };
  205. /*
  206. * Maximum number of free event structures to cache
  207. */
  208. #define SDE_CRTC_MAX_EVENT_COUNT 16
  209. /**
  210. * struct sde_crtc - virtualized CRTC data structure
  211. * @base : Base drm crtc structure
  212. * @name : ASCII description of this crtc
  213. * @num_ctls : Number of ctl paths in use
  214. * @num_mixers : Number of mixers in use
  215. * @mixers_swapped: Whether the mixers have been swapped for left/right update
  216. * especially in the case of DSC Merge.
  217. * @mixers : List of active mixers
  218. * @event : Pointer to last received drm vblank event. If there is a
  219. * pending vblank event, this will be non-null.
  220. * @vsync_count : Running count of received vsync events
  221. * @drm_requested_vblank : Whether vblanks have been enabled in the encoder
  222. * @property_info : Opaque structure for generic property support
  223. * @property_defaults : Array of default values for generic property support
  224. * @output_fence : output release fence context
  225. * @stage_cfg : H/w mixer stage configuration
  226. * @debugfs_root : Parent of debugfs node
  227. * @priv_handle : Pointer to external private handle, if present
  228. * @vblank_cb_count : count of vblank callback since last reset
  229. * @play_count : frame count between crtc enable and disable
  230. * @vblank_cb_time : ktime at vblank count reset
  231. * @vblank_last_cb_time : ktime at last vblank notification
  232. * @retire_frame_event_time : ktime at last retire frame event
  233. * @sysfs_dev : sysfs device node for crtc
  234. * @vsync_event_sf : vsync event notifier sysfs device
  235. * @retire_frame_event_sf :retire frame event notifier sysfs device
  236. * @enabled : whether the SDE CRTC is currently enabled. updated in the
  237. * commit-thread, not state-swap time which is earlier, so
  238. * safe to make decisions on during VBLANK on/off work
  239. * @cp_feature_list : list of color processing features supported on a crtc
  240. * @cp_active_list : list of color processing features are active
  241. * @cp_dirty_list : list of color processing features are dirty
  242. * @ad_dirty : list containing ad properties that are dirty
  243. * @ad_active : list containing ad properties that are active
  244. * @crtc_lock : crtc lock around create, destroy and access.
  245. * @frame_pending : Whether or not an update is pending
  246. * @frame_events : static allocation of in-flight frame events
  247. * @frame_event_list : available frame event list
  248. * @spin_lock : spin lock for transaction status, etc...
  249. * @fevent_spin_lock : spin lock for frame event
  250. * @event_thread : Pointer to event handler thread
  251. * @event_worker : Event worker queue
  252. * @event_cache : Local cache of event worker structures
  253. * @event_free_list : List of available event structures
  254. * @event_lock : Spinlock around event handling code
  255. * @misr_enable_sui : boolean entry indicates misr enable/disable status
  256. * for secure cases.
  257. * @misr_enable_debugfs : boolean entry indicates misr enable/disable status
  258. * from debugfs.
  259. * @misr_reconfigure : boolean entry indicates misr reconfigure status
  260. * @misr_frame_count : misr frame count provided by client
  261. * @misr_data : store misr data before turning off the clocks.
  262. * @idle_notify_work: delayed worker to notify idle timeout to user space
  263. * @power_event : registered power event handle
  264. * @cur_perf : current performance committed to clock/bandwidth driver
  265. * @plane_mask_old: keeps track of the planes used in the previous commit
  266. * @frame_trigger_mode: frame trigger mode
  267. * @cp_pu_feature_mask: mask indicating cp feature enable for partial update
  268. * @ltm_buffer_cnt : number of ltm buffers
  269. * @ltm_buffers : struct stores ltm buffer related data
  270. * @ltm_buf_free : list of LTM buffers that are available
  271. * @ltm_buf_busy : list of LTM buffers that are been used by HW
  272. * @ltm_hist_en : flag to indicate whether LTM hist is enabled or not
  273. * @ltm_buffer_lock : muttx to protect ltm_buffers allcation and free
  274. * @ltm_lock : Spinlock to protect ltm buffer_cnt, hist_en and ltm lists
  275. * @needs_hw_reset : Initiate a hw ctl reset
  276. * @hist_irq_idx : hist interrupt irq idx
  277. * @src_bpp : source bpp used to calculate compression ratio
  278. * @target_bpp : target bpp used to calculate compression ratio
  279. * @static_cache_read_work: delayed worker to transition cache state to read
  280. * @cache_state : Current static image cache state
  281. * @dspp_blob_info : blob containing dspp hw capability information
  282. * @cached_encoder_mask : cached encoder_mask for vblank work
  283. * @valid_skip_blend_plane: flag to indicate if skip blend plane is valid
  284. * @skip_blend_plane: enabled plane that has skip blending
  285. * @skip_blend_plane_w: skip blend plane width
  286. * @skip_blend_plane_h: skip blend plane height
  287. * @line_time_in_ns : current mode line time in nano sec is needed for QOS update
  288. */
  289. struct sde_crtc {
  290. struct drm_crtc base;
  291. char name[SDE_CRTC_NAME_SIZE];
  292. /* HW Resources reserved for the crtc */
  293. u32 num_ctls;
  294. u32 num_mixers;
  295. bool mixers_swapped;
  296. struct sde_crtc_mixer mixers[MAX_MIXERS_PER_CRTC];
  297. struct drm_pending_vblank_event *event;
  298. u32 vsync_count;
  299. struct msm_property_info property_info;
  300. struct msm_property_data property_data[CRTC_PROP_COUNT];
  301. struct drm_property_blob *blob_info;
  302. /* output fence support */
  303. struct sde_fence_context *output_fence;
  304. struct sde_hw_stage_cfg stage_cfg[MAX_LAYOUTS_PER_CRTC];
  305. struct dentry *debugfs_root;
  306. void *priv_handle;
  307. u32 vblank_cb_count;
  308. u64 play_count;
  309. ktime_t vblank_cb_time;
  310. ktime_t vblank_last_cb_time;
  311. ktime_t retire_frame_event_time;
  312. struct sde_crtc_fps_info fps_info;
  313. struct device *sysfs_dev;
  314. struct kernfs_node *vsync_event_sf;
  315. struct kernfs_node *retire_frame_event_sf;
  316. bool enabled;
  317. struct list_head cp_feature_list;
  318. struct list_head cp_active_list;
  319. struct list_head cp_dirty_list;
  320. struct list_head ad_dirty;
  321. struct list_head ad_active;
  322. struct list_head user_event_list;
  323. struct mutex crtc_lock;
  324. struct mutex crtc_cp_lock;
  325. atomic_t frame_pending;
  326. struct sde_crtc_frame_event frame_events[SDE_CRTC_FRAME_EVENT_SIZE];
  327. struct list_head frame_event_list;
  328. spinlock_t spin_lock;
  329. spinlock_t fevent_spin_lock;
  330. /* for handling internal event thread */
  331. struct sde_crtc_event event_cache[SDE_CRTC_MAX_EVENT_COUNT];
  332. struct list_head event_free_list;
  333. spinlock_t event_lock;
  334. bool misr_enable_sui;
  335. bool misr_enable_debugfs;
  336. bool misr_reconfigure;
  337. u32 misr_frame_count;
  338. struct kthread_delayed_work idle_notify_work;
  339. struct sde_power_event *power_event;
  340. struct sde_core_perf_params cur_perf;
  341. struct sde_core_perf_params new_perf;
  342. u32 plane_mask_old;
  343. /* blob for histogram data */
  344. struct drm_property_blob *hist_blob;
  345. enum frame_trigger_mode_type frame_trigger_mode;
  346. u32 cp_pu_feature_mask;
  347. u32 ltm_buffer_cnt;
  348. struct sde_ltm_buffer *ltm_buffers[LTM_BUFFER_SIZE];
  349. struct list_head ltm_buf_free;
  350. struct list_head ltm_buf_busy;
  351. bool ltm_hist_en;
  352. struct drm_msm_ltm_cfg_param ltm_cfg;
  353. struct mutex ltm_buffer_lock;
  354. spinlock_t ltm_lock;
  355. bool needs_hw_reset;
  356. int hist_irq_idx;
  357. int src_bpp;
  358. int target_bpp;
  359. struct kthread_delayed_work static_cache_read_work;
  360. enum sde_crtc_cache_state cache_state;
  361. struct drm_property_blob *dspp_blob_info;
  362. u32 cached_encoder_mask;
  363. bool valid_skip_blend_plane;
  364. enum sde_sspp skip_blend_plane;
  365. u32 skip_blend_plane_w;
  366. u32 skip_blend_plane_h;
  367. u32 line_time_in_ns;
  368. };
  369. enum sde_crtc_dirty_flags {
  370. SDE_CRTC_DIRTY_DEST_SCALER,
  371. SDE_CRTC_DIRTY_DIM_LAYERS,
  372. SDE_CRTC_NOISE_LAYER,
  373. SDE_CRTC_DIRTY_MAX,
  374. };
  375. #define to_sde_crtc(x) container_of(x, struct sde_crtc, base)
  376. /**
  377. * struct sde_crtc_state - sde container for atomic crtc state
  378. * @base: Base drm crtc state structure
  379. * @connectors : Currently associated drm connectors
  380. * @num_connectors: Number of associated drm connectors
  381. * @rsc_client : sde rsc client when mode is valid
  382. * @is_ppsplit : Whether current topology requires PPSplit special handling
  383. * @bw_control : true if bw/clk controlled by core bw/clk properties
  384. * @bw_split_vote : true if bw controlled by llcc/dram bw properties
  385. * @crtc_roi : Current CRTC ROI. Possibly sub-rectangle of mode.
  386. * Origin top left of CRTC.
  387. * @lm_bounds : LM boundaries based on current mode full resolution, no ROI.
  388. * Origin top left of CRTC.
  389. * @lm_roi : Current LM ROI, possibly sub-rectangle of mode.
  390. * Origin top left of CRTC.
  391. * @user_roi_list : List of user's requested ROIs as from set property
  392. * @cached_user_roi_list : Copy of user_roi_list from previous PU frame
  393. * @property_state: Local storage for msm_prop properties
  394. * @property_values: Current crtc property values
  395. * @input_fence_timeout_ns : Cached input fence timeout, in ns
  396. * @num_dim_layers: Number of dim layers
  397. * @dim_layer: Dim layer configs
  398. * @num_ds: Number of destination scalers to be configured
  399. * @num_ds_enabled: Number of destination scalers enabled
  400. * @ds_cfg: Destination scaler config
  401. * @scl3_lut_cfg: QSEED3 lut config
  402. * @new_perf: new performance state being requested
  403. * @noise_layer_en: flag to indicate if noise layer cfg is valid
  404. * @drm_msm_noise_layer_cfg: noise layer configuration
  405. * @cp_prop_cnt: number of dirty color processing features
  406. * @cp_prop_values: array of cp property values
  407. * @cp_dirty_list: array tracking features that are dirty
  408. * @cp_range_payload: array storing state user_data passed via range props
  409. * @cont_splash_populated: State was populated as part of cont. splash
  410. */
  411. struct sde_crtc_state {
  412. struct drm_crtc_state base;
  413. struct drm_connector *connectors[MAX_CONNECTORS];
  414. int num_connectors;
  415. struct sde_rsc_client *rsc_client;
  416. bool rsc_update;
  417. bool bw_control;
  418. bool bw_split_vote;
  419. bool is_ppsplit;
  420. struct sde_rect crtc_roi;
  421. struct sde_rect lm_bounds[MAX_MIXERS_PER_CRTC];
  422. struct sde_rect lm_roi[MAX_MIXERS_PER_CRTC];
  423. struct msm_roi_list user_roi_list, cached_user_roi_list;
  424. struct msm_property_state property_state;
  425. struct msm_property_value property_values[CRTC_PROP_COUNT];
  426. DECLARE_BITMAP(dirty, SDE_CRTC_DIRTY_MAX);
  427. uint64_t input_fence_timeout_ns;
  428. uint32_t num_dim_layers;
  429. struct sde_hw_dim_layer dim_layer[SDE_MAX_DIM_LAYERS];
  430. uint32_t num_ds;
  431. uint32_t num_ds_enabled;
  432. struct sde_hw_ds_cfg ds_cfg[SDE_MAX_DS_COUNT];
  433. struct sde_hw_scaler3_lut_cfg scl3_lut_cfg;
  434. struct sde_core_perf_params new_perf;
  435. bool noise_layer_en;
  436. struct drm_msm_noise_layer_cfg layer_cfg;
  437. uint32_t cp_prop_cnt;
  438. struct sde_cp_crtc_property_state
  439. cp_prop_values[SDE_CP_CRTC_MAX_FEATURES];
  440. uint32_t cp_dirty_list[SDE_CP_CRTC_MAX_FEATURES];
  441. struct sde_cp_crtc_range_prop_payload
  442. cp_range_payload[SDE_CP_CRTC_MAX_FEATURES];
  443. bool cont_splash_populated;
  444. };
  445. enum sde_crtc_irq_state {
  446. IRQ_NOINIT,
  447. IRQ_ENABLED,
  448. IRQ_DISABLING,
  449. IRQ_DISABLED,
  450. };
  451. /**
  452. * sde_crtc_irq_info - crtc interrupt info
  453. * @irq: interrupt callback
  454. * @event: event type of the interrupt
  455. * @func: function pointer to enable/disable the interrupt
  456. * @list: list of user customized event in crtc
  457. * @state: state of the interrupt
  458. * @state_lock: spin lock for interrupt state
  459. */
  460. struct sde_crtc_irq_info {
  461. struct sde_irq_callback irq;
  462. u32 event;
  463. int (*func)(struct drm_crtc *crtc, bool en,
  464. struct sde_irq_callback *irq);
  465. struct list_head list;
  466. enum sde_crtc_irq_state state;
  467. spinlock_t state_lock;
  468. };
  469. #define to_sde_crtc_state(x) \
  470. container_of(x, struct sde_crtc_state, base)
  471. /**
  472. * sde_crtc_get_property - query integer value of crtc property
  473. * @S: Pointer to crtc state
  474. * @X: Property index, from enum msm_mdp_crtc_property
  475. * Returns: Integer value of requested property
  476. */
  477. #define sde_crtc_get_property(S, X) \
  478. ((S) && ((X) < CRTC_PROP_COUNT) ? ((S)->property_values[(X)].value) : 0)
  479. /**
  480. * sde_crtc_get_mixer_width - get the mixer width
  481. * Mixer width will be same as panel width(/2 for split)
  482. * unless destination scaler feature is enabled
  483. */
  484. static inline int sde_crtc_get_mixer_width(struct sde_crtc *sde_crtc,
  485. struct sde_crtc_state *cstate, struct drm_display_mode *mode)
  486. {
  487. u32 mixer_width;
  488. if (!sde_crtc || !cstate || !mode)
  489. return 0;
  490. if (cstate->num_ds_enabled)
  491. mixer_width = cstate->ds_cfg[0].lm_width;
  492. else
  493. mixer_width = mode->hdisplay / sde_crtc->num_mixers;
  494. return mixer_width;
  495. }
  496. /**
  497. * sde_crtc_get_mixer_height - get the mixer height
  498. * Mixer height will be same as panel height unless
  499. * destination scaler feature is enabled
  500. */
  501. static inline int sde_crtc_get_mixer_height(struct sde_crtc *sde_crtc,
  502. struct sde_crtc_state *cstate, struct drm_display_mode *mode)
  503. {
  504. if (!sde_crtc || !cstate || !mode)
  505. return 0;
  506. return (cstate->num_ds_enabled ?
  507. cstate->ds_cfg[0].lm_height : mode->vdisplay);
  508. }
  509. /**
  510. * sde_crtc_frame_pending - retun the number of pending frames
  511. * @crtc: Pointer to drm crtc object
  512. */
  513. static inline int sde_crtc_frame_pending(struct drm_crtc *crtc)
  514. {
  515. struct sde_crtc *sde_crtc;
  516. if (!crtc)
  517. return -EINVAL;
  518. sde_crtc = to_sde_crtc(crtc);
  519. return atomic_read(&sde_crtc->frame_pending);
  520. }
  521. /**
  522. * sde_crtc_set_needs_hw_reset - set hw reset flag, to handle reset during
  523. * commit kickoff
  524. * @crtc: Pointer to DRM crtc instance
  525. */
  526. static inline void sde_crtc_set_needs_hw_reset(struct drm_crtc *crtc)
  527. {
  528. struct sde_crtc *sde_crtc;
  529. if (!crtc)
  530. return;
  531. sde_crtc = to_sde_crtc(crtc);
  532. sde_crtc->needs_hw_reset = true;
  533. }
  534. /**
  535. * sde_crtc_reset_hw - attempt hardware reset on errors
  536. * @crtc: Pointer to DRM crtc instance
  537. * @old_state: Pointer to crtc state for previous commit
  538. * @recovery_events: Whether or not recovery events are enabled
  539. * Returns: Zero if current commit should still be attempted
  540. */
  541. int sde_crtc_reset_hw(struct drm_crtc *crtc, struct drm_crtc_state *old_state,
  542. bool recovery_events);
  543. /**
  544. * sde_crtc_request_frame_reset - requests for next frame reset
  545. * @crtc: Pointer to drm crtc object
  546. */
  547. static inline int sde_crtc_request_frame_reset(struct drm_crtc *crtc)
  548. {
  549. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  550. if (sde_crtc->frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START)
  551. sde_crtc_reset_hw(crtc, crtc->state, false);
  552. return 0;
  553. }
  554. /**
  555. * sde_crtc_vblank - enable or disable vblanks for this crtc
  556. * @crtc: Pointer to drm crtc object
  557. * @en: true to enable vblanks, false to disable
  558. */
  559. int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
  560. /**
  561. * sde_crtc_get_msm_mode - get msm_mode for a given crtc state
  562. * @c_state: Pointer to drm crtc state object
  563. * Returns: msm_display_mode corresponding to this crtc state, or NULL if none
  564. */
  565. struct msm_display_mode *sde_crtc_get_msm_mode(struct drm_crtc_state *c_state);
  566. /**
  567. * sde_crtc_commit_kickoff - trigger kickoff of the commit for this crtc
  568. * @crtc: Pointer to drm crtc object
  569. * @old_state: Pointer to drm crtc old state object
  570. */
  571. void sde_crtc_commit_kickoff(struct drm_crtc *crtc,
  572. struct drm_crtc_state *old_state);
  573. /**
  574. * sde_crtc_prepare_commit - callback to prepare for output fences
  575. * @crtc: Pointer to drm crtc object
  576. * @old_state: Pointer to drm crtc old state object
  577. */
  578. void sde_crtc_prepare_commit(struct drm_crtc *crtc,
  579. struct drm_crtc_state *old_state);
  580. /**
  581. * sde_crtc_complete_commit - callback signalling completion of current commit
  582. * @crtc: Pointer to drm crtc object
  583. * @old_state: Pointer to drm crtc old state object
  584. */
  585. void sde_crtc_complete_commit(struct drm_crtc *crtc,
  586. struct drm_crtc_state *old_state);
  587. /**
  588. * sde_crtc_init - create a new crtc object
  589. * @dev: sde device
  590. * @plane: base plane
  591. * @Return: new crtc object or error
  592. */
  593. struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane);
  594. /**
  595. * sde_crtc_post_init - update crtc object with post initialization. It
  596. * can update the debugfs, sysfs, entires.
  597. * @dev: sde device
  598. * @crtc: Pointer to drm crtc structure
  599. */
  600. int sde_crtc_post_init(struct drm_device *dev, struct drm_crtc *crtc);
  601. /**
  602. * sde_crtc_complete_flip - complete flip for clients
  603. * @crtc: Pointer to drm crtc object
  604. * @file: client to cancel's file handle
  605. */
  606. void sde_crtc_complete_flip(struct drm_crtc *crtc, struct drm_file *file);
  607. /**
  608. * sde_crtc_register_custom_event - api for enabling/disabling crtc event
  609. * @kms: Pointer to sde_kms
  610. * @crtc_drm: Pointer to crtc object
  611. * @event: Event that client is interested
  612. * @en: Flag to enable/disable the event
  613. */
  614. int sde_crtc_register_custom_event(struct sde_kms *kms,
  615. struct drm_crtc *crtc_drm, u32 event, bool en);
  616. /**
  617. * sde_crtc_get_intf_mode - get interface mode of the given crtc
  618. * @crtc: Pointert to DRM crtc
  619. * @crtc: Pointert to DRM crtc_state
  620. */
  621. enum sde_intf_mode sde_crtc_get_intf_mode(struct drm_crtc *crtc,
  622. struct drm_crtc_state *cstate);
  623. /**
  624. * sde_crtc_get_fps_mode - get frame rate of the given crtc
  625. * @crtc: Pointert to crtc
  626. */
  627. u32 sde_crtc_get_fps_mode(struct drm_crtc *crtc);
  628. /**
  629. * sde_crtc_get_dfps_maxfps - get DFPS max fps of the given crtc
  630. * @crtc: Pointert to crtc
  631. */
  632. u32 sde_crtc_get_dfps_maxfps(struct drm_crtc *crtc);
  633. /**
  634. * sde_crtc_get_client_type - check the crtc type- rt, rsc_rt, etc.
  635. * @crtc: Pointer to crtc
  636. */
  637. static inline enum sde_crtc_client_type sde_crtc_get_client_type(
  638. struct drm_crtc *crtc)
  639. {
  640. struct sde_crtc_state *cstate =
  641. crtc ? to_sde_crtc_state(crtc->state) : NULL;
  642. if (!cstate)
  643. return RT_CLIENT;
  644. return cstate->rsc_client ? RT_RSC_CLIENT : RT_CLIENT;
  645. }
  646. /**
  647. * sde_crtc_is_rt_client - check if real-time client or not
  648. * @crtc: Pointer to DRM crtc
  649. * @crtc_state: Pointer to DRM crtc_state
  650. */
  651. static inline bool sde_crtc_is_rt_client(struct drm_crtc *crtc,
  652. struct drm_crtc_state *cstate)
  653. {
  654. if (!crtc || !cstate)
  655. return true;
  656. return (sde_crtc_get_intf_mode(crtc, cstate) != INTF_MODE_WB_LINE);
  657. }
  658. /**
  659. * sde_crtc_is_enabled - check if sde crtc is enabled or not
  660. * @crtc: Pointer to crtc
  661. */
  662. static inline bool sde_crtc_is_enabled(struct drm_crtc *crtc)
  663. {
  664. return crtc ? crtc->enabled : false;
  665. }
  666. static inline u32 sde_crtc_get_line_time(struct drm_crtc *crtc)
  667. {
  668. struct sde_crtc *sde_crtc;
  669. if (!crtc)
  670. return 0;
  671. sde_crtc = to_sde_crtc(crtc);
  672. return sde_crtc->line_time_in_ns;
  673. }
  674. /**
  675. * sde_crtc_is_reset_required - validate the reset request based on the
  676. * pm_suspend and crtc's active status. crtc's are left active
  677. * on pm_suspend during LP1/LP2 states, as the display is still
  678. * left ON. Avoid reset for the subsequent pm_resume in such cases.
  679. * @crtc: Pointer to crtc
  680. * return: false if in suspend state and crtc active, true otherwise
  681. */
  682. static inline bool sde_crtc_is_reset_required(struct drm_crtc *crtc)
  683. {
  684. /*
  685. * reset is required even when there is no crtc_state as it is required
  686. * to create the initial state object
  687. */
  688. if (!crtc || !crtc->state)
  689. return true;
  690. /* reset not required if crtc is active during suspend state */
  691. if (sde_kms_is_suspend_state(crtc->dev) && crtc->state->active)
  692. return false;
  693. return true;
  694. }
  695. /**
  696. * sde_crtc_event_queue - request event callback
  697. * @crtc: Pointer to drm crtc structure
  698. * @func: Pointer to callback function
  699. * @usr: Pointer to user data to be passed to callback
  700. * @color_processing_event: True if color processing event
  701. * Returns: Zero on success
  702. */
  703. int sde_crtc_event_queue(struct drm_crtc *crtc,
  704. void (*func)(struct drm_crtc *crtc, void *usr),
  705. void *usr, bool color_processing_event);
  706. /**
  707. * sde_crtc_get_crtc_roi - retrieve the crtc_roi from the given state object
  708. * used to allow the planes to adjust their final lm out_xy value in the
  709. * case of partial update
  710. * @crtc_state: Pointer to crtc state
  711. * @crtc_roi: Output pointer to crtc roi in the given state
  712. */
  713. void sde_crtc_get_crtc_roi(struct drm_crtc_state *state,
  714. const struct sde_rect **crtc_roi);
  715. /**
  716. * sde_crtc_is_crtc_roi_dirty - retrieve whether crtc_roi was updated this frame
  717. * Note: Only use during atomic_check since dirty properties may be popped
  718. * @crtc_state: Pointer to crtc state
  719. * Return: true if roi is dirty, false otherwise
  720. */
  721. bool sde_crtc_is_crtc_roi_dirty(struct drm_crtc_state *state);
  722. /** sde_crt_get_secure_level - retrieve the secure level from the give state
  723. * object, this is used to determine the secure state of the crtc
  724. * @crtc : Pointer to drm crtc structure
  725. * @usr: Pointer to drm crtc state
  726. * return: secure_level
  727. */
  728. static inline int sde_crtc_get_secure_level(struct drm_crtc *crtc,
  729. struct drm_crtc_state *state)
  730. {
  731. if (!crtc || !state)
  732. return -EINVAL;
  733. return sde_crtc_get_property(to_sde_crtc_state(state),
  734. CRTC_PROP_SECURITY_LEVEL);
  735. }
  736. /** sde_crtc_atomic_check_has_modeset - checks if the new_crtc_state in the
  737. * drm_atomic_state has a modeset
  738. * @state : pointer to drm_atomic_state
  739. * @crtc : Pointer to drm crtc structure
  740. * Returns true if crtc has modeset
  741. */
  742. static inline bool sde_crtc_atomic_check_has_modeset(
  743. struct drm_atomic_state *state, struct drm_crtc *crtc)
  744. {
  745. struct drm_crtc_state *crtc_state;
  746. if (!state || !crtc)
  747. return false;
  748. crtc_state = drm_atomic_get_new_crtc_state(state,
  749. crtc);
  750. return (crtc_state && drm_atomic_crtc_needs_modeset(crtc_state));
  751. }
  752. /**
  753. * sde_crtc_get_secure_transition - determines the operations to be
  754. * performed before transitioning to secure state
  755. * This function should be called after swapping the new state
  756. * @crtc: Pointer to drm crtc structure
  757. * @old_crtc_state: Poniter to previous CRTC state
  758. * Returns the bitmask of operations need to be performed, -Error in
  759. * case of error cases
  760. */
  761. int sde_crtc_get_secure_transition_ops(struct drm_crtc *crtc,
  762. struct drm_crtc_state *old_crtc_state,
  763. bool old_valid_fb);
  764. /**
  765. * sde_crtc_find_plane_fb_modes - finds the modes of all planes attached
  766. * to crtc
  767. * @crtc: Pointer to DRM crtc object
  768. * @fb_ns: number of non secure planes
  769. * @fb_sec: number of secure-playback planes
  770. * @fb_sec_dir: number of secure-ui/secure-camera planes
  771. */
  772. int sde_crtc_find_plane_fb_modes(struct drm_crtc *crtc,
  773. uint32_t *fb_ns, uint32_t *fb_sec, uint32_t *fb_sec_dir);
  774. /**
  775. * sde_crtc_state_find_plane_fb_modes - finds the modes of all planes attached
  776. * to the crtc state
  777. * @crtc_state: Pointer to DRM crtc state object
  778. * @fb_ns: number of non secure planes
  779. * @fb_sec: number of secure-playback planes
  780. * @fb_sec_dir: number of secure-ui/secure-camera planes
  781. */
  782. int sde_crtc_state_find_plane_fb_modes(struct drm_crtc_state *state,
  783. uint32_t *fb_ns, uint32_t *fb_sec, uint32_t *fb_sec_dir);
  784. /**
  785. * sde_crtc_secure_ctrl - Initiates the transition between secure and
  786. * non-secure world
  787. * @crtc: Pointer to crtc
  788. * @post_commit: if this operation is triggered after commit
  789. */
  790. int sde_crtc_secure_ctrl(struct drm_crtc *crtc, bool post_commit);
  791. /**
  792. * sde_crtc_helper_reset_properties - reset properties to default values in the
  793. * given DRM CRTC state object
  794. * @crtc: Pointer to DRM crtc object
  795. * @crtc_state: Pointer to DRM crtc state object
  796. * Returns: 0 on success, negative errno on failure
  797. */
  798. int sde_crtc_helper_reset_custom_properties(struct drm_crtc *crtc,
  799. struct drm_crtc_state *crtc_state);
  800. /**
  801. * sde_crtc_timeline_status - current buffer timeline status
  802. * @crtc: Pointer to crtc
  803. */
  804. void sde_crtc_timeline_status(struct drm_crtc *crtc);
  805. /**
  806. * sde_crtc_update_cont_splash_settings - update mixer settings
  807. * during device bootup for cont_splash use case
  808. * @crtc: Pointer to drm crtc structure
  809. */
  810. void sde_crtc_update_cont_splash_settings(
  811. struct drm_crtc *crtc);
  812. /**
  813. * sde_crtc_set_qos_dirty - update plane dirty flag to include
  814. * QoS reprogramming which is required during fps switch
  815. * @crtc: Pointer to drm crtc structure
  816. */
  817. void sde_crtc_set_qos_dirty(struct drm_crtc *crtc);
  818. /**
  819. * sde_crtc_misr_setup - to configure and enable/disable MISR
  820. * @crtc: Pointer to drm crtc structure
  821. * @enable: boolean to indicate enable/disable misr
  822. * @frame_count: frame_count to be configured
  823. */
  824. void sde_crtc_misr_setup(struct drm_crtc *crtc, bool enable, u32 frame_count);
  825. /**
  826. * sde_crtc_get_misr_info - to configure and enable/disable MISR
  827. * @crtc: Pointer to drm crtc structure
  828. * @crtc_misr_info: Pointer to crtc misr info structure
  829. */
  830. void sde_crtc_get_misr_info(struct drm_crtc *crtc,
  831. struct sde_crtc_misr_info *crtc_misr_info);
  832. /**
  833. * sde_crtc_set_bpp - set src and target bpp values
  834. * @sde_crtc: Pointer to sde crtc struct
  835. * @src_bpp: source bpp value to be stored
  836. * @target_bpp: target value to be stored
  837. */
  838. static inline void sde_crtc_set_bpp(struct sde_crtc *sde_crtc, int src_bpp,
  839. int target_bpp)
  840. {
  841. sde_crtc->src_bpp = src_bpp;
  842. sde_crtc->target_bpp = target_bpp;
  843. }
  844. /**
  845. * sde_crtc_static_img_control - transition static img cache state
  846. * @crtc: Pointer to drm crtc structure
  847. * @state: cache state to transition to
  848. * @is_vidmode: if encoder is video mode
  849. */
  850. void sde_crtc_static_img_control(struct drm_crtc *crtc,
  851. enum sde_crtc_cache_state state, bool is_vidmode);
  852. /**
  853. * sde_crtc_static_cache_read_kickoff - kickoff cache read work
  854. * @crtc: Pointer to drm crtc structure
  855. */
  856. void sde_crtc_static_cache_read_kickoff(struct drm_crtc *crtc);
  857. /**
  858. * sde_crtc_get_num_datapath - get the number of datapath active
  859. * of primary connector
  860. * @crtc: Pointer to DRM crtc object
  861. * @connector: Pointer to DRM connector object of WB in CWB case
  862. */
  863. int sde_crtc_get_num_datapath(struct drm_crtc *crtc,
  864. struct drm_connector *connector);
  865. /**
  866. * sde_crtc_reset_sw_state - reset dirty proerties on crtc and
  867. * planes attached to the crtc
  868. * @crtc: Pointer to DRM crtc object
  869. */
  870. void sde_crtc_reset_sw_state(struct drm_crtc *crtc);
  871. /**
  872. * sde_crtc_disable_cp_features - api to disable cp features that depend on planes being active.
  873. * Encoder disables the planes during suspend and calls this api for the crtc to disable
  874. * any features that require planes to be active
  875. * @crtc: Pointer to DRM crtc object
  876. */
  877. void sde_crtc_disable_cp_features(struct drm_crtc *crtc);
  878. #endif /* _SDE_CRTC_H_ */