blob: f8ab1108e8f5cbf1d9efe51c0f84672bc6cf8fcb [file] [log] [blame]
Dhaval Patel14d46ce2017-01-17 16:28:12 -08001/*
2 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
Abhijit Kulkarni40e38162016-06-26 22:12:09 -04005 *
Dhaval Patel14d46ce2017-01-17 16:28:12 -08006 * 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.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -04009 *
Dhaval Patel14d46ce2017-01-17 16:28:12 -080010 * 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/>.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040017 */
18
19#ifndef _SDE_CRTC_H_
20#define _SDE_CRTC_H_
21
Clarence Ipa18d4832017-03-13 12:35:44 -070022#include <linux/kthread.h>
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040023#include "drm_crtc.h"
Clarence Ip7a753bb2016-07-07 11:47:44 -040024#include "msm_prop.h"
Clarence Ip24f80662016-06-13 19:05:32 -040025#include "sde_fence.h"
Clarence Ip7a753bb2016-07-07 11:47:44 -040026#include "sde_kms.h"
Alan Kwong9aa061c2016-11-06 21:17:12 -050027#include "sde_core_perf.h"
Alan Kwongcdb2f282017-03-18 13:42:06 -070028#include "sde_hw_blk.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040029
Clarence Ip8f7366c2016-07-05 12:15:26 -040030#define SDE_CRTC_NAME_SIZE 12
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040031
Alan Kwong628d19e2016-10-31 13:50:13 -040032/* define the maximum number of in-flight frame events */
Veera Sundaram Sankaran675ff622017-06-21 21:44:46 -070033#define SDE_CRTC_FRAME_EVENT_SIZE 4
Alan Kwong628d19e2016-10-31 13:50:13 -040034
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040035/**
Dhaval Patel4d424602017-02-18 19:40:14 -080036 * 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 */
43enum sde_crtc_client_type {
44 RT_CLIENT,
45 NRT_CLIENT,
46 RT_RSC_CLIENT,
47};
48
49/**
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040050 * struct sde_crtc_mixer: stores the map for each virtual pipeline in the CRTC
51 * @hw_lm: LM HW Driver context
52 * @hw_ctl: CTL Path HW driver context
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -070053 * @hw_dspp: DSPP HW driver context
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040054 * @encoder: Encoder attached to this lm & ctl
Dhaval Patel48c76022016-09-01 17:51:23 -070055 * @mixer_op_mode: mixer blending operation mode
56 * @flush_mask: mixer flush mask for ctl, mixer and pipe
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040057 */
58struct sde_crtc_mixer {
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040059 struct sde_hw_mixer *hw_lm;
Lloyd Atkinsonc44a52e2016-08-16 16:40:17 -040060 struct sde_hw_ctl *hw_ctl;
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -070061 struct sde_hw_dspp *hw_dspp;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040062 struct drm_encoder *encoder;
Dhaval Patel48c76022016-09-01 17:51:23 -070063 u32 mixer_op_mode;
64 u32 flush_mask;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040065};
66
67/**
Alan Kwong628d19e2016-10-31 13:50:13 -040068 * struct sde_crtc_frame_event: stores crtc frame event for crtc processing
69 * @work: base work structure
70 * @crtc: Pointer to crtc handling this event
71 * @list: event list
72 * @ts: timestamp at queue entry
73 * @event: event identifier
74 */
75struct sde_crtc_frame_event {
76 struct kthread_work work;
77 struct drm_crtc *crtc;
78 struct list_head list;
79 ktime_t ts;
80 u32 event;
81};
82
83/**
Clarence Ipa18d4832017-03-13 12:35:44 -070084 * struct sde_crtc_event - event callback tracking structure
85 * @list: Linked list tracking node
86 * @kt_work: Kthread worker structure
87 * @sde_crtc: Pointer to associated sde_crtc structure
88 * @cb_func: Pointer to callback function
89 * @usr: Pointer to user data to be provided to the callback
90 */
91struct sde_crtc_event {
92 struct list_head list;
93 struct kthread_work kt_work;
94 void *sde_crtc;
95
Gopikrishnaiah Anandanb6b401f2017-03-14 16:39:49 -070096 void (*cb_func)(struct drm_crtc *crtc, void *usr);
Clarence Ipa18d4832017-03-13 12:35:44 -070097 void *usr;
98};
99
100/*
101 * Maximum number of free event structures to cache
102 */
103#define SDE_CRTC_MAX_EVENT_COUNT 16
104
105/**
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400106 * struct sde_crtc - virtualized CRTC data structure
107 * @base : Base drm crtc structure
108 * @name : ASCII description of this crtc
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400109 * @num_ctls : Number of ctl paths in use
110 * @num_mixers : Number of mixers in use
Lloyd Atkinson094780d2017-04-24 17:25:08 -0400111 * @mixers_swapped: Whether the mixers have been swapped for left/right update
112 * especially in the case of DSC Merge.
Lloyd Atkinsona9d7e752017-01-17 16:31:43 -0500113 * @mixers : List of active mixers
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400114 * @event : Pointer to last received drm vblank event. If there is a
115 * pending vblank event, this will be non-null.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400116 * @vsync_count : Running count of received vsync events
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400117 * @drm_requested_vblank : Whether vblanks have been enabled in the encoder
Clarence Ip7a753bb2016-07-07 11:47:44 -0400118 * @property_info : Opaque structure for generic property support
119 * @property_defaults : Array of default values for generic property support
Dhaval Patel39323d42017-03-01 23:48:24 -0800120 * @output_fence : output release fence context
Clarence Ip8f7366c2016-07-05 12:15:26 -0400121 * @stage_cfg : H/w mixer stage configuration
122 * @debugfs_root : Parent of debugfs node
Alan Kwong07da0982016-11-04 12:57:45 -0400123 * @vblank_cb_count : count of vblank callback since last reset
Dhaval Pateld67cf4a2017-06-14 18:08:32 -0700124 * @play_count : frame count between crtc enable and disable
Alan Kwong07da0982016-11-04 12:57:45 -0400125 * @vblank_cb_time : ktime at vblank count reset
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400126 * @vblank_requested : whether the user has requested vblank events
Clarence Ip7f70ce42017-03-20 06:53:46 -0700127 * @suspend : whether or not a suspend operation is in progress
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400128 * @enabled : whether the SDE CRTC is currently enabled. updated in the
129 * commit-thread, not state-swap time which is earlier, so
130 * safe to make decisions on during VBLANK on/off work
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700131 * @feature_list : list of color processing features supported on a crtc
132 * @active_list : list of color processing features are active
133 * @dirty_list : list of color processing features are dirty
Gopikrishnaiah Anandan9ba43782017-01-31 18:23:08 -0800134 * @ad_dirty: list containing ad properties that are dirty
135 * @ad_active: list containing ad properties that are active
Dhaval Patel3fbe6bf2016-10-20 20:00:41 -0700136 * @crtc_lock : crtc lock around create, destroy and access.
Alan Kwong628d19e2016-10-31 13:50:13 -0400137 * @frame_pending : Whether or not an update is pending
138 * @frame_events : static allocation of in-flight frame events
139 * @frame_event_list : available frame event list
140 * @spin_lock : spin lock for frame event, transaction status, etc...
Veera Sundaram Sankaran7ee99092017-06-13 11:19:36 -0700141 * @frame_done_comp : for frame_event_done synchronization
Clarence Ipa18d4832017-03-13 12:35:44 -0700142 * @event_thread : Pointer to event handler thread
143 * @event_worker : Event worker queue
144 * @event_cache : Local cache of event worker structures
145 * @event_free_list : List of available event structures
146 * @event_lock : Spinlock around event handling code
Dhaval Patelf9245d62017-03-28 16:24:00 -0700147 * @misr_enable : boolean entry indicates misr enable/disable status.
Dhaval Patel010f5172017-08-01 22:40:09 -0700148 * @misr_frame_count : misr frame count provided by client
149 * @misr_data : store misr data before turning off the clocks.
Veera Sundaram Sankaran82916e02017-03-29 18:44:22 -0700150 * @power_event : registered power event handle
Alan Kwong751cf462017-06-08 10:26:46 -0400151 * @cur_perf : current performance committed to clock/bandwidth driver
Alan Kwong310e9b02017-08-03 02:04:07 -0400152 * @rp_lock : serialization lock for resource pool
153 * @rp_head : list of active resource pool
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400154 */
155struct sde_crtc {
156 struct drm_crtc base;
Clarence Ip8f7366c2016-07-05 12:15:26 -0400157 char name[SDE_CRTC_NAME_SIZE];
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400158
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400159 /* HW Resources reserved for the crtc */
Lloyd Atkinsonc44a52e2016-08-16 16:40:17 -0400160 u32 num_ctls;
161 u32 num_mixers;
Lloyd Atkinson094780d2017-04-24 17:25:08 -0400162 bool mixers_swapped;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400163 struct sde_crtc_mixer mixers[CRTC_DUAL_MIXERS];
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400164
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400165 struct drm_pending_vblank_event *event;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400166 u32 vsync_count;
Clarence Ip8f7366c2016-07-05 12:15:26 -0400167
Clarence Ip7a753bb2016-07-07 11:47:44 -0400168 struct msm_property_info property_info;
169 struct msm_property_data property_data[CRTC_PROP_COUNT];
Dhaval Patele4a5dda2016-10-13 19:29:30 -0700170 struct drm_property_blob *blob_info;
Clarence Ip7a753bb2016-07-07 11:47:44 -0400171
Clarence Ip24f80662016-06-13 19:05:32 -0400172 /* output fence support */
Dhaval Patel39323d42017-03-01 23:48:24 -0800173 struct sde_fence_context output_fence;
Clarence Ip24f80662016-06-13 19:05:32 -0400174
Clarence Ip8f7366c2016-07-05 12:15:26 -0400175 struct sde_hw_stage_cfg stage_cfg;
176 struct dentry *debugfs_root;
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700177
Alan Kwong07da0982016-11-04 12:57:45 -0400178 u32 vblank_cb_count;
Dhaval Pateld67cf4a2017-06-14 18:08:32 -0700179 u64 play_count;
Alan Kwong07da0982016-11-04 12:57:45 -0400180 ktime_t vblank_cb_time;
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400181 bool vblank_requested;
Clarence Ip7f70ce42017-03-20 06:53:46 -0700182 bool suspend;
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400183 bool enabled;
Alan Kwong07da0982016-11-04 12:57:45 -0400184
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700185 struct list_head feature_list;
186 struct list_head active_list;
187 struct list_head dirty_list;
Gopikrishnaiah Anandan9ba43782017-01-31 18:23:08 -0800188 struct list_head ad_dirty;
189 struct list_head ad_active;
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700190 struct list_head user_event_list;
Dhaval Patel3fbe6bf2016-10-20 20:00:41 -0700191
192 struct mutex crtc_lock;
Alan Kwong628d19e2016-10-31 13:50:13 -0400193
194 atomic_t frame_pending;
195 struct sde_crtc_frame_event frame_events[SDE_CRTC_FRAME_EVENT_SIZE];
196 struct list_head frame_event_list;
197 spinlock_t spin_lock;
Veera Sundaram Sankaran7ee99092017-06-13 11:19:36 -0700198 struct completion frame_done_comp;
Clarence Ipa18d4832017-03-13 12:35:44 -0700199
200 /* for handling internal event thread */
Clarence Ipa18d4832017-03-13 12:35:44 -0700201 struct sde_crtc_event event_cache[SDE_CRTC_MAX_EVENT_COUNT];
202 struct list_head event_free_list;
203 spinlock_t event_lock;
Dhaval Patelf9245d62017-03-28 16:24:00 -0700204 bool misr_enable;
Dhaval Patel010f5172017-08-01 22:40:09 -0700205 u32 misr_frame_count;
206 u32 misr_data[CRTC_DUAL_MIXERS];
Veera Sundaram Sankaran82916e02017-03-29 18:44:22 -0700207
208 struct sde_power_event *power_event;
Alan Kwong751cf462017-06-08 10:26:46 -0400209
210 struct sde_core_perf_params cur_perf;
Alan Kwong310e9b02017-08-03 02:04:07 -0400211
212 struct mutex rp_lock;
213 struct list_head rp_head;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400214};
215
216#define to_sde_crtc(x) container_of(x, struct sde_crtc, base)
217
Clarence Ip7a753bb2016-07-07 11:47:44 -0400218/**
Alan Kwongcdb2f282017-03-18 13:42:06 -0700219 * struct sde_crtc_res_ops - common operations for crtc resources
220 * @get: get given resource
221 * @put: put given resource
222 */
223struct sde_crtc_res_ops {
224 void *(*get)(void *val, u32 type, u64 tag);
225 void (*put)(void *val);
226};
227
228/* crtc resource type (0x0-0xffff reserved for hw block type */
229#define SDE_CRTC_RES_ROT_OUT_FBO 0x10000
230#define SDE_CRTC_RES_ROT_OUT_FB 0x10001
231#define SDE_CRTC_RES_ROT_PLANE 0x10002
232#define SDE_CRTC_RES_ROT_IN_FB 0x10003
233
234#define SDE_CRTC_RES_FLAG_FREE BIT(0)
235
236/**
237 * struct sde_crtc_res - definition of crtc resources
238 * @list: list of crtc resource
239 * @type: crtc resource type
240 * @tag: unique identifier per type
241 * @refcount: reference/usage count
242 * @ops: callback operations
243 * @val: resource handle associated with type/tag
244 * @flags: customization flags
245 */
246struct sde_crtc_res {
247 struct list_head list;
248 u32 type;
249 u64 tag;
250 atomic_t refcount;
251 struct sde_crtc_res_ops ops;
252 void *val;
253 u32 flags;
254};
255
256/**
257 * sde_crtc_respool - crtc resource pool
Alan Kwong310e9b02017-08-03 02:04:07 -0400258 * @rp_lock: pointer to serialization lock
259 * @rp_head: pointer to head of active resource pools of this crtc
260 * @rp_list: list of crtc resource pool
Alan Kwongcdb2f282017-03-18 13:42:06 -0700261 * @sequence_id: sequence identifier, incremented per state duplication
262 * @res_list: list of resource managed by this resource pool
263 * @ops: resource operations for parent resource pool
264 */
265struct sde_crtc_respool {
Alan Kwong310e9b02017-08-03 02:04:07 -0400266 struct mutex *rp_lock;
267 struct list_head *rp_head;
268 struct list_head rp_list;
Alan Kwongcdb2f282017-03-18 13:42:06 -0700269 u32 sequence_id;
270 struct list_head res_list;
271 struct sde_crtc_res_ops ops;
272};
273
274/**
Clarence Ip7a753bb2016-07-07 11:47:44 -0400275 * struct sde_crtc_state - sde container for atomic crtc state
276 * @base: Base drm crtc state structure
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400277 * @connectors : Currently associated drm connectors
278 * @num_connectors: Number of associated drm connectors
Alan Kwong67a3f792016-11-01 23:16:53 -0400279 * @intf_mode : Interface mode of the primary connector
Dhaval Patel4d424602017-02-18 19:40:14 -0800280 * @rsc_client : sde rsc client when mode is valid
Lloyd Atkinson66e7dde2017-02-08 15:52:53 -0500281 * @is_ppsplit : Whether current topology requires PPSplit special handling
Alan Kwong0230a102017-05-16 11:36:44 -0700282 * @bw_control : true if bw/clk controlled by core bw/clk properties
283 * @bw_split_vote : true if bw controlled by llcc/dram bw properties
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400284 * @crtc_roi : Current CRTC ROI. Possibly sub-rectangle of mode.
285 * Origin top left of CRTC.
Lloyd Atkinson73fb8092017-02-08 16:02:55 -0500286 * @lm_bounds : LM boundaries based on current mode full resolution, no ROI.
287 * Origin top left of CRTC.
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400288 * @lm_roi : Current LM ROI, possibly sub-rectangle of mode.
289 * Origin top left of CRTC.
290 * @user_roi_list : List of user's requested ROIs as from set property
Clarence Ip4a2955d2017-07-04 18:04:33 -0400291 * @property_state: Local storage for msm_prop properties
Clarence Ip7a753bb2016-07-07 11:47:44 -0400292 * @property_values: Current crtc property values
Clarence Ipcae1bb62016-07-07 12:07:13 -0400293 * @input_fence_timeout_ns : Cached input fence timeout, in ns
Veera Sundaram Sankaran3171ff82017-01-04 14:34:47 -0800294 * @num_dim_layers: Number of dim layers
295 * @dim_layer: Dim layer configs
Alan Kwong751cf462017-06-08 10:26:46 -0400296 * @new_perf: new performance state being requested
Alan Kwong4dd64c82017-02-04 18:41:51 -0800297 * @sbuf_cfg: stream buffer configuration
Alan Kwong4aacd532017-02-04 18:51:33 -0800298 * @sbuf_prefill_line: number of line for inline rotator prefetch
Clarence Ip7e5f0002017-05-29 18:46:56 -0400299 * @sbuf_flush_mask: flush mask for inline rotator
Clarence Ip7a753bb2016-07-07 11:47:44 -0400300 */
301struct sde_crtc_state {
302 struct drm_crtc_state base;
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400303
304 struct drm_connector *connectors[MAX_CONNECTORS];
305 int num_connectors;
Alan Kwong67a3f792016-11-01 23:16:53 -0400306 enum sde_intf_mode intf_mode;
Dhaval Patel4d424602017-02-18 19:40:14 -0800307 struct sde_rsc_client *rsc_client;
Dhaval Patel82c8dbc2017-02-18 23:15:10 -0800308 bool rsc_update;
Alan Kwongff30f4a2017-05-23 12:02:00 -0700309 bool bw_control;
Alan Kwong0230a102017-05-16 11:36:44 -0700310 bool bw_split_vote;
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400311
Lloyd Atkinson66e7dde2017-02-08 15:52:53 -0500312 bool is_ppsplit;
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400313 struct sde_rect crtc_roi;
Lloyd Atkinson73fb8092017-02-08 16:02:55 -0500314 struct sde_rect lm_bounds[CRTC_DUAL_MIXERS];
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400315 struct sde_rect lm_roi[CRTC_DUAL_MIXERS];
316 struct msm_roi_list user_roi_list;
Lloyd Atkinsona9d7e752017-01-17 16:31:43 -0500317
Clarence Ip4a2955d2017-07-04 18:04:33 -0400318 struct msm_property_state property_state;
319 struct msm_property_value property_values[CRTC_PROP_COUNT];
Clarence Ipcae1bb62016-07-07 12:07:13 -0400320 uint64_t input_fence_timeout_ns;
Veera Sundaram Sankaran3171ff82017-01-04 14:34:47 -0800321 uint32_t num_dim_layers;
322 struct sde_hw_dim_layer dim_layer[SDE_MAX_DIM_LAYERS];
Alan Kwong9aa061c2016-11-06 21:17:12 -0500323
Alan Kwong9aa061c2016-11-06 21:17:12 -0500324 struct sde_core_perf_params new_perf;
Alan Kwong4dd64c82017-02-04 18:41:51 -0800325 struct sde_ctl_sbuf_cfg sbuf_cfg;
Clarence Ip7eb90452017-05-23 11:41:19 -0400326 u32 sbuf_prefill_line;
Clarence Ip7e5f0002017-05-29 18:46:56 -0400327 u32 sbuf_flush_mask;
Alan Kwongcdb2f282017-03-18 13:42:06 -0700328
329 struct sde_crtc_respool rp;
Clarence Ip7a753bb2016-07-07 11:47:44 -0400330};
331
332#define to_sde_crtc_state(x) \
333 container_of(x, struct sde_crtc_state, base)
334
335/**
336 * sde_crtc_get_property - query integer value of crtc property
337 * @S: Pointer to crtc state
338 * @X: Property index, from enum msm_mdp_crtc_property
339 * Returns: Integer value of requested property
340 */
341#define sde_crtc_get_property(S, X) \
Clarence Ip4a2955d2017-07-04 18:04:33 -0400342 ((S) && ((X) < CRTC_PROP_COUNT) ? ((S)->property_values[(X)].value) : 0)
Clarence Ip7a753bb2016-07-07 11:47:44 -0400343
Dhaval Patel48c76022016-09-01 17:51:23 -0700344static inline int sde_crtc_mixer_width(struct sde_crtc *sde_crtc,
345 struct drm_display_mode *mode)
346{
347 if (!sde_crtc || !mode)
348 return 0;
349
350 return sde_crtc->num_mixers == CRTC_DUAL_MIXERS ?
351 mode->hdisplay / CRTC_DUAL_MIXERS : mode->hdisplay;
352}
353
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400354/**
Veera Sundaram Sankaranc9efbec2017-03-29 18:59:05 -0700355 * sde_crtc_frame_pending - retun the number of pending frames
356 * @crtc: Pointer to drm crtc object
357 */
358static inline int sde_crtc_frame_pending(struct drm_crtc *crtc)
359{
360 struct sde_crtc *sde_crtc;
361
362 if (!crtc)
363 return -EINVAL;
364
365 sde_crtc = to_sde_crtc(crtc);
366 return atomic_read(&sde_crtc->frame_pending);
367}
368
369/**
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400370 * sde_crtc_vblank - enable or disable vblanks for this crtc
371 * @crtc: Pointer to drm crtc object
372 * @en: true to enable vblanks, false to disable
373 */
374int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
375
376/**
377 * sde_crtc_commit_kickoff - trigger kickoff of the commit for this crtc
378 * @crtc: Pointer to drm crtc object
379 */
380void sde_crtc_commit_kickoff(struct drm_crtc *crtc);
381
382/**
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400383 * sde_crtc_prepare_commit - callback to prepare for output fences
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400384 * @crtc: Pointer to drm crtc object
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400385 * @old_state: Pointer to drm crtc old state object
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400386 */
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400387void sde_crtc_prepare_commit(struct drm_crtc *crtc,
388 struct drm_crtc_state *old_state);
389
390/**
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400391 * sde_crtc_init - create a new crtc object
392 * @dev: sde device
393 * @plane: base plane
394 * @Return: new crtc object or error
395 */
396struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane);
397
398/**
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400399 * sde_crtc_cancel_pending_flip - complete flip for clients on lastclose
400 * @crtc: Pointer to drm crtc object
401 * @file: client to cancel's file handle
402 */
403void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
404
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400405/**
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700406 * sde_crtc_register_custom_event - api for enabling/disabling crtc event
407 * @kms: Pointer to sde_kms
408 * @crtc_drm: Pointer to crtc object
409 * @event: Event that client is interested
410 * @en: Flag to enable/disable the event
411 */
412int sde_crtc_register_custom_event(struct sde_kms *kms,
413 struct drm_crtc *crtc_drm, u32 event, bool en);
414
415/**
416 * sde_crtc_get_intf_mode - get interface mode of the given crtc
Alan Kwong9aa061c2016-11-06 21:17:12 -0500417 * @crtc: Pointert to crtc
418 */
Alan Kwong3e985f02017-02-12 15:08:44 -0800419enum sde_intf_mode sde_crtc_get_intf_mode(struct drm_crtc *crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500420
421/**
Dhaval Patel4d424602017-02-18 19:40:14 -0800422 * sde_crtc_get_client_type - check the crtc type- rt, nrt, rsc, etc.
Alan Kwong9aa061c2016-11-06 21:17:12 -0500423 * @crtc: Pointer to crtc
424 */
Dhaval Patel82c8dbc2017-02-18 23:15:10 -0800425static inline enum sde_crtc_client_type sde_crtc_get_client_type(
426 struct drm_crtc *crtc)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500427{
428 struct sde_crtc_state *cstate =
429 crtc ? to_sde_crtc_state(crtc->state) : NULL;
430
Dhaval Patel82c8dbc2017-02-18 23:15:10 -0800431 if (!cstate)
432 return NRT_CLIENT;
433
434 return cstate->rsc_client ? RT_RSC_CLIENT :
435 (cstate->intf_mode == INTF_MODE_WB_LINE ? NRT_CLIENT : RT_CLIENT);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500436}
437
438/**
439 * sde_crtc_is_enabled - check if sde crtc is enabled or not
440 * @crtc: Pointer to crtc
441 */
442static inline bool sde_crtc_is_enabled(struct drm_crtc *crtc)
443{
444 return crtc ? crtc->enabled : false;
445}
446
Clarence Ipa18d4832017-03-13 12:35:44 -0700447/**
Alan Kwong56f1a942017-04-04 11:53:42 -0700448 * sde_crtc_get_inline_prefill - get current inline rotation prefill
449 * @crtc: Pointer to crtc
450 * return: number of prefill lines
451 */
452static inline u32 sde_crtc_get_inline_prefill(struct drm_crtc *crtc)
453{
Clarence Ip7eb90452017-05-23 11:41:19 -0400454 struct sde_crtc_state *cstate;
455
Alan Kwong56f1a942017-04-04 11:53:42 -0700456 if (!crtc || !crtc->state)
457 return 0;
458
Clarence Ip7eb90452017-05-23 11:41:19 -0400459 cstate = to_sde_crtc_state(crtc->state);
460 return cstate->sbuf_cfg.rot_op_mode != SDE_CTL_ROT_OP_MODE_OFFLINE ?
461 cstate->sbuf_prefill_line : 0;
Alan Kwong56f1a942017-04-04 11:53:42 -0700462}
463
464/**
Clarence Ipa18d4832017-03-13 12:35:44 -0700465 * sde_crtc_event_queue - request event callback
466 * @crtc: Pointer to drm crtc structure
467 * @func: Pointer to callback function
468 * @usr: Pointer to user data to be passed to callback
469 * Returns: Zero on success
470 */
471int sde_crtc_event_queue(struct drm_crtc *crtc,
Gopikrishnaiah Anandanb6b401f2017-03-14 16:39:49 -0700472 void (*func)(struct drm_crtc *crtc, void *usr), void *usr);
Clarence Ipa18d4832017-03-13 12:35:44 -0700473
Alan Kwongcdb2f282017-03-18 13:42:06 -0700474/**
475 * sde_crtc_res_add - add given resource to resource pool in crtc state
476 * @state: Pointer to drm crtc state
477 * @type: Resource type
478 * @tag: Search tag for given resource
479 * @val: Resource handle
480 * @ops: Resource callback operations
481 * return: 0 if success; error code otherwise
482 */
483int sde_crtc_res_add(struct drm_crtc_state *state, u32 type, u64 tag,
484 void *val, struct sde_crtc_res_ops *ops);
485
486/**
487 * sde_crtc_res_get - get given resource from resource pool in crtc state
488 * @state: Pointer to drm crtc state
489 * @type: Resource type
490 * @tag: Search tag for given resource
491 * return: Resource handle if success; pointer error or null otherwise
492 */
493void *sde_crtc_res_get(struct drm_crtc_state *state, u32 type, u64 tag);
494
495/**
496 * sde_crtc_res_put - return given resource to resource pool in crtc state
497 * @state: Pointer to drm crtc state
498 * @type: Resource type
499 * @tag: Search tag for given resource
500 * return: None
501 */
502void sde_crtc_res_put(struct drm_crtc_state *state, u32 type, u64 tag);
503
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400504/**
505 * sde_crtc_get_crtc_roi - retrieve the crtc_roi from the given state object
506 * used to allow the planes to adjust their final lm out_xy value in the
507 * case of partial update
508 * @crtc_state: Pointer to crtc state
509 * @crtc_roi: Output pointer to crtc roi in the given state
510 */
511void sde_crtc_get_crtc_roi(struct drm_crtc_state *state,
512 const struct sde_rect **crtc_roi);
513
Abhijit Kulkarni7444a7d2017-06-21 18:53:36 -0700514/** sde_crt_get_secure_level - retrieve the secure level from the give state
515 * object, this is used to determine the secure state of the crtc
516 * @crtc : Pointer to drm crtc structure
517 * @usr: Pointer to drm crtc state
518 * return: secure_level
519 */
520static inline int sde_crtc_get_secure_level(struct drm_crtc *crtc,
521 struct drm_crtc_state *state)
522{
523 if (!crtc || !state)
524 return -EINVAL;
525
526 return sde_crtc_get_property(to_sde_crtc_state(state),
527 CRTC_PROP_SECURITY_LEVEL);
528}
529
530
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400531#endif /* _SDE_CRTC_H_ */