sde_crtc.h 34 KB

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